Add QDSTheme to theming and use it in ManhattanStyle

Change-Id: If3f634cd96665150b27605eaf7a2a5d4ea7078b6
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Thomas Hartmann
2023-01-30 17:25:10 +01:00
parent 0078b47c8d
commit 724eb54387
5 changed files with 29 additions and 3 deletions

View File

@@ -513,3 +513,4 @@ FlatMenuBar=true
ToolBarIconShadow=true
WindowColorAsBase=false
DarkUserInterface=true
QDSTheme=true

View File

@@ -101,6 +101,14 @@ QColor StyleHelper::baseColor(bool lightColored)
return (lightColored || windowColorAsBase) ? windowColor : m_baseColor;
}
QColor StyleHelper::toolbarBaseColor(bool lightColored)
{
if (creatorTheme()->flag(Theme::QDSTheme))
return creatorTheme()->color(Utils::Theme::DStoolbarBackground);
else
return StyleHelper::baseColor(lightColored);
}
QColor StyleHelper::highlightColor(bool lightColored)
{
QColor result = baseColor(lightColored);
@@ -626,6 +634,11 @@ QLinearGradient StyleHelper::statusBarGradient(const QRect &statusBarRect)
return grad;
}
bool StyleHelper::isQDSTheme()
{
return creatorTheme()->flag(Theme::QDSTheme);
}
QIcon StyleHelper::getIconFromIconFont(const QString &fontName, const QList<IconFontHelper> &parameters)
{
QFontDatabase a;

View File

@@ -33,6 +33,7 @@ public:
// This is our color table, all colors derive from baseColor
static QColor requestedBaseColor() { return m_requestedBaseColor; }
static QColor baseColor(bool lightColored = false);
static QColor toolbarBaseColor(bool lightColored = false);
static QColor panelTextColor(bool lightColored = false);
static QColor highlightColor(bool lightColored = false);
static QColor shadowColor(bool lightColored = false);
@@ -72,6 +73,8 @@ public:
static void tintImage(QImage &img, const QColor &tintColor);
static QLinearGradient statusBarGradient(const QRect &statusBarRect);
static bool isQDSTheme();
class IconFontHelper
{
public:

View File

@@ -448,7 +448,8 @@ public:
FlatMenuBar,
ToolBarIconShadow,
WindowColorAsBase,
DarkUserInterface
DarkUserInterface,
QDSTheme
};
Q_ENUM(Color)

View File

@@ -522,9 +522,16 @@ int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
case PM_ButtonShiftHorizontal:
case PM_MenuBarPanelWidth:
case PM_ToolBarItemMargin:
if (StyleHelper::isQDSTheme()) {
retval = 0;
break;
}
[[fallthrough]];
case PM_ToolBarItemSpacing:
if (panelWidget(widget))
retval = 0;
if (StyleHelper::isQDSTheme())
retval = 4;
break;
case PM_DefaultFrameWidth:
if (qobject_cast<const QLineEdit*>(widget) && panelWidget(widget))
@@ -1030,7 +1037,7 @@ void ManhattanStyle::drawPrimitiveForPanelWidget(PrimitiveElement element,
break;
case PE_IndicatorToolBarSeparator:
{
if (!StyleHelper::isQDSTheme()) {
QRect separatorRect = rect;
separatorRect.setLeft(rect.width() / 2);
separatorRect.setWidth(1);
@@ -1147,6 +1154,7 @@ void ManhattanStyle::drawControlForQmlEditor(ControlElement element,
QPainter *painter,
const QWidget *widget) const
{
Q_UNUSED(element)
if (const auto mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
painter->save();
const int iconHeight = pixelMetric(QStyle::PM_SmallIconSize, option, widget);
@@ -1518,7 +1526,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
bool drawLightColored = lightColored(widget);
// draws the background of the 'Type hierarchy', 'Projects' headers
if (creatorTheme()->flag(Theme::FlatToolBars))
painter->fillRect(rect, StyleHelper::baseColor(drawLightColored));
painter->fillRect(rect, StyleHelper::toolbarBaseColor(drawLightColored));
else if (horizontal)
StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
else