qt5-ukui-platformtheme/ukui-styles/qt5-style-ukui/kabstract-style-parameters.cpp

3954 lines
157 KiB
C++

/*
* Qt5-UKUI's Library
*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <https://www.gnu.org/licenses/>.
*
* Authors: xibowen <xibowen@kylinos.cn>
*
*/
#include <QPushButton>
#include <QToolButton>
#include <QApplication>
#include <QPainter>
#include <KWindowEffects>
#include <QPainterPath>
#include <QDebug>
#include <QObject>
#include <QGSettings>
#include <QDBusMessage>
#include <QDBusArgument>
#include <QDBusConnection>
#include "ukui-style-settings.h"
#include "kabstract-style-parameters.h"
#include "black-list.h"
extern QColor mixColor(const QColor &c1, const QColor &c2, qreal bias);
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
KAbstractStyleParameters::KAbstractStyleParameters(QObject *parent, bool isDark)
{
QDBusMessage message = QDBusMessage::createMethodCall("com.kylin.statusmanager.interface",
"/",
"com.kylin.statusmanager.interface",
"get_current_tabletmode");
QDBusMessage ret = QDBusConnection::sessionBus().call(message);
if (ret.type() != QDBusMessage::ReplyMessage)
{
//从返回参数获取返回值
qDebug() << "complex type failed!";
}
else
{
m_isTableMode = ret.arguments()[0].value<bool>();
}
updateParameters(m_isTableMode);
auto settings = UKUIStyleSettings::globalInstance();
auto styleName = settings->get("styleName").toString();
}
QPalette KAbstractStyleParameters::setPalette(QPalette &palette)
{
palette.setColor(QPalette::Active, QPalette::WindowText, defaultPalette.color(QPalette::Active, QPalette::WindowText));
palette.setColor(QPalette::Inactive, QPalette::WindowText, defaultPalette.color(QPalette::Inactive, QPalette::WindowText));
palette.setColor(QPalette::Disabled, QPalette::WindowText, defaultPalette.color(QPalette::Disabled, QPalette::WindowText));
palette.setColor(QPalette::Active, QPalette::Button, defaultPalette.color(QPalette::Active, QPalette::Button));
palette.setColor(QPalette::Inactive, QPalette::Button, defaultPalette.color(QPalette::Inactive, QPalette::Button));
palette.setColor(QPalette::Disabled, QPalette::Button, defaultPalette.color(QPalette::Disabled, QPalette::Button));
palette.setColor(QPalette::Active, QPalette::Light, defaultPalette.color(QPalette::Active, QPalette::Light));
palette.setColor(QPalette::Inactive, QPalette::Light, defaultPalette.color(QPalette::Inactive, QPalette::Light));
palette.setColor(QPalette::Disabled, QPalette::Light, defaultPalette.color(QPalette::Disabled, QPalette::Light));
palette.setColor(QPalette::Active, QPalette::Midlight, defaultPalette.color(QPalette::Active, QPalette::Midlight));
palette.setColor(QPalette::Inactive, QPalette::Midlight, defaultPalette.color(QPalette::Inactive, QPalette::Midlight));
palette.setColor(QPalette::Disabled, QPalette::Midlight, defaultPalette.color(QPalette::Disabled, QPalette::Midlight));
palette.setColor(QPalette::Active, QPalette::Dark, defaultPalette.color(QPalette::Active, QPalette::Dark));
palette.setColor(QPalette::Inactive, QPalette::Dark, defaultPalette.color(QPalette::Inactive, QPalette::Dark));
palette.setColor(QPalette::Disabled, QPalette::Dark, defaultPalette.color(QPalette::Disabled, QPalette::Dark));
palette.setColor(QPalette::Active, QPalette::Mid, defaultPalette.color(QPalette::Active, QPalette::Mid));
palette.setColor(QPalette::Inactive, QPalette::Mid, defaultPalette.color(QPalette::Inactive, QPalette::Mid));
palette.setColor(QPalette::Disabled, QPalette::Mid, defaultPalette.color(QPalette::Disabled, QPalette::Mid));
palette.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Active, QPalette::Text));
palette.setColor(QPalette::Inactive, QPalette::Text, defaultPalette.color(QPalette::Inactive, QPalette::Text));
palette.setColor(QPalette::Disabled, QPalette::Text, defaultPalette.color(QPalette::Disabled, QPalette::Text));
palette.setColor(QPalette::Active, QPalette::BrightText, defaultPalette.color(QPalette::Active, QPalette::BrightText));
palette.setColor(QPalette::Inactive, QPalette::BrightText, defaultPalette.color(QPalette::Inactive, QPalette::BrightText));
palette.setColor(QPalette::Disabled, QPalette::BrightText, defaultPalette.color(QPalette::Disabled, QPalette::BrightText));
palette.setColor(QPalette::Active, QPalette::ButtonText, defaultPalette.color(QPalette::Active, QPalette::ButtonText));
palette.setColor(QPalette::Inactive, QPalette::ButtonText, defaultPalette.color(QPalette::Inactive, QPalette::ButtonText));
palette.setColor(QPalette::Disabled, QPalette::ButtonText, defaultPalette.color(QPalette::Disabled, QPalette::ButtonText));
palette.setColor(QPalette::Active, QPalette::Base, defaultPalette.color(QPalette::Active, QPalette::Base));
palette.setColor(QPalette::Inactive, QPalette::Base, defaultPalette.color(QPalette::Inactive, QPalette::Base));
palette.setColor(QPalette::Disabled, QPalette::Base, defaultPalette.color(QPalette::Disabled, QPalette::Base));
palette.setColor(QPalette::Active, QPalette::Window, defaultPalette.color(QPalette::Active, QPalette::Window));
palette.setColor(QPalette::Inactive, QPalette::Window, defaultPalette.color(QPalette::Inactive, QPalette::Window));
palette.setColor(QPalette::Disabled, QPalette::Window, defaultPalette.color(QPalette::Disabled, QPalette::Window));
palette.setColor(QPalette::Active, QPalette::Shadow, defaultPalette.color(QPalette::Active, QPalette::Shadow));
palette.setColor(QPalette::Inactive, QPalette::Shadow, defaultPalette.color(QPalette::Inactive, QPalette::Shadow));
palette.setColor(QPalette::Disabled, QPalette::Shadow, defaultPalette.color(QPalette::Disabled, QPalette::Shadow));
palette.setColor(QPalette::Active, QPalette::Highlight, defaultPalette.color(QPalette::Active, QPalette::Highlight));
palette.setColor(QPalette::Inactive, QPalette::Highlight, defaultPalette.color(QPalette::Inactive, QPalette::Highlight));
palette.setColor(QPalette::Disabled, QPalette::Highlight, defaultPalette.color(QPalette::Disabled, QPalette::Highlight));
palette.setColor(QPalette::Active, QPalette::HighlightedText, defaultPalette.color(QPalette::Active, QPalette::HighlightedText));
palette.setColor(QPalette::Inactive, QPalette::HighlightedText, defaultPalette.color(QPalette::Inactive, QPalette::HighlightedText));
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, defaultPalette.color(QPalette::Disabled, QPalette::HighlightedText));
palette.setColor(QPalette::Active, QPalette::Link, defaultPalette.color(QPalette::Active, QPalette::Link));
palette.setColor(QPalette::Inactive, QPalette::Link, defaultPalette.color(QPalette::Inactive, QPalette::Link));
palette.setColor(QPalette::Disabled, QPalette::Link, defaultPalette.color(QPalette::Disabled, QPalette::Link));
palette.setColor(QPalette::Active, QPalette::LinkVisited, defaultPalette.color(QPalette::Active, QPalette::LinkVisited));
palette.setColor(QPalette::Inactive, QPalette::LinkVisited, defaultPalette.color(QPalette::Inactive, QPalette::LinkVisited));
palette.setColor(QPalette::Disabled, QPalette::LinkVisited, defaultPalette.color(QPalette::Disabled, QPalette::LinkVisited));
palette.setColor(QPalette::Active, QPalette::AlternateBase, defaultPalette.color(QPalette::Active, QPalette::AlternateBase));
palette.setColor(QPalette::Inactive, QPalette::AlternateBase, defaultPalette.color(QPalette::Inactive, QPalette::AlternateBase));
palette.setColor(QPalette::Disabled, QPalette::AlternateBase, defaultPalette.color(QPalette::Disabled, QPalette::AlternateBase));
palette.setColor(QPalette::Active, QPalette::NoRole, defaultPalette.color(QPalette::Active, QPalette::NoRole));
palette.setColor(QPalette::Inactive, QPalette::NoRole, defaultPalette.color(QPalette::Inactive, QPalette::NoRole));
palette.setColor(QPalette::Disabled, QPalette::NoRole, defaultPalette.color(QPalette::Disabled, QPalette::NoRole));
palette.setColor(QPalette::Active, QPalette::ToolTipBase, defaultPalette.color(QPalette::Active, QPalette::ToolTipBase));
palette.setColor(QPalette::Inactive, QPalette::ToolTipBase, defaultPalette.color(QPalette::Inactive, QPalette::ToolTipBase));
palette.setColor(QPalette::Disabled, QPalette::ToolTipBase, defaultPalette.color(QPalette::Disabled, QPalette::ToolTipBase));
palette.setColor(QPalette::Active, QPalette::ToolTipText, defaultPalette.color(QPalette::Active, QPalette::ToolTipText));
palette.setColor(QPalette::Inactive, QPalette::ToolTipText, defaultPalette.color(QPalette::Inactive, QPalette::ToolTipText));
palette.setColor(QPalette::Disabled, QPalette::ToolTipText, defaultPalette.color(QPalette::Disabled, QPalette::ToolTipText));
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
palette.setColor(QPalette::Active, QPalette::PlaceholderText, defaultPalette.color(QPalette::Active, QPalette::PlaceholderText));
palette.setColor(QPalette::Inactive, QPalette::PlaceholderText, defaultPalette.color(QPalette::Inactive, QPalette::PlaceholderText));
palette.setColor(QPalette::Disabled, QPalette::PlaceholderText, defaultPalette.color(QPalette::Disabled, QPalette::PlaceholderText));
#endif
return palette;
}
int KAbstractStyleParameters::getSpinBoxControlLayout()
{
return m_spinBoxControlLayout;
}
void KAbstractStyleParameters::updateParameters(bool isTabletMode)
{
if(isTabletMode){//styleName == "ukui-dark"){//
m_scaleRatio4_3 = (4 * 1.0) / 3.0;
m_scaleRatio3_2 = (3 * 1.0) / 2.0;
m_scaleRatio2_1 = (2 * 1.0) / 1.0;
m_scaleSliderDefaultLength = (241 * 1.0) / (94 * 1.0);
m_ScaleComboBoxDefaultLength = (49 * 1.0) / (40 * 1.0);
m_ScaleLineEditDefaultLength = (49 * 1.0) / (40 * 1.0);
m_scaleTabBarHeight6_5 = (6 *1.0) / (5 * 1.0);
m_isTableMode = true;
m_spinBoxControlLayout = SpinBoxControlLayout::Horizontal;
m_headerDefaultSectionSizeVertical = m_headerDefaultSectionSizeVertical4_3;
}
else{
m_scaleRatio4_3 = 1.0;
m_scaleRatio3_2 = 1.0;
m_scaleRatio2_1 = 1.0;
m_scaleSliderDefaultLength = 1.0;
m_ScaleComboBoxDefaultLength = 1.0;
m_ScaleLineEditDefaultLength = 1.0;
m_scaleTabBarHeight6_5 = 1.0;
m_isTableMode = false;
m_spinBoxControlLayout = SpinBoxControlLayout::Vertical;
m_headerDefaultSectionSizeVertical = m_headerDefaultSectionSizeVertical1_1;
}
ComboBox_DefaultMenuItemHeight = ComboBox_DefaultMenuItemHeight_original * m_scaleRatio4_3;
MenuItem_DefaultHeight = MenuItem_DefaultHeight_origin * m_scaleRatio4_3;
MenuItemSeparator_MarginHeight = MenuItemSeparator_MarginHeight_origin * m_scaleRatio4_3;
LineEdit_DefaultHeight = LineEdit_DefaultHeight_origin * m_scaleRatio4_3;
IconButton_DefaultWidth = IconButton_DefaultWidth_origin * m_scaleRatio4_3;
Button_DefaultHeight = Button_DefaultHeight_origin * m_scaleRatio4_3;
SpinBox_DefaultHeight = SpinBox_DefaultHeight_origin * m_scaleRatio4_3;
ComboBox_DefaultHeight = ComboBox_DefaultHeight_origin * m_scaleRatio4_3;
RadioButton_DefaultHeight = RadioButton_DefaultHeight_origin * m_scaleRatio4_3;
CheckBox_DefaultHeight = CheckBox_DefaultHeight_origin * m_scaleRatio4_3;
Table_HeaderHeight = Table_HeaderHeight_origin * m_scaleRatio4_3;
ScroolBar_Width = ScroolBar_Width_origin * m_scaleRatio3_2;
Slider_Length = Slider_Length_origin * m_scaleRatio2_1;
Slider_GrooveLength = Slider_GrooveLength_origin * m_scaleRatio2_1;
Slider_DefaultLength = Slider_DefaultLength_origin * m_scaleSliderDefaultLength;
LineEdit_DefaultWidth = LineEdit_DefaultWidth_origin * m_ScaleLineEditDefaultLength;
TabBar_DefaultHeight = TabBar_DefaultHeight_origin * m_scaleTabBarHeight6_5;
ViewItem_DefaultHeight = ViewItem_DefaultHeight_origin * m_scaleRatio4_3;
ToolTip_Height = ToolTip_Height_origin * m_scaleRatio4_3;
qDebug() << "updateParameters......... ";
}
//Default widget theme
KDefaultStyleParameters::KDefaultStyleParameters(QObject *parent, bool isDark) : KAbstractStyleParameters(parent, isDark)
{
radius = 6;
ColoseButtonColor = QColor(204, 18, 34);
initPalette(isDark);
}
void KDefaultStyleParameters::initPalette(bool isDark)
{
//ukui-light palette UKUI3.1
QColor windowText_at(38, 38, 38),
windowText_iat(0, 0, 0, 255 * 0.55),
windowText_dis(0, 0, 0, 255 * 0.3),
button_at(230, 230, 230),
button_iat(230, 230, 230),
button_dis(233, 233, 233),
light_at(255, 255, 255),
light_iat(255, 255, 255),
light_dis(242, 242, 242),
midlight_at(218, 218, 218),
midlight_iat(218, 218, 218),
midlight_dis(230, 230, 230),
dark_at(77, 77, 77),
dark_iat(77, 77, 77),
dark_dis(64, 64, 64),
mid_at(115, 115, 115),
mid_iat(115, 115, 115),
mid_dis(102, 102, 102),
text_at(38, 38, 38),
text_iat(38, 38, 38),
text_dis(0, 0, 0, 255 * 0.3),
brightText_at(0, 0, 0),
brightText_iat(0, 0, 0),
brightText_dis(0, 0, 0),
buttonText_at(38, 38, 38),
buttonText_iat(38, 38, 38),
buttonText_dis(0, 0, 0, 255 * 0.3),
base_at(255, 255, 255),
base_iat(245, 245, 245),
base_dis(237, 237, 237),
window_at(245, 245, 245),
window_iat(237, 237, 237),
window_dis(230, 230, 230),
shadow_at(0, 0, 0, 255 * 0.16),
shadow_iat(0, 0, 0, 255 * 0.16),
shadow_dis(0, 0, 0, 255 * 0.21),
// shadow_at(214, 214, 214),
// shadow_iat(214, 214, 214),
// shadow_dis(201, 201, 201),
highLight_at(55, 144, 250),
highLight_iat(55, 144, 250),
highLight_dis(233, 233, 233),
highLightText_at(255, 255, 255),
highLightText_iat(255, 255, 255),
highLightText_dis(179, 179, 179),
link_at(55, 144, 250),
link_iat(55, 144, 250),
link_dis(55, 144, 250),
linkVisited_at(114, 46, 209),
linkVisited_iat(114, 46, 209),
linkVisited_dis(114, 46, 209),
alternateBase_at(245, 245, 245),
alternateBase_iat(245, 245, 245),
alternateBase_dis(245, 245, 245),
noRale_at(240, 240, 240),
noRole_iat(240, 240, 240),
noRole_dis(217, 217, 217),
toolTipBase_at(255, 255, 255),
toolTipBase_iat(255, 255, 255),
toolTipBase_dis(255, 255, 255),
toolTipText_at(38, 38, 38),
toolTipText_iat(38, 38, 38),
toolTipText_dis(38, 38, 38),
placeholderText_at(0, 0, 0, 255 * 0.35),
placeholderText_iat(0, 0, 0, 255 * 0.35),
placeholderText_dis(0, 0, 0, 255 * 0.3);
//ukui-dark
if (isDark) {
windowText_at.setRgb(217, 217, 217);
windowText_iat.setRgb(255, 255, 255, 255 * 0.55);
windowText_dis.setRgb(255, 255, 255, 255 * 0.3);
button_at.setRgb(55, 55, 59);
button_iat.setRgb(55, 55, 59);
button_dis.setRgb(46, 46, 46);
light_at.setRgb(255, 255, 255);
light_iat.setRgb(255, 255, 255);
light_dis.setRgb(242, 242, 242);
midlight_at.setRgb(95, 95, 98);
midlight_iat.setRgb(95, 95, 98);
midlight_dis.setRgb(79, 79, 82);
dark_at.setRgb(38, 38, 38);
dark_iat.setRgb(38, 38, 38);
dark_dis.setRgb(26, 26, 26);
mid_at.setRgb(115, 115, 115);
mid_iat.setRgb(115, 115, 115);
mid_dis.setRgb(102, 102, 102);
text_at.setRgb(217, 217, 217);
text_iat.setRgb(217, 217, 217);
text_dis.setRgb(255, 255, 255, 255 * 0.3);
brightText_at.setRgb(255, 255, 255);
brightText_iat.setRgb(255, 255, 255);
brightText_dis.setRgb(255, 255, 255);
buttonText_at.setRgb(217, 217, 217);
buttonText_iat.setRgb(217, 217, 217);
buttonText_dis.setRgb(255, 255, 255, 255 * 0.3);
base_at.setRgb(29, 29, 29);
base_iat.setRgb(28, 28, 28);
base_dis.setRgb(36, 36, 36);
window_at.setRgb(35, 36, 38);
window_iat.setRgb(26, 26, 26);
window_dis.setRgb(18, 18, 18);
shadow_at.setRgb(0, 0, 0, 255 * 0.16);
shadow_iat.setRgb(0, 0, 0, 255 * 0.16);
shadow_dis.setRgb(0, 0, 0, 255 * 0.21);
// shadow_at.setRgb(214, 214, 214);
// shadow_iat.setRgb(214, 214, 214);
// shadow_dis.setRgb(201, 201, 201);
highLight_at.setRgb(55, 144, 250);
highLight_iat.setRgb(55, 144, 250);
highLight_dis.setRgb(46, 46, 46);
highLightText_at.setRgb(255, 255, 255);
highLightText_iat.setRgb(255, 255, 255);
highLightText_dis.setRgb(77, 77, 77);
link_at.setRgb(55, 144, 250);
link_iat.setRgb(55, 144, 250);
link_dis.setRgb(55, 144, 250);
linkVisited_at.setRgb(114, 46, 209);
linkVisited_iat.setRgb(114, 46, 209);
linkVisited_dis.setRgb(114, 46, 209);
alternateBase_at.setRgb(38, 38, 38);
alternateBase_iat.setRgb(38, 38, 38);
alternateBase_dis.setRgb(38, 38, 38);
noRale_at.setRgb(51, 51, 51);
noRole_iat.setRgb(51, 51, 51);
noRole_dis.setRgb(60, 60, 60);
toolTipBase_at.setRgb(38, 38, 38);
toolTipBase_iat.setRgb(38, 38, 38);
toolTipBase_dis.setRgb(38, 38, 38);
toolTipText_at.setRgb(217, 217, 217);
toolTipText_iat.setRgb(217, 217, 217);
toolTipText_dis.setRgb(217, 217, 217);
placeholderText_at.setRgb(255, 255, 255, 255 * 0.35);
placeholderText_iat.setRgb(255, 255, 255, 255 * 0.35);
placeholderText_dis.setRgb(255, 255, 255, 255 * 0.3);
}
defaultPalette.setColor(QPalette::Active, QPalette::WindowText, windowText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::WindowText, windowText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::WindowText, windowText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Button, button_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Button, button_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Button, button_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Light, light_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Light, light_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Light, light_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Midlight, midlight_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Midlight, midlight_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Midlight, midlight_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Dark, dark_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Dark, dark_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Dark, dark_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Mid, mid_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Mid, mid_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Mid, mid_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Text, text_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Text, text_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Text, text_dis);
defaultPalette.setColor(QPalette::Active, QPalette::BrightText, brightText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::BrightText, brightText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::BrightText, brightText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ButtonText, buttonText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ButtonText, buttonText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ButtonText, buttonText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Base, base_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Base, base_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Base, base_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Window, window_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Window, window_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Window, window_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Shadow, shadow_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Shadow, shadow_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Shadow, shadow_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Highlight, highLight_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Highlight, highLight_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Highlight, highLight_dis);
defaultPalette.setColor(QPalette::Active, QPalette::HighlightedText, highLightText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, highLightText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, highLightText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Link, link_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Link, link_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Link, link_dis);
defaultPalette.setColor(QPalette::Active, QPalette::LinkVisited, linkVisited_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::LinkVisited, linkVisited_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::LinkVisited, linkVisited_dis);
defaultPalette.setColor(QPalette::Active, QPalette::AlternateBase, alternateBase_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::AlternateBase, alternateBase_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::AlternateBase, alternateBase_dis);
defaultPalette.setColor(QPalette::Active, QPalette::NoRole, noRale_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::NoRole, noRole_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::NoRole, noRole_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ToolTipBase, toolTipBase_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ToolTipBase, toolTipBase_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ToolTipBase, toolTipBase_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ToolTipText, toolTipText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ToolTipText, toolTipText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ToolTipText, toolTipText_dis);
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
defaultPalette.setColor(QPalette::Active, QPalette::PlaceholderText, placeholderText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::PlaceholderText, placeholderText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::PlaceholderText, placeholderText_dis);
#endif
}
void KDefaultStyleParameters::initPushButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
pushButtonParameters.radius = 6;
QBrush defaultBrush;
QBrush clickBrush;
QBrush hoverBrush;
QBrush disableBrush;
QBrush checkBrush;
QBrush checkHoverBrush;
QBrush checkClickBrush;
QBrush checkDisableBrush;
QPen focusPen;
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
if (isDark) {
hoverBrush = QBrush(mixColor(highlight, mix, 0.2));
} else {
hoverBrush = QBrush(mixColor(highlight, mix, 0.05));
}
if (isDark) {
clickBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
clickBrush = QBrush(mixColor(highlight, mix, 0.2));
}
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
checkBrush = option->palette.color(QPalette::Active, QPalette::Highlight);
checkHoverBrush = hoverBrush;
checkClickBrush = clickBrush;
checkDisableBrush = option->palette.brush(QPalette::Disabled, QPalette::NoRole);
focusPen = QPen(QBrush(mixColor(highlight, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
if (widget) {
bool isWindowButton = false;
bool isWindowColoseButton = false;
bool isImportant = false;
bool useButtonPalette = false;
bool needTranslucent = false;
if (widget->property("isWindowButton").isValid()) {
if (widget->property("isWindowButton").toInt() == 0x01) {
isWindowButton = true;
}
if (widget->property("isWindowButton").toInt() == 0x02) {
isWindowColoseButton = true;
}
}
if (widget->property("isImportant").isValid()) {
isImportant = widget->property("isImportant").toBool();
}
if (widget->property("useButtonPalette").isValid()) {
useButtonPalette = widget->property("useButtonPalette").toBool();
}
if (widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor;
hoverBrush = QBrush(QColor(243, 34, 45));
clickBrush = QBrush(ColoseButton);
focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
if (isDark) {
mix.setAlphaF(0.28);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.15);
clickBrush = QBrush(mix);
} else {
mix.setAlphaF(0.15);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.28);
clickBrush = QBrush(mix);
}
} else if (useButtonPalette || isWindowButton) {
if (needTranslucent)
{
QColor hoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
hoverColor.setAlphaF(isDark ? 0.20 : 0.16);
hoverBrush.setColor(hoverColor);
QColor clickColor = option->palette.color(QPalette::Active, QPalette::BrightText);
clickColor.setAlphaF(isDark ? 0.30 : 0.21);
clickBrush.setColor(clickColor);
}
else
{
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
if (isDark) {
hoverBrush = QBrush(mixColor(button, mix, 0.2));
clickBrush = QBrush(mixColor(button, mix, 0.05));
} else {
hoverBrush = QBrush(mixColor(button, mix, 0.05));
clickBrush = QBrush(mixColor(button, mix, 0.2));
}
}
}
if (needTranslucent) {
QColor defaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
defaultColor.setAlphaF(0.1);
defaultBrush.setColor(defaultColor);
QColor disableColor = option->palette.color(QPalette::Disabled, QPalette::BrightText);
disableColor.setAlphaF(0.1);
disableBrush.setColor(disableColor);
}
if (isImportant) {
defaultBrush = highlight;
}
}
pushButtonParameters.pushButtonDefaultBrush = defaultBrush;
pushButtonParameters.pushButtonClickBrush = clickBrush;
pushButtonParameters.pushButtonHoverBrush = hoverBrush;
pushButtonParameters.pushButtonDisableBrush = disableBrush;
pushButtonParameters.pushButtonCheckBrush = checkBrush;
pushButtonParameters.pushButtonCheckHoverBrush = checkHoverBrush;
pushButtonParameters.pushButtonCheckClickBrush = checkClickBrush;
pushButtonParameters.pushButtonCheckDisableBrush = checkDisableBrush;
pushButtonParameters.pushButtonFocusPen = focusPen;
}
void KDefaultStyleParameters::initToolButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
toolButtonParameters.radius = 6;
QBrush defaultBrush;
QBrush clickBrush;
QBrush hoverBrush;
QBrush disableBrush;
QBrush checkBrush;
QBrush checkHoverBrush;
QBrush checkClickBrush;
QBrush checkDisableBrush;
QPen focusPen;
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
if (isDark) {
hoverBrush = QBrush(mixColor(highlight, mix, 0.2));
clickBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
hoverBrush = QBrush(mixColor(highlight, mix, 0.05));
clickBrush = QBrush(mixColor(highlight, mix, 0.2));
}
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
checkBrush = option->palette.color(QPalette::Active, QPalette::Highlight);
checkHoverBrush = hoverBrush;
checkClickBrush = clickBrush;
checkDisableBrush = option->palette.brush(QPalette::Disabled, QPalette::NoRole);
focusPen = QPen(QBrush(mixColor(highlight, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
if (widget) {
bool isWindowButton = false;
bool isWindowColoseButton = false;
bool useButtonPalette = false;
bool needTranslucent = false;
if (widget->property("isWindowButton").isValid()) {
if (widget->property("isWindowButton").toInt() == 0x01) {
isWindowButton = true;
}
if (widget->property("isWindowButton").toInt() == 0x02) {
isWindowColoseButton = true;
}
}
if (widget->property("useButtonPalette").isValid()) {
useButtonPalette = widget->property("useButtonPalette").toBool();
}
if (widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor;
hoverBrush = QBrush(QColor(243, 34, 45));
clickBrush = QBrush(ColoseButton);
focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
if (isDark) {
mix.setAlphaF(0.28);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.15);
clickBrush = QBrush(mix);
} else {
mix.setAlphaF(0.15);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.28);
clickBrush = QBrush(mix);
}
} else if (useButtonPalette || isWindowButton) {
if(needTranslucent)
{
QColor hoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
hoverColor.setAlphaF(isDark ? 0.20 : 0.16);
hoverBrush.setColor(hoverColor);
QColor clickColor = option->palette.color(QPalette::Active, QPalette::BrightText);
clickColor.setAlphaF(isDark ? 0.30 : 0.21);
clickBrush.setColor(clickColor);
}
else
{
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
if (isDark) {
hoverBrush = QBrush(mixColor(button, mix, 0.2));
clickBrush = QBrush(mixColor(button, mix, 0.05));
} else {
hoverBrush = QBrush(mixColor(button, mix, 0.05));
clickBrush = QBrush(mixColor(button, mix, 0.2));
}
}
}
if (needTranslucent) {
QColor defaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
defaultColor.setAlphaF(0.1);
defaultBrush.setColor(defaultColor);
QColor disableColor = option->palette.color(QPalette::Disabled, QPalette::BrightText);
disableColor.setAlphaF(0.1);
disableBrush.setColor(disableColor);
}
}
toolButtonParameters.toolButtonDefaultBrush = defaultBrush;
toolButtonParameters.toolButtonClickBrush = clickBrush;
toolButtonParameters.toolButtonHoverBrush = hoverBrush;
toolButtonParameters.toolButtonDisableBrush = disableBrush;
toolButtonParameters.toolButtonCheckBrush = checkBrush;
toolButtonParameters.toolButtonCheckHoverBrush = checkHoverBrush;
toolButtonParameters.toolButtonCheckClickBrush = checkClickBrush;
toolButtonParameters.toolButtonCheckDisableBrush = checkDisableBrush;
toolButtonParameters.toolButtonFocusPen = focusPen;
}
void KDefaultStyleParameters::initLineEditParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
lineEditParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush focusBrush;
QBrush disableBrush;
QPen defaultPen;
QPen hoverPen;
QPen focusPen;
QPen disablePen;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
//default state
defaultBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
defaultPen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
//hover state
hoverBrush = defaultBrush;
hoverPen = defaultPen;
//focus state
focusBrush = option->palette.brush(QPalette::Active, QPalette::Base);
focusPen = QPen(option->palette.brush(QPalette::Active, QPalette::Highlight),
2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//disable state
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
disablePen = QPen(Qt::NoPen);
disablePen.setWidth(0);
if(needTranslucent)
{
QColor defaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
defaultColor.setAlphaF(isDark ? 0.08 : 0.04);
defaultBrush.setColor(defaultColor);
QColor focusColor = option->palette.color(QPalette::Active, QPalette::Base);
focusColor.setAlphaF(isDark ? 0.45 : 0.65);
focusBrush.setColor(focusColor);
QColor hoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
hoverColor.setAlphaF(isDark ? 0.20 : 0.10);
hoverBrush.setColor(hoverColor);
}
lineEditParameters.lineEditDefaultBrush = defaultBrush;
lineEditParameters.lineEditHoverBrush = hoverBrush;
lineEditParameters.lineEditFocusBrush = focusBrush;
lineEditParameters.lineEditDisableBrush = disableBrush;
lineEditParameters.lineEditDefaultPen = defaultPen;
lineEditParameters.lineEditHoverPen = hoverPen;
lineEditParameters.lineEditFocusPen = focusPen;
lineEditParameters.lineEditDisablePen = disablePen;
}
void KDefaultStyleParameters::initSpinBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget, bool isHorizonLayout)
{
spinBoxParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush focusBrush;
QBrush disableBrush;
QPen defaultPen;
QPen hoverPen;
QPen focusPen;
QPen disablePen;
QBrush upHoverBrush;
QBrush upFocusHoverBrush;
QBrush upClickBrush;
QBrush upDefaultBrush;
QBrush downHoverBrush;
QBrush downFocusHoverBrush;
QBrush downClickBrush;
QBrush downDefaultBrush;
//default state
if(!isHorizonLayout)
defaultBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
else
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
defaultPen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
//hover state
hoverBrush = defaultBrush;
hoverPen = defaultPen;
if(isHorizonLayout)
hoverPen.setWidth(2);
//focus state
focusBrush = option->palette.brush(QPalette::Active, QPalette::Base);
focusPen = QPen(option->palette.brush(QPalette::Active, QPalette::Highlight),
2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//disable state
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
disablePen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
if(isHorizonLayout)
{
upDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
downDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
}
else
{
upDefaultBrush = QBrush(Qt::NoBrush);
downDefaultBrush = QBrush(Qt::NoBrush);
}
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//up hover
if (isDark) {
upHoverBrush = QBrush(mixColor(button, mix, 0.2));
} else {
upHoverBrush = QBrush(mixColor(button, mix, 0.05));
}
//up focus hover
if (isDark) {
upFocusHoverBrush = QBrush(mixColor(highlight, mix, 0.2));
} else {
upFocusHoverBrush = QBrush(mixColor(highlight, mix, 0.05));
}
//up click
if (isDark) {
if(isHorizonLayout)
upClickBrush = QBrush(mixColor(button, mix, 0.05));
else
upClickBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
if(isHorizonLayout)
upClickBrush = QBrush(mixColor(button, mix, 0.2));
else
upClickBrush = QBrush(mixColor(highlight, mix, 0.2));
}
//down hover
if (isDark) {
downHoverBrush = QBrush(mixColor(button, mix, 0.2));
} else {
downHoverBrush = QBrush(mixColor(button, mix, 0.05));
}
//down focus hover
if (isDark) {
downFocusHoverBrush = QBrush(mixColor(highlight, mix, 0.2));
} else {
downFocusHoverBrush = QBrush(mixColor(highlight, mix, 0.05));
}
//down click
if (isDark) {
if(isHorizonLayout)
downClickBrush = QBrush(mixColor(button, mix, 0.05));
else
downClickBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
if(isHorizonLayout)
downClickBrush = QBrush(mixColor(button, mix, 0.2));
else
downClickBrush = QBrush(mixColor(highlight, mix, 0.2));
}
spinBoxParameters.spinBoxDefaultBrush = defaultBrush;
spinBoxParameters.spinBoxHoverBrush = hoverBrush;
spinBoxParameters.spinBoxFocusBrush = focusBrush;
spinBoxParameters.spinBoxDisableBrush = disableBrush;
spinBoxParameters.spinBoxDefaultPen = defaultPen;
spinBoxParameters.spinBoxHoverPen = hoverPen;
spinBoxParameters.spinBoxFocusPen = focusPen;
spinBoxParameters.spinBoxDisablePen = disablePen;
spinBoxParameters.spinBoxUpHoverBrush = upHoverBrush;
spinBoxParameters.spinBoxUpFocusHoverBrush = upFocusHoverBrush;
spinBoxParameters.spinBoxUpClickBrush = upClickBrush;
spinBoxParameters.spinBoxUpDefaultBrush = upDefaultBrush;
spinBoxParameters.spinBoxDownHoverBrush = downHoverBrush;
spinBoxParameters.spinBoxDownFocusHoverBrush = downFocusHoverBrush;
spinBoxParameters.spinBoxDownClickBrush = downClickBrush;
spinBoxParameters.spinBoxDownDefaultBrush = downDefaultBrush;
}
void KDefaultStyleParameters::initComboBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
comboBoxParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush onBrush;
QBrush editBrush;
QBrush disableBrush;
QPen defaultPen;
QPen hoverPen;
QPen onPen;
QPen editPen;
QPen disablePen;
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//default state
defaultBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
defaultPen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
//hover state
if (isDark) {
hoverBrush = QBrush(mixColor(button, mix, 0.2));
} else {
hoverBrush = QBrush(mixColor(button, mix, 0.05));
}
hoverPen = QPen(Qt::NoPen);
hoverPen.setWidth(0);
//on state
if (isDark) {
onBrush = QBrush(mixColor(button, mix, 0.05));
} else {
onBrush = QBrush(mixColor(button, mix, 0.2));
}
onPen = QPen(Qt::NoPen);
onPen.setWidth(0);
//focus and on state,edit mode
editBrush = option->palette.brush(QPalette::Active, QPalette::Base);
editPen = QPen(option->palette.brush(QPalette::Active, QPalette::Highlight),
2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//disable state
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
disablePen = QPen(Qt::NoPen);
disablePen.setWidth(0);
comboBoxParameters.comboBoxDefaultBrush = defaultBrush;
comboBoxParameters.comboBoxHoverBrush = hoverBrush;
comboBoxParameters.comboBoxOnBrush = onBrush;
comboBoxParameters.comboBoxEditBrush = editBrush;
comboBoxParameters.comboBoxDisableBrush = disableBrush;
comboBoxParameters.comboBoxDefaultPen = defaultPen;
comboBoxParameters.comboBoxHoverPen = hoverPen;
comboBoxParameters.comboBoxOnPen = onPen;
comboBoxParameters.comboBoxEditPen = editPen;
comboBoxParameters.comboBoxDisablePen = disablePen;
}
void KDefaultStyleParameters::initListParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
listParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush selectBrush;
QBrush disableBrush;
QPen textHoverPen = QPen(Qt::NoPen);
QPen textSelectPen = QPen(Qt::NoPen);
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
//default
defaultBrush = QBrush(Qt::transparent);
//hover
hoverBrush = option->palette.brush(QPalette::Disabled, QPalette::Midlight);
//select
selectBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
//disable
disableBrush = QBrush(Qt::transparent);
const QStyleOptionViewItem *vi = qstyleoption_cast<const QStyleOptionViewItem *>(option);
QPalette::ColorGroup cg = vi->state & QStyle::State_Enabled
? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(vi->state & QStyle::State_Active))
cg = QPalette::Inactive;
if(needTranslucent)
{
QColor hoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
hoverColor.setAlphaF(isDark ? 0.1 : 0.05);
hoverBrush.setColor(hoverColor);
QColor selectColor = option->palette.color(QPalette::Active, QPalette::BrightText);
selectColor.setAlphaF(isDark ? 0.20 : 0.15);
selectBrush.setColor(selectColor);
textSelectPen = option->palette.color(cg, QPalette::Text);
textHoverPen = option->palette.color(cg, QPalette::BrightText);
}
else
{
textSelectPen = option->palette.color(cg, QPalette::HighlightedText);
textHoverPen = option->palette.color(cg, QPalette::Text);
}
listParameters.listDefaultBrush = defaultBrush;
listParameters.listHoverBrush = hoverBrush;
listParameters.listSelectBrush = selectBrush;
listParameters.listDisableBrush = disableBrush;
listParameters.listTextHoverPen = textHoverPen;
listParameters.listTextSelectPen = textSelectPen;
}
void KDefaultStyleParameters::initTreeParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
treeParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush selectBrush;
QBrush disableBrush;
QBrush branchDefaultBrush;
QBrush branchHoverBrush;
QBrush branchSelectBrush;
QBrush branchDisableBrush;
//default
defaultBrush = QBrush(Qt::transparent);
branchDefaultBrush = defaultBrush;
//hover
hoverBrush = option->palette.brush(QPalette::Disabled, QPalette::Midlight);
branchHoverBrush = hoverBrush;
//select
selectBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
branchSelectBrush = selectBrush;
//disable
disableBrush = QBrush(Qt::transparent);
branchDisableBrush = disableBrush;
treeParameters.treeDefaultBrush = defaultBrush;
treeParameters.treeHoverBrush = hoverBrush;
treeParameters.treeSelectBrush = selectBrush;
treeParameters.treeDisableBrush = disableBrush;
treeParameters.treeBranchDefaultBrush = branchDefaultBrush;
treeParameters.treeBranchHoverBrush = branchHoverBrush;
treeParameters.treeBranchSelectBrush = branchSelectBrush;
treeParameters.treeBranchDisableBrush = branchDisableBrush;
}
void KDefaultStyleParameters::initTableParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
tableParameters.radius = 0;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush selectBrush;
QBrush disableBrush;
//default
defaultBrush = QBrush(Qt::transparent);
//hover
hoverBrush = option->palette.brush(QPalette::Disabled, QPalette::Midlight);
//select
selectBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
//disable
disableBrush = QBrush(Qt::transparent);
tableParameters.tableDefaultBrush = defaultBrush;
tableParameters.tableHoverBrush = hoverBrush;
tableParameters.tableSelectBrush = selectBrush;
tableParameters.tableDisableBrush = disableBrush;
}
void KDefaultStyleParameters::initCheckBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
checkBoxParameters.radius = 4;
QPen defaultPen;
QPen hoverPen;
QPen clickPen;
QPen disablePen;
QPen onDefaultPen;
QPen onHoverPen;
QPen onClickPen;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush clickBrush;
QBrush disableBrush;
QBrush onDefaultBrush;
QBrush onHoverBrush;
QBrush onClickBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//default
if (isDark) {
QColor col = option->palette.color(QPalette::Active, QPalette::BrightText);
col.setAlphaF(0.15);
defaultPen = QPen(col, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else {
defaultPen = QPen(option->palette.brush(QPalette::Disabled, QPalette::ButtonText),
1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
defaultBrush = QBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(200));
//hover
hoverPen = defaultPen;
if (isDark) {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
} else {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.05));
}
//click
clickPen = defaultPen;
if (isDark) {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.1));
} else {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
}
if(needTranslucent)
{
QColor defaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
defaultColor.setAlphaF(isDark ? 0.04 : 0.05);
defaultBrush.setColor(defaultColor);
QColor defaultPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
defaultPenColor.setAlphaF(0.35);
defaultPen = QPen(QBrush(defaultPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
QColor hoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
hoverColor.setAlphaF(isDark ? 0.10 : 0.10);
hoverBrush.setColor(hoverColor);
QColor hoverPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
hoverPenColor.setAlphaF(0.3);
hoverPen = QPen(QBrush(hoverPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
QColor clickColor = option->palette.color(QPalette::Active, QPalette::BrightText);
clickColor.setAlphaF(isDark ? 0.20 : 0.16);
clickBrush.setColor(clickColor);
QColor clickPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
if(!isDark)
clickPenColor = option->palette.color(QPalette::Active, QPalette::Mid);
clickPenColor.setAlphaF(isDark ? 0.25 : 0.65);
clickPen = QPen(QBrush(clickPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
//disable
disablePen = defaultPen;
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
//on default
onDefaultPen = QPen(Qt::NoPen);
onDefaultPen.setWidth(0);
onDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
if(needTranslucent)
{
QColor onDefaultPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
onDefaultPenColor.setAlphaF(0.1);
onDefaultPen = QPen(QBrush(onDefaultPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
//on hover
onHoverPen = QPen(Qt::NoPen);
onHoverPen.setWidth(0);
if (isDark) {
onHoverBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.2));
} else {
onHoverBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.05));
}
if(needTranslucent)
{
QColor onHoverPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
onHoverPenColor.setAlphaF(0.15);
onHoverPen = QPen(QBrush(onHoverPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
//on click
onClickPen = QPen(Qt::NoPen);
onClickPen.setWidth(0);
if (isDark) {
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.05));
} else {
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.2));
}
if(needTranslucent)
{
QColor onClickPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
onClickPenColor.setAlphaF(0.1);
onClickPen = QPen(QBrush(onClickPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
checkBoxParameters.checkBoxDefaultPen = defaultPen;
checkBoxParameters.checkBoxHoverPen = hoverPen;
checkBoxParameters.checkBoxClickPen = clickPen;
checkBoxParameters.checkBoxDisablePen = disablePen;
checkBoxParameters.checkBoxOnDefaultPen = onDefaultPen;
checkBoxParameters.checkBoxOnHoverPen = onHoverPen;
checkBoxParameters.checkBoxOnClickPen = onClickPen;
checkBoxParameters.checkBoxDefaultBrush = defaultBrush;
checkBoxParameters.checkBoxHoverBrush = hoverBrush;
checkBoxParameters.checkBoxClickBrush = clickBrush;
checkBoxParameters.checkBoxDisableBrush = disableBrush;
checkBoxParameters.checkBoxOnDefaultBrush = onDefaultBrush;
checkBoxParameters.checkBoxOnHoverBrush = onHoverBrush;
checkBoxParameters.checkBoxOnClickBrush = onClickBrush;
}
void KDefaultStyleParameters::initRadioButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
radioButtonParameters.radius = 6;
QPen defaultPen;
QPen hoverPen;
QPen clickPen;
QPen disablePen;
QPen onDefaultPen;
QPen onHoverPen;
QPen onClickPen;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush clickBrush;
QBrush disableBrush;
QBrush onDefaultBrush;
QBrush onHoverBrush;
QBrush onClickBrush;
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//default
if (isDark) {
QColor col = option->palette.color(QPalette::Active, QPalette::BrightText);
col.setAlphaF(0.15);
defaultPen = QPen(col, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else {
defaultPen = QPen(option->palette.brush(QPalette::Disabled, QPalette::ButtonText),
1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
defaultBrush = QBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(200));
//hover
hoverPen = defaultPen;
if (isDark) {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
} else {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.05));
}
//click
clickPen = defaultPen;
if (isDark) {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.1));
} else {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
}
//disable
disablePen = defaultPen;
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
//on default
onDefaultPen = QPen(Qt::NoPen);
onDefaultPen.setWidth(0);
onDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
//on hover
onHoverPen = QPen(Qt::NoPen);
onHoverPen.setWidth(0);
if (isDark) {
onHoverBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.2));
} else {
onHoverBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.05));
}
//on click
onClickPen = QPen(Qt::NoPen);
onClickPen.setWidth(0);
if (isDark) {
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.05));
} else {
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.2));
}
//if set property
if (widget) {
if (widget->property("setDefaultPen").isValid() && widget->property("setDefaultPen").canConvert<QPen>()) {
defaultPen = widget->property("setDefaultPen").value<QPen>();
}
if (widget->property("setHoverPen").isValid() && widget->property("setHoverPen").canConvert<QPen>()) {
hoverPen = widget->property("setHoverPen").value<QPen>();
}
if (widget->property("setClickPen").isValid() && widget->property("setClickPen").canConvert<QPen>()) {
clickPen = widget->property("setClickPen").value<QPen>();
}
if (widget->property("setDisablePen").isValid() && widget->property("setDisablePen").canConvert<QPen>()) {
disablePen = widget->property("setDisablePen").value<QPen>();
}
if (widget->property("setOnDefaultPen").isValid() && widget->property("setOnDefaultPen").canConvert<QPen>()) {
onDefaultPen = widget->property("setOnDefaultPen").value<QPen>();
}
if (widget->property("setOnHoverPen").isValid() && widget->property("setOnHoverPen").canConvert<QPen>()) {
onHoverPen = widget->property("setOnHoverPen").value<QPen>();
}
if (widget->property("setOnClickPen").isValid() && widget->property("setOnClickPen").canConvert<QPen>()) {
onClickPen = widget->property("setOnClickPen").value<QPen>();
}
if (widget->property("setDefaultBrush").isValid() && widget->property("setDefaultBrush").canConvert<QBrush>()) {
defaultBrush = widget->property("setDefaultBrush").value<QBrush>();
}
if (widget->property("setHoverBrush").isValid() && widget->property("setHoverBrush").canConvert<QBrush>()) {
hoverBrush = widget->property("setHoverBrush").value<QBrush>();
}
if (widget->property("setClickBrush").isValid() && widget->property("setClickBrush").canConvert<QBrush>()) {
clickBrush = widget->property("setClickBrush").value<QBrush>();
}
if (widget->property("setDisableBrush").isValid() && widget->property("setDisableBrush").canConvert<QBrush>()) {
disableBrush = widget->property("setDisableBrush").value<QBrush>();
}
if (widget->property("setOnDefaultBrush").isValid() && widget->property("setOnDefaultBrush").canConvert<QBrush>()) {
onDefaultBrush = widget->property("setOnDefaultBrush").value<QBrush>();
}
if (widget->property("setOnHoverBrush").isValid() && widget->property("setOnHoverBrush").canConvert<QBrush>()) {
onHoverBrush = widget->property("setOnHoverBrush").value<QBrush>();
}
if (widget->property("setOnClickBrush").isValid() && widget->property("setOnClickBrush").canConvert<QBrush>()) {
onClickBrush = widget->property("setOnClickBrush").value<QBrush>();
}
}
radioButtonParameters.radioButtonDefaultPen = defaultPen;
radioButtonParameters.radioButtonHoverPen = hoverPen;
radioButtonParameters.radioButtonClickPen = clickPen;
radioButtonParameters.radioButtonDisablePen = disablePen;
radioButtonParameters.radioButtonOnDefaultPen = onDefaultPen;
radioButtonParameters.radioButtonOnHoverPen = onHoverPen;
radioButtonParameters.radioButtonOnClickPen = onClickPen;
radioButtonParameters.radioButtonDefaultBrush = defaultBrush;
radioButtonParameters.radioButtonHoverBrush = hoverBrush;
radioButtonParameters.radioButtonClickBrush = clickBrush;
radioButtonParameters.radioButtonDisableBrush = disableBrush;
radioButtonParameters.radioButtonOnDefaultBrush = onDefaultBrush;
radioButtonParameters.radioButtonOnHoverBrush = onHoverBrush;
radioButtonParameters.radioButtonOnClickBrush = onClickBrush;
}
void KDefaultStyleParameters::initSliderParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
QBrush handleDefaultBrush;
QBrush handleHoverBrush;
QBrush handleClickBrush;
QBrush handleDisableBrush;
QBrush grooveValueDefaultBrush;
QBrush grooveValueHoverBrush;
QBrush grooveValueDisableBrush;
QBrush grooveUnvalueDefaultBrush;
QBrush grooveUnvalueHoverBrush;
QBrush grooveUnvalueDisableBrush;
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
//handle default
handleDefaultBrush = option->palette.color(QPalette::Active, QPalette::Highlight);
//handle hover
if (isDark) {
handleHoverBrush = QBrush(mixColor(highlight, mix, 0.2));
} else {
handleHoverBrush = QBrush(mixColor(highlight, mix, 0.05));
}
//handle click
if (isDark) {
handleClickBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
handleClickBrush = QBrush(mixColor(highlight, mix, 0.2));
}
//handle disable
handleDisableBrush = option->palette.color(QPalette::Disabled, QPalette::ButtonText);
//groove value default
if (isDark) {
grooveValueDefaultBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
grooveValueDefaultBrush = QBrush(mixColor(highlight, mix, 0.2));
}
//groove value hover
grooveValueHoverBrush = grooveValueDefaultBrush;
//groove value disable
grooveValueDisableBrush = handleDisableBrush;
//groove unvalue default
grooveUnvalueDefaultBrush = option->palette.color(QPalette::Active, QPalette::Button);
if(needTranslucent)
{
QColor color = option->palette.color(QPalette::Active, QPalette::BrightText);
color.setAlphaF(0.1);
grooveUnvalueDefaultBrush.setColor(color);
}
//groove unvalue hover
grooveUnvalueHoverBrush = grooveUnvalueDefaultBrush;
//groove unvalue disable
grooveUnvalueDisableBrush = grooveUnvalueDefaultBrush;
sliderParameters.sliderHandleDefaultBrush = handleDefaultBrush;
sliderParameters.sliderHandleHoverBrush = handleHoverBrush;
sliderParameters.sliderHandleClickBrush = handleClickBrush;
sliderParameters.sliderHandleDisableBrush = handleDisableBrush;
sliderParameters.sliderGrooveValueDefaultBrush = grooveValueDefaultBrush;
sliderParameters.sliderGrooveValueHoverBrush = grooveValueHoverBrush;
sliderParameters.sliderGrooveValueDisableBrush = grooveValueDisableBrush;
sliderParameters.sliderGrooveUnvalueDefaultBrush = grooveUnvalueDefaultBrush;
sliderParameters.sliderGrooveUnvalueHoverBrush = grooveUnvalueHoverBrush;
sliderParameters.sliderGrooveUnvalueDisableBrush = grooveUnvalueDisableBrush;
}
void KDefaultStyleParameters::initProgressBarParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
QBrush contentBrush;
QBrush grooveDefaultBrush;
QBrush grooveDisableBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option);
const bool vertical = pb->orientation == Qt::Vertical;
const bool inverted = pb->invertedAppearance;
bool reverse = (!vertical && (pb->direction == Qt::RightToLeft)) || vertical;
if (inverted)
reverse = !reverse;
//content
QColor startColor = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor endColor = option->palette.color(QPalette::Active, QPalette::Highlight).lighter(120);
QLinearGradient linearGradient;
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
if (vertical) {
if (reverse) {
linearGradient.setStart(pb->rect.bottomLeft());
linearGradient.setFinalStop(pb->rect.topLeft());
} else {
linearGradient.setStart(pb->rect.topLeft());
linearGradient.setFinalStop(pb->rect.bottomLeft());
}
} else {
if (reverse) {
linearGradient.setStart(pb->rect.topRight());
linearGradient.setFinalStop(pb->rect.topLeft());
} else {
linearGradient.setStart(pb->rect.topLeft());
linearGradient.setFinalStop(pb->rect.topRight());
}
}
contentBrush = QBrush(linearGradient);
//groove default
grooveDefaultBrush = pb->palette.brush(QPalette::Active, QPalette::Button);
if(needTranslucent)
{
QColor grooveDefaultColor = pb->palette.color(QPalette::Active, QPalette::BrightText);
grooveDefaultColor.setAlphaF(0.10);
grooveDefaultBrush.setColor(grooveDefaultColor);
}
//groove disable
grooveDisableBrush = pb->palette.brush(QPalette::Disabled, QPalette::Button);
progressBarParameters.radius = 6;
progressBarParameters.progressBarContentBrush = contentBrush;
progressBarParameters.progressBarGrooveDefaultBrush = grooveDefaultBrush;
progressBarParameters.progressBarGrooveDisableBrush = grooveDisableBrush;
}
void KDefaultStyleParameters::initScrollBarParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
int sliderRadius;
QBrush grooveDefaultBrush;
QBrush grooveInactiveBrush;
QBrush sliderDefaultBrush;
QBrush sliderHoverBrush;
QBrush sliderClickBrush;
QBrush sliderDisableBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
const QStyleOptionSlider *bar = qstyleoption_cast<const QStyleOptionSlider *>(option);
//radius
if (bar->orientation == Qt::Horizontal) {
sliderRadius = (bar->rect.height()) / 4;
} else {
sliderRadius = (bar->rect.width()) / 4;
}
//groove default
grooveDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Base);
//groove inactive
grooveInactiveBrush = option->palette.brush(QPalette::Inactive, QPalette::Base);
//slider default
sliderDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
//slider hover
if (isDark) {
sliderHoverBrush = QBrush(mixColor(sliderDefaultBrush.color(), mix, 0.2));
} else {
sliderHoverBrush = QBrush(mixColor(sliderDefaultBrush.color(), mix, 0.05));
}
//slider click
if (isDark) {
sliderClickBrush = QBrush(mixColor(sliderDefaultBrush.color(), mix, 0.05));
} else {
sliderClickBrush = QBrush(mixColor(sliderDefaultBrush.color(), mix, 0.2));
}
//slider disable
sliderDisableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
if(needTranslucent)
{
QColor grooveDefaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
grooveDefaultColor.setAlphaF(isDark ? 0.08 : 0.06);
grooveDefaultBrush.setColor(grooveDefaultColor);
QColor grooveInactiveColor = option->palette.color(QPalette::Active, QPalette::BrightText);
grooveInactiveColor.setAlphaF(isDark ? 0.08 : 0.06);
grooveInactiveBrush.setColor(grooveInactiveColor);
QColor sliderDefaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
sliderDefaultColor.setAlphaF(isDark ? 0.10 : 0.10);
sliderDefaultBrush.setColor(sliderDefaultColor);
QColor sliderHoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
sliderHoverColor.setAlphaF(isDark ? 0.20 : 0.18);
sliderHoverBrush.setColor(sliderHoverColor);
QColor sliderClickColor = option->palette.color(QPalette::Active, QPalette::BrightText);
sliderClickColor.setAlphaF(isDark ? 0.30 : 0.28);
sliderClickBrush.setColor(sliderClickColor);
}
scrollBarParameters.radius = sliderRadius;
scrollBarParameters.scrollBarGrooveDefaultBrush = grooveDefaultBrush;
scrollBarParameters.scrollBarGrooveInactiveBrush = grooveInactiveBrush;
scrollBarParameters.scrollBarSliderDefaultBrush = sliderDefaultBrush;
scrollBarParameters.scrollBarSliderHoverBrush = sliderHoverBrush;
scrollBarParameters.scrollBarSliderClickBrush = sliderClickBrush;
scrollBarParameters.scrollBarSliderDisableBrush = sliderDisableBrush;
}
void KDefaultStyleParameters::initToolTipParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
QBrush backgroundBrush;
//background
backgroundBrush = option->palette.color(QPalette::Active, QPalette::ToolTipBase);
toolTipParameters.radius = 6;
toolTipParameters.toolTipBackgroundBrush = backgroundBrush;
}
void KDefaultStyleParameters::initTabWidgetParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
int tabradius = 6;
QBrush widgetBackgroundBrush;
QBrush tabBarBackgroundBrush;
QBrush tabBarDefaultBrush;
QBrush tabBarHoverBrush;
QBrush tabBarSelectBrush;
//tab widget background
widgetBackgroundBrush = option->palette.brush(QPalette::Active, QPalette::Base);
//tabbar background
tabBarBackgroundBrush = option->palette.brush(QPalette::Active, QPalette::Window);
//tabbar default
tabBarDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Window);
//tabbar hover
QColor hover_color = option->palette.color(QPalette::Active, QPalette::Window);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
tabBarHoverBrush = QBrush(mixColor(hover_color, mix, 0.1));
//tabbar select
tabBarSelectBrush = option->palette.brush(QPalette::Active, QPalette::Base);
if (widget && widget->property("setRadius").isValid() && widget->property("setRadius").canConvert<int>()) {
tabradius = widget->property("setRadius").value<int>();
}
tabWidgetParameters.radius = tabradius;
tabWidgetParameters.tabWidgetBackgroundBrush = widgetBackgroundBrush;
tabWidgetParameters.tabBarBackgroundBrush = tabBarBackgroundBrush;
tabWidgetParameters.tabBarDefaultBrush = tabBarDefaultBrush;
tabWidgetParameters.tabBarHoverBrush = tabBarHoverBrush;
tabWidgetParameters.tabBarSelectBrush = tabBarSelectBrush;
}
void KDefaultStyleParameters::initMenuParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
int frameradius = 8;
int itemradius = 6;
QPixmap framePixmap(option->rect.size());
QBrush itemSelectBrush;
//frame Pixmap
framePixmap.fill(Qt::transparent);
if (qobject_cast<const QFrame*>(widget)) {
QPainter pixmapPainter(&framePixmap);
pixmapPainter.setPen(Qt::NoPen);
pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(180));
pixmapPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter.drawRoundedRect(option->rect, frameradius, frameradius);
} else {
int rander = 2;
// Draw a black floor
QPainter pixmapPainter(&framePixmap);
pixmapPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter.setPen(Qt::transparent);
pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::BrightText));
pixmapPainter.drawRoundedRect(option->rect.adjusted(+rander, +rander+6, -rander, -rander-6), frameradius, frameradius);
pixmapPainter.end();
// Blur the black background
QImage img = framePixmap.toImage();
qt_blurImage(img, 4, false, false);
// Dig out the center part, Shadow rendering
framePixmap = QPixmap::fromImage(img);
QPainter pixmapPainter2(&framePixmap);
pixmapPainter2.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear);
pixmapPainter2.setPen(Qt::transparent);
pixmapPainter2.setBrush(Qt::transparent);
pixmapPainter2.drawRoundedRect(option->rect.adjusted(+rander, +rander+6, -rander, -rander-6), frameradius, frameradius);
pixmapPainter2.end();
//That's when I started drawing the frame floor
auto color = option->palette.color(QPalette::Base);
if (UKUIStyleSettings::isSchemaInstalled("org.ukui.style")) {
auto opacity = UKUIStyleSettings::globalInstance()->get("menuTransparency").toInt()/100.0;
color.setAlphaF(opacity);
}
if (qApp->property("blurEnable").isValid()) {
bool blurEnable = qApp->property("blurEnable").toBool();
if (!blurEnable) {
color.setAlphaF(1);
}
}
if (widget) {
if (widget->property("useSystemStyleBlur").isValid() && !widget->property("useSystemStyleBlur").toBool()) {
color.setAlphaF(1);
}
}
//if blur effect is not supported, do not use transparent color.
if (!KWindowEffects::isEffectAvailable(KWindowEffects::BlurBehind) || blackAppListWithBlurHelper().contains(qAppName())) {
color.setAlphaF(1);
}
QPainterPath path;
QRegion region;
if (widget) {
region = widget->mask();
}
if (region.isEmpty()) {
path.addRoundedRect(option->rect.adjusted(+rander, +rander+6, -rander, -rander-6), frameradius, frameradius);
} else {
path.addRegion(region);
}
//draw blur background
QPainter pixmapPainter3(&framePixmap);
pixmapPainter3.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter3.setPen(Qt::transparent);
pixmapPainter3.setBrush(color);
pixmapPainter3.drawPath(path);
}
//item select brush
itemSelectBrush = QBrush(option->palette.brush(QPalette::Active, QPalette::Highlight));
menuParameters.frameRadius = frameradius;
menuParameters.itemRadius = itemradius;
menuParameters.menuFramePixmap = framePixmap;
menuParameters.menuItemSelectBrush = itemSelectBrush;
}
//Classical widget theme
KClassicalStyleParameters::KClassicalStyleParameters(QObject *parent, bool isDark) : KAbstractStyleParameters(parent, isDark)
{
radius = 0;
CheckBox_Radius = 0;
initPalette(isDark);
}
void KClassicalStyleParameters::initPalette(bool isDark)
{
QColor windowText_at(38, 38, 38),
windowText_iat(38, 38, 38),
windowText_dis(166, 166, 166),
button_at(230, 230, 230),
button_iat(230, 230, 230),
button_dis(233, 233, 233),
light_at(255, 255, 255),
light_iat(255, 255, 255),
light_dis(242, 242, 242),
midlight_at(217, 217, 217),
midlight_iat(217, 217, 217),
midlight_dis(230, 230, 230),
dark_at(77, 77, 77),
dark_iat(77, 77, 77),
dark_dis(64, 64, 64),
mid_at(115, 115, 115),
mid_iat(115, 115, 115),
mid_dis(102, 102, 102),
text_at(38, 38, 38),
text_iat(38, 38, 38),
text_dis(140, 140, 140),
brightText_at(89, 89, 89),
brightText_iat(89, 89, 89),
brightText_dis(77, 77, 77),
buttonText_at(38, 38, 38),
buttonText_iat(38, 38, 38),
buttonText_dis(179, 179, 179),
base_at(255, 255, 255),
base_iat(245, 245, 245),
base_dis(237, 237, 237),
window_at(245, 245, 245),
window_iat(237, 237, 237),
window_dis(230, 230, 230),
shadow_at(214, 214, 214),
shadow_iat(214, 214, 214),
shadow_dis(201, 201, 201),
highLight_at(55, 144, 250),
highLight_iat(55, 144, 250),
hightight_dis(233, 233, 233),
highLightText_at(255, 255, 255),
highLightText_iat(255, 255, 255),
highLightText_dis(179, 179, 179),
link_at(55, 144, 250),
link_iat(55, 144, 250),
link_dis(55, 144, 250),
linkVisited_at(114, 46, 209),
linkVisited_iat(114, 46, 209),
linkVisited_dis(114, 46, 209),
alternateBase_at(244, 245, 245),
noRale_at(240, 240, 240),
noRole_iat(240, 240, 240),
noRole_dis(217, 217, 217),
toolTipBase(255, 255, 255),
toolTipText(38, 38, 38),
placeholderText(38, 38, 38);
if (isDark) {
windowText_at.setRgb(217, 217, 217);
windowText_iat.setRgb(217, 217, 217);
windowText_dis.setRgb(77, 77, 77);
button_at.setRgb(55, 55, 59);
button_iat.setRgb(55, 55, 59);
button_dis.setRgb(46, 46, 48);
midlight_at.setRgb(77, 77, 77);
midlight_iat.setRgb(77, 77, 77);
midlight_dis.setRgb(64, 64, 64);
dark_at.setRgb(38, 38, 38);
dark_iat.setRgb(38, 38, 38);
dark_dis.setRgb(26, 26, 26);
text_at.setRgb(217, 217, 217);
text_iat.setRgb(217, 217, 217);
text_dis.setRgb(77, 77, 77);
brightText_at.setRgb(255, 255, 255);
brightText_iat.setRgb(255, 255, 255);
brightText_dis.setRgb(77, 77, 77);
buttonText_at.setRgb(217, 217, 217);
buttonText_iat.setRgb(217, 217, 217);
buttonText_dis.setRgb(76, 76, 79);
base_at.setRgb(18, 18, 18);
base_iat.setRgb(28, 28, 28);
base_dis.setRgb(36, 36, 36);
window_at.setRgb(35, 36, 38);
window_iat.setRgb(26, 26, 26);
window_dis.setRgb(18, 18, 18);
hightight_dis.setRgb(46, 46, 48);
highLightText_dis.setRgb(77, 77, 77);
alternateBase_at.setRgb(38, 38, 38);
noRale_at.setRgb(51, 51, 51);
noRole_iat.setRgb(51, 51, 51);
noRole_dis.setRgb(60, 60, 64);
toolTipBase.setRgb(38, 38, 38);
toolTipText.setRgb(217, 217, 217);
placeholderText.setRgb(166, 166, 166);
}
defaultPalette.setColor(QPalette::Active, QPalette::WindowText, windowText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::WindowText, windowText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::WindowText, windowText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Button, button_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Button, button_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Button, button_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Light, light_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Light, light_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Light, light_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Midlight, midlight_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Midlight, midlight_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Midlight, midlight_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Dark, dark_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Dark, dark_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Dark, dark_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Mid, mid_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Mid, mid_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Mid, mid_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Text, text_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Text, text_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Text, text_dis);
defaultPalette.setColor(QPalette::Active, QPalette::BrightText, brightText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::BrightText, brightText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::BrightText, brightText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ButtonText, buttonText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ButtonText, buttonText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ButtonText, buttonText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Base, base_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Base, base_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Base, base_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Window, window_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Window, window_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Window, window_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Shadow, shadow_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Shadow, shadow_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Shadow, shadow_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Highlight, highLight_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Highlight, highLight_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Highlight, hightight_dis);
defaultPalette.setColor(QPalette::Active, QPalette::HighlightedText, highLightText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, highLightText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, highLightText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Link, link_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Link, link_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Link, link_dis);
defaultPalette.setColor(QPalette::Active, QPalette::LinkVisited, linkVisited_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::LinkVisited, linkVisited_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::LinkVisited, linkVisited_dis);
defaultPalette.setColor(QPalette::AlternateBase, alternateBase_at);
defaultPalette.setColor(QPalette::Active, QPalette::NoRole, noRale_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::NoRole, noRole_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::NoRole, noRole_dis);
defaultPalette.setColor(QPalette::ToolTipBase, toolTipBase);
defaultPalette.setColor(QPalette::ToolTipText, toolTipText);
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
defaultPalette.setColor(QPalette::PlaceholderText, placeholderText);
#endif
}
void KClassicalStyleParameters::initPushButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initToolButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initLineEditParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initSpinBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget, bool isHorizonLayout)
{
}
void KClassicalStyleParameters::initComboBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initListParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initTreeParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initTableParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initCheckBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initRadioButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initSliderParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initProgressBarParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initScrollBarParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initToolTipParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initTabWidgetParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
void KClassicalStyleParameters::initMenuParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
}
//fashion widget theme
KFashionStyleParameters::KFashionStyleParameters(QObject *parent, bool isDark) : KAbstractStyleParameters(parent, isDark)
{
radius = 6;
ColoseButtonColor = QColor(198, 42, 63);
initPalette(isDark);
}
void KFashionStyleParameters::initPalette(bool isDark)
{
//ukui-light palette UKUI3.1
QColor windowText_at(38, 38, 38),
windowText_iat(0, 0, 0, 255 * 0.55),
windowText_dis(0, 0, 0, 255 * 0.3),
button_at(230, 230, 230),
button_iat(230, 230, 230),
button_dis(233, 233, 233),
light_at(255, 255, 255),
light_iat(255, 255, 255),
light_dis(242, 242, 242),
midlight_at(218, 218, 218),
midlight_iat(218, 218, 218),
midlight_dis(230, 230, 230),
dark_at(77, 77, 77),
dark_iat(77, 77, 77),
dark_dis(64, 64, 64),
mid_at(115, 115, 115),
mid_iat(115, 115, 115),
mid_dis(102, 102, 102),
text_at(38, 38, 38),
text_iat(38, 38, 38),
text_dis(0, 0, 0, 255 * 0.3),
brightText_at(0, 0, 0),
brightText_iat(0, 0, 0),
brightText_dis(0, 0, 0),
buttonText_at(38, 38, 38),
buttonText_iat(38, 38, 38),
buttonText_dis(0, 0, 0, 255 * 0.3),
base_at(255, 255, 255),
base_iat(245, 245, 245),
base_dis(237, 237, 237),
window_at(245, 245, 245),
window_iat(237, 237, 237),
window_dis(230, 230, 230),
shadow_at(0, 0, 0, 255 * 0.16),
shadow_iat(0, 0, 0, 255 * 0.16),
shadow_dis(0, 0, 0, 255 * 0.21),
// shadow_at(214, 214, 214),
// shadow_iat(214, 214, 214),
// shadow_dis(201, 201, 201),
highLight_at(120, 115, 245),
highLight_iat(120, 115, 245),
highLight_dis(233, 233, 233),
highLightText_at(255, 255, 255),
highLightText_iat(255, 255, 255),
highLightText_dis(179, 179, 179),
link_at(120, 115, 245),
link_iat(120, 115, 245),
link_dis(120, 115, 245),
linkVisited_at(62, 118, 247),
linkVisited_iat(62, 118, 247),
linkVisited_dis(62, 118, 247),
alternateBase_at(245, 245, 245),
alternateBase_iat(245, 245, 245),
alternateBase_dis(245, 245, 245),
noRale_at(240, 240, 240),
noRole_iat(240, 240, 240),
noRole_dis(217, 217, 217),
toolTipBase_at(255, 255, 255),
toolTipBase_iat(255, 255, 255),
toolTipBase_dis(255, 255, 255),
toolTipText_at(38, 38, 38),
toolTipText_iat(38, 38, 38),
toolTipText_dis(38, 38, 38),
placeholderText_at(0, 0, 0, 255 * 0.35),
placeholderText_iat(0, 0, 0, 255 * 0.35),
placeholderText_dis(0, 0, 0, 255 * 0.3);
//ukui-dark
if (isDark) {
windowText_at.setRgb(217, 217, 217);
windowText_iat.setRgb(255, 255, 255, 255 * 0.55);
windowText_dis.setRgb(255, 255, 255, 255 * 0.3);
button_at.setRgb(55, 55, 59);
button_iat.setRgb(55, 55, 59);
button_dis.setRgb(46, 46, 46);
light_at.setRgb(255, 255, 255);
light_iat.setRgb(255, 255, 255);
light_dis.setRgb(242, 242, 242);
midlight_at.setRgb(95, 95, 98);
midlight_iat.setRgb(95, 95, 98);
midlight_dis.setRgb(79, 79, 82);
dark_at.setRgb(38, 38, 38);
dark_iat.setRgb(38, 38, 38);
dark_dis.setRgb(26, 26, 26);
mid_at.setRgb(115, 115, 115);
mid_iat.setRgb(115, 115, 115);
mid_dis.setRgb(102, 102, 102);
text_at.setRgb(217, 217, 217);
text_iat.setRgb(217, 217, 217);
text_dis.setRgb(255, 255, 255, 255 * 0.3);
brightText_at.setRgb(255, 255, 255);
brightText_iat.setRgb(255, 255, 255);
brightText_dis.setRgb(255, 255, 255);
buttonText_at.setRgb(217, 217, 217);
buttonText_iat.setRgb(217, 217, 217);
buttonText_dis.setRgb(255, 255, 255, 255 * 0.3);
base_at.setRgb(29, 29, 29);
base_iat.setRgb(28, 28, 28);
base_dis.setRgb(36, 36, 36);
window_at.setRgb(35, 36, 38);
window_iat.setRgb(26, 26, 26);
window_dis.setRgb(18, 18, 18);
shadow_at.setRgb(0, 0, 0, 255 * 0.16);
shadow_iat.setRgb(0, 0, 0, 255 * 0.16);
shadow_dis.setRgb(0, 0, 0, 255 * 0.21);
// shadow_at.setRgb(214, 214, 214);
// shadow_iat.setRgb(214, 214, 214);
// shadow_dis.setRgb(201, 201, 201);
highLight_at.setRgb(120, 115, 245);
highLight_iat.setRgb(120, 115, 245);
highLight_dis.setRgb(46, 46, 46);
highLightText_at.setRgb(255, 255, 255);
highLightText_iat.setRgb(255, 255, 255);
highLightText_dis.setRgb(77, 77, 77);
link_at.setRgb(120, 115, 245);
link_iat.setRgb(120, 115, 245);
link_dis.setRgb(120, 115, 245);
linkVisited_at.setRgb(62, 118, 247);
linkVisited_iat.setRgb(62, 118, 247);
linkVisited_dis.setRgb(62, 118, 247);
alternateBase_at.setRgb(38, 38, 38);
alternateBase_iat.setRgb(38, 38, 38);
alternateBase_dis.setRgb(38, 38, 38);
noRale_at.setRgb(51, 51, 51);
noRole_iat.setRgb(51, 51, 51);
noRole_dis.setRgb(60, 60, 60);
toolTipBase_at.setRgb(38, 38, 38);
toolTipBase_iat.setRgb(38, 38, 38);
toolTipBase_dis.setRgb(38, 38, 38);
toolTipText_at.setRgb(217, 217, 217);
toolTipText_iat.setRgb(217, 217, 217);
toolTipText_dis.setRgb(217, 217, 217);
placeholderText_at.setRgb(255, 255, 255, 255 * 0.35);
placeholderText_iat.setRgb(255, 255, 255, 255 * 0.35);
placeholderText_dis.setRgb(255, 255, 255, 255 * 0.3);
}
defaultPalette.setColor(QPalette::Active, QPalette::WindowText, windowText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::WindowText, windowText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::WindowText, windowText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Button, button_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Button, button_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Button, button_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Light, light_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Light, light_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Light, light_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Midlight, midlight_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Midlight, midlight_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Midlight, midlight_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Dark, dark_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Dark, dark_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Dark, dark_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Mid, mid_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Mid, mid_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Mid, mid_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Text, text_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Text, text_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Text, text_dis);
defaultPalette.setColor(QPalette::Active, QPalette::BrightText, brightText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::BrightText, brightText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::BrightText, brightText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ButtonText, buttonText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ButtonText, buttonText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ButtonText, buttonText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Base, base_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Base, base_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Base, base_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Window, window_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Window, window_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Window, window_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Shadow, shadow_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Shadow, shadow_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Shadow, shadow_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Highlight, highLight_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Highlight, highLight_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Highlight, highLight_dis);
defaultPalette.setColor(QPalette::Active, QPalette::HighlightedText, highLightText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, highLightText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, highLightText_dis);
defaultPalette.setColor(QPalette::Active, QPalette::Link, link_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::Link, link_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::Link, link_dis);
defaultPalette.setColor(QPalette::Active, QPalette::LinkVisited, linkVisited_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::LinkVisited, linkVisited_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::LinkVisited, linkVisited_dis);
defaultPalette.setColor(QPalette::Active, QPalette::AlternateBase, alternateBase_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::AlternateBase, alternateBase_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::AlternateBase, alternateBase_dis);
defaultPalette.setColor(QPalette::Active, QPalette::NoRole, noRale_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::NoRole, noRole_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::NoRole, noRole_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ToolTipBase, toolTipBase_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ToolTipBase, toolTipBase_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ToolTipBase, toolTipBase_dis);
defaultPalette.setColor(QPalette::Active, QPalette::ToolTipText, toolTipText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::ToolTipText, toolTipText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::ToolTipText, toolTipText_dis);
#if (QT_VERSION >= QT_VERSION_CHECK(5,12,0))
defaultPalette.setColor(QPalette::Active, QPalette::PlaceholderText, placeholderText_at);
defaultPalette.setColor(QPalette::Inactive, QPalette::PlaceholderText, placeholderText_iat);
defaultPalette.setColor(QPalette::Disabled, QPalette::PlaceholderText, placeholderText_dis);
#endif
}
void KFashionStyleParameters::initPushButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
pushButtonParameters.radius = 6;
QBrush defaultBrush;
QBrush clickBrush;
QBrush hoverBrush;
QBrush disableBrush;
QBrush checkBrush;
QBrush checkHoverBrush;
QBrush checkClickBrush;
QBrush checkDisableBrush;
QPen focusPen;
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
//hover
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = mixColor(highlight, QColor(Qt::white), 0.2);
endColor = mixColor(highlight, QColor(Qt::black), 0.05);
} else {
startColor = mixColor(highlight, QColor(Qt::white), 0.05);
endColor = mixColor(highlight, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
clickBrush = QBrush(mixColor(highlight, mix, 0.1));
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
checkBrush = option->palette.color(QPalette::Active, QPalette::Highlight);
checkHoverBrush = hoverBrush;
checkClickBrush = clickBrush;
checkDisableBrush = option->palette.brush(QPalette::Disabled, QPalette::NoRole);
focusPen = QPen(QBrush(mixColor(highlight, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
if (widget) {
bool isWindowButton = false;
bool isWindowColoseButton = false;
bool isImportant = false;
bool useButtonPalette = false;
bool needTranslucent = false;
if (widget->property("isWindowButton").isValid()) {
if (widget->property("isWindowButton").toInt() == 0x01) {
isWindowButton = true;
}
if (widget->property("isWindowButton").toInt() == 0x02) {
isWindowColoseButton = true;
}
}
if (widget->property("isImportant").isValid()) {
isImportant = widget->property("isImportant").toBool();
}
if (widget->property("useButtonPalette").isValid()) {
useButtonPalette = widget->property("useButtonPalette").toBool();
}
if (widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor;
if (isDark) {
startColor = QColor(242, 116, 133);
endColor = QColor(221, 44, 68);
} else {
startColor = QColor(242, 82, 117);
endColor = QColor(221, 44, 68);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
//click
clickBrush = QBrush(ColoseButton);
//focus
focusPen = QPen(QBrush(ColoseButton), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
if (isDark) {
mix.setAlphaF(0.28);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.15);
clickBrush = QBrush(mix);
} else {
mix.setAlphaF(0.15);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.28);
clickBrush = QBrush(mix);
}
} else if (useButtonPalette || isWindowButton) {
if(needTranslucent)
{
if (isDark) {
startColor = option->palette.color(QPalette::Active, QPalette::Light);
endColor = option->palette.color(QPalette::Active, QPalette::Text);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Mid);
endColor = option->palette.color(QPalette::Active, QPalette::Dark);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
QColor clickColor = option->palette.color(QPalette::Active, QPalette::Dark);
if(isDark)
clickColor = option->palette.color(QPalette::Active, QPalette::Light);
clickColor.setAlphaF(isDark ? 0.30 : 0.30);
clickBrush.setColor(clickColor);
}
else{
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
//hover
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
//click
clickBrush = QBrush(mixColor(button, mix, 0.2));
}
}
if (needTranslucent) {
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Mid);
disableBrush = option->palette.brush(QPalette::Active, QPalette::Mid);
if(isDark){
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Text);
disableBrush = option->palette.brush(QPalette::Active, QPalette::Text);
}
QColor defaultColor = defaultBrush.color();
defaultColor.setAlphaF(0.15);
defaultBrush.setColor(defaultColor);
QColor disableColor = disableBrush.color();
disableColor.setAlphaF(0.1);
disableBrush.setColor(disableColor);
}
if (isImportant) {
defaultBrush = highlight;
}
}
pushButtonParameters.pushButtonDefaultBrush = defaultBrush;
pushButtonParameters.pushButtonClickBrush = clickBrush;
pushButtonParameters.pushButtonHoverBrush = hoverBrush;
pushButtonParameters.pushButtonDisableBrush = disableBrush;
pushButtonParameters.pushButtonCheckBrush = checkBrush;
pushButtonParameters.pushButtonCheckHoverBrush = checkHoverBrush;
pushButtonParameters.pushButtonCheckClickBrush = checkClickBrush;
pushButtonParameters.pushButtonCheckDisableBrush = checkDisableBrush;
pushButtonParameters.pushButtonFocusPen = focusPen;
}
void KFashionStyleParameters::initToolButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
toolButtonParameters.radius = 6;
QBrush defaultBrush;
QBrush clickBrush;
QBrush hoverBrush;
QBrush disableBrush;
QBrush checkBrush;
QBrush checkHoverBrush;
QBrush checkClickBrush;
QBrush checkDisableBrush;
QPen focusPen;
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
//hover
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = mixColor(highlight, QColor(Qt::white), 0.2);
endColor = mixColor(highlight, QColor(Qt::black), 0.05);
} else {
startColor = mixColor(highlight, QColor(Qt::white), 0.05);
endColor = mixColor(highlight, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
clickBrush = QBrush(mixColor(highlight, mix, 0.1));
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
checkBrush = option->palette.color(QPalette::Active, QPalette::Highlight);
checkHoverBrush = hoverBrush;
checkClickBrush = clickBrush;
checkDisableBrush = option->palette.brush(QPalette::Disabled, QPalette::NoRole);
focusPen = QPen(QBrush(mixColor(highlight, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
if (widget) {
bool isWindowButton = false;
bool isWindowColoseButton = false;
bool useButtonPalette = false;
bool needTranslucent = false;
if (widget->property("isWindowButton").isValid()) {
if (widget->property("isWindowButton").toInt() == 0x01) {
isWindowButton = true;
}
if (widget->property("isWindowButton").toInt() == 0x02) {
isWindowColoseButton = true;
}
}
if (widget->property("useButtonPalette").isValid()) {
useButtonPalette = widget->property("useButtonPalette").toBool();
}
if (widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor;
if (isDark) {
startColor = QColor(242, 116, 133);
endColor = QColor(221, 44, 68);
} else {
startColor = QColor(242, 82, 117);
endColor = QColor(221, 44, 68);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
//click
clickBrush = QBrush(ColoseButton);
//focus
focusPen = QPen(QBrush(ColoseButton), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
if (isDark) {
mix.setAlphaF(0.28);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.15);
clickBrush = QBrush(mix);
} else {
mix.setAlphaF(0.15);
hoverBrush = QBrush(mix);
mix.setAlphaF(0.28);
clickBrush = QBrush(mix);
}
} else if (useButtonPalette || isWindowButton) {
if(needTranslucent)
{
if (isDark) {
startColor = option->palette.color(QPalette::Active, QPalette::Light);
endColor = option->palette.color(QPalette::Active, QPalette::Text);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Mid);
endColor = option->palette.color(QPalette::Active, QPalette::Dark);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
QColor clickColor = option->palette.color(QPalette::Active, QPalette::Dark);
if(isDark)
clickColor = option->palette.color(QPalette::Active, QPalette::Light);
clickColor.setAlphaF(isDark ? 0.30 : 0.30);
clickBrush.setColor(clickColor);
} else {
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
//hover
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
//click
clickBrush = QBrush(mixColor(button, mix, 0.2));
}
}
if (needTranslucent) {
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Mid);
disableBrush = option->palette.brush(QPalette::Active, QPalette::Mid);
if(isDark){
defaultBrush = option->palette.brush(QPalette::Active, QPalette::Text);
disableBrush = option->palette.brush(QPalette::Active, QPalette::Text);
}
QColor defaultColor = defaultBrush.color();
defaultColor.setAlphaF(0.15);
defaultBrush.setColor(defaultColor);
QColor disableColor = disableBrush.color();
disableColor.setAlphaF(0.1);
disableBrush.setColor(disableColor);
}
}
toolButtonParameters.toolButtonDefaultBrush = defaultBrush;
toolButtonParameters.toolButtonClickBrush = clickBrush;
toolButtonParameters.toolButtonHoverBrush = hoverBrush;
toolButtonParameters.toolButtonDisableBrush = disableBrush;
toolButtonParameters.toolButtonCheckBrush = checkBrush;
toolButtonParameters.toolButtonCheckHoverBrush = checkHoverBrush;
toolButtonParameters.toolButtonCheckClickBrush = checkClickBrush;
toolButtonParameters.toolButtonCheckDisableBrush = checkDisableBrush;
toolButtonParameters.toolButtonFocusPen = focusPen;
}
void KFashionStyleParameters::initLineEditParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
lineEditParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush focusBrush;
QBrush disableBrush;
QPen defaultPen;
QPen hoverPen;
QPen focusPen;
QPen disablePen;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
//default state
defaultBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
defaultPen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
//hover state
hoverBrush = defaultBrush;
hoverPen = defaultPen;
//focus state
focusBrush = option->palette.brush(QPalette::Active, QPalette::Base);
focusPen = QPen(option->palette.brush(QPalette::Active, QPalette::Highlight),
2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//disable state
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
disablePen = QPen(Qt::NoPen);
disablePen.setWidth(0);
if(needTranslucent)
{
QColor defaultColor = option->palette.color(QPalette::Active, QPalette::Mid);
if (isDark)
defaultColor = option->palette.color(QPalette::Active, QPalette::Text);
defaultColor.setAlphaF(isDark ? 0.1 : 0.15);
defaultBrush.setColor(defaultColor);
QColor focusColor = option->palette.color(QPalette::Active, QPalette::Base);
focusColor.setAlphaF(isDark ? 0.45 : 0.65);
focusBrush.setColor(focusColor);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
if (isDark) {
startColor = option->palette.color(QPalette::Active, QPalette::Light);
endColor = option->palette.color(QPalette::Active, QPalette::Text);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Mid);
endColor = option->palette.color(QPalette::Active, QPalette::Dark);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
}
lineEditParameters.lineEditDefaultBrush = defaultBrush;
lineEditParameters.lineEditHoverBrush = hoverBrush;
lineEditParameters.lineEditFocusBrush = focusBrush;
lineEditParameters.lineEditDisableBrush = disableBrush;
lineEditParameters.lineEditDefaultPen = defaultPen;
lineEditParameters.lineEditHoverPen = hoverPen;
lineEditParameters.lineEditFocusPen = focusPen;
lineEditParameters.lineEditDisablePen = disablePen;
}
void KFashionStyleParameters::initSpinBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget, bool isHorizonLayout)
{
spinBoxParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush focusBrush;
QBrush disableBrush;
QPen defaultPen;
QPen hoverPen;
QPen focusPen;
QPen disablePen;
QBrush upHoverBrush;
QBrush upFocusHoverBrush;
QBrush upClickBrush;
QBrush upDefaultBrush;
QBrush downHoverBrush;
QBrush downFocusHoverBrush;
QBrush downClickBrush;
QBrush downDefaultBrush;
//default state
defaultBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
defaultPen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
//hover state
hoverPen = defaultPen;
if(isHorizonLayout)
hoverPen.setWidth(2);
{//hoverBrush
QColor startColor;
QColor endColor;
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
QLinearGradient linearGradient;
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = option->palette.color(QPalette::Active, QPalette::Midlight);
endColor = option->palette.color(QPalette::Disabled, QPalette::NoRole);
startColor.setAlphaF(0.5);
endColor.setAlphaF(0.5);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Midlight);
endColor = mixColor(startColor, mix, 0.1);
startColor.setAlphaF(0.5);
endColor.setAlphaF(0.5);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
}
//focus state
focusBrush = option->palette.brush(QPalette::Active, QPalette::Base);
focusPen = QPen(option->palette.brush(QPalette::Active, QPalette::Highlight),
2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//disable state
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
disablePen = QPen(Qt::NoPen);
disablePen.setWidth(0);
if(isHorizonLayout)
{
upDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
downDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
}
else
{
upDefaultBrush = QBrush(Qt::NoBrush);
downDefaultBrush = QBrush(Qt::NoBrush);
}
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
QColor startColor;
QColor endColor;
QLinearGradient upLinearGradient;
upLinearGradient.setStart(option->rect.left(), option->rect.top());
upLinearGradient.setFinalStop(option->rect.left(), option->rect.center().y());
//up hover
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
upLinearGradient.setColorAt(0, startColor);
upLinearGradient.setColorAt(1, endColor);
upHoverBrush = QBrush(upLinearGradient);
//up focus hover
if (isDark) {
startColor = mixColor(highlight, QColor(Qt::white), 0.2);
endColor = mixColor(highlight, QColor(Qt::black), 0.05);
} else {
startColor = mixColor(highlight, QColor(Qt::white), 0.05);
endColor = mixColor(highlight, QColor(Qt::black), 0.2);
}
upLinearGradient.setColorAt(0, startColor);
upLinearGradient.setColorAt(1, endColor);
upFocusHoverBrush = QBrush(upLinearGradient);
//up click
upClickBrush = QBrush(mixColor(highlight, mix, 0.1));
QLinearGradient downLinearGradient;
downLinearGradient.setStart(option->rect.left(), option->rect.center().y());
downLinearGradient.setFinalStop(option->rect.left(), option->rect.bottom());
//down hover
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
downLinearGradient.setColorAt(0, startColor);
downLinearGradient.setColorAt(1, endColor);
downHoverBrush = QBrush(downLinearGradient);
//down focus hover
if (isDark) {
startColor = mixColor(highlight, QColor(Qt::white), 0.2);
endColor = mixColor(highlight, QColor(Qt::black), 0.05);
} else {
startColor = mixColor(highlight, QColor(Qt::white), 0.05);
endColor = mixColor(highlight, QColor(Qt::black), 0.2);
}
downLinearGradient.setColorAt(0, startColor);
downLinearGradient.setColorAt(1, endColor);
downFocusHoverBrush = QBrush(downLinearGradient);
//down click
downClickBrush = QBrush(mixColor(highlight, mix, 0.1));
spinBoxParameters.spinBoxDefaultBrush = defaultBrush;
spinBoxParameters.spinBoxHoverBrush = hoverBrush;
spinBoxParameters.spinBoxFocusBrush = focusBrush;
spinBoxParameters.spinBoxDisableBrush = disableBrush;
spinBoxParameters.spinBoxDefaultPen = defaultPen;
spinBoxParameters.spinBoxHoverPen = hoverPen;
spinBoxParameters.spinBoxFocusPen = focusPen;
spinBoxParameters.spinBoxDisablePen = disablePen;
spinBoxParameters.spinBoxUpDefaultBrush = upDefaultBrush;
spinBoxParameters.spinBoxUpHoverBrush = upHoverBrush;
spinBoxParameters.spinBoxUpFocusHoverBrush = upFocusHoverBrush;
spinBoxParameters.spinBoxUpClickBrush = upClickBrush;
spinBoxParameters.spinBoxDownHoverBrush = downHoverBrush;
spinBoxParameters.spinBoxDownFocusHoverBrush = downFocusHoverBrush;
spinBoxParameters.spinBoxDownClickBrush = downClickBrush;
spinBoxParameters.spinBoxDownDefaultBrush = downDefaultBrush;
}
void KFashionStyleParameters::initComboBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
comboBoxParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush onBrush;
QBrush editBrush;
QBrush disableBrush;
QPen defaultPen;
QPen hoverPen;
QPen onPen;
QPen editPen;
QPen disablePen;
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//default state
defaultBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
defaultPen = QPen(Qt::NoPen);
defaultPen.setWidth(0);
//hover state
if (isDark) {
hoverBrush = QBrush(mixColor(button, mix, 0.2));
} else {
hoverBrush = QBrush(mixColor(button, mix, 0.05));
}
hoverPen = QPen(Qt::NoPen);
hoverPen.setWidth(0);
//on state
if (isDark) {
onBrush = QBrush(mixColor(button, mix, 0.05));
} else {
onBrush = QBrush(mixColor(button, mix, 0.2));
}
onPen = QPen(Qt::NoPen);
onPen.setWidth(0);
//focus and on state,edit mode
editBrush = option->palette.brush(QPalette::Active, QPalette::Base);
editPen = QPen(option->palette.brush(QPalette::Active, QPalette::Highlight),
2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
//disable state
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
disablePen = QPen(Qt::NoPen);
disablePen.setWidth(0);
comboBoxParameters.comboBoxDefaultBrush = defaultBrush;
comboBoxParameters.comboBoxHoverBrush = hoverBrush;
comboBoxParameters.comboBoxOnBrush = onBrush;
comboBoxParameters.comboBoxEditBrush = editBrush;
comboBoxParameters.comboBoxDisableBrush = disableBrush;
comboBoxParameters.comboBoxDefaultPen = defaultPen;
comboBoxParameters.comboBoxHoverPen = hoverPen;
comboBoxParameters.comboBoxOnPen = onPen;
comboBoxParameters.comboBoxEditPen = editPen;
comboBoxParameters.comboBoxDisablePen = disablePen;
}
void KFashionStyleParameters::initListParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
listParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush selectBrush;
QBrush disableBrush;
QPen textHoverPen = QPen(Qt::NoPen);
QPen textSelectPen = QPen(Qt::NoPen);
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
//default
defaultBrush = QBrush(Qt::transparent);
//hover
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
//select
selectBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
//disable
disableBrush = QBrush(Qt::transparent);
const QStyleOptionViewItem *vi = qstyleoption_cast<const QStyleOptionViewItem *>(option);
QPalette::ColorGroup cg = vi->state & QStyle::State_Enabled
? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(vi->state & QStyle::State_Active))
cg = QPalette::Inactive;
if(needTranslucent)
{
if (isDark) {
startColor = option->palette.color(QPalette::Active, QPalette::Light);
endColor = option->palette.color(QPalette::Active, QPalette::Text);
startColor.setAlphaF(0.15);
endColor.setAlphaF(0.15);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Mid);
endColor = option->palette.color(QPalette::Active, QPalette::Dark);
startColor.setAlphaF(0.1);
endColor.setAlphaF(0.1);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
QColor selectColor = option->palette.color(QPalette::Active, QPalette::Dark);
if(isDark)
selectColor = option->palette.color(QPalette::Active, QPalette::Light);
selectColor.setAlphaF(isDark ? 0.20 : 0.25);
selectBrush.setColor(selectColor);
textSelectPen = option->palette.color(cg, QPalette::Text);
textHoverPen = option->palette.color(cg, QPalette::BrightText);
}
else
{
textSelectPen = option->palette.color(cg, QPalette::HighlightedText);
textHoverPen = option->palette.color(cg, QPalette::Text);
}
listParameters.listDefaultBrush = defaultBrush;
listParameters.listHoverBrush = hoverBrush;
listParameters.listSelectBrush = selectBrush;
listParameters.listDisableBrush = disableBrush;
listParameters.listTextHoverPen = textHoverPen;
listParameters.listTextSelectPen = textSelectPen;
}
void KFashionStyleParameters::initTreeParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
treeParameters.radius = 6;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush selectBrush;
QBrush disableBrush;
QBrush branchDefaultBrush;
QBrush branchHoverBrush;
QBrush branchSelectBrush;
QBrush branchDisableBrush;
//default
defaultBrush = QBrush(Qt::transparent);
branchDefaultBrush = defaultBrush;
//hover
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
branchHoverBrush = hoverBrush;
//select
selectBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
branchSelectBrush = selectBrush;
//disable
disableBrush = QBrush(Qt::transparent);
branchDisableBrush = disableBrush;
treeParameters.treeDefaultBrush = defaultBrush;
treeParameters.treeHoverBrush = hoverBrush;
treeParameters.treeSelectBrush = selectBrush;
treeParameters.treeDisableBrush = disableBrush;
treeParameters.treeBranchDefaultBrush = branchDefaultBrush;
treeParameters.treeBranchHoverBrush = branchHoverBrush;
treeParameters.treeBranchSelectBrush = branchSelectBrush;
treeParameters.treeBranchDisableBrush = branchDisableBrush;
}
void KFashionStyleParameters::initTableParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
tableParameters.radius = 0;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush selectBrush;
QBrush disableBrush;
//default
defaultBrush = QBrush(Qt::transparent);
//hover
QColor button = option->palette.color(QPalette::Active, QPalette::Button);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = mixColor(button, QColor(Qt::white), 0.2);
endColor = mixColor(button, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(button, QColor(Qt::black), 0.05);
endColor = mixColor(button, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
//select
selectBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
//disable
disableBrush = QBrush(Qt::transparent);
tableParameters.tableDefaultBrush = defaultBrush;
tableParameters.tableHoverBrush = hoverBrush;
tableParameters.tableSelectBrush = selectBrush;
tableParameters.tableDisableBrush = disableBrush;
}
void KFashionStyleParameters::initCheckBoxParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
checkBoxParameters.radius = 4;
QPen defaultPen;
QPen hoverPen;
QPen clickPen;
QPen disablePen;
QPen onDefaultPen;
QPen onHoverPen;
QPen onClickPen;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush clickBrush;
QBrush disableBrush;
QBrush onDefaultBrush;
QBrush onHoverBrush;
QBrush onClickBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//default
if (isDark) {
QColor col = option->palette.color(QPalette::Active, QPalette::BrightText);
col.setAlphaF(0.15);
defaultPen = QPen(col, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else {
defaultPen = QPen(option->palette.brush(QPalette::Disabled, QPalette::ButtonText),
1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
defaultBrush = QBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(200));
//hover
hoverPen = defaultPen;
if (isDark) {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
} else {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.05));
}
//click
clickPen = defaultPen;
if (isDark) {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.1));
} else {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
}
if(needTranslucent)
{
QColor defaultColor = option->palette.color(QPalette::Active, QPalette::Mid);
if(isDark)
defaultColor = option->palette.color(QPalette::Active, QPalette::Text);
defaultColor.setAlphaF(isDark ? 0.15 : 0.20);
defaultBrush.setColor(defaultColor);
QColor defaultPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
defaultPenColor.setAlphaF(0.3);
defaultPen = QPen(QBrush(defaultPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
if (isDark) {
startColor = option->palette.color(QPalette::Active, QPalette::Light);
endColor = option->palette.color(QPalette::Active, QPalette::Text);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Mid);
endColor = option->palette.color(QPalette::Active, QPalette::Dark);
startColor.setAlphaF(0.2);
endColor.setAlphaF(0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient);
hoverPen = defaultPen;
QColor clickColor = option->palette.color(QPalette::Active, QPalette::Dark);
if(isDark)
clickColor = option->palette.color(QPalette::Active, QPalette::Light);
clickColor.setAlphaF(0.30);
clickBrush.setColor(clickColor);
clickPen = defaultPen;
}
//disable
disablePen = defaultPen;
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
//on default
onDefaultPen = QPen(Qt::NoPen);
onDefaultPen.setWidth(0);
onDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
if(needTranslucent)
{
QColor onDefaultPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
onDefaultPenColor.setAlphaF(0.1);
onDefaultPen = QPen(QBrush(onDefaultPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
//on hover
onHoverPen = QPen(Qt::NoPen);
onHoverPen.setWidth(0);
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
if (isDark) {
startColor = mixColor(onDefaultBrush.color(), QColor(Qt::white), 0.2);
endColor = mixColor(onDefaultBrush.color(), QColor(Qt::black), 0.05);
} else {
startColor = mixColor(onDefaultBrush.color(), QColor(Qt::white), 0.05);
endColor = mixColor(onDefaultBrush.color(), QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
onHoverBrush = QBrush(linearGradient);
if(needTranslucent)
{
QColor onHoverPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
onHoverPenColor.setAlphaF(0.2);
onHoverPen = QPen(QBrush(onHoverPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
//on click
onClickPen = QPen(Qt::NoPen);
onClickPen.setWidth(0);
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.1));
if(needTranslucent)
{
QColor onClickPenColor = option->palette.color(QPalette::Active, QPalette::BrightText);
onClickPenColor.setAlphaF(0.2);
onClickPen = QPen(QBrush(onClickPenColor), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
checkBoxParameters.checkBoxDefaultPen = defaultPen;
checkBoxParameters.checkBoxHoverPen = hoverPen;
checkBoxParameters.checkBoxClickPen = clickPen;
checkBoxParameters.checkBoxDisablePen = disablePen;
checkBoxParameters.checkBoxOnDefaultPen = onDefaultPen;
checkBoxParameters.checkBoxOnHoverPen = onHoverPen;
checkBoxParameters.checkBoxOnClickPen = onClickPen;
checkBoxParameters.checkBoxDefaultBrush = defaultBrush;
checkBoxParameters.checkBoxHoverBrush = hoverBrush;
checkBoxParameters.checkBoxClickBrush = clickBrush;
checkBoxParameters.checkBoxDisableBrush = disableBrush;
checkBoxParameters.checkBoxOnDefaultBrush = onDefaultBrush;
checkBoxParameters.checkBoxOnHoverBrush = onHoverBrush;
checkBoxParameters.checkBoxOnClickBrush = onClickBrush;
}
void KFashionStyleParameters::initRadioButtonParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
radioButtonParameters.radius = 6;
QPen defaultPen;
QPen hoverPen;
QPen clickPen;
QPen disablePen;
QPen onDefaultPen;
QPen onHoverPen;
QPen onClickPen;
QBrush defaultBrush;
QBrush hoverBrush;
QBrush clickBrush;
QBrush disableBrush;
QBrush onDefaultBrush;
QBrush onHoverBrush;
QBrush onClickBrush;
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//default
if (isDark) {
QColor col = option->palette.color(QPalette::Active, QPalette::BrightText);
col.setAlphaF(0.15);
defaultPen = QPen(col, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else {
defaultPen = QPen(option->palette.brush(QPalette::Disabled, QPalette::ButtonText),
1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
}
defaultBrush = QBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(200));
//hover
hoverPen = defaultPen;
if (isDark) {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
} else {
hoverBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.05));
}
//click
clickPen = defaultPen;
if (isDark) {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.1));
} else {
clickBrush = QBrush(mixColor(defaultBrush.color(), mix, 0.15));
}
//disable
disablePen = defaultPen;
disableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
//on default
onDefaultPen = QPen(Qt::NoPen);
onDefaultPen.setWidth(0);
onDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Highlight);
//on hover
onHoverPen = QPen(Qt::NoPen);
onHoverPen.setWidth(0);
if (isDark) {
onHoverBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.2));
} else {
onHoverBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.05));
}
//on click
onClickPen = QPen(Qt::NoPen);
onClickPen.setWidth(0);
if (isDark) {
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.05));
} else {
onClickBrush = QBrush(mixColor(onDefaultBrush.color(), mix, 0.2));
}
//if set property
if (widget) {
if (widget->property("setDefaultPen").isValid() && widget->property("setDefaultPen").canConvert<QPen>()) {
defaultPen = widget->property("setDefaultPen").value<QPen>();
}
if (widget->property("setHoverPen").isValid() && widget->property("setHoverPen").canConvert<QPen>()) {
hoverPen = widget->property("setHoverPen").value<QPen>();
}
if (widget->property("setClickPen").isValid() && widget->property("setClickPen").canConvert<QPen>()) {
clickPen = widget->property("setClickPen").value<QPen>();
}
if (widget->property("setDisablePen").isValid() && widget->property("setDisablePen").canConvert<QPen>()) {
disablePen = widget->property("setDisablePen").value<QPen>();
}
if (widget->property("setOnDefaultPen").isValid() && widget->property("setOnDefaultPen").canConvert<QPen>()) {
onDefaultPen = widget->property("setOnDefaultPen").value<QPen>();
}
if (widget->property("setOnHoverPen").isValid() && widget->property("setOnHoverPen").canConvert<QPen>()) {
onHoverPen = widget->property("setOnHoverPen").value<QPen>();
}
if (widget->property("setOnClickPen").isValid() && widget->property("setOnClickPen").canConvert<QPen>()) {
onClickPen = widget->property("setOnClickPen").value<QPen>();
}
if (widget->property("setDefaultBrush").isValid() && widget->property("setDefaultBrush").canConvert<QBrush>()) {
defaultBrush = widget->property("setDefaultBrush").value<QBrush>();
}
if (widget->property("setHoverBrush").isValid() && widget->property("setHoverBrush").canConvert<QBrush>()) {
hoverBrush = widget->property("setHoverBrush").value<QBrush>();
}
if (widget->property("setClickBrush").isValid() && widget->property("setClickBrush").canConvert<QBrush>()) {
clickBrush = widget->property("setClickBrush").value<QBrush>();
}
if (widget->property("setDisableBrush").isValid() && widget->property("setDisableBrush").canConvert<QBrush>()) {
disableBrush = widget->property("setDisableBrush").value<QBrush>();
}
if (widget->property("setOnDefaultBrush").isValid() && widget->property("setOnDefaultBrush").canConvert<QBrush>()) {
onDefaultBrush = widget->property("setOnDefaultBrush").value<QBrush>();
}
if (widget->property("setOnHoverBrush").isValid() && widget->property("setOnHoverBrush").canConvert<QBrush>()) {
onHoverBrush = widget->property("setOnHoverBrush").value<QBrush>();
}
if (widget->property("setOnClickBrush").isValid() && widget->property("setOnClickBrush").canConvert<QBrush>()) {
onClickBrush = widget->property("setOnClickBrush").value<QBrush>();
}
}
radioButtonParameters.radioButtonDefaultPen = defaultPen;
radioButtonParameters.radioButtonHoverPen = hoverPen;
radioButtonParameters.radioButtonClickPen = clickPen;
radioButtonParameters.radioButtonDisablePen = disablePen;
radioButtonParameters.radioButtonOnDefaultPen = onDefaultPen;
radioButtonParameters.radioButtonOnHoverPen = onHoverPen;
radioButtonParameters.radioButtonOnClickPen = onClickPen;
radioButtonParameters.radioButtonDefaultBrush = defaultBrush;
radioButtonParameters.radioButtonHoverBrush = hoverBrush;
radioButtonParameters.radioButtonClickBrush = clickBrush;
radioButtonParameters.radioButtonDisableBrush = disableBrush;
radioButtonParameters.radioButtonOnDefaultBrush = onDefaultBrush;
radioButtonParameters.radioButtonOnHoverBrush = onHoverBrush;
radioButtonParameters.radioButtonOnClickBrush = onClickBrush;
}
void KFashionStyleParameters::initSliderParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
QBrush handleDefaultBrush;
QBrush handleHoverBrush;
QBrush handleClickBrush;
QBrush handleDisableBrush;
QBrush grooveValueDefaultBrush;
QBrush grooveValueHoverBrush;
QBrush grooveValueDisableBrush;
QBrush grooveUnvalueDefaultBrush;
QBrush grooveUnvalueHoverBrush;
QBrush grooveUnvalueDisableBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option);
QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
//handle default
handleDefaultBrush = option->palette.color(QPalette::Active, QPalette::Highlight);
//handle hover
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
if (slider->orientation == Qt::Vertical) {
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.topRight());
} else {
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
}
if (isDark) {
startColor = mixColor(highlight, QColor(Qt::white), 0.2);
endColor = mixColor(highlight, QColor(Qt::black), 0.05);
} else {
startColor = mixColor(highlight, QColor(Qt::white), 0.05);
endColor = mixColor(highlight, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
handleHoverBrush = QBrush(linearGradient);
//handle click
handleClickBrush = QBrush(mixColor(highlight, mix, 0.1));
//handle disable
handleDisableBrush = option->palette.color(QPalette::Disabled, QPalette::ButtonText);
//groove value default
if (isDark) {
grooveValueDefaultBrush = QBrush(mixColor(highlight, mix, 0.05));
} else {
grooveValueDefaultBrush = QBrush(mixColor(highlight, mix, 0.2));
}
//groove value hover
grooveValueHoverBrush = grooveValueDefaultBrush;
//groove value disable
grooveValueDisableBrush = handleDisableBrush;
//groove unvalue default
grooveUnvalueDefaultBrush = option->palette.color(QPalette::Active, QPalette::Button);
if(needTranslucent)
{
QColor color = option->palette.color(QPalette::Active, QPalette::BrightText);
color.setAlphaF(0.1);
grooveUnvalueDefaultBrush.setColor(color);
}
//groove unvalue hover
grooveUnvalueHoverBrush = grooveUnvalueDefaultBrush;
//groove unvalue disable
grooveUnvalueDisableBrush = grooveUnvalueDefaultBrush;
sliderParameters.sliderHandleDefaultBrush = handleDefaultBrush;
sliderParameters.sliderHandleHoverBrush = handleHoverBrush;
sliderParameters.sliderHandleClickBrush = handleClickBrush;
sliderParameters.sliderHandleDisableBrush = handleDisableBrush;
sliderParameters.sliderGrooveValueDefaultBrush = grooveValueDefaultBrush;
sliderParameters.sliderGrooveValueHoverBrush = grooveValueHoverBrush;
sliderParameters.sliderGrooveValueDisableBrush = grooveValueDisableBrush;
sliderParameters.sliderGrooveUnvalueDefaultBrush = grooveUnvalueDefaultBrush;
sliderParameters.sliderGrooveUnvalueHoverBrush = grooveUnvalueHoverBrush;
sliderParameters.sliderGrooveUnvalueDisableBrush = grooveUnvalueDisableBrush;
}
void KFashionStyleParameters::initProgressBarParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
QBrush contentBrush;
QBrush grooveDefaultBrush;
QBrush grooveDisableBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option);
const bool vertical = pb->orientation == Qt::Vertical;
const bool inverted = pb->invertedAppearance;
bool reverse = (!vertical && (pb->direction == Qt::RightToLeft)) || vertical;
if (inverted)
reverse = !reverse;
//content
QColor startColor = option->palette.color(QPalette::Active, QPalette::Highlight);
QColor endColor = option->palette.color(QPalette::Active, QPalette::Highlight).lighter(120);
QLinearGradient linearGradient;
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
if (vertical) {
if (reverse) {
linearGradient.setStart(pb->rect.bottomLeft());
linearGradient.setFinalStop(pb->rect.topLeft());
} else {
linearGradient.setStart(pb->rect.topLeft());
linearGradient.setFinalStop(pb->rect.bottomLeft());
}
} else {
if (reverse) {
linearGradient.setStart(pb->rect.topRight());
linearGradient.setFinalStop(pb->rect.topLeft());
} else {
linearGradient.setStart(pb->rect.topLeft());
linearGradient.setFinalStop(pb->rect.topRight());
}
}
contentBrush = QBrush(linearGradient);
//groove default
grooveDefaultBrush = pb->palette.brush(QPalette::Active, QPalette::Button);
if(needTranslucent)
{
QColor grooveDefaultColor = pb->palette.color(QPalette::Active, QPalette::BrightText);
grooveDefaultColor.setAlphaF(0.1);
grooveDefaultBrush.setColor(grooveDefaultColor);
}
//groove disable
grooveDisableBrush = pb->palette.brush(QPalette::Disabled, QPalette::Button);
progressBarParameters.radius = 6;
progressBarParameters.progressBarContentBrush = contentBrush;
progressBarParameters.progressBarGrooveDefaultBrush = grooveDefaultBrush;
progressBarParameters.progressBarGrooveDisableBrush = grooveDisableBrush;
}
void KFashionStyleParameters::initScrollBarParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
int sliderRadius;
QBrush grooveDefaultBrush;
QBrush grooveInactiveBrush;
QBrush sliderDefaultBrush;
QBrush sliderHoverBrush;
QBrush sliderClickBrush;
QBrush sliderDisableBrush;
bool needTranslucent = false;
if (widget && widget->property("needTranslucent").isValid()) {
needTranslucent = widget->property("needTranslucent").toBool();
}
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
const QStyleOptionSlider *bar = qstyleoption_cast<const QStyleOptionSlider *>(option);
//radius
if (bar->orientation == Qt::Horizontal) {
sliderRadius = (bar->rect.height()) / 4;
} else {
sliderRadius = (bar->rect.width()) / 4;
}
//groove default
grooveDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Base);
//groove inactive
grooveInactiveBrush = option->palette.brush(QPalette::Inactive, QPalette::Base);
//slider default
sliderDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Button);
//slider hover
QColor startColor;
QColor endColor;
QLinearGradient linearGradient;
if (bar->orientation == Qt::Horizontal) {
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.bottomLeft());
} else {
linearGradient.setStart(option->rect.topLeft());
linearGradient.setFinalStop(option->rect.topRight());
}
QColor color = option->palette.color(QPalette::Active, QPalette::Button);
if (isDark) {
startColor = mixColor(color, QColor(Qt::white), 0.2);
endColor = mixColor(color, QColor(Qt::white), 0.05);
} else {
startColor = mixColor(color, QColor(Qt::black), 0.05);
endColor = mixColor(color, QColor(Qt::black), 0.2);
}
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
sliderHoverBrush = QBrush(linearGradient);
//slider click
sliderClickBrush = QBrush(mixColor(sliderDefaultBrush.color(), mix, 0.2));
//slider disable
sliderDisableBrush = option->palette.brush(QPalette::Disabled, QPalette::Button);
if(needTranslucent)
{
QColor grooveDefaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
grooveDefaultColor.setAlphaF(0.05);
grooveDefaultBrush = QBrush(grooveDefaultColor);
QColor grooveInactiveColor = option->palette.color(QPalette::Active, QPalette::BrightText);
grooveInactiveColor.setAlphaF(0.05);
grooveInactiveBrush = QBrush(grooveInactiveColor);
QColor sliderDefaultColor = option->palette.color(QPalette::Active, QPalette::BrightText);
sliderDefaultColor.setAlphaF(0.10);
sliderDefaultBrush = QBrush(sliderDefaultColor);
QColor sliderHoverColor = option->palette.color(QPalette::Active, QPalette::BrightText);
sliderHoverColor.setAlphaF(0.2);
sliderHoverBrush = QBrush(sliderHoverColor);
QColor sliderClickColor = option->palette.color(QPalette::Active, QPalette::BrightText);
sliderClickColor.setAlphaF(0.3);
sliderClickBrush = QBrush(sliderClickColor);
}
scrollBarParameters.radius = sliderRadius;
scrollBarParameters.scrollBarGrooveDefaultBrush = grooveDefaultBrush;
scrollBarParameters.scrollBarGrooveInactiveBrush = grooveInactiveBrush;
scrollBarParameters.scrollBarSliderDefaultBrush = sliderDefaultBrush;
scrollBarParameters.scrollBarSliderHoverBrush = sliderHoverBrush;
scrollBarParameters.scrollBarSliderClickBrush = sliderClickBrush;
scrollBarParameters.scrollBarSliderDisableBrush = sliderDisableBrush;
}
void KFashionStyleParameters::initToolTipParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
QBrush backgroundBrush;
//background
backgroundBrush = option->palette.color(QPalette::Active, QPalette::ToolTipBase);
toolTipParameters.radius = 6;
toolTipParameters.toolTipBackgroundBrush = backgroundBrush;
}
void KFashionStyleParameters::initTabWidgetParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
int tabradius = 6;
QBrush widgetBackgroundBrush;
QBrush tabBarBackgroundBrush;
QBrush tabBarDefaultBrush;
QBrush tabBarHoverBrush;
QBrush tabBarSelectBrush;
//tab widget background
widgetBackgroundBrush = option->palette.brush(QPalette::Active, QPalette::Base);
//tabbar background
tabBarBackgroundBrush = option->palette.brush(QPalette::Active, QPalette::Window);
//tabbar default
tabBarDefaultBrush = option->palette.brush(QPalette::Active, QPalette::Window);
//tabbar hover
QColor hover_color = option->palette.color(QPalette::Active, QPalette::Window);
QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText);
tabBarHoverBrush = QBrush(mixColor(hover_color, mix, 0.1));
//tabbar select
tabBarSelectBrush = option->palette.brush(QPalette::Active, QPalette::Base);
if (widget && widget->property("setRadius").isValid() && widget->property("setRadius").canConvert<int>()) {
tabradius = widget->property("setRadius").value<int>();
}
tabWidgetParameters.radius = tabradius;
tabWidgetParameters.tabWidgetBackgroundBrush = widgetBackgroundBrush;
tabWidgetParameters.tabBarBackgroundBrush = tabBarBackgroundBrush;
tabWidgetParameters.tabBarDefaultBrush = tabBarDefaultBrush;
tabWidgetParameters.tabBarHoverBrush = tabBarHoverBrush;
tabWidgetParameters.tabBarSelectBrush = tabBarSelectBrush;
}
void KFashionStyleParameters::initMenuParameters(bool isDark, const QStyleOption *option, const QWidget *widget)
{
int frameradius = 8;
int itemradius = 6;
QPixmap framePixmap(option->rect.size());
QBrush itemSelectBrush;
//frame Pixmap
framePixmap.fill(Qt::transparent);
QRect drawRect;
if (qobject_cast<const QFrame*>(widget)) {
//path has 1px blank on right and bottom
drawRect = option->rect.adjusted(0, 0, 1, 1);
QPainterPath drawRectPath;
drawRectPath.moveTo(drawRect.left(), drawRect.top() + frameradius);
drawRectPath.arcTo(QRect(drawRect.left(), drawRect.top(), 2 * frameradius, 2 * frameradius), 180, -90);
drawRectPath.lineTo(drawRect.right() - frameradius, drawRect.top());
drawRectPath.arcTo(QRect(drawRect.right() - 2 * frameradius, drawRect.top(), 2 * frameradius, 2 * frameradius), 90, -90);
drawRectPath.lineTo(drawRect.right(), drawRect.bottom() - 28);
drawRectPath.arcTo(QRect(drawRect.right() - 2 * 20, drawRect.bottom() - 2 * 28, 2 * 20, 2 * 28), 0, -90);
drawRectPath.lineTo(drawRect.left() + frameradius, drawRect.bottom());
drawRectPath.arcTo(QRect(drawRect.left(), drawRect.bottom() - 2 * frameradius, 2 * frameradius, 2 * frameradius), -90, -90);
drawRectPath.lineTo(drawRect.left(), drawRect.top() + frameradius);
QPainter pixmapPainter(&framePixmap);
pixmapPainter.setPen(Qt::NoPen);
pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(180));
pixmapPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter.drawPath(drawRectPath);
pixmapPainter.end();
QPainterPath drawRightBottomPath;
drawRightBottomPath.moveTo(drawRect.right(), drawRect.bottom() - 28);
drawRightBottomPath.arcTo(QRect(drawRect.right() - 2 * 20, drawRect.bottom() - 2 * 28, 2 * 20, 2 * 28), 0, -90);
drawRightBottomPath.lineTo(drawRect.right() - frameradius, drawRect.bottom());
drawRightBottomPath.arcTo(QRect(drawRect.right() - 2 * frameradius, drawRect.bottom() - 2 * frameradius, 2 * frameradius, 2 * frameradius), -90, 90);
drawRightBottomPath.lineTo(drawRect.right(), drawRect.bottom() - 28);
//draw right bottom corner
QColor startColor = option->palette.color(QPalette::Active, QPalette::Base).lighter(300);
QColor endColor = mixColor(startColor, QColor(Qt::black), 0.25);
QLinearGradient linearGradient;
QPainter pixmapPainter2(&framePixmap);
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
linearGradient.setStart(drawRect.right(), drawRect.bottom() - 28);
linearGradient.setFinalStop(drawRect.right(), drawRect.bottom());
pixmapPainter2.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter2.setPen(Qt::transparent);
pixmapPainter2.setBrush(linearGradient);
pixmapPainter2.drawPath(drawRightBottomPath);
} else {
int rander = 2;
drawRect = option->rect.adjusted(+rander, +rander+6, -rander, -rander-6);
// Draw a black floor
QPainter pixmapPainter(&framePixmap);
pixmapPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter.setPen(Qt::transparent);
pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::BrightText));
pixmapPainter.drawRoundedRect(drawRect.adjusted(1, 1, -1, -1), frameradius, frameradius);
pixmapPainter.end();
// Blur the black background
QImage img = framePixmap.toImage();
qt_blurImage(img, 4, false, false);
// Dig out the center part, Shadow rendering
framePixmap = QPixmap::fromImage(img);
QPainter pixmapPainter2(&framePixmap);
pixmapPainter2.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear);
pixmapPainter2.setPen(Qt::transparent);
pixmapPainter2.setBrush(Qt::transparent);
pixmapPainter2.drawRoundedRect(drawRect.adjusted(1, 1, -1, -1), frameradius, frameradius);
pixmapPainter2.end();
//That's when I started drawing the frame floor
QColor color = option->palette.color(QPalette::Base);
QColor startColor;
QColor endColor;
if (isDark) {
endColor = option->palette.color(QPalette::Active, QPalette::Base).lighter(300);
startColor = mixColor(endColor, QColor(Qt::white), 0.2);
} else {
startColor = option->palette.color(QPalette::Active, QPalette::Base).lighter(300);
endColor = mixColor(startColor, QColor(Qt::black), 0.2);
}
if (UKUIStyleSettings::isSchemaInstalled("org.ukui.style")) {
auto opacity = UKUIStyleSettings::globalInstance()->get("menuTransparency").toInt()/100.0;
color.setAlphaF(opacity);
startColor.setAlphaF(opacity);
endColor.setAlphaF(opacity);
}
if (qApp->property("blurEnable").isValid()) {
bool blurEnable = qApp->property("blurEnable").toBool();
if (!blurEnable) {
color.setAlphaF(1);
startColor.setAlphaF(1);
endColor.setAlphaF(1);
}
}
if (widget) {
if (widget->property("useSystemStyleBlur").isValid() && !widget->property("useSystemStyleBlur").toBool()) {
color.setAlphaF(1);
startColor.setAlphaF(1);
endColor.setAlphaF(1);
}
}
//if blur effect is not supported, do not use transparent color.
if (!KWindowEffects::isEffectAvailable(KWindowEffects::BlurBehind) || blackAppListWithBlurHelper().contains(qAppName())) {
color.setAlphaF(1);
startColor.setAlphaF(1);
endColor.setAlphaF(1);
}
QRegion region;
if (widget) {
region = widget->mask();
}
if (!region.isEmpty()) {
QPainterPath path;
path.addRegion(region);
//draw blur background
QPainter pixmapPainter3(&framePixmap);
pixmapPainter3.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter3.setPen(Qt::transparent);
pixmapPainter3.setBrush(color);
pixmapPainter3.drawPath(path);
} else {
//path has 1px blank on right and bottom
drawRect.adjust(0, 0, 1, 1);
QPainterPath drawRectPath;
drawRectPath.moveTo(drawRect.left(), drawRect.top() + frameradius);
drawRectPath.arcTo(QRect(drawRect.left(), drawRect.top(), 2 * frameradius, 2 * frameradius), 180, -90);
drawRectPath.lineTo(drawRect.right() - frameradius, drawRect.top());
drawRectPath.arcTo(QRect(drawRect.right() - 2 * frameradius, drawRect.top(), 2 * frameradius, 2 * frameradius), 90, -90);
drawRectPath.lineTo(drawRect.right(), drawRect.bottom() - 28);
drawRectPath.arcTo(QRect(drawRect.right() - 2 * 20, drawRect.bottom() - 2 * 28, 2 * 20, 2 * 28), 0, -90);
drawRectPath.lineTo(drawRect.left() + frameradius, drawRect.bottom());
drawRectPath.arcTo(QRect(drawRect.left(), drawRect.bottom() - 2 * frameradius, 2 * frameradius, 2 * frameradius), -90, -90);
drawRectPath.lineTo(drawRect.left(), drawRect.top() + frameradius);
//draw blur background
QPainter pixmapPainter3(&framePixmap);
pixmapPainter3.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter3.setPen(Qt::transparent);
pixmapPainter3.setBrush(color);
pixmapPainter3.drawPath(drawRectPath);
pixmapPainter3.end();
QPainterPath drawRightBottomPath;
drawRightBottomPath.moveTo(drawRect.right(), drawRect.bottom() - 28);
drawRightBottomPath.arcTo(QRect(drawRect.right() - 2 * 20, drawRect.bottom() - 2 * 28, 2 * 20, 2 * 28), 0, -90);
drawRightBottomPath.lineTo(drawRect.right() - frameradius, drawRect.bottom());
drawRightBottomPath.arcTo(QRect(drawRect.right() - 2 * frameradius, drawRect.bottom() - 2 * frameradius, 2 * frameradius, 2 * frameradius), -90, 90);
drawRightBottomPath.lineTo(drawRect.right(), drawRect.bottom() - 28);
//draw right bottom corner
QLinearGradient linearGradient;
linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor);
linearGradient.setStart(drawRect.right(), drawRect.bottom() - 28);
linearGradient.setFinalStop(drawRect.right(), drawRect.bottom());
QPainter pixmapPainter4(&framePixmap);
pixmapPainter4.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter4.setPen(Qt::transparent);
pixmapPainter4.setBrush(linearGradient);
pixmapPainter4.drawPath(drawRightBottomPath);
}
}
//item select brush
itemSelectBrush = QBrush(option->palette.brush(QPalette::Active, QPalette::Highlight));
menuParameters.frameRadius = frameradius;
menuParameters.itemRadius = itemradius;
menuParameters.menuFramePixmap = framePixmap;
menuParameters.menuItemSelectBrush = itemSelectBrush;
}