summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.h2
-rw-r--r--src/plugins/platforms/cocoa/qcocoatheme.mm12
-rw-r--r--src/plugins/platforms/windows/qtwindows_additional.h4
-rw-r--r--src/plugins/platforms/windows/qtwindowsglobal.h6
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp6
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.h1
-rw-r--r--src/plugins/platforms/windows/qwindowsdialoghelpers.cpp7
-rw-r--r--src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp3
-rw-r--r--src/plugins/platforms/windows/qwindowstheme.cpp175
-rw-r--r--src/plugins/platforms/windows/qwindowstheme.h24
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp9
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.h3
12 files changed, 243 insertions, 9 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h
index 08f813b906..a7dc973937 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.h
+++ b/src/plugins/platforms/cocoa/qcocoatheme.h
@@ -59,6 +59,8 @@ public:
bool usePlatformNativeDialog(DialogType dialogType) const;
QPlatformDialogHelper *createPlatformDialogHelper(DialogType dialogType) const;
+
+ QVariant themeHint(ThemeHint hint) const;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm
index a23faf438d..ad20c2fb27 100644
--- a/src/plugins/platforms/cocoa/qcocoatheme.mm
+++ b/src/plugins/platforms/cocoa/qcocoatheme.mm
@@ -102,4 +102,16 @@ QPlatformDialogHelper * QCocoaTheme::createPlatformDialogHelper(DialogType dialo
}
}
+QVariant QCocoaTheme::themeHint(ThemeHint hint) const
+{
+ switch (hint) {
+ case QPlatformTheme::StyleNames:
+ return QStringList() << QLatin1Literal("macintosh");
+ break;
+ default:
+ return QPlatformTheme::themeHint(hint);
+ break;
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/windows/qtwindows_additional.h b/src/plugins/platforms/windows/qtwindows_additional.h
index ab51f36c24..d82240255e 100644
--- a/src/plugins/platforms/windows/qtwindows_additional.h
+++ b/src/plugins/platforms/windows/qtwindows_additional.h
@@ -45,6 +45,10 @@
#include <QtCore/QtGlobal> // get compiler define
#include <QtCore/qt_windows.h>
+#ifndef WM_THEMECHANGED
+# define WM_THEMECHANGED 0x031A
+#endif
+
/* Complement the definitions and declarations missing
* when using MinGW or older Windows SDKs. */
diff --git a/src/plugins/platforms/windows/qtwindowsglobal.h b/src/plugins/platforms/windows/qtwindowsglobal.h
index 3445a3c7a8..27cfbdc662 100644
--- a/src/plugins/platforms/windows/qtwindowsglobal.h
+++ b/src/plugins/platforms/windows/qtwindowsglobal.h
@@ -60,7 +60,8 @@ enum
KeyDownEventFlag = 0x200000,
TouchEventFlag = 0x400000,
ClipboardEventFlag = 0x800000,
- ApplicationEventFlag = 0x1000000
+ ApplicationEventFlag = 0x1000000,
+ ThemingEventFlag = 0x2000000
};
enum WindowsEventType // Simplify event types
@@ -97,6 +98,7 @@ enum WindowsEventType // Simplify event types
InputMethodOpenCandidateWindowEvent = InputMethodEventFlag + 4,
InputMethodCloseCandidateWindowEvent = InputMethodEventFlag + 5,
InputMethodRequest = InputMethodEventFlag + 6,
+ ThemeChanged = ThemingEventFlag + 1,
DisplayChangedEvent = 437,
UnknownEvent = 542
};
@@ -178,6 +180,8 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI
return QtWindows::FocusOutEvent;
case WM_DISPLAYCHANGE:
return QtWindows::DisplayChangedEvent;
+ case WM_THEMECHANGED:
+ return QtWindows::ThemeChanged;
default:
break;
}
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index a257736d98..2706e02cf8 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -49,6 +49,7 @@
#include "qwindowsinputcontext.h"
#include "qwindowsaccessibility.h"
#include "qwindowsscreen.h"
+#include "qwindowstheme.h"
#include <QtGui/QWindow>
#include <QtGui/QWindowSystemInterface>
@@ -78,6 +79,7 @@ int QWindowsContext::verboseGL = 0;
int QWindowsContext::verboseOLE = 0;
int QWindowsContext::verboseInputMethods = 0;
int QWindowsContext::verboseDialogs = 0;
+int QWindowsContext::verboseTheming = 0;
// Get verbosity of components from "foo:2,bar:3"
static inline int componentVerbose(const char *v, const char *keyWord)
@@ -284,6 +286,7 @@ QWindowsContext::QWindowsContext() :
QWindowsContext::verboseOLE = componentVerbose(v, "ole");
QWindowsContext::verboseInputMethods = componentVerbose(v, "im");
QWindowsContext::verboseDialogs = componentVerbose(v, "dialogs");
+ QWindowsContext::verboseTheming = componentVerbose(v, "theming");
}
}
@@ -784,6 +787,9 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
case QtWindows::CloseEvent:
QWindowSystemInterface::handleCloseEvent(platformWindow->window());
return true;
+ case QtWindows::ThemeChanged: // ### fixme: Compress these events?
+ QWindowsTheme::instance()->windowsThemeChanged(platformWindow->window());
+ return true;
default:
break;
}
diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h
index b5a36c3fe9..9f16ed232b 100644
--- a/src/plugins/platforms/windows/qwindowscontext.h
+++ b/src/plugins/platforms/windows/qwindowscontext.h
@@ -121,6 +121,7 @@ public:
static int verboseOLE;
static int verboseInputMethods;
static int verboseDialogs;
+ static int verboseTheming;
explicit QWindowsContext();
~QWindowsContext();
diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
index 8875590e63..25b9336361 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
@@ -43,6 +43,7 @@
#include "qwindowscontext.h"
#include "qwindowswindow.h"
+#include "qwindowstheme.h" // Color conversion helpers
#include <QtWidgets/QColorDialog>
#include <QtWidgets/QFontDialog>
@@ -1268,12 +1269,6 @@ QWindowsNativeColorDialog::QWindowsNativeColorDialog(const SharedPointerColor &c
qFill(m_customColors, m_customColors + 16, COLORREF(0));
}
-static inline COLORREF qColorToCOLORREF(const QColor &color)
-{ return RGB(color.red(), color.green(), color.blue()); }
-
-static inline QColor COLORREFToQColor(COLORREF cr)
-{ return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); }
-
void QWindowsNativeColorDialog::exec(HWND owner)
{
typedef BOOL (WINAPI *ChooseColorWType)(LPCHOOSECOLORW);
diff --git a/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp b/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp
index 34ab1665d8..49158dce48 100644
--- a/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp
+++ b/src/plugins/platforms/windows/qwindowsguieventdispatcher.cpp
@@ -203,7 +203,8 @@ messageDebugEntries[] = {
{WM_IME_ENDCOMPOSITION, "WM_IME_ENDCOMPOSITION"},
{WM_IME_NOTIFY, "WM_IME_NOTIFY"},
{WM_IME_REQUEST, "WM_IME_REQUEST"},
- {WM_DISPLAYCHANGE, "WM_DISPLAYCHANGE"}
+ {WM_DISPLAYCHANGE, "WM_DISPLAYCHANGE"},
+ {WM_THEMECHANGED , "WM_THEMECHANGED"}
};
static inline const MessageDebugEntry *messageDebugEntry(UINT msg)
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp
index 73cff3c9ce..a59b74cef3 100644
--- a/src/plugins/platforms/windows/qwindowstheme.cpp
+++ b/src/plugins/platforms/windows/qwindowstheme.cpp
@@ -42,12 +42,126 @@
#include "qwindowstheme.h"
#include "qwindowsdialoghelpers.h"
#include "qwindowscontext.h"
+#include "qwindowsintegration.h"
#include "qt_windows.h"
#include <QtCore/QVariant>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDebug>
+#include <QtCore/QTextStream>
+#include <QtCore/QSysInfo>
+#include <QtGui/QPalette>
+#include <QtGui/QGuiApplication>
QT_BEGIN_NAMESPACE
+static inline QTextStream& operator<<(QTextStream &str, const QColor &c)
+{
+ str.setIntegerBase(16);
+ str.setFieldWidth(2);
+ str.setPadChar(QLatin1Char('0'));
+ str << " rgb: #" << c.red() << c.green() << c.blue();
+ str.setIntegerBase(10);
+ str.setFieldWidth(0);
+ return str;
+}
+
+static inline QString paletteToString(const QPalette &palette)
+{
+ QString result;
+ QTextStream str(&result);
+ str << "text=" << palette.color(QPalette::WindowText)
+ << " background=" << palette.color(QPalette::Window);
+ return result;
+}
+
+static inline QColor mixColors(const QColor &c1, const QColor &c2)
+{
+ return QColor ((c1.red() + c2.red()) / 2,
+ (c1.green() + c2.green()) / 2,
+ (c1.blue() + c2.blue()) / 2);
+}
+
+static inline QColor getSysColor(int index)
+{
+ return qColorToCOLORREF(GetSysColor(index));
+}
+
+static inline QPalette systemPalette()
+{
+ QPalette result;
+ result.setColor(QPalette::WindowText, getSysColor(COLOR_WINDOWTEXT));
+ result.setColor(QPalette::Button, getSysColor(COLOR_BTNFACE));
+ result.setColor(QPalette::Light, getSysColor(COLOR_BTNHIGHLIGHT));
+ result.setColor(QPalette::Dark, getSysColor(COLOR_BTNSHADOW));
+ result.setColor(QPalette::Mid, result.button().color().darker(150));
+ result.setColor(QPalette::Text, getSysColor(COLOR_WINDOWTEXT));
+ result.setColor(QPalette::BrightText, getSysColor(COLOR_BTNHIGHLIGHT));
+ result.setColor(QPalette::Base, getSysColor(COLOR_WINDOW));
+ result.setColor(QPalette::Window, getSysColor(COLOR_BTNFACE));
+ result.setColor(QPalette::ButtonText, getSysColor(COLOR_BTNTEXT));
+ result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT));
+ result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW));
+ result.setColor(QPalette::Highlight, getSysColor(COLOR_HIGHLIGHT));
+ result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT));
+ result.setColor(QPalette::Link, Qt::blue);
+ result.setColor(QPalette::LinkVisited, Qt::magenta);
+ result.setColor(QPalette::Inactive, QPalette::Button, result.button().color());
+ result.setColor(QPalette::Inactive, QPalette::Window, result.background().color());
+ result.setColor(QPalette::Inactive, QPalette::Light, result.light().color());
+ result.setColor(QPalette::Inactive, QPalette::Dark, result.dark().color());
+
+ if (result.midlight() == result.button())
+ result.setColor(QPalette::Midlight, result.button().color().lighter(110));
+ if (result.background() != result.base()) {
+ result.setColor(QPalette::Inactive, QPalette::Highlight, result.color(QPalette::Inactive, QPalette::Window));
+ result.setColor(QPalette::Inactive, QPalette::HighlightedText, result.color(QPalette::Inactive, QPalette::Text));
+ }
+
+ const QColor disabled =
+ mixColors(result.foreground().color(), result.button().color());
+
+ result.setColorGroup(QPalette::Disabled, result.foreground(), result.button(),
+ result.light(), result.dark(), result.mid(),
+ result.text(), result.brightText(), result.base(),
+ result.background());
+ result.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
+ result.setColor(QPalette::Disabled, QPalette::Text, disabled);
+ result.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
+ result.setColor(QPalette::Disabled, QPalette::Highlight,
+ getSysColor(COLOR_HIGHLIGHT));
+ result.setColor(QPalette::Disabled, QPalette::HighlightedText,
+ getSysColor(COLOR_HIGHLIGHTTEXT));
+ result.setColor(QPalette::Disabled, QPalette::Base,
+ result.background().color());
+ return result;
+}
+
+QPalette toolTipPalette(const QPalette &systemPalette)
+{
+ QPalette result(systemPalette);
+ const QColor tipBgColor(getSysColor(COLOR_INFOBK));
+ const QColor tipTextColor(getSysColor(COLOR_INFOTEXT));
+
+ result.setColor(QPalette::All, QPalette::Button, tipBgColor);
+ result.setColor(QPalette::All, QPalette::Window, tipBgColor);
+ result.setColor(QPalette::All, QPalette::Text, tipTextColor);
+ result.setColor(QPalette::All, QPalette::WindowText, tipTextColor);
+ result.setColor(QPalette::All, QPalette::ButtonText, tipTextColor);
+ result.setColor(QPalette::All, QPalette::Button, tipBgColor);
+ result.setColor(QPalette::All, QPalette::Window, tipBgColor);
+ result.setColor(QPalette::All, QPalette::Text, tipTextColor);
+ result.setColor(QPalette::All, QPalette::WindowText, tipTextColor);
+ result.setColor(QPalette::All, QPalette::ButtonText, tipTextColor);
+ const QColor disabled =
+ mixColors(result.foreground().color(), result.button().color());
+ result.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
+ result.setColor(QPalette::Disabled, QPalette::Text, disabled);
+ result.setColor(QPalette::Disabled, QPalette::Base, Qt::white);
+ result.setColor(QPalette::Disabled, QPalette::BrightText, Qt::white);
+ return result;
+}
+
static inline bool booleanSystemParametersInfo(UINT what, bool defaultValue)
{
BOOL result;
@@ -66,11 +180,53 @@ static inline bool dWordSystemParametersInfo(UINT what, DWORD defaultValue)
QWindowsTheme::QWindowsTheme()
{
+ qFill(m_palettes, m_palettes + NPalettes, static_cast<QPalette *>(0));
+ refresh();
+}
+
+QWindowsTheme::~QWindowsTheme()
+{
+ clearPalettes();
+}
+
+void QWindowsTheme::clearPalettes()
+{
+ qDeleteAll(m_palettes, m_palettes + NPalettes);
+ qFill(m_palettes, m_palettes + NPalettes, static_cast<QPalette *>(0));
+}
+
+QWindowsTheme *QWindowsTheme::instance()
+{
+ return static_cast<QWindowsTheme *>(QWindowsIntegration::instance()->platformTheme());
+}
+
+static inline QStringList iconThemeSearchPaths()
+{
+ const QFileInfo appDir(QCoreApplication::applicationDirPath() + QStringLiteral("/icons"));
+ return appDir.isDir() ? QStringList(appDir.absoluteFilePath()) : QStringList();
+}
+
+static inline QStringList styleNames()
+{
+ QStringList result;
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
+ result.append(QStringLiteral("WindowsVista"));
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP)
+ result.append(QStringLiteral("WindowsXP"));
+ result.append(QStringLiteral("Windows"));
+ return result;
}
QVariant QWindowsTheme::themeHint(ThemeHint hint) const
{
switch (hint) {
+ case SystemIconThemeName:
+ break;
+ case IconThemeSearchPaths:
+ return QVariant(iconThemeSearchPaths());
+ break;
+ case StyleNames:
+ return QVariant(styleNames());
case TextCursorWidth:
return QVariant(int(dWordSystemParametersInfo(SPI_GETCARETWIDTH, 1u)));
case DropShadow:
@@ -81,6 +237,19 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const
return QVariant();
}
+void QWindowsTheme::refresh()
+{
+ clearPalettes();
+ if (QGuiApplication::desktopSettingsAware()) {
+ m_palettes[SystemPalette] = new QPalette(systemPalette());
+ m_palettes[ToolTipPalette] = new QPalette(toolTipPalette(*m_palettes[SystemPalette]));
+ if (QWindowsContext::verboseTheming)
+ qDebug() << __FUNCTION__ << '\n'
+ << " system=" << paletteToString(*m_palettes[SystemPalette])
+ << " tooltip=" << paletteToString(*m_palettes[ToolTipPalette]);
+ }
+}
+
bool QWindowsTheme::usePlatformNativeDialog(DialogType type) const
{
return QWindowsDialogs::useHelper(type);
@@ -91,4 +260,10 @@ QPlatformDialogHelper *QWindowsTheme::createPlatformDialogHelper(DialogType type
return QWindowsDialogs::createHelper(type);
}
+void QWindowsTheme::windowsThemeChanged(QWindow * /* window */)
+{
+ refresh();
+ // QWindowSystemInterface::handleThemeChange(window);
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h
index 77c85b2d6e..950c380737 100644
--- a/src/plugins/platforms/windows/qwindowstheme.h
+++ b/src/plugins/platforms/windows/qwindowstheme.h
@@ -43,19 +43,43 @@
#define QWINDOWSTHEME_H
#include <QtGui/QPlatformTheme>
+#include <QtGui/QColor>
+
+#include "qtwindows_additional.h"
QT_BEGIN_NAMESPACE
+class QWindow;
+
class QWindowsTheme : public QPlatformTheme
{
public:
QWindowsTheme();
+ ~QWindowsTheme();
+
+ static QWindowsTheme *instance();
virtual bool usePlatformNativeDialog(DialogType type) const;
virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
virtual QVariant themeHint(ThemeHint) const;
+ virtual const QPalette *palette(Palette type = SystemPalette) const
+ { return m_palettes[type]; }
+
+ void windowsThemeChanged(QWindow *window);
+
+private:
+ void refresh();
+ void clearPalettes();
+
+ QPalette *m_palettes[NPalettes];
};
+static inline COLORREF qColorToCOLORREF(const QColor &color)
+{ return RGB(color.red(), color.green(), color.blue()); }
+
+static inline QColor COLORREFToQColor(COLORREF cr)
+{ return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); }
+
QT_END_NAMESPACE
#endif // QWINDOWSTHEME_H
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index c976e75dbf..e7cdef4da9 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -70,6 +70,7 @@
#endif
#include <private/qplatforminputcontextfactory_qpa_p.h>
+#include <private/qgenericunixthemes_p.h>
#include <qplatforminputcontext_qpa.h>
#if defined(XCB_USE_GLX)
@@ -87,7 +88,8 @@ QT_BEGIN_NAMESPACE
QXcbIntegration::QXcbIntegration(const QStringList &parameters)
: m_eventDispatcher(createUnixEventDispatcher()),
- m_services(new QGenericUnixServices)
+ m_services(new QGenericUnixServices),
+ m_theme(QGenericUnixTheme::createUnixTheme())
{
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
@@ -278,4 +280,9 @@ QPlatformServices *QXcbIntegration::services() const
return m_services.data();
}
+QPlatformTheme *QXcbIntegration::platformTheme() const
+{
+ return m_theme.data();
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h
index 0f20658c70..457f90d6e0 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.h
+++ b/src/plugins/platforms/xcb/qxcbintegration.h
@@ -85,6 +85,8 @@ public:
QPlatformServices *services() const;
+ QPlatformTheme *platformTheme() const;
+
private:
QList<QXcbConnection *> m_connections;
@@ -101,6 +103,7 @@ private:
#endif
QScopedPointer<QPlatformServices> m_services;
+ QScopedPointer<QPlatformTheme> m_theme;
};
QT_END_NAMESPACE