qskinny/src/controls/QskSkinHintTable.h
2022-03-31 18:09:03 +02:00

115 lines
2.6 KiB
C++

/******************************************************************************
* 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"
#include <qvariant.h>
#include <unordered_map>
class QskAnimationHint;
class QSK_EXPORT QskSkinHintTable
{
public:
QskSkinHintTable();
~QskSkinHintTable();
bool setAnimation( QskAspect, QskAnimationHint );
QskAnimationHint animation( QskAspect ) const;
bool setHint( QskAspect, const QVariant& );
const QVariant& hint( QskAspect ) const;
template< typename T > bool setHint( QskAspect, const T& );
template< typename T > T hint( QskAspect ) const;
bool removeHint( QskAspect );
QVariant takeHint( QskAspect );
bool hasHint( QskAspect ) const;
const std::unordered_map< QskAspect, QVariant >& hints() const;
bool hasAnimators() const;
bool hasHints() const;
QskAspect::States states() const;
void clear();
const QVariant* resolvedHint( QskAspect,
QskAspect* resolvedAspect = nullptr ) const;
QskAspect resolvedAspect( QskAspect ) const;
QskAspect resolvedAnimator(
QskAspect, QskAnimationHint& ) const;
bool isResolutionMatching( QskAspect, QskAspect ) const;
private:
Q_DISABLE_COPY( QskSkinHintTable )
static const QVariant invalidHint;
typedef std::unordered_map< QskAspect, QVariant > HintMap;
HintMap* m_hints = nullptr;
unsigned short m_animatorCount = 0;
QskAspect::States m_states;
};
inline bool QskSkinHintTable::hasHints() const
{
return m_hints != nullptr;
}
inline QskAspect::States QskSkinHintTable::states() const
{
return m_states;
}
inline bool QskSkinHintTable::hasAnimators() const
{
return m_animatorCount > 0;
}
inline bool QskSkinHintTable::hasHint( QskAspect aspect ) const
{
if ( m_hints != nullptr )
return m_hints->find( aspect ) != m_hints->cend();
return false;
}
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;
}
template< typename T >
inline bool QskSkinHintTable::setHint( QskAspect aspect, const T& hint )
{
return setHint( aspect, QVariant::fromValue( hint ) );
}
template< typename T >
inline T QskSkinHintTable::hint( QskAspect aspect ) const
{
return hint( aspect ).value< T >();
}
#endif