2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskAnimationHint.h>
|
|
|
|
#include <QskAspect.h>
|
|
|
|
#include <QskColorFilter.h>
|
|
|
|
#include <QskGradient.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QskGraphic.h>
|
|
|
|
#include <QskGraphicIO.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskGraphicLabel.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QskLinearBox.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskPushButton.h>
|
|
|
|
#include <QskRgbValue.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QskSetup.h>
|
|
|
|
#include <QskSkin.h>
|
2018-08-03 08:15:28 +02:00
|
|
|
#include <QskTabView.h>
|
2021-12-06 19:12:27 +01:00
|
|
|
#include <QskBoxShapeMetrics.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
class GraphicLabel : public QskGraphicLabel
|
|
|
|
{
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
enum Role
|
|
|
|
{
|
|
|
|
Normal,
|
|
|
|
Inverted
|
|
|
|
};
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
GraphicLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr )
|
|
|
|
: QskGraphicLabel( graphic, parent )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2021-12-06 19:12:27 +01:00
|
|
|
setMargins( 10 );
|
|
|
|
setPanel( true );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2021-12-06 19:12:27 +01:00
|
|
|
setBoxShapeHint( Panel, 8 );
|
|
|
|
setAlignment( Qt::AlignCenter );
|
2017-07-21 18:21:34 +02:00
|
|
|
setDarknessMode( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDarknessMode( bool on )
|
|
|
|
{
|
2017-08-22 20:15:11 +02:00
|
|
|
const int oldRole = graphicRole();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
QskGradient gradient;
|
2017-07-21 18:21:34 +02:00
|
|
|
if ( on )
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
gradient.setColor( qRgb( 40, 40, 40 ) );
|
2017-08-22 20:15:11 +02:00
|
|
|
setGraphicRole( Inverted );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-15 13:29:17 +02:00
|
|
|
gradient.setColor( QskRgb::Wheat );
|
2017-08-22 20:15:11 +02:00
|
|
|
setGraphicRole( Normal );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const int duration = 500;
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
const QskGradient oldGradient = background();
|
2021-12-06 19:12:27 +01:00
|
|
|
setGradientHint( Panel, gradient );
|
2017-10-17 17:34:00 +02:00
|
|
|
|
|
|
|
// finally setup a smooth transition manually
|
2020-12-15 07:21:12 +01:00
|
|
|
startTransition( QskAspect::Control | QskAspect::Color, duration,
|
2017-10-17 17:34:00 +02:00
|
|
|
QVariant::fromValue( oldGradient ), QVariant::fromValue( gradient ) );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
startTransition( QskGraphicLabel::Graphic | QskAspect::GraphicRole,
|
2017-10-17 17:34:00 +02:00
|
|
|
duration, oldRole, graphicRole() );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MainWindow::MainWindow()
|
|
|
|
{
|
2019-04-17 16:33:17 +02:00
|
|
|
m_tabView = new QskTabView( Qsk::Left );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
const QString resourceDir( ":/qvg" );
|
|
|
|
const QStringList icons = QDir( resourceDir ).entryList();
|
|
|
|
|
2018-08-03 11:11:42 +02:00
|
|
|
for ( const auto& icon : icons )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2017-12-07 09:03:29 +01:00
|
|
|
auto title = icon;
|
|
|
|
m_tabView->addTab( title.replace( ".qvg", "" ),
|
2017-07-21 18:21:34 +02:00
|
|
|
new GraphicLabel( QskGraphicIO::read( resourceDir + "/" + icon ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto invertButton = new QskPushButton( "Inverted" );
|
|
|
|
invertButton->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
|
|
|
|
invertButton->setCheckable( true );
|
2019-09-05 10:46:42 +02:00
|
|
|
invertButton->setLayoutAlignmentHint( Qt::AlignRight );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
auto box = new QskLinearBox( Qt::Vertical );
|
|
|
|
box->setMargins( 5 );
|
2019-09-05 10:46:42 +02:00
|
|
|
box->addItem( invertButton );
|
2017-07-21 18:21:34 +02:00
|
|
|
box->addItem( m_tabView );
|
|
|
|
|
|
|
|
addItem( box );
|
|
|
|
|
|
|
|
connect( invertButton, &QskPushButton::toggled,
|
|
|
|
this, &MainWindow::setDarknessMode );
|
|
|
|
|
|
|
|
connect( qskSetup, &QskSetup::skinChanged,
|
|
|
|
this, &MainWindow::setGraphicRoles );
|
|
|
|
|
|
|
|
setGraphicRoles( qskSetup->skin() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setDarknessMode( bool on )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < m_tabView->count(); i++ )
|
|
|
|
{
|
|
|
|
auto label = static_cast< GraphicLabel* >( m_tabView->itemAt( i ) );
|
|
|
|
label->setDarknessMode( on );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setGraphicRoles( QskSkin* skin )
|
|
|
|
{
|
|
|
|
// substituting black and white
|
|
|
|
QskColorFilter colorFilter;
|
|
|
|
colorFilter.addColorSubstitution( qRgb( 0, 0, 0 ), qRgb( 189, 183, 107 ) );
|
|
|
|
colorFilter.addColorSubstitution( qRgb( 255, 255, 255 ), qRgb( 50, 50, 50 ) );
|
|
|
|
|
|
|
|
skin->setGraphicFilter( GraphicLabel::Inverted, colorFilter );
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_MainWindow.cpp"
|