Qt CSS allows to read palette colors by using "palette(role)" but the supported roles haven't been updated since at least Qt 5.12, therefore placeholder-text and accent are not recognized. An "accent-color" property has been added to *set* the accent color on an object when it was introduced but it wasn't possible to *read* the accent color, even though it was documented to work. For sake of completeness, add tooltip-base and tooltip-text as well. Also amend the comment in QPalette to mention QCss and add a static_assert so this doesn't happen again. Pick-to: 6.9 6.9.0 6.8 Change-Id: I59ed09dc91fa18ca0356857c8ddb43946b309035 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
170 lines
7.4 KiB
C++
170 lines
7.4 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
|
|
|
#ifndef QPALETTE_H
|
|
#define QPALETTE_H
|
|
|
|
#include <QtGui/qtguiglobal.h>
|
|
#include <QtGui/qwindowdefs.h>
|
|
#include <QtGui/qcolor.h>
|
|
#include <QtGui/qbrush.h>
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
class QPalettePrivate;
|
|
class QVariant;
|
|
|
|
class Q_GUI_EXPORT QPalette
|
|
{
|
|
Q_GADGET
|
|
public:
|
|
QPalette();
|
|
QPalette(const QColor &button);
|
|
QPalette(Qt::GlobalColor button);
|
|
QPalette(const QColor &button, const QColor &window);
|
|
QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light,
|
|
const QBrush &dark, const QBrush &mid, const QBrush &text,
|
|
const QBrush &bright_text, const QBrush &base, const QBrush &window);
|
|
QPalette(const QColor &windowText, const QColor &window, const QColor &light,
|
|
const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
|
|
QPalette(const QPalette &palette);
|
|
~QPalette();
|
|
QPalette &operator=(const QPalette &palette);
|
|
QPalette(QPalette &&other) noexcept
|
|
: d(std::exchange(other.d, nullptr)), currentGroup(other.currentGroup)
|
|
{}
|
|
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPalette)
|
|
|
|
void swap(QPalette &other) noexcept
|
|
{
|
|
std::swap(currentGroup, other.currentGroup);
|
|
qt_ptr_swap(d, other.d);
|
|
}
|
|
|
|
operator QVariant() const;
|
|
|
|
// Do not change the order, the serialization format depends on it
|
|
// Ensure these values are kept in sync with QQuickColorGroup's properties
|
|
// and QCss::KnownValue!
|
|
enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
|
|
Q_ENUM(ColorGroup)
|
|
enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
|
|
Text, BrightText, ButtonText, Base, Window, Shadow,
|
|
Highlight, HighlightedText,
|
|
Link, LinkVisited,
|
|
AlternateBase,
|
|
NoRole,
|
|
ToolTipBase, ToolTipText,
|
|
PlaceholderText,
|
|
Accent,
|
|
NColorRoles = Accent + 1,
|
|
};
|
|
Q_ENUM(ColorRole)
|
|
|
|
inline ColorGroup currentColorGroup() const { return currentGroup; }
|
|
inline void setCurrentColorGroup(ColorGroup cg) { currentGroup = cg; }
|
|
|
|
inline const QColor &color(ColorGroup cg, ColorRole cr) const
|
|
{ return brush(cg, cr).color(); }
|
|
const QBrush &brush(ColorGroup cg, ColorRole cr) const;
|
|
inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
|
|
inline void setColor(ColorRole cr, const QColor &color);
|
|
inline void setBrush(ColorRole cr, const QBrush &brush);
|
|
bool isBrushSet(ColorGroup cg, ColorRole cr) const;
|
|
void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
|
|
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
|
|
const QBrush &light, const QBrush &dark, const QBrush &mid,
|
|
const QBrush &text, const QBrush &bright_text, const QBrush &base,
|
|
const QBrush &window);
|
|
bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
|
|
|
|
inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
|
|
inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
|
|
inline const QBrush &windowText() const { return brush(WindowText); }
|
|
inline const QBrush &button() const { return brush(Button); }
|
|
inline const QBrush &light() const { return brush(Light); }
|
|
inline const QBrush &dark() const { return brush(Dark); }
|
|
inline const QBrush &mid() const { return brush(Mid); }
|
|
inline const QBrush &text() const { return brush(Text); }
|
|
inline const QBrush &base() const { return brush(Base); }
|
|
inline const QBrush &alternateBase() const { return brush(AlternateBase); }
|
|
inline const QBrush &toolTipBase() const { return brush(ToolTipBase); }
|
|
inline const QBrush &toolTipText() const { return brush(ToolTipText); }
|
|
inline const QBrush &window() const { return brush(Window); }
|
|
inline const QBrush &midlight() const { return brush(Midlight); }
|
|
inline const QBrush &brightText() const { return brush(BrightText); }
|
|
inline const QBrush &buttonText() const { return brush(ButtonText); }
|
|
inline const QBrush &shadow() const { return brush(Shadow); }
|
|
inline const QBrush &highlight() const { return brush(Highlight); }
|
|
inline const QBrush &highlightedText() const { return brush(HighlightedText); }
|
|
inline const QBrush &link() const { return brush(Link); }
|
|
inline const QBrush &linkVisited() const { return brush(LinkVisited); }
|
|
inline const QBrush &placeholderText() const { return brush(PlaceholderText); }
|
|
inline const QBrush &accent() const { return brush(Accent); }
|
|
|
|
bool operator==(const QPalette &p) const;
|
|
inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
|
|
bool isCopyOf(const QPalette &p) const;
|
|
|
|
qint64 cacheKey() const;
|
|
|
|
QPalette resolve(const QPalette &other) const;
|
|
|
|
using ResolveMask = quint64;
|
|
ResolveMask resolveMask() const;
|
|
void setResolveMask(ResolveMask mask);
|
|
|
|
private:
|
|
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
|
|
const QBrush &light, const QBrush &dark, const QBrush &mid,
|
|
const QBrush &text, const QBrush &bright_text,
|
|
const QBrush &base, const QBrush &alternate_base,
|
|
const QBrush &window, const QBrush &midlight,
|
|
const QBrush &button_text, const QBrush &shadow,
|
|
const QBrush &highlight, const QBrush &highlighted_text,
|
|
const QBrush &link, const QBrush &link_visited);
|
|
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
|
|
const QBrush &light, const QBrush &dark, const QBrush &mid,
|
|
const QBrush &text, const QBrush &bright_text,
|
|
const QBrush &base, const QBrush &alternate_base,
|
|
const QBrush &window, const QBrush &midlight,
|
|
const QBrush &button_text, const QBrush &shadow,
|
|
const QBrush &highlight, const QBrush &highlighted_text,
|
|
const QBrush &link, const QBrush &link_visited,
|
|
const QBrush &toolTipBase, const QBrush &toolTipText);
|
|
void init();
|
|
void detach();
|
|
|
|
QPalettePrivate *d;
|
|
ColorGroup currentGroup{Active};
|
|
|
|
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
|
|
};
|
|
|
|
Q_DECLARE_SHARED(QPalette)
|
|
|
|
inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
|
|
const QColor &acolor)
|
|
{ setBrush(acg, acr, QBrush(acolor)); }
|
|
inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
|
|
{ setColor(All, acr, acolor); }
|
|
inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
|
|
{ setBrush(All, acr, abrush); }
|
|
|
|
/*****************************************************************************
|
|
QPalette stream functions
|
|
*****************************************************************************/
|
|
#ifndef QT_NO_DATASTREAM
|
|
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
|
|
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
|
|
#endif // QT_NO_DATASTREAM
|
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
|
|
#endif
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
#endif // QPALETTE_H
|