2017-08-22 20:50:55 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QSK_SKIN_HINT_TABLE_H
|
|
|
|
#define QSK_SKIN_HINT_TABLE_H
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskAnimationHint.h"
|
2017-08-22 20:50:55 +02:00
|
|
|
#include "QskAspect.h"
|
2017-10-17 17:34:00 +02:00
|
|
|
#include "QskBoxBorderColors.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskBoxBorderMetrics.h"
|
|
|
|
#include "QskBoxShapeMetrics.h"
|
|
|
|
#include "QskGradient.h"
|
|
|
|
#include "QskMargins.h"
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qcolor.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <qvariant.h>
|
2017-08-22 20:50:55 +02:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2020-12-20 16:04:19 +01:00
|
|
|
class QSK_EXPORT QskSkinHintTable
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-10-17 17:34:00 +02:00
|
|
|
QskSkinHintTable();
|
|
|
|
QskSkinHintTable( const QskSkinHintTable& other );
|
|
|
|
|
2017-08-22 20:50:55 +02:00
|
|
|
~QskSkinHintTable();
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
QskSkinHintTable& operator=( const QskSkinHintTable& );
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setColor( QskAspect, Qt::GlobalColor );
|
|
|
|
void setColor( QskAspect, QRgb );
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setColor( QskAspect, const QColor& );
|
|
|
|
QColor color( QskAspect ) const;
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setMetric( QskAspect, qreal );
|
|
|
|
qreal metric( QskAspect ) const;
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setStrutSize( QskAspect, const QSizeF& );
|
|
|
|
QSizeF strutSize( QskAspect ) const;
|
2020-12-16 12:49:24 +01:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setMargin( QskAspect, const QskMargins& );
|
|
|
|
QskMargins margin( QskAspect ) const;
|
2020-12-15 07:21:12 +01:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setPadding( QskAspect, const QskMargins& );
|
|
|
|
QskMargins padding( QskAspect ) const;
|
2017-08-23 14:53:29 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setGradient( QskAspect, const QskGradient& );
|
|
|
|
QskGradient gradient( QskAspect ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setBoxShape( QskAspect, const QskBoxShapeMetrics& );
|
|
|
|
QskBoxShapeMetrics boxShape( QskAspect ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setBoxBorder( QskAspect, const QskBoxBorderMetrics& );
|
|
|
|
QskBoxBorderMetrics boxBorder( QskAspect ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setBoxBorderColors( QskAspect, const QskBoxBorderColors& );
|
|
|
|
QskBoxBorderColors boxBorderColors( QskAspect ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setSpacing( QskAspect, qreal );
|
|
|
|
qreal spacing( QskAspect ) const;
|
2020-12-15 07:21:12 +01:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setAlignment( QskAspect, Qt::Alignment );
|
|
|
|
Qt::Alignment alignment( QskAspect ) const;
|
2020-12-15 07:21:12 +01:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setAnimation( QskAspect, QskAnimationHint );
|
|
|
|
QskAnimationHint animation( QskAspect ) const;
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setGraphicRole( QskAspect, int role );
|
|
|
|
void setFontRole( QskAspect, int role );
|
|
|
|
void setFlagHint( QskAspect, int flag );
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
void setHint( QskAspect, const QVariant& );
|
|
|
|
const QVariant& hint( QskAspect ) const;
|
2019-05-16 08:14:53 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
bool removeHint( QskAspect );
|
|
|
|
QVariant takeHint( QskAspect );
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
bool hasHint( QskAspect ) const;
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
const std::unordered_map< QskAspect, QVariant >& hints() const;
|
2017-08-22 20:50:55 +02:00
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
bool hasAnimators() const;
|
|
|
|
bool hasStates() const;
|
|
|
|
bool hasHints() const;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
const QVariant* resolvedHint( QskAspect,
|
|
|
|
QskAspect* resolvedAspect = nullptr ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect resolvedAspect( QskAspect ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect resolvedAnimator(
|
|
|
|
QskAspect, QskAnimationHint& ) const;
|
2017-10-17 17:34:00 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
2017-10-17 17:34:00 +02:00
|
|
|
static QVariant invalidHint;
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
typedef std::unordered_map< QskAspect, QVariant > HintMap;
|
2017-10-17 17:34:00 +02:00
|
|
|
HintMap* m_hints;
|
|
|
|
|
|
|
|
quint16 m_animatorCount;
|
|
|
|
bool m_hasStates : 1;
|
2017-08-22 20:50:55 +02:00
|
|
|
};
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
inline bool QskSkinHintTable::hasHints() const
|
|
|
|
{
|
|
|
|
return m_hints != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool QskSkinHintTable::hasStates() const
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return m_hasStates;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool QskSkinHintTable::hasAnimators() const
|
|
|
|
{
|
|
|
|
return m_animatorCount;
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline bool QskSkinHintTable::hasHint( QskAspect aspect ) const
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
if ( m_hints != nullptr )
|
2017-08-22 20:50:55 +02:00
|
|
|
return m_hints->find( aspect ) != m_hints->cend();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline const QVariant& QskSkinHintTable::hint( QskAspect aspect ) const
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
|
|
|
if ( m_hints != nullptr )
|
|
|
|
{
|
|
|
|
auto it = m_hints->find( aspect );
|
|
|
|
if ( it != m_hints->cend() )
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return invalidHint;
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setColor( QskAspect aspect, const QColor& color )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect | QskAspect::Color, color );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setColor( QskAspect aspect, Qt::GlobalColor color )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect | QskAspect::Color, QColor( color ) );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setColor( QskAspect aspect, QRgb rgb )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect | QskAspect::Color, QColor::fromRgba( rgb ) );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QColor QskSkinHintTable::color( QskAspect aspect ) const
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
return hint( aspect | QskAspect::Color ).value< QColor >();
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setMetric( QskAspect aspect, qreal metric )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect | QskAspect::Metric, metric );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline qreal QskSkinHintTable::metric( QskAspect aspect ) const
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return hint( aspect | QskAspect::Metric ).toReal();
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setStrutSize( QskAspect aspect, const QSizeF& size )
|
2020-12-16 12:49:24 +01:00
|
|
|
{
|
|
|
|
const auto aspectStrut = aspect | QskAspect::Metric | QskAspect::StrutSize;
|
|
|
|
setHint( aspectStrut, QVariant::fromValue( size ) );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QSizeF QskSkinHintTable::strutSize( QskAspect aspect ) const
|
2020-12-16 12:49:24 +01:00
|
|
|
{
|
|
|
|
const auto aspectStrut = aspect | QskAspect::Metric | QskAspect::StrutSize;
|
|
|
|
return hint( aspectStrut ).value< QSizeF >();
|
|
|
|
}
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
inline void QskSkinHintTable::setMargin(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, const QskMargins& margins )
|
2017-08-23 14:53:29 +02:00
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
const auto aspectMargin = aspect | QskAspect::Metric | QskAspect::Margin;
|
|
|
|
setHint( aspectMargin, QVariant::fromValue( margins ) );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskMargins QskSkinHintTable::margin( QskAspect aspect ) const
|
2020-12-15 07:21:12 +01:00
|
|
|
{
|
|
|
|
const auto aspectMargin = aspect | QskAspect::Metric | QskAspect::Margin;
|
|
|
|
return hint( aspectMargin ).value< QskMargins >();
|
2017-08-23 14:53:29 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
inline void QskSkinHintTable::setPadding(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, const QskMargins& padding )
|
2017-08-23 14:53:29 +02:00
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
const auto aspectPadding = aspect | QskAspect::Metric | QskAspect::Padding;
|
|
|
|
setHint( aspectPadding, QVariant::fromValue( padding ) );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskMargins QskSkinHintTable::padding( QskAspect aspect ) const
|
2020-12-15 07:21:12 +01:00
|
|
|
{
|
|
|
|
const auto aspectPadding = aspect | QskAspect::Metric | QskAspect::Padding;
|
|
|
|
return hint( aspectPadding ).value< QskMargins >();
|
2017-10-17 17:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void QskSkinHintTable::setGradient(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, const QskGradient& gradient )
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
|
|
|
setHint( aspect | QskAspect::Color, QVariant::fromValue( gradient ) );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskGradient QskSkinHintTable::gradient( QskAspect aspect ) const
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
|
|
|
return hint( aspect | QskAspect::Color ).value< QskGradient >();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void QskSkinHintTable::setBoxShape(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, const QskBoxShapeMetrics& shape )
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
|
|
|
setHint( aspect | A::Shape | A::Metric, QVariant::fromValue( shape ) );
|
2017-10-17 17:34:00 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskBoxShapeMetrics QskSkinHintTable::boxShape( QskAspect aspect ) const
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
|
|
|
return hint( aspect | A::Shape | A::Metric ).value< QskBoxShapeMetrics >();
|
2017-10-17 17:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void QskSkinHintTable::setBoxBorder(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, const QskBoxBorderMetrics& border )
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
|
|
|
setHint( aspect | A::Border | A::Metric, QVariant::fromValue( border ) );
|
2017-10-17 17:34:00 +02:00
|
|
|
}
|
2018-08-03 08:15:28 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskBoxBorderMetrics QskSkinHintTable::boxBorder( QskAspect aspect ) const
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
|
|
|
return hint( aspect | A::Border | A::Metric ).value< QskBoxBorderMetrics >();
|
2017-08-23 14:53:29 +02:00
|
|
|
}
|
2018-08-03 08:15:28 +02:00
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
inline void QskSkinHintTable::setBoxBorderColors(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, const QskBoxBorderColors& colors )
|
2018-08-03 08:15:28 +02:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
|
|
|
setHint( aspect | A::Border | A::Color, QVariant::fromValue( colors ) );
|
2018-08-03 08:15:28 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskBoxBorderColors QskSkinHintTable::boxBorderColors( QskAspect aspect ) const
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
|
|
|
return hint( aspect | A::Border | A::Color ).value< QskBoxBorderColors >();
|
2018-08-03 08:15:28 +02:00
|
|
|
}
|
2017-08-23 14:53:29 +02:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setSpacing( QskAspect aspect, qreal spacing )
|
2020-12-15 07:21:12 +01:00
|
|
|
{
|
|
|
|
setMetric( aspect | QskAspect::Spacing, spacing );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline qreal QskSkinHintTable::spacing( QskAspect aspect ) const
|
2020-12-15 07:21:12 +01:00
|
|
|
{
|
|
|
|
return metric( aspect | QskAspect::Spacing );
|
2020-08-09 10:45:48 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline QskAnimationHint QskSkinHintTable::animation( QskAspect aspect ) const
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
|
|
|
aspect.setAnimator( true );
|
2017-10-17 17:34:00 +02:00
|
|
|
return hint( aspect ).value< QskAnimationHint >();
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setGraphicRole( QskAspect aspect, int role )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect | QskAspect::GraphicRole, role );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setFontRole( QskAspect aspect, int role )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect | QskAspect::FontRole, role );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
inline void QskSkinHintTable::setAlignment(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, Qt::Alignment alignment )
|
2020-12-15 07:21:12 +01:00
|
|
|
{
|
|
|
|
setFlagHint( aspect | QskAspect::Alignment, alignment );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline Qt::Alignment QskSkinHintTable::alignment( QskAspect aspect ) const
|
2020-12-15 07:21:12 +01:00
|
|
|
{
|
|
|
|
return hint( aspect | QskAspect::Alignment ).value< Qt::Alignment >();
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
inline void QskSkinHintTable::setFlagHint( QskAspect aspect, int flag )
|
2017-08-22 20:50:55 +02:00
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
setHint( aspect, QVariant( flag ) );
|
2017-08-22 20:50:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-19 08:44:16 +02:00
|
|
|
inline void QskSkinHintTable::setAnimation(
|
2020-12-21 16:06:58 +01:00
|
|
|
QskAspect aspect, QskAnimationHint animation )
|
2018-08-03 08:15:28 +02:00
|
|
|
{
|
2017-10-19 08:44:16 +02:00
|
|
|
aspect.setAnimator( true );
|
2018-08-03 08:15:28 +02:00
|
|
|
setHint( aspect, QVariant::fromValue( animation ) );
|
2017-10-19 08:44:16 +02:00
|
|
|
}
|
|
|
|
|
2017-08-22 20:50:55 +02:00
|
|
|
#endif
|