diff --git a/imports/QtDesktop/SpinBox.qml b/imports/QtDesktop/SpinBox.qml index 8c07f596ddce3b85b299d5ababb41802ca5b646f..6da9f39ea74c3d5a53cc5543046844f6c26fe70d 100644 --- a/imports/QtDesktop/SpinBox.qml +++ b/imports/QtDesktop/SpinBox.qml @@ -127,6 +127,7 @@ FocusScope { (upEnabled ? (1<<2) : 0) | (downEnabled == 1 ? (1<<3) : 0) hint: spinbox.styleHint + onFontChanged: input.font = font } } @@ -194,10 +195,14 @@ FocusScope { clip: true + renderType: Text.NativeRendering + font: styleitem.font + x: loader.inputRect.x y: loader.inputRect.y width: loader.inputRect.width - height: loader.inputRect.height + anchors.verticalCenter: parent.verticalCenter + selectByMouse: true selectionColor: syspal.highlight selectedTextColor: syspal.highlightedText @@ -209,6 +214,7 @@ FocusScope { opacity: parent.enabled ? 1 : 0.5 Text { text: postfix + font: input.font anchors.rightMargin: 4 anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter diff --git a/imports/QtDesktop/TableView.qml b/imports/QtDesktop/TableView.qml index ac29d8a18db0ba37b1b98f39d08218e86298809d..56a8eb3def93535055f37c3d6b4fad702a197a72 100644 --- a/imports/QtDesktop/TableView.qml +++ b/imports/QtDesktop/TableView.qml @@ -160,7 +160,7 @@ FocusScope{ id: label width: parent.width anchors.margins: 6 - font.pointSize: itemstyle.fontPointSize + font: itemstyle.font anchors.left: parent.left anchors.right: parent.right horizontalAlignment: itemTextAlignment @@ -629,7 +629,7 @@ FocusScope{ elementType: "header" visible:false contentWidth: 16 - contentHeight: fontHeight + contentHeight: font.pixelSize } StyleItem { diff --git a/src/qstyleitem.cpp b/src/qstyleitem.cpp index 4ac2793ce2a0edf4081e43a6f3054e3fb215d5a0..18986887e1075b385d48b97f8b5c0907852778df 100644 --- a/src/qstyleitem.cpp +++ b/src/qstyleitem.cpp @@ -84,6 +84,7 @@ QStyleItem::QStyleItem(QQuickPaintedItem *parent) m_contentHeight(0) { + m_font = qApp->font(); setFlag(QQuickItem::ItemHasContents, true); setSmooth(false); @@ -416,19 +417,12 @@ void QStyleItem::initStyleOption() if (m_horizontal) m_styleoption->state |= QStyle::State_Horizontal; -// m_styleoption->fontMetrics = widget()->fontMetrics(); - -// if (m_hint.contains("mini")) { -// m_styleoption->state |= Qt::WA_MacMiniSize; -// } else if (m_hint.contains("small")) { -// m_styleoption->state |= Qt::WA_MacSmallSize; -// } -//#ifdef Q_OS_MAC -// if (m_itemType == Button && style() == "mac") { -// // Macstyle hardcodes extra spacing inside the button paintrect -// m_styleoption->rect.adjust(-5, 0, 6, 0); -// } -//#endif + if (m_hint.contains("mini")) { + m_styleoption->state |= QStyle::State_Mini; + } else if (m_hint.contains("small")) { + m_styleoption->state |= QStyle::State_Small; + } + } /* @@ -646,6 +640,22 @@ QVariant QStyleItem::styleHint(const QString &metric) return 0; } +void QStyleItem::setHint(const QString &str) +{ + if (m_hint != str) { + m_hint= str; emit hintChanged(); + + if (hint().contains("mini")) { + m_font.setPointSize(9.); + emit fontChanged(); + } else if (hint().contains("small")) { + m_font.setPointSize(11.); + emit fontChanged(); + } + } +} + + void QStyleItem::setElementType(const QString &str) { if (m_type == str) @@ -663,6 +673,10 @@ void QStyleItem::setElementType(const QString &str) if (str == "menu" || str == "menuitem") { m_itemType = (str == "menu") ? Menu : MenuItem; } else if (str == "item" || str == "itemrow" || str == "header") { +#ifdef Q_OS_MAC + m_font.setPointSize(11.0); + emit fontChanged(); +#endif if (str == "header") { m_itemType = Header; } else { @@ -996,7 +1010,7 @@ void QStyleItem::paint(QPainter *painter) int QStyleItem::textWidth(const QString &text) { - return qApp->fontMetrics().boundingRect(text).width(); + return QFontMetrics(m_font).boundingRect(text).width(); } QString QStyleItem::elidedText(const QString &text, int elideMode, int width) @@ -1004,25 +1018,6 @@ QString QStyleItem::elidedText(const QString &text, int elideMode, int width) return qApp->fontMetrics().elidedText(text, Qt::TextElideMode(elideMode), width); } -int QStyleItem::fontHeight() -{ - return qApp->fontMetrics().height(); -} - -QString QStyleItem::fontFamily() -{ - return qApp->font().family(); -} - -double QStyleItem::fontPointSize() -{ -#ifdef Q_OS_MAC - if (elementType() == "item") - return 11; -#endif - return qApp->font().pointSizeF(); -} - bool QStyleItem::hasThemeIcon(const QString &icon) const { return QIcon::hasThemeIcon(icon); diff --git a/src/qstyleitem.h b/src/qstyleitem.h index 88a7a84640a3274e5c140c83d98b88fc5610721b..14e7f1f9839c250f9900118da39f6f71fdd5b705 100644 --- a/src/qstyleitem.h +++ b/src/qstyleitem.h @@ -64,6 +64,7 @@ class QStyleItem: public QQuickPaintedItem Q_PROPERTY( QString info READ info WRITE setInfo NOTIFY infoChanged) Q_PROPERTY( QString style READ style NOTIFY styleChanged) Q_PROPERTY( QString hint READ hint WRITE setHint NOTIFY hintChanged) + Q_PROPERTY( QFont font READ font NOTIFY fontChanged) // For range controls Q_PROPERTY( int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged) @@ -75,10 +76,6 @@ class QStyleItem: public QQuickPaintedItem Q_PROPERTY( int contentWidth READ contentWidth() WRITE setContentWidth NOTIFY contentWidthChanged) Q_PROPERTY( int contentHeight READ contentHeight() WRITE setContentHeight NOTIFY contentHeightChanged) - Q_PROPERTY( QString fontFamily READ fontFamily NOTIFY fontHeightChanged) - Q_PROPERTY( double fontPointSize READ fontPointSize NOTIFY fontHeightChanged) - Q_PROPERTY( int fontHeight READ fontHeight NOTIFY fontHeightChanged) - public: QStyleItem(QQuickPaintedItem *parent = 0); ~QStyleItem(); @@ -137,6 +134,7 @@ public: QString activeControl() const { return m_activeControl; } QString info() const { return m_info; } QString hint() const { return m_hint; } + QFont font() const { return m_font;} QString style() const; void setSunken(bool sunken) { if (m_sunken != sunken) {m_sunken = sunken; emit sunkenChanged();}} @@ -151,30 +149,17 @@ public: void setMaximum(int maximum) { if (m_maximum != maximum) {m_maximum = maximum; emit maximumChanged();}} void setValue(int value) { if (m_value!= value) {m_value = value; emit valueChanged();}} void setStep(int step) { if (m_step != step) { m_step = step; emit stepChanged(); }} - void setPaintMargins(int value) { - Q_UNUSED(value) - if (m_paintMargins!= value) {m_paintMargins = value;} - } + void setPaintMargins(int value) { if (m_paintMargins!= value) {m_paintMargins = value;} } void setElementType(const QString &str); void setText(const QString &str) { if (m_text != str) {m_text = str; emit textChanged();}} void setActiveControl(const QString &str) { if (m_activeControl != str) {m_activeControl = str; emit activeControlChanged();}} void setInfo(const QString &str) { if (m_info != str) {m_info = str; emit infoChanged();}} - void setHint(const QString &str) { if (m_hint != str) {m_hint= str; emit hintChanged();}} - - virtual void initStyleOption (); - - int fontHeight(); - QString fontFamily(); - double fontPointSize(); + void setHint(const QString &str); + int contentWidth() const { return m_contentWidth; } + int contentHeight() const { return m_contentHeight; } - int contentWidth() const { - return m_contentWidth; - } - - int contentHeight() const { - return m_contentHeight; - } + virtual void initStyleOption (); public Q_SLOTS: int pixelMetric(const QString&); @@ -223,7 +208,7 @@ Q_SIGNALS: void styleChanged(); void paintMarginsChanged(); void hintChanged(); - void fontHeightChanged(); + void fontChanged(); void contentWidthChanged(int arg); void contentHeightChanged(int arg); @@ -241,6 +226,7 @@ protected: QString m_activeControl; QString m_info; QString m_hint; + QFont m_font; bool m_sunken; bool m_raised;