mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-29 20:05:38 +03:00
A
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#include <QListWidget>
|
||||
#include <QBrush>
|
||||
#include <QKeyEvent>
|
||||
#include "messangerwidget.h"
|
||||
#include "ui_messangerwidget.h"
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QMessageBox>
|
||||
#include <QLabel>
|
||||
#include <QScrollBar>
|
||||
#include "messangerwidget.h"
|
||||
#include "ui_messangerwidget.h"
|
||||
#include "msgwidget.h"
|
||||
|
||||
MessangerWidget::MessangerWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@@ -37,13 +40,7 @@ void MessangerWidget::addMsg(Trainee trainee, QString text, MessangerWidget::ETy
|
||||
//Добавляем в существующую вкладку
|
||||
ui->tabWidget->setCurrentIndex(dialogMsg.getIndexTab());
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(QIcon(":/icons/trainee.png"), prefix + text);
|
||||
//item->setTextAlignment(Qt::AlignBaseline);
|
||||
//QString style = QStringLiteral("QListView::item { color: red; }");
|
||||
//dialogMsg.getListWidget()->setStyleSheet(style);
|
||||
|
||||
//item->setBackground(QBrush(QColor(200, 200, 255)));
|
||||
dialogMsg.getListWidget()->addItem(item);
|
||||
dialogMsg.addMsgWidgetRemote(text);
|
||||
|
||||
currLogin = trainee.getLogin();
|
||||
return;
|
||||
@@ -71,7 +68,9 @@ void MessangerWidget::addTabDialogMessenger(Trainee trainee)
|
||||
//Добавляем новую вкладку диалога
|
||||
QListWidget* listWidget = new QListWidget();
|
||||
listWidget->setWordWrap(true);
|
||||
//listWidget->setItemAlignment(Qt::AlignmentFlag::AlignTop);
|
||||
|
||||
listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
|
||||
|
||||
int index = ui->tabWidget->addTab(listWidget, /*login + ": " +*/ trainee.getName());
|
||||
|
||||
if(trainee.getLoggedIn())
|
||||
@@ -102,9 +101,7 @@ void MessangerWidget::on_btnSend_clicked()
|
||||
//Добавляем в существующую вкладку
|
||||
ui->tabWidget->setCurrentIndex(dialogMsg.getIndexTab());
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(QIcon(":/icons/instructor.png"), prefix + text);
|
||||
//item->setBackground(QBrush(QColor(200, 255, 200)));
|
||||
dialogMsg.getListWidget()->addItem(item);
|
||||
dialogMsg.addMsgWidgetLocal(text);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -182,3 +179,37 @@ void MessangerWidget::changeEvent(QEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TabDialogMessenger::addMsgWidgetLocal(QString text)
|
||||
{
|
||||
QListWidgetItem *listWidgetItem = new QListWidgetItem();
|
||||
QString avatar = ":/icons/instructor.png";
|
||||
MsgWidget *msgWidget = new MsgWidget(avatar, MsgWidget::AligneAvatar::Left,
|
||||
listWidget->width() - listWidget->verticalScrollBar()->size().width());
|
||||
|
||||
listWidget->addItem(listWidgetItem);
|
||||
listWidget->setItemWidget(listWidgetItem, msgWidget);
|
||||
|
||||
msgWidget->setText(text);
|
||||
|
||||
listWidgetItem->setSizeHint (QSize(10, msgWidget->height()));
|
||||
|
||||
listWidget->scrollToItem(listWidgetItem);
|
||||
}
|
||||
|
||||
void TabDialogMessenger::addMsgWidgetRemote(QString text)
|
||||
{
|
||||
QListWidgetItem *listWidgetItem = new QListWidgetItem();
|
||||
QString avatar = ":/icons/trainee.png";
|
||||
MsgWidget *msgWidget = new MsgWidget(avatar, MsgWidget::AligneAvatar::Right,
|
||||
listWidget->width() - listWidget->verticalScrollBar()->size().width());
|
||||
|
||||
listWidget->addItem(listWidgetItem);
|
||||
listWidget->setItemWidget(listWidgetItem, msgWidget);
|
||||
|
||||
msgWidget->setText(text);
|
||||
|
||||
listWidgetItem->setSizeHint (QSize(10, msgWidget->height()));
|
||||
|
||||
listWidget->scrollToItem(listWidgetItem);
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@ public:
|
||||
};
|
||||
|
||||
QString getLogin() {return login;};
|
||||
QListWidget* getListWidget() {return listWidget;};
|
||||
int getIndexTab() {return indexTab;};
|
||||
|
||||
void addMsgWidgetLocal(QString text);
|
||||
void addMsgWidgetRemote(QString text);
|
||||
|
||||
private:
|
||||
QString login = "";
|
||||
int indexTab = 0;
|
||||
|
||||
@@ -113,12 +113,22 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>30</y>
|
||||
<width>256</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
|
||||
81
DB_IaT/InstructorsAndTrainees/messanger/msgwidget.cpp
Normal file
81
DB_IaT/InstructorsAndTrainees/messanger/msgwidget.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "msgwidget.h"
|
||||
#include "ui_msgwidget.h"
|
||||
#include <QSizePolicy>
|
||||
|
||||
MsgWidget::MsgWidget(QString avatar, AligneAvatar aligneAvatar, int width, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::MsgWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setAvatar(avatar);
|
||||
|
||||
if(aligneAvatar == AligneAvatar::Left)
|
||||
setAligneAvatarLeft();
|
||||
else
|
||||
setAligneAvatarRight();
|
||||
|
||||
setWidth(width);
|
||||
}
|
||||
|
||||
MsgWidget::~MsgWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MsgWidget::setAligneAvatarLeft()
|
||||
{
|
||||
ui->horizontalLayout->removeWidget(ui->textEdit);
|
||||
ui->horizontalLayout->removeItem(ui->verticalLayout);
|
||||
ui->horizontalLayout->removeItem(ui->horizontalLayout_2);
|
||||
|
||||
ui->horizontalLayout->addLayout(ui->verticalLayout);
|
||||
ui->horizontalLayout->addWidget(ui->textEdit);
|
||||
ui->horizontalLayout->addLayout(ui->horizontalLayout_2);
|
||||
|
||||
ui->textEdit->setObjectName("MsgWidgetLocal");
|
||||
}
|
||||
|
||||
void MsgWidget::setAligneAvatarRight()
|
||||
{
|
||||
ui->horizontalLayout->removeWidget(ui->textEdit);
|
||||
ui->horizontalLayout->removeItem(ui->verticalLayout);
|
||||
ui->horizontalLayout->removeItem(ui->horizontalLayout_2);
|
||||
|
||||
ui->horizontalLayout->addLayout(ui->horizontalLayout_2);
|
||||
ui->horizontalLayout->addWidget(ui->textEdit);
|
||||
ui->horizontalLayout->addLayout(ui->verticalLayout);
|
||||
|
||||
ui->textEdit->setObjectName("MsgWidgetRemote");
|
||||
}
|
||||
|
||||
|
||||
void MsgWidget::setAvatar(QString avatar)
|
||||
{
|
||||
QPixmap pix(avatar);
|
||||
ui->label->setPixmap( pix.scaled(32,32) );
|
||||
}
|
||||
|
||||
void MsgWidget::setWidth(int width)
|
||||
{
|
||||
this->setFixedWidth(width);
|
||||
ui->textEdit->setFixedWidth(width - 200);
|
||||
}
|
||||
|
||||
void MsgWidget::setText(QString text)
|
||||
{
|
||||
ui->textEdit->setText(text);
|
||||
}
|
||||
|
||||
void MsgWidget::on_textEdit_textChanged()
|
||||
{
|
||||
QString text = ui->textEdit->toPlainText();
|
||||
QFontMetrics metricsFont(ui->textEdit->font()); //метрики шрифта
|
||||
QRect textRect = metricsFont.boundingRect(QRect(0, 0, 0, 0), 0 , text); //геометрические параметры текста (высота/ширина в пикселях)
|
||||
int X = 10; // отступы
|
||||
|
||||
this->setFixedHeight(textRect.height()+X + 20);
|
||||
|
||||
ui->textEdit->setFixedWidth(textRect.width()+X);
|
||||
ui->textEdit->setFixedHeight(textRect.height()+X);
|
||||
}
|
||||
38
DB_IaT/InstructorsAndTrainees/messanger/msgwidget.h
Normal file
38
DB_IaT/InstructorsAndTrainees/messanger/msgwidget.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef MSGWIDGET_H
|
||||
#define MSGWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class MsgWidget;
|
||||
}
|
||||
|
||||
class MsgWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum AligneAvatar
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
|
||||
public:
|
||||
explicit MsgWidget(QString avatar, AligneAvatar aligneAvatar, int width, QWidget *parent = nullptr);
|
||||
~MsgWidget();
|
||||
|
||||
void setAligneAvatarLeft();
|
||||
void setAligneAvatarRight();
|
||||
void setAvatar(QString avatar);
|
||||
void setWidth(int width);
|
||||
|
||||
void setText(QString text);
|
||||
|
||||
private slots:
|
||||
void on_textEdit_textChanged();
|
||||
|
||||
private:
|
||||
Ui::MsgWidget *ui;
|
||||
};
|
||||
|
||||
#endif // MSGWIDGET_H
|
||||
106
DB_IaT/InstructorsAndTrainees/messanger/msgwidget.ui
Normal file
106
DB_IaT/InstructorsAndTrainees/messanger/msgwidget.ui
Normal file
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MsgWidget</class>
|
||||
<widget class="QWidget" name="MsgWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user