qskinny/examples/qvgviewer/MainWindow.cpp
Uwe Rathmann e6f0088ae4 All box subcontrols are displayd with vertex lists instead of
textures
    now. Implementation is almost complete beside of the not yet done Qt
    antialiasing mode. Not all sort of linear gradients ( see
    QLinearGradients ) are implemented - needs 1-2 days more.
    The aspect flags for box primitives have been substantially changed
from
    too atomic to more strutured units.
    The skins are currently incomplete - will be fixed later.
2017-10-17 17:34:00 +02:00

129 lines
3.4 KiB
C++

/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "MainWindow.h"
#include <QskGraphic.h>
#include <QskGraphicLabel.h>
#include <QskGraphicIO.h>
#include <QskPushButton.h>
#include <QskLinearBox.h>
#include <QskColorFilter.h>
#include <QskAspect.h>
#include <QskTabView.h>
#include <QskSetup.h>
#include <QskSkin.h>
#include <QskAnimationHint.h>
#include <QskGradient.h>
#include <QskRgbValue.h>
#include <QDir>
#include <QVariant>
class GraphicLabel : public QskGraphicLabel
{
public:
enum Role
{
Normal,
Inverted
};
GraphicLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr ):
QskGraphicLabel( graphic, parent )
{
setAlignment( Qt::AlignCenter );
setAutoFillBackground( true );
setDarknessMode( false );
}
void setDarknessMode( bool on )
{
using namespace QskAspect;
const int oldRole = graphicRole();
QskGradient gradient;
if ( on )
{
gradient.setColor( qRgb( 40, 40, 40 ) );
setGraphicRole( Inverted );
}
else
{
gradient.setColor( QskRgbValue::Wheat );
setGraphicRole( Normal );
}
const int duration = 500;
const QskGradient oldGradient = background();
setBackground( gradient );
// finally setup a smooth transition manually
startTransition( Control | Color, duration,
QVariant::fromValue( oldGradient ), QVariant::fromValue( gradient ) );
startTransition( QskGraphicLabel::Graphic | GraphicRole,
duration, oldRole, graphicRole() );
}
};
MainWindow::MainWindow()
{
m_tabView = new QskTabView( Qt::Horizontal );
const QString resourceDir( ":/qvg" );
const QStringList icons = QDir( resourceDir ).entryList();
for ( auto icon : icons )
{
m_tabView->addTab( icon.replace( ".qvg", "" ),
new GraphicLabel( QskGraphicIO::read( resourceDir + "/" + icon ) ) );
}
auto invertButton = new QskPushButton( "Inverted" );
invertButton->setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
invertButton->setCheckable( true );
auto box = new QskLinearBox( Qt::Vertical );
box->setMargins( 5 );
box->addItem( invertButton, Qt::AlignRight );
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"