1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(ui): updating friends list color at runtime

This commit is contained in:
bodwok 2020-04-09 15:53:02 +03:00
parent f6daafe914
commit d01fed92f0
No known key found for this signature in database
GPG Key ID: A279D059178DA7BA
2 changed files with 47 additions and 22 deletions

View File

@ -42,8 +42,10 @@ GenericChatroomWidget::GenericChatroomWidget(bool compact, QWidget* parent)
statusMessageLabel = new CroppingLabel(this);
statusMessageLabel->setTextFormat(Qt::PlainText);
statusMessageLabel->setForegroundRole(QPalette::WindowText);
statusMessageLabel->setObjectName("statusMessageLabelObj");
nameLabel->setForegroundRole(QPalette::WindowText);
nameLabel->setObjectName("nameLabelObj");
Settings& s = Settings::getInstance();
connect(&s, &Settings::compactLayoutChanged, this, &GenericChatroomWidget::compactChange);
@ -123,14 +125,38 @@ void GenericChatroomWidget::setActive(bool _active)
{
active = _active;
if (active) {
setBackgroundRole(QPalette::Light);
statusMessageLabel->setForegroundRole(QPalette::HighlightedText);
nameLabel->setForegroundRole(QPalette::HighlightedText);
currentColors.baseBackground = Style::getColor(Style::GroundBase); // When active
currentColors.statusLbl = Style::getColor(Style::StatusActive); // Color when active
currentColors.nameLbl = Style::getColor(Style::NameActive); // Color when active
} else {
setBackgroundRole(QPalette::Window);
statusMessageLabel->setForegroundRole(QPalette::WindowText);
nameLabel->setForegroundRole(QPalette::WindowText);
currentColors.baseBackground = Style::getColor(Style::ThemeMedium); // Base background color
currentColors.statusLbl = Style::getColor(Style::GroundExtra); // Base color
currentColors.nameLbl = Style::getColor(Style::GroundBase); // Base color
}
changeStyle();
}
void GenericChatroomWidget::changeStyle()
{
QString wgtStyle = QString("GenericChatroomWidget {"
" background-color: #%1;" // Base background color
"}"
"GenericChatroomWidget:hover {"
" background-color: #%2;" // On mouse over
"}"
"CroppingLabel#statusMessageLabelObj {"
" color: #%3;"
"}"
"CroppingLabel#nameLabelObj {"
" color: #%4;"
"}")
.arg(currentColors.baseBackground.rgba(), 0, 16)
.arg(currentColors.mouseOver.rgba(), 0, 16)
.arg(currentColors.statusLbl.rgba(), 0, 16)
.arg(currentColors.nameLbl.rgba(), 0, 16);
setStyleSheet(wgtStyle);
}
void GenericChatroomWidget::setName(const QString& name)
@ -160,23 +186,12 @@ QString GenericChatroomWidget::getTitle() const
void GenericChatroomWidget::reloadTheme()
{
QPalette p;
currentColors.baseBackground = Style::getColor(Style::ThemeMedium); // Base background color
currentColors.mouseOver = Style::getColor(Style::ThemeLight); // On mouse over
currentColors.statusLbl = Style::getColor(Style::GroundExtra); // statusMessageLabel base color
currentColors.nameLbl = Style::getColor(Style::GroundBase); // nameLabel base color
p = statusMessageLabel->palette();
p.setColor(QPalette::WindowText, Style::getColor(Style::GroundExtra)); // Base color
p.setColor(QPalette::HighlightedText, Style::getColor(Style::StatusActive)); // Color when active
statusMessageLabel->setPalette(p);
p = nameLabel->palette();
p.setColor(QPalette::WindowText, Style::getColor(Style::GroundBase)); // Base color
p.setColor(QPalette::HighlightedText, Style::getColor(Style::NameActive)); // Color when active
nameLabel->setPalette(p);
p = palette();
p.setColor(QPalette::Window, Style::getColor(Style::ThemeMedium)); // Base background color
p.setColor(QPalette::Highlight, Style::getColor(Style::ThemeLight)); // On mouse over
p.setColor(QPalette::Light, Style::getColor(Style::GroundBase)); // When active
setPalette(p);
changeStyle();
}
void GenericChatroomWidget::activate()

View File

@ -85,6 +85,16 @@ protected:
MaskablePixmapWidget* avatar;
CroppingLabel* statusMessageLabel;
bool active;
private:
void changeStyle();
struct Colors{
QColor baseBackground;
QColor mouseOver;
QColor statusLbl;
QColor nameLbl;
};
Colors currentColors;
};
#endif // GENERICCHATROOMWIDGET_H