diff --git a/examples/gallery/dialog/DialogPage.cpp b/examples/gallery/dialog/DialogPage.cpp index 46f750d5..9af09429 100644 --- a/examples/gallery/dialog/DialogPage.cpp +++ b/examples/gallery/dialog/DialogPage.cpp @@ -6,65 +6,87 @@ #include "DialogPage.h" #include -#include +#include #include #include +#include namespace { - class Box : public QskGridBox + class Button : public QskPushButton { + Q_OBJECT + public: - Box( QQuickItem* parent ) - : QskGridBox( parent ) + enum ButtonType { - auto* messageButton = new QskPushButton( "message", this ); + Message, + Information, + Warning, + Critical, - connect( messageButton, &QskPushButton::clicked, this, - []() { qskDialog->message( "message", "text", QskStandardSymbol::Ok ); } ); + Question, + Selection, - auto* informationButton = new QskPushButton( "information", this ); + TypeCount + }; + Q_ENUM( ButtonType ); - connect( informationButton, &QskPushButton::clicked, this, - []() { qskDialog->information( "information", "text" ); } ); + Button( ButtonType type, QQuickItem* parent = nullptr ) + : QskPushButton( parent ) + , m_type( type ) + { + setShape( 10 ); + initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Ignored ); - auto* warningButton = new QskPushButton( "warning", this ); + const int index = metaObject()->indexOfEnumerator( "ButtonType" ); + setText( metaObject()->enumerator( index ).key( m_type ) ); - connect( warningButton, &QskPushButton::clicked, this, - []() { qskDialog->warning( "warning", "text" ); } ); - - auto* criticalButton = new QskPushButton( "critical", this ); - - connect( criticalButton, &QskPushButton::clicked, this, - []() { qskDialog->critical( "critical", "text" ); } ); - - auto* questionButton = new QskPushButton( "question", this ); - - connect( questionButton, &QskPushButton::clicked, this, - []() { qskDialog->question( "question", "text" ); } ); - - auto* selectButton = new QskPushButton( "select", this ); - - connect( selectButton, &QskPushButton::clicked, this, - []() { qskDialog->select( "select", "text", { "yes", "no", "maybe" } ); } ); - - addItem( messageButton, 0, 0 ); - addItem( informationButton, 0, 1 ); - addItem( warningButton, 0, 2 ); - addItem( criticalButton, 1, 0 ); - addItem( questionButton, 1, 1 ); - addItem( selectButton, 1, 2 ); + connect( this, &QskPushButton::clicked, this, &Button::showDialog ); } + + private: + void showDialog() + { + switch( static_cast< int >( m_type ) ) + { + case Message: + qskDialog->message( text(), text(), QskStandardSymbol::Ok ); + break; + + case Information: + qskDialog->information( text(), text() ); + break; + + case Warning: + qskDialog->warning( text(), text() ); + break; + + case Critical: + qskDialog->critical( text(), text() ); + break; + + case Question: + qskDialog->question( text(), text() ); + break; + + case Selection: + qskDialog->select( text(), text(), { "yes", "no", "maybe" } ); + break; + } + } + + const ButtonType m_type; }; } DialogPage::DialogPage( QQuickItem* parent ) : Page( Qt::Horizontal, parent ) { - populate(); + auto box = new QskLinearBox( Qt::Horizontal, 2, this ); + + for ( int i = 0; i < Button::TypeCount; i++ ) + new Button( static_cast< Button::ButtonType >( i ), box ); } -void DialogPage::populate() -{ - new Box( this ); -} +#include "DialogPage.moc" diff --git a/examples/gallery/dialog/DialogPage.h b/examples/gallery/dialog/DialogPage.h index f41a2a37..596de2c6 100644 --- a/examples/gallery/dialog/DialogPage.h +++ b/examples/gallery/dialog/DialogPage.h @@ -11,7 +11,4 @@ class DialogPage : public Page { public: DialogPage( QQuickItem* = nullptr ); - - private: - void populate(); }; diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 552054f9..14ebfe7a 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,8 @@ #include #include #include +#include +#include #include #include @@ -48,6 +51,22 @@ namespace for ( int i = 0; i < count(); i++ ) itemAt( i )->setEnabled( on ); } + + 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 ); + } }; class MenuButton : public QskPushButton @@ -191,12 +210,12 @@ namespace auto header = new Header( this ); auto tabView = new TabView( this ); - tabView->addTab( "Buttons", new ButtonPage() ); - tabView->addTab( "Labels", new LabelPage() ); - tabView->addTab( "Inputs", new InputPage() ); - tabView->addTab( "Progress\nBars", new ProgressBarPage() ); - tabView->addTab( "Selectors", new SelectorPage() ); - tabView->addTab( "Dialogs", new DialogPage() ); + 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() ); connect( header, &Header::enabledToggled, tabView, &TabView::setTabsEnabled ); @@ -224,14 +243,11 @@ int main( int argc, char* argv[] ) auto mainView = new ApplicationView(); - QSize size( 800, 600 ); - size = size.expandedTo( mainView->sizeHint().toSize() ); - QskWindow window; window.addItem( mainView ); window.addItem( new QskFocusIndicator() ); - window.resize( size ); + window.resize( 800, 600 ); window.show(); return app.exec();