From 55975ef73f4c0e6434670f8ada49ef7a0f324ecb Mon Sep 17 00:00:00 2001 From: tanjing Date: Mon, 23 Oct 2023 17:06:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E4=BB=BB?= =?UTF-8?q?=E6=84=8F=E8=89=B2=E4=B8=BA=E9=AB=98=E4=BA=AE=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settings/org.ukui.style.gschema.xml | 2 +- .../ukui-config-style.cpp | 84 +++++++++++++------ .../qt5-config-style-ukui/ukui-config-style.h | 2 +- 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/libqt5-ukui-style/settings/org.ukui.style.gschema.xml b/libqt5-ukui-style/settings/org.ukui.style.gschema.xml index ae3b13f..1a48afa 100644 --- a/libqt5-ukui-style/settings/org.ukui.style.gschema.xml +++ b/libqt5-ukui-style/settings/org.ukui.style.gschema.xml @@ -63,7 +63,7 @@ "daybreakBlue" theme color - Set theme color for UKUI desktop environment.include default,daybreakBlue,jamPurple,magenta,sunRed,sunsetOrange,dustGold,polarGreen + Set theme color for UKUI desktop environment.include default,daybreakBlue,jamPurple,magenta,sunRed,sunsetOrange,dustGold,polarGreen, and using rgba for example "(125,125,125)" true diff --git a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp index 7b077be..aa4e5ac 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp @@ -724,7 +724,61 @@ QPalette UKUIConfigStyle::standardPalette() const if (auto settings = UKUIStyleSettings::globalInstance()) { QString themeColor = settings->get("themeColor").toString(); themeColor = settings->get("theme-color").toString(); - setThemeColor(themeColor, palette); + + QColor color = palette.color(QPalette::Active, QPalette::Highlight); + if (themeColor == "default") { + + } else if (themeColor == "daybreakBlue") { + color = QColor(55, 144, 250); + } else if (themeColor == "jamPurple") { + color = QColor(120, 115, 245); + } else if (themeColor == "magenta") { + color = QColor(235, 48, 150); + } else if (themeColor == "sunRed") { + color = QColor(243, 34, 45); + } else if (themeColor == "sunsetOrange") { + color = QColor(246, 140, 39); + } else if (themeColor == "dustGold") { + color = QColor(249, 197, 61); + } else if (themeColor == "polarGreen") { + color = QColor(82, 196, 41); + } + else if(!themeColor.isEmpty() && themeColor.startsWith("(") && themeColor.endsWith(")")){ + QColor c = color; + QString colorStr = themeColor; + colorStr = colorStr.remove(colorStr.length() - 1, 1); + colorStr = colorStr.remove(0, 1); + QStringList list = colorStr.split(","); + if (list.length() == 3 || list.length() == 4) { + c.setRed(list[0].toInt()); + c.setGreen(list[1].toInt()); + c.setBlue(list[2].toInt()); + if (list.length() == 4) { + QStringList alphaList = QString(list[3]).split("*"); + if (alphaList.length() == 2) { + if (alphaList[0].toFloat() == 255.0) + c.setAlphaF(alphaList[1].toFloat()); + else if (alphaList[1].toFloat() == 255.0) + c.setAlphaF(alphaList[0].toFloat()); + else + c.setAlphaF(alphaList[0].toFloat() * alphaList[1].toFloat() / 255.0); + + } else if (alphaList.length() == 1) { + if(alphaList[0].toFloat() <= 1.0) + c.setAlphaF(alphaList[0].toFloat()); + else + c.setAlpha(alphaList[0].toInt()); + } else + c.setAlphaF(1.0); + } + }/* else if (list.length() == 1 && list[0].startsWith("#")) { + c = list[0]; + }*/ + + color = c; + } + + setThemeColor(color, palette); sp->setUKUIThemeColor(themeColor); } @@ -823,32 +877,10 @@ QColor UKUIConfigStyle::highLight_Hover(const QStyleOption *option) const -void UKUIConfigStyle::setThemeColor(QString themeColor, QPalette &palette) const +void UKUIConfigStyle::setThemeColor(QColor color, QPalette &palette) const { - if (themeColor == "default") { - - } else if (themeColor == "daybreakBlue") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(55, 144, 250)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(55, 144, 250)); - } else if (themeColor == "jamPurple") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(120, 115, 245)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(120, 115, 245)); - } else if (themeColor == "magenta") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(235, 48, 150)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(235, 48, 150)); - } else if (themeColor == "sunRed") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(243, 34, 45)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(243, 34, 45)); - } else if (themeColor == "sunsetOrange") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(246, 140, 39)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(246, 140, 39)); - } else if (themeColor == "dustGold") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(249, 197, 61)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(249, 197, 61)); - } else if (themeColor == "polarGreen") { - palette.setColor(QPalette::Active, QPalette::Highlight, QColor(82, 196, 41)); - palette.setColor(QPalette::Inactive, QPalette::Highlight, QColor(82, 196, 41)); - } + palette.setColor(QPalette::Active, QPalette::Highlight, color); + palette.setColor(QPalette::Inactive, QPalette::Highlight, color); } void UKUIConfigStyle::updateTabletModeValue(bool isTabletMode) diff --git a/ukui-styles/qt5-config-style-ukui/ukui-config-style.h b/ukui-styles/qt5-config-style-ukui/ukui-config-style.h index dbf330b..18f4c11 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style.h +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style.h @@ -159,7 +159,7 @@ private: QColor highLight_Click(const QStyleOption *option) const; QColor highLight_Hover(const QStyleOption *option) const; - void setThemeColor(QString themeColor, QPalette &palette) const; + void setThemeColor(QColor color, QPalette &palette) const; // view QString calculateElidedText(const QString &text, const QTextOption &textOption,