diff --git a/designsystems/fluent2/QskFluent2Skin.cpp b/designsystems/fluent2/QskFluent2Skin.cpp index 1225f447..6ef5a14a 100644 --- a/designsystems/fluent2/QskFluent2Skin.cpp +++ b/designsystems/fluent2/QskFluent2Skin.cpp @@ -95,6 +95,7 @@ #include #include #include +#include #include #include @@ -102,22 +103,30 @@ #include #include +namespace Fluent2 +{ + using F = QskFontRole; + + /* + Fluent2/Windows font roles according to: + https://fluent2.microsoft.design/typography + */ + constexpr F Caption = { F::Caption, F::Normal }; + + constexpr F Body = { F::Body, F::Normal }; + constexpr F BodyStrong = { F::Body, F::High }; + constexpr F BodyStronger = { F::Body, F::VeryHigh }; + + constexpr F Subtitle = { F::Subtitle, F::Normal }; + + constexpr F Title = { F::Title, F::Normal }; + + constexpr F LargeTitle = { F::Headline, F::Normal }; + constexpr F Display = { F::Display, F::Normal }; +} + namespace { - inline QFont createFont( const QString& name, qreal lineHeight, - qreal size, qreal tracking, QFont::Weight weight ) - { - QFont font( name, qRound( size ) ); - font.setPixelSize( qRound( lineHeight ) ); - - if( !qskFuzzyCompare( tracking, 0.0 ) ) - font.setLetterSpacing( QFont::AbsoluteSpacing, tracking ); - - font.setWeight( weight ); - - return font; - } - inline constexpr QRgb rgbGray( int value, qreal opacity = 1.0 ) { return qRgba( value, value, value, qRound( opacity * 255 ) ); @@ -395,7 +404,7 @@ void Editor::setupCheckBoxMetrics() setBoxBorderMetrics( Q::Box, 1 ); setPadding( Q::Box, 5 ); // "icon size" - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); } void Editor::setupCheckBoxColors( @@ -520,7 +529,7 @@ void Editor::setupComboBoxMetrics() setPadding( Q::Icon, { 0, 0, 8, 0 } ); setAlignment( Q::Text, Qt::AlignLeft | Qt::AlignVCenter ); - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); setStrutSize( Q::StatusIndicator, 12, 12 ); setSymbol( Q::StatusIndicator, symbol( "spin-box-arrow-down" ) ); @@ -767,7 +776,7 @@ void Editor::setupMenuMetrics() setSpacing( Q::Segment, 15 ); setBoxBorderMetrics( Q::Segment | Q::Selected, { 3, 0, 0, 0 } ); - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); setStrutSize( Q::Icon, 12, 12 ); setPadding( Q::Icon, { 8, 8, 0, 8 } ); @@ -965,7 +974,7 @@ void Editor::setupPushButtonMetrics() setStrutSize( Q::Icon, 12, 12 ); setPadding( Q::Icon, { 0, 0, 8, 0 } ); - setFontRole( Q::Text, W::Body ); + setFontRole( Q::Text, Fluent2::Body ); } void Editor::setupPushButtonColors( @@ -1105,7 +1114,7 @@ void Editor::setupRadioBoxMetrics() setBoxBorderMetrics( Q::CheckIndicatorPanel | Q::Disabled | Q::Selected, 0 ); setPadding( Q::CheckIndicatorPanel | Q::Disabled | Q::Selected, { 6, 6 } ); // indicator "strut size" - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); } void Editor::setupRadioBoxColors( @@ -1288,7 +1297,7 @@ void Editor::setupSegmentedBarMetrics() setStrutSize( Q::Icon, { 12, 12 } ); - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); setStrutSize( Q::Segment | A::Horizontal, segmentStrutSize ); setStrutSize( Q::Segment | A::Vertical, segmentStrutSize.transposed() ); @@ -1485,7 +1494,7 @@ void Editor::setupSpinBoxMetrics() setPadding( Q::Panel, { 11, 0, 11, 0 } ); setAlignment( Q::Text, Qt::AlignLeft ); - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); setPadding( Q::TextPanel, { 11, 5, 0, 0 } ); @@ -1593,8 +1602,8 @@ void Editor::setupTabButtonMetrics() setBoxBorderMetrics( Q::Panel, { 0, 0, 0, 1 } ); setBoxBorderMetrics( Q::Panel | Q::Checked, { 1, 1, 1, 0 } ); - setFontRole( Q::Text, QskFluent2Skin::Body ); - setFontRole( Q::Text | Q::Checked, QskFluent2Skin::BodyStrong ); + setFontRole( Q::Text, Fluent2::Body ); + setFontRole( Q::Text | Q::Checked, Fluent2::BodyStrong ); } void Editor::setupTabButtonColors( @@ -1689,7 +1698,7 @@ void Editor::setupTextLabelMetrics() setBoxShape( Q::Panel, 3 ); setBoxBorderMetrics( Q::Panel, 1 ); - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); } void Editor::setupTextLabelColors( @@ -1719,7 +1728,7 @@ void Editor::setupTextInputMetrics() setBoxShape( Q::Panel, 3 ); setAlignment( Q::Text, Qt::AlignLeft | Qt::AlignVCenter ); - setFontRole( Q::Text, QskFluent2Skin::Body ); + setFontRole( Q::Text, Fluent2::Body ); } void Editor::setupTextInputColors( @@ -1915,7 +1924,7 @@ void Editor::setupSubWindow( const QskFluent2Theme& theme ) setHint( Q::TitleBarPanel | QskAspect::Style, Q::NoDecoration ); setPadding( Q::TitleBarPanel, { 24, 31, 24, 0 } ); - setFontRole( Q::TitleBarText, QskFluent2Skin::Subtitle ); + setFontRole( Q::TitleBarText, Fluent2::Subtitle ); setColor( Q::TitleBarText, pal.fillColor.text.primary ); setAlignment( Q::TitleBarText, Qt::AlignLeft ); setTextOptions( Q::TitleBarText, Qt::ElideRight, QskTextOptions::NoWrap ); @@ -1927,7 +1936,7 @@ void Editor::setupDialogSubWindow( const QskFluent2Theme& ) { using Q = QskDialogSubWindow; - setFontRole( Q::DialogTitle, QskFluent2Skin::Subtitle ); + setFontRole( Q::DialogTitle, Fluent2::Subtitle ); setAlignment( Q::DialogTitle, Qt::AlignLeft | Qt::AlignVCenter ); setTextOptions( Q::DialogTitle, Qt::ElideRight, QskTextOptions::WordWrap ); } @@ -1937,7 +1946,7 @@ void Editor::setupVirtualKeyboardMetrics() using Q = QskVirtualKeyboard; setMargin( Q::ButtonPanel, 2 ); - setFontRole( Q::ButtonText, QskFluent2Skin::BodyLarge ); + setFontRole( Q::ButtonText, Fluent2::BodyStrong ); setPadding( Q::Panel, 8 ); } @@ -2003,13 +2012,13 @@ void QskFluent2Skin::initHints() { colors[0].baseColors = { rgbGray( 32 ), rgbGray( 40 ), rgbGray( 28 ) }; colors[0].accentColors = { 0xff0078d4, 0xff0093f9, 0xff60ccfe, 0xff98ecfe }; - + colors[1].baseColors = { rgbGray( 40 ), rgbGray( 44 ), rgbGray( 28 ) }; colors[1].accentColors = colors[0].accentColors; } setupFonts(); - + Editor editor( &hintTable() ); editor.setupMetrics(); @@ -2024,19 +2033,50 @@ void QskFluent2Skin::initHints() addTheme( QskAspect::Footer, themeHeader ); } +static inline QFont createFont( int size, int lineHeight, QFont::Weight weight ) +{ + Q_UNUSED( size ); // ??? + const int pixelSize = qRound( qskDpToPixels( lineHeight ) ); + + /* + Font size determines how big or small the letters are, while line height + controls the vertical space between the lines of text. + + https://doc.qt.io/qt-6/qfont.html#details: + "It is possible to set the height of characters shown on the screen + to a specified number of pixels with setPixelSize()" + + https://doc.qt.io/qt-5/qfontmetrics.html#lineSpacing: + "This value is always equal to leading()+height()" + */ + + QFont font( QStringLiteral( "Segoe UI Variable" ), -1, weight ); + + // sp: this is like the dp unit, but it is also scaled by the user's font size preference + font.setPixelSize( pixelSize ); + + return font; +} + void QskFluent2Skin::setupFonts() { - static QString fontName( QStringLiteral( "Segoe UI Variable" ) ); - Inherited::setupFonts( fontName ); + // see: https://fluent2.microsoft.design/typography ( Windows ) - setFont( Caption, createFont( fontName, 12, 16, 0.0, QFont::Normal ) ); - setFont( Body, createFont( fontName, 14, 20, 0.0, QFont::Normal ) ); - setFont( BodyStrong, createFont( fontName, 14, 20, 0.0, QFont::DemiBold ) ); - setFont( BodyLarge, createFont( fontName, 18, 24, 0.0, QFont::Medium ) ); - setFont( Subtitle, createFont( fontName, 20, 28, 0.0, QFont::DemiBold ) ); - setFont( Title, createFont( fontName, 28, 36, 0.0, QFont::DemiBold ) ); - setFont( TitleLarge, createFont( fontName, 40, 52, 0.0, QFont::DemiBold ) ); - setFont( Display, createFont( fontName, 68, 92, 0.0, QFont::DemiBold ) ); + setFont( Fluent2::Caption, createFont( 12, 16, QFont::Normal ) ); + + setFont( Fluent2::Body, createFont( 14, 20, QFont::Normal ) ); + setFont( Fluent2::BodyStrong, createFont( 14, 20, QFont::DemiBold ) ); + setFont( Fluent2::BodyStronger, createFont( 18, 24, QFont::Normal ) ); + + setFont( Fluent2::Subtitle, createFont( 20, 28, QFont::DemiBold ) ); + + setFont( Fluent2::Title, createFont( 28, 36, QFont::Normal ) ); + setFont( Fluent2::LargeTitle, createFont( 40, 52, QFont::DemiBold ) ); + + setFont( Fluent2::Display, createFont( 68, 92, QFont::DemiBold ) ); + + // to have something for the unused roles + QskSkin::completeFontTable(); } void QskFluent2Skin::setGraphicColor( GraphicRole role, QRgb rgb ) diff --git a/designsystems/fluent2/QskFluent2Skin.h b/designsystems/fluent2/QskFluent2Skin.h index 239a73a8..5a72c481 100644 --- a/designsystems/fluent2/QskFluent2Skin.h +++ b/designsystems/fluent2/QskFluent2Skin.h @@ -31,18 +31,6 @@ class QSK_FLUENT2_EXPORT QskFluent2Skin : public QskSkin GraphicRoleFillColorTextSecondary, }; - enum FontRole - { - Caption = TinyFont, - Body = DefaultFont, - BodyStrong = SmallFont, - BodyLarge = MediumFont, - Subtitle = LargeFont, - Title = HugeFont, - TitleLarge, - Display, - }; - static constexpr QskAspect::Variation Standard = QskAspect::NoVariation; static constexpr QskAspect::Variation Accent = QskAspect::Large; diff --git a/designsystems/fusion/QskFusionSkin.cpp b/designsystems/fusion/QskFusionSkin.cpp index 8b93fd38..b2add0a2 100644 --- a/designsystems/fusion/QskFusionSkin.cpp +++ b/designsystems/fusion/QskFusionSkin.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -681,7 +682,7 @@ void Editor::setupPageIndicator() void Editor::setupPushButton() { /* - QC2/Fusion offers flat/highlighted. We could the emphasis variations to + QC2/Fusion offers flat/highlighted. We could the emphasis variations to have the same: TODO ... */ using Q = QskPushButton; @@ -741,7 +742,7 @@ void Editor::setupDialogSubWindow() using Q = QskDialogSubWindow; #if 1 - setFontRole( Q::DialogTitle, QskFusionSkin::LargeFont ); + setFontRole( Q::DialogTitle, QskFontRole::Headline ); #endif setAlignment( Q::DialogTitle, Qt::AlignLeft | Qt::AlignVCenter ); setTextOptions( Q::DialogTitle, Qt::ElideRight, QskTextOptions::WordWrap ); @@ -1324,7 +1325,10 @@ void QskFusionSkin::initHints() using P = QPalette; - setupFonts( QStringLiteral( "Roboto" ) ); +#if 1 + // we should use QApplication::font somehow: TODO ... + setupFontTable( QStringLiteral( "Roboto" ) ); +#endif const QskFusionPalette palette( colorScheme() ); diff --git a/designsystems/material3/QskMaterial3Skin.cpp b/designsystems/material3/QskMaterial3Skin.cpp index a8247e17..b9139e26 100644 --- a/designsystems/material3/QskMaterial3Skin.cpp +++ b/designsystems/material3/QskMaterial3Skin.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,36 @@ static const int qskDuration = 150; +namespace +{ + using F = QskFontRole; + + /* + Material 3 font roles according to: + https://m3.material.io/styles/typography/overview + https://www.figma.com/file/O4H724CKmUVPocw6JoSUrd/Material-3-Design-Kit-(Community)?type=design&node-id=49848-6285&mode=design + */ + constexpr F LabelSmall = { F::Caption, F::Low }; + constexpr F LabelMedium = { F::Caption, F::Normal }; + constexpr F LabelLarge = { F::Caption, F::High }; + + constexpr F BodySmall = { F::Body, F::Low }; + constexpr F BodyMedium = { F::Body, F::Normal }; + constexpr F BodyLarge = { F::Body, F::High }; + + constexpr F TitleSmall = { F::Title, F::Low }; + constexpr F TitleMedium = { F::Title, F::Normal }; + constexpr F TitleLarge = { F::Title, F::High }; + + constexpr F HeadlineSmall = { F::Headline, F::Low }; + constexpr F HeadlineMedium = { F::Headline, F::Normal }; + constexpr F HeadlineLarge = { F::Headline, F::High }; + + constexpr F DisplaySmall = { F::Display, F::Low }; + constexpr F DisplayMedium = { F::Display, F::Normal }; + constexpr F DisplayLarge = { F::Display, F::High }; +} + namespace { Q_DECL_UNUSED inline double operator ""_dp( long double value ) @@ -131,20 +162,6 @@ namespace const QskMaterial3Theme& m_pal; }; - QFont createFont( const QString& name, qreal lineHeight, - qreal size, qreal tracking, QFont::Weight weight ) - { - QFont font( name, qRound( size ) ); - font.setPixelSize( qRound( lineHeight ) ); - - if( !qskFuzzyCompare( tracking, 0.0 ) ) - font.setLetterSpacing( QFont::AbsoluteSpacing, tracking ); - - font.setWeight( weight ); - - return font; - } - inline QRgb flattenedColor( QRgb foregroundColor, QRgb backgroundColor, qreal ratio ) { @@ -270,7 +287,7 @@ void Editor::setupComboBox() setGraphicRole( Q::Icon, QskMaterial3Skin::GraphicRoleOnSurface ); setColor( Q::Text, m_pal.onSurface ); - setFontRole( Q::Text, QskMaterial3Skin::M3BodyMedium ); + setFontRole( Q::Text, BodyMedium ); setStrutSize( Q::StatusIndicator, 12_dp, 12_dp ); setGraphicRole( Q::StatusIndicator, QskMaterial3Skin::GraphicRoleOnSurface ); @@ -353,7 +370,7 @@ void Editor::setupMenu() setGraphicRole( Q::Icon, QskMaterial3Skin::GraphicRoleOnSurface ); setColor( Q::Text, m_pal.onSurface ); - setFontRole( Q::Text, QskMaterial3Skin::M3BodyMedium ); + setFontRole( Q::Text, BodyMedium ); setAnimation( Q::Cursor | A::Position | A::Metric, 75, QEasingCurve::OutCubic ); @@ -392,7 +409,7 @@ void Editor::setupTextInput() // ### Also add a pressed state setColor( Q::Text, m_pal.onSurface ); - setFontRole( Q::Text, QskMaterial3Skin::M3BodyMedium ); + setFontRole( Q::Text, BodyMedium ); setAlignment( Q::Text, Qt::AlignLeft | Qt::AlignVCenter ); const auto disabledPanelColor = QskRgb::toTransparentF( m_pal.onSurface, 0.04 ); @@ -553,7 +570,7 @@ void Editor::setupSegmentedBar() { // Text - setFontRole( Q::Text, QskMaterial3Skin::M3LabelLarge ); + setFontRole( Q::Text, LabelLarge ); setTextOptions( Q::Text, Qt::ElideMiddle, QskTextOptions::NoWrap ); setColor( Q::Text, m_pal.onSurface ); @@ -630,7 +647,7 @@ void Editor::setupPushButton() setPadding( Q::Icon, { 0, 0, 8_dp, 0 } ); setGraphicRole( Q::Icon, QskMaterial3Skin::GraphicRoleOnPrimary ); - setFontRole( Q::Text, QskMaterial3Skin::M3LabelLarge ); + setFontRole( Q::Text, LabelLarge ); setPadding( Q::Text, 0 ); setBoxShape( Q::Splash, 40_dp ); @@ -784,7 +801,7 @@ void Editor::setupDialogSubWindow() using Q = QskDialogSubWindow; #if 1 - setFontRole( Q::DialogTitle, QskMaterial3Skin::M3BodyLarge ); + setFontRole( Q::DialogTitle, BodyLarge ); #endif setAlignment( Q::DialogTitle, Qt::AlignLeft | Qt::AlignVCenter ); setTextOptions( Q::DialogTitle, Qt::ElideRight, QskTextOptions::WordWrap ); @@ -1035,7 +1052,7 @@ void Editor::setupTabButton() setAnimation( Q::Panel | A::Color, qskDuration ); - setFontRole( Q::Text, QskMaterial3Skin::M3LabelLarge ); + setFontRole( Q::Text, LabelLarge ); setAlignment( Q::Text, Qt::AlignCenter ); } @@ -1106,7 +1123,7 @@ void Editor::setupVirtualKeyboard() setAnimation( Q::ButtonPanel | A::Metric, qskDuration ); setColor( Q::ButtonText, m_pal.onBackground ); - setFontRole( Q::ButtonText, QskMaterial3Skin::M3HeadlineSmall ); + setFontRole( Q::ButtonText, HeadlineSmall ); // panel setGradient( Q::Panel, m_pal.background ); @@ -1202,7 +1219,7 @@ void Editor::setupListView() } } - setFontRole( Q::Text, QskMaterial3Skin::M3BodyMedium ); + setFontRole( Q::Text, BodyMedium ); setColor( Q::Text, m_pal.onSurface ); setColor( Q::Text | Q::Disabled, m_pal.onSurface38 ); @@ -1236,7 +1253,7 @@ void Editor::setupSubWindow() setGradient( Q::TitleBarPanel, m_pal.secondaryContainer ); // TitleBarText - setFontRole( Q::TitleBarText, QskMaterial3Skin::M3HeadlineSmall ); + setFontRole( Q::TitleBarText, HeadlineSmall ); setColor( Q::TitleBarText, m_pal.onSurface ); setAlignment( Q::TitleBarText, Qt::AlignCenter ); @@ -1412,17 +1429,57 @@ QskMaterial3Skin::~QskMaterial3Skin() { } +static inline QFont createFont( int size, int lineHeight, + qreal spacing, QFont::Weight weight ) +{ + Q_UNUSED( size ); + + /* + sp (Scaleable Pixels OR scale-independent pixels) — this is + like the dp unit, but it is also scaled by the user’s font size preference. + It is recommended you use this unit when specifying font sizes, so they will + be adjusted for both the screen density and user’s preference. + */ + + const int pixelSize = qRound( qskDpToPixels( lineHeight ) ); + + QFont font( QStringLiteral( "Roboto" ), -1, weight ); + font.setPixelSize( pixelSize ); + + if ( spacing > 0.0 ) + font.setLetterSpacing( QFont::AbsoluteSpacing, spacing ); + + return font; +} + void QskMaterial3Skin::setupFonts() { - Inherited::setupFonts( QStringLiteral( "Roboto" ) ); + setFont( LabelSmall, createFont( 11, 16, 0.5, QFont::Medium ) ); + setFont( LabelMedium, createFont( 12, 16, 0.5, QFont::Medium ) ); + setFont( LabelLarge, createFont( 14, 20, 0.1, QFont::Medium ) ); - setFont( M3BodyMedium, - createFont( QStringLiteral( "Roboto Regular"), 20_dp, 14_dp, 0.25, QFont::Normal ) ); - setFont( M3BodyLarge, - createFont( QStringLiteral( "Roboto Medium" ), 24_dp, 16_dp, 0.5, QFont::Normal ) ); - setFont( M3HeadlineSmall, - createFont( QStringLiteral( "Roboto Regular" ), 32_dp, 28_dp, 0.0, QFont::Normal ) ); - setFont( M3LabelLarge, createFont( "Roboto Medium", 20_dp, 14_dp, 0.1, QFont::Medium ) ); + setFont( BodySmall, createFont( 12, 16, 0.4, QFont::Normal ) ); + setFont( BodyMedium, createFont( 14, 20, 0.25, QFont::Normal ) ); + setFont( BodyLarge, createFont( 16, 24, 0.5, QFont::Normal ) ); + + setFont( TitleSmall, createFont( 14, 20, 0.1, QFont::Medium ) ); + setFont( TitleMedium, createFont( 16, 24, 0.15, QFont::Medium ) ); + setFont( TitleLarge, createFont( 22, 28, 0.0, QFont::Normal ) ); + + setFont( HeadlineSmall, createFont( 24, 32, 0.0, QFont::Normal ) ); + setFont( HeadlineMedium, createFont( 28, 36, 0.0, QFont::Medium ) ); + setFont( HeadlineLarge, createFont( 32, 40, 0.0, QFont::Medium ) ); + + setFont( DisplaySmall, createFont( 36, 44, 0.0, QFont::Normal ) ); + setFont( DisplayMedium, createFont( 45, 52, 0.0, QFont::Normal ) ); + setFont( DisplayLarge, createFont( 57, 64, 0.0, QFont::Normal ) ); + + // to have something for the unused roles + + setFont( { QskFontRole::Subtitle, QskFontRole::Normal }, + createFont( 16, 24, 0.0, QFont::Normal ) ); + + QskSkin::completeFontTable(); } void QskMaterial3Skin::setGraphicColor( GraphicRole role, QRgb rgb ) diff --git a/designsystems/material3/QskMaterial3Skin.h b/designsystems/material3/QskMaterial3Skin.h index 95a89310..b790addb 100644 --- a/designsystems/material3/QskMaterial3Skin.h +++ b/designsystems/material3/QskMaterial3Skin.h @@ -103,9 +103,6 @@ class QSK_MATERIAL3_EXPORT QskMaterial3Skin : public QskSkin using Inherited = QskSkin; public: - QskMaterial3Skin( QObject* parent = nullptr ); - ~QskMaterial3Skin() override; - enum GraphicRole { GraphicRoleOnError, @@ -118,13 +115,8 @@ class QSK_MATERIAL3_EXPORT QskMaterial3Skin : public QskSkin GraphicRoleSurface, }; - enum FontRole - { - M3BodyMedium = DefaultFont, - M3BodyLarge = LargeFont, - M3HeadlineSmall = SmallFont, - M3LabelLarge = HugeFont, - }; + QskMaterial3Skin( QObject* parent = nullptr ); + ~QskMaterial3Skin() override; static constexpr QskAspect::Variation Filled = QskAspect::NoVariation; static constexpr QskAspect::Variation Tonal = QskAspect::Huge; diff --git a/examples/gallery/CMakeLists.txt b/examples/gallery/CMakeLists.txt index 4941b1ff..d8d02042 100644 --- a/examples/gallery/CMakeLists.txt +++ b/examples/gallery/CMakeLists.txt @@ -4,7 +4,6 @@ ############################################################################ set(SOURCES - label/LabelPage.h label/LabelPage.cpp inputs/InputPage.h inputs/InputPage.cpp progressbar/ProgressBarPage.h progressbar/ProgressBarPage.cpp button/ButtonPage.h button/ButtonPage.cpp diff --git a/examples/gallery/label/LabelPage.cpp b/examples/gallery/label/LabelPage.cpp deleted file mode 100644 index d979d726..00000000 --- a/examples/gallery/label/LabelPage.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#include "LabelPage.h" -#include -#include -#include -#include -#include - -namespace -{ - class TextLabel : public QskTextLabel - { - public: - TextLabel( int role, QQuickItem* parent = nullptr ) - : QskTextLabel( parent ) - { - setAlignment( Qt::AlignCenter ); - setText( textFromRole( role ) ); - setFontRole( role ); - - setSizePolicy( Qt::Horizontal, QskSizePolicy::Ignored ); - } - - private: - QString textFromRole( int role ) const - { - static QMetaEnum metaEnum; - - if ( !metaEnum.isValid() ) - { - const auto& mo = QskSkin::staticMetaObject; - metaEnum = mo.enumerator( mo.indexOfEnumerator( "SkinFontRole" ) ); - } - - QString s( metaEnum.valueToKey( role ) ); - s.remove( QStringLiteral( "Font" ) ); - - return s; - } - }; - - class TextBox : public QskLinearBox - { - public: - TextBox( QQuickItem* parent = nullptr ) - : QskLinearBox( Qt::Horizontal, 3, parent ) - { - setMargins( 10 ); - setDefaultAlignment( Qt::AlignCenter ); - - for ( int i = 0; i <= QskSkin::HugeFont; i++ ) - ( void ) new TextLabel( i, this ); - } - }; - - class IconBox : public QskLinearBox - { - public: - IconBox( QQuickItem* parent = nullptr ) - : QskLinearBox( Qt::Horizontal, 3, parent ) - { - setMargins( 10 ); - setSpacing( 20 ); - - const char* icons[] = - { - "rectangle/royalblue", - "triangleright/thistle", - "ellipse/khaki", - "ring/sandybrown", - "star/darkviolet", - "hexagon/darkslategray" - }; - - const auto prefix = QStringLiteral( "image://shapes/" ); - - for ( const auto icon : icons ) - { - auto label = new QskGraphicLabel( prefix + icon, this ); - label->setAlignment( Qt::AlignCenter ); - } - } - }; -} - -LabelPage::LabelPage( QQuickItem* parent ) - : Page( Qt::Vertical, parent ) -{ - setSpacing( 40 ); - - (void) new TextBox( this ); - (void) new QskSeparator( this ); - (void) new IconBox( this ); -} diff --git a/examples/gallery/label/LabelPage.h b/examples/gallery/label/LabelPage.h deleted file mode 100644 index b25cc549..00000000 --- a/examples/gallery/label/LabelPage.h +++ /dev/null @@ -1,14 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#pragma once - -#include "Page.h" - -class LabelPage : public Page -{ - public: - LabelPage( QQuickItem* = nullptr ); -}; diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 26878e3c..fad5d426 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -3,7 +3,6 @@ * SPDX-License-Identifier: BSD-3-Clause *****************************************************************************/ -#include "label/LabelPage.h" #include "progressbar/ProgressBarPage.h" #include "inputs/InputPage.h" #include "button/ButtonPage.h" @@ -261,7 +260,6 @@ namespace { auto tabView = new TabView( this ); tabView->addPage( "Buttons", new ButtonPage() ); - tabView->addPage( "Labels", new LabelPage() ); tabView->addPage( "Inputs", new InputPage() ); tabView->addPage( "Indicators", new ProgressBarPage() ); tabView->addPage( "Selectors", new SelectorPage() ); diff --git a/examples/iotdashboard/Box.cpp b/examples/iotdashboard/Box.cpp index 5ce0c9a8..93a4eb00 100644 --- a/examples/iotdashboard/Box.cpp +++ b/examples/iotdashboard/Box.cpp @@ -7,6 +7,7 @@ #include "Skin.h" #include +#include QSK_SUBCONTROL( Box, Panel ) @@ -19,7 +20,7 @@ Box::Box( const QString& title, QQuickItem* parent ) if ( !title.isEmpty() ) { auto label = new QskTextLabel( title, this ); - label->setFontRole( Skin::TitleFont ); + label->setFontRole( { QskFontRole::Caption, QskFontRole::High } ); } } diff --git a/examples/iotdashboard/BoxWithButtons.cpp b/examples/iotdashboard/BoxWithButtons.cpp index 3ad42e90..7df72a99 100644 --- a/examples/iotdashboard/BoxWithButtons.cpp +++ b/examples/iotdashboard/BoxWithButtons.cpp @@ -10,6 +10,7 @@ #include #include +#include QSK_SUBCONTROL( BoxWithButtons, ValueText ) QSK_SUBCONTROL( BoxWithButtons, ValuePanel ) @@ -66,7 +67,7 @@ BoxWithButtons::BoxWithButtons( titleAndValue->setSubcontrolProxy( QskBox::Panel, ValuePanel ); auto* titleLabel = new QskTextLabel( title, titleAndValue ); - titleLabel->setFontRole( Skin::TitleFont ); + titleLabel->setFontRole( { QskFontRole::Caption, QskFontRole::High } ); m_valueLabel = new QskTextLabel( titleAndValue ); m_valueLabel->setSubcontrolProxy( QskTextLabel::Text, ValueText ); diff --git a/examples/iotdashboard/DevicesPage.cpp b/examples/iotdashboard/DevicesPage.cpp index 811840bc..8a394383 100644 --- a/examples/iotdashboard/DevicesPage.cpp +++ b/examples/iotdashboard/DevicesPage.cpp @@ -5,8 +5,8 @@ #include "DevicesPage.h" -#include #include +#include QSK_SUBCONTROL( DevicesPage, Panel ) @@ -15,7 +15,7 @@ DevicesPage::DevicesPage( QQuickItem* parent ) { auto* const textLabel = new QskTextLabel( "devices page", this ); textLabel->setAlignmentHint( QskTextLabel::Text, Qt::AlignCenter ); - textLabel->setFontRole( QskSkin::HugeFont ); + textLabel->setFontRole( QskFontRole::Display ); } #include "moc_DevicesPage.cpp" diff --git a/examples/iotdashboard/EnergyMeter.cpp b/examples/iotdashboard/EnergyMeter.cpp index 836dc977..f9d20537 100644 --- a/examples/iotdashboard/EnergyMeter.cpp +++ b/examples/iotdashboard/EnergyMeter.cpp @@ -7,7 +7,7 @@ #include "CircularProgressBar.h" #include -#include +#include namespace { @@ -19,7 +19,7 @@ namespace { initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); setLayoutAlignmentHint( Qt::AlignCenter ); - setFontRole( QskSkin::SmallFont ); + setFontRole( QskFontRole::Caption ); } void setValue( int value ) diff --git a/examples/iotdashboard/MembersPage.cpp b/examples/iotdashboard/MembersPage.cpp index 691d8731..cbd6812b 100644 --- a/examples/iotdashboard/MembersPage.cpp +++ b/examples/iotdashboard/MembersPage.cpp @@ -7,6 +7,7 @@ #include #include +#include QSK_SUBCONTROL( MembersPage, Panel ) @@ -15,7 +16,7 @@ MembersPage::MembersPage( QQuickItem* parent ) { auto* const textLabel = new QskTextLabel( "members page", this ); textLabel->setAlignmentHint( QskTextLabel::Text, Qt::AlignCenter ); - textLabel->setFontRole( QskSkin::HugeFont ); + textLabel->setFontRole( QskFontRole::Display ); } #include "moc_MembersPage.cpp" diff --git a/examples/iotdashboard/MyDevices.cpp b/examples/iotdashboard/MyDevices.cpp index edeb7a5a..6e44f1ed 100644 --- a/examples/iotdashboard/MyDevices.cpp +++ b/examples/iotdashboard/MyDevices.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -32,7 +33,7 @@ namespace icon->setCheckable( true ); auto textLabel = new QskTextLabel( name, this ); - textLabel->setFontRole( QskSkin::TinyFont ); + textLabel->setFontRole( { QskFontRole::Caption, QskFontRole::Low } ); textLabel->setAlignment( Qt::AlignHCenter ); } }; diff --git a/examples/iotdashboard/Skin.cpp b/examples/iotdashboard/Skin.cpp index 250ab932..0b0b2626 100644 --- a/examples/iotdashboard/Skin.cpp +++ b/examples/iotdashboard/Skin.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -74,15 +75,14 @@ void Skin::initHints() QFontDatabase db; db.addApplicationFont( ":/fonts/ProximaNova-Regular.otf" ); // ### use fontconfig - setFont( QskSkin::DefaultFont, createFont( 12 ) ); + setFont( { QskFontRole::Caption, QskFontRole::Low }, createFont( 9 ) ); + setFont( { QskFontRole::Caption, QskFontRole::Normal }, createFont( 10 ) ); + setFont( { QskFontRole::Caption, QskFontRole::High }, createFont( 10, QFont::Bold ) ); - setFont( QskSkin::TinyFont, createFont( 9 ) ); - setFont( QskSkin::SmallFont, createFont( 10 ) ); - setFont( QskSkin::MediumFont, createFont( 13 ) ); - setFont( QskSkin::LargeFont, createFont( 20 ) ); - setFont( QskSkin::HugeFont, createFont( 27, QFont::Bold ) ); - - setFont( Skin::TitleFont, createFont( 10, QFont::Bold ) ); + setFont( { QskFontRole::Body, QskFontRole::Normal }, createFont( 12 ) ); + setFont( { QskFontRole::Subtitle, QskFontRole::Normal }, createFont( 13 ) ); + setFont( { QskFontRole::Headline, QskFontRole::Normal }, createFont( 20 ) ); + setFont( { QskFontRole::Display, QskFontRole::Normal }, createFont( 27, QFont::Bold ) ); QskSkinHintTableEditor ed( &hintTable() ); @@ -106,7 +106,7 @@ void Skin::initHints() ed.setSpacing( Q::Panel | A::Header, 10 ); ed.setColor( Q::Text | A::Header, Qt::white ); - ed.setFontRole( Q::Text | A::Header, QskSkin::SmallFont ); + ed.setFontRole( Q::Text | A::Header, QskFontRole::Caption ); ed.setAlignment( Q::Text | A::Header, Qt::AlignLeft | Qt::AlignVCenter ); ed.setPadding( Q::Icon | A::Header, { 30, 0, 0, 0 } ); @@ -134,16 +134,16 @@ void Skin::initHints() // value here: ed.setArcMetrics( CircularProgressBar::Bar, 90, -180, 8.53 ); - ed.setFontRole( TimeTitleLabel::Text, Skin::TitleFont ); + ed.setFontRole( TimeTitleLabel::Text, { QskFontRole::Caption, QskFontRole::High } ); - ed.setFontRole( TimeLabel::Text, QskSkin::HugeFont ); + ed.setFontRole( TimeLabel::Text, QskFontRole::Display ); ed.setColor( TimeLabel::Text, 0xff6776ff ); // boxes: ed.setPadding( Box::Panel, 8 ); // content in boxes (indoor temperature, humidity etc.): - ed.setFontRole( UsageBox::Separator, QskSkin::SmallFont ); + ed.setFontRole( UsageBox::Separator, QskFontRole::Caption ); ed.setColor( UsageBox::Separator, 0xffdddddd ); ed.setPadding( BoxWithButtons::Panel, 8 ); @@ -193,7 +193,7 @@ void Skin::initHints() ed.setGradient( subControl | RoundedIcon::Bright, bright ); } - ed.setFontRole( BoxWithButtons::ValueText, QskSkin::HugeFont ); + ed.setFontRole( BoxWithButtons::ValueText, QskFontRole::Display ); ed.setColor( BoxWithButtons::ValueText, 0xff929cb2 ); ed.setPadding( BoxWithButtons::ValuePanel, 0, 10, 0, 0 ); @@ -204,7 +204,7 @@ void Skin::initHints() // diagram: ed.setBoxBorderMetrics( UsageDiagramBox::DaysBox, 0, 0, 3, 3 ); - ed.setFontRole( UsageDiagramBox::DayText, QskSkin::TinyFont ); + ed.setFontRole( UsageDiagramBox::DayText, { QskFontRole::Caption, QskFontRole::Low } ); ed.setStrutSize( UsageDiagramLegend::Symbol, 8, 8 ); ed.setBoxShape( UsageDiagramLegend::Symbol, 100, Qt::RelativeSize ); // a circle @@ -240,7 +240,7 @@ void Skin::initHints() ed.setArcMetrics( LightDisplay::Tickmarks, 0, 180, 4.69 ); ed.setColor( LightDisplay::Tickmarks, 0x55929cb2 ); - ed.setFontRole( LightDisplay::ValueText, QskSkin::LargeFont ); + ed.setFontRole( LightDisplay::ValueText, QskFontRole::Headline ); ed.setColor( LightDisplay::ValueText, 0xff929cb2 ); ed.setStrutSize( LightDisplay::Knob, { 20, 20 } ); diff --git a/examples/iotdashboard/Skin.h b/examples/iotdashboard/Skin.h index 1b0d18d1..1b2cd7f1 100644 --- a/examples/iotdashboard/Skin.h +++ b/examples/iotdashboard/Skin.h @@ -30,11 +30,6 @@ class Skin : public QskSkin Skin( QObject* parent = nullptr ); ~Skin() override; - enum SkinFontRole - { - TitleFont = QskSkin::HugeFont + 1, - }; - private: void initHints() override; diff --git a/examples/iotdashboard/StatisticsPage.cpp b/examples/iotdashboard/StatisticsPage.cpp index 93427f39..be949611 100644 --- a/examples/iotdashboard/StatisticsPage.cpp +++ b/examples/iotdashboard/StatisticsPage.cpp @@ -5,8 +5,8 @@ #include "StatisticsPage.h" -#include #include +#include QSK_SUBCONTROL( StatisticsPage, Panel ) @@ -15,7 +15,7 @@ StatisticsPage::StatisticsPage( QQuickItem* parent ) { auto* const textLabel = new QskTextLabel( "statistics page", this ); textLabel->setAlignmentHint( QskTextLabel::Text, Qt::AlignCenter ); - textLabel->setFontRole( QskSkin::HugeFont ); + textLabel->setFontRole( QskFontRole::Display ); } #include "moc_StatisticsPage.cpp" diff --git a/examples/iotdashboard/StorageMeter.cpp b/examples/iotdashboard/StorageMeter.cpp index 73bc39e8..af9d528b 100644 --- a/examples/iotdashboard/StorageMeter.cpp +++ b/examples/iotdashboard/StorageMeter.cpp @@ -5,7 +5,7 @@ #include "StorageMeter.h" #include "CircularProgressBar.h" -#include +#include #include QSK_SUBCONTROL( StorageMeter, Status ) @@ -28,7 +28,7 @@ StorageMeter::StorageMeter( QQuickItem* parent ) noexcept label->setText( make_text( locale(), value() ) ); label->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); label->setLayoutAlignmentHint( Qt::AlignCenter ); - label->setFontRole( QskSkin::SmallFont ); + label->setFontRole( QskFontRole::Caption ); } void StorageMeter::setValue( const qreal value ) diff --git a/examples/iotdashboard/StoragePage.cpp b/examples/iotdashboard/StoragePage.cpp index 35261843..f1ff5b3c 100644 --- a/examples/iotdashboard/StoragePage.cpp +++ b/examples/iotdashboard/StoragePage.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -89,9 +89,9 @@ void StoragePage::addRow( const QString& title, const QString& description, meter->setMaximumSize( 64, 64 ); auto* const maintitle = new QskTextLabel( storage.title, center ); - maintitle->setFontRole( QskSkin::LargeFont ); + maintitle->setFontRole( QskFontRole::Headline ); auto* const subtitle = new QskTextLabel( storage.description, center ); - subtitle->setFontRole( QskSkin::MediumFont ); + subtitle->setFontRole( QskFontRole::Subtitle ); const auto& media = storage.distribution; @@ -106,7 +106,7 @@ void StoragePage::addRow( const QString& title, const QString& description, legend->setSpacing( 12 ); legend->addSpacer( 1, 999 ); auto* const sync = new QskPushButton( "Update", legend ); - sync->setFontRoleHint( QskPushButton::Text, QskSkin::SmallFont ); + sync->setFontRoleHint( QskPushButton::Text, QskFontRole::Caption ); using S = StorageBar; for ( const auto& pair : QVector< QPair< QString, QskGradient > >{ @@ -124,7 +124,7 @@ void StoragePage::addRow( const QString& title, const QString& description, dot->setMaximumSize( size, size ); dot->setGradientHint( QskBox::Panel, pair.second ); auto* const label = new QskTextLabel( pair.first, legend ); - label->setFontRole( QskSkin::SmallFont ); + label->setFontRole( QskFontRole::Caption ); } auto* const animator = new StorageRowAnimator( window(), sync ); diff --git a/examples/iotdashboard/TopBar.cpp b/examples/iotdashboard/TopBar.cpp index f869bb8c..9deb9089 100644 --- a/examples/iotdashboard/TopBar.cpp +++ b/examples/iotdashboard/TopBar.cpp @@ -6,7 +6,7 @@ #include "TopBar.h" #include "EnergyMeter.h" -#include +#include #include #include @@ -54,7 +54,7 @@ TopBarItem::TopBarItem( setSpacing( 15 ); auto* textLabel = new QskTextLabel( name, this ); - textLabel->setFontRole( QskSkin::SmallFont ); + textLabel->setFontRole( QskFontRole::Caption ); auto* pieChartAndDisplay = new QskLinearBox( Qt::Horizontal, this ); pieChartAndDisplay->setSpacing( 10 ); @@ -71,10 +71,10 @@ TopBarItem::TopBarItem( display->addSpacer( 0, 1 ); auto displayValue = new QskTextLabel( QString::number( value ), display ); - displayValue->setFontRole( QskSkin::MediumFont ); + displayValue->setFontRole( QskFontRole::Subtitle ); auto displayUnit = new QskTextLabel( "kwH", display ); - displayUnit->setFontRole( QskSkin::SmallFont ); + displayUnit->setFontRole( QskFontRole::Caption ); display->addSpacer( 0, 1 ); } diff --git a/examples/iotdashboard/UsageBox.cpp b/examples/iotdashboard/UsageBox.cpp index 8327bc6c..d8ea9ad3 100644 --- a/examples/iotdashboard/UsageBox.cpp +++ b/examples/iotdashboard/UsageBox.cpp @@ -5,7 +5,7 @@ #include "UsageBox.h" -#include +#include #include QSK_SUBCONTROL( UsageBox, Separator ) @@ -19,13 +19,13 @@ namespace : QskLinearBox( Qt::Horizontal, parent ) { auto infoLabel = new QskTextLabel( info, this ); - infoLabel->setFontRole( QskSkin::SmallFont ); + infoLabel->setFontRole( QskFontRole::Caption ); auto separator = new QskTextLabel( "_____", this ); separator->setSubcontrolProxy( QskTextLabel::Text, UsageBox::Separator ); auto valueLabel = new QskTextLabel( value, this ); - valueLabel->setFontRole( QskSkin::SmallFont ); + valueLabel->setFontRole( QskFontRole::Caption ); } }; } diff --git a/examples/iotdashboard/UsageDiagram.cpp b/examples/iotdashboard/UsageDiagram.cpp index 95f511cb..21523a58 100644 --- a/examples/iotdashboard/UsageDiagram.cpp +++ b/examples/iotdashboard/UsageDiagram.cpp @@ -7,7 +7,7 @@ #include "Diagram.h" #include -#include +#include #include QSK_SUBCONTROL( UsageDiagramLegend, Panel ) @@ -52,7 +52,7 @@ namespace } auto label = new QskTextLabel( text ); - label->setFontRole( QskSkin::TinyFont ); + label->setFontRole( { QskFontRole::Caption, QskFontRole::Low } ); addItem( symbol ); addItem( label ); diff --git a/examples/layouts/TestRectangle.cpp b/examples/layouts/TestRectangle.cpp index e1232206..955e0880 100644 --- a/examples/layouts/TestRectangle.cpp +++ b/examples/layouts/TestRectangle.cpp @@ -4,13 +4,13 @@ *****************************************************************************/ #include "TestRectangle.h" -#include +#include TestRectangle::TestRectangle( QQuickItem* parent ) : QskTextLabel( parent ) { setAlignment( Qt::AlignCenter ); - setFontRole( QskSkin::HugeFont ); + setFontRole( QskFontRole::Title ); setTextColor( Qt::white ); setPreferredSize( 10, 10 ); diff --git a/examples/tabview/main.cpp b/examples/tabview/main.cpp index 1311650d..0a3b7ab9 100644 --- a/examples/tabview/main.cpp +++ b/examples/tabview/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -29,7 +30,7 @@ class Label : public QskTextLabel : QskTextLabel( text, parent ) { setTextColor( Qt::darkRed ); - setFontRole( QskSkin::LargeFont ); + setFontRole( QskFontRole::Headline ); setAlignment( Qt::AlignCenter ); } }; diff --git a/playground/CMakeLists.txt b/playground/CMakeLists.txt index 2e7b04ca..2bc146fa 100644 --- a/playground/CMakeLists.txt +++ b/playground/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(anchors) add_subdirectory(dials) add_subdirectory(dialogbuttons) +add_subdirectory(fonts) add_subdirectory(gradients) add_subdirectory(invoker) add_subdirectory(shadows) diff --git a/playground/dials/Skin.cpp b/playground/dials/Skin.cpp index 7a0e79f9..760c927e 100644 --- a/playground/dials/Skin.cpp +++ b/playground/dials/Skin.cpp @@ -12,6 +12,7 @@ #include #include #include +#include static inline QFont qskFont( qreal pointSize ) { @@ -30,8 +31,9 @@ void Skin::initHints() { using namespace QskRgb; - setFont( QskSkin::DefaultFont, qskFont( 13 ) ); - setFont( QskSkin::LargeFont, qskFont( 20 ) ); + setFont( QskFontRole::Caption, qskFont( 8 ) ); + setFont( QskFontRole::Body, qskFont( 13 ) ); + setFont( QskFontRole::Title, qskFont( 20 ) ); const auto rgb1 = qRgb( 1, 16, 27 ); // Maastricht blue const auto rgb2 = qRgb( 255, 0, 22 ); // Ruddy @@ -65,6 +67,6 @@ void Skin::initHints() ed.setSpacing( Q::TickLabels, 4 ); ed.setStrutSize( Q::TickLabels, 2, 15 ); ed.setColor( Q::TickLabels, rgb4 ); - ed.setFontRole( Q::TickLabels, QskSkin::SmallFont ); + ed.setFontRole( Q::TickLabels, QskFontRole::Caption ); } } diff --git a/playground/fonts/CMakeLists.txt b/playground/fonts/CMakeLists.txt new file mode 100644 index 00000000..edf62848 --- /dev/null +++ b/playground/fonts/CMakeLists.txt @@ -0,0 +1,6 @@ +############################################################################ +# QSkinny - Copyright (C) The authors +# SPDX-License-Identifier: BSD-3-Clause +############################################################################ + +qsk_add_example(fonts main.cpp) diff --git a/playground/fonts/main.cpp b/playground/fonts/main.cpp new file mode 100644 index 00000000..350a4eaf --- /dev/null +++ b/playground/fonts/main.cpp @@ -0,0 +1,132 @@ +/****************************************************************************** + * QSkinny - Copyright (C) The authors + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace +{ + class TextLabel : public QskTextLabel + { + public: + TextLabel( const QskFontRole& role, QQuickItem* parent = nullptr ) + : QskTextLabel( parent ) + { + setAlignment( Qt::AlignCenter ); + setText( textFromRole( role ) ); + setFontRole( role ); + + setSizePolicy( Qt::Horizontal, QskSizePolicy::Ignored ); + } + + private: + QString textFromRole( const QskFontRole& role ) const + { + static QMetaEnum metaEnums[2]; + + const auto& mo = QskFontRole::staticMetaObject; + + if ( !metaEnums[0].isValid() ) + metaEnums[0] = mo.enumerator( mo.indexOfEnumerator( "Category" ) ); + + if ( !metaEnums[1].isValid() ) + metaEnums[1] = mo.enumerator( mo.indexOfEnumerator( "Emphasis" ) ); + + QString s( metaEnums[0].valueToKey( role.category() ) ); +#if 0 + s += ' '; + s += metaEnums[1].valueToKey( role.emphasis() ); +#endif + + return s; + } + }; + + class TextBox : public QskLinearBox + { + public: + TextBox( QQuickItem* parent = nullptr ) + : QskLinearBox( Qt::Horizontal, 3, parent ) + { + setMargins( 10 ); + setDefaultAlignment( Qt::AlignCenter ); + + for ( int i = 0; i <= QskFontRole::Display; i++ ) + { + const auto category = static_cast< QskFontRole::Category >( i ); + for ( int j = 0; j <= QskFontRole::VeryHigh; j++ ) + { + const auto emphasis = static_cast< QskFontRole::Emphasis >( j ); + ( void ) new TextLabel( { category, emphasis }, this ); + } + } + } + }; + + class SkinLabel : public QskTextLabel + { + public: + SkinLabel( QQuickItem* parent = nullptr ) + : QskTextLabel( parent ) + { + setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Fixed ); + setAlignment( Qt::AlignCenter ); + setFontRole( QskFontRole::Title ); + + updateText(); + } + + protected: + void changeEvent( QEvent* event ) + { + if ( event->type() == QEvent::StyleChange ) + updateText(); + + QskTextLabel::changeEvent( event ); + } + + private: + void updateText() + { + setText( qskSkinManager->skinName() ); + } + }; + + class MainView : public QskLinearBox + { + public: + MainView( QQuickItem* parent = nullptr ) + : QskLinearBox( Qt::Vertical, parent ) + { + setPanel( true ); + + (void) new SkinLabel( this ); + (void) new QskSeparator( this ); + (void) new TextBox( this ); + } + }; +} + +int main( int argc, char** argv ) +{ + QGuiApplication app( argc, argv ); + + Skinny::init(); // we need a skin + SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts ); + + QskWindow window; + window.addItem( new MainView() ); + window.resize( 1024, 600 ); + window.show(); + + return app.exec(); +} diff --git a/playground/plots/PlotSkin.cpp b/playground/plots/PlotSkin.cpp index 4ff8b1d2..e79dcb3f 100644 --- a/playground/plots/PlotSkin.cpp +++ b/playground/plots/PlotSkin.cpp @@ -30,6 +30,7 @@ #include #include +#include #include @@ -98,7 +99,7 @@ void SkinEditor::setupPlotHints() setPadding( Q::AxisScale | A::Bottom, 0, padding, 0, 0 ); setColor( Q::AxisScale, qRgb( 20, 20, 20 ) ); - setFontRole( Q::AxisScale, QskSkin::MediumFont ); + setFontRole( Q::AxisScale, QskFontRole::Caption ); setFlag( Q::AxisScale | A::Style, QskGraduationRenderer::Backbone ); // thickness/length of the major ticks diff --git a/playground/plots/QskPlotViewSkinlet.cpp b/playground/plots/QskPlotViewSkinlet.cpp index f3f1aaf4..08eb396b 100644 --- a/playground/plots/QskPlotViewSkinlet.cpp +++ b/playground/plots/QskPlotViewSkinlet.cpp @@ -13,11 +13,7 @@ #include #include #include -#include -#include - -#include -#include +#include static inline QskTextColors qskTextColors( const QskSkinnable* skinnable, QskAspect aspect ) @@ -84,9 +80,7 @@ namespace setTickMetrics( graduation.value< QskGraduationMetrics >() ); setSpacing( view->spacingHint( aspect ) ); - - const auto fontRole = view->fontRoleHint( aspect ); - setFont( view->effectiveSkin()->font( fontRole ) ); + setFont( view->effectiveFont( aspect ) ); setTextColors( qskTextColors( view, aspect ) ); } diff --git a/qmlexport/QskQml.cpp b/qmlexport/QskQml.cpp index 6795587f..54a00043 100644 --- a/qmlexport/QskQml.cpp +++ b/qmlexport/QskQml.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -267,6 +268,7 @@ void QskQml::registerTypes() registerGadget< QskPlacementPolicy >(); registerGadget< QskSizePolicy >(); registerGadget< QskTextOptions >(); + registerGadget< QskFontRole >(); registerNamespace( QskStandardSymbol::staticMetaObject ); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d949057a..de2dd310 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND HEADERS common/QskBoxBorderMetrics.h common/QskBoxShapeMetrics.h common/QskBoxHints.h + common/QskFontRole.h common/QskFunctions.h common/QskGlobal.h common/QskGradient.h @@ -45,6 +46,7 @@ list(APPEND SOURCES common/QskBoxBorderMetrics.cpp common/QskBoxShapeMetrics.cpp common/QskBoxHints.cpp + common/QskFontRole.cpp common/QskFunctions.cpp common/QskGradient.cpp common/QskGradientDirection.cpp diff --git a/src/common/QskFontRole.cpp b/src/common/QskFontRole.cpp new file mode 100644 index 00000000..5be6b21f --- /dev/null +++ b/src/common/QskFontRole.cpp @@ -0,0 +1,45 @@ +/****************************************************************************** + * QSkinny - Copyright (C) The authors + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include "QskFontRole.h" +#include + +static void qskRegisterFontRole() +{ + qRegisterMetaType< QskFontRole >(); + +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + QMetaType::registerEqualsComparator< QskFontRole >(); +#endif +} + +Q_CONSTRUCTOR_FUNCTION( qskRegisterFontRole ) + +QskHashValue QskFontRole::hash( QskHashValue seed ) const noexcept +{ + const auto v = static_cast< ushort >( category() ) + | ( static_cast< ushort >( emphasis() ) << 8 ); + + return qHash( v, seed ); +} + +#ifndef QT_NO_DEBUG_STREAM + +#include + +QDebug operator<<( QDebug debug, const QskFontRole& fontRole ) +{ + QDebugStateSaver saver( debug ); + debug.nospace(); + + debug << "FontRole( " << fontRole.category() + << ", " << fontRole.emphasis() << " )"; + + return debug; +} + +#endif + +#include "moc_QskFontRole.cpp" diff --git a/src/common/QskFontRole.h b/src/common/QskFontRole.h new file mode 100644 index 00000000..c0873686 --- /dev/null +++ b/src/common/QskFontRole.h @@ -0,0 +1,122 @@ +/****************************************************************************** + * QSkinny - Copyright (C) The authors + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#ifndef QSK_FONT_ROLE_H +#define QSK_FONT_ROLE_H + +#include "QskGlobal.h" +#include + +class QSK_EXPORT QskFontRole +{ + Q_GADGET + + Q_PROPERTY( Category category READ category WRITE setCategory ) + Q_PROPERTY( Emphasis emphasis READ emphasis WRITE setEmphasis ) + + public: + enum Category + { + Caption, + Body, + Subtitle, + Title, + Headline, + Display + }; + Q_ENUM( Category ); + + enum Emphasis + { + VeryLow, + Low, + + Normal, + + High, + VeryHigh + }; + Q_ENUM( Emphasis ); + + constexpr QskFontRole( Category = Body, Emphasis = Normal ) noexcept; + + constexpr bool operator==( const QskFontRole& ) const noexcept; + constexpr bool operator!=( const QskFontRole& ) const noexcept; + + void setCategory( Category ) noexcept; + constexpr Category category() const noexcept; + + void setEmphasis( Emphasis ) noexcept; + constexpr Emphasis emphasis() const noexcept; + + QskHashValue hash( QskHashValue seed = 0 ) const noexcept; + + private: + unsigned char m_category; + unsigned char m_emphasis; +}; + +inline constexpr QskFontRole::QskFontRole( Category category, Emphasis emphasis ) noexcept + : m_category( category ) + , m_emphasis( emphasis ) +{ +} + +inline constexpr bool QskFontRole::operator==( const QskFontRole& other ) const noexcept +{ + return ( m_category == other.m_category ) && ( m_emphasis == other.m_emphasis ); +} + +inline constexpr bool QskFontRole::operator!=( const QskFontRole& other ) const noexcept +{ + return !( *this == other ); +} + +inline void QskFontRole::setCategory( Category category ) noexcept +{ + m_category = category; +} + +inline constexpr QskFontRole::Category QskFontRole::category() const noexcept +{ + return static_cast< Category >( m_category ); +} + +inline void QskFontRole::setEmphasis( Emphasis emphasis ) noexcept +{ + m_emphasis = emphasis; +} + +inline constexpr QskFontRole::Emphasis QskFontRole::emphasis() const noexcept +{ + return static_cast< Emphasis >( m_emphasis ); +} + +inline QskHashValue qHash( const QskFontRole fontRole, QskHashValue seed = 0 ) noexcept +{ + return fontRole.hash( seed ); +} + +namespace std +{ + template< > struct hash< QskFontRole > + { + size_t operator()( const QskFontRole& fontRole ) const noexcept + { + return fontRole.hash(); + } + }; +} + +#ifndef QT_NO_DEBUG_STREAM + +QSK_EXPORT QDebug operator<<( QDebug, const QskFontRole& ); + +#endif + +Q_DECLARE_TYPEINFO( QskFontRole, Q_MOVABLE_TYPE ); +Q_DECLARE_METATYPE( QskFontRole ) + +#endif diff --git a/src/controls/QskSkin.cpp b/src/controls/QskSkin.cpp index df4150aa..416f7a0a 100644 --- a/src/controls/QskSkin.cpp +++ b/src/controls/QskSkin.cpp @@ -10,14 +10,15 @@ #include "QskColorFilter.h" #include "QskGraphic.h" #include "QskGraphicProviderMap.h" -#include "QskSkinHintTable.h" #include "QskStandardSymbol.h" #include "QskPlatform.h" +#include "QskMargins.h" +#include "QskFontRole.h" + +#include "QskSkinHintTable.h" #include "QskSkinManager.h" #include "QskSkinTransition.h" -#include "QskMargins.h" - #include #include #include @@ -151,7 +152,7 @@ class QskSkin::PrivateData QskSkinHintTable hintTable; - QHash< int, QFont > fonts; + QHash< QskFontRole, QFont > fonts; QHash< int, QskColorFilter > graphicFilters; QskGraphicProviderMap graphicProviders; @@ -194,7 +195,7 @@ QskSkin::QskSkin( QObject* parent ) declareSkinlet< QskRadioBox, QskRadioBoxSkinlet >(); const QFont font = QGuiApplication::font(); - setupFonts( font.family(), font.weight(), font.italic() ); + setupFontTable( font.family(), font.italic() ); const auto noMargins = QVariant::fromValue( QskMargins( 0 ) ); @@ -288,46 +289,91 @@ void QskSkin::declareSkinlet( const QMetaObject* metaObject, } } -void QskSkin::setupFonts( const QString& family, int weight, bool italic ) +static inline void qskSetFont( QskSkin* skin, + QskFontRole::Category category, QskFontRole::Emphasis emphasis, + QFont font, QFont::Weight weight ) { - const int sizes[] = { 10, 15, 20, 32, 66 }; - static_assert( sizeof( sizes ) / sizeof( sizes[ 0 ] ) == HugeFont, - "QskSkin::setupFonts: bad list size." ); - - QFont font( family, -1, weight, italic ); - - for ( int i = TinyFont; i <= HugeFont; i++ ) - { - font.setPixelSize( qRound( qskDpToPixels( sizes[i - 1] ) ) ); - m_data->fonts[ i ] = font; - } - - const QFont appFont( QGuiApplication::font() ); - if ( appFont.pixelSize() > 0 ) - font.setPixelSize( appFont.pixelSize() ); - else - font.setPointSize( appFont.pointSize() ); - - m_data->fonts[ QskSkin::DefaultFont ] = font; + font.setWeight( weight ); + skin->setFont( { category, emphasis }, font ); } -void QskSkin::setFont( int fontRole, const QFont& font ) +static inline void qskSetNormalFont( QskSkin* skin, + QskFontRole::Category category, QFont font, int pixelSize ) +{ + font.setPixelSize( qRound( qskDpToPixels( pixelSize ) ) ); + qskSetFont( skin, category, QskFontRole::Normal, font, QFont::Normal ); +} + +void QskSkin::setupFontTable( const QString& family, bool italic ) +{ + const QFont font( family, -1, -1, italic ); + + qskSetNormalFont( this, QskFontRole::Caption, font, 10 ); + qskSetNormalFont( this, QskFontRole::Subtitle, font, 15 ); + qskSetNormalFont( this, QskFontRole::Body, font, 20 ); + qskSetNormalFont( this, QskFontRole::Title, font, 24 ); + qskSetNormalFont( this, QskFontRole::Headline, font, 32 ); + qskSetNormalFont( this, QskFontRole::Display, font, 66 ); + + completeFontTable(); +} + +void QskSkin::completeFontTable() +{ + // varying the weight of QskFontRole::Normal + + for ( int i = QskFontRole::Caption; i <= QskFontRole::Display; i++ ) + { + auto& table = m_data->fonts; + + const auto category = static_cast< QskFontRole::Category >( i ); + + const auto it = table.constFind( { category, QskFontRole::Normal } ); + if ( it == table.constEnd() ) + continue; + + const auto normalFont = it.value(); + + for ( int j = QskFontRole::VeryLow; j <= QskFontRole::VeryHigh; j++ ) + { + const auto emphasis = static_cast< QskFontRole::Emphasis >( j ); + + if ( emphasis == QskFontRole::Normal + || table.contains( { category, emphasis } ) ) + { + continue; + } + + int weight = normalFont.weight() + ( j - 2 ) * 100; + weight = qBound( 0, weight, 900 ); + + auto font = normalFont; + font.setWeight( static_cast< QFont::Weight >( weight ) ); + + m_data->fonts[ { category, emphasis } ] = font; + } + } +} + +void QskSkin::setFont( const QskFontRole& fontRole, const QFont& font ) { m_data->fonts[ fontRole ] = font; } -void QskSkin::resetFont( int fontRole ) +void QskSkin::resetFont( const QskFontRole& fontRole ) { m_data->fonts.remove( fontRole ); } -QFont QskSkin::font( int fontRole ) const +QFont QskSkin::font( const QskFontRole& fontRole ) const { - auto it = m_data->fonts.constFind( fontRole ); - if ( it != m_data->fonts.constEnd() ) + const auto& table = m_data->fonts; + + auto it = table.constFind( fontRole ); + if ( it != table.constEnd() ) return it.value(); - it = m_data->fonts.constFind( QskSkin::DefaultFont ); + it = table.constFind( QskFontRole() ); if ( it != m_data->fonts.constEnd() ) return it.value(); @@ -359,7 +405,7 @@ QskSkinHintTable& QskSkin::hintTable() return m_data->hintTable; } -const QHash< int, QFont >& QskSkin::fonts() const +const QHash< QskFontRole, QFont >& QskSkin::fontTable() const { return m_data->fonts; } diff --git a/src/controls/QskSkin.h b/src/controls/QskSkin.h index f70636b4..1a3012c3 100644 --- a/src/controls/QskSkin.h +++ b/src/controls/QskSkin.h @@ -20,6 +20,7 @@ class QskSkinlet; class QskColorFilter; class QskGraphic; class QskGraphicProvider; +class QskFontRole; class QskSkinHintTable; @@ -33,19 +34,6 @@ class QSK_EXPORT QskSkin : public QObject using Inherited = QObject; public: - enum SkinFontRole - { - DefaultFont = 0, - - TinyFont, - SmallFont, - MediumFont, - LargeFont, - HugeFont - }; - - Q_ENUM( SkinFontRole ) - #if 1 // Use Qt::ColorScheme once minimum version is Qt 6.5 enum ColorScheme @@ -71,12 +59,9 @@ class QSK_EXPORT QskSkin : public QObject void resetGraphicFilter( int graphicRole ); QskColorFilter graphicFilter( int graphicRole ) const; - void setFont( int fontRole, const QFont& ); - void resetFont( int fontRole ); - QFont font( int fontRole ) const; - - void setupFonts( const QString& family, - int weight = -1, bool italic = false ); + void setFont( const QskFontRole&, const QFont& ); + void resetFont( const QskFontRole& ); + QFont font( const QskFontRole& ) const; void addGraphicProvider( const QString& providerId, QskGraphicProvider* ); QskGraphicProvider* graphicProvider( const QString& providerId ) const; @@ -91,7 +76,7 @@ class QSK_EXPORT QskSkin : public QObject const QskSkinHintTable& hintTable() const; QskSkinHintTable& hintTable(); - const QHash< int, QFont >& fonts() const; + const QHash< QskFontRole, QFont >& fontTable() const; const QHash< int, QskColorFilter >& graphicFilters() const; ColorScheme colorScheme() const; @@ -106,6 +91,9 @@ class QSK_EXPORT QskSkin : public QObject void clearHints(); virtual void initHints() = 0; + void setupFontTable( const QString& family, bool italic = false ); + void completeFontTable(); + private: void declareSkinlet( const QMetaObject* metaObject, const QMetaObject* skinletMetaObject ); diff --git a/src/controls/QskSkinHintTableEditor.cpp b/src/controls/QskSkinHintTableEditor.cpp index a89ed995..393762db 100644 --- a/src/controls/QskSkinHintTableEditor.cpp +++ b/src/controls/QskSkinHintTableEditor.cpp @@ -15,6 +15,7 @@ #include "QskShadowMetrics.h" #include "QskStippleMetrics.h" #include "QskGraphic.h" +#include "QskFontRole.h" namespace { @@ -405,7 +406,7 @@ Qt::Alignment QskSkinHintTableEditor::alignment( QskAspect aspect ) const } void QskSkinHintTableEditor::setFontRole( - QskAspect aspect, int fontRole, QskStateCombination combination ) + QskAspect aspect, const QskFontRole& fontRole, QskStateCombination combination ) { setHint( aspectFontRole( aspect ), fontRole, combination ); } @@ -416,9 +417,9 @@ bool QskSkinHintTableEditor::removeFontRole( return removeHint( aspectFontRole( aspect ), combination ); } -int QskSkinHintTableEditor::fontRole( QskAspect aspect ) const +QskFontRole QskSkinHintTableEditor::fontRole( QskAspect aspect ) const { - return hint< int >( aspectFontRole( aspect ) ); + return hint< QskFontRole >( aspectFontRole( aspect ) ); } void QskSkinHintTableEditor::setGraphicRole( diff --git a/src/controls/QskSkinHintTableEditor.h b/src/controls/QskSkinHintTableEditor.h index b91255c4..7aff2805 100644 --- a/src/controls/QskSkinHintTableEditor.h +++ b/src/controls/QskSkinHintTableEditor.h @@ -26,6 +26,7 @@ class QskGraduationMetrics; class QskShadowMetrics; class QskStippleMetrics; class QskGraphic; +class QskFontRole; class QSK_EXPORT QskSkinHintTableEditor { @@ -178,9 +179,10 @@ class QSK_EXPORT QskSkinHintTableEditor // fontRole - void setFontRole( QskAspect, int, QskStateCombination = QskStateCombination() ); + void setFontRole( QskAspect, const QskFontRole&, + QskStateCombination = QskStateCombination() ); bool removeFontRole( QskAspect, QskStateCombination = QskStateCombination() ); - int fontRole( QskAspect ) const; + QskFontRole fontRole( QskAspect ) const; // graphicRole diff --git a/src/controls/QskSkinnable.cpp b/src/controls/QskSkinnable.cpp index 9d6ed3a9..5f63e0dc 100644 --- a/src/controls/QskSkinnable.cpp +++ b/src/controls/QskSkinnable.cpp @@ -28,6 +28,7 @@ #include "QskGradient.h" #include "QskTextOptions.h" #include "QskGraphic.h" +#include "QskFontRole.h" #include #include @@ -704,9 +705,11 @@ QskTextOptions QskSkinnable::textOptionsHint( aspect | QskAspect::Option, status ).value< QskTextOptions >(); } -bool QskSkinnable::setFontRoleHint( const QskAspect aspect, int role ) +bool QskSkinnable::setFontRoleHint( + const QskAspect aspect, const QskFontRole& role ) { - return qskSetFlag( this, aspect | QskAspect::FontRole, role ); + return setSkinHint( aspect | QskAspect::FontRole, + QVariant::fromValue( role ) ); } bool QskSkinnable::resetFontRoleHint( const QskAspect aspect ) @@ -714,10 +717,11 @@ bool QskSkinnable::resetFontRoleHint( const QskAspect aspect ) return resetSkinHint( aspect | QskAspect::FontRole ); } -int QskSkinnable::fontRoleHint( +QskFontRole QskSkinnable::fontRoleHint( const QskAspect aspect, QskSkinHintStatus* status ) const { - return qskFlag( this, aspect | QskAspect::FontRole, status ); + return effectiveSkinHint( + aspect | QskAspect::FontRole, status ).value< QskFontRole >(); } QFont QskSkinnable::effectiveFont( const QskAspect aspect ) const @@ -733,7 +737,7 @@ QFont QskSkinnable::effectiveFont( const QskAspect aspect ) const return hint.value< QFont >(); } - return effectiveSkin()->font( hint.toInt() ); // font role + return effectiveSkin()->font( hint.value< QskFontRole >() ); } qreal QskSkinnable::effectiveFontHeight( const QskAspect aspect ) const diff --git a/src/controls/QskSkinnable.h b/src/controls/QskSkinnable.h index bed91135..d7ec2d6b 100644 --- a/src/controls/QskSkinnable.h +++ b/src/controls/QskSkinnable.h @@ -36,6 +36,7 @@ class QskTextOptions; class QskBoxHints; class QskGradient; class QskGraphic; +class QskFontRole; class QskSkin; class QskSkinlet; @@ -245,9 +246,9 @@ class QSK_EXPORT QskSkinnable bool resetTextOptionsHint( QskAspect ); QskTextOptions textOptionsHint( QskAspect, QskSkinHintStatus* = nullptr ) const; - bool setFontRoleHint( QskAspect, int role ); + bool setFontRoleHint( QskAspect, const QskFontRole& ); bool resetFontRoleHint( QskAspect ); - int fontRoleHint( QskAspect, QskSkinHintStatus* = nullptr ) const; + QskFontRole fontRoleHint( QskAspect, QskSkinHintStatus* = nullptr ) const; bool setGraphicRoleHint( QskAspect, int role ); bool resetGraphicRoleHint( QskAspect ); diff --git a/src/controls/QskTextInput.cpp b/src/controls/QskTextInput.cpp index 91491377..da21c40b 100644 --- a/src/controls/QskTextInput.cpp +++ b/src/controls/QskTextInput.cpp @@ -4,6 +4,7 @@ *****************************************************************************/ #include "QskTextInput.h" +#include "QskFontRole.h" #include "QskQuick.h" QSK_QT_PRIVATE_BEGIN @@ -561,7 +562,7 @@ static inline void qskUpdateInputMethodFont( const QskTextInput* input ) qskUpdateInputMethod( input, queries ); } -void QskTextInput::setFontRole( int role ) +void QskTextInput::setFontRole( const QskFontRole& role ) { if ( setFontRoleHint( Text, role ) ) { @@ -579,7 +580,7 @@ void QskTextInput::resetFontRole() } } -int QskTextInput::fontRole() const +QskFontRole QskTextInput::fontRole() const { return fontRoleHint( Text ); } diff --git a/src/controls/QskTextInput.h b/src/controls/QskTextInput.h index f26e6a6b..cfba7dae 100644 --- a/src/controls/QskTextInput.h +++ b/src/controls/QskTextInput.h @@ -9,6 +9,7 @@ #include "QskControl.h" class QValidator; +class QskFontRole; class QSK_EXPORT QskTextInput : public QskControl { @@ -19,7 +20,7 @@ class QSK_EXPORT QskTextInput : public QskControl Q_PROPERTY( QString description READ description WRITE setDescription NOTIFY descriptionChanged ) - Q_PROPERTY( int fontRole READ fontRole + Q_PROPERTY( QskFontRole fontRole READ fontRole WRITE setFontRole RESET resetFontRole NOTIFY fontRoleChanged ) Q_PROPERTY( QFont font READ font ) @@ -93,9 +94,9 @@ class QSK_EXPORT QskTextInput : public QskControl void setPanel( bool ); bool hasPanel() const; - void setFontRole( int role ); + void setFontRole( const QskFontRole& role ); void resetFontRole(); - int fontRole() const; + QskFontRole fontRole() const; void setAlignment( Qt::Alignment ); void resetAlignment(); diff --git a/src/controls/QskTextLabel.cpp b/src/controls/QskTextLabel.cpp index d5fd6d24..d660a7f2 100644 --- a/src/controls/QskTextLabel.cpp +++ b/src/controls/QskTextLabel.cpp @@ -6,6 +6,7 @@ #include "QskTextLabel.h" #include "QskAspect.h" #include "QskTextOptions.h" +#include "QskFontRole.h" QSK_SUBCONTROL( QskTextLabel, Panel ) QSK_SUBCONTROL( QskTextLabel, Text ) @@ -161,7 +162,7 @@ Qt::TextElideMode QskTextLabel::elideMode() const return textOptions().elideMode(); } -void QskTextLabel::setFontRole( int role ) +void QskTextLabel::setFontRole( const QskFontRole& role ) { if ( setFontRoleHint( Text, role ) ) Q_EMIT fontRoleChanged( role ); @@ -173,7 +174,7 @@ void QskTextLabel::resetFontRole() Q_EMIT fontRoleChanged( fontRoleHint( Text ) ); } -int QskTextLabel::fontRole() const +QskFontRole QskTextLabel::fontRole() const { return fontRoleHint( Text ); } diff --git a/src/controls/QskTextLabel.h b/src/controls/QskTextLabel.h index 4911a8dd..a2d69682 100644 --- a/src/controls/QskTextLabel.h +++ b/src/controls/QskTextLabel.h @@ -9,13 +9,15 @@ #include "QskControl.h" #include "QskTextOptions.h" +class QskFontRole; + class QSK_EXPORT QskTextLabel : public QskControl { Q_OBJECT Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged ) - Q_PROPERTY( int fontRole READ fontRole + Q_PROPERTY( QskFontRole fontRole READ fontRole WRITE setFontRole RESET resetFontRole NOTIFY fontRoleChanged ) Q_PROPERTY( QFont font READ font ) @@ -44,9 +46,9 @@ class QSK_EXPORT QskTextLabel : public QskControl QString text() const; - void setFontRole( int role ); + void setFontRole( const QskFontRole& ); void resetFontRole(); - int fontRole() const; + QskFontRole fontRole() const; void setTextColor( const QColor& ); void resetTextColor(); @@ -80,7 +82,7 @@ class QSK_EXPORT QskTextLabel : public QskControl void textChanged( const QString& ); void textColorChanged( const QColor& ); void textOptionsChanged( const QskTextOptions& ); - void fontRoleChanged( int ); + void fontRoleChanged( const QskFontRole& ); void alignmentChanged( Qt::Alignment ); void panelChanged( bool ); diff --git a/support/SkinnyNamespace.cpp b/support/SkinnyNamespace.cpp index 498d4c3d..ec0d95bc 100644 --- a/support/SkinnyNamespace.cpp +++ b/support/SkinnyNamespace.cpp @@ -6,6 +6,7 @@ #include "SkinnyNamespace.h" #include +#include #include #include @@ -156,9 +157,9 @@ void Skinny::changeFonts( int increment ) { auto skin = qskSkinManager->skin(); - const auto fonts = skin->fonts(); + const auto table = skin->fontTable(); - for ( auto it = fonts.constBegin(); it != fonts.constEnd(); ++it ) + for ( auto it = table.constBegin(); it != table.constEnd(); ++it ) { auto role = it.key(); auto font = it.value();