qskinny/src/controls/QskSkinHintTable.h

116 lines
2.6 KiB
C
Raw Normal View History

/******************************************************************************
* 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
#include "QskAspect.h"
2018-08-03 08:15:28 +02:00
#include <qvariant.h>
#include <unordered_map>
2020-12-26 12:57:08 +01:00
class QskAnimationHint;
2020-12-20 16:04:19 +01:00
class QSK_EXPORT QskSkinHintTable
{
2018-08-03 08:15:28 +02:00
public:
QskSkinHintTable();
QskSkinHintTable( const QskSkinHintTable& other );
~QskSkinHintTable();
QskSkinHintTable& operator=( const QskSkinHintTable& );
2020-12-21 16:06:58 +01:00
void setAnimation( QskAspect, QskAnimationHint );
QskAnimationHint animation( QskAspect ) const;
2020-12-21 16:06:58 +01:00
void setHint( QskAspect, const QVariant& );
const QVariant& hint( QskAspect ) const;
2020-12-26 12:57:08 +01:00
template< typename T > void setHint( QskAspect, const T& );
template< typename T > T hint( QskAspect ) const;
2020-12-21 16:06:58 +01:00
bool removeHint( QskAspect );
QVariant takeHint( QskAspect );
2020-12-21 16:06:58 +01:00
bool hasHint( QskAspect ) const;
2020-12-21 16:06:58 +01:00
const std::unordered_map< QskAspect, QVariant >& hints() const;
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;
2020-12-21 16:06:58 +01:00
QskAspect resolvedAspect( QskAspect ) const;
2020-12-21 16:06:58 +01:00
QskAspect resolvedAnimator(
QskAspect, QskAnimationHint& ) const;
2020-12-26 13:00:09 +01:00
bool isResolutionMatching( QskAspect, QskAspect ) const;
2018-08-03 08:15:28 +02:00
private:
2020-12-26 12:57:08 +01:00
static const QVariant invalidHint;
2020-12-21 16:06:58 +01:00
typedef std::unordered_map< QskAspect, QVariant > HintMap;
HintMap* m_hints;
quint16 m_animatorCount;
bool m_hasStates : 1;
};
inline bool QskSkinHintTable::hasHints() const
{
return m_hints != nullptr;
}
inline bool QskSkinHintTable::hasStates() const
{
return m_hasStates;
}
inline bool QskSkinHintTable::hasAnimators() const
{
return m_animatorCount;
}
2020-12-21 16:06:58 +01:00
inline bool QskSkinHintTable::hasHint( QskAspect aspect ) const
{
if ( m_hints != nullptr )
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
{
if ( m_hints != nullptr )
{
auto it = m_hints->find( aspect );
if ( it != m_hints->cend() )
return it->second;
}
return invalidHint;
}
2020-12-26 12:57:08 +01:00
template< typename T >
inline void QskSkinHintTable::setHint( QskAspect aspect, const T& hint )
{
2020-12-26 12:57:08 +01:00
setHint( aspect, QVariant::fromValue( hint ) );
}
2020-12-26 12:57:08 +01:00
template< typename T >
inline T QskSkinHintTable::hint( QskAspect aspect ) const
2018-08-03 08:15:28 +02:00
{
2020-12-26 12:57:08 +01:00
return hint( aspect ).value< T >();
}
#endif