mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
styleSheet
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <QKeyEvent>
|
||||
#include "messangerwidget.h"
|
||||
#include "ui_messangerwidget.h"
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QMessageBox>
|
||||
|
||||
MessangerWidget::MessangerWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@@ -13,9 +15,14 @@ MessangerWidget::MessangerWidget(QWidget *parent) :
|
||||
ui->tabWidget->removeTab(1);
|
||||
ui->tabWidget->removeTab(0);
|
||||
|
||||
ui->btnSend->setObjectName("btnSend");
|
||||
|
||||
/*
|
||||
ui->tabWidget->setStyleSheet("QTabBar::tab:selected "
|
||||
"{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);"
|
||||
"color: #ffffff;}");
|
||||
"color: #ffffff;}");*/
|
||||
|
||||
//updateMyStyleSheet();
|
||||
}
|
||||
|
||||
MessangerWidget::~MessangerWidget()
|
||||
@@ -23,42 +30,46 @@ MessangerWidget::~MessangerWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MessangerWidget::addMsg(QString login, QString name, QString text, MessangerWidget::ETypeMsg typeMsg)
|
||||
void MessangerWidget::addMsg(Trainee trainee, QString text, MessangerWidget::ETypeMsg typeMsg)
|
||||
{
|
||||
addDialogTab(login, name);
|
||||
addTabDialogMessenger(trainee);
|
||||
|
||||
QString prefix = (typeMsg == MessangerWidget::ETypeMsg::fromClient)? ">> " : "<< ";
|
||||
|
||||
//Ищем нужный диалог
|
||||
foreach(DialogMsg dialogMsg, listDialogMsg)
|
||||
foreach(TabDialogMessenger dialogMsg, listTabDialogMessenger)
|
||||
{
|
||||
if(dialogMsg.getLogin() == login)
|
||||
if(dialogMsg.getLogin() == trainee.getLogin())
|
||||
{
|
||||
//Добавляем в существующую вкладку
|
||||
ui->tabWidget->setCurrentIndex(dialogMsg.getIndexTab());
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(QIcon(":/icons/trainee.png"), prefix + text);
|
||||
item->setBackground(QBrush(QColor(200, 200, 255)));
|
||||
//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);
|
||||
|
||||
currLogin = login;
|
||||
currLogin = trainee.getLogin();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessangerWidget::addDialogTab(QString login, QString name)
|
||||
void MessangerWidget::addTabDialogMessenger(Trainee trainee)
|
||||
{
|
||||
if(listDialogMsg.count() == 0)
|
||||
if(listTabDialogMessenger.count() == 0)
|
||||
{
|
||||
currLogin = login;
|
||||
currLogin = trainee.getLogin();
|
||||
emit signal_tabMessengerChanged(currLogin);
|
||||
}
|
||||
|
||||
//Проверяем наличие диалога с этим клиентом
|
||||
foreach(DialogMsg dialogMsg, listDialogMsg)
|
||||
foreach(TabDialogMessenger dialogMsg, listTabDialogMessenger)
|
||||
{
|
||||
if(dialogMsg.getLogin() == login)
|
||||
if(dialogMsg.getLogin() == trainee.getLogin())
|
||||
{//Диалог для этого клиента уже существует
|
||||
return;
|
||||
}
|
||||
@@ -66,16 +77,51 @@ void MessangerWidget::addDialogTab(QString login, QString name)
|
||||
|
||||
//Добавляем новую вкладку диалога
|
||||
QListWidget* listWidget = new QListWidget();
|
||||
int index = ui->tabWidget->addTab(listWidget, /*login + ": " +*/ name);
|
||||
listWidget->setWordWrap(true);
|
||||
listWidget->setItemAlignment(Qt::AlignmentFlag::AlignTop);
|
||||
int index = ui->tabWidget->addTab(listWidget, /*login + ": " +*/ trainee.getName());
|
||||
|
||||
if(trainee.getLoggedIn())
|
||||
ui->tabWidget->setTabIcon(index, QIcon(":/icons/circleGreen.png"));
|
||||
else
|
||||
ui->tabWidget->setTabIcon(index, QIcon(":/icons/circleGray.png"));
|
||||
|
||||
//Помещаем новый диалог в список диалогов
|
||||
DialogMsg dialogMsg(index, listWidget, login);
|
||||
listDialogMsg.append(dialogMsg);
|
||||
TabDialogMessenger dialogMsg(index, listWidget, trainee.getLogin());
|
||||
listTabDialogMessenger.append(dialogMsg);
|
||||
}
|
||||
|
||||
void MessangerWidget::updateMyStyleSheet()
|
||||
{
|
||||
QString styleSheet = loadStyleSheet();
|
||||
styleSheet = styleSheet.replace("\n", "");
|
||||
|
||||
foreach(TabDialogMessenger dialogMsg, listTabDialogMessenger)
|
||||
dialogMsg.getListWidget()->setStyleSheet(styleSheet);
|
||||
}
|
||||
|
||||
QString MessangerWidget::loadStyleSheet()
|
||||
{
|
||||
QString fileName = "./styleSheetListWidget.css";
|
||||
QFile styleSheetFile(fileName);
|
||||
if (!styleSheetFile.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Attention!"), tr("The file could not be opened ") + fileName);
|
||||
return QStringLiteral("");
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray byteArray = styleSheetFile.readAll();
|
||||
styleSheetFile.close();
|
||||
|
||||
QString style = byteArray;
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
void MessangerWidget::on_btnSend_clicked()
|
||||
{
|
||||
QString text = ui->editMsg->text();
|
||||
QString text = ui->editMsg->toPlainText();
|
||||
|
||||
emit signal_msgToClientReady(currLogin, text);
|
||||
|
||||
@@ -84,7 +130,7 @@ void MessangerWidget::on_btnSend_clicked()
|
||||
QString prefix = "<< ";
|
||||
|
||||
//Ищем нужный диалог
|
||||
foreach(DialogMsg dialogMsg, listDialogMsg)
|
||||
foreach(TabDialogMessenger dialogMsg, listTabDialogMessenger)
|
||||
{
|
||||
if(dialogMsg.getLogin() == currLogin)
|
||||
{
|
||||
@@ -103,7 +149,7 @@ void MessangerWidget::on_btnSend_clicked()
|
||||
void MessangerWidget::on_tabWidget_currentChanged(int index)
|
||||
{
|
||||
//Ищем нужный диалог
|
||||
foreach(DialogMsg dialogMsg, listDialogMsg)
|
||||
foreach(TabDialogMessenger dialogMsg, listTabDialogMessenger)
|
||||
{
|
||||
if(dialogMsg.getIndexTab() == index)
|
||||
{
|
||||
@@ -117,7 +163,7 @@ void MessangerWidget::on_tabWidget_currentChanged(int index)
|
||||
void MessangerWidget::slot_traineeSelected(QString login)
|
||||
{
|
||||
//Ищем нужный диалог
|
||||
foreach(DialogMsg dialogMsg, listDialogMsg)
|
||||
foreach(TabDialogMessenger dialogMsg, listTabDialogMessenger)
|
||||
{
|
||||
if(dialogMsg.getLogin() == login)
|
||||
{
|
||||
@@ -136,16 +182,22 @@ void MessangerWidget::slot_LanguageChanged(QString language)
|
||||
|
||||
void MessangerWidget::slot_InitMessanger(QList<Trainee> listTrainees)
|
||||
{
|
||||
this->listTrainees = listTrainees;
|
||||
|
||||
for(Trainee trainee: listTrainees)
|
||||
{
|
||||
if(! trainee.getArchived())
|
||||
this->addDialogTab(trainee.getLogin(), trainee.getName());
|
||||
this->addTabDialogMessenger(trainee);
|
||||
}
|
||||
}
|
||||
|
||||
void MessangerWidget::slot_msgFromClientReady(QString login, QString text)
|
||||
{
|
||||
addMsg(login, "name", text, MessangerWidget::ETypeMsg::fromClient);
|
||||
for(Trainee trainee: listTrainees)
|
||||
{
|
||||
if(trainee.getLogin() == login)
|
||||
addMsg(trainee, text, MessangerWidget::ETypeMsg::fromClient);
|
||||
}
|
||||
}
|
||||
|
||||
void MessangerWidget::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#include <trainee.h>
|
||||
#include "Datas.h"
|
||||
|
||||
class DialogMsg
|
||||
class TabDialogMessenger
|
||||
{
|
||||
public:
|
||||
DialogMsg();
|
||||
DialogMsg(int indexTab, QListWidget* listWidget, QString login)
|
||||
TabDialogMessenger();
|
||||
TabDialogMessenger(int indexTab, QListWidget* listWidget, QString login)
|
||||
{
|
||||
this->indexTab = indexTab;
|
||||
this->listWidget = listWidget;
|
||||
@@ -48,8 +48,13 @@ protected:
|
||||
public:
|
||||
enum ETypeMsg{fromClient, toClient};
|
||||
|
||||
void addMsg(QString login, QString name, QString text, ETypeMsg typeMsg);
|
||||
void addDialogTab(QString login, QString name);
|
||||
void addMsg(Trainee trainee, QString text, ETypeMsg typeMsg);
|
||||
void addTabDialogMessenger(Trainee trainee);
|
||||
|
||||
public:
|
||||
void updateMyStyleSheet();
|
||||
private:
|
||||
QString loadStyleSheet();
|
||||
|
||||
private slots:
|
||||
void on_btnSend_clicked();
|
||||
@@ -58,25 +63,26 @@ private slots:
|
||||
signals:
|
||||
//сигнал о готовности нового сообщения на отправку клиенту
|
||||
void signal_msgToClientReady(QString login, QString text);
|
||||
//сигнал об изменении вкладки диалога
|
||||
//сигнал об изменении вкладки диалога (TabDialogMessenger)
|
||||
void signal_tabMessengerChanged(QString login);
|
||||
|
||||
public slots:
|
||||
//слот обработки сигнала о выборе обучаемого
|
||||
void slot_traineeSelected(QString login);
|
||||
//слот обработки сигнала о смене языка
|
||||
void slot_LanguageChanged(QString language);
|
||||
//слот обработки сигнала об инициализации мессенджера
|
||||
void slot_InitMessanger(QList<Trainee> listTrainees);
|
||||
//слот обработки сигнала о выборе обучаемого
|
||||
void slot_traineeSelected(QString login);
|
||||
//слот о приходе нового сообщения от клиента
|
||||
void slot_msgFromClientReady(QString login, QString text);
|
||||
|
||||
private:
|
||||
virtual void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
QList <DialogMsg> listDialogMsg;
|
||||
|
||||
QList <TabDialogMessenger> listTabDialogMessenger;
|
||||
QList<Trainee> listTrainees;
|
||||
QString currLogin = "";
|
||||
|
||||
Ui::MessangerWidget *ui;
|
||||
QTranslator qtLanguageTranslator;
|
||||
};
|
||||
|
||||
@@ -28,10 +28,90 @@
|
||||
<string>Messenger</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="editMsg">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>1000</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnSend">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>65</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1000</width>
|
||||
<height>1000</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/sendMsg.png</normaloff>:/icons/sendMsg.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
@@ -49,39 +129,6 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editMsg"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnSend">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/sendMsg.png</normaloff>:/icons/sendMsg.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user