2019-06-20 12:02:28 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-07-25 21:34:27 +02:00
|
|
|
#include "SkinFactory.h"
|
|
|
|
|
2020-12-13 19:38:46 +01:00
|
|
|
#include "ButtonBar.h"
|
|
|
|
#include "Speedometer.h"
|
|
|
|
#include "SpeedometerSkinlet.h"
|
|
|
|
|
|
|
|
#include <QskBoxBorderColors.h>
|
|
|
|
#include <QskBoxBorderMetrics.h>
|
|
|
|
#include <QskColorFilter.h>
|
|
|
|
#include <QskFunctions.h>
|
|
|
|
#include <QskMargins.h>
|
|
|
|
#include <QskTextLabel.h>
|
|
|
|
#include <QskAnimationHint.h>
|
2017-07-25 21:34:27 +02:00
|
|
|
#include <QskSetup.h>
|
|
|
|
#include <QskSkinTransition.h>
|
2020-12-26 12:57:08 +01:00
|
|
|
#include <QskSkinHintTableEditor.h>
|
2020-12-13 19:38:46 +01:00
|
|
|
#include <QskSkin.h>
|
|
|
|
|
|
|
|
#include <QEasingCurve>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
inline QFont qskFont( qreal pointSize )
|
|
|
|
{
|
|
|
|
QFont font( "Roboto" );
|
|
|
|
font.setPointSizeF( pointSize / qskDpiScaled( 1.0 ) );
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Skin : public QskSkin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Skin()
|
|
|
|
{
|
|
|
|
declareSkinlet< Speedometer, SpeedometerSkinlet >();
|
|
|
|
|
|
|
|
setFont( QskSkin::DefaultFont, qskFont( 13 ) );
|
|
|
|
setFont( QskSkin::LargeFont, qskFont( 20 ) );
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
setSkinHint( ButtonBar::Indicator | QskAspect::GraphicRole, SkinFactory::Indicator );
|
2020-12-13 19:38:46 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Skin1 : public Skin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Skin1()
|
|
|
|
{
|
|
|
|
const QColor color1( "#363636" ); // Jet
|
|
|
|
const QColor color2( "#242F40" ); // Yankees blue
|
|
|
|
const QColor color3( "#CCA43B" ); // Satin sheet gold
|
|
|
|
const QColor color4( "#E5E5E5" ); // Platinum
|
|
|
|
const QColor color5( "#FFFFFF" ); // white
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
QskSkinHintTableEditor ed( &hintTable() );
|
|
|
|
|
|
|
|
ed.setColor( QskTextLabel::Text, color3 );
|
2020-12-13 19:38:46 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
using Q = Speedometer;
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
ed.setBoxBorderMetrics( Q::Panel, 5 );
|
|
|
|
ed.setBoxShape( Q::Panel, 30, Qt::RelativeSize );
|
|
|
|
ed.setGradient( Q::Panel,
|
2020-12-13 19:38:46 +01:00
|
|
|
QskGradient( QskGradient::Vertical, color2, color4 ) );
|
2020-12-26 12:57:08 +01:00
|
|
|
ed.setBoxBorderColors( Q::Panel, color3 );
|
|
|
|
|
|
|
|
ed.setBoxBorderMetrics( Q::Knob, 5 );
|
|
|
|
ed.setStrutSize( Q::Knob, 20, 20 );
|
|
|
|
ed.setBoxShape( Q::Knob, 100, Qt::RelativeSize );
|
|
|
|
ed.setGradient( Q::Knob, color2 );
|
|
|
|
ed.setBoxBorderColors( Q::Knob, color4 );
|
|
|
|
|
|
|
|
ed.setMetric( Q::Needle | QskAspect::Size, 4 );
|
|
|
|
ed.setMetric( Q::Needle | QskAspect::Margin, 15 );
|
|
|
|
ed.setColor( Q::Needle, color4 );
|
|
|
|
|
|
|
|
ed.setSpacing( Q::TickLabels, 3 );
|
|
|
|
ed.setStrutSize( Q::TickLabels, 3, 25 );
|
|
|
|
ed.setColor( Q::TickLabels, color4 );
|
|
|
|
ed.setFontRole( Q::TickLabels, QskSkin::SmallFont );
|
2020-12-13 19:38:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// all SVGs on the header/footer are plain white
|
|
|
|
|
|
|
|
QskColorFilter filter;
|
|
|
|
filter.addColorSubstitution( Qt::white, color3.rgb() );
|
|
|
|
|
|
|
|
setGraphicFilter( SkinFactory::Indicator, filter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Skin2 : public Skin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Skin2()
|
|
|
|
{
|
|
|
|
const QColor color1( "#011627" ); // Maastricht blue
|
|
|
|
const QColor color2( "#FF0022" ); // ruddy
|
|
|
|
const QColor color3( "#41EAD4" ); // Turquoise
|
|
|
|
const QColor color4( "#FDFFFC" ); // baby powder
|
|
|
|
const QColor color5( "#B91372" ); // red violet
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
QskSkinHintTableEditor ed( &hintTable() );
|
|
|
|
|
|
|
|
ed.setColor( QskTextLabel::Text, color4 );
|
2020-12-13 19:38:46 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
using Q = Speedometer;
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
ed.setBoxBorderMetrics( Q::Panel, 2 );
|
|
|
|
ed.setBoxShape( Q::Panel, 100, Qt::RelativeSize );
|
|
|
|
ed.setGradient( Q::Panel, color1 );
|
|
|
|
ed.setBoxBorderColors( Q::Panel, color3 );
|
2020-12-13 19:38:46 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
ed.setBoxBorderMetrics( Q::Knob, 2 );
|
|
|
|
ed.setStrutSize( Q::Knob, 30, 30 );
|
|
|
|
ed.setBoxShape( Q::Knob, 100, Qt::RelativeSize );
|
|
|
|
ed.setGradient( Q::Knob,
|
2020-12-13 19:38:46 +01:00
|
|
|
QskGradient( QskGradient::Diagonal, color2, color1 ) );
|
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
ed.setMetric( Q::Needle | QskAspect::Size, 2 );
|
|
|
|
ed.setMetric( Q::Needle | QskAspect::Margin, 10 );
|
|
|
|
ed.setColor( Q::Needle, color2 );
|
2020-12-13 19:38:46 +01:00
|
|
|
|
2020-12-26 12:57:08 +01:00
|
|
|
ed.setSpacing( Q::TickLabels, 4 );
|
|
|
|
ed.setStrutSize( Q::TickLabels, 2, 15 );
|
|
|
|
ed.setColor( Q::TickLabels, color4 );
|
|
|
|
ed.setFontRole( Q::TickLabels, QskSkin::SmallFont );
|
2020-12-13 19:38:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2017-07-25 21:34:27 +02:00
|
|
|
|
|
|
|
QStringList SkinFactory::skinNames() const
|
|
|
|
{
|
2020-12-13 19:38:46 +01:00
|
|
|
return { "Skin1", "Skin2" };
|
2017-07-25 21:34:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QskSkin* SkinFactory::createSkin( const QString& skinName )
|
|
|
|
{
|
2020-12-13 19:38:46 +01:00
|
|
|
if ( skinName == "Skin1" )
|
|
|
|
return new Skin1();
|
2017-07-25 21:34:27 +02:00
|
|
|
|
2020-12-13 19:38:46 +01:00
|
|
|
if ( skinName == "Skin2" )
|
|
|
|
return new Skin2();
|
2017-07-25 21:34:27 +02:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkinFactory::rotateSkin()
|
|
|
|
{
|
2020-12-13 19:38:46 +01:00
|
|
|
const auto names = skinNames();
|
2017-07-25 21:34:27 +02:00
|
|
|
|
|
|
|
int index = names.indexOf( qskSetup->skinName() );
|
|
|
|
index = ( index + 1 ) % names.size();
|
|
|
|
|
2018-05-09 08:47:33 +02:00
|
|
|
auto oldSkin = qskSetup->skin();
|
2017-07-25 21:34:27 +02:00
|
|
|
if ( oldSkin->parent() == qskSetup )
|
|
|
|
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
|
|
|
|
|
2018-05-09 08:47:33 +02:00
|
|
|
auto newSkin = qskSetup->setSkin( names[ index ] );
|
2017-07-25 21:34:27 +02:00
|
|
|
|
|
|
|
QskSkinTransition transition;
|
|
|
|
|
|
|
|
transition.setSourceSkin( oldSkin );
|
|
|
|
transition.setTargetSkin( newSkin );
|
2017-07-26 17:54:25 +02:00
|
|
|
transition.setAnimation( 600 );
|
2017-07-25 21:34:27 +02:00
|
|
|
|
|
|
|
transition.process();
|
|
|
|
|
|
|
|
if ( oldSkin->parent() == nullptr )
|
|
|
|
delete oldSkin;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_SkinFactory.cpp"
|