qskinny/examples/qvgviewer/MainWindow.cpp

111 lines
2.9 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
2024-01-17 14:31:45 +01:00
* QSkinny - Copyright (C) The authors
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>
#include <QskSkinManager.h>
2017-07-21 18:21:34 +02:00
#include <QskSkin.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 = 1000,
2017-07-21 18:21:34 +02:00
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()
{
auto label = new GraphicLabel( QskGraphicIO::read( QString( ":/qvg/Tux.qvg" ) ) );
2017-07-21 18:21:34 +02:00
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->setPanel( true );
box->setPadding( 5 );
box->addItem( invertButton );
box->addItem( label );
2017-07-21 18:21:34 +02:00
addItem( box );
connect( invertButton, &QskPushButton::toggled,
label, &GraphicLabel::setDarknessMode );
2017-07-21 18:21:34 +02:00
connect( qskSkinManager, &QskSkinManager::skinChanged,
2017-07-21 18:21:34 +02:00
this, &MainWindow::setGraphicRoles );
setGraphicRoles( qskSkinManager->skin() );
2017-07-21 18:21:34 +02:00
}
void MainWindow::setGraphicRoles( QskSkin* skin )
{
// substituting black
2017-07-21 18:21:34 +02:00
QskColorFilter colorFilter;
colorFilter.addColorSubstitution( QskRgb::Black, QskRgb::DarkKhaki );
2017-07-21 18:21:34 +02:00
skin->setGraphicFilter( GraphicLabel::Inverted, colorFilter );
}
#include "moc_MainWindow.cpp"