diff --git a/friend.cpp b/friend.cpp index 6676cea81..5f48197dd 100644 --- a/friend.cpp +++ b/friend.cpp @@ -36,19 +36,17 @@ Friend::~Friend() void Friend::setName(QString name) { - widget->name.setText(name); - widget->name.setToolTip(name); // for overlength names + widget->setName(name); chatForm->setName(name); } void Friend::setStatusMessage(QString message) { - widget->statusMessage.setText(message); - widget->statusMessage.setToolTip(message); // for overlength messsages + widget->setStatusMsg(message); chatForm->setStatusMessage(message); } QString Friend::getName() { - return widget->name.text(); + return widget->getName(); } diff --git a/misc/style.cpp b/misc/style.cpp index 609dcc277..b4d1cc209 100644 --- a/misc/style.cpp +++ b/misc/style.cpp @@ -19,17 +19,129 @@ #include #include +#include +#include +#include +#include -QString Style::get(const QString &filename) +// helper functions +QFont appFont(int pixelSize, int weight) +{ + QFont font; + font.setPixelSize(pixelSize); + font.setWeight(weight); + return font; +} + +QString qssifyWeight(int weight) +{ + QString weightStr = "normal"; + if (weight == QFont::Bold) + weightStr = "bold"; + if (weight == QFont::Light) + weightStr = "light"; + + return QString("%1").arg(weightStr); +} + +QString qssifyFont(QFont font) +{ + return QString("%1px %2 \"%3\"") + .arg(font.pixelSize()) + .arg(qssifyWeight(font.weight())) + .arg(font.family()); +} + +QString Style::getStylesheet(const QString &filename) { if (!Settings::getInstance().getUseNativeStyle()) { QFile file(filename); if (file.open(QFile::ReadOnly | QFile::Text)) - return file.readAll(); + return resolve(file.readAll()); else - qWarning() << "Style " << filename << " not found"; + qWarning() << "Style: Stylesheet " << filename << " not found"; } return QString(); } + +QColor Style::getColor(Style::ColorPalette entry) +{ + static QColor palette[] = { + QColor("#6bc260"), + QColor("#cebf44"), + QColor("#c84e4e"), + QColor("#000000"), + QColor("#1c1c1c"), + QColor("#414141"), + QColor("#414141").lighter(120), + QColor("#d1d1d1"), + QColor("#ffffff"), + }; + + return palette[entry]; +} + +QFont Style::getFont(Style::Font font) +{ + static QFont fonts[] = { + appFont(14, QFont::Bold), + appFont(12, QFont::Normal), + appFont(12, QFont::Bold), + appFont(11, QFont::Normal), + appFont(11, QFont::Bold), + appFont(10, QFont::Normal), + appFont(10, QFont::Light), + }; + + return fonts[font]; +} + +QString Style::resolve(QString qss) +{ + static QMap dict = { + // colors + {"@green", getColor(Green).name()}, + {"@yellow", getColor(Yellow).name()}, + {"@red", getColor(Red).name()}, + {"@black", getColor(Black).name()}, + {"@darkGrey", getColor(DarkGrey).name()}, + {"@mediumGrey", getColor(MediumGrey).name()}, + {"@mediumGreyLight", getColor(MediumGreyLight).name()}, + {"@lightGrey", getColor(LightGrey).name()}, + {"@white", getColor(White).name()}, + + // fonts + {"@extraBig", qssifyFont(getFont(ExtraBig))}, + {"@big", qssifyFont(getFont(Big))}, + {"@bigBold", qssifyFont(getFont(BigBold))}, + {"@medium", qssifyFont(getFont(Medium))}, + {"@mediumBold", qssifyFont(getFont(MediumBold))}, + {"@small", qssifyFont(getFont(Small))}, + {"@smallLight", qssifyFont(getFont(SmallLight))}, + }; + + for (const QString& key : dict.keys()) + { + qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]); + } + + return qss; +} + +void Style::repolish(QWidget *w) +{ + w->style()->unpolish(w); + w->style()->polish(w); + + for (QObject* o : w->children()) + { + QWidget* c = qobject_cast(o); + if (c) + { + c->style()->unpolish(c); + c->style()->polish(c); + } + } +} diff --git a/misc/style.h b/misc/style.h index 4bd42d77f..35c0b7e98 100644 --- a/misc/style.h +++ b/misc/style.h @@ -17,12 +17,45 @@ #ifndef STYLE_H #define STYLE_H +#include +#include + class QString; +class QWidget; class Style { public: - static QString get(const QString& filename); + enum ColorPalette + { + Green, + Yellow, + Red, + Black, + DarkGrey, + MediumGrey, + MediumGreyLight, + LightGrey, + White, + }; + + enum Font + { + ExtraBig, // 14px, bold + Big, // 12px + BigBold, // 12px, bold + Medium, // 11px + MediumBold, // 11px, bold + Small, // 10px + SmallLight // 10px, light + }; + + static QString getStylesheet(const QString& filename); + static QColor getColor(ColorPalette entry); + static QFont getFont(Font font); + static QString resolve(QString qss); + static void repolish(QWidget* w); + private: Style(); }; diff --git a/res.qrc b/res.qrc index c4719df01..5b4910039 100644 --- a/res.qrc +++ b/res.qrc @@ -145,5 +145,6 @@ translations/uk.qm img/avatar_mask.png img/group_2x.png + ui/chatroomWidgets/genericChatroomWidget.css diff --git a/ui/chatArea/innerStyle.css b/ui/chatArea/innerStyle.css index 28bcb32c8..fd0ca03ee 100644 --- a/ui/chatArea/innerStyle.css +++ b/ui/chatArea/innerStyle.css @@ -1,25 +1,31 @@ -div.name_me { - color: #646464; - font-weight: bold; - padding-right: 3px; -} - div.name { - color: #000000; - font-weight: bold; - padding-right: 3px; + color: @black; + font: @big; } div.message { - color: #000000; - padding-right: 3px; - padding-left: 3px; + color: @black; + font: @big; } div.date { - color: #000000; - padding-left: 3px; - white-space: nowrap; + color: @black; + font: @big; +} + +div.name_me { + color: @mediumGrey; + font: @big; +} + +div.message_me { + color: @mediumGrey; + font: @big; +} + +div.date_me { + color: @mediumGrey; + font: @big; } span.quote { @@ -31,9 +37,9 @@ div.green { margin-bottom: 12px; margin-left: 12px; margin-right: 12px; - color: #ffffff; - background-color: #6bc260; - font-size: 10px; + color: @white; + background-color: @green; + font: @small; } div.silver { @@ -41,9 +47,9 @@ div.silver { margin-bottom: 12px; margin-left: 12px; margin-right: 12px; - color: #000000; - background-color: #d1d1d1; - font-size: 10px; + color: @black; + background-color: @lightGrey; + font: @small; } div.red { @@ -51,14 +57,14 @@ div.red { margin-bottom: 12px; margin-left: 12px; margin-right: 12px; - color: #ffffff; - background-color: rgb(200,78,78); - font-size: 10px; + color: @white; + background-color: @red; + font: @small; } div.button { margin-top: 0px; margin-bottom: 0px; margin-left: 0px; - color: #ffffff; + color: @white; } diff --git a/ui/chatroomWidgets/genericChatroomWidget.css b/ui/chatroomWidgets/genericChatroomWidget.css new file mode 100644 index 000000000..4ed573fb0 --- /dev/null +++ b/ui/chatroomWidgets/genericChatroomWidget.css @@ -0,0 +1,38 @@ +GenericChatroomWidget +{ + background-color: @mediumGrey; +} + +GenericChatroomWidget[active="true"] +{ + background-color: @white; +} + +GenericChatroomWidget[active="false"]:hover +{ + background-color: @mediumGreyLight; +} + +GenericChatroomWidget[active="true"] > QLabel#status +{ + font: @medium; + color: @mediumGrey; +} + +GenericChatroomWidget[active="false"] > QLabel#status +{ + font: @medium; + color: @lightGrey; +} + +GenericChatroomWidget[active="true"] > QLabel#name +{ + font: @big; + color: @darkGrey; +} + +GenericChatroomWidget[active="false"] > QLabel#name +{ + font: @big; + color: @white; +} \ No newline at end of file diff --git a/ui/emoticonWidget/dot_page.png b/ui/emoticonWidget/dot_page.png index c7c2aa172..e74d514e2 100644 Binary files a/ui/emoticonWidget/dot_page.png and b/ui/emoticonWidget/dot_page.png differ diff --git a/ui/emoticonWidget/dot_page_current.png b/ui/emoticonWidget/dot_page_current.png index aa101903a..7b18c42c2 100644 Binary files a/ui/emoticonWidget/dot_page_current.png and b/ui/emoticonWidget/dot_page_current.png differ diff --git a/ui/emoticonWidget/dot_page_hover.png b/ui/emoticonWidget/dot_page_hover.png index 1c23931b9..822dbb6c6 100644 Binary files a/ui/emoticonWidget/dot_page_hover.png and b/ui/emoticonWidget/dot_page_hover.png differ diff --git a/ui/emoticonWidget/emoticonWidget.css b/ui/emoticonWidget/emoticonWidget.css index a1aab7de3..093db5122 100644 --- a/ui/emoticonWidget/emoticonWidget.css +++ b/ui/emoticonWidget/emoticonWidget.css @@ -35,6 +35,6 @@ QRadioButton::indicator::checked QMenu { - background-color: rgb(240,240,240); /* sets background of the menu */ - border: 1px solid; + background-color: @mediumGrey; /* sets background of the menu */ + border: 0px solid; } diff --git a/ui/msgEdit/msgEdit.css b/ui/msgEdit/msgEdit.css index 2509f57fc..bbc967ccc 100644 --- a/ui/msgEdit/msgEdit.css +++ b/ui/msgEdit/msgEdit.css @@ -1,5 +1,5 @@ QTextEdit { - border-color: #c4c1bd; + border-color: @lightGrey; border-style: solid; border-width: 1px 0 1px 1px; } diff --git a/widget/adjustingscrollarea.cpp b/widget/adjustingscrollarea.cpp index 04b735ed1..29315ba8b 100644 --- a/widget/adjustingscrollarea.cpp +++ b/widget/adjustingscrollarea.cpp @@ -48,17 +48,3 @@ QSize AdjustingScrollArea::sizeHint() const return QScrollArea::sizeHint(); } - -bool AdjustingScrollArea::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() == QEvent::Paint) - { - // workaround: sometimes a child widget gets drawn on top of the scrollbar - // so we trigger a repaint afterwards - // => Actually, we don't. This triggers an infinite loop of QEvent::UpdateRequest and burns 100% CPU ! - //verticalScrollBar()->update(); - //horizontalScrollBar()->update(); - } - - return QObject::eventFilter(obj, ev); -} diff --git a/widget/adjustingscrollarea.h b/widget/adjustingscrollarea.h index 380ac5df8..584e4e875 100644 --- a/widget/adjustingscrollarea.h +++ b/widget/adjustingscrollarea.h @@ -27,7 +27,6 @@ public: virtual void resizeEvent(QResizeEvent *ev) override; virtual QSize sizeHint() const override; - virtual bool eventFilter(QObject *obj, QEvent *ev) override; }; #endif // ADJUSTINGSCROLLAREA_H diff --git a/widget/chatareawidget.cpp b/widget/chatareawidget.cpp index c2e7a90b6..c743574fa 100644 --- a/widget/chatareawidget.cpp +++ b/widget/chatareawidget.cpp @@ -23,8 +23,9 @@ #include #include -ChatAreaWidget::ChatAreaWidget(QWidget *parent) : - QTextBrowser(parent) +ChatAreaWidget::ChatAreaWidget(QWidget *parent) + : QTextBrowser(parent) + , nameWidth(75) { setReadOnly(true); viewport()->setCursor(Qt::ArrowCursor); @@ -36,19 +37,19 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) : setAcceptRichText(false); setFrameStyle(QFrame::NoFrame); - chatTextTable = textCursor().insertTable(1,3); - QTextTableFormat tableFormat; + tableFormat.setCellSpacing(15); tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None); - tableFormat.setCellSpacing(2); - tableFormat.setWidth(QTextLength(QTextLength::PercentageLength,100)); - chatTextTable->setFormat(tableFormat); - setNameColWidth(100); + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::FixedLength,nameWidth), + QTextLength(QTextLength::PercentageLength,100), + QTextLength(QTextLength::VariableLength,0)}); -// nameFormat.setAlignment(Qt::AlignRight); -// nameFormat.setNonBreakableLines(true); -// dateFormat.setAlignment(Qt::AlignLeft); -// dateFormat.setNonBreakableLines(true); + chatTextTable = textCursor().insertTable(1,3,tableFormat); + + nameFormat.setAlignment(Qt::AlignRight); + nameFormat.setNonBreakableLines(true); + dateFormat.setAlignment(Qt::AlignLeft); + dateFormat.setNonBreakableLines(true); connect(this, &ChatAreaWidget::anchorClicked, this, &ChatAreaWidget::onAnchorClicked); connect(verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged())); @@ -112,9 +113,11 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction) cur.clearSelection(); cur.setKeepPositionOnInsert(true); chatTextTable->appendRows(1); + chatTextTable->cellAt(row,0).firstCursorPosition().setBlockFormat(nameFormat); chatTextTable->cellAt(row,0).firstCursorPosition().insertHtml(msgAction->getName()); chatTextTable->cellAt(row,1).firstCursorPosition().insertHtml(msgAction->getMessage()); - chatTextTable->cellAt(row,2).firstCursorPosition().insertText(msgAction->getDate()); + chatTextTable->cellAt(row,2).firstCursorPosition().setBlockFormat(dateFormat); + chatTextTable->cellAt(row,2).firstCursorPosition().insertHtml(msgAction->getDate()); msgAction->setup(cur, this); diff --git a/widget/emoticonswidget.cpp b/widget/emoticonswidget.cpp index 1e3d0ea4e..8383c79a9 100644 --- a/widget/emoticonswidget.cpp +++ b/widget/emoticonswidget.cpp @@ -27,7 +27,7 @@ EmoticonsWidget::EmoticonsWidget(QWidget *parent) : QMenu(parent) { - setStyleSheet(Style::get(":/ui/emoticonWidget/emoticonWidget.css")); + setStyleSheet(Style::getStylesheet(":/ui/emoticonWidget/emoticonWidget.css")); setLayout(&layout); layout.addWidget(&stack); diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index ed307bc89..f2f2c32d6 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -34,18 +34,26 @@ #include "core.h" #include "widget/widget.h" #include "widget/maskablepixmapwidget.h" +#include "widget/croppinglabel.h" +#include "misc/style.h" ChatForm::ChatForm(Friend* chatFriend) : f(chatFriend) { nameLabel->setText(f->getName()); - avatar->setPixmap(QPixmap(":/img/contact_dark.png")); + + avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent); statusMessageLabel = new CroppingLabel(); + statusMessageLabel->setFont(Style::getFont(Style::Medium)); + QPalette pal; pal.setColor(QPalette::WindowText, Style::getColor(Style::MediumGrey)); + statusMessageLabel->setPalette(pal); + netcam = new NetCamView(); headTextLayout->addWidget(statusMessageLabel); headTextLayout->addStretch(); + headTextLayout->setSpacing(0); connect(Core::getInstance(), &Core::fileSendStarted, this, &ChatForm::startFileSend); connect(Core::getInstance(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay); @@ -507,5 +515,5 @@ void ChatForm::onAvatarRemoved(int FriendId) if (FriendId != f->friendId) return; - avatar->setPixmap(QPixmap(":/img/contact_dark.png")); + avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent); } diff --git a/widget/form/genericchatform.cpp b/widget/form/genericchatform.cpp index 26bd958ba..a7bcb5e2b 100644 --- a/widget/form/genericchatform.cpp +++ b/widget/form/genericchatform.cpp @@ -36,6 +36,10 @@ GenericChatForm::GenericChatForm(QWidget *parent) : headWidget = new QWidget(); nameLabel = new CroppingLabel(); + nameLabel->setFont(Style::getFont(Style::MediumBold)); + QPalette pal; pal.setColor(QPalette::WindowText, Style::getColor(Style::DarkGrey)); + nameLabel->setPalette(pal); + avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png"); QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout(); headTextLayout = new QVBoxLayout(); @@ -43,8 +47,8 @@ GenericChatForm::GenericChatForm(QWidget *parent) : 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")); + chatWidget->document()->setDefaultStyleSheet(Style::getStylesheet(":ui/chatArea/innerStyle.css")); + chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css")); msgEdit = new ChatTextEdit(); @@ -63,25 +67,25 @@ GenericChatForm::GenericChatForm(QWidget *parent) : footButtonsSmall->setSpacing(2); - msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css")); + msgEdit->setStyleSheet(Style::getStylesheet(":/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")); + sendButton->setStyleSheet(Style::getStylesheet(":/ui/sendButton/sendButton.css")); + fileButton->setStyleSheet(Style::getStylesheet(":/ui/fileButton/fileButton.css")); + emoteButton->setStyleSheet(Style::getStylesheet(":/ui/emoteButton/emoteButton.css")); callButton->setObjectName("green"); - callButton->setStyleSheet(Style::get(":/ui/callButton/callButton.css")); + callButton->setStyleSheet(Style::getStylesheet(":/ui/callButton/callButton.css")); videoButton->setObjectName("green"); - videoButton->setStyleSheet(Style::get(":/ui/videoButton/videoButton.css")); + videoButton->setStyleSheet(Style::getStylesheet(":/ui/videoButton/videoButton.css")); - QString volButtonStylesheet = Style::get(":/ui/volButton/volButton.css"); + QString volButtonStylesheet = Style::getStylesheet(":/ui/volButton/volButton.css"); volButton->setObjectName("green"); volButton->setStyleSheet(volButtonStylesheet); - QString micButtonStylesheet = Style::get(":/ui/micButton/micButton.css"); + QString micButtonStylesheet = Style::getStylesheet(":/ui/micButton/micButton.css"); micButton->setObjectName("green"); micButton->setStyleSheet(micButtonStylesheet); @@ -169,7 +173,9 @@ void GenericChatForm::addMessage(QString author, QString message, QDateTime date if (previousName == author) chatWidget->insertMessage(new MessageAction("", message, date, isMe)); - else chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe)); + else + chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe)); + previousName = author; } diff --git a/widget/form/groupchatform.cpp b/widget/form/groupchatform.cpp index 7622f2cf0..412ef46e8 100644 --- a/widget/form/groupchatform.cpp +++ b/widget/form/groupchatform.cpp @@ -21,6 +21,7 @@ #include "widget/croppinglabel.h" #include "widget/maskablepixmapwidget.h" #include "core.h" +#include "misc/style.h" #include #include #include @@ -40,10 +41,14 @@ GroupChatForm::GroupChatForm(Group* chatGroup) QFont small; small.setPixelSize(10); - nameLabel->setText(group->widget->name.text()); - nusersLabel->setFont(small); + nameLabel->setText(group->widget->getName()); + + nusersLabel->setFont(Style::getFont(Style::Medium)); nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size())); - avatar->setPixmap(QPixmap(":/img/group_dark.png")); + QPalette pal; pal.setColor(QPalette::WindowText, Style::getColor(Style::MediumGrey)); + nusersLabel->setPalette(pal); + + avatar->setPixmap(QPixmap(":/img/group_dark.png"), Qt::transparent); QString names; for (QString& s : group->peers) diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index ad16ac75c..a524a7daf 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -23,6 +23,8 @@ #include "core.h" #include "widget/form/chatform.h" #include "widget/maskablepixmapwidget.h" +#include "widget/croppinglabel.h" +#include "misc/style.h" #include #include #include @@ -31,56 +33,12 @@ #include FriendWidget::FriendWidget(int FriendId, QString id) - : friendId(FriendId), isDefaultAvatar{true} + : friendId(FriendId) + , isDefaultAvatar{true} { - setMouseTracking(true); - setAutoFillBackground(true); - setFixedHeight(55); - setLayout(&layout); - layout.setSpacing(0); - layout.setMargin(0); - layout.setStretchFactor(this, 100); - textLayout.setSpacing(0); - textLayout.setMargin(0); - setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft - - avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png"); - avatar->setPixmap(QPixmap(":img/contact_dark.png")); - name.setText(id); - //statusPic.setAlignment(Qt::AlignHCenter); + avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent); statusPic.setPixmap(QPixmap(":img/status/dot_away.png")); - QFont small; - small.setPixelSize(10); - statusMessage.setFont(small); - QPalette pal; - pal.setColor(QPalette::WindowText,Qt::gray); - statusMessage.setPalette(pal); - QPalette pal2; - pal2.setColor(QPalette::WindowText,Qt::white); - name.setPalette(pal2); - QPalette pal3; - pal3.setColor(QPalette::Background, QColor(65,65,65,255)); - this->setPalette(pal3); - - textLayout.addStretch(); - textLayout.addWidget(&name); - textLayout.addWidget(&statusMessage); - textLayout.addStretch(); - - layout.addSpacing(20); - layout.addWidget(avatar); - layout.addSpacing(5); - layout.addLayout(&textLayout); - layout.addSpacing(5); - layout.addWidget(&statusPic); - layout.addSpacing(5); - - isActiveWidget = 0; - - layout.invalidate(); - layout.update(); - layout.activate(); - updateGeometry(); + nameLabel->setText(id); } void FriendWidget::contextMenuEvent(QContextMenuEvent * event) @@ -92,7 +50,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) QMap groupActions; for (Group* group : GroupList::groupList) { - QAction* groupAction = inviteMenu->addAction(group->widget->name.text()); + QAction* groupAction = inviteMenu->addAction(group->widget->getName()); groupActions[groupAction] = group; } if (groupActions.isEmpty()) @@ -126,38 +84,18 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) void FriendWidget::setAsActiveChatroom() { - isActiveWidget = 1; + setActive(true); - QFont small; - small.setPixelSize(10); - statusMessage.setFont(small); - QPalette pal; - pal.setColor(QPalette::WindowText,Qt::darkGray); - statusMessage.setPalette(pal); - QPalette pal2; - pal2.setColor(QPalette::WindowText,Qt::black); - name.setPalette(pal2); - QPalette pal3; - pal3.setColor(QPalette::Background, Qt::white); - this->setPalette(pal3); + if (isDefaultAvatar) + avatar->setPixmap(QPixmap(":img/contact_dark.png"), Qt::transparent); } void FriendWidget::setAsInactiveChatroom() { - isActiveWidget = 0; + setActive(false); - QFont small; - small.setPixelSize(10); - statusMessage.setFont(small); - QPalette pal; - pal.setColor(QPalette::WindowText,Qt::gray); - statusMessage.setPalette(pal); - QPalette pal2; - pal2.setColor(QPalette::WindowText,Qt::white); - name.setPalette(pal2); - QPalette pal3; - pal3.setColor(QPalette::Background, QColor(65,65,65,255)); - this->setPalette(pal3); + if (isDefaultAvatar) + avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent); } void FriendWidget::updateStatusLight() @@ -202,6 +140,7 @@ void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic) isDefaultAvatar = false; avatar->setPixmap(pic); + avatar->autopickBackground(); } void FriendWidget::onAvatarRemoved(int FriendId) @@ -210,7 +149,7 @@ void FriendWidget::onAvatarRemoved(int FriendId) return; isDefaultAvatar = true; - avatar->setPixmap(QPixmap(":img/contact_dark.png")); + avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent); } void FriendWidget::mousePressEvent(QMouseEvent *ev) diff --git a/widget/friendwidget.h b/widget/friendwidget.h index cc29c0385..a04a5e76e 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -20,7 +20,6 @@ #include #include "genericchatroomwidget.h" -#include "croppinglabel.h" class QPixmap; class MaskablePixmapWidget; @@ -52,9 +51,6 @@ protected: public: int friendId; - MaskablePixmapWidget* avatar; - QLabel statusPic; - CroppingLabel name, statusMessage; bool isDefaultAvatar; QPoint dragStartPos; }; diff --git a/widget/genericchatroomwidget.cpp b/widget/genericchatroomwidget.cpp index 234da1222..8e875bd3e 100644 --- a/widget/genericchatroomwidget.cpp +++ b/widget/genericchatroomwidget.cpp @@ -15,56 +15,82 @@ */ #include "genericchatroomwidget.h" +#include "misc/style.h" +#include "widget/maskablepixmapwidget.h" +#include "croppinglabel.h" #include +#include -GenericChatroomWidget::GenericChatroomWidget(QWidget *parent) : - QWidget(parent) +GenericChatroomWidget::GenericChatroomWidget(QWidget *parent) + : QFrame(parent) { + setFixedHeight(55); + + setLayout(&layout); + layout.setSpacing(0); + layout.setMargin(0); + textLayout.setSpacing(0); + textLayout.setMargin(0); + setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft + + // avatar + avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png"); + + // status text + statusMessageLabel = new CroppingLabel(this); + statusMessageLabel->setObjectName("status"); + + // name text + nameLabel = new CroppingLabel(this); + nameLabel->setObjectName("name"); + + textLayout.addStretch(); + textLayout.addWidget(nameLabel); + textLayout.addWidget(statusMessageLabel); + textLayout.addStretch(); + + layout.addSpacing(20); + layout.addWidget(avatar); + layout.addSpacing(10); + layout.addLayout(&textLayout); + layout.addSpacing(10); + layout.addWidget(&statusPic); + layout.addSpacing(10); + layout.activate(); + + setProperty("active", false); + setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/genericChatroomWidget.css")); } -int GenericChatroomWidget::isActive() +bool GenericChatroomWidget::isActive() { - return isActiveWidget; + return property("active").toBool(); } -void GenericChatroomWidget::mousePressEvent(QMouseEvent *event) +void GenericChatroomWidget::setActive(bool active) { - if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton) - { - if (isActive()) - { - QPalette pal; - pal.setColor(QPalette::Background, QColor(250,250,250,255)); - this->setPalette(pal); - } - else - { - QPalette pal; - pal.setColor(QPalette::Background, QColor(85,85,85,255)); - this->setPalette(pal); - } - } + setProperty("active", active); + Style::repolish(this); } -void GenericChatroomWidget::leaveEvent(QEvent *) +void GenericChatroomWidget::setName(const QString &name) { - if (isActive() != 1) - { - QPalette pal; - pal.setColor(QPalette::Background, lastColor); - this->setPalette(pal); - } + nameLabel->setText(name); } -void GenericChatroomWidget::enterEvent(QEvent *) +void GenericChatroomWidget::setStatusMsg(const QString &status) { - if (isActive() != 1) - { - QPalette pal; - pal.setColor(QPalette::Background, QColor(75,75,75,255)); - lastColor = this->palette().background().color(); - this->setPalette(pal); - } + statusMessageLabel->setText(status); +} + +QString GenericChatroomWidget::getName() const +{ + return nameLabel->text(); +} + +QString GenericChatroomWidget::getStatusMsg() const +{ + return statusMessageLabel->text(); } void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*) diff --git a/widget/genericchatroomwidget.h b/widget/genericchatroomwidget.h index 14e46c16e..1dd6d8250 100644 --- a/widget/genericchatroomwidget.h +++ b/widget/genericchatroomwidget.h @@ -17,23 +17,24 @@ #ifndef GENERICCHATROOMWIDGET_H #define GENERICCHATROOMWIDGET_H -#include +#include #include #include +#include + +class CroppingLabel; +class MaskablePixmapWidget; namespace Ui { class MainWindow; } -class GenericChatroomWidget : public QWidget +class GenericChatroomWidget : public QFrame { Q_OBJECT public: GenericChatroomWidget(QWidget *parent = 0); - void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent (QMouseEvent* event); - void leaveEvent(QEvent *); - void enterEvent(QEvent *); virtual void setAsActiveChatroom(){;} virtual void setAsInactiveChatroom(){;} @@ -41,7 +42,14 @@ public: virtual void setChatForm(Ui::MainWindow &){;} virtual void resetEventFlags(){;} - int isActive(); + bool isActive(); + void setActive(bool active); + + void setName(const QString& name); + void setStatusMsg(const QString& status); + + QString getName() const; + QString getStatusMsg() const; signals: void chatroomWidgetClicked(GenericChatroomWidget* widget); @@ -49,10 +57,12 @@ signals: public slots: protected: - int isActiveWidget; QColor lastColor; QHBoxLayout layout; QVBoxLayout textLayout; + MaskablePixmapWidget* avatar; + QLabel statusPic; + CroppingLabel *nameLabel, *statusMessageLabel; }; #endif // GENERICCHATROOMWIDGET_H diff --git a/widget/groupwidget.cpp b/widget/groupwidget.cpp index d803063ce..ab64a54da 100644 --- a/widget/groupwidget.cpp +++ b/widget/groupwidget.cpp @@ -20,6 +20,7 @@ #include "misc/settings.h" #include "widget/form/groupchatform.h" #include "widget/maskablepixmapwidget.h" +#include "misc/style.h" #include #include #include @@ -29,53 +30,15 @@ GroupWidget::GroupWidget(int GroupId, QString Name) : groupId{GroupId} { - setMouseTracking(true); - setAutoFillBackground(true); - setLayout(&layout); - setFixedHeight(55); - layout.setSpacing(0); - layout.setMargin(0); - textLayout.setSpacing(0); - textLayout.setMargin(0); - setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft - - avatar = new MaskablePixmapWidget(this, QSize(40,40), QString(), Qt::transparent); - avatar->setPixmap(QPixmap(":img/group.png")); + avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent); statusPic.setPixmap(QPixmap(":img/status/dot_online.png")); - name.setText(Name); - QFont small; - small.setPixelSize(10); - nusers.setFont(small); - QPalette pal; - pal.setColor(QPalette::WindowText,Qt::gray); - nusers.setPalette(pal); - QPalette pal2; - pal2.setColor(QPalette::WindowText,Qt::white); - name.setPalette(pal2); - QPalette pal3; - pal3.setColor(QPalette::Background, QColor(65,65,65,255)); - this->setPalette(pal3); + nameLabel->setText(Name); + Group* g = GroupList::findGroup(groupId); if (g) - nusers.setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size())); + statusMessageLabel->setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size())); else - nusers.setText(GroupWidget::tr("0 users in chat")); - - textLayout.addStretch(); - textLayout.addWidget(&name); - textLayout.addWidget(&nusers); - textLayout.addStretch(); - - layout.addSpacing(20); - layout.addWidget(avatar); - layout.addSpacing(5); - layout.addLayout(&textLayout); - layout.addStretch(); - layout.addSpacing(5); - layout.addWidget(&statusPic); - layout.addSpacing(5); - - isActiveWidget = 0; + statusMessageLabel->setText(GroupWidget::tr("0 users in chat")); } void GroupWidget::contextMenuEvent(QContextMenuEvent * event) @@ -86,60 +49,28 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event) QAction* selectedItem = menu.exec(pos); if (selectedItem == quitGroup) - { - hide(); - show(); //Toggle visibility to work around bug of repaintEvent() not being fired on parent widget when this is hidden - hide(); emit removeGroup(groupId); - return; - } } void GroupWidget::onUserListChanged() { Group* g = GroupList::findGroup(groupId); if (g) - nusers.setText(tr("%1 users in chat").arg(g->nPeers)); + statusMessageLabel->setText(tr("%1 users in chat").arg(g->nPeers)); else - nusers.setText(tr("0 users in chat")); + statusMessageLabel->setText(tr("0 users in chat")); } void GroupWidget::setAsActiveChatroom() { - isActiveWidget = 1; - - QFont small; - small.setPixelSize(10); - nusers.setFont(small); - QPalette pal; - pal.setColor(QPalette::WindowText,Qt::darkGray); - nusers.setPalette(pal); - QPalette pal2; - pal2.setColor(QPalette::WindowText,Qt::black); - name.setPalette(pal2); - QPalette pal3; - pal3.setColor(QPalette::Background, Qt::white); - this->setPalette(pal3); - avatar->setPixmap(QPixmap(":img/group_dark.png")); + setActive(true); + avatar->setPixmap(QPixmap(":img/group_dark.png"), Qt::transparent); } void GroupWidget::setAsInactiveChatroom() { - isActiveWidget = 0; - - QFont small; - small.setPixelSize(10); - nusers.setFont(small); - QPalette pal; - pal.setColor(QPalette::WindowText,Qt::gray); - nusers.setPalette(pal); - QPalette pal2; - pal2.setColor(QPalette::WindowText,Qt::white); - name.setPalette(pal2); - QPalette pal3; - pal3.setColor(QPalette::Background, QColor(65,65,65,255)); - this->setPalette(pal3); - avatar->setPixmap(QPixmap(":img/group.png")); + setActive(false); + avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent); } void GroupWidget::updateStatusLight() @@ -152,16 +83,20 @@ void GroupWidget::updateStatusLight() { statusPic.setPixmap(QPixmap(":img/status/dot_online.png")); } else { - if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); - else statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); + if (g->userWasMentioned == 0) + statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); + else + statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png")); } } else { if (g->hasNewMessages == 0) { statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png")); } else { - if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png")); - else statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png")); + if (g->userWasMentioned == 0) + statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png")); + else + statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png")); } } } diff --git a/widget/groupwidget.h b/widget/groupwidget.h index 960ab9cb7..2d35000a0 100644 --- a/widget/groupwidget.h +++ b/widget/groupwidget.h @@ -20,8 +20,6 @@ #include #include "genericchatroomwidget.h" -class MaskablePixmapWidget; - class GroupWidget : public GenericChatroomWidget { Q_OBJECT @@ -41,8 +39,6 @@ signals: public: int groupId; - QLabel name, nusers, statusPic; - MaskablePixmapWidget* avatar; }; #endif // GROUPWIDGET_H diff --git a/widget/maskablepixmapwidget.cpp b/widget/maskablepixmapwidget.cpp index 90eaf9552..185494147 100644 --- a/widget/maskablepixmapwidget.cpp +++ b/widget/maskablepixmapwidget.cpp @@ -17,9 +17,9 @@ #include "maskablepixmapwidget.h" #include -MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName, QColor background) +MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName) : QWidget(parent) - , backgroundColor(background) + , backgroundColor(Qt::white) , clickable(false) { setFixedSize(size); @@ -30,6 +30,48 @@ MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString mask = QPixmap(maskName).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } +void MaskablePixmapWidget::autopickBackground() +{ + QImage pic = pixmap.toImage(); + + if (pic.isNull()) + return; + + int r = 0; + int g = 0; + int b = 0; + int weight = 0; + + for (int x=0;xclickable = clickable; @@ -40,10 +82,26 @@ void MaskablePixmapWidget::setClickable(bool clickable) unsetCursor(); } +void MaskablePixmapWidget::setPixmap(const QPixmap &pmap, QColor background) +{ + if (!pmap.isNull()) + { + pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + backgroundColor = background; + + update(); + } +} + void MaskablePixmapWidget::setPixmap(const QPixmap &pmap) { - pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); - update(); + if (!pmap.isNull()) + { + pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + autopickBackground(); + + update(); + } } QPixmap MaskablePixmapWidget::getPixmap() const diff --git a/widget/maskablepixmapwidget.h b/widget/maskablepixmapwidget.h index c4601d227..2fe92c180 100644 --- a/widget/maskablepixmapwidget.h +++ b/widget/maskablepixmapwidget.h @@ -23,9 +23,12 @@ class MaskablePixmapWidget : public QWidget { Q_OBJECT public: - MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName, QColor background = Qt::white); + MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName = QString()); + void autopickBackground(); + void setBackground(QColor color); void setClickable(bool clickable); + void setPixmap(const QPixmap &pmap, QColor background); void setPixmap(const QPixmap &pmap); QPixmap getPixmap() const; diff --git a/widget/tool/chatactions/chataction.cpp b/widget/tool/chatactions/chataction.cpp index 7758aae33..6978711a6 100644 --- a/widget/tool/chatactions/chataction.cpp +++ b/widget/tool/chatactions/chataction.cpp @@ -41,13 +41,15 @@ QString ChatAction::QImage2base64(const QImage &img) QString ChatAction::getName() { if (isMe) - return QString("
" + toHtmlChars(name) + "
"); + return QString("
%2
").arg("name_me").arg(toHtmlChars(name)); else - return QString("
" + toHtmlChars(name) + "
"); + return QString("
%2
").arg("name").arg(toHtmlChars(name)); } QString ChatAction::getDate() { - QString res = date; - return res; + if (isMe) + return QString("
" + toHtmlChars(date) + "
"); + else + return QString("
" + toHtmlChars(date) + "
"); } diff --git a/widget/tool/chatactions/messageaction.cpp b/widget/tool/chatactions/messageaction.cpp index 9904be470..6445279ea 100644 --- a/widget/tool/chatactions/messageaction.cpp +++ b/widget/tool/chatactions/messageaction.cpp @@ -71,5 +71,8 @@ QString MessageAction::getMessage() } message_ = message_.left(message_.length()-4); - return QString("
" + message_ + "
"); + if (isMe) + return QString("
" + message_ + "
"); + else + return QString("
" + message_ + "
"); } diff --git a/widget/widget.cpp b/widget/widget.cpp index a70fac605..e2c4770e9 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -68,17 +68,17 @@ Widget::Widget(QWidget *parent) this->layout()->setContentsMargins(0, 0, 0, 0); ui->friendList->setObjectName("friendList"); - ui->friendList->setStyleSheet(Style::get(":ui/friendList/friendList.css")); + ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css")); } else { this->setObjectName("activeWindow"); - this->setStyleSheet(Style::get(":ui/window/window.css")); + this->setStyleSheet(Style::getStylesheet(":ui/window/window.css")); ui->statusPanel->setStyleSheet(QString("")); ui->friendList->setStyleSheet(QString("")); ui->friendList->setObjectName("friendList"); - ui->friendList->setStyleSheet(Style::get(":ui/friendList/friendList.css")); + ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css")); ui->tbMenu->setIcon(QIcon(":ui/window/applicationIcon.png")); ui->pbMin->setObjectName("minimizeButton"); @@ -116,6 +116,7 @@ Widget::Widget(QWidget *parent) profilePicture->setPixmap(QPixmap(":/img/contact_dark.png")); profilePicture->setClickable(true); ui->horizontalLayout_3->insertWidget(0,profilePicture); + ui->horizontalLayout_3->insertSpacing(1, 7); ui->mainContent->setLayout(new QVBoxLayout()); ui->mainHead->setLayout(new QVBoxLayout()); @@ -129,13 +130,16 @@ Widget::Widget(QWidget *parent) ui->nameLabel->setEditable(true); ui->statusLabel->setEditable(true); + ui->statusLabel->setFont(Style::getFont(Style::Medium)); + ui->nameLabel->setFont(Style::getFont(Style::ExtraBig)); + // delay setting username and message until Core inits //ui->nameLabel->setText(core->getUsername()); ui->nameLabel->setStyleSheet("QLabel { color : white; font-size: 11pt; font-weight:bold;}"); //ui->statusLabel->setText(core->getStatusMessage()); ui->statusLabel->setStyleSheet("QLabel { color : white; font-size: 8pt;}"); - ui->statusButton->setStyleSheet(Style::get(":/ui/statusButton/statusButton.css")); + ui->statusButton->setStyleSheet(Style::getStylesheet(":/ui/statusButton/statusButton.css")); QMenu *statusButtonMenu = new QMenu(ui->statusButton); QAction* setStatusOnline = statusButtonMenu->addAction(Widget::tr("Online","Button to set your status to 'Online'"));