#include <QScrollBar>
#include "tabdialogmessenger.h"
#include "msgwidget.h"


TabDialogMessenger::TabDialogMessenger(int id, QString login, QWidget *parent):
    QListWidget(parent),
    login(""),
    id(0)
{
    this->id = id;
    this->login = login;

    setWordWrap(true);
    setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
}

TabDialogMessenger::~TabDialogMessenger()
{

}

void TabDialogMessenger::addMsgWidgetLocal(QString text)
{
    QListWidgetItem *listWidgetItem = new QListWidgetItem();
    QString avatar = ":/resources/icons/instructor.png";
    MsgWidget *msgWidget = new MsgWidget(avatar, MsgWidget::AligneAvatar::Left,
                                      width() - verticalScrollBar()->size().width());

    addItem(listWidgetItem);
    setItemWidget(listWidgetItem, msgWidget);

    msgWidget->setText(text);

    //Корректировка высоты item
    listWidgetItem->setSizeHint (QSize(10, msgWidget->height()));

    scrollToItem(listWidgetItem);
}

void TabDialogMessenger::addMsgWidgetRemote(QString text)
{
    QListWidgetItem *listWidgetItem = new QListWidgetItem();
    QString avatar = ":/resources/icons/trainee.png";
    MsgWidget *msgWidget = new MsgWidget(avatar, MsgWidget::AligneAvatar::Right,
                                      width() - verticalScrollBar()->size().width());

    addItem(listWidgetItem);
    setItemWidget(listWidgetItem, msgWidget);

    msgWidget->setText(text);

    //Корректировка высоты item
    listWidgetItem->setSizeHint (QSize(10, msgWidget->height()));

    scrollToItem(listWidgetItem);
}
