From c999303b11d83e52680d9e32c8d7597ff33aa1b7 Mon Sep 17 00:00:00 2001 From: tanjing Date: Mon, 15 Jan 2024 10:54:27 +0800 Subject: [PATCH] =?UTF-8?q?tabbar=20=E9=85=8D=E7=BD=AE=E5=8C=96=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../themeconfig/default.json | 4 +- .../themeconfig/fashion.json | 4 +- .../ukui-config-style-parameters.cpp | 75 +++++++------------ .../ukui-config-style.cpp | 21 +++++- .../config-tabwidget-parameters.h | 4 +- ukui-styles/themeinformation.h | 1 + 6 files changed, 54 insertions(+), 55 deletions(-) diff --git a/ukui-styles/qt5-config-style-ukui/themeconfig/default.json b/ukui-styles/qt5-config-style-ukui/themeconfig/default.json index ef383e4..b34f25c 100644 --- a/ukui-styles/qt5-config-style-ukui/themeconfig/default.json +++ b/ukui-styles/qt5-config-style-ukui/themeconfig/default.json @@ -449,7 +449,7 @@ "WidgetBackgroundBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarBackgroundBrush" : {"value": "Window_at", "type": "paletterole"}, "TabBarDefaultBrush" : {"value": "Window_at", "type": "paletterole"}, - "TabBarHoverBrush" : { "type": "color"}, + "TabBarHoverBrush" : {"value": "0, 0, 0, 0.05", "type": "color"}, "TabBarSelectBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarClickBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarFocusPen" : {"value": "HighLight_at", "type": "paletterole"} @@ -908,7 +908,7 @@ "WidgetBackgroundBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarBackgroundBrush" : {"value": "Window_at", "type": "paletterole"}, "TabBarDefaultBrush" : {"value": "Window_at", "type": "paletterole"}, - "TabBarHoverBrush" : { "type": "color"}, + "TabBarHoverBrush" : {"value": "255, 255, 255, 0.15","type": "color"}, "TabBarSelectBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarClickBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarFocusPen" : {"value": "HighLight_at", "type": "paletterole"} diff --git a/ukui-styles/qt5-config-style-ukui/themeconfig/fashion.json b/ukui-styles/qt5-config-style-ukui/themeconfig/fashion.json index 7bb4d9a..e6ee89f 100644 --- a/ukui-styles/qt5-config-style-ukui/themeconfig/fashion.json +++ b/ukui-styles/qt5-config-style-ukui/themeconfig/fashion.json @@ -447,7 +447,7 @@ "WidgetBackgroundBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarBackgroundBrush" : {"value": "Window_at", "type": "paletterole"}, "TabBarDefaultBrush" : {"value": "Window_at", "type": "paletterole"}, - "TabBarHoverBrush" : { "type": "gradient"}, + "TabBarHoverBrush" : {"value": "238, 238, 238 ~ 232, 232, 232","type": "gradient"}, "TabBarSelectBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarClickBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarFocusPen" : {"value": "HighLight_at", "type": "paletterole"} @@ -904,7 +904,7 @@ "WidgetBackgroundBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarBackgroundBrush" : {"value": "Window_at", "type": "paletterole"}, "TabBarDefaultBrush" : {"value": "Window_at", "type": "paletterole"}, - "TabBarHoverBrush" : { "type": "gradient"}, + "TabBarHoverBrush" : {"value": "50, 51, 52 ~ 43, 44, 45", "type": "gradient"}, "TabBarSelectBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarClickBrush" : {"value": "Base_at", "type": "paletterole"}, "TabBarFocusPen" : {"value": "HighLight_at", "type": "paletterole"} diff --git a/ukui-styles/qt5-config-style-ukui/ukui-config-style-parameters.cpp b/ukui-styles/qt5-config-style-ukui/ukui-config-style-parameters.cpp index 5303ac3..6852cd4 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style-parameters.cpp +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style-parameters.cpp @@ -591,14 +591,6 @@ void UKUIConfigStyleParameters::normalButtonColor(bool isDark, QPalette p, QPen QPen &hoverPen, QBrush &hoverBrush, QPen &clickPen, QBrush &clickBrush, QPen &disablePen, QBrush &disableBrush) { - //default - if (isDark) { - defaultPen = QPen(QBrush(adjustColor(defaultBrush.color(), 0, 0, 8)), - 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - } else - defaultPen = QPen(QBrush(adjustColor(defaultBrush.color(), 0, 0, -25)), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - - //hover if (isDark) { //hightlight->210,72%,71% 210,67%,56% @@ -623,13 +615,6 @@ void UKUIConfigStyleParameters::normalButtonColor(bool isDark, QPalette p, QPen 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } clickBrush = QBrush(highlightClick(isDark, p)); - - //disable - if (isDark) { - disablePen = QPen(QBrush(adjustL(disableBrush.color(), 18)), - 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - } - } @@ -3494,36 +3479,24 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const QBrush tabBarHoverBrush = tabWidgetColorCfg.tabBarHoverBrush; QBrush tabBarSelectBrush = tabWidgetColorCfg.tabBarSelectBrush; QBrush tabBarClickBrush = tabWidgetColorCfg.tabBarClickBrush; -// QPen tabBarHoverPen = QPen(tabWidgetColorCfg.tabBarHoverPen, (tabWidgetColorCfg.tabBarHoverPen == Qt::NoPen || tabWidgetColorCfg.tabBarHoverPen.alpha() == 0) ? 0 : 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); -// QPen tabBarClickPen = QPen(tabWidgetColorCfg.tabBarClickPen, (tabWidgetColorCfg.tabBarClickPen == Qt::NoPen || tabWidgetColorCfg.tabBarClickPen.alpha() == 0) ? 0 : 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - QPen tabBarPen = QPen(QColor(Qt::NoPen), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + QPen tabBarHoverPen = QPen(tabWidgetColorCfg.tabBarHoverPen, (tabWidgetColorCfg.tabBarHoverPen == Qt::NoPen || tabWidgetColorCfg.tabBarHoverPen.alpha() == 0) ? 0 : 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + QPen tabBarClickPen = QPen(tabWidgetColorCfg.tabBarClickPen, (tabWidgetColorCfg.tabBarClickPen == Qt::NoPen || tabWidgetColorCfg.tabBarClickPen.alpha() == 0) ? 0 : 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + QPen tabBarDefaultPen = QPen(tabWidgetColorCfg.tabBarDefaultPen, (tabWidgetColorCfg.tabBarDefaultPen == Qt::NoPen || tabWidgetColorCfg.tabBarDefaultPen.alpha() == 0) ? 0 : 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QPen tabBarFocusPen = QPen(tabWidgetColorCfg.tabBarFocusPen , (tabWidgetColorCfg.tabBarFocusPen.alpha() == 0 || tabWidgetColorCfg.tabBarFocusPen == Qt::NoPen) ? 0 : 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); switch (m_adjustColorRules) { case AdjustColorRules::DefaultRGB: - if (tabWidgetColorCfg.tabBarHoverType == Obj_Color_Type) { + if (tabWidgetColorCfg.tabBarHoverType == Obj_Gradient_Type) { //tabbar hover - QColor hover_color = option->palette.color(QPalette::Active, QPalette::Window); - QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText); - tabBarHoverBrush = QBrush(configMixColor(hover_color, mix, 0.1)); - } else if (tabWidgetColorCfg.tabBarHoverType == Obj_Gradient_Type) { - //tabbar hover - QColor hover_color = option->palette.color(QPalette::Active, QPalette::Window); - QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText); QColor startColor; QColor endColor; QLinearGradient linearGradient; linearGradient.setStart(option->rect.topLeft()); linearGradient.setFinalStop(option->rect.bottomLeft()); - if (isDark) { - startColor = configMixColor(hover_color, mix, 0.1); - endColor = configMixColor(hover_color, mix, 0.05); - } else { - startColor = configMixColor(hover_color, mix, 0.05); - endColor = configMixColor(hover_color, mix, 0.1); - } + startColor = tabWidgetColorCfg.tabBarHoverGradientList.value(0); + endColor = tabWidgetColorCfg.tabBarHoverGradientList.value(1); linearGradient.setColorAt(0, startColor); linearGradient.setColorAt(1, endColor); tabBarHoverBrush = QBrush(linearGradient); @@ -3538,10 +3511,10 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const tabBarHoverBrush = highlightHover(isDark, option->palette); tabBarClickBrush = highlightClick(isDark, option->palette); if (click) { - tabBarPen = QPen(QBrush(option->palette.color(QPalette::Active, QPalette::Highlight)), + tabBarClickPen = QPen(QBrush(option->palette.color(QPalette::Active, QPalette::Highlight)), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } else if(hover && !selected) { - tabBarPen = QPen(QBrush(adjustColor(option->palette.color(QPalette::Active, QPalette::Highlight), 0, -5, -15)), + tabBarHoverPen = QPen(QBrush(adjustColor(option->palette.color(QPalette::Active, QPalette::Highlight), 0, -5, -15)), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } } else { @@ -3549,11 +3522,11 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const tabBarClickBrush = highlightClick(isDark, option->palette); if(click){ - tabBarPen = QPen(QBrush(adjustColor(option->palette.color(QPalette::Active, QPalette::Highlight), 1, -21, 3)), + tabBarClickPen = QPen(QBrush(adjustColor(option->palette.color(QPalette::Active, QPalette::Highlight), 1, -21, 3)), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } else if(hover && !selected){ - tabBarPen = QPen(QBrush(adjustColor(option->palette.color(QPalette::Active, QPalette::Highlight), 4, -14, 15)), + tabBarHoverPen = QPen(QBrush(adjustColor(option->palette.color(QPalette::Active, QPalette::Highlight), 4, -14, 15)), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } } @@ -3562,9 +3535,9 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const break; } - if((option->state & QStyle::State_HasFocus) && (option->state & QStyle::State_Enabled)){ - tabBarPen = tabBarFocusPen; - } +// if((option->state & QStyle::State_HasFocus) && (option->state & QStyle::State_Enabled)){ +// tabBarPen = tabBarFocusPen; +// } auto *w = const_cast(widget); if (w) { @@ -3575,8 +3548,10 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const w->setProperty("tabBarHoverBrush", tabBarHoverBrush); w->setProperty("tabBarClickBrush", tabBarClickBrush); w->setProperty("tabBarSelectBrush", tabBarSelectBrush); - w->setProperty("tabBarPen", tabBarPen); + w->setProperty("tabBarDefaultPen", tabBarDefaultPen); w->setProperty("tabBarFocusPen", tabBarFocusPen); + w->setProperty("tabBarClickPen", tabBarClickPen); + w->setProperty("tabBarHoverPen", tabBarHoverPen); } if (widget) { if (widget->property("setRadius").isValid() && widget->property("setRadius").canConvert()) { @@ -3600,12 +3575,18 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const if (widget->property("setTabBarSelectBrush").isValid() && widget->property("setTabBarSelectBrush").canConvert()) { tabBarSelectBrush = widget->property("setTabBarSelectBrush").value(); } - if (widget->property("setTabBarPen").isValid() && widget->property("setTabBarPen").canConvert()) { - tabBarPen = widget->property("setTabBarPen").value(); + if (widget->property("setTabBarDefaultPen").isValid() && widget->property("setTabBarDefaultPen").canConvert()) { + tabBarDefaultPen = widget->property("setTabBarDefaultPen").value(); } - if (widget->property("setTabBarFocusPen").isValid() && widget->property("setTabBarFocusPen").canConvert()) { + if (widget->property("setTabBarFocusPen").isValid() && widget->property("setTabBarFocusPen").canConvert()) { tabBarFocusPen = widget->property("setTabBarFocusPen").value(); } + if (widget->property("setTabBarClickPen").isValid() && widget->property("setTabBarClickPen").canConvert()) { + tabBarFocusPen = widget->property("setTabBarClickPen").value(); + } + if (widget->property("setTabBarHoverPen").isValid() && widget->property("setTabBarHoverPen").canConvert()) { + tabBarFocusPen = widget->property("setTabBarHoverPen").value(); + } } m_TabWidgetParameters.radius = tabradius; @@ -3615,8 +3596,10 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const m_TabWidgetParameters.tabBarHoverBrush = tabBarHoverBrush; m_TabWidgetParameters.tabBarClickBrush = tabBarClickBrush; m_TabWidgetParameters.tabBarSelectBrush = tabBarSelectBrush; - m_TabWidgetParameters.tabBarPen = tabBarPen; - m_TabWidgetParameters.tabBarFocusPen = tabBarFocusPen; + m_TabWidgetParameters.tabBarDefaultPen = tabBarDefaultPen; + m_TabWidgetParameters.tabBarHoverPen = tabBarHoverPen; + m_TabWidgetParameters.tabBarClickPen = tabBarClickPen; + m_TabWidgetParameters.tabBarFocusPen = tabBarFocusPen; } void UKUIConfigStyleParameters::initConfigMenuParameters(bool isDark, const QStyleOption *option, const QWidget *widget) 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 5e56249..431cbd2 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp @@ -5141,8 +5141,11 @@ void UKUIConfigStyle::drawControl(QStyle::ControlElement element, const QStyleOp path.addRect(drawRect); } - int penWidth = sp->m_TabWidgetParameters.tabBarPen.width(); + int penWidth = (sp->m_TabWidgetParameters.tabBarDefaultPen == Qt::NoPen || + sp->m_TabWidgetParameters.tabBarDefaultPen.color().alpha() == 0) ? + 0 : sp->m_TabWidgetParameters.tabBarDefaultPen.width(); int radius = sp->m_TabWidgetParameters.radius; + QPen pen = Qt::NoPen; // drawRect.adjust(0, 0, -1 * penWidth, 0); // penPath.moveTo(drawRect.left(), drawRect.bottom() - penWidth - radius); // penPath.lineTo(drawRect.left(), drawRect.top()); @@ -5151,23 +5154,33 @@ void UKUIConfigStyle::drawControl(QStyle::ControlElement element, const QStyleOp // penPath.lineTo(drawRect.left(), drawRect.bottom() - penWidth); if(click) { + penWidth = sp->m_TabWidgetParameters.tabBarClickPen.width(); painter->setBrush(sp->m_TabWidgetParameters.tabBarClickBrush); + pen = sp->m_TabWidgetParameters.tabBarClickPen; } else if (selected) { painter->setBrush(sp->m_TabWidgetParameters.tabBarSelectBrush); } else if (hover) { + penWidth = sp->m_TabWidgetParameters.tabBarHoverPen.width(); painter->setBrush(sp->m_TabWidgetParameters.tabBarHoverBrush); + pen = sp->m_TabWidgetParameters.tabBarHoverPen; } else{ + penWidth = sp->m_TabWidgetParameters.tabBarDefaultPen.width(); painter->setBrush(sp->m_TabWidgetParameters.tabBarDefaultBrush); + pen = sp->m_TabWidgetParameters.tabBarDefaultPen; + } + if((tab->state & State_Enabled) && (tab->state & State_HasFocus)){ + penWidth = sp->m_TabWidgetParameters.tabBarFocusPen.width(); + pen = sp->m_TabWidgetParameters.tabBarFocusPen; } painter->drawPath(path); painter->restore(); painter->save(); - painter->setPen(penWidth > 0 ? sp->m_TabWidgetParameters.tabBarPen : Qt::NoPen); + painter->setPen(penWidth > 0 ? pen : Qt::NoPen); painter->setBrush(Qt::NoBrush); painter->setRenderHint(QPainter::Antialiasing, true); - if(painter->pen().width() == 1) - painter->translate(0.5, 0.5); +// if(painter->pen().width() == 1) +// painter->translate(0.5, 0.5); painter->drawRoundedRect(drawRect.adjusted(penWidth/2, penWidth/2, -1 * penWidth/2, -1 * penWidth), radius, radius); painter->restore(); diff --git a/ukui-styles/qt5-config-style-ukui/widget-parameters/config-tabwidget-parameters.h b/ukui-styles/qt5-config-style-ukui/widget-parameters/config-tabwidget-parameters.h index 0644eda..eb85537 100644 --- a/ukui-styles/qt5-config-style-ukui/widget-parameters/config-tabwidget-parameters.h +++ b/ukui-styles/qt5-config-style-ukui/widget-parameters/config-tabwidget-parameters.h @@ -42,8 +42,10 @@ public: QBrush tabBarHoverBrush; QBrush tabBarClickBrush; QBrush tabBarSelectBrush; - QPen tabBarPen = Qt::NoPen; + QPen tabBarDefaultPen = Qt::NoPen; QPen tabBarFocusPen = Qt::NoPen; + QPen tabBarClickPen = Qt::NoPen; + QPen tabBarHoverPen = Qt::NoPen; }; } diff --git a/ukui-styles/themeinformation.h b/ukui-styles/themeinformation.h index 993f9cf..155dafa 100644 --- a/ukui-styles/themeinformation.h +++ b/ukui-styles/themeinformation.h @@ -807,6 +807,7 @@ typedef struct TabWidgetColorStruct QColor tabBarHoverBrush = QColor(232, 232, 232); QColor tabBarSelectBrush = QColor(255, 255, 255); QColor tabBarClickBrush = QColor(255, 255, 255); + QColor tabBarDefaultPen = QColor(0, 0, 0, 0); QColor tabBarHoverPen = QColor(0, 0, 0, 0); QColor tabBarClickPen = QColor(0, 0, 0, 0); QColor tabBarFocusPen = QColor(55, 144, 250);