支持设置任意色为高亮色

This commit is contained in:
tanjing 2023-10-23 17:06:18 +08:00 committed by xibowen
parent 9346a089f0
commit 55975ef73f
3 changed files with 60 additions and 28 deletions

View File

@ -63,7 +63,7 @@
<key type="s" name="theme-color">
<default>"daybreakBlue"</default>
<summary> theme color</summary>
<description>Set theme color for UKUI desktop environment.include default,daybreakBlue,jamPurple,magenta,sunRed,sunsetOrange,dustGold,polarGreen</description>
<description>Set theme color for UKUI desktop environment.include default,daybreakBlue,jamPurple,magenta,sunRed,sunsetOrange,dustGold,polarGreen, and using rgba for example "(125,125,125)" </description>
</key>
<key type="b" name="cursor-blink">
<default>true</default>

View File

@ -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)

View File

@ -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,