From c8415e977ca72d84b85a92b0630abd0f4b72d75f Mon Sep 17 00:00:00 2001 From: Rick Vogel Date: Sat, 3 Feb 2024 21:54:14 +0100 Subject: [PATCH] inital commit of controls gallery --- playground/CMakeLists.txt | 1 + playground/controlsgallery/CMakeLists.txt | 8 + playground/controlsgallery/main.cpp | 213 ++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 playground/controlsgallery/CMakeLists.txt create mode 100644 playground/controlsgallery/main.cpp diff --git a/playground/CMakeLists.txt b/playground/CMakeLists.txt index 2e7b04ca..cd0d8e1a 100644 --- a/playground/CMakeLists.txt +++ b/playground/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(anchors) +add_subdirectory(controlsgallery) add_subdirectory(dials) add_subdirectory(dialogbuttons) add_subdirectory(gradients) diff --git a/playground/controlsgallery/CMakeLists.txt b/playground/controlsgallery/CMakeLists.txt new file mode 100644 index 00000000..e7811eb6 --- /dev/null +++ b/playground/controlsgallery/CMakeLists.txt @@ -0,0 +1,8 @@ +############################################################################ +# QSkinny - Copyright (C) The authors +# SPDX-License-Identifier: BSD-3-Clause +############################################################################ + +set(SOURCES main.cpp) +qsk_add_example(controlsgallery ${SOURCES}) + diff --git a/playground/controlsgallery/main.cpp b/playground/controlsgallery/main.cpp new file mode 100644 index 00000000..fa12bf6f --- /dev/null +++ b/playground/controlsgallery/main.cpp @@ -0,0 +1,213 @@ +/****************************************************************************** + * QSkinny - Copyright (C) The authors + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +// registered controls +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const std::map< QString, std::function< QQuickItem*( QQuickItem* ) > > allocators{ + { "QskCheckBox", []( QQuickItem* p ) { return new QskCheckBox( p ); } }, + { "QskComboBox", []( QQuickItem* p ) { return new QskComboBox( p ); } }, + { "QskGraphicLabel", + []( QQuickItem* p ) { return new QskGraphicLabel( p ); } }, // TODO add icon + { "QskProgressBar", + []( QQuickItem* p ) { + auto* const control = new QskProgressBar( p ); + control->setValueAsRatio( 0.5 ); + return control; + } }, + { "QskProgressRing", + []( QQuickItem* p ) { + auto* const control = new QskProgressRing( p ); + control->setValueAsRatio( 0.5 ); + return control; + } }, + { "QskPushButton", []( QQuickItem* p ) { return new QskPushButton( "Click", p ); } }, + { "QskRadioBox", + []( QQuickItem* p ) { + return new QskRadioBox( QStringList{ "A", "B", "C" }, p ); + } }, + { "QskSegmentedBar", + []( QQuickItem* p ) { + auto* const control = new QskSegmentedBar( p ); + control->setOptions( QStringList{ "A", "B", "C" } ); + return control; + } }, + { "QskSlider", []( QQuickItem* p ) { return new QskSlider( p ); } }, + { "QskSpinBox", []( QQuickItem* p ) { return new QskSpinBox( p ); } }, + { "QskSwitchButton", []( QQuickItem* p ) { return new QskSwitchButton( p ); } }, + { "QskTabBar", + []( QQuickItem* p ) { + auto* const control = new QskTabBar( p ); + control->addTab( "A" ); + control->addTab( "B" ); + control->addTab( "C" ); + return control; + } }, + { "QskTabView", + []( QQuickItem* p ) { + auto* const control = new QskTabView( p ); + control->addTab( "A", new QskTextLabel( "Content of A" ) ); + control->addTab( "B", new QskTextLabel( "Content of B" ) ); + control->addTab( "C", new QskTextLabel( "Content of C" ) ); + return control; + } }, + { "QskTextInput", + []( QQuickItem* p ) { + auto* const control = new QskTextInput( "Entered text", p ); + return control; + } }, + { "QskTextLabel", + []( QQuickItem* p ) { + auto* const control = new QskTextLabel( "Example Text", p ); + return control; + } } +}; + +class Window : public QskWindow +{ + public: + Window( QWindow* parent = nullptr ) + : QskWindow( parent ) + { + auto* const layout = new QskLinearBox( Qt::Horizontal, contentItem() ); + auto* const left = new QskLinearBox( Qt::Vertical, layout ); + auto* const right = new QskLinearBox( Qt::Vertical, layout ); + + auto* const controls = new QskSimpleListBox( left ); + auto* const skins = new QskSegmentedBar( right ); + auto* const control = m_layout = new QskLinearBox( right ); + auto* const schemes = new QskSegmentedBar( right ); + + schemes->setOptions( QStringList{ "Light", "Dark" } ); + + controls->setEntries( [] { + QStringList controlNames; + for ( const auto& control : allocators ) + { + controlNames << control.first; + } + return controlNames; + }() ); + controls->setMinimumWidth( 200 ); + + skins->setOptions( []() { + QStringList skinNames; + for ( const auto& skinName : qskSkinManager->skinNames() ) + { + skinNames << skinName; + } + return skinNames; + }() ); + + layout->setStretchFactor( 0, 1 ); + layout->setStretchFactor( 1, 4 ); + + right->setStretchFactor( 0, 0 ); + right->setStretchFactor( 1, 1 ); + right->setStretchFactor( 2, 0 ); + + connect( controls, &QskSimpleListBox::selectedEntryChanged, this, + [ this ]( const QString& control ) { setControl( control ); } ); + + connect( skins, &QskSegmentedBar::selectedIndexChanged, this, []( const int index ) { + qskSkinManager->setSkin( qskSkinManager->skinNames()[ index ] ); + } ); + + connect( schemes, &QskSegmentedBar::selectedIndexChanged, this, []( const int index ) { + qskSkinManager->skin()->setColorScheme( static_cast< QskSkin::ColorScheme >( index ) ); + } ); + } + + void setControl( const QString& className ) + { + m_layout->clear( true ); + const auto& allocator = allocators.at( className ); + auto* const control = allocator( m_layout ); + m_layout->addItem( control ); + } + + private: + QskLinearBox* m_layout = nullptr; +}; + +int main( int argc, char* argv[] ) +{ +#ifdef ITEM_STATISTICS + QskObjectCounter counter( true ); +#endif + + if ( true ) // environment variable, TODO ... + { + // dialogs in faked windows -> QskSubWindow + QskDialog::instance()->setPolicy( QskDialog::EmbeddedBox ); + } + + QGuiApplication app( argc, argv ); + + SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts ); + + QString controlName = argc > 1 ? argv[ 1 ] : "QskPushButton"; + + Window window; + window.resize( 800, 600 ); + window.setControl( controlName ); + window.show(); + + return app.exec(); +} + +// #include "main.moc"