diff --git a/examples/gallery/button/ButtonPage.cpp b/examples/gallery/button/ButtonPage.cpp new file mode 100644 index 00000000..9a347c37 --- /dev/null +++ b/examples/gallery/button/ButtonPage.cpp @@ -0,0 +1,88 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * This file may be used under the terms of the 3-clause BSD License + *****************************************************************************/ + +#include "ButtonPage.h" + +#include +#include +#include +#include + +namespace +{ + class ButtonBox : public QskLinearBox + { + public: + ButtonBox( QQuickItem* parent = nullptr ) + : QskLinearBox( Qt::Horizontal, 4, parent ) + { + setSpacing( 20 ); + setExtraSpacingAt( Qt::BottomEdge ); + setDefaultAlignment( Qt::AlignCenter ); + + populate(); + } + + private: + void populate() + { + const char* texts[] = { "Press Me", "Check Me" }; + const char* graphics[] = { "diamond/khaki", "ellipse/sandybrown" }; + + for ( int i = 0; i < 6; i++ ) + { + const int index = i % 2; + + auto button = new QskPushButton( this ); + button->setCheckable( index != 0 ); + //button->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); + + if ( i > 1 ) + { + auto src = QStringLiteral( "image://shapes/" ) + graphics[ index ]; + button->setGraphicSource( src ); + } + + if ( i < 2 || i > 3 ) + { + button->setText( texts[ index ] ); + } + } + } + }; + + class SwitchButtonBox : public QskLinearBox + { + public: + SwitchButtonBox( QQuickItem* parent = nullptr ) + : QskLinearBox( Qt::Horizontal, parent ) + { + setSpacing( 20 ); + setExtraSpacingAt( Qt::LeftEdge | Qt::RightEdge | Qt::BottomEdge ); + + for ( auto orientation : { Qt::Vertical, Qt::Horizontal } ) + { + (void) new QskSwitchButton( orientation, this ); + + auto button = new QskSwitchButton( orientation, this ); + button->setInverted( true ); + } + } + }; +} + +ButtonPage::ButtonPage( QQuickItem* parent ) + : Page( Qt::Vertical, parent ) +{ + setSpacing( 40 ); + populate(); +} + +void ButtonPage::populate() +{ + new ButtonBox( this ); + new QskSeparator( Qt::Horizontal, this ); + new SwitchButtonBox( this ); +} diff --git a/examples/gallery/switchbutton/SwitchButtonPage.h b/examples/gallery/button/ButtonPage.h similarity index 80% rename from examples/gallery/switchbutton/SwitchButtonPage.h rename to examples/gallery/button/ButtonPage.h index 377092da..ad7cad86 100644 --- a/examples/gallery/switchbutton/SwitchButtonPage.h +++ b/examples/gallery/button/ButtonPage.h @@ -7,10 +7,10 @@ #include "Page.h" -class SwitchButtonPage : public Page +class ButtonPage : public Page { public: - SwitchButtonPage( QQuickItem* = nullptr ); + ButtonPage( QQuickItem* = nullptr ); private: void populate(); diff --git a/examples/gallery/gallery.pro b/examples/gallery/gallery.pro index 75cd1071..2c1eedb3 100644 --- a/examples/gallery/gallery.pro +++ b/examples/gallery/gallery.pro @@ -25,10 +25,10 @@ SOURCES += \ progressbar/ProgressBarPage.cpp \ HEADERS += \ - switchbutton/SwitchButtonPage.h + button/ButtonPage.h SOURCES += \ - switchbutton/SwitchButtonPage.cpp \ + button/ButtonPage.cpp \ HEADERS += \ Page.h diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 1fca95f2..6d4b79c3 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -6,7 +6,7 @@ #include "label/LabelPage.h" #include "progressbar/ProgressBarPage.h" #include "slider/SliderPage.h" -#include "switchbutton/SwitchButtonPage.h" +#include "button/ButtonPage.h" #include #include @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include @@ -30,6 +32,61 @@ namespace setTabPosition( Qsk::Left ); setAutoFitTabs( true ); } + + void setTabsEnabled( bool on ) + { + for ( int i = 0; i < count(); i++ ) + itemAt( i )->setEnabled( on ); + } + }; + + /* + Once QskApplicationView and friends are implemented we can replace + Header/ApplicationWindow with it. TODO ... + */ + class Header : public QskLinearBox + { + Q_OBJECT + + public: + Header( QQuickItem* parent = nullptr ) + : QskLinearBox( Qt::Horizontal, parent ) + { + initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Fixed ); + setMargins( 10 ); + + addStretch( 10 ); + + new QskTextLabel( "Enabled", this ); + + auto button = new QskSwitchButton( this ); + button->setChecked( true ); + + connect( button, &QskSwitchButton::toggled, + this, &Header::enabledToggled ); + } + + Q_SIGNALS: + void enabledToggled( bool ); + }; + + class ApplicationView : public QskLinearBox + { + public: + ApplicationView( QQuickItem* parent = nullptr ) + : QskLinearBox( Qt::Vertical, parent ) + { + auto header = new Header( this ); + + auto tabView = new TabView( this ); + tabView->addTab( "Labels", new LabelPage() ); + tabView->addTab( "Buttons", new ButtonPage() ); + tabView->addTab( "Sliders", new SliderPage() ); + tabView->addTab( "Progress\nBars", new ProgressBarPage() ); + + connect( header, &Header::enabledToggled, + tabView, &TabView::setTabsEnabled ); + } }; } @@ -45,18 +102,13 @@ int main( int argc, char* argv[] ) SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts ); - auto tabView = new TabView(); - - tabView->addTab( "Labels", new LabelPage() ); - tabView->addTab( "Sliders", new SliderPage() ); - tabView->addTab( "Progress\nBars", new ProgressBarPage() ); - tabView->addTab( "Switches", new SwitchButtonPage() ); + auto mainView = new ApplicationView(); QSize size( 800, 600 ); - size = size.expandedTo( tabView->sizeHint().toSize() ); + size = size.expandedTo( mainView->sizeHint().toSize() ); QskWindow window; - window.addItem( tabView ); + window.addItem( mainView ); window.addItem( new QskFocusIndicator() ); window.resize( size ); @@ -64,3 +116,5 @@ int main( int argc, char* argv[] ) return app.exec(); } + +#include "main.moc" diff --git a/examples/gallery/switchbutton/SwitchButtonPage.cpp b/examples/gallery/switchbutton/SwitchButtonPage.cpp deleted file mode 100644 index 1fab35b1..00000000 --- a/examples/gallery/switchbutton/SwitchButtonPage.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) 2016 Uwe Rathmann - * This file may be used under the terms of the 3-clause BSD License - *****************************************************************************/ - -#include "SwitchButtonPage.h" - -#include -#include -#include -#include - -#include - -SwitchButtonPage::SwitchButtonPage( QQuickItem* parent ) - : Page( Qt::Horizontal, parent ) -{ - setSpacing( 40 ); - populate(); -} - -void SwitchButtonPage::populate() -{ - auto hbox1 = new QskLinearBox(); - hbox1->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed ); - hbox1->setExtraSpacingAt( Qt::LeftEdge ); - - auto label = new QskTextLabel( "Disable the switches:", hbox1 ); - label->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed ); - - auto button0 = new QskSwitchButton( hbox1 ); - - auto hbox2 = new QskLinearBox( Qt::Horizontal ); - hbox2->setDefaultAlignment( Qt::AlignHCenter | Qt::AlignTop ); - hbox2->setMargins( 30 ); - - (void) new QskSwitchButton( Qt::Vertical, hbox2 ); - (void) new QskSwitchButton( Qt::Horizontal, hbox2 ); - - auto button3 = new QskSwitchButton( Qt::Vertical, hbox2 ); - button3->setInverted( true ); - - auto button4 = new QskSwitchButton( Qt::Horizontal, hbox2 ); - button4->setInverted( true ); - - auto vbox = new QskLinearBox( Qt::Vertical, this ); - vbox->addItem( hbox1 ); - vbox->addItem( new QskSeparator() ); - vbox->addItem( hbox2 ); - vbox->setExtraSpacingAt( Qt::BottomEdge ); - - QObject::connect( button0, &QskSwitchButton::checkedChanged, - hbox2, &QskQuickItem::setDisabled ); -}