17#include <qpa/qwindowsysteminterface.h>
50QBrush QGtk3Storage::brush(
const Source &
source,
const BrushMap &
map)
const
52 switch (
source.sourceType) {
54 return m_interface ?
QBrush(m_interface->brush(
source.gtk3.gtkWidgetType,
72 (
c.green() +
source.rec.deltaGreen),
73 (
c.blue() +
source.rec.deltaBlue));
79 return source.fix.fixedBrush;
99#define FIND(brush) if (map.contains(brush))\
100 return map.value(brush)
132 QColor backgroundColor(0xd4, 0xd0, 0xc8);
135 const QBrush darkBrush(darkColor);
158 if (m_paletteCache[
type].has_value()) {
159 qCDebug(lcQGtk3Interface) <<
"Returning palette from cache:"
162 return &m_paletteCache[
type].value();
171 qCDebug(lcQGtk3Interface) <<
"Returning system palette for unknown type"
183 for (
auto i = brushes.
begin();
i != brushes.
end(); ++
i) {
189 const auto appSource =
i.key().colorScheme;
191 const bool setBrush = (appSource == appTheme) ||
196 p.setBrush(
i.key().colorGroup,
i.key().colorRole,
brush(
source, brushes));
200 m_paletteCache[
type].emplace(
p);
204 return &m_paletteCache[
type].value();
215 if (m_fontCache[
type].has_value())
216 return &m_fontCache[
type].value();
218 m_fontCache[
type].emplace(m_interface->font(
type));
219 return &m_fontCache[
type].value();
252 return m_interface ? m_interface->fileIcon(fileInfo) :
QIcon();
259void QGtk3Storage::clear()
263 for (
auto &
cache : m_paletteCache)
266 for (
auto &
cache : m_fontCache)
342 newColorScheme = m_portalInterface->colorScheme();
351 if (m_themeName == newThemeName && m_colorScheme == newColorScheme)
356 if (m_themeName.isEmpty()) {
357 qCDebug(lcQGtk3Interface) <<
"GTK theme initialized:" << newThemeName << newColorScheme;
359 qCDebug(lcQGtk3Interface) <<
"GTK theme changed to:" << newThemeName << newColorScheme;
361 m_colorScheme = newColorScheme;
362 m_themeName = newThemeName;
366 if (!jsonInput.isEmpty()) {
367 if (load(jsonInput)) {
370 qWarning() <<
"Falling back to standard GTK mapping.";
377 if (!jsonOutput.isEmpty() && !save(jsonOutput))
378 qWarning() <<
"File" << jsonOutput <<
"could not be saved.\n";
399 for (
auto paletteIterator =
map.
begin(); paletteIterator !=
map.
end();
402 for (
auto brushIterator = bm.
begin(); brushIterator != bm.
end();
405 switch (
s.sourceType) {
410 s.fix.fixedBrush = fixedBrush;
456bool QGtk3Storage::load(
const QString &filename)
468void QGtk3Storage::createMapping()
475#define GTK(wtype, colorSource, state)\
476 source = Source(QGtk3Interface::QGtkWidget::gtk_ ##wtype,\
477 QGtk3Interface::QGtkColorSource::colorSource, GTK_STATE_FLAG_ ##state)
480#define LIGHTER(group, role, lighter)\
481 source = Source(QPalette::group, QPalette::role,\
482 Qt::ColorScheme::Unknown, lighter)
483#define MODIFY(group, role, red, green, blue)\
484 source = Source(QPalette::group, QPalette::role,\
485 Qt::ColorScheme::Unknown, red, green, blue)
488#define FIX(color) source = FixedSource(color);
492#define ADD_2(group, role) map.insert(TargetBrush(QPalette::group, QPalette::role), source);
493#define ADD_3(group, role, app) map.insert(TargetBrush(QPalette::group, QPalette::role,\
494 Qt::ColorScheme::app), source);
495#define ADD_X(x, group, role, app, FUNC, ...) FUNC
496#define ADD(...) ADD_X(,##__VA_ARGS__, ADD_3(__VA_ARGS__), ADD_2(__VA_ARGS__))
498#define SAVE(palette) m_palettes.insert(QPlatformTheme::palette, map)
500#define CLEAR map.clear()
548 ADD(Inactive, Light);
556 ADD(Inactive, WindowText);
563 ADD(Inactive, ButtonText);
569 ADD(Inactive, Highlight);
573 ADD(Inactive, HighlightedText);
590 ADD(
All, PlaceholderText, Light);
592 ADD(
All, PlaceholderText, Dark);
614 ADD(Inactive, WindowText);
625 ADD(Inactive, WindowText, Dark);
635 ADD(Inactive, WindowText, Light);
637 SAVE(CheckBoxPalette);
638 SAVE(RadioButtonPalette);
644 GTK(combo_box, Text, NORMAL);
647 ADD(Inactive, WindowText, Dark);
649 GTK(combo_box, Text, ACTIVE);
652 ADD(Inactive, WindowText, Light);
654 SAVE(ComboBoxPalette);
655 SAVE(GroupBoxPalette);
671 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
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
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)