8#include "QskAnimationHint.h"
10#include "QskColorFilter.h"
11#include "QskGraphic.h"
12#include "QskGraphicProviderMap.h"
13#include "QskStandardSymbol.h"
14#include "QskPlatform.h"
15#include "QskMargins.h"
16#include "QskFontRole.h"
18#include "QskSkinHintTable.h"
19#include "QskSkinManager.h"
20#include "QskSkinTransition.h"
22#include <qguiapplication.h>
23#include <qpa/qplatformdialoghelper.h>
24#include <qpa/qplatformtheme.h>
29#include "QskBoxSkinlet.h"
31#include "QskCheckBox.h"
32#include "QskCheckBoxSkinlet.h"
34#include "QskComboBox.h"
35#include "QskComboBoxSkinlet.h"
38#include "QskDrawerSkinlet.h"
40#include "QskFocusIndicator.h"
41#include "QskFocusIndicatorSkinlet.h"
43#include "QskGraphicLabel.h"
44#include "QskGraphicLabelSkinlet.h"
46#include "QskListView.h"
47#include "QskListViewSkinlet.h"
50#include "QskMenuSkinlet.h"
52#include "QskPageIndicator.h"
53#include "QskPageIndicatorSkinlet.h"
56#include "QskPopupSkinlet.h"
58#include "QskProgressBar.h"
59#include "QskProgressBarSkinlet.h"
61#include "QskProgressRing.h"
62#include "QskProgressRingSkinlet.h"
64#include "QskRadioBox.h"
65#include "QskRadioBoxSkinlet.h"
67#include "QskPushButton.h"
68#include "QskPushButtonSkinlet.h"
70#include "QskScrollView.h"
71#include "QskScrollViewSkinlet.h"
73#include "QskSegmentedBar.h"
74#include "QskSegmentedBarSkinlet.h"
76#include "QskSeparator.h"
77#include "QskSeparatorSkinlet.h"
80#include "QskSliderSkinlet.h"
82#include "QskSpinBox.h"
83#include "QskSpinBoxSkinlet.h"
85#include "QskSubWindow.h"
86#include "QskSubWindowSkinlet.h"
88#include "QskSubWindowArea.h"
89#include "QskSubWindowAreaSkinlet.h"
91#include "QskSwitchButton.h"
92#include "QskSwitchButtonSkinlet.h"
94#include "QskTabButton.h"
95#include "QskTabButtonSkinlet.h"
97#include "QskTabView.h"
98#include "QskTabViewSkinlet.h"
100#include "QskTextLabel.h"
101#include "QskTextLabelSkinlet.h"
103#include "QskTextArea.h"
104#include "QskTextAreaSkinlet.h"
106#include "QskTextField.h"
107#include "QskTextFieldSkinlet.h"
109#include "QskStatusIndicator.h"
110#include "QskStatusIndicatorSkinlet.h"
112#include "QskInternalMacros.h"
116static inline QskSkinlet* qskNewSkinlet(
const QMetaObject* metaObject,
QskSkin* skin )
118 const QByteArray signature = metaObject->className() + QByteArrayLiteral(
"(QskSkin*)" );
122 const int index = metaObject->indexOfConstructor( signature.constData() );
125 void* param[] = { &skinlet, &skin };
126 metaObject->static_metacall( QMetaObject::CreateInstance, index, param );
134QSK_HIDDEN_EXTERNAL_BEGIN
136QFont qskResolvedFont(
const QHash< QskFontRole, QFont >& fontTable,
139 auto it = fontTable.constFind( fontRole );
140 if ( it != fontTable.constEnd() )
144 if ( it != fontTable.constEnd() )
147 return QGuiApplication::font();
150QSK_HIDDEN_EXTERNAL_END
157 SkinletData(
const QMetaObject* metaObject )
158 : metaObject( metaObject )
168 const QMetaObject* metaObject;
173class QskSkin::PrivateData
176 QHash< const QMetaObject*, SkinletData > skinletMap;
180 QHash< QskFontRole, QFont > fonts;
181 QHash< int, QskColorFilter > graphicFilters;
185 int colorScheme = -1;
188QskSkin::QskSkin( QObject* parent )
190 , m_data( new PrivateData() )
192 declareSkinlet< QskControl, QskSkinlet >();
194 declareSkinlet< QskBox, QskBoxSkinlet >();
195 declareSkinlet< QskCheckBox, QskCheckBoxSkinlet >();
196 declareSkinlet< QskComboBox, QskComboBoxSkinlet >();
197 declareSkinlet< QskDrawer, QskDrawerSkinlet >();
198 declareSkinlet< QskFocusIndicator, QskFocusIndicatorSkinlet >();
199 declareSkinlet< QskGraphicLabel, QskGraphicLabelSkinlet >();
200 declareSkinlet< QskListView, QskListViewSkinlet >();
201 declareSkinlet< QskPageIndicator, QskPageIndicatorSkinlet >();
202 declareSkinlet< QskPopup, QskPopupSkinlet >();
203 declareSkinlet< QskMenu, QskMenuSkinlet >();
204 declareSkinlet< QskPushButton, QskPushButtonSkinlet >();
205 declareSkinlet< QskScrollView, QskScrollViewSkinlet >();
206 declareSkinlet< QskSegmentedBar, QskSegmentedBarSkinlet >();
207 declareSkinlet< QskSeparator, QskSeparatorSkinlet >();
208 declareSkinlet< QskSlider, QskSliderSkinlet >();
209 declareSkinlet< QskSpinBox, QskSpinBoxSkinlet >();
210 declareSkinlet< QskStatusIndicator, QskStatusIndicatorSkinlet >();
211 declareSkinlet< QskSubWindow, QskSubWindowSkinlet >();
212 declareSkinlet< QskSubWindowArea, QskSubWindowAreaSkinlet >();
213 declareSkinlet< QskSwitchButton, QskSwitchButtonSkinlet >();
214 declareSkinlet< QskTabButton, QskTabButtonSkinlet >();
215 declareSkinlet< QskTabView, QskTabViewSkinlet >();
216 declareSkinlet< QskTextLabel, QskTextLabelSkinlet >();
217 declareSkinlet< QskTextArea, QskTextAreaSkinlet >();
218 declareSkinlet< QskTextField, QskTextFieldSkinlet >();
219 declareSkinlet< QskProgressBar, QskProgressBarSkinlet >();
220 declareSkinlet< QskProgressRing, QskProgressRingSkinlet >();
221 declareSkinlet< QskRadioBox, QskRadioBoxSkinlet >();
223 const QFont font = QGuiApplication::font();
224 setupFontTable( font.family(), font.italic() );
226 const auto noMargins = QVariant::fromValue(
QskMargins( 0 ) );
247QskSkin::ColorScheme QskSkin::colorScheme()
const
249 if ( m_data->colorScheme < 0 )
250 return QskSkin::UnknownScheme;
252 return static_cast< QskSkin::ColorScheme
>( m_data->colorScheme );
255void QskSkin::setColorScheme( ColorScheme colorScheme )
257 if ( colorScheme == m_data->colorScheme )
260 m_data->colorScheme = colorScheme;
264 if ( qskSkinManager->currentSkin() ==
this )
265 transitionHint = qskSkinManager->transitionHint();
267 if ( transitionHint.isValid() )
270 transition.setMask( QskSkinTransition::Color );
271 transition.setSourceSkin(
this );
276 transition.setTargetSkin(
this );
277 transition.run( transitionHint );
285 Q_EMIT colorSchemeChanged( colorScheme );
288void QskSkin::setSkinHint(
QskAspect aspect,
const QVariant& skinHint )
290 m_data->hintTable.setHint( aspect, skinHint );
293const QVariant& QskSkin::skinHint(
QskAspect aspect )
const
295 return m_data->hintTable.hint( aspect );
298void QskSkin::declareSkinlet(
const QMetaObject* metaObject,
299 const QMetaObject* skinletMetaObject )
301 Q_ASSERT( skinletMetaObject->constructorCount() );
303 const auto it = m_data->skinletMap.find( metaObject );
305 if ( it != m_data->skinletMap.end() )
307 auto& entry = it.value();
308 if ( entry.metaObject != skinletMetaObject )
310 entry.metaObject = skinletMetaObject;
312 delete entry.skinlet;
313 entry.skinlet =
nullptr;
318 m_data->skinletMap.insert( metaObject, skinletMetaObject );
322static inline void qskSetFont(
QskSkin* skin,
323 QskFontRole::Category category, QFont font, qreal pointSize )
325 font.setPointSize( pointSize );
326 skin->setFont( { category, QskFontRole::Normal }, font );
329void QskSkin::setupFontTable(
const QString& family,
bool italic )
331 QFont font( family );
332 font.setItalic( italic );
333 font.setWeight( QFont::Normal );
335 qskSetFont(
this, QskFontRole::Caption, font, 8 );
336 qskSetFont(
this, QskFontRole::Subtitle, font, 10 );
337 qskSetFont(
this, QskFontRole::Body, font, 12 );
338 qskSetFont(
this, QskFontRole::Title, font, 20 );
339 qskSetFont(
this, QskFontRole::Headline, font, 30 );
340 qskSetFont(
this, QskFontRole::Display, font, 48 );
345void QskSkin::completeFontTable()
349 for (
int i = QskFontRole::Caption; i <= QskFontRole::Display; i++ )
351 auto& table = m_data->fonts;
353 const auto category =
static_cast< QskFontRole::Category
>( i );
355 const auto it = table.constFind( { category, QskFontRole::Normal } );
356 if ( it == table.constEnd() )
359 const auto normalFont = it.value();
361 for (
int j = QskFontRole::VeryLow; j <= QskFontRole::VeryHigh; j++ )
363 const auto emphasis =
static_cast< QskFontRole::Emphasis
>( j );
365 if ( emphasis == QskFontRole::Normal
366 || table.contains( { category, emphasis } ) )
371#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
372 const auto step = 10;
374 const auto step = 100;
377 int weight = normalFont.weight() + ( j - 2 ) * step;
378 weight = qBound(
static_cast<int>( QFont::Thin ),
379 weight,
static_cast<int>( QFont::Black ) );
381 auto font = normalFont;
382 font.setWeight(
static_cast< QFont::Weight
>( weight ) );
384 m_data->fonts[ { category, emphasis } ] = font;
389void QskSkin::setFont(
const QskFontRole& fontRole,
const QFont& font )
391 m_data->fonts[ fontRole ] = font;
394void QskSkin::resetFont(
const QskFontRole& fontRole )
396 m_data->fonts.remove( fontRole );
399QFont QskSkin::font(
const QskFontRole& fontRole )
const
401 return qskResolvedFont( m_data->fonts, fontRole );
404void QskSkin::setGraphicFilter(
int graphicRole,
const QskColorFilter& colorFilter )
406 m_data->graphicFilters[ graphicRole ] = colorFilter;
409void QskSkin::resetGraphicFilter(
int graphicRole )
411 m_data->graphicFilters.remove( graphicRole );
416 return m_data->graphicFilters.value( graphicRole );
421 return m_data->hintTable;
426 return m_data->hintTable;
429const QHash< QskFontRole, QFont >& QskSkin::fontTable()
const
431 return m_data->fonts;
434const QHash< int, QskColorFilter >& QskSkin::graphicFilters()
const
436 return m_data->graphicFilters;
439void QskSkin::addGraphicProvider(
442 m_data->graphicProviders.insert( providerId, provider );
447 return m_data->graphicProviders.provider( providerId );
450bool QskSkin::hasGraphicProvider()
const
452 return m_data->graphicProviders.size() > 0;
455void QskSkin::clearHints()
457 m_data->hintTable.clear();
458 m_data->fonts.clear();
459 m_data->graphicFilters.clear();
460 m_data->graphicProviders.clear();
463QString QskSkin::dialogButtonText(
int action )
const
465 const auto theme = qskPlatformTheme();
467 auto text = theme->standardButtonText( action );
468 text = QPlatformTheme::removeMnemonics( text );
473const int* QskSkin::dialogButtonLayout( Qt::Orientation orientation )
const
476 auto policy = QPlatformDialogHelper::WinLayout;
478 if (
const auto theme = qskPlatformTheme() )
480 const QVariant v = theme->themeHint( QPlatformTheme::DialogButtonBoxLayout );
481 policy =
static_cast< QPlatformDialogHelper::ButtonLayout
>( v.toInt() );
484 return QPlatformDialogHelper::buttonLayout( orientation, policy );
487const QMetaObject* QskSkin::skinletMetaObject(
const QMetaObject* metaObject )
const
491 auto it = m_data->skinletMap.constFind( metaObject );
492 if ( it != m_data->skinletMap.constEnd() )
493 return it.value().metaObject;
495 metaObject = metaObject->superClass();
501QskSkinlet* QskSkin::skinlet(
const QMetaObject* metaObject )
505 auto it = m_data->skinletMap.find( metaObject );
506 if ( it != m_data->skinletMap.end() )
508 auto& entry = it.value();
510 if ( entry.skinlet ==
nullptr )
511 entry.skinlet = qskNewSkinlet( entry.metaObject,
this );
513 return entry.skinlet;
516 metaObject = metaObject->superClass();
520 return &defaultSkinlet;
523#include "moc_QskSkin.cpp"
Lookup key for a QskSkinHintTable.
Describes the rendering interface of a QskControl. Change the skinlet to change the appearance of the...