QskFontRole introduced

This commit is contained in:
Uwe Rathmann 2024-02-19 15:51:55 +01:00
parent d8dd07d305
commit f3b4a3d8da
46 changed files with 671 additions and 350 deletions

View File

@ -95,6 +95,7 @@
#include <QskGraphicIO.h>
#include <QskMargins.h>
#include <QskRgbValue.h>
#include <QskFontRole.h>
#include <QskNamespace.h>
#include <QskPlatform.h>
@ -102,22 +103,30 @@
#include <QGuiApplication>
#include <QScreen>
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 )

View File

@ -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;

View File

@ -16,6 +16,7 @@
#include <QskDialogSubWindow.h>
#include <QskDrawer.h>
#include <QskFocusIndicator.h>
#include <QskFontRole.h>
#include <QskFunctions.h>
#include <QskGraphic.h>
#include <QskGraphicIO.h>
@ -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() );

View File

@ -51,6 +51,7 @@
#include <QskMargins.h>
#include <QskHctColor.h>
#include <QskRgbValue.h>
#include <QskFontRole.h>
#include <QskNamespace.h>
#include <QskPlatform.h>
@ -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 users 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 users 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 )

View File

@ -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;

View File

@ -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

View File

@ -1,98 +0,0 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "LabelPage.h"
#include <QskTextLabel.h>
#include <QskGraphicLabel.h>
#include <QskSeparator.h>
#include <QskRgbValue.h>
#include <QskSkin.h>
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 );
}

View File

@ -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 );
};

View File

@ -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() );

View File

@ -7,6 +7,7 @@
#include "Skin.h"
#include <QskTextLabel.h>
#include <QskFontRole.h>
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 } );
}
}

View File

@ -10,6 +10,7 @@
#include <QskTextLabel.h>
#include <QskLinearBox.h>
#include <QskFontRole.h>
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 );

View File

@ -5,8 +5,8 @@
#include "DevicesPage.h"
#include <QskSkin.h>
#include <QskTextLabel.h>
#include <QskFontRole.h>
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"

View File

@ -7,7 +7,7 @@
#include "CircularProgressBar.h"
#include <QskTextLabel.h>
#include <QskSkin.h>
#include <QskFontRole.h>
namespace
{
@ -19,7 +19,7 @@ namespace
{
initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
setLayoutAlignmentHint( Qt::AlignCenter );
setFontRole( QskSkin::SmallFont );
setFontRole( QskFontRole::Caption );
}
void setValue( int value )

View File

@ -7,6 +7,7 @@
#include <QskSkin.h>
#include <QskTextLabel.h>
#include <QskFontRole.h>
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"

View File

@ -11,6 +11,7 @@
#include <QskGridBox.h>
#include <QskSkin.h>
#include <QskTextLabel.h>
#include <QskFontRole.h>
#include <QImage>
@ -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 );
}
};

View File

@ -38,6 +38,7 @@
#include <QskStateCombination.h>
#include <QskTextLabel.h>
#include <QskGraphicLabel.h>
#include <QskFontRole.h>
#include <QFontDatabase>
@ -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 } );

View File

@ -30,11 +30,6 @@ class Skin : public QskSkin
Skin( QObject* parent = nullptr );
~Skin() override;
enum SkinFontRole
{
TitleFont = QskSkin::HugeFont + 1,
};
private:
void initHints() override;

View File

@ -5,8 +5,8 @@
#include "StatisticsPage.h"
#include <QskSkin.h>
#include <QskTextLabel.h>
#include <QskFontRole.h>
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"

View File

@ -5,7 +5,7 @@
#include "StorageMeter.h"
#include "CircularProgressBar.h"
#include <QskSkin.h>
#include <QskFontRole.h>
#include <QskTextLabel.h>
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 )

View File

@ -15,7 +15,7 @@
#include <QskGradientStop.h>
#include <QskGraphicLabel.h>
#include <QskPushButton.h>
#include <QskSkin.h>
#include <QskFontRole.h>
#include <QskStackBox.h>
#include <QskTextLabel.h>
@ -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 );

View File

@ -6,7 +6,7 @@
#include "TopBar.h"
#include "EnergyMeter.h"
#include <QskSkin.h>
#include <QskFontRole.h>
#include <QskTextLabel.h>
#include <QTime>
@ -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 );
}

View File

@ -5,7 +5,7 @@
#include "UsageBox.h"
#include <QskSkin.h>
#include <QskFontRole.h>
#include <QskTextLabel.h>
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 );
}
};
}

View File

@ -7,7 +7,7 @@
#include "Diagram.h"
#include <QskGridBox.h>
#include <QskSkin.h>
#include <QskFontRole.h>
#include <QskTextLabel.h>
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 );

View File

@ -4,13 +4,13 @@
*****************************************************************************/
#include "TestRectangle.h"
#include <QskSkin.h>
#include <QskFontRole.h>
TestRectangle::TestRectangle( QQuickItem* parent )
: QskTextLabel( parent )
{
setAlignment( Qt::AlignCenter );
setFontRole( QskSkin::HugeFont );
setFontRole( QskFontRole::Title );
setTextColor( Qt::white );
setPreferredSize( 10, 10 );

View File

@ -19,6 +19,7 @@
#include <QskTextLabel.h>
#include <QskWindow.h>
#include <QskShortcutMap.h>
#include <QskFontRole.h>
#include <QGuiApplication>
@ -29,7 +30,7 @@ class Label : public QskTextLabel
: QskTextLabel( text, parent )
{
setTextColor( Qt::darkRed );
setFontRole( QskSkin::LargeFont );
setFontRole( QskFontRole::Headline );
setAlignment( Qt::AlignCenter );
}
};

View File

@ -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)

View File

@ -12,6 +12,7 @@
#include <QskSkinHintTableEditor.h>
#include <QskRgbValue.h>
#include <QskPlatform.h>
#include <QskFontRole.h>
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 );
}
}

View File

@ -0,0 +1,6 @@
############################################################################
# QSkinny - Copyright (C) The authors
# SPDX-License-Identifier: BSD-3-Clause
############################################################################
qsk_add_example(fonts main.cpp)

132
playground/fonts/main.cpp Normal file
View File

@ -0,0 +1,132 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include <SkinnyNamespace.h>
#include <SkinnyShortcut.h>
#include <QskFontRole.h>
#include <QskTextLabel.h>
#include <QskLinearBox.h>
#include <QskSeparator.h>
#include <QskWindow.h>
#include <QskSkinManager.h>
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();
}

View File

@ -30,6 +30,7 @@
#include <QskStippleMetrics.h>
#include <QskGraduationRenderer.h>
#include <QskFontRole.h>
#include <qbrush.h>
@ -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

View File

@ -13,11 +13,7 @@
#include <QskFunctions.h>
#include <QskSGNode.h>
#include <QskBoxBorderMetrics.h>
#include <QskMargins.h>
#include <QskSkin.h>
#include <qfontmetrics.h>
#include <qquickwindow.h>
#include <QskFontRole.h>
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 ) );
}

View File

@ -20,6 +20,7 @@
#include <QskDialogWindow.h>
#include <QskDrawer.h>
#include <QskFocusIndicator.h>
#include <QskFontRole.h>
#include <QskGradient.h>
#include <QskGradientDirection.h>
#include <QskGraduationMetrics.h>
@ -267,6 +268,7 @@ void QskQml::registerTypes()
registerGadget< QskPlacementPolicy >();
registerGadget< QskSizePolicy >();
registerGadget< QskTextOptions >();
registerGadget< QskFontRole >();
registerNamespace( QskStandardSymbol::staticMetaObject );

View File

@ -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

View File

@ -0,0 +1,45 @@
/******************************************************************************
* QSkinny - Copyright (C) The authors
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "QskFontRole.h"
#include <qhash.h>
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.h>
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"

122
src/common/QskFontRole.h Normal file
View File

@ -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 <qmetatype.h>
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

View File

@ -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 <qguiapplication.h>
#include <qpa/qplatformdialoghelper.h>
#include <qpa/qplatformtheme.h>
@ -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;
}

View File

@ -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 );

View File

@ -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(

View File

@ -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

View File

@ -28,6 +28,7 @@
#include "QskGradient.h"
#include "QskTextOptions.h"
#include "QskGraphic.h"
#include "QskFontRole.h"
#include <qfont.h>
#include <qfontmetrics.h>
@ -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

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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();

View File

@ -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 );
}

View File

@ -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 );

View File

@ -6,6 +6,7 @@
#include "SkinnyNamespace.h"
#include <QskSkinManager.h>
#include <QskFontRole.h>
#include <QskSkin.h>
#include <QGuiApplication>
@ -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();