diff options
author | Liang Qi <liang.qi@qt.io> | 2016-05-12 07:31:50 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-05-12 08:33:08 +0200 |
commit | 990969655c5fb4d03682e96df9b12101f5ee9815 (patch) | |
tree | b8fb5c50285105c8bc5a938fb50f93ff9f24889d /src/widgets/styles | |
parent | a213011a53f12f101d08a04afc8fdacd2d54a232 (diff) | |
parent | e64b2234e829cc47872225debcf80d6c06db18f0 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
config_help.txt
configure
src/corelib/io/qprocess_wince.cpp
src/plugins/platforms/windows/qwindowstheme.cpp
src/plugins/platforms/xcb/qxcbbackingstore.cpp
tests/auto/corelib/tools/qtimezone/BLACKLIST
tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
Change-Id: I26644d1cb3b78412c8ff285e2a55bea1bd641c01
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qandroidstyle.cpp | 29 | ||||
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 4 | ||||
-rw-r--r-- | src/widgets/styles/qfusionstyle.cpp | 18 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 4 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 73 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle_p_p.h | 8 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsxpstyle.cpp | 70 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsxpstyle_p_p.h | 7 |
8 files changed, 116 insertions, 97 deletions
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp index e59c35ed68..743166549b 100644 --- a/src/widgets/styles/qandroidstyle.cpp +++ b/src/widgets/styles/qandroidstyle.cpp @@ -838,7 +838,7 @@ int QAndroidStyle::Android9PatchDrawable::calculateStretch(int boundsLimit, void QAndroidStyle::Android9PatchDrawable::extractIntArray(const QVariantList &values, QVector<int> & array) { - foreach (QVariant value, values) + for (const QVariant &value : values) array << value.toInt(); } @@ -1140,8 +1140,8 @@ QAndroidStyle::AndroidStateDrawable::AndroidStateDrawable(const QVariantMap &dra QAndroidStyle::ItemType itemType) : AndroidDrawable(drawable, itemType) { - QVariantList states = drawable.value(QLatin1String("stateslist")).toList(); - foreach (QVariant stateVariant, states) { + const QVariantList states = drawable.value(QLatin1String("stateslist")).toList(); + for (const QVariant &stateVariant : states) { QVariantMap state = stateVariant.toMap(); const int s = extractState(state.value(QLatin1String("states")).toMap()); if (-1 == s) @@ -1158,7 +1158,7 @@ QAndroidStyle::AndroidStateDrawable::AndroidStateDrawable(const QVariantMap &dra QAndroidStyle::AndroidStateDrawable::~AndroidStateDrawable() { - foreach (const StateType type, m_states) + for (const StateType &type : qAsConst(m_states)) delete type.second; } @@ -1192,7 +1192,7 @@ const QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidStateDrawable::best } uint bestCost = 0xffff; - foreach (const StateType & state, m_states) { + for (const StateType & state : m_states) { if (int(opt->state) == state.first) return state.second; uint cost = 1; @@ -1234,8 +1234,9 @@ const QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidStateDrawable::best int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value) { QStyle::State state = QStyle::State_Enabled | QStyle::State_Active;; - foreach (const QString &key, value.keys()) { - bool val = value.value(key).toString() == QLatin1String("true"); + for (auto it = value.cbegin(), end = value.cend(); it != end; ++it) { + const QString &key = it.key(); + bool val = it.value().toString() == QLatin1String("true"); if (key == QLatin1String("enabled")) { state.setFlag(QStyle::State_Enabled, val); continue; @@ -1282,7 +1283,7 @@ int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value) void QAndroidStyle::AndroidStateDrawable::setPaddingLeftToSizeWidth() { - foreach (const StateType type, m_states) + for (const StateType &type : qAsConst(m_states)) const_cast<AndroidDrawable *>(type.second)->setPaddingLeftToSizeWidth(); } @@ -1293,8 +1294,8 @@ QAndroidStyle::AndroidLayerDrawable::AndroidLayerDrawable(const QVariantMap &dra m_id = 0; m_factor = 1; m_orientation = Qt::Horizontal; - QVariantList layers = drawable.value(QLatin1String("layers")).toList(); - foreach (QVariant layer, layers) { + const QVariantList layers = drawable.value(QLatin1String("layers")).toList(); + for (const QVariant &layer : layers) { QVariantMap layerMap = layer.toMap(); AndroidDrawable *ad = fromMap(layerMap, itemType); if (ad) { @@ -1308,7 +1309,7 @@ QAndroidStyle::AndroidLayerDrawable::AndroidLayerDrawable(const QVariantMap &dra QAndroidStyle::AndroidLayerDrawable::~AndroidLayerDrawable() { - foreach (const LayerType &layer, m_layers) + for (const LayerType &layer : qAsConst(m_layers)) delete layer.second; } @@ -1326,7 +1327,7 @@ void QAndroidStyle::AndroidLayerDrawable::setFactor(int id, double factor, Qt::O void QAndroidStyle::AndroidLayerDrawable::draw(QPainter *painter, const QStyleOption *opt) const { - foreach (const LayerType &layer, m_layers) { + for (const LayerType &layer : m_layers) { if (layer.first == m_id) { QStyleOption copy(*opt); if (m_orientation == Qt::Horizontal) @@ -1342,7 +1343,7 @@ void QAndroidStyle::AndroidLayerDrawable::draw(QPainter *painter, const QStyleOp QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidLayerDrawable::layer(int id) const { - foreach (const LayerType &layer, m_layers) + for (const LayerType &layer : m_layers) if (layer.first == id) return layer.second; return 0; @@ -1351,7 +1352,7 @@ QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidLayerDrawable::layer(int i QSize QAndroidStyle::AndroidLayerDrawable::size() const { QSize sz; - foreach (const LayerType &layer, m_layers) + for (const LayerType &layer : m_layers) sz = sz.expandedTo(layer.second->size()); return sz; } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 91d4bcc7ab..6b9e5577a4 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4985,7 +4985,11 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget break; case SH_BlinkCursorWhenTextSelected: +#if defined(Q_OS_DARWIN) + ret = 0; +#else ret = 1; +#endif break; case SH_Table_GridLineColor: diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index a9cea0e2ab..8a768443d1 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3414,12 +3414,28 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom QSize textSize = option->fontMetrics.boundingRect(groupBox->text).size() + QSize(2, 2); int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget); int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget); + + const int width = textSize.width() + + (option->subControls & QStyle::SC_GroupBoxCheckBox ? indicatorWidth + 5 : 0); + rect = QRect(); + + if (option->rect.width() > width) { + switch (groupBox->textAlignment & Qt::AlignHorizontal_Mask) { + case Qt::AlignHCenter: + rect.moveLeft((option->rect.width() - width) / 2); + break; + case Qt::AlignRight: + rect.moveLeft(option->rect.width() - width); + break; + } + } + if (subControl == SC_GroupBoxCheckBox) { rect.setWidth(indicatorWidth); rect.setHeight(indicatorHeight); rect.moveTop(textSize.height() > indicatorHeight ? (textSize.height() - indicatorHeight) / 2 : 0); - rect.moveLeft(1); + rect.translate(1, 0); } else if (subControl == SC_GroupBoxLabel) { rect.setSize(textSize); rect.moveTop(1); diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 16a11e6029..d72a898ee9 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -157,10 +157,10 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C Qt's built-in widgets use QStyle to perform nearly all of their drawing, ensuring that they look exactly like the equivalent - native widgets. The diagram below shows a QComboBox in eight + native widgets. The diagram below shows a QComboBox in nine different styles. - \image qstyle-comboboxes.png Eight combo boxes + \image qstyle-comboboxes.png Nine combo boxes Topics: diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 2b2b919818..dce0a93e10 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -426,9 +426,9 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt case PE_IndicatorBranch: { - XPThemeData theme(widget, painter, QWindowsXPStylePrivate::TreeViewTheme); + XPThemeData theme(widget, painter, QWindowsXPStylePrivate::VistaTreeViewTheme); static int decoration_size = 0; - if (!decoration_size && d->initTreeViewTheming() && theme.isValid()) { + if (!decoration_size && theme.isValid()) { XPThemeData themeSize = theme; themeSize.partId = TVP_HOTGLYPH; themeSize.stateId = GLPS_OPENED; @@ -728,9 +728,9 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt QPainter pixmapPainter(&pixmap); XPThemeData theme(widget, &pixmapPainter, - QWindowsXPStylePrivate::TreeViewTheme, + QWindowsXPStylePrivate::VistaTreeViewTheme, LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height())); - if (d->initTreeViewTheming() && theme.isValid()) { + if (theme.isValid()) { d->drawBackground(theme); } else { QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget); @@ -1149,7 +1149,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; - if (widget) { // Not needed for QtQuick Controls + if (widget && mbi->palette.color(QPalette::Window) != Qt::transparent) { // Not needed for QtQuick Controls //The rect adjustment is a workaround for the menu not really filling its background. XPThemeData theme(widget, painter, QWindowsXPStylePrivate::MenuTheme, @@ -2357,10 +2357,6 @@ void QWindowsVistaStyle::unpolish(QWidget *widget) QWindowsXPStyle::unpolish(widget); QWindowsVistaStylePrivate *d = d_func(); - // Delete the tree view helper in case the XP style cleaned the - // theme handle map due to a theme or QStyle change (QProxyStyle). - if (!QWindowsXPStylePrivate::hasTheme(QWindowsXPStylePrivate::TreeViewTheme)) - d->cleanupTreeViewTheming(); d->stopAnimation(widget); @@ -2426,15 +2422,10 @@ QPixmap QWindowsVistaStyle::standardPixmap(StandardPixmap standardPixmap, const } QWindowsVistaStylePrivate::QWindowsVistaStylePrivate() : - QWindowsXPStylePrivate(), m_treeViewHelper(0) + QWindowsXPStylePrivate() { } -QWindowsVistaStylePrivate::~QWindowsVistaStylePrivate() -{ - cleanupTreeViewTheming(); -} - bool QWindowsVistaStylePrivate::transitionsEnabled() const { BOOL animEnabled = false; @@ -2446,58 +2437,6 @@ bool QWindowsVistaStylePrivate::transitionsEnabled() const return false; } -/* - * We need to set the windows "explorer" theme explicitly on a native - * window and open the "TREEVIEW" theme handle passing its window handle - * in order to get Vista-style item view themes (particulary drawBackground() - * for selected items needs this). - * We invoke a service of the native Windows interface to create - * a non-visible window handle, open the theme on it and insert it into - * the cache so that it is found by XPThemeData::handle() first. - */ - -static inline HWND createTreeViewHelperWindow() -{ - if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { - void *hwnd = 0; - void *wndProc = reinterpret_cast<void *>(DefWindowProc); - if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, - Q_RETURN_ARG(void *, hwnd), - Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindowClass")), - Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindow")), - Q_ARG(void *, wndProc)) && hwnd) { - return reinterpret_cast<HWND>(hwnd); - } - } - return 0; -} - -bool QWindowsVistaStylePrivate::initTreeViewTheming() -{ - if (m_treeViewHelper) - return true; - - m_treeViewHelper = createTreeViewHelperWindow(); - if (Q_UNLIKELY(!m_treeViewHelper)) { - qWarning("Unable to create the treeview helper window."); - return false; - } - const HRESULT hr = QWindowsXPStylePrivate::pSetWindowTheme(m_treeViewHelper, L"explorer", NULL); - if (Q_UNLIKELY(hr != S_OK)) { - qErrnoWarning("SetWindowTheme() failed."); - return false; - } - return QWindowsXPStylePrivate::createTheme(QWindowsXPStylePrivate::TreeViewTheme, m_treeViewHelper); -} - -void QWindowsVistaStylePrivate::cleanupTreeViewTheming() -{ - if (m_treeViewHelper) { - DestroyWindow(m_treeViewHelper); - m_treeViewHelper = 0; - } -} - /*! \reimp */ diff --git a/src/widgets/styles/qwindowsvistastyle_p_p.h b/src/widgets/styles/qwindowsvistastyle_p_p.h index 7adfbb08ec..e207a27a66 100644 --- a/src/widgets/styles/qwindowsvistastyle_p_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p_p.h @@ -168,16 +168,10 @@ class QWindowsVistaStylePrivate : public QWindowsXPStylePrivate public: QWindowsVistaStylePrivate(); - ~QWindowsVistaStylePrivate(); + static int fixedPixelMetric(QStyle::PixelMetric pm); static inline bool useVista(); bool transitionsEnabled() const; - -private: - bool initTreeViewTheming(); - void cleanupTreeViewTheming(); - - HWND m_treeViewHelper; }; QT_END_NAMESPACE diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 1f910d41cb..b39cecbd73 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -54,6 +54,8 @@ #include <qbackingstore.h> #include <qapplication.h> #include <qpixmapcache.h> +#include <private/qapplication_p.h> +#include <qpa/qplatformnativeinterface.h> #include <qdesktopwidget.h> #include <qtoolbutton.h> @@ -163,7 +165,7 @@ static const wchar_t *themeNames[QWindowsXPStylePrivate::NThemes] = L"BUTTON", L"COMBOBOX", L"EDIT", L"HEADER", L"LISTVIEW", L"MENU", L"PROGRESS", L"REBAR", L"SCROLLBAR", L"SPIN", L"TAB", L"TASKDIALOG", L"TOOLBAR", L"TOOLTIP", L"TRACKBAR", - L"TREEVIEW", L"WINDOW", L"STATUS" + L"TREEVIEW", L"WINDOW", L"STATUS", L"TREEVIEW" }; static inline QBackingStore *backingStoreForWidget(const QWidget *widget) @@ -244,6 +246,7 @@ HRGN XPThemeData::mask(QWidget *widget) // QWindowsXPStylePrivate ------------------------------------------------------------------------- // Static initializations QPixmap *QWindowsXPStylePrivate::tabbody = 0; +HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0; HTHEME QWindowsXPStylePrivate::m_themes[NThemes]; bool QWindowsXPStylePrivate::use_xp = false; QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting @@ -327,6 +330,58 @@ void QWindowsXPStylePrivate::cleanup(bool force) tabbody = 0; } +/* In order to obtain the correct VistaTreeViewTheme (arrows for PE_IndicatorBranch), + * we need to set the windows "explorer" theme explicitly on a native + * window and open the "TREEVIEW" theme handle passing its window handle + * in order to get Vista-style item view themes (particulary drawBackground() + * for selected items needs this). + * We invoke a service of the native Windows interface to create + * a non-visible window handle, open the theme on it and insert it into + * the cache so that it is found by XPThemeData::handle() first. + */ + +static inline HWND createTreeViewHelperWindow() +{ + if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { + void *hwnd = 0; + void *wndProc = reinterpret_cast<void *>(DefWindowProc); + if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, + Q_RETURN_ARG(void *, hwnd), + Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindowClass")), + Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindow")), + Q_ARG(void *, wndProc)) && hwnd) { + return reinterpret_cast<HWND>(hwnd); + } + } + return 0; +} + +bool QWindowsXPStylePrivate::initVistaTreeViewTheming() +{ + if (m_vistaTreeViewHelper) + return true; + + m_vistaTreeViewHelper = createTreeViewHelperWindow(); + if (!m_vistaTreeViewHelper) { + qWarning("Unable to create the treeview helper window."); + return false; + } + if (FAILED(QWindowsXPStylePrivate::pSetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) { + qErrnoWarning("SetWindowTheme() failed."); + cleanupVistaTreeViewTheming(); + return false; + } + return true; +} + +void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() +{ + if (m_vistaTreeViewHelper) { + DestroyWindow(m_vistaTreeViewHelper); + m_vistaTreeViewHelper = 0; + } +} + /* \internal Closes all open theme data handles to ensure that we don't leak resources, and that we don't refere to old handles when for @@ -339,6 +394,7 @@ void QWindowsXPStylePrivate::cleanupHandleMap() pCloseThemeData(m_themes[i]); m_themes[i] = 0; } + QWindowsXPStylePrivate::cleanupVistaTreeViewTheming(); } HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) @@ -349,6 +405,8 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) } if (!m_themes[theme]) { const wchar_t *name = themeNames[theme]; + if (theme == VistaTreeViewTheme && QWindowsXPStylePrivate::initVistaTreeViewTheming()) + hwnd = QWindowsXPStylePrivate::m_vistaTreeViewHelper; m_themes[theme] = pOpenThemeData(hwnd, name); if (Q_UNLIKELY(!m_themes[theme])) qErrnoWarning("OpenThemeData() failed for theme %d (%s).", @@ -1952,7 +2010,7 @@ case PE_Frame: bef_v -= delta; aft_h += delta; aft_v += delta; - XPThemeData theme(0, p, QWindowsXPStylePrivate::TreeViewTheme); + XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme); theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size); theme.partId = TVP_GLYPH; theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED; @@ -3740,10 +3798,12 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt { XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); if (buttontheme.isValid()) { - const QMarginsF borderSize = buttontheme.margins() / QWindowsXPStylePrivate::devicePixelRatio(widget); + const qreal devicePixelRatio = QWindowsXPStylePrivate::devicePixelRatio(widget); + const QMarginsF borderSize = buttontheme.margins() / devicePixelRatio; if (!borderSize.isNull()) { - sz.rwidth() += qRound(borderSize.left() + borderSize.right() - 2); - sz.rheight() += qRound(borderSize.bottom() + borderSize.top() - 2); + const qreal margin = qreal(2) / devicePixelRatio; + sz.rwidth() += qRound(borderSize.left() + borderSize.right() - margin); + sz.rheight() += int(borderSize.bottom() + borderSize.top() - margin + devicePixelRatio - 1); } const int textMargins = 2*(proxy()->pixelMetric(PM_FocusFrameHMargin) + 1); sz += QSize(qMax(pixelMetric(QStyle::PM_ScrollBarExtent, option, widget) diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h index 68aa10e12a..8ee4d1a641 100644 --- a/src/widgets/styles/qwindowsxpstyle_p_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p_p.h @@ -356,9 +356,10 @@ public: ToolBarTheme, ToolTipTheme, TrackBarTheme, - TreeViewTheme, + XpTreeViewTheme, // '+'/'-' shape treeview indicators (XP) WindowTheme, StatusTheme, + VistaTreeViewTheme, // arrow shape treeview indicators (Vista) obtained from "explorer" theme. NThemes }; @@ -419,6 +420,9 @@ private: void showProperties(XPThemeData &themeData); #endif + static bool initVistaTreeViewTheming(); + static void cleanupVistaTreeViewTheming(); + static QBasicAtomicInt ref; static bool use_xp; static QPixmap *tabbody; @@ -430,6 +434,7 @@ private: uchar *bufferPixels; int bufferW, bufferH; + static HWND m_vistaTreeViewHelper; static HTHEME m_themes[NThemes]; }; |