From 214e428b7ea8efb6e40b3df5c6ed7fbb924bd611 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Tue, 30 Sep 2014 23:45:33 +0200 Subject: [PATCH] cleanup, use qss instead of QPalette --- misc/style.cpp | 16 +++++++------- widget/friendwidget.cpp | 21 ------------------- widget/genericchatroomwidget.cpp | 36 +++++++++++++------------------- widget/groupwidget.cpp | 28 ++++++++----------------- 4 files changed, 32 insertions(+), 69 deletions(-) diff --git a/misc/style.cpp b/misc/style.cpp index 0801cf154..84096aad8 100644 --- a/misc/style.cpp +++ b/misc/style.cpp @@ -19,7 +19,14 @@ #include #include -#include + +// helper function +QFont appFont(int pixelSize, int weight) { + auto font = QFont(); + font.setPixelSize(pixelSize); + font.setWeight(weight); + return font; +} QString Style::getStylesheet(const QString &filename) { @@ -51,13 +58,6 @@ QColor Style::getColor(Style::ColorPalette entry) return palette[entry]; } -QFont appFont(int pixelSize, int weight) { - auto font = QFont(); - font.setPixelSize(pixelSize); - font.setWeight(weight); - return font; -} - QFont Style::getFont(Style::Font font) { static QFont fonts[] = { diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index be83930ec..cc4e925de 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -35,22 +35,10 @@ FriendWidget::FriendWidget(int FriendId, QString id) : 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.png"), Qt::transparent); name.setText(id); - //statusPic.setAlignment(Qt::AlignHCenter); statusPic.setPixmap(QPixmap(":img/status/dot_away.png")); // status text @@ -65,11 +53,6 @@ FriendWidget::FriendWidget(int FriendId, QString id) name.setPalette(pal2); name.setFont(Style::getFont(Style::Big)); - // background - QPalette pal3; - pal3.setColor(QPalette::Background, Style::getColor(Style::MediumGrey)); - setPalette(pal3); - textLayout.addStretch(); textLayout.addWidget(&name); textLayout.addWidget(&statusMessage); @@ -82,11 +65,7 @@ FriendWidget::FriendWidget(int FriendId, QString id) layout.addSpacing(10); layout.addWidget(&statusPic); layout.addSpacing(10); - - layout.invalidate(); - layout.update(); layout.activate(); - updateGeometry(); } void FriendWidget::contextMenuEvent(QContextMenuEvent * event) diff --git a/widget/genericchatroomwidget.cpp b/widget/genericchatroomwidget.cpp index 224c8f463..971e1c303 100644 --- a/widget/genericchatroomwidget.cpp +++ b/widget/genericchatroomwidget.cpp @@ -22,49 +22,43 @@ GenericChatroomWidget::GenericChatroomWidget(QWidget *parent) : QWidget(parent) , isActiveWidget(false) { + setMouseTracking(true); + 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 + + setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name())); } bool GenericChatroomWidget::isActive() { return isActiveWidget; } - void GenericChatroomWidget::setActive(bool active) { isActiveWidget = active; if (active) - { - QPalette pal; - pal.setColor(QPalette::Background, Style::getColor(Style::White)); - setPalette(pal); - } + setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::White).name())); else - { - QPalette pal; - pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey)); - setPalette(pal); - } + setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name())); } void GenericChatroomWidget::leaveEvent(QEvent *) { if (!isActive()) - { - QPalette pal; - pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey)); - setPalette(pal); - } + setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name())); } void GenericChatroomWidget::enterEvent(QEvent *) { if (!isActive()) - { - QPalette pal; - pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey).lighter(120)); - setPalette(pal); - } + setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).lighter(120).name())); } void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*) diff --git a/widget/groupwidget.cpp b/widget/groupwidget.cpp index d2af2ba4c..0c24e7183 100644 --- a/widget/groupwidget.cpp +++ b/widget/groupwidget.cpp @@ -30,16 +30,6 @@ 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), ":/img/avatar_mask.png"); avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent); @@ -58,11 +48,6 @@ GroupWidget::GroupWidget(int GroupId, QString Name) nusers.setPalette(pal); nusers.setFont(Style::getFont(Style::Medium)); - // background - QPalette pal3; - pal3.setColor(QPalette::Background, Style::getColor(Style::MediumGrey)); - this->setPalette(pal3); - Group* g = GroupList::findGroup(groupId); if (g) nusers.setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size())); @@ -82,6 +67,7 @@ GroupWidget::GroupWidget(int GroupId, QString Name) layout.addSpacing(10); layout.addWidget(&statusPic); layout.addSpacing(10); + layout.activate(); } void GroupWidget::contextMenuEvent(QContextMenuEvent * event) @@ -154,16 +140,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")); } } }