qskinny/src/controls/QskSkinHintTable.h

113 lines
2.6 KiB
C
Raw Normal View History

/******************************************************************************
2024-01-17 14:31:45 +01:00
* QSkinny - Copyright (C) The authors
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#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 <qhash.h>
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& );
~QskSkinHintTable();
QskSkinHintTable& operator=( const QskSkinHintTable& );
bool setAnimation( QskAspect, QskAnimationHint );
2020-12-21 16:06:58 +01:00
QskAnimationHint animation( QskAspect ) const;
bool setHint( QskAspect, const QVariant& );
2020-12-21 16:06:58 +01:00
const QVariant& hint( QskAspect ) const;
template< typename T > bool setHint( QskAspect, const T& );
2020-12-26 12:57:08 +01:00
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;
const QHash< QskAspect, QVariant >& hints() const;
bool hasAnimators() const;
bool hasHints() const;
QskAspect::States states() 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:
2022-03-31 18:09:03 +02:00
2020-12-26 12:57:08 +01:00
static const QVariant invalidHint;
QHash< QskAspect, QVariant >* 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;
}
2020-12-21 16:06:58 +01:00
inline bool QskSkinHintTable::hasHint( QskAspect aspect ) const
{
return m_hints && m_hints->contains( aspect );
}
2020-12-21 16:06:58 +01:00
inline const QVariant& QskSkinHintTable::hint( QskAspect aspect ) const
{
if ( m_hints != nullptr )
{
auto it = m_hints->constFind( aspect );
if ( it != m_hints->constEnd() )
return it.value();
}
return invalidHint;
}
2020-12-26 12:57:08 +01:00
template< typename T >
inline bool QskSkinHintTable::setHint( QskAspect aspect, const T& hint )
{
return 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