118 lines
2.8 KiB
C++
Raw Normal View History

2017-07-23 16:40:24 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Theme.h"
2018-08-03 08:15:28 +02:00
#include <QskAspect.h>
#include <QskBoxBorderColors.h>
#include <QskFocusIndicator.h>
#include <QskListView.h>
2017-07-23 16:40:24 +02:00
#include <QskSetup.h>
#include <QskSkin.h>
#include <QskSkinTransition.h>
2020-12-26 12:57:08 +01:00
#include <QskSkinHintTable.h>
#include <QskSkinHintTableEditor.h>
2017-07-23 16:40:24 +02:00
namespace
{
2018-07-31 17:32:25 +02:00
class SkinTransition final : public QskSkinTransition
2017-07-23 16:40:24 +02:00
{
2018-08-03 08:15:28 +02:00
public:
SkinTransition( const QColor& accent )
: m_accent( accent )
2017-07-23 16:40:24 +02:00
{
}
2018-08-03 08:15:28 +02:00
protected:
2018-07-31 17:32:25 +02:00
void updateSkin( QskSkin*, QskSkin* newSkin ) override
2017-07-23 16:40:24 +02:00
{
2020-12-26 12:57:08 +01:00
newSkin->resetColors( m_accent );
/*
The current implementation of the skins is not that good
and we don't have support for customizing them by a minimal set
of attributes. So we do some manual extra work here
*/
QskSkinHintTableEditor ed( &newSkin->hintTable() );
2021-08-04 09:31:16 +02:00
2020-12-26 12:57:08 +01:00
ed.setColor( QskListView::CellSelected, m_accent.darker( 130 ) );
ed.setBoxBorderColors( QskFocusIndicator::Panel, m_accent.darker( 150 ) );
2017-07-23 16:40:24 +02:00
}
2018-08-03 08:15:28 +02:00
private:
2017-07-23 16:40:24 +02:00
const QColor m_accent;
};
}
2018-08-03 08:15:28 +02:00
Theme::Theme( QObject* parent )
: QObject( parent )
2020-12-26 12:57:08 +01:00
, m_accent( Qt::blue )
2017-07-23 16:40:24 +02:00
{
connect( qskSetup, &QskSetup::skinChanged,
2018-08-03 08:15:28 +02:00
this, [ this ]( QskSkin* ) { updateColors(); } );
2017-07-23 16:40:24 +02:00
connect( qskSetup, &QskSetup::skinChanged,
2018-08-03 08:15:28 +02:00
this, [ this ]( QskSkin* ) { Q_EMIT skinChanged(); } );
2017-07-23 16:40:24 +02:00
}
void Theme::setAccent( QColor color )
{
if ( m_accent != color )
{
m_accent = color;
updateColors();
Q_EMIT accentChanged();
}
}
QColor Theme::accent() const
{
return m_accent;
}
void Theme::setSkin( const QString& skinName )
{
if ( skinName == qskSetup->skinName() )
return;
2019-02-26 21:49:39 +01:00
auto oldSkin = qskSetup->skin();
2017-07-23 16:40:24 +02:00
if ( oldSkin->parent() == qskSetup )
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
2019-02-26 21:49:39 +01:00
auto newSkin = qskSetup->setSkin( skinName );
2017-07-23 16:40:24 +02:00
SkinTransition transition( m_accent );
transition.setSourceSkin( oldSkin );
transition.setTargetSkin( newSkin );
transition.setAnimation( 500 );
transition.process();
if ( oldSkin->parent() == nullptr )
delete oldSkin;
}
QString Theme::skin() const
{
return qskSetup->skinName();
}
void Theme::updateColors()
{
SkinTransition transition( m_accent );
transition.setMask( SkinTransition::Color );
transition.setSourceSkin( qskSetup->skin() );
transition.setTargetSkin( qskSetup->skin() );
transition.setAnimation( 500 );
transition.process();
}
#include "moc_Theme.cpp"