qskinny/examples/qvgviewer/MainWindow.cpp

132 lines
3.5 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 18:21:34 +02:00
*****************************************************************************/
#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 )
{
const int oldRole = graphicRole();
2017-07-21 18:21:34 +02:00
QskGradient gradient;
2017-07-21 18:21:34 +02:00
if ( on )
{
2022-10-21 16:45:58 +02:00
gradient = QskGradient( qRgb( 40, 40, 40 ) );
setGraphicRole( Inverted );
2017-07-21 18:21:34 +02:00
}
else
{
2022-10-21 16:45:58 +02:00
gradient = QskGradient( QskRgb::Wheat );
setGraphicRole( Normal );
2017-07-21 18:21:34 +02:00
}
const int duration = 500;
2022-11-18 12:12:05 +01:00
const auto oldGradient = gradientHint( Panel );
2021-12-06 19:12:27 +01:00
setGradientHint( Panel, gradient );
// finally setup a smooth transition manually
2022-11-18 12:12:05 +01:00
startTransition( Panel | QskAspect::Color, duration,
QVariant::fromValue( oldGradient ), QVariant::fromValue( gradient ) );
2017-07-21 18:21:34 +02:00
2022-11-18 12:12:05 +01:00
startTransition( Graphic | QskAspect::GraphicRole,
duration, oldRole, graphicRole() );
2017-07-21 18:21:34 +02:00
}
};
MainWindow::MainWindow()
{
m_tabView = new QskTabView();
m_tabView->setTabBarEdge( Qt::LeftEdge );
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
{
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 );
invertButton->setLayoutAlignmentHint( Qt::AlignRight );
2017-07-21 18:21:34 +02:00
auto box = new QskLinearBox( Qt::Vertical );
box->setMargins( 5 );
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->pageAt( i ) );
2017-07-21 18:21:34 +02:00
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"