colorswitch example adjusted
This commit is contained in:
parent
6dccfb1de5
commit
1d27ce667f
116
examples/colorswitch/Theme.cpp
Normal file
116
examples/colorswitch/Theme.cpp
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||||
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "Theme.h"
|
||||||
|
|
||||||
|
#include <QskSetup.h>
|
||||||
|
#include <QskSkin.h>
|
||||||
|
#include <QskSkinTransition.h>
|
||||||
|
#include <QskAspect.h>
|
||||||
|
#include <QskListView.h>
|
||||||
|
#include <QskFocusIndicator.h>
|
||||||
|
|
||||||
|
static void qskResetColors( QskSkin* skin, const QColor& accent )
|
||||||
|
{
|
||||||
|
skin->resetColors( 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
|
||||||
|
*/
|
||||||
|
skin->setColor( QskListView::CellSelected, accent.darker( 130 ) );
|
||||||
|
skin->setColor( QskFocusIndicator::Panel | QskAspect::Border, accent.darker( 150 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class SkinTransition : public QskSkinTransition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SkinTransition( const QColor& accent ):
|
||||||
|
m_accent( accent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void updateSkin( QskSkin*, QskSkin* newSkin ) override final
|
||||||
|
{
|
||||||
|
qskResetColors( newSkin, m_accent );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QColor m_accent;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Theme::Theme( QObject* parent ):
|
||||||
|
QObject( parent ),
|
||||||
|
m_accent( qskSetup->skin()->color( QskAspect::Color ) )
|
||||||
|
{
|
||||||
|
connect( qskSetup, &QskSetup::skinChanged,
|
||||||
|
[this]( QskSkin* ) { updateColors(); } );
|
||||||
|
|
||||||
|
connect( qskSetup, &QskSetup::skinChanged,
|
||||||
|
[this]( QskSkin* ) { Q_EMIT skinChanged(); } );
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
QskSkin* oldSkin = qskSetup->skin();
|
||||||
|
if ( oldSkin->parent() == qskSetup )
|
||||||
|
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
|
||||||
|
|
||||||
|
QskSkin* newSkin = qskSetup->setSkin( skinName );
|
||||||
|
|
||||||
|
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"
|
38
examples/colorswitch/Theme.h
Normal file
38
examples/colorswitch/Theme.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||||
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef THEME_H
|
||||||
|
#define THEME_H 1
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
class Theme : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( QColor accent READ accent WRITE setAccent NOTIFY accentChanged )
|
||||||
|
Q_PROPERTY( QString skin READ skin WRITE setSkin NOTIFY skinChanged )
|
||||||
|
|
||||||
|
public:
|
||||||
|
Theme( QObject* parent = nullptr );
|
||||||
|
|
||||||
|
void setAccent( QColor color );
|
||||||
|
QColor accent() const;
|
||||||
|
|
||||||
|
void setSkin( const QString& );
|
||||||
|
QString skin() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void accentChanged();
|
||||||
|
void skinChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateColors();
|
||||||
|
|
||||||
|
QColor m_accent;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -5,5 +5,9 @@ TARGET = colorswitch
|
|||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
colorswitch.qrc
|
colorswitch.qrc
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
Theme.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
Theme.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
@ -6,14 +6,14 @@ Main
|
|||||||
{
|
{
|
||||||
id: main
|
id: main
|
||||||
|
|
||||||
property var accentColors: [ "red", "lightgreen", "#66336699" ]
|
|
||||||
|
|
||||||
skin: listBox.entries[ listBox.selectedRow ]
|
|
||||||
inputPanel: embeddedInputPanel
|
inputPanel: embeddedInputPanel
|
||||||
|
|
||||||
|
property var accentColors: [ "red", "lightgreen", "#66336699" ]
|
||||||
|
|
||||||
Theme
|
Theme
|
||||||
{
|
{
|
||||||
accent: accentColors[ tabBar.currentIndex < 0 ? 0 : tabBar.currentIndex ]
|
accent: accentColors[ tabBar.currentIndex < 0 ? 0 : tabBar.currentIndex ]
|
||||||
|
skin: listBox.entries[ listBox.selectedRow ]
|
||||||
}
|
}
|
||||||
|
|
||||||
Window
|
Window
|
||||||
|
@ -3,92 +3,17 @@
|
|||||||
* This file may be used under the terms of the 3-clause BSD License
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "Theme.h"
|
||||||
|
|
||||||
#include <SkinnyFont.h>
|
#include <SkinnyFont.h>
|
||||||
#include <SkinnyShortcut.h>
|
#include <SkinnyShortcut.h>
|
||||||
|
|
||||||
#include <QskModule.h>
|
#include <QskModule.h>
|
||||||
#include <QskSetup.h>
|
|
||||||
#include <QskSkin.h>
|
|
||||||
#include <QskSkinTransition.h>
|
|
||||||
#include <QskAspect.h>
|
|
||||||
#include <QskObjectCounter.h>
|
#include <QskObjectCounter.h>
|
||||||
|
|
||||||
#include <QskFocusIndicator.h>
|
|
||||||
#include <QskListView.h>
|
|
||||||
#include <QskSlider.h>
|
|
||||||
|
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
||||||
class SkinTransition: public QskSkinTransition
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SkinTransition( const QColor& accent ):
|
|
||||||
m_accent( accent )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void updateSkin( QskSkin*, QskSkin* skin ) override final
|
|
||||||
{
|
|
||||||
skin->resetColors( m_accent );
|
|
||||||
skin->setColor( QskListView::CellSelected, m_accent.darker( 130 ) );
|
|
||||||
skin->setColor( QskFocusIndicator::Panel | QskAspect::Border, m_accent.darker( 150 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const QColor m_accent;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Theme: public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY( QColor accent READ accent WRITE setAccent NOTIFY accentChanged )
|
|
||||||
|
|
||||||
public:
|
|
||||||
Theme( QObject* parent = nullptr ):
|
|
||||||
QObject( parent ),
|
|
||||||
m_accent( qskSetup->skin()->color( QskAspect::Color ) )
|
|
||||||
{
|
|
||||||
connect( qskSetup, &QskSetup::skinChanged,
|
|
||||||
[this]( QskSkin* ) { updateColors(); } );
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAccent( QColor color )
|
|
||||||
{
|
|
||||||
if ( m_accent != color )
|
|
||||||
{
|
|
||||||
m_accent = color;
|
|
||||||
updateColors();
|
|
||||||
|
|
||||||
Q_EMIT accentChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor accent() const
|
|
||||||
{
|
|
||||||
return m_accent;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void accentChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void updateColors()
|
|
||||||
{
|
|
||||||
SkinTransition transition( m_accent );
|
|
||||||
|
|
||||||
transition.setMask( SkinTransition::Color );
|
|
||||||
transition.setSourceSkin( qskSetup->skin() );
|
|
||||||
transition.setTargetSkin( qskSetup->skin() );
|
|
||||||
transition.setAnimation( 500 );
|
|
||||||
|
|
||||||
transition.process();
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor m_accent;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
#ifdef ITEM_STATISTICS
|
#ifdef ITEM_STATISTICS
|
||||||
@ -110,5 +35,3 @@ int main( int argc, char* argv[] )
|
|||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "main.moc"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user