Introduce a QVariant themeHint() to QPlatformTheme.
Start on removing platform-specific code from QtWidgets. Change-Id: Ic2163a0ce6f2db2151cdf7ca93766b2d861eeb55 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>bb10
parent
15db15d448
commit
da71c1c755
|
|
@ -41,8 +41,36 @@
|
|||
|
||||
#include "qplatformtheme_qpa.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -41,13 +41,46 @@
|
|||
|
||||
#include "qwindowstheme.h"
|
||||
#include "qwindowsdialoghelpers.h"
|
||||
#include "qwindowscontext.h"
|
||||
#include "qt_windows.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#ifndef QT_NO_WHATSTHIS
|
||||
#include "qpointer.h"
|
||||
#include "qapplication.h"
|
||||
#include <private/qguiapplication_p.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
|
||||
#include <qfile.h>
|
||||
#include <qapplication.h>
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <qbitmap.h>
|
||||
#include <qcache.h>
|
||||
#include <qdockwidget.h>
|
||||
|
|
@ -72,6 +73,7 @@
|
|||
#include <qfileinfo.h>
|
||||
#include <qdir.h>
|
||||
#include <qsettings.h>
|
||||
#include <qvariant.h>
|
||||
#include <qpixmapcache.h>
|
||||
#include <private/qguiplatformplugin_p.h>
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue