299 lines
8.6 KiB
C++
Raw Normal View History

2020-08-11 17:56:53 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2020-08-11 17:56:53 +02:00
*****************************************************************************/
2023-05-02 01:02:47 +02:00
#include "QskLinearBox.h"
2020-08-11 17:56:53 +02:00
#include "label/LabelPage.h"
#include "progressbar/ProgressBarPage.h"
2023-02-27 09:56:41 +01:00
#include "inputs/InputPage.h"
2022-04-01 14:54:31 +02:00
#include "button/ButtonPage.h"
#include "selector/SelectorPage.h"
2022-07-05 15:45:06 +02:00
#include "dialog/DialogPage.h"
2020-08-11 17:56:53 +02:00
#include <SkinnyShortcut.h>
#include <SkinnyShapeProvider.h>
2022-04-01 15:58:47 +02:00
#include <SkinnyNamespace.h>
2020-08-11 17:56:53 +02:00
2023-03-10 15:45:53 +01:00
#include <QskMainView.h>
2020-08-11 17:56:53 +02:00
#include <QskFocusIndicator.h>
#include <QskObjectCounter.h>
2023-05-02 01:02:47 +02:00
#include <QskDrawer.h>
2020-08-11 17:56:53 +02:00
#include <QskTabView.h>
2022-04-01 14:54:31 +02:00
#include <QskTextLabel.h>
#include <QskSwitchButton.h>
2022-04-01 15:58:47 +02:00
#include <QskPushButton.h>
2023-02-27 12:27:57 +01:00
#include <QskScrollArea.h>
2022-04-05 10:41:36 +02:00
#include <QskMenu.h>
2020-08-11 17:56:53 +02:00
#include <QskWindow.h>
2022-04-19 08:42:53 +02:00
#include <QskDialog.h>
2022-07-14 13:19:25 +02:00
#include <QskSkinManager.h>
#include <QskSkin.h>
#include <QskSkinTransition.h>
#include <QskAnimationHint.h>
2023-02-27 12:27:57 +01:00
#include <QskBoxBorderMetrics.h>
#include <QskBoxShapeMetrics.h>
#include <QskGraphicProvider.h>
#include <QskGraphicIO.h>
#include <QskGraphic.h>
2022-07-14 13:19:25 +02:00
#include <QskSetup.h>
2020-08-11 17:56:53 +02:00
#include <QGuiApplication>
2021-12-06 19:20:59 +01:00
namespace
{
class GraphicProvider : public QskGraphicProvider
{
protected:
const QskGraphic* loadGraphic( const QString& id ) const override
{
const QString path = QStringLiteral( ":gallery/icons/qvg/" )
+ id + QStringLiteral( ".qvg" );
const auto graphic = QskGraphicIO::read( path );
return graphic.isNull() ? nullptr : new QskGraphic( graphic );
}
};
2021-12-06 19:20:59 +01:00
class TabView : public QskTabView
{
public:
TabView( QQuickItem* parent = nullptr )
: QskTabView( parent )
{
setAutoFitTabs( true );
}
2022-04-01 14:54:31 +02:00
void setPagesEnabled( bool on )
2022-04-01 14:54:31 +02:00
{
for ( int i = 0; i < count(); i++ )
pageAt( i )->setEnabled( on );
2022-04-01 14:54:31 +02:00
}
2023-02-27 12:27:57 +01:00
void addPage( const QString& tabText, QQuickItem* page )
{
auto scrollArea = new QskScrollArea();
scrollArea->setMargins( 5 );
// hiding the viewport
scrollArea->setGradientHint( QskScrollView::Viewport, QskGradient() );
scrollArea->setBoxShapeHint( QskScrollView::Viewport, 0 );
scrollArea->setBoxBorderMetricsHint( QskScrollView::Viewport, 0 );
scrollArea->setItemResizable( true );
scrollArea->setScrolledItem( page );
addTab( tabText, scrollArea );
}
2022-04-01 14:54:31 +02:00
};
2022-04-05 10:41:36 +02:00
class MenuButton : public QskPushButton
{
public:
MenuButton( const QString& text, QQuickItem* parent = nullptr )
: QskPushButton( text, parent )
{
connect( this, &QskPushButton::pressed, this, &MenuButton::openMenu );
}
private:
void openMenu()
{
2022-04-05 11:38:23 +02:00
auto menu = new QskMenu( window()->contentItem() );
2022-04-05 10:41:36 +02:00
2022-07-14 13:19:25 +02:00
populateMenu( menu );
menu->setOrigin( geometry().bottomLeft() );
menu->open();
}
virtual void populateMenu( QskMenu* ) = 0;
};
class SkinButton final : public MenuButton
{
public:
SkinButton( const QString& text, QQuickItem* parent = nullptr )
: MenuButton( text, parent )
{
}
private:
void populateMenu( QskMenu* menu ) override
{
const auto names = qskSkinManager->skinNames();
for ( const auto& name : names )
menu->addOption( QUrl(), name );
if ( const auto index = names.indexOf( qskSetup->skinName() ) )
menu->setCurrentIndex( index );
connect( menu, &QskMenu::triggered, this, &SkinButton::changeSkin );
}
void changeSkin( int index )
{
const auto names = qskSkinManager->skinNames();
if ( index < 0 || index >= names.size() )
return;
if ( index == names.indexOf( qskSetup->skinName() ) )
return;
auto oldSkin = qskSetup->skin();
if ( oldSkin->parent() == qskSetup )
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
if ( auto newSkin = qskSetup->setSkin( names[ index ] ) )
{
QskSkinTransition transition;
transition.setSourceSkin( oldSkin );
transition.setTargetSkin( newSkin );
transition.setAnimation( 500 );
transition.process();
if ( oldSkin->parent() == nullptr )
delete oldSkin;
}
}
};
class FileButton final : public MenuButton
{
public:
FileButton( const QString& text, QQuickItem* parent = nullptr )
: MenuButton( text, parent )
{
}
private:
void populateMenu( QskMenu* menu ) override
{
2022-04-05 11:38:23 +02:00
menu->addOption( "image://shapes/Rectangle/White", "Print" );
menu->addOption( "image://shapes/Diamond/Yellow", "Save As" );
menu->addOption( "image://shapes/Ellipse/Red", "Setup" );
menu->addSeparator();
2022-05-30 07:49:58 +02:00
menu->addOption( "image://shapes/Hexagon/PapayaWhip", "Quit" );
// see https://github.com/uwerat/qskinny/issues/192
connect( menu, &QskMenu::triggered,
[]( int index ) { if ( index == 3 ) qApp->quit(); } );
2022-04-05 10:41:36 +02:00
}
};
2022-07-14 13:19:25 +02:00
2022-04-01 14:54:31 +02:00
class Header : public QskLinearBox
{
Q_OBJECT
public:
Header( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, parent )
{
2023-02-27 14:07:42 +01:00
setPaddingHint( QskBox::Panel, 5 );
2022-04-01 14:54:31 +02:00
initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Fixed );
setPanel( true );
2022-04-01 15:58:47 +02:00
2022-07-14 13:19:25 +02:00
new FileButton( "File", this );
new SkinButton( "Skin", this );
2022-04-05 10:41:36 +02:00
2022-04-01 14:54:31 +02:00
addStretch( 10 );
2022-04-01 15:58:47 +02:00
{
new QskTextLabel( "Enabled", this );
2022-04-01 14:54:31 +02:00
2022-04-01 15:58:47 +02:00
auto button = new QskSwitchButton( this );
button->setChecked( true );
2022-04-01 14:54:31 +02:00
2022-04-01 15:58:47 +02:00
connect( button, &QskSwitchButton::toggled,
this, &Header::enabledToggled );
}
2023-05-02 01:02:47 +02:00
{
QskDrawer* drawer = new QskDrawer( this->parentItem() );
drawer->setEdge( Qt::RightEdge );
auto o = new QskLinearBox( Qt::Vertical );
auto c = new QskLinearBox( Qt::Vertical, o );
new QskPushButton( "One", c );
new QskPushButton( "Two", c );
new QskPushButton( "Three", c );
c->setExtraSpacingAt( Qt::BottomEdge );
auto close = new QskPushButton( "Close", o );
connect( close, &QskPushButton::clicked,
drawer, &QskDrawer::close );
drawer->setContent( o );
auto burger = new QskPushButton( "", this );
burger->setEmphasis( QskPushButton::LowEmphasis );
connect( burger, &QskPushButton::clicked,
this, [drawer]() { drawer->open(); });
}
2022-04-01 14:54:31 +02:00
}
Q_SIGNALS:
void enabledToggled( bool );
};
2023-03-10 15:45:53 +01:00
class MainView : public QskMainView
2022-04-01 14:54:31 +02:00
{
public:
2023-03-10 15:45:53 +01:00
MainView( QQuickItem* parent = nullptr )
: QskMainView( parent )
2022-04-01 14:54:31 +02:00
{
auto header = new Header( this );
auto tabView = new TabView( this );
2023-02-27 12:27:57 +01:00
tabView->addPage( "Buttons", new ButtonPage() );
tabView->addPage( "Labels", new LabelPage() );
tabView->addPage( "Inputs", new InputPage() );
tabView->addPage( "Progress\nBars", new ProgressBarPage() );
tabView->addPage( "Selectors", new SelectorPage() );
tabView->addPage( "Dialogs", new DialogPage() );
2022-04-01 14:54:31 +02:00
connect( header, &Header::enabledToggled,
tabView, &TabView::setPagesEnabled );
2022-07-12 16:51:39 +02:00
setHeader( header );
2022-07-15 13:13:14 +02:00
setBody( tabView );
2022-04-01 14:54:31 +02:00
}
2021-12-06 19:20:59 +01:00
};
}
2020-08-11 17:56:53 +02:00
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
QskObjectCounter counter( true );
#endif
Qsk::addGraphicProvider( QString(), new GraphicProvider() );
2020-08-11 17:56:53 +02:00
Qsk::addGraphicProvider( "shapes", new SkinnyShapeProvider() );
2022-04-19 08:42:53 +02:00
// dialogs in faked windows -> QskSubWindow
QskDialog::instance()->setPolicy( QskDialog::EmbeddedBox );
2020-08-11 17:56:53 +02:00
QGuiApplication app( argc, argv );
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
2023-03-10 15:45:53 +01:00
auto mainView = new MainView();
2020-08-11 17:56:53 +02:00
QskWindow window;
2022-04-01 14:54:31 +02:00
window.addItem( mainView );
2020-08-11 17:56:53 +02:00
window.addItem( new QskFocusIndicator() );
2023-02-27 12:27:57 +01:00
window.resize( 800, 600 );
2020-08-11 17:56:53 +02:00
window.show();
return app.exec();
}
2022-04-01 14:54:31 +02:00
#include "main.moc"