From e146c11f0fbe52e91dda2267a54f83943768d410 Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Thu, 21 Feb 2019 15:53:31 +0200 Subject: [PATCH] feat: edit reload themes --- src/chatlog/chatline.cpp | 7 ++ src/chatlog/chatline.h | 1 + src/chatlog/chatlinecontent.cpp | 4 + src/chatlog/chatlinecontent.h | 1 + src/chatlog/chatlog.cpp | 9 ++ src/chatlog/chatlog.h | 1 + src/chatlog/chatmessage.cpp | 19 ++-- src/chatlog/content/text.cpp | 28 +++++- src/chatlog/content/text.h | 15 ++- src/widget/chatformheader.cpp | 8 ++ src/widget/chatformheader.h | 2 + src/widget/contentlayout.cpp | 13 ++- src/widget/contentlayout.h | 1 + src/widget/form/genericchatform.cpp | 27 ++++-- src/widget/form/genericchatform.h | 1 + src/widget/form/searchsettingsform.cpp | 9 +- src/widget/form/searchsettingsform.h | 1 + src/widget/searchform.cpp | 11 +++ src/widget/searchform.h | 1 + src/widget/style.cpp | 121 ++++++++++++++++--------- src/widget/style.h | 2 + src/widget/widget.cpp | 25 +++-- 22 files changed, 224 insertions(+), 83 deletions(-) diff --git a/src/chatlog/chatline.cpp b/src/chatlog/chatline.cpp index aebfa79cd..caded2169 100644 --- a/src/chatlog/chatline.cpp +++ b/src/chatlog/chatline.cpp @@ -119,6 +119,13 @@ void ChatLine::fontChanged(const QFont& font) c->fontChanged(font); } +void ChatLine::reloadTheme() +{ + for (ChatLineContent* c : content) { + c->reloadTheme(); + } +} + int ChatLine::getColumnCount() { return content.size(); diff --git a/src/chatlog/chatline.h b/src/chatlog/chatline.h index 3e32590e6..b9832d716 100644 --- a/src/chatlog/chatline.h +++ b/src/chatlog/chatline.h @@ -82,6 +82,7 @@ public: void selectionCleared(); void selectionFocusChanged(bool focusIn); void fontChanged(const QFont& font); + void reloadTheme(); int getColumnCount(); int getRow() const; diff --git a/src/chatlog/chatlinecontent.cpp b/src/chatlog/chatlinecontent.cpp index b4cd2592f..82f61d6e4 100644 --- a/src/chatlog/chatlinecontent.cpp +++ b/src/chatlog/chatlinecontent.cpp @@ -88,6 +88,10 @@ void ChatLineContent::visibilityChanged(bool) { } +void ChatLineContent::reloadTheme() +{ +} + QString ChatLineContent::getText() const { return QString(); diff --git a/src/chatlog/chatlinecontent.h b/src/chatlog/chatlinecontent.h index 39af04274..d58bbeb35 100644 --- a/src/chatlog/chatlinecontent.h +++ b/src/chatlog/chatlinecontent.h @@ -59,6 +59,7 @@ public: virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) = 0; virtual void visibilityChanged(bool visible); + virtual void reloadTheme(); private: friend class ChatLine; diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 888424a11..a4180645b 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -660,6 +660,15 @@ void ChatLog::fontChanged(const QFont& font) } } +void ChatLog::reloadTheme() +{ + setBackgroundBrush(QBrush(Style::getColor(Style::White), Qt::SolidPattern)); + + for (ChatLine::Ptr l : lines) { + l->reloadTheme(); + } +} + void ChatLog::forceRelayout() { startResizeWorker(); diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 9ac12806f..f0533ad0d 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -53,6 +53,7 @@ public: void scrollToLine(ChatLine::Ptr line); void selectAll(); void fontChanged(const QFont& font); + void reloadTheme(); QString getSelectedText() const; diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index 125c8ceec..4a4de016b 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -50,8 +50,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt QString text = rawMessage.toHtmlEscaped(); QString senderText = sender; - const QColor actionColor = Style::getColor(Style::Action); - + auto textType = Text::NORMAL; // smileys if (Settings::getInstance().getUseEmoticons()) text = SmileyPack::getInstance().smileyfied(text); @@ -72,6 +71,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt text = wrapDiv(text, "msg"); break; case ACTION: + textType = Text::ACTION; senderText = "*"; text = wrapDiv(QString("%1 %2").arg(sender.toHtmlEscaped(), text), "action"); msg->setAsAction(); @@ -88,23 +88,18 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt authorFont.setBold(true); QColor color = Style::getColor(Style::Black); - QColor authorColor; - - if (colorizeName && Settings::getInstance().getEnableGroupChatsColor()) - { + if (colorizeName && Settings::getInstance().getEnableGroupChatsColor()) { QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256); quint8 *data = (quint8*)hash.data(); - authorColor.setHsv(data[0], 255, 196); + color.setHsv(data[0], 255, 196); - if (!isMe) - { - color = authorColor; + if (!isMe && textType == Text::NORMAL) { + textType = Text::CUSTOM; } } - msg->addColumn(new Text(senderText, authorFont, true, sender, - type == ACTION ? actionColor : color), + msg->addColumn(new Text(senderText, authorFont, true, sender, textType, color), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); msg->addColumn(new Text(text, baseFont, false, ((type == ACTION) && isMe) ? QString("%1 %2").arg(sender, rawMessage) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index 0dd717156..7d2f73862 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -34,14 +34,15 @@ static const QString COLOR_HIGHLIGHT = QStringLiteral("#ff7626"); Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString& rwText, - const QColor c) + const TextType& type, const QColor& custom) : rawText(rwText) , elide(enableElide) , defFont(font) , defStyleSheet(Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), font)) - , color(c) + , textType(type) + , customColor(custom) { - QString ct = c.name(); + color = textColor(); setText(txt); setAcceptedMouseButtons(Qt::LeftButton); setAcceptHoverEvents(true); @@ -247,6 +248,15 @@ void Text::visibilityChanged(bool visible) update(); } +void Text::reloadTheme() +{ + defStyleSheet = Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), defFont); + color = textColor(); + dirty = true; + regenerate(); + update(); +} + qreal Text::getAscent() const { return ascent; @@ -458,3 +468,15 @@ void Text::selectText(QTextCursor& cursor, const std::pair& point) update(); } } + +QColor Text::textColor() const +{ + QColor c = Style::getColor(Style::Black); + if (textType == ACTION) { + c = Style::getColor(Style::Action); + } else if (textType == CUSTOM) { + c = customColor; + } + + return c; +} diff --git a/src/chatlog/content/text.h b/src/chatlog/content/text.h index aba23d4ba..b3f26533d 100644 --- a/src/chatlog/content/text.h +++ b/src/chatlog/content/text.h @@ -32,8 +32,15 @@ class Text : public ChatLineContent Q_OBJECT public: + enum TextType + { + NORMAL, + ACTION, + CUSTOM + }; + Text(const QString& txt = "", const QFont& font = QFont(), bool enableElide = false, - const QString& rawText = QString(), const QColor c = Style::getColor(Style::Black)); + const QString& rawText = QString(), const TextType& type = NORMAL, const QColor& custom = Style::getColor(Style::Black)); virtual ~Text(); void setText(const QString& txt); @@ -57,11 +64,12 @@ public: virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) final; virtual void visibilityChanged(bool keepInMemory) final; + virtual void reloadTheme() final override; virtual qreal getAscent() const final; virtual void mousePressEvent(QGraphicsSceneMouseEvent* event) final override; virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) final override; - void hoverMoveEvent(QGraphicsSceneHoverEvent* event) final override; + void hoverMoveEvent(QGraphicsSceneHoverEvent* event) final override; virtual QString getText() const final; QString getLinkAt(QPointF scenePos) const; @@ -85,6 +93,7 @@ protected: private: void selectText(QTextCursor& cursor, const std::pair& point); + QColor textColor() const; QString text; QString rawText; @@ -98,7 +107,9 @@ private: qreal ascent = 0.0; QFont defFont; QString defStyleSheet; + TextType textType; QColor color; + QColor customColor; }; #endif // TEXT_H diff --git a/src/widget/chatformheader.cpp b/src/widget/chatformheader.cpp index 82ada779d..e03e4892b 100644 --- a/src/widget/chatformheader.cpp +++ b/src/widget/chatformheader.cpp @@ -281,6 +281,14 @@ QSize ChatFormHeader::getAvatarSize() const return QSize{avatar->width(), avatar->height()}; } +void ChatFormHeader::reloadTheme() +{ + callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); + videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); + volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); + micButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); +} + void ChatFormHeader::addWidget(QWidget* widget, int stretch, Qt::Alignment alignment) { headTextLayout->addWidget(widget, stretch, alignment); diff --git a/src/widget/chatformheader.h b/src/widget/chatformheader.h index bc1b89907..7121fcda2 100644 --- a/src/widget/chatformheader.h +++ b/src/widget/chatformheader.h @@ -72,6 +72,8 @@ public: void setAvatar(const QPixmap& img); QSize getAvatarSize() const; + void reloadTheme(); + // TODO: Remove void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()); void addLayout(QLayout* layout); diff --git a/src/widget/contentlayout.cpp b/src/widget/contentlayout.cpp index 4c3a0e259..29f932449 100644 --- a/src/widget/contentlayout.cpp +++ b/src/widget/contentlayout.cpp @@ -66,6 +66,14 @@ ContentLayout::~ContentLayout() mainContent->deleteLater(); } +void ContentLayout::reloadTheme() +{ +#ifndef Q_OS_MAC + mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css")); + mainContent->setStyleSheet(Style::getStylesheet("settings/mainContent.css")); +#endif +} + void ContentLayout::clear() { QLayoutItem* item; @@ -110,10 +118,7 @@ void ContentLayout::init() mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle())); } -#ifndef Q_OS_MAC - mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css")); - mainContent->setStyleSheet(Style::getStylesheet("settings/mainContent.css")); -#endif + reloadTheme(); mainHLineLayout.addWidget(&mainHLine); mainHLineLayout.addSpacing(5); diff --git a/src/widget/contentlayout.h b/src/widget/contentlayout.h index 6ab3e4d90..cc4d93712 100644 --- a/src/widget/contentlayout.h +++ b/src/widget/contentlayout.h @@ -30,6 +30,7 @@ public: explicit ContentLayout(QWidget* parent); ~ContentLayout(); + void reloadTheme(); void clear(); QFrame mainHLine; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index a2c95f425..6591e853b 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -170,10 +170,6 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent) fileLayout->setSpacing(0); fileLayout->setMargin(0); - setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css")); - - msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css") - + fontToCss(s.getChatMessageFont(), "QTextEdit")); msgEdit->setFixedHeight(MESSAGE_EDIT_HEIGHT); msgEdit->setFrameStyle(QFrame::NoFrame); @@ -240,8 +236,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent) connect(chatWidget, &ChatLog::workerTimeoutFinished, this, &GenericChatForm::onContinueSearch); - chatWidget->setStyleSheet(Style::getStylesheet("chatArea/chatArea.css")); - headWidget->setStyleSheet(Style::getStylesheet("chatArea/chatHead.css")); + reloadTheme(); fileFlyout->setFixedSize(FILE_FLYOUT_SIZE); fileFlyout->setParent(this); @@ -295,6 +290,26 @@ QDate GenericChatForm::getFirstDate() const return getDate(chatWidget->getFirstLine()); } +void GenericChatForm::reloadTheme() +{ + const Settings& s = Settings::getInstance(); + setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css")); + + msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css") + + fontToCss(s.getChatMessageFont(), "QTextEdit")); + + chatWidget->setStyleSheet(Style::getStylesheet("chatArea/chatArea.css")); + headWidget->setStyleSheet(Style::getStylesheet("chatArea/chatHead.css")); + chatWidget->reloadTheme(); + headWidget->reloadTheme(); + searchForm->reloadTheme(); + + emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); + fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); + screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); + sendButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); +} + void GenericChatForm::setName(const QString& newName) { headWidget->setName(newName); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index ff04bb0d3..f97d365a4 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -83,6 +83,7 @@ public: static QString resolveToxPk(const ToxPk& pk); QDate getLatestDate() const; QDate getFirstDate() const; + void reloadTheme(); signals: void sendMessage(uint32_t, QString); diff --git a/src/widget/form/searchsettingsform.cpp b/src/widget/form/searchsettingsform.cpp index 4d993ad06..b55c26dde 100644 --- a/src/widget/form/searchsettingsform.cpp +++ b/src/widget/form/searchsettingsform.cpp @@ -15,9 +15,8 @@ SearchSettingsForm::SearchSettingsForm(QWidget *parent) : ui->choiceDateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); ui->choiceDateButton->setObjectName(QStringLiteral("choiceDateButton")); - ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); - ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css"))); + reloadTheme(); connect(ui->startSearchComboBox, static_cast(&QComboBox::currentIndexChanged), this, &SearchSettingsForm::onStartSearchSelected); @@ -75,6 +74,12 @@ ParameterSearch SearchSettingsForm::getParameterSearch() return ps; } +void SearchSettingsForm::reloadTheme() +{ + ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); + ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css"))); +} + void SearchSettingsForm::updateStartDateLabel() { ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat())); diff --git a/src/widget/form/searchsettingsform.h b/src/widget/form/searchsettingsform.h index bf9c15d8c..624d6a597 100644 --- a/src/widget/form/searchsettingsform.h +++ b/src/widget/form/searchsettingsform.h @@ -17,6 +17,7 @@ public: ~SearchSettingsForm(); ParameterSearch getParameterSearch(); + void reloadTheme(); private: Ui::SearchSettingsForm *ui; diff --git a/src/widget/searchform.cpp b/src/widget/searchform.cpp index 6aca3f67e..74af10d62 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -118,6 +118,17 @@ void SearchForm::insertEditor(const QString &text) searchLine->insert(text); } +void SearchForm::reloadTheme() +{ + settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); + upButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); + downButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); + hideButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); + startButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); + + settings->reloadTheme(); +} + void SearchForm::showEvent(QShowEvent* event) { QWidget::showEvent(event); diff --git a/src/widget/searchform.h b/src/widget/searchform.h index 4adc4103c..def40567a 100644 --- a/src/widget/searchform.h +++ b/src/widget/searchform.h @@ -45,6 +45,7 @@ public: ParameterSearch getParameterSearch(); void setFocusEditor(); void insertEditor(const QString &text); + void reloadTheme(); protected: virtual void showEvent(QShowEvent* event) final override; diff --git a/src/widget/style.cpp b/src/widget/style.cpp index 38f16f77c..b87621b05 100644 --- a/src/widget/style.cpp +++ b/src/widget/style.cpp @@ -65,7 +65,8 @@ namespace { const QLatin1Literal ThemeSubFolder{"themes/"}; - const QLatin1Literal BuiltinThemePath{":themes/dark/"}; + const QLatin1Literal BuiltinThemeDefaultPath{":themes/default/"}; + const QLatin1Literal BuiltinThemeDarkPath{":themes/dark/"}; } // helper functions @@ -84,12 +85,15 @@ QString qssifyFont(QFont font) static QMap palette; -static QMap dict; +static QMap dictColor; +static QMap dictFont; +static QMap dictTheme; QStringList Style::getThemeColorNames() { return {QObject::tr("Default"), QObject::tr("Blue"), QObject::tr("Olive"), QObject::tr("Red"), - QObject::tr("Violet")}; + QObject::tr("Violet"), QObject::tr("Dark"), QObject::tr("Dark blue"), QObject::tr("Dark olive"), + QObject::tr("Dark red"), QObject::tr("Dark violet")}; } QString Style::getThemeName() @@ -108,14 +112,16 @@ QString Style::getThemeFolder() // No themes available, fallback to builtin if(fullPath.isEmpty()) { - return BuiltinThemePath; + return getThemePath(); } return fullPath % QDir::separator(); } QList Style::themeColorColors = {QColor(), QColor("#004aa4"), QColor("#97ba00"), - QColor("#c23716"), QColor("#4617b5")}; + QColor("#c23716"), QColor("#4617b5"), + QColor(), QColor("#00336d"), QColor("#4d5f00"), + QColor("#7a210d"), QColor("#280d6c")}; QMap Style::aliasColors = {{Green, "green"}, {Yellow, "yellow"}, @@ -170,7 +176,7 @@ const QString Style::getImagePath(const QString& filename) } else { qWarning() << "Failed to open file (using defaults):" << fullPath; - fullPath = BuiltinThemePath % filename; + fullPath = getThemePath() % filename; if (QFileInfo::exists(fullPath)) { return fullPath; @@ -218,7 +224,7 @@ const QString Style::resolve(const QString& filename, const QFont& baseFont) } else { qWarning() << "Failed to open file (using defaults):" << fullPath; - fullPath = BuiltinThemePath; + fullPath = getThemePath(); QFile file{fullPath}; if (file.open(QFile::ReadOnly | QFile::Text)) { @@ -233,38 +239,33 @@ const QString Style::resolve(const QString& filename, const QFont& baseFont) initPalette(); } - if (dict.isEmpty()) { - dict = {// colors - {"@green", Style::getColor(Style::Green).name()}, - {"@yellow", Style::getColor(Style::Yellow).name()}, - {"@red", Style::getColor(Style::Red).name()}, - {"@black", Style::getColor(Style::Black).name()}, // NOTE: (Dark) rename to textColor - {"@darkGrey", Style::getColor(Style::DarkGrey).name()}, - {"@mediumGrey", Style::getColor(Style::MediumGrey).name()}, - {"@mediumGreyLight", Style::getColor(Style::MediumGreyLight).name()}, - {"@lightGrey", Style::getColor(Style::LightGrey).name()}, - {"@white", Style::getColor(Style::White).name()}, - {"@orange", Style::getColor(Style::Orange).name()}, - {"@themeDark", Style::getColor(Style::ThemeDark).name()}, - {"@themeMediumDark", Style::getColor(Style::ThemeMediumDark).name()}, - {"@themeMedium", Style::getColor(Style::ThemeMedium).name()}, - {"@themeLight", Style::getColor(Style::ThemeLight).name()}, - {"@action", Style::getColor(Style::Action).name()}, - - // fonts - {"@baseFont", - QString::fromUtf8("'%1' %2px").arg(baseFont.family()).arg(QFontInfo(baseFont).pixelSize())}, - {"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))}, - {"@big", qssifyFont(Style::getFont(Style::Big))}, - {"@bigBold", qssifyFont(Style::getFont(Style::BigBold))}, - {"@medium", qssifyFont(Style::getFont(Style::Medium))}, - {"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))}, - {"@small", qssifyFont(Style::getFont(Style::Small))}, - {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}}; + if (dictColor.isEmpty()) { + initDictColor(); } - for (const QString& key : dict.keys()) { - qss.replace(QRegularExpression(key % QLatin1Literal{"\\b"}), dict[key]); + if (dictFont.isEmpty()) { + dictFont = { + {"@baseFont", + QString::fromUtf8("'%1' %2px").arg(baseFont.family()).arg(QFontInfo(baseFont).pixelSize())}, + {"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))}, + {"@big", qssifyFont(Style::getFont(Style::Big))}, + {"@bigBold", qssifyFont(Style::getFont(Style::BigBold))}, + {"@medium", qssifyFont(Style::getFont(Style::Medium))}, + {"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))}, + {"@small", qssifyFont(Style::getFont(Style::Small))}, + {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}}; + } + + for (const QString& key : dictColor.keys()) { + qss.replace(QRegularExpression(key % QLatin1Literal{"\\b"}), dictColor[key]); + } + + for (const QString& key : dictFont.keys()) { + qss.replace(QRegularExpression(key % QLatin1Literal{"\\b"}), dictFont[key]); + } + + for (const QString& key : dictTheme.keys()) { + qss.replace(QRegularExpression(key % QLatin1Literal{"\\b"}), dictTheme[key]); } // @getImagePath() function @@ -286,7 +287,7 @@ const QString Style::resolve(const QString& filename, const QFont& baseFont) existingImagesCache << fullImagePath; } else { qWarning() << "Failed to open file (using defaults):" << fullImagePath; - fullImagePath = BuiltinThemePath % path; + fullImagePath = getThemePath() % path; } } @@ -313,6 +314,10 @@ void Style::repolish(QWidget* w) void Style::setThemeColor(int color) { stylesheetsCache.clear(); // clear stylesheet cache which includes color info + palette.clear(); + dictColor.clear(); + initPalette(); + initDictColor(); if (color < 0 || color >= themeColorColors.size()) setThemeColor(QColor()); else @@ -340,10 +345,10 @@ void Style::setThemeColor(const QColor& color) palette[ThemeLight] = color.lighter(110); } - dict["@themeDark"] = getColor(ThemeDark).name(); - dict["@themeMediumDark"] = getColor(ThemeMediumDark).name(); - dict["@themeMedium"] = getColor(ThemeMedium).name(); - dict["@themeLight"] = getColor(ThemeLight).name(); + dictTheme["@themeDark"] = getColor(ThemeDark).name(); + dictTheme["@themeMediumDark"] = getColor(ThemeMediumDark).name(); + dictTheme["@themeMedium"] = getColor(ThemeMedium).name(); + dictTheme["@themeLight"] = getColor(ThemeLight).name(); } /** @@ -366,16 +371,42 @@ QPixmap Style::scaleSvgImage(const QString& path, uint32_t width, uint32_t heigh void Style::initPalette() { - QSettings settings(BuiltinThemePath % "palette.ini", QSettings::IniFormat); + QSettings settings(getThemePath() % "palette.ini", QSettings::IniFormat); auto keys = aliasColors.keys(); settings.beginGroup("colors"); - + QMap c; for (auto k : keys) { + c[k] = settings.value(aliasColors[k], "#000").toString(); palette[k] = QColor(settings.value(aliasColors[k], "#000").toString()); } - + auto p = palette; settings.endGroup(); } + +void Style::initDictColor() +{ + dictColor = { + {"@green", Style::getColor(Style::Green).name()}, + {"@yellow", Style::getColor(Style::Yellow).name()}, + {"@red", Style::getColor(Style::Red).name()}, + {"@black", Style::getColor(Style::Black).name()}, // NOTE: (Dark) rename to textColor + {"@darkGrey", Style::getColor(Style::DarkGrey).name()}, + {"@mediumGrey", Style::getColor(Style::MediumGrey).name()}, + {"@mediumGreyLight", Style::getColor(Style::MediumGreyLight).name()}, + {"@lightGrey", Style::getColor(Style::LightGrey).name()}, + {"@white", Style::getColor(Style::White).name()}, + {"@orange", Style::getColor(Style::Orange).name()}, + {"@action", Style::getColor(Style::Action).name()}}; +} + +QString Style::getThemePath() +{ + if (Settings::getInstance().getThemeColor() > 4) { + return BuiltinThemeDarkPath; + } + + return BuiltinThemeDefaultPath; +} diff --git a/src/widget/style.h b/src/widget/style.h index 23da6d27e..883de2564 100644 --- a/src/widget/style.h +++ b/src/widget/style.h @@ -73,6 +73,8 @@ public: static void applyTheme(); static QPixmap scaleSvgImage(const QString& path, uint32_t width, uint32_t height); static void initPalette(); + static void initDictColor(); + static QString getThemePath(); signals: void themeChanged(); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 96cc99e89..dc2c68a5e 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -150,14 +150,11 @@ void Widget::init() connect(actionQuit, &QAction::triggered, qApp, &QApplication::quit); layout()->setContentsMargins(0, 0, 0, 0); - ui->centralwidget->setStyleSheet(Style::getStylesheet(QStringLiteral("centralWidget/centralWidget.css"))); - ui->friendList->setStyleSheet(Style::getStylesheet("friendList/friendList.css")); profilePicture = new MaskablePixmapWidget(this, QSize(40, 40), ":/img/avatar_mask.svg"); profilePicture->setPixmap(QPixmap(":/img/contact_dark.svg")); profilePicture->setClickable(true); profilePicture->setObjectName("selfAvatar"); - profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css")); ui->myProfile->insertWidget(0, profilePicture); ui->myProfile->insertSpacing(1, 7); @@ -200,10 +197,6 @@ void Widget::init() ui->searchContactFilterBox->setMenu(filterMenu); -#ifndef Q_OS_MAC - ui->statusHead->setStyleSheet(Style::getStylesheet("window/statusPanel.css")); -#endif - contactListWidget = new FriendListWidget(this, settings.getGroupchatPosition()); ui->friendList->setWidget(contactListWidget); ui->friendList->setLayoutDirection(Qt::RightToLeft); @@ -211,8 +204,6 @@ void Widget::init() ui->statusLabel->setEditable(true); - ui->statusPanel->setStyleSheet(Style::getStylesheet("window/statusPanel.css")); - QMenu* statusButtonMenu = new QMenu(ui->statusButton); statusButtonMenu->addAction(statusOnline); statusButtonMenu->addAction(statusAway); @@ -2176,6 +2167,7 @@ void Widget::reloadTheme() { this->setStyleSheet(Style::getStylesheet("window/general.css")); QString statusPanelStyle = Style::getStylesheet("window/statusPanel.css"); + ui->centralwidget->setStyleSheet(Style::getStylesheet(QStringLiteral("centralWidget/centralWidget.css"))); ui->tooliconsZone->setStyleSheet(Style::getStylesheet("tooliconsZone/tooliconsZone.css")); ui->statusPanel->setStyleSheet(statusPanelStyle); ui->statusHead->setStyleSheet(statusPanelStyle); @@ -2183,6 +2175,12 @@ void Widget::reloadTheme() ui->statusButton->setStyleSheet(Style::getStylesheet("statusButton/statusButton.css")); contactListWidget->reDraw(); + profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css")); + + if (contentLayout != nullptr) { + contentLayout->reloadTheme(); + } + for (Friend* f : FriendList::getAllFriends()) { uint32_t friendId = f->getId(); friendWidgets[friendId]->reloadTheme(); @@ -2192,6 +2190,15 @@ void Widget::reloadTheme() uint32_t groupId = g->getId(); groupWidgets[groupId]->reloadTheme(); } + + + for (auto f : FriendList::getAllFriends()) { + chatForms[f->getId()]->reloadTheme(); + } + + for (auto g : GroupList::getAllGroups()) { + groupChatForms[g->getId()]->reloadTheme(); + } } void Widget::nextContact()