[vlc-commits] qt: expose system color palette from C++ QPalette

Pierre Lamot git at videolan.org
Thu Feb 20 13:56:52 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Tue Feb 18 15:09:09 2020 +0100| [e181aa5364c0ee64fdcbfc14ca14ffbf4894485c] | committer: Jean-Baptiste Kempf

qt: expose system color palette from C++ QPalette

  QML SystemPalette is incomplete

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e181aa5364c0ee64fdcbfc14ca14ffbf4894485c
---

 modules/gui/qt/Makefile.am                      |   2 +
 modules/gui/qt/maininterface/main_interface.cpp |   2 +
 modules/gui/qt/util/systempalette.cpp           |  80 ++++++++++++
 modules/gui/qt/util/systempalette.hpp           | 165 ++++++++++++++++++++++++
 4 files changed, 249 insertions(+)

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 3c5b3dfdca..627cc5c5ab 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -180,6 +180,7 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/settings.hpp \
 	gui/qt/util/singleton.hpp \
 	gui/qt/util/soutchain.cpp gui/qt/util/soutchain.hpp \
+	gui/qt/util/systempalette.cpp gui/qt/util/systempalette.hpp \
 	gui/qt/util/validators.cpp gui/qt/util/validators.hpp \
 	gui/qt/util/varcommon_p.hpp \
 	gui/qt/util/varchoicemodel.cpp  gui/qt/util/varchoicemodel.hpp \
@@ -297,6 +298,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	gui/qt/util/renderer_manager.moc.cpp \
 	gui/qt/util/selectable_list_model.moc.cpp \
 	gui/qt/util/settings.moc.cpp \
+	gui/qt/util/systempalette.moc.cpp \
 	gui/qt/util/validators.moc.cpp \
 	gui/qt/util/varchoicemodel.moc.cpp \
 	gui/qt/util/variables.moc.cpp \
diff --git a/modules/gui/qt/maininterface/main_interface.cpp b/modules/gui/qt/maininterface/main_interface.cpp
index 98aaceb74f..8027b116cb 100644
--- a/modules/gui/qt/maininterface/main_interface.cpp
+++ b/modules/gui/qt/maininterface/main_interface.cpp
@@ -70,6 +70,7 @@
 
 #include "util/qmleventfilter.hpp"
 #include "util/i18n.hpp"
+#include "util/systempalette.hpp"
 
 #include "menus/menus.hpp"                            // Menu creation
 
@@ -406,6 +407,7 @@ void MainInterface::createMainWidget( QSettings * )
     rootCtx->setContextProperty( "dialogProvider", DialogsProvider::getInstance());
     rootCtx->setContextProperty( "recentsMedias",  new VLCRecentMediaModel( p_intf, this ));
     rootCtx->setContextProperty( "settings",  new Settings( p_intf, this ));
+    rootCtx->setContextProperty( "systemPalette", new SystemPalette(this));
 
     if (b_hasMedialibrary)
     {
diff --git a/modules/gui/qt/util/systempalette.cpp b/modules/gui/qt/util/systempalette.cpp
new file mode 100644
index 0000000000..c7fcfb3000
--- /dev/null
+++ b/modules/gui/qt/util/systempalette.cpp
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include "systempalette.hpp"
+#include <QGuiApplication>
+
+SystemPalette::SystemPalette(QObject* parent)
+    : QObject(parent)
+    , m_palette(qApp->palette())
+{
+
+    connect(qApp, &QGuiApplication::paletteChanged, this, &SystemPalette::paletteChanged);
+
+}
+
+#define COLOR_GETTER(getter, role) \
+    QColor SystemPalette::getter() const{ \
+        return m_palette.color(QPalette::Normal, role); \
+    } \
+    QColor SystemPalette::getter##Disabled() const { \
+        return m_palette.color(QPalette::Disabled, role); \
+    } \
+    QColor SystemPalette::getter##Inactive() const { \
+        return m_palette.color(QPalette::Inactive, role); \
+    }
+
+COLOR_GETTER(text, QPalette::Text)
+COLOR_GETTER(textBright, QPalette::BrightText)
+COLOR_GETTER(link, QPalette::Link)
+COLOR_GETTER(linkVisited, QPalette::LinkVisited)
+COLOR_GETTER(base, QPalette::Base)
+COLOR_GETTER(alternateBase, QPalette::AlternateBase)
+COLOR_GETTER(window, QPalette::Window)
+COLOR_GETTER(windowText, QPalette::WindowText)
+COLOR_GETTER(button, QPalette::Button)
+COLOR_GETTER(buttonText, QPalette::ButtonText)
+COLOR_GETTER(highlight, QPalette::Highlight)
+COLOR_GETTER(highlightText, QPalette::HighlightedText)
+COLOR_GETTER(tooltip, QPalette::ToolTipBase)
+COLOR_GETTER(tooltipText, QPalette::ToolTipText)
+
+QColor SystemPalette::light() const
+{
+    return m_palette.color(QPalette::Normal, QPalette::Light);
+}
+
+QColor SystemPalette::midlight() const
+{
+    return m_palette.color(QPalette::Normal, QPalette::Midlight);
+}
+
+QColor SystemPalette::mid() const
+{
+    return m_palette.color(QPalette::Normal, QPalette::Mid);
+}
+
+QColor SystemPalette::dark() const
+{
+    return m_palette.color(QPalette::Normal, QPalette::Dark);
+}
+
+QColor SystemPalette::shadow() const
+{
+    return m_palette.color(QPalette::Normal, QPalette::Shadow);
+}
+
diff --git a/modules/gui/qt/util/systempalette.hpp b/modules/gui/qt/util/systempalette.hpp
new file mode 100644
index 0000000000..bedf2782cf
--- /dev/null
+++ b/modules/gui/qt/util/systempalette.hpp
@@ -0,0 +1,165 @@
+/*****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef SYSTEMPALETTE_H
+#define SYSTEMPALETTE_H
+
+#include <QObject>
+#include <QPalette>
+#include <QWidget>
+
+class SystemPalette : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QColor text         READ text         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor textDisabled READ textDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor textInactive READ textInactive NOTIFY paletteChanged)
+
+
+    Q_PROPERTY(QColor textBright         READ textBright         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor textBrightDisabled READ textBrightDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor textBrightInactive READ textBrightInactive NOTIFY paletteChanged)
+
+
+    Q_PROPERTY(QColor link         READ link         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor linkDisabled READ linkDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor linkInactive READ linkInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor linkVisited         READ linkVisited         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor linkVisitedDisabled READ linkVisitedDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor linkVisitedInactive READ linkVisitedInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor base         READ base         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor baseDisabled READ baseDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor baseInactive READ baseInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor alternateBase         READ alternateBase         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor alternateBaseDisabled READ alternateBaseDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor alternateBaseInactive READ alternateBaseInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor window         READ window         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor windowDisabled READ windowDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor windowInactive READ windowInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor windowText         READ windowText         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor windowTextDisabled READ windowTextDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor windowTextInactive READ windowTextInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor button         READ button         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor buttonDisabled READ buttonDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor buttonInactive READ buttonInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor buttonText         READ buttonText         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor buttonTextDisabled READ buttonTextDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor buttonTextInactive READ buttonTextInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor highlight         READ highlight         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor highlightDisabled READ highlightDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor highlightInactive READ highlightInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor highlightText         READ highlightText         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor highlightTextDisabled READ highlightTextDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor highlightTextInactive READ highlightTextInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor tooltip         READ tooltip         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor tooltipDisabled READ tooltipDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor tooltipInactive READ tooltipInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor tooltipText         READ tooltipText         NOTIFY paletteChanged)
+    Q_PROPERTY(QColor tooltipTextDisabled READ tooltipTextDisabled NOTIFY paletteChanged)
+    Q_PROPERTY(QColor tooltipTextInactive READ tooltipTextInactive NOTIFY paletteChanged)
+
+    Q_PROPERTY(QColor light     READ light    NOTIFY paletteChanged)
+    Q_PROPERTY(QColor midlight  READ midlight NOTIFY paletteChanged)
+    Q_PROPERTY(QColor dark      READ dark     NOTIFY paletteChanged)
+    Q_PROPERTY(QColor mid       READ mid      NOTIFY paletteChanged)
+    Q_PROPERTY(QColor shadow    READ shadow   NOTIFY paletteChanged)
+
+public:
+    SystemPalette(QObject* parent = nullptr);
+
+    QColor text() const;
+    QColor textDisabled() const;
+    QColor textInactive() const;
+
+    QColor textBright() const;
+    QColor textBrightDisabled() const;
+    QColor textBrightInactive() const;
+
+    QColor link() const;
+    QColor linkDisabled() const;
+    QColor linkInactive() const;
+
+    QColor linkVisited() const;
+    QColor linkVisitedDisabled() const;
+    QColor linkVisitedInactive() const;
+
+    QColor base() const;
+    QColor baseDisabled() const;
+    QColor baseInactive() const;
+
+    QColor alternateBase() const;
+    QColor alternateBaseDisabled() const;
+    QColor alternateBaseInactive() const;
+
+    QColor window() const;
+    QColor windowDisabled() const;
+    QColor windowInactive() const;
+
+    QColor windowText() const;
+    QColor windowTextDisabled() const;
+    QColor windowTextInactive() const;
+
+    QColor button() const;
+    QColor buttonDisabled() const;
+    QColor buttonInactive() const;
+
+    QColor buttonText() const;
+    QColor buttonTextDisabled() const;
+    QColor buttonTextInactive() const;
+
+    QColor highlight() const;
+    QColor highlightDisabled() const;
+    QColor highlightInactive() const;
+
+    QColor highlightText() const;
+    QColor highlightTextDisabled() const;
+    QColor highlightTextInactive() const;
+
+    QColor tooltip() const;
+    QColor tooltipDisabled() const;
+    QColor tooltipInactive() const;
+
+    QColor tooltipText() const;
+    QColor tooltipTextDisabled() const;
+    QColor tooltipTextInactive() const;
+
+    QColor light() const;
+    QColor midlight() const;
+    QColor dark() const;
+    QColor mid() const;
+    QColor shadow() const;
+
+signals:
+    void paletteChanged();
+
+private:
+    QPalette m_palette;
+};
+
+#endif // SYSTEMPALETTE_H



More information about the vlc-commits mailing list