qskinny/src/controls/QskSkinHintTableEditor.cpp

517 lines
15 KiB
C++
Raw Normal View History

2020-12-26 12:57:08 +01:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskSkinHintTableEditor.h"
#include "QskSkinHintTable.h"
#include "QskArcMetrics.h"
2020-12-26 12:57:08 +01:00
#include "QskMargins.h"
#include "QskBoxShapeMetrics.h"
#include "QskBoxBorderMetrics.h"
#include "QskBoxBorderColors.h"
#include "QskGradient.h"
namespace
{
inline QskAspect::State lowestState( QskAspect::States mask )
{
using StateInt = typename std::underlying_type< QskAspect::State >::type;
2021-12-23 19:05:59 +01:00
const auto count = qCountTrailingZeroBits( static_cast< StateInt >( mask ) );
return static_cast< QskAspect::State >( 1 << count );
}
inline void setHintStateMask(
QskSkinHintTable* table, QskAspect aspect, const QVariant& hint,
bool noState, QskAspect::States states, QskAspect::States mask )
{
if ( mask == 0 )
{
if ( noState || states != 0 )
table->setHint( aspect | states, hint );
return;
}
const auto stateLow = lowestState( mask );
mask &= ~stateLow;
setHintStateMask( table, aspect, hint, noState, states, mask );
setHintStateMask( table, aspect, hint, noState, states | stateLow, mask );
}
inline bool removeHintStateMask(
QskSkinHintTable* table, QskAspect aspect,
bool noState, QskAspect::States states, QskAspect::States mask )
2021-12-23 19:05:59 +01:00
{
if ( mask == 0 )
2021-12-23 19:05:59 +01:00
{
if ( noState || states != 0 )
return table->removeHint( aspect | states );
2021-12-23 19:05:59 +01:00
return false;
}
2021-12-23 19:05:59 +01:00
const auto stateLow = lowestState( mask );
2021-12-23 19:05:59 +01:00
mask &= ~stateLow;
2021-12-23 19:05:59 +01:00
bool ret = removeHintStateMask( table, aspect, noState, states, mask );
ret |= removeHintStateMask( table, aspect, noState, states | stateLow, mask );
return ret;
}
2021-12-29 15:36:04 +01:00
inline QskAspect aspectPosition( QskAspect aspect )
{
return aspect | QskAspect::Position;
}
2020-12-26 12:57:08 +01:00
inline QskAspect aspectStrutSize( QskAspect aspect )
{
return aspect | QskAspect::StrutSize;
}
inline QskAspect aspectMargin( QskAspect aspect )
{
return aspect | QskAspect::Margin;
}
inline QskAspect aspectPadding( QskAspect aspect )
{
return aspect | QskAspect::Padding;
}
inline QskAspect aspectSpacing( QskAspect aspect )
{
return aspect | QskAspect::Spacing;
}
inline QskAspect aspectAlignment( QskAspect aspect )
{
return aspect | QskAspect::Alignment;
}
inline QskAspect aspectFontRole( QskAspect aspect )
{
return aspect | QskAspect::FontRole;
}
inline QskAspect aspectGraphicRole( QskAspect aspect )
{
return aspect | QskAspect::GraphicRole;
}
inline QskAspect aspectShape( QskAspect aspect )
{
return aspect | QskAspect::Shape;
}
inline QskAspect aspectBorder( QskAspect aspect )
{
return aspect | QskAspect::Border;
}
}
QskSkinHintTableEditor::QskSkinHintTableEditor( QskSkinHintTable* table )
: m_table( table )
{
}
void QskSkinHintTableEditor::setTable( QskSkinHintTable* table )
{
m_table = table;
}
QskSkinHintTable* QskSkinHintTableEditor::table() const
{
return m_table;
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setHint( QskAspect aspect,
const QVariant& hint, QskStateCombination combination )
{
if ( combination.isNull() )
2021-09-04 16:48:02 +02:00
{
m_table->setHint( aspect, hint );
}
else
{
const bool noState =
( combination.type() == QskStateCombination::CombinationNoState );
2021-09-04 16:48:02 +02:00
setHintStateMask( m_table, aspect, hint,
noState, QskAspect::States(), combination.states() );
2021-09-04 16:48:02 +02:00
}
}
2021-09-04 16:48:02 +02:00
bool QskSkinHintTableEditor::removeHint(
QskAspect aspect, QskStateCombination combination )
{
if ( combination.isNull() )
2021-09-04 16:48:02 +02:00
{
return m_table->removeHint( aspect );
}
else
{
const bool noState =
( combination.type() == QskStateCombination::CombinationNoState );
2021-09-04 16:48:02 +02:00
return removeHintStateMask( m_table, aspect,
noState, QskAspect::States(), combination.states() );
2021-09-04 16:48:02 +02:00
}
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setFlag(
QskAspect aspect, int flag, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setFlagHint( aspect, flag, combination );
2020-12-26 12:57:08 +01:00
}
int QskSkinHintTableEditor::flag( QskAspect aspect ) const
{
2021-08-04 09:31:16 +02:00
return flagHint< int >( aspect );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setMetric(
QskAspect aspect, qreal metric, QskStateCombination combination )
2021-09-03 06:51:50 +02:00
{
setMetricHint( aspect, metric, combination );
2020-12-26 12:57:08 +01:00
}
qreal QskSkinHintTableEditor::metric( QskAspect aspect ) const
{
2021-08-04 09:31:16 +02:00
return metricHint< qreal >( aspect );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setColor(
QskAspect aspect, Qt::GlobalColor color, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setColorHint( aspect, QColor( color ), combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setColor(
QskAspect aspect, QRgb rgb, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setColorHint( aspect, QColor::fromRgba( rgb ), combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setColor(
QskAspect aspect, const QColor& color, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setColorHint( aspect, color, combination );
2020-12-26 12:57:08 +01:00
}
QColor QskSkinHintTableEditor::color( QskAspect aspect ) const
{
2021-08-04 09:31:16 +02:00
return colorHint< QColor >( aspect );
2020-12-26 12:57:08 +01:00
}
2021-01-07 13:48:56 +01:00
void QskSkinHintTableEditor::setHGradient(
2021-09-04 16:48:02 +02:00
QskAspect aspect, const QColor& color1, const QColor& color2,
QskStateCombination combination )
2021-01-07 13:48:56 +01:00
{
2021-09-04 16:48:02 +02:00
const QskGradient gradient( QskGradient::Horizontal, color1, color2 );
setGradient( aspect, gradient, combination );
2021-01-07 13:48:56 +01:00
}
void QskSkinHintTableEditor::setVGradient(
2021-09-04 16:48:02 +02:00
QskAspect aspect, const QColor& color1, const QColor& color2,
QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
2021-09-04 16:48:02 +02:00
const QskGradient gradient( QskGradient::Vertical, color1, color2 );
setGradient( aspect, gradient, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setGradient(
QskAspect aspect, const QskGradient& gradient,
QskStateCombination combination )
{
setColorHint( aspect, gradient, combination );
}
2020-12-26 12:57:08 +01:00
QskGradient QskSkinHintTableEditor::gradient( QskAspect aspect ) const
{
2021-08-04 09:31:16 +02:00
return colorHint< QskGradient >( aspect );
2020-12-26 12:57:08 +01:00
}
2021-12-29 15:36:04 +01:00
void QskSkinHintTableEditor::setPosition(
QskAspect aspect, qreal position, QskStateCombination combination )
{
setMetricHint( aspectPosition( aspect ), position, combination );
}
void QskSkinHintTableEditor::removePosition(
QskAspect aspect, QskStateCombination combination )
{
removeMetricHint( aspectPosition( aspect ), combination );
}
qreal QskSkinHintTableEditor::position( QskAspect aspect ) const
{
return metricHint< qreal >( aspectPosition( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setStrutSize(
QskAspect aspect, const QSizeF& size, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setMetricHint( aspectStrutSize( aspect ), size, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setStrutSize(
QskAspect aspect, qreal width, qreal height, QskStateCombination combination )
2021-09-03 06:51:50 +02:00
{
2021-09-04 16:48:02 +02:00
setMetricHint( aspectStrutSize( aspect ),
QSizeF( width, height ), combination );
2021-09-03 06:51:50 +02:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeStrutSize(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
removeMetricHint( aspectStrutSize( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
QSizeF QskSkinHintTableEditor::strutSize( QskAspect aspect ) const
{
return metricHint< QSizeF >( aspectStrutSize( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setMargin(
QskAspect aspect, const QskMargins& margins, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setMetricHint( aspectMargin( aspect ), margins, combination );
2020-12-26 12:57:08 +01:00
}
void QskSkinHintTableEditor::setMargin( QskAspect aspect,
2021-09-04 16:48:02 +02:00
qreal left, qreal top, qreal right, qreal bottom,
QskStateCombination combination )
2021-09-03 06:51:50 +02:00
{
2021-09-04 16:48:02 +02:00
const QskMargins margins( left, top, right, bottom );
setMetricHint( aspectMargin( aspect ), margins, combination );
2021-09-03 06:51:50 +02:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeMargin(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
removeMetricHint( aspectMargin( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
QskMargins QskSkinHintTableEditor::margin( QskAspect aspect ) const
{
return metricHint< QskMargins >( aspectMargin( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setPadding(
QskAspect aspect, const QskMargins& padding,
QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setMetricHint( aspectPadding( aspect ), padding, combination );
2020-12-26 12:57:08 +01:00
}
void QskSkinHintTableEditor::setPadding( QskAspect aspect,
2021-09-04 16:48:02 +02:00
qreal left, qreal top, qreal right, qreal bottom,
QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
2021-09-04 16:48:02 +02:00
QskMargins padding( left, top, right, bottom );
setMetricHint( aspectPadding( aspect ), padding, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removePadding(
QskAspect aspect, QskStateCombination combination )
2021-09-03 06:51:50 +02:00
{
removeMetricHint( aspectPadding( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
QskMargins QskSkinHintTableEditor::padding( QskAspect aspect ) const
{
return metricHint< QskMargins >( aspectPadding( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setSpacing(
QskAspect aspect, qreal spacing, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setMetricHint( aspectSpacing( aspect ), spacing, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeSpacing(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
removeMetricHint( aspectSpacing( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
qreal QskSkinHintTableEditor::spacing( QskAspect aspect ) const
{
return metricHint< qreal >( aspectSpacing( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setAlignment(
QskAspect aspect, Qt::Alignment alignment, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
2021-09-04 16:48:02 +02:00
setFlagHint( aspectAlignment( aspect ),
static_cast< int >( alignment ), combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeAlignment(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
return removeFlagHint( aspectAlignment( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
Qt::Alignment QskSkinHintTableEditor::alignment( QskAspect aspect ) const
{
return flagHint< Qt::Alignment >( aspectAlignment( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setFontRole(
QskAspect aspect, int fontRole, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setFlagHint( aspectFontRole( aspect ), fontRole, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeFontRole(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
return removeFlagHint( aspectFontRole( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
int QskSkinHintTableEditor::fontRole( QskAspect aspect ) const
{
return flagHint< int >( aspectFontRole( aspect ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setGraphicRole(
QskAspect aspect, int graphicRole, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setFlagHint( aspectGraphicRole( aspect ), graphicRole, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeGraphicRole(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
return removeFlagHint( aspectGraphicRole( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
int QskSkinHintTableEditor::graphicRole( QskAspect aspect ) const
{
return flagHint< int >( aspectGraphicRole( aspect ) );
}
void QskSkinHintTableEditor::setBoxShape(
QskAspect aspect, qreal radius, Qt::SizeMode sizeMode )
{
setMetricHint( aspectShape( aspect ),
QskBoxShapeMetrics( radius, sizeMode ) );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::setBoxShape( QskAspect aspect,
qreal topLeft, qreal topRight, qreal bottomLeft, qreal bottomRight,
Qt::SizeMode sizeMode )
2020-12-26 12:57:08 +01:00
{
setMetricHint( aspectShape( aspect ),
QskBoxShapeMetrics( topLeft, topRight, bottomLeft, bottomRight, sizeMode ) );
}
void QskSkinHintTableEditor::setBoxShape(
QskAspect aspect, const QskBoxShapeMetrics& shape,
QskStateCombination combination )
{
setMetricHint( aspectShape( aspect ), shape, combination );
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeBoxShape(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
return removeMetricHint( aspectShape( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
QskBoxShapeMetrics QskSkinHintTableEditor::boxShape( QskAspect aspect ) const
{
return metricHint< QskBoxShapeMetrics >( aspectShape( aspect ) );
}
void QskSkinHintTableEditor::setBoxBorderMetrics( QskAspect aspect,
qreal borderWidth, Qt::SizeMode sizeMode )
{
setMetricHint( aspectBorder( aspect ),
QskBoxBorderMetrics( borderWidth, sizeMode ) );
}
void QskSkinHintTableEditor::setBoxBorderMetrics( QskAspect aspect,
qreal left, qreal top, qreal right, qreal bottom, Qt::SizeMode sizeMode )
{
setMetricHint( aspectBorder( aspect ),
QskBoxBorderMetrics( left, top, right, bottom, sizeMode ) );
}
void QskSkinHintTableEditor::setBoxBorderMetrics(
2021-09-04 16:48:02 +02:00
QskAspect aspect, const QskBoxBorderMetrics& borderMetrics,
QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
setMetricHint( aspectBorder( aspect ), borderMetrics, combination );
2020-12-26 12:57:08 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeBoxBorderMetric(
QskAspect aspect, QskStateCombination combination )
{
return removeMetricHint( aspectBorder( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
QskBoxBorderMetrics QskSkinHintTableEditor::boxBorderMetrics( QskAspect aspect ) const
{
return metricHint< QskBoxBorderMetrics >( aspectBorder( aspect ) );
}
void QskSkinHintTableEditor::setBoxBorderColors(
2021-09-04 16:48:02 +02:00
QskAspect aspect, const QskBoxBorderColors& borderColors,
QskStateCombination combination )
{
setColorHint( aspectBorder( aspect ), borderColors, combination );
}
void QskSkinHintTableEditor::setBoxBorderColors(QskAspect aspect,
const QskGradient& left, const QskGradient& top, const QskGradient& right,
const QskGradient& bottom, QskStateCombination combination )
2021-02-01 10:23:47 +01:00
{
setColorHint( aspectBorder( aspect ),
2021-09-04 16:48:02 +02:00
QskBoxBorderColors( left, top, right, bottom ),
combination );
2021-02-01 10:23:47 +01:00
}
2021-09-04 16:48:02 +02:00
void QskSkinHintTableEditor::removeBoxBorderColors(
QskAspect aspect, QskStateCombination combination )
2020-12-26 12:57:08 +01:00
{
return removeColorHint( aspectBorder( aspect ), combination );
2020-12-26 12:57:08 +01:00
}
QskBoxBorderColors QskSkinHintTableEditor::boxBorderColors( QskAspect aspect ) const
{
return colorHint< QskBoxBorderColors >( aspectBorder( aspect ) );
}
void QskSkinHintTableEditor::setArcMetrics( QskAspect aspect, qreal width,
2021-10-20 09:27:05 +02:00
qreal startAngle, qreal spanAngle, Qt::SizeMode sizeMode )
{
setMetricHint( aspectShape( aspect ),
QskArcMetrics( width, startAngle, spanAngle, sizeMode ) );
}
void QskSkinHintTableEditor::setArcMetrics( QskAspect aspect,
const QskArcMetrics& arcMetrics, QskStateCombination combination )
{
setMetricHint( aspectShape( aspect ), arcMetrics, combination );
}
void QskSkinHintTableEditor::removeArcMetrics( QskAspect aspect,
QskStateCombination combination )
{
return removeMetricHint( aspectShape( aspect ), combination );
}
QskArcMetrics QskSkinHintTableEditor::arcMetrics( QskAspect aspect ) const
{
return metricHint< QskArcMetrics >( aspectShape( aspect ) );
}