242 lines
6.5 KiB
C++
Raw Normal View History

2019-02-26 21:52:02 +01:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2019-02-26 21:52:02 +01:00
*****************************************************************************/
#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 );
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 );
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;
2021-12-27 18:47:46 +01:00
for( auto subControl : { Q::UncheckedText, Q::CheckedText } )
2019-02-26 21:52:02 +01:00
{
QColor color1 = foregroundTextColor;
QColor color2 = baseTextColor;
2021-12-27 18:47:46 +01:00
if( subControl == Q::CheckedText )
2019-02-26 21:52:02 +01:00
std::swap( color1, color2 );
2021-12-27 18:47:46 +01:00
setColor( subControl, color1 );
setColor( subControl | Q::Checked, color2 );
2019-02-26 21:52:02 +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 } )
2019-02-26 21:52:02 +01:00
{
2021-12-27 18:47:46 +01:00
int role1 = MySkin::GraphicRoleInverted;
int role2 = MySkin::GraphicRoleNormal;
2019-02-26 21:52:02 +01:00
if( subControl == Q::CheckedIcon )
2019-02-26 21:52:02 +01:00
std::swap( role1, role2 );
setGraphicRole( subControl, role1 );
setGraphicRole( subControl | Q::Checked, role2 );
setAnimation( subControl, 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
setStrutSize( Q::Panel, width, height );
2019-02-26 21:52:02 +01:00
setBoxShape( Q::Panel, radius );
setBoxShape( Q::Cursor, radius );
2019-02-26 21:52:02 +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
{
2021-12-29 17:05:29 +01:00
const auto aspect = Q::Cursor | state;
2019-02-26 21:52:02 +01:00
2021-12-29 17:05:29 +01:00
setPosition( aspect, 0 );
setPosition( aspect | Q::Checked, 1 );
2019-02-26 21:52:02 +01:00
}
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
};
2021-12-27 18:47:46 +01:00
namespace
2019-02-26 21:52:02 +01:00
{
2021-12-27 18:47:46 +01:00
class SkinBlue : public MySkin
2019-02-26 21:52:02 +01:00
{
2021-12-27 18:47:46 +01:00
public:
SkinBlue()
{
using namespace QskRgb;
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
setGraphicFilter( GraphicRoleNormal, Crimson );
setGraphicFilter( GraphicRoleInverted, Gold );
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
MySkinEditor editor;
editor.setTable( &hintTable() );
editor.setAnimator( 200, QEasingCurve::Linear );
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
editor.setupFocusIndicator( 2, 3, 6, DarkBlue );
editor.setupBox( 2, 8, DarkCyan, LightCyan );
2020-12-26 12:57:08 +01:00
2021-12-27 18:47:46 +01:00
editor.setupToggleButton( false, 150, 120, 6,
AliceBlue, Black, CornflowerBlue, White );
}
};
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
class SkinPink : public MySkin
2019-02-26 21:52:02 +01:00
{
2021-12-27 18:47:46 +01:00
public:
SkinPink()
{
using namespace QskRgb;
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
setGraphicFilter( GraphicRoleNormal, HotPink );
setGraphicFilter( GraphicRoleInverted, White );
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
MySkinEditor editor;
editor.setTable( &hintTable() );
editor.setAnimator( 100, QEasingCurve::InQuad );
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
editor.setupFocusIndicator( 2, 6, 6, Crimson );
editor.setupBox( 4, 30, LightPink, MistyRose );
2020-12-26 12:57:08 +01:00
2021-12-27 18:47:46 +01:00
editor.setupToggleButton( true, 130, 100, 40,
LightPink, Black, HotPink, White );
}
};
}
2019-02-26 21:52:02 +01:00
QStringList MySkinFactory::skinNames() const
{
2021-12-27 18:47:46 +01:00
return { QStringLiteral( "Blue" ), QStringLiteral( "Pink" ) };
2019-02-26 21:52:02 +01:00
}
QskSkin* MySkinFactory::createSkin( const QString& skinName )
{
2021-12-27 18:47:46 +01:00
if ( skinName == QStringLiteral( "Blue" ) )
return new SkinBlue();
2019-02-26 21:52:02 +01:00
2021-12-27 18:47:46 +01:00
if ( skinName == QStringLiteral( "Pink" ) )
return new SkinPink();
2019-02-26 21:52:02 +01:00
return nullptr;
}
#include "moc_MySkin.cpp"