17#include <qpa/qwindowsysteminterface.h>
47QBrush QGtk3Storage::brush(
const Source &
source,
const BrushMap &
map)
const
49 switch (
source.sourceType) {
51 return m_interface ?
QBrush(m_interface->brush(
source.gtk3.gtkWidgetType,
69 (
c.green() +
source.rec.deltaGreen),
70 (
c.blue() +
source.rec.deltaBlue));
76 return source.fix.fixedBrush;
96#define FIND(brush) if (map.contains(brush))\
97 return map.value(brush)
129 QColor backgroundColor(0xd4, 0xd0, 0xc8);
132 const QBrush darkBrush(darkColor);
155 if (m_paletteCache[
type].has_value()) {
156 qCDebug(lcQGtk3Interface) <<
"Returning palette from cache:"
159 return &m_paletteCache[
type].value();
168 qCDebug(lcQGtk3Interface) <<
"Returning system palette for unknown type"
180 for (
auto i = brushes.
begin();
i != brushes.
end(); ++
i) {
186 const auto appSource =
i.key().colorScheme;
188 const bool setBrush = (appSource == appTheme) ||
193 p.setBrush(
i.key().colorGroup,
i.key().colorRole,
brush(
source, brushes));
197 m_paletteCache[
type].emplace(
p);
201 return &m_paletteCache[
type].value();
212 if (m_fontCache[
type].has_value())
213 return &m_fontCache[
type].value();
215 m_fontCache[
type].emplace(m_interface->font(
type));
216 return &m_fontCache[
type].value();
249 return m_interface ? m_interface->fileIcon(fileInfo) :
QIcon();
256void QGtk3Storage::clear()
260 for (
auto &
cache : m_paletteCache)
263 for (
auto &
cache : m_fontCache)
335 if (m_themeName == newThemeName)
345 qCDebug(lcQGtk3Interface) <<
"GTK theme initialized:" << newThemeName << m_colorScheme;
347 qCDebug(lcQGtk3Interface) <<
"GTK theme changed to:" << newThemeName << m_colorScheme;
349 m_themeName = newThemeName;
354 if (load(jsonInput)) {
357 qWarning() <<
"Falling back to standard GTK mapping.";
364 if (!jsonOutput.
isEmpty() && !save(jsonOutput))
365 qWarning() <<
"File" << jsonOutput <<
"could not be saved.\n";
386 for (
auto paletteIterator =
map.
begin(); paletteIterator !=
map.
end();
389 for (
auto brushIterator = bm.
begin(); brushIterator != bm.
end();
392 switch (
s.sourceType) {
397 s.fix.fixedBrush = fixedBrush;
443bool QGtk3Storage::load(
const QString &filename)
455void QGtk3Storage::createMapping()
462#define GTK(wtype, colorSource, state)\
463 source = Source(QGtk3Interface::QGtkWidget::gtk_ ##wtype,\
464 QGtk3Interface::QGtkColorSource::colorSource, GTK_STATE_FLAG_ ##state)
467#define LIGHTER(group, role, lighter)\
468 source = Source(QPalette::group, QPalette::role,\
469 Qt::ColorScheme::Unknown, lighter)
470#define MODIFY(group, role, red, green, blue)\
471 source = Source(QPalette::group, QPalette::role,\
472 Qt::ColorScheme::Unknown, red, green, blue)
475#define FIX(color) source = FixedSource(color);
479#define ADD_2(group, role) map.insert(TargetBrush(QPalette::group, QPalette::role), source);
480#define ADD_3(group, role, app) map.insert(TargetBrush(QPalette::group, QPalette::role,\
481 Qt::ColorScheme::app), source);
482#define ADD_X(x, group, role, app, FUNC, ...) FUNC
483#define ADD(...) ADD_X(,##__VA_ARGS__, ADD_3(__VA_ARGS__), ADD_2(__VA_ARGS__))
485#define SAVE(palette) m_palettes.insert(QPlatformTheme::palette, map)
487#define CLEAR map.clear()
541 ADD(Inactive, WindowText);
545 ADD(Inactive, ButtonText);
555 ADD(Inactive, HighlightedText);
572 ADD(
All, PlaceholderText, Light);
574 ADD(
All, PlaceholderText, Dark);
585 SAVE(CheckBoxPalette);
586 SAVE(RadioButtonPalette);
590 GTK(combo_box, Text, NORMAL);
593 GTK(combo_box, Text, ACTIVE);
596 SAVE(ComboBoxPalette);
597 SAVE(GroupBoxPalette);
609 SAVE(TextLineEditPalette);
bool contains(const Key &key) const noexcept
T * object(const Key &key) const noexcept
bool insert(const Key &key, T *object, qsizetype cost=1)
The QColor class provides colors based on RGB, HSV or CMYK values.
QColor darker(int f=200) const noexcept
QColor lighter(int f=150) const noexcept
\inmodule QtCore \reentrant
bool contains(const Key &key) const
T value(const Key &key, const T &defaultValue) const
The QGtk3Interface class centralizes communication with the GTK3 library.
static bool save(const QGtk3Storage::PaletteMap &map, const QString &fileName, QJsonDocument::JsonFormat format=QJsonDocument::Indented)
static bool load(QGtk3Storage::PaletteMap &map, const QString &fileName)
static QLatin1String fromPalette(QPlatformTheme::Palette palette)
void handleThemeChange()
Handles a theme change at runtime.
const QPalette * palette(QPlatformTheme::Palette=QPlatformTheme::SystemPalette) const
Return a GTK styled QPalette.
QFlatMap< QPlatformTheme::Palette, BrushMap > PaletteMap
static QPalette standardPalette()
Returns a simple, hard coded base palette.
const QString themeName() const
Qt::ColorScheme colorScheme() const
QFlatMap< TargetBrush, Source > BrushMap
QIcon fileIcon(const QFileInfo &fileInfo) const
Returns a GTK styled file icon corresponding to.
void populateMap()
Populates a map with information about how to locate colors in GTK.
const QFont * font(QPlatformTheme::Font type) const
Return a GTK styled font.
QPixmap standardPixmap(QPlatformTheme::StandardPixmap standardPixmap, const QSizeF &size) const
Return a GTK styled standard pixmap if available.
The QIcon class provides scalable icons in different modes and states.
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore\reentrant
The QPalette class contains color groups for each widget state.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static void handleThemeChange(QWindow *window=nullptr)
[Window class with invokable method]
QMap< QString, QString > map
[6]
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
#define SAVE(src, state, prop, def)
#define GTK(wtype, colorSource, state)
#define LIGHTER(group, role, lighter)
#define MODIFY(group, role, red, green, blue)
#define qCDebug(category,...)
GLboolean GLboolean GLboolean b
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei GLsizei GLchar * source
static QT_BEGIN_NAMESPACE const uint Default
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)