void GroupChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date) { QPalette greentext; greentext.setColor(QPalette::WindowText, QColor(61,204,61)); QScrollBar* scroll = chatArea->verticalScrollBar(); lockSliderToBottom = scroll && scroll->value() == scroll->maximum(); author->setAlignment(Qt::AlignTop | Qt::AlignLeft); date->setAlignment(Qt::AlignTop); message->setWordWrap(true); message->setTextInteractionFlags(Qt::TextBrowserInteraction); author->setTextInteractionFlags(Qt::TextBrowserInteraction); date->setTextInteractionFlags(Qt::TextBrowserInteraction); if (author->text() == Widget::getInstance()->getUsername()) { QPalette pal; pal.setColor(QPalette::WindowText, Qt::gray); author->setPalette(pal); message->setPalette(pal); } if (previousName.isEmpty() || previousName != author->text()) { if (curRow) { mainChatLayout->setRowStretch(curRow, 0); mainChatLayout->addItem(new QSpacerItem(0,AUTHOR_CHANGE_SPACING),curRow,0,1,3); } previousName = author->text(); curRow++; } else if (curRow)// onSaveLogClicked expects 0 or 3 QLabel per line author->setText(""); if (message->text()[0] == '>') message->setPalette(greentext); mainChatLayout->addWidget(author, curRow, 0); mainChatLayout->addWidget(message, curRow, 1); mainChatLayout->addWidget(date, curRow, 3); mainChatLayout->setRowStretch(curRow+1, 1); mainChatLayout->setRowStretch(curRow, 0); curRow++; author->setContextMenuPolicy(Qt::CustomContextMenu); message->setContextMenuPolicy(Qt::CustomContextMenu); date->setContextMenuPolicy(Qt::CustomContextMenu); connect(author, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); connect(message, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); connect(date, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); }
GenericChatForm::GenericChatForm(QObject *parent) : QObject(parent) { curRow = 0; mainWidget = new QWidget(); headWidget = new QWidget(); nameLabel = new CroppingLabel(); avatarLabel = new QLabel(); QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout(); headTextLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *footButtonsSmall = new QVBoxLayout(), *volMicLayout = new QVBoxLayout(); chatWidget = new ChatAreaWidget(); chatWidget->document()->setDefaultStyleSheet(Style::get(":ui/chatArea/innerStyle.css")); chatWidget->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css")); msgEdit = new ChatTextEdit(); sendButton = new QPushButton(); emoteButton = new QPushButton(); fileButton = new QPushButton(); callButton = new QPushButton(); videoButton = new QPushButton(); volButton = new QPushButton(); micButton = new QPushButton(); QFont bold; bold.setBold(true); nameLabel->setFont(bold); footButtonsSmall->setSpacing(2); msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css")); msgEdit->setFixedHeight(50); msgEdit->setFrameStyle(QFrame::NoFrame); sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css")); fileButton->setStyleSheet(Style::get(":/ui/fileButton/fileButton.css")); emoteButton->setStyleSheet(Style::get(":/ui/emoteButton/emoteButton.css")); callButton->setObjectName("green"); callButton->setStyleSheet(Style::get(":/ui/callButton/callButton.css")); videoButton->setObjectName("green"); videoButton->setStyleSheet(Style::get(":/ui/videoButton/videoButton.css")); QString volButtonStylesheet = Style::get(":/ui/volButton/volButton.css"); volButton->setObjectName("green"); volButton->setStyleSheet(volButtonStylesheet); QString micButtonStylesheet = Style::get(":/ui/micButton/micButton.css"); micButton->setObjectName("green"); micButton->setStyleSheet(micButtonStylesheet); mainWidget->setLayout(mainLayout); mainLayout->addWidget(chatWidget); mainLayout->addLayout(mainFootLayout); mainLayout->setMargin(0); footButtonsSmall->addWidget(emoteButton); footButtonsSmall->addWidget(fileButton); mainFootLayout->addWidget(msgEdit); mainFootLayout->addLayout(footButtonsSmall); mainFootLayout->addSpacing(5); mainFootLayout->addWidget(sendButton); mainFootLayout->setSpacing(0); headWidget->setLayout(headLayout); headLayout->addWidget(avatarLabel); headLayout->addLayout(headTextLayout); headLayout->addLayout(volMicLayout); headLayout->addWidget(callButton); headLayout->addWidget(videoButton); volMicLayout->addWidget(micButton); volMicLayout->addWidget(volButton); headTextLayout->addStretch(); headTextLayout->addWidget(nameLabel); //Fix for incorrect layouts on OS X as per //https://bugreports.qt-project.org/browse/QTBUG-14591 sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked())); connect(chatWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); }
GroupChatForm::GroupChatForm(Group* chatGroup) : group(chatGroup), curRow{0}, lockSliderToBottom{true} { main = new QWidget(), head = new QWidget(), chatAreaWidget = new QWidget(); headLayout = new QHBoxLayout(), mainFootLayout = new QHBoxLayout(); headTextLayout = new QVBoxLayout(), mainLayout = new QVBoxLayout(); mainChatLayout = new QGridLayout(); avatar = new QLabel(), name = new QLabel(), nusers = new QLabel(), namesList = new QLabel(); msgEdit = new ChatTextEdit(); sendButton = new QPushButton(); chatArea = new QScrollArea(); QFont bold; bold.setBold(true); QFont small; small.setPixelSize(10); name->setText(group->widget->name.text()); name->setFont(bold); nusers->setFont(small); nusers->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size())); avatar->setPixmap(QPixmap(":/img/group.png")); QString names; for (QString& s : group->peers) names.append(s+", "); names.chop(2); namesList->setText(names); namesList->setFont(small); chatAreaWidget->setLayout(mainChatLayout); chatArea->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css")); chatArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); chatArea->setWidgetResizable(true); chatArea->setContextMenuPolicy(Qt::CustomContextMenu); chatArea->setFrameStyle(QFrame::NoFrame); mainChatLayout->setColumnStretch(1,1); mainChatLayout->setSpacing(10); msgEdit->setObjectName("group"); msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css")); msgEdit->setFixedHeight(50); msgEdit->setFrameStyle(QFrame::NoFrame); mainChatLayout->setColumnStretch(1,1); mainChatLayout->setHorizontalSpacing(10); sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css")); sendButton->setFixedSize(50, 50); main->setLayout(mainLayout); mainLayout->addWidget(chatArea); mainLayout->addLayout(mainFootLayout); mainLayout->setMargin(0); mainFootLayout->addWidget(msgEdit); mainFootLayout->addWidget(sendButton); head->setLayout(headLayout); headLayout->addWidget(avatar); headLayout->addLayout(headTextLayout); headLayout->addStretch(); headLayout->setMargin(0); headTextLayout->addStretch(); headTextLayout->addWidget(name); headTextLayout->addWidget(nusers); headTextLayout->addWidget(namesList); headTextLayout->setMargin(0); headTextLayout->setSpacing(0); headTextLayout->addStretch(); chatArea->setWidget(chatAreaWidget); sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered())); connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered())); connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged())); connect(chatArea, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); }