tabbar 配置化颜色提取

This commit is contained in:
tanjing 2024-01-15 10:54:27 +08:00
parent 606e0e5919
commit c999303b11
6 changed files with 54 additions and 55 deletions

View File

@ -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"}

View File

@ -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"}

View File

@ -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<QWidget *>(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<int>()) {
@ -3600,12 +3575,18 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const
if (widget->property("setTabBarSelectBrush").isValid() && widget->property("setTabBarSelectBrush").canConvert<QBrush>()) {
tabBarSelectBrush = widget->property("setTabBarSelectBrush").value<QBrush>();
}
if (widget->property("setTabBarPen").isValid() && widget->property("setTabBarPen").canConvert<QBrush>()) {
tabBarPen = widget->property("setTabBarPen").value<QPen>();
if (widget->property("setTabBarDefaultPen").isValid() && widget->property("setTabBarDefaultPen").canConvert<QPen>()) {
tabBarDefaultPen = widget->property("setTabBarDefaultPen").value<QPen>();
}
if (widget->property("setTabBarFocusPen").isValid() && widget->property("setTabBarFocusPen").canConvert<QBrush>()) {
if (widget->property("setTabBarFocusPen").isValid() && widget->property("setTabBarFocusPen").canConvert<QPen>()) {
tabBarFocusPen = widget->property("setTabBarFocusPen").value<QPen>();
}
if (widget->property("setTabBarClickPen").isValid() && widget->property("setTabBarClickPen").canConvert<QPen>()) {
tabBarFocusPen = widget->property("setTabBarClickPen").value<QPen>();
}
if (widget->property("setTabBarHoverPen").isValid() && widget->property("setTabBarHoverPen").canConvert<QPen>()) {
tabBarFocusPen = widget->property("setTabBarHoverPen").value<QPen>();
}
}
m_TabWidgetParameters.radius = tabradius;
@ -3615,7 +3596,9 @@ void UKUIConfigStyleParameters::initConfigTabWidgetParameters(bool isDark, const
m_TabWidgetParameters.tabBarHoverBrush = tabBarHoverBrush;
m_TabWidgetParameters.tabBarClickBrush = tabBarClickBrush;
m_TabWidgetParameters.tabBarSelectBrush = tabBarSelectBrush;
m_TabWidgetParameters.tabBarPen = tabBarPen;
m_TabWidgetParameters.tabBarDefaultPen = tabBarDefaultPen;
m_TabWidgetParameters.tabBarHoverPen = tabBarHoverPen;
m_TabWidgetParameters.tabBarClickPen = tabBarClickPen;
m_TabWidgetParameters.tabBarFocusPen = tabBarFocusPen;
}

View File

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

View File

@ -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;
};
}

View File

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