From da71c1c755b60a5f2544fd6708b97a8bc13f3679 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 9 Jan 2012 15:36:02 +0100 Subject: Introduce a QVariant themeHint() to QPlatformTheme. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Start on removing platform-specific code from QtWidgets. Change-Id: Ic2163a0ce6f2db2151cdf7ca93766b2d861eeb55 Reviewed-by: Samuel Rødal --- src/gui/kernel/qplatformtheme_qpa.cpp | 41 +++++++++++++++++++++++++ src/gui/kernel/qplatformtheme_qpa.h | 9 ++++++ src/plugins/platforms/windows/qwindowstheme.cpp | 33 ++++++++++++++++++++ src/plugins/platforms/windows/qwindowstheme.h | 1 + src/widgets/kernel/qwhatsthis.cpp | 19 +++--------- src/widgets/styles/qcommonstyle.cpp | 6 ++-- src/widgets/styles/qwindowsstyle.cpp | 20 ++---------- 7 files changed, 95 insertions(+), 34 deletions(-) diff --git a/src/gui/kernel/qplatformtheme_qpa.cpp b/src/gui/kernel/qplatformtheme_qpa.cpp index b4a177f915..22d4452f4e 100644 --- a/src/gui/kernel/qplatformtheme_qpa.cpp +++ b/src/gui/kernel/qplatformtheme_qpa.cpp @@ -41,8 +41,36 @@ #include "qplatformtheme_qpa.h" +#include + QT_BEGIN_NAMESPACE +/*! + \class QPlatformTheme + \since 5.0 + \internal + \preliminary + \ingroup qpa + \brief The QPlatformTheme class allows customizing the UI based on themes. + +*/ + +/*! + \enum QPlatformTheme::ThemeHint + + This enum describes the available theme hints. + + \value TextCursorWidth (int) Determines the width of the text cursor. + + \value DropShadow (bool) Determines whether the drop shadow effect for + tooltips or whatsthis is enabled. + + \value MaximumScrollBarDragDistance (int) Determines the value returned by + QStyle::pixelMetric(PM_MaximumDragDistance) + + \sa themeHint(), QStyle::pixelMetric() +*/ + QPlatformMenu *QPlatformTheme::createPlatformMenu(QMenu *menu) const { Q_UNUSED(menu); @@ -67,4 +95,17 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(QDialog *dialo return 0; } +QVariant QPlatformTheme::themeHint(ThemeHint hint) const +{ + switch (hint) { + case TextCursorWidth: + return QVariant(1); + case DropShadow: + return QVariant(false); + case MaximumScrollBarDragDistance: + return QVariant(-1); + } + return QVariant(); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformtheme_qpa.h b/src/gui/kernel/qplatformtheme_qpa.h index 06a81fda4a..c3e5b677a2 100644 --- a/src/gui/kernel/qplatformtheme_qpa.h +++ b/src/gui/kernel/qplatformtheme_qpa.h @@ -56,15 +56,24 @@ class QPlatformMenu; class QPlatformMenuBar; class QPlatformDialogHelper; class QDialog; +class QVariant; class Q_GUI_EXPORT QPlatformTheme { public: + enum ThemeHint { + TextCursorWidth, + DropShadow, + MaximumScrollBarDragDistance + }; + virtual QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const; virtual QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const; virtual bool usePlatformNativeDialog(const QDialog *dialog = 0) const; virtual QPlatformDialogHelper *createPlatformDialogHelper(QDialog *dialog = 0) const; + + virtual QVariant themeHint(ThemeHint hint) const; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 4e1b004631..31adcfa167 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -41,13 +41,46 @@ #include "qwindowstheme.h" #include "qwindowsdialoghelpers.h" +#include "qwindowscontext.h" +#include "qt_windows.h" + +#include QT_BEGIN_NAMESPACE +static inline bool booleanSystemParametersInfo(UINT what, bool defaultValue) +{ + BOOL result; + if (SystemParametersInfo(what, 0, &result, 0)) + return result ? true : false; + return defaultValue; +} + +static inline bool dWordSystemParametersInfo(UINT what, DWORD defaultValue) +{ + DWORD result; + if (SystemParametersInfo(what, 0, &result, 0)) + return result; + return defaultValue; +} + QWindowsTheme::QWindowsTheme() { } +QVariant QWindowsTheme::themeHint(ThemeHint hint) const +{ + switch (hint) { + case TextCursorWidth: + return QVariant(int(dWordSystemParametersInfo(SPI_GETCARETWIDTH, 1u))); + case DropShadow: + return QVariant(booleanSystemParametersInfo(SPI_GETDROPSHADOW, false)); + case MaximumScrollBarDragDistance: + return QVariant(qRound(qreal(QWindowsContext::instance()->defaultDPI()) * 1.375)); + } + return QVariant(); +} + bool QWindowsTheme::usePlatformNativeDialog(const QDialog *dialog) const { return QWindowsDialogs::useHelper(dialog); diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index 67a0813835..9bb937d607 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -53,6 +53,7 @@ public: virtual bool usePlatformNativeDialog(const QDialog *dialog = 0) const; virtual QPlatformDialogHelper *createPlatformDialogHelper(QDialog *dialog = 0) const; + virtual QVariant themeHint(ThemeHint) const; }; QT_END_NAMESPACE diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp index 7b29ac6e8f..e1a1cd05ef 100644 --- a/src/widgets/kernel/qwhatsthis.cpp +++ b/src/widgets/kernel/qwhatsthis.cpp @@ -43,6 +43,7 @@ #ifndef QT_NO_WHATSTHIS #include "qpointer.h" #include "qapplication.h" +#include #include "qdesktopwidget.h" #include "qevent.h" #include "qpixmap.h" @@ -59,12 +60,6 @@ #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" #endif -#if defined(Q_WS_WIN) -#include "qt_windows.h" -#ifndef SPI_GETDROPSHADOW -#define SPI_GETDROPSHADOW 0x1024 -#endif -#endif QT_BEGIN_NAMESPACE @@ -221,15 +216,9 @@ QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor + Qt::TextWordWrap + Qt::TextExpandTabs, text); } -#if defined(Q_WS_WIN) - if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP - && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) - { - BOOL shadow; - SystemParametersInfo(SPI_GETDROPSHADOW, 0, &shadow, 0); - shadowWidth = shadow ? 0 : 6; - } -#endif + shadowWidth = + QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::DropShadow).toBool() ? + 0 : 6; resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth); } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 10c2dedaeb..c874770fdb 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -72,6 +73,7 @@ #include #include #include +#include #include #include @@ -4313,7 +4315,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; #endif case PM_MaximumDragDistance: - ret = -1; + ret = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MaximumScrollBarDragDistance).toInt(); break; #ifndef QT_NO_SLIDER @@ -4550,7 +4552,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid } break; case PM_TextCursorWidth: - ret = 1; + ret = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TextCursorWidth).toInt(); break; case PM_TabBar_ScrollButtonOverlap: ret = 1; diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 2f3d60eed8..1029433fe6 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -392,16 +392,9 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW break; #endif case PM_MaximumDragDistance: -#if defined(Q_OS_WIN) - { - HDC hdcScreen = GetDC(0); - int dpi = GetDeviceCaps(hdcScreen, LOGPIXELSX); - ReleaseDC(0, hdcScreen); - ret = (int)(dpi * 1.375); - } -#else - ret = 60; -#endif + ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance); + if (ret == -1) + ret = 60; break; #ifndef QT_NO_SLIDER @@ -530,13 +523,6 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW ret = GetSystemMetrics(SM_CYFRAME); #endif break; - case PM_TextCursorWidth: { - DWORD caretWidth = 1; -#if defined(SPI_GETCARETWIDTH) - SystemParametersInfo(SPI_GETCARETWIDTH, 0, &caretWidth, 0); -#endif - ret = (int)caretWidth; - break; } #endif case PM_ToolBarItemMargin: ret = 1; -- cgit v1.2.3