push buttons added

This commit is contained in:
Uwe Rathmann 2022-04-01 14:54:31 +02:00
parent bd9718007d
commit 4cb3301045
5 changed files with 155 additions and 67 deletions

View File

@ -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 <QskSwitchButton.h>
#include <QskPushButton.h>
#include <QskSeparator.h>
#include <QskLinearBox.h>
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 );
}

View File

@ -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();

View File

@ -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

View File

@ -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 <SkinnyShortcut.h>
#include <SkinnyShapeProvider.h>
@ -14,6 +14,8 @@
#include <QskFocusIndicator.h>
#include <QskObjectCounter.h>
#include <QskTabView.h>
#include <QskTextLabel.h>
#include <QskSwitchButton.h>
#include <QskWindow.h>
#include <QGuiApplication>
@ -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"

View File

@ -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 <QskSwitchButton.h>
#include <QskLinearBox.h>
#include <QskTextLabel.h>
#include <QskSeparator.h>
#include <QskRgbValue.h>
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 );
}