diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index cd9c7b8f..5a00d0a7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,7 +6,6 @@ add_subdirectory(desktop) add_subdirectory(gallery) add_subdirectory(layouts) -add_subdirectory(listbox) add_subdirectory(messagebox) add_subdirectory(mycontrols) add_subdirectory(qvgviewer) diff --git a/examples/gallery/CMakeLists.txt b/examples/gallery/CMakeLists.txt index 1608492a..e229a560 100644 --- a/examples/gallery/CMakeLists.txt +++ b/examples/gallery/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCES button/ButtonPage.h button/ButtonPage.cpp selector/SelectorPage.h selector/SelectorPage.cpp dialog/DialogPage.h dialog/DialogPage.cpp + listbox/ListBoxPage.h listbox/ListBoxPage.cpp Page.h Page.cpp main.cpp ) diff --git a/examples/gallery/listbox/ListBoxPage.cpp b/examples/gallery/listbox/ListBoxPage.cpp new file mode 100644 index 00000000..e0650d87 --- /dev/null +++ b/examples/gallery/listbox/ListBoxPage.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include "ListBoxPage.h" +#include +#include + +namespace +{ + class ListBox : public QskSimpleListBox + { + public: + ListBox( QQuickItem* parent = nullptr ) + : QskSimpleListBox( parent ) + { + setMargins( QMarginsF( 15, 10, 10, 10 ) ); + + // increasing the padding of each row: usually the job of the skin ! + setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) ); + + populate(); + + setSelectedRow( 5 ); + } + + private: + void populate() + { + const int count = 10000; + + const QString format( "Row %1: The quick brown fox jumps over the lazy dog" ); + + QStringList entries; + entries.reserve( count ); + + for ( int i = 0; i < count; i++ ) + { + entries += format.arg( i + 1 ); + } + + // we know, that the last entry is the longest one and + // can prevent the list box from having to find it out + // the expensive way. + + const qreal maxWidth = qskHorizontalAdvance( effectiveFont( Cell ), entries.last() ); + setColumnWidthHint( 0, maxWidth ); + + append( entries ); + } + }; +} + +ListBoxPage::ListBoxPage( QQuickItem* parent ) + : Page( Qt::Horizontal, parent ) +{ + setMargins( 5 ); + (void) new ListBox( this ); +} diff --git a/examples/gallery/listbox/ListBoxPage.h b/examples/gallery/listbox/ListBoxPage.h new file mode 100644 index 00000000..0fc44927 --- /dev/null +++ b/examples/gallery/listbox/ListBoxPage.h @@ -0,0 +1,14 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#pragma once + +#include "Page.h" + +class ListBoxPage : public Page +{ + public: + ListBoxPage( QQuickItem* = nullptr ); +}; diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 6d09297a..42e8b280 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -10,6 +10,7 @@ #include "button/ButtonPage.h" #include "selector/SelectorPage.h" #include "dialog/DialogPage.h" +#include "listbox/ListBoxPage.h" #include #include @@ -250,6 +251,7 @@ namespace tabView->addPage( "Progress\nBars", new ProgressBarPage() ); tabView->addPage( "Selectors", new SelectorPage() ); tabView->addPage( "Dialogs", new DialogPage() ); + tabView->addPage( "ListBox", new ListBoxPage() ); connect( header, &Header::enabledToggled, tabView, &TabView::setPagesEnabled ); diff --git a/examples/listbox/CMakeLists.txt b/examples/listbox/CMakeLists.txt deleted file mode 100644 index b0064b70..00000000 --- a/examples/listbox/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -############################################################################ -# QSkinny - Copyright (C) 2016 Uwe Rathmann -# SPDX-License-Identifier: BSD-3-Clause -############################################################################ - -qsk_add_example(listbox main.cpp) diff --git a/examples/listbox/main.cpp b/examples/listbox/main.cpp deleted file mode 100644 index 8f67688c..00000000 --- a/examples/listbox/main.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) 2016 Uwe Rathmann - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include - -class ListBox : public QskSimpleListBox -{ - public: - ListBox() - { - setMargins( QMarginsF( 15, 10, 10, 10 ) ); - setAlternatingRowColors( true ); - - // increasing the padding of each row: usually the job of the skin ! - setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) ); - - populate(); - - setSelectedRow( 5 ); - } - - private: - void populate() - { - const int count = 10000; - - const QString format( "Row %1: The quick brown fox jumps over the lazy dog" ); - - QStringList entries; - entries.reserve( count ); - - for ( int i = 0; i < count; i++ ) - { - entries += format.arg( i + 1 ); - } - - // we know, that the last entry is the longest one and - // can prevent the list box from having to find it out - // the expensive way. - - const qreal maxWidth = qskHorizontalAdvance( effectiveFont( Cell ), entries.last() ); - setColumnWidthHint( 0, maxWidth ); - - append( entries ); - } -}; - -int main( int argc, char* argv[] ) -{ -#ifdef ITEM_STATISTICS - QskObjectCounter counter( true ); -#endif - - QGuiApplication app( argc, argv ); - - SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts ); - - QskWindow window; - window.setColor( "Silver" ); - - window.addItem( new ListBox() ); - window.resize( 400, 600 ); - window.show(); - - return app.exec(); -}