2020-08-11 17:56:53 +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
|
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"
|
2022-04-20 15:25:15 +02:00
|
|
|
#include "selector/SelectorPage.h"
|
2022-07-05 15:45:06 +02:00
|
|
|
#include "dialog/DialogPage.h"
|
2023-06-30 14:40:19 +02:00
|
|
|
#include "listbox/ListBoxPage.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-11-30 08:42:51 +01:00
|
|
|
#include "QskLinearBox.h"
|
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>
|
2024-01-24 17:36:31 +01:00
|
|
|
#include <QskPageIndicator.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>
|
2023-03-09 11:11:36 +01:00
|
|
|
#include <QskGraphicProvider.h>
|
|
|
|
#include <QskGraphicIO.h>
|
|
|
|
#include <QskGraphic.h>
|
2020-08-11 17:56:53 +02:00
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
|
2021-12-06 19:20:59 +01:00
|
|
|
namespace
|
|
|
|
{
|
2023-03-09 11:11:36 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-02 18:51:09 +02:00
|
|
|
class Drawer : public QskDrawer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Drawer( QQuickItem* parent = nullptr )
|
|
|
|
: QskDrawer( parent )
|
|
|
|
{
|
2023-10-17 12:14:42 +02:00
|
|
|
auto box = new QskLinearBox( Qt::Vertical, this );
|
|
|
|
|
2023-05-02 18:51:09 +02:00
|
|
|
box->setSection( QskAspect::Header );
|
|
|
|
box->setPanel( true );
|
|
|
|
box->setPaddingHint( QskBox::Panel, 20 );
|
|
|
|
|
|
|
|
new QskPushButton( "One", box );
|
|
|
|
new QskPushButton( "Two", box );
|
|
|
|
new QskPushButton( "Three", box );
|
|
|
|
|
|
|
|
box->addStretch( 1 );
|
|
|
|
|
|
|
|
auto btn = new QskPushButton( "Close", box );
|
|
|
|
connect( btn, &QskPushButton::clicked, this, &QskDrawer::close );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2023-03-14 09:34:52 +01:00
|
|
|
void setPagesEnabled( bool on )
|
2022-04-01 14:54:31 +02:00
|
|
|
{
|
|
|
|
for ( int i = 0; i < count(); i++ )
|
2023-03-14 09:34:52 +01:00
|
|
|
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 );
|
|
|
|
|
2023-07-21 12:59:50 +02:00
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
We need a mode, where the focus policy gets adjusted
|
|
|
|
when a scroll bar becomes visible. TODO ...
|
|
|
|
*/
|
|
|
|
scrollArea->setFocusPolicy( Qt::NoFocus );
|
|
|
|
#endif
|
|
|
|
|
2023-02-27 12:27:57 +01:00
|
|
|
// 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 );
|
|
|
|
|
2024-01-30 10:43:27 +01:00
|
|
|
if ( const auto index = names.indexOf( qskSkinManager->skinName() ) )
|
2022-07-14 13:19:25 +02:00
|
|
|
menu->setCurrentIndex( index );
|
|
|
|
|
|
|
|
connect( menu, &QskMenu::triggered, this, &SkinButton::changeSkin );
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeSkin( int index )
|
|
|
|
{
|
|
|
|
const auto names = qskSkinManager->skinNames();
|
|
|
|
|
2023-05-16 11:12:11 +02:00
|
|
|
if ( ( index >= 0 ) && ( index < names.size() )
|
2024-01-30 10:43:27 +01:00
|
|
|
&& ( index != names.indexOf( qskSkinManager->skinName() ) ) )
|
2022-07-14 13:19:25 +02:00
|
|
|
{
|
2023-05-16 11:12:11 +02:00
|
|
|
Skinny::setSkin( index, 500 );
|
2022-07-14 13:19:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2023-05-16 12:49:46 +02:00
|
|
|
[]( int index ) { if ( index == 4 ) 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:
|
2024-01-24 17:36:31 +01:00
|
|
|
Header( int tabCount, QQuickItem* parent = nullptr )
|
2022-04-01 14:54:31 +02:00
|
|
|
: 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 );
|
2022-07-12 15:10:09 +02:00
|
|
|
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
|
|
|
|
2024-01-24 17:36:31 +01:00
|
|
|
addStretch( 10 );
|
|
|
|
m_pageIndicator = new QskPageIndicator( tabCount, this );
|
|
|
|
m_pageIndicator->setCurrentIndex( 0 );
|
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
|
|
|
|
|
|
|
{
|
|
|
|
auto burger = new QskPushButton( "≡", this );
|
2023-05-16 12:49:46 +02:00
|
|
|
burger->setEmphasis( QskPushButton::LowEmphasis );
|
2023-05-02 18:51:09 +02:00
|
|
|
|
2023-05-02 01:02:47 +02:00
|
|
|
connect( burger, &QskPushButton::clicked,
|
2023-10-11 09:18:09 +02:00
|
|
|
this, &Header::drawerRequested );
|
2023-05-02 01:02:47 +02:00
|
|
|
}
|
2022-04-01 14:54:31 +02:00
|
|
|
}
|
|
|
|
|
2024-01-24 17:36:31 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
void setCurrentTab( int index )
|
|
|
|
{
|
|
|
|
m_pageIndicator->setCurrentIndex( index );
|
|
|
|
}
|
|
|
|
|
2022-04-01 14:54:31 +02:00
|
|
|
Q_SIGNALS:
|
|
|
|
void enabledToggled( bool );
|
2023-10-11 09:18:09 +02:00
|
|
|
void drawerRequested();
|
2024-01-24 17:36:31 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QskPageIndicator* m_pageIndicator;
|
2022-04-01 14:54:31 +02:00
|
|
|
};
|
|
|
|
|
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 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() );
|
2024-01-24 17:36:31 +01:00
|
|
|
tabView->addPage( "Indicators", new ProgressBarPage() );
|
2023-02-27 12:27:57 +01:00
|
|
|
tabView->addPage( "Selectors", new SelectorPage() );
|
|
|
|
tabView->addPage( "Dialogs", new DialogPage() );
|
2023-06-30 14:40:19 +02:00
|
|
|
tabView->addPage( "ListBox", new ListBoxPage() );
|
2022-04-01 14:54:31 +02:00
|
|
|
|
2024-01-24 17:36:31 +01:00
|
|
|
auto header = new Header( tabView->count(), this );
|
|
|
|
|
2022-04-01 14:54:31 +02:00
|
|
|
connect( header, &Header::enabledToggled,
|
2023-03-14 09:34:52 +01:00
|
|
|
tabView, &TabView::setPagesEnabled );
|
2022-07-12 16:51:39 +02:00
|
|
|
|
2024-01-24 17:36:31 +01:00
|
|
|
connect( tabView, &TabView::currentIndexChanged,
|
|
|
|
header, &Header::setCurrentTab );
|
|
|
|
|
2023-10-17 14:36:44 +02:00
|
|
|
auto drawer = new Drawer( tabView );
|
2023-10-11 09:18:09 +02:00
|
|
|
drawer->setEdge( Qt::RightEdge );
|
|
|
|
|
|
|
|
connect( header, &Header::drawerRequested,
|
2023-10-17 14:36:44 +02:00
|
|
|
drawer, &QskPopup::toggle );
|
2023-10-11 09:18:09 +02:00
|
|
|
|
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
|
|
|
|
|
2023-03-09 11:11:36 +01:00
|
|
|
Qsk::addGraphicProvider( QString(), new GraphicProvider() );
|
2020-08-11 17:56:53 +02:00
|
|
|
Qsk::addGraphicProvider( "shapes", new SkinnyShapeProvider() );
|
|
|
|
|
2023-07-03 16:53:12 +02:00
|
|
|
if ( true ) // environment variable, TODO ...
|
|
|
|
{
|
|
|
|
// dialogs in faked windows -> QskSubWindow
|
|
|
|
QskDialog::instance()->setPolicy( QskDialog::EmbeddedBox );
|
|
|
|
}
|
2022-04-19 08:42:53 +02:00
|
|
|
|
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 );
|
2023-12-02 12:48:20 +01:00
|
|
|
window.addItem( new QskFocusIndicator() );
|
2020-08-11 17:56:53 +02:00
|
|
|
|
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"
|