From 01518ec2e28bfc9f95a8f440a77814a69b92a447 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Date: Fri, 26 Apr 2013 17:13:21 +0200 Subject: [PATCH] StyleItem: Add support for 'small', 'mini' style hints Currently supports Button and ComboBox. Change-Id: I0c051e7c6f93d53861e6b8869f3fd3a9478cdee0 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> --- src/private/qquickstyleitem.cpp | 32 +++++++++++++++++++++++++--- src/styles/Desktop/ComboBoxStyle.qml | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp index 4cc0d42a9..b54f38695 100644 --- a/src/private/qquickstyleitem.cpp +++ b/src/private/qquickstyleitem.cpp @@ -177,6 +177,10 @@ void QQuickStyleItem::initStyleOption() if (m_styleoption) m_styleoption->state = 0; + QPlatformTheme::Font platformFont = (m_hints.indexOf("mini") != -1) ? QPlatformTheme::MiniFont : + (m_hints.indexOf("small") != -1) ? QPlatformTheme::SmallFont : + QPlatformTheme::SystemFont; + switch (m_itemType) { case Button: { if (!m_styleoption) @@ -190,7 +194,10 @@ void QQuickStyleItem::initStyleOption() opt->features = (activeControl() == "default") ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None; - if (const QFont *font = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::PushButtonFont)) + if (platformFont == QPlatformTheme::SystemFont) + platformFont = QPlatformTheme::PushButtonFont; + const QFont *font = QGuiApplicationPrivate::platformTheme()->font(platformFont); + if (font) opt->fontMetrics = QFontMetrics(*font); } break; @@ -439,8 +446,12 @@ void QQuickStyleItem::initStyleOption() case ComboBox :{ if (!m_styleoption) m_styleoption = new QStyleOptionComboBox(); + QStyleOptionComboBox *opt = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); - const QFont *font = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::PushButtonFont); + + if (platformFont == QPlatformTheme::SystemFont) + platformFont = QPlatformTheme::PushButtonFont; + const QFont *font = QGuiApplicationPrivate::platformTheme()->font(platformFont); if (font) opt->fontMetrics = QFontMetrics(*font); opt->currentText = text(); @@ -448,7 +459,14 @@ void QQuickStyleItem::initStyleOption() #ifdef Q_OS_MAC if (m_properties["popup"].canConvert<QObject *>() && style() == "mac") { QObject *popup = m_properties["popup"].value<QObject *>(); - popup->setProperty("__yOffset", 6); + if (platformFont == QPlatformTheme::MiniFont) { + popup->setProperty("__xOffset", -2); + popup->setProperty("__yOffset", 5); + } else { + if (platformFont == QPlatformTheme::SmallFont) + popup->setProperty("__xOffset", -1); + popup->setProperty("__yOffset", 6); + } if (font) popup->setProperty("__font", *font); } @@ -1102,6 +1120,14 @@ void QQuickStyleItem::paint(QPainter *painter) initStyleOption(); if (QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption)) painter->setFont(opt->font); + else { + QPlatformTheme::Font platformFont = (m_styleoption->state & QStyle::State_Mini) ? QPlatformTheme::MiniFont : + (m_styleoption->state & QStyle::State_Small) ? QPlatformTheme::SmallFont : + QPlatformTheme::NFonts; + if (platformFont != QPlatformTheme::NFonts) + if (const QFont *font = QGuiApplicationPrivate::platformTheme()->font(platformFont)) + painter->setFont(*font); + } // Set AA_UseHighDpiPixmaps when calling style code to make QIcon return // "retina" pixmaps. The flag is controlled by the application so we can't diff --git a/src/styles/Desktop/ComboBoxStyle.qml b/src/styles/Desktop/ComboBoxStyle.qml index 83215a13d..852ef741b 100644 --- a/src/styles/Desktop/ComboBoxStyle.qml +++ b/src/styles/Desktop/ComboBoxStyle.qml @@ -67,6 +67,7 @@ Style { // contentHeight as in QComboBox contentHeight: Math.max(Math.ceil(textHeight("")), 14) + 2 + hints: control.styleHints properties: { "popup": control.__popup } -- GitLab