qskinny/examples/automotive/SkinFactory.cpp

122 lines
3.6 KiB
C++
Raw Normal View History

2017-07-25 21:34:27 +02:00
#include "SkinFactory.h"
#include "DefaultSkin.h"
#include "OtherSkin.h"
#include "SoundControl.h"
2017-07-25 21:34:27 +02:00
#include <QskSetup.h>
#include <QskSkinTransition.h>
#include <QskColorFilter.h>
#include <QskTextLabel.h>
#include <QskPushButton.h>
#include <QskSeparator.h>
#include <QskBoxBorderMetrics.h>
2017-07-25 21:34:27 +02:00
#include <squiek/QskSquiekSkin.h>
#include <material/QskMaterialSkin.h>
QStringList SkinFactory::skinNames() const
{
return { "DefaultSkin", "OtherSkin", "SquiekSkin", "MaterialSkin" };
2017-07-25 21:34:27 +02:00
}
QskSkin* SkinFactory::createSkin( const QString& skinName )
{
if ( skinName == "DefaultSkin" )
return new DefaultSkin( skinName );
if ( skinName == "OtherSkin" )
return new OtherSkin( skinName );
if ( skinName == "SquiekSkin" )
{
auto skin = new QskSquiekSkin();
const QColor themeColor( "FireBrick" );
QColor overlayColor( "SlateGray");
overlayColor.setAlpha( 200 );
skin->setGradient( SoundControl::Overlay, overlayColor );
QskColorFilter filter;
filter.addColorSubstitution( Qt::white, themeColor.rgb() );
skin->setGraphicFilter( SkinFactory::Indicator, filter );
filter.addColorSubstitution( Qt::white, QColor( "CornflowerBlue" ).rgb() );
skin->setGraphicFilter( SkinFactory::Vehicle, filter );
skin->setSkinHint( SoundControl::MarkerControl | QskAspect::GraphicRole, SkinFactory::Indicator );
skin->setSkinHint( SoundControl::Vehicle | QskAspect::GraphicRole, SkinFactory::Vehicle );
skin->setGradient( SoundControl::Marker, themeColor );
2017-10-18 20:00:06 +02:00
skin->setBoxBorderMetrics( SoundControl::Marker, 1 );
skin->setBoxShape( SoundControl::Marker, 6 );
skin->setColor( QskTextLabel::Text, "PeachPuff" );
skin->setGradient( QskPushButton::Text, themeColor );
return skin;
}
2017-07-25 21:34:27 +02:00
if ( skinName == "MaterialSkin" )
{
auto skin = new QskMaterialSkin();
const QColor themeColor( "Tan" );
QColor overlayColor = themeColor;
overlayColor.setAlpha( 200 );
skin->setGradient( SoundControl::Overlay, overlayColor );
QskColorFilter filter;
filter.addColorSubstitution( Qt::white, QColor( "SaddleBrown" ).rgb() );
skin->setGraphicFilter( SkinFactory::Indicator, filter );
skin->setSkinHint( SoundControl::MarkerControl | QskAspect::GraphicRole, SkinFactory::Indicator );
2017-10-18 20:00:06 +02:00
skin->setBoxBorderMetrics( SoundControl::Marker, 1 );
skin->setBoxShape( SoundControl::Marker, 8 );
skin->setGradient( SoundControl::Marker, QColor( "SaddleBrown" ) );
skin->setGradient( SoundControl::CrossHair, QColor( "Sienna" ) );
skin->setColor( QskTextLabel::Text, "SaddleBrown" );
skin->setGradient( QskSeparator::Panel, QColor( "Sienna" ) );
return skin;
}
2017-07-25 21:34:27 +02:00
return nullptr;
}
void SkinFactory::toggleScheme()
{
if ( qskSetup->skinName() == "DefaultSkin" )
static_cast< DefaultSkin* >( qskSetup->skin() )->toggleScheme();
}
void SkinFactory::rotateSkin()
{
const QStringList names = skinNames();
int index = names.indexOf( qskSetup->skinName() );
index = ( index + 1 ) % names.size();
QskSkin* oldSkin = qskSetup->skin();
if ( oldSkin->parent() == qskSetup )
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
QskSkin* newSkin = qskSetup->setSkin( names[ index ] );
QskSkinTransition transition;
transition.setSourceSkin( oldSkin );
transition.setTargetSkin( newSkin );
transition.setAnimation( 600 );
2017-07-25 21:34:27 +02:00
transition.process();
if ( oldSkin->parent() == nullptr )
delete oldSkin;
}
#include "moc_SkinFactory.cpp"