2019-02-26 21:52:02 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "MySkin.h"
|
|
|
|
|
|
|
|
#include "MyToggleButton.h"
|
|
|
|
#include "MyToggleButtonSkinlet.h"
|
|
|
|
|
|
|
|
#include <QskSkin.h>
|
2020-12-26 12:57:08 +01:00
|
|
|
#include <QskSkinHintTableEditor.h>
|
2019-02-26 21:52:02 +01:00
|
|
|
#include <QskAnimationHint.h>
|
|
|
|
#include <QskSetup.h>
|
|
|
|
|
|
|
|
#include <QskBoxBorderMetrics.h>
|
|
|
|
#include <QskBoxShapeMetrics.h>
|
|
|
|
#include <QskBoxBorderColors.h>
|
|
|
|
#include <QskGradient.h>
|
|
|
|
#include <QskRgbValue.h>
|
|
|
|
#include <QskColorFilter.h>
|
|
|
|
|
|
|
|
#include <QskBox.h>
|
|
|
|
#include <QskBoxSkinlet.h>
|
|
|
|
|
|
|
|
#include <QskFocusIndicator.h>
|
|
|
|
#include <QskFocusIndicatorSkinlet.h>
|
|
|
|
|
|
|
|
class MySkin : public QskSkin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum GraphicRole
|
|
|
|
{
|
|
|
|
GraphicRoleNormal,
|
|
|
|
GraphicRoleInverted
|
|
|
|
};
|
|
|
|
|
|
|
|
MySkin()
|
|
|
|
{
|
|
|
|
declareSkinlet< QskBox, QskBoxSkinlet >();
|
|
|
|
declareSkinlet< QskFocusIndicator, QskFocusIndicatorSkinlet >();
|
|
|
|
declareSkinlet< MyToggleButton, MyToggleButtonSkinlet >();
|
2020-12-26 12:57:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void setGraphicFilter( int role, QRgb rgb )
|
|
|
|
{
|
|
|
|
QskColorFilter filter;
|
|
|
|
filter.addColorSubstitution( QskRgb::Khaki, rgb );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
QskSkin::setGraphicFilter( role, filter );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
2020-12-26 12:57:08 +01:00
|
|
|
};
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
class MySkinEditor : public QskSkinHintTableEditor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setupFocusIndicator(
|
2019-02-26 21:52:02 +01:00
|
|
|
qreal border, qreal radius, qreal padding, QRgb rgb )
|
|
|
|
{
|
|
|
|
const auto subControl = QskFocusIndicator::Panel;
|
|
|
|
|
|
|
|
setBoxBorderMetrics( subControl, border );
|
|
|
|
setBoxShape( subControl, radius );
|
2020-12-15 07:21:12 +01:00
|
|
|
setPadding( subControl, padding );
|
2019-02-26 21:52:02 +01:00
|
|
|
setGradient( subControl, Qt::transparent );
|
|
|
|
|
|
|
|
setBoxBorderColors( subControl, rgb );
|
|
|
|
}
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
void setupBox(
|
2019-02-26 21:52:02 +01:00
|
|
|
qreal border, qreal radius,
|
|
|
|
const QskBoxBorderColors& borderColors,
|
|
|
|
const QskGradient& fillColor )
|
|
|
|
{
|
|
|
|
const auto subControl = QskBox::Panel;
|
|
|
|
|
|
|
|
setBoxBorderMetrics( subControl, border );
|
|
|
|
setBoxShape( subControl, radius );
|
|
|
|
setBoxBorderColors( subControl, borderColors );
|
|
|
|
setGradient( subControl, fillColor );
|
2020-12-15 07:21:12 +01:00
|
|
|
setPadding( subControl, 0.5 * radius );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
void setupToggleButton(
|
2019-02-27 06:17:10 +01:00
|
|
|
bool raised, qreal width, qreal height, qreal radius,
|
2019-02-26 21:52:02 +01:00
|
|
|
QRgb baseColor, QRgb baseTextColor,
|
|
|
|
QRgb foregroundColor, QRgb foregroundTextColor )
|
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
using A = QskAspect;
|
2019-02-26 21:52:02 +01:00
|
|
|
using Q = MyToggleButton;
|
|
|
|
|
|
|
|
for( auto subControl : { Q::UncheckedLabel, Q::CheckedLabel } )
|
|
|
|
{
|
|
|
|
QColor color1 = foregroundTextColor;
|
|
|
|
QColor color2 = baseTextColor;
|
|
|
|
|
|
|
|
if( subControl == Q::UncheckedLabel )
|
|
|
|
{
|
|
|
|
std::swap( color1, color2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
setColor( subControl | Q::Checked, color1 );
|
|
|
|
setColor( subControl, color2 );
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
setAlignment( subControl, Qt::AlignCenter );
|
2020-12-21 16:06:58 +01:00
|
|
|
setAnimation( subControl | A::Color, animator() );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for( auto subControl : { Q::UncheckedIcon, Q::CheckedIcon } )
|
|
|
|
{
|
|
|
|
int role1 = MySkin::GraphicRoleNormal;
|
|
|
|
int role2 = MySkin::GraphicRoleInverted;
|
|
|
|
|
|
|
|
if( subControl == Q::UncheckedIcon )
|
|
|
|
{
|
|
|
|
std::swap( role1, role2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
setGraphicRole( subControl, role1 );
|
|
|
|
setGraphicRole( subControl | Q::Checked, role2 );
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
setAnimation( subControl | A::Flag, animator() );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setGradient( Q::Panel, baseColor );
|
2019-02-27 06:17:10 +01:00
|
|
|
|
|
|
|
if ( raised )
|
|
|
|
{
|
|
|
|
setBoxBorderMetrics( Q::Panel, 3 );
|
|
|
|
|
2019-06-25 07:06:57 +02:00
|
|
|
auto light = QColor( baseColor ).lighter( 110 );
|
|
|
|
auto dark = QColor( baseColor ).darker( 120 );
|
2019-02-27 06:17:10 +01:00
|
|
|
setBoxBorderColors( Q::Panel,
|
|
|
|
QskBoxBorderColors( light, light, dark, dark ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setBoxBorderMetrics( Q::Panel, 1 );
|
2019-06-25 07:06:57 +02:00
|
|
|
setBoxBorderColors( Q::Panel, QColor( baseColor ).darker( 120 ) );
|
2019-02-27 06:17:10 +01:00
|
|
|
}
|
2019-02-26 21:52:02 +01:00
|
|
|
|
|
|
|
setGradient( Q::Cursor, foregroundColor );
|
2019-06-25 07:06:57 +02:00
|
|
|
setBoxBorderColors( Q::Cursor, QColor( foregroundColor ).darker( 120 ) );
|
2019-02-27 06:17:10 +01:00
|
|
|
setBoxBorderMetrics( Q::Cursor, 1 );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-16 12:49:24 +01:00
|
|
|
setStrutSize( Q::Panel, width, height );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-16 12:49:24 +01:00
|
|
|
setBoxShape( Q::Panel, radius );
|
|
|
|
setBoxShape( Q::Cursor, radius );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
setPadding( Q::CheckedPanel, 10 );
|
|
|
|
setPadding( Q::UncheckedPanel, 10 );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
for( auto state : { A::NoState, Q::Disabled } )
|
2019-02-26 21:52:02 +01:00
|
|
|
{
|
2020-12-21 16:06:58 +01:00
|
|
|
const auto aspect = Q::Cursor | state | A::Position;
|
2019-02-26 21:52:02 +01:00
|
|
|
|
|
|
|
setMetric( aspect | Q::Checked, 0 );
|
|
|
|
setMetric( aspect, 1 );
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:06:58 +01:00
|
|
|
setAnimation( Q::Cursor | A::Metric, animator() );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
void setAnimator( uint duration, QEasingCurve::Type type )
|
2019-02-26 21:52:02 +01:00
|
|
|
{
|
2020-12-26 12:57:08 +01:00
|
|
|
m_animationHint.duration = duration;
|
|
|
|
m_animationHint.type = type;
|
|
|
|
}
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
QskAnimationHint animator() const
|
|
|
|
{
|
|
|
|
return m_animationHint;
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-12-26 12:57:08 +01:00
|
|
|
QskAnimationHint m_animationHint;
|
2019-02-26 21:52:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class MySkin1 : public MySkin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MySkin1()
|
|
|
|
{
|
2020-08-15 13:29:17 +02:00
|
|
|
using namespace QskRgb;
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-08-15 13:29:17 +02:00
|
|
|
setGraphicFilter( GraphicRoleNormal, Crimson );
|
|
|
|
setGraphicFilter( GraphicRoleInverted, Gold );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
MySkinEditor editor;
|
|
|
|
editor.setTable( &hintTable() );
|
|
|
|
editor.setAnimator( 200, QEasingCurve::Linear );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
editor.setGradient( QskAspect::Control, Qt::gray );
|
|
|
|
|
|
|
|
editor.setupFocusIndicator( 2, 3, 6, DarkBlue );
|
|
|
|
editor.setupBox( 2, 8, DarkCyan, LightCyan );
|
|
|
|
|
|
|
|
editor.setupToggleButton( false, 150, 120, 6,
|
|
|
|
AliceBlue, Black, CornflowerBlue, White );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MySkin2 : public MySkin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MySkin2()
|
|
|
|
{
|
2020-08-15 13:29:17 +02:00
|
|
|
using namespace QskRgb;
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-08-15 13:29:17 +02:00
|
|
|
setGraphicFilter( GraphicRoleNormal, HotPink );
|
|
|
|
setGraphicFilter( GraphicRoleInverted, White );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
MySkinEditor editor;
|
|
|
|
editor.setTable( &hintTable() );
|
|
|
|
editor.setAnimator( 100, QEasingCurve::InQuad );
|
2019-02-26 21:52:02 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
editor.setGradient( QskAspect::Control, Qt::gray );
|
|
|
|
|
|
|
|
editor.setupFocusIndicator( 2, 6, 6, Crimson );
|
|
|
|
editor.setupBox( 4, 30, LightPink, MistyRose );
|
|
|
|
|
|
|
|
editor.setupToggleButton( true, 130, 100, 40,
|
|
|
|
LightPink, Black, HotPink, White );
|
2019-02-26 21:52:02 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QStringList MySkinFactory::skinNames() const
|
|
|
|
{
|
|
|
|
return { QStringLiteral( "MySkin1" ), QStringLiteral( "MySkin2" ) };
|
|
|
|
}
|
|
|
|
|
|
|
|
QskSkin* MySkinFactory::createSkin( const QString& skinName )
|
|
|
|
{
|
|
|
|
if ( skinName == QStringLiteral( "MySkin1" ) )
|
|
|
|
return new MySkin1();
|
|
|
|
|
|
|
|
if ( skinName == QStringLiteral( "MySkin2" ) )
|
|
|
|
return new MySkin2();
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_MySkin.cpp"
|