From 82a10afa0c413f8fc010fbc2626523663c78f2ab Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Thu, 27 Apr 2023 14:34:31 +0200 Subject: [PATCH 1/5] make builds parallel for msvc --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e45367a..6e3db68c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,11 @@ project(QSkinny HOMEPAGE_URL "https://github.com/uwerat/qskinny" VERSION 0.8.0) +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + message(STATUS "Added parallel build arguments to CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") +endif() + qsk_setup_options() include(GNUInstallDirs) From 835259c1a9711f0b9c77153ab4ccbf3eb9270049 Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Fri, 28 Apr 2023 10:47:36 +0200 Subject: [PATCH 2/5] integrate qsktreeview --- examples/listbox/CMakeLists.txt | 4 +- examples/listbox/ListBox.cpp | 44 ++++++++ examples/listbox/ListBox.h | 17 +++ examples/listbox/TreeBox.cpp | 74 ++++++++++++ examples/listbox/TreeBox.h | 25 ++++ examples/listbox/main.cpp | 57 ++-------- skins/material3/QskMaterial3Skin.cpp | 18 ++- skins/squiek/QskSquiekSkin.cpp | 17 +++ src/CMakeLists.txt | 4 + src/controls/QskListView.cpp | 28 +++++ src/controls/QskListView.h | 5 + src/controls/QskListViewSkinlet.cpp | 163 +++++++++++++++------------ src/controls/QskListViewSkinlet.h | 1 + src/controls/QskTreeView.cpp | 11 ++ src/controls/QskTreeView.h | 13 +++ src/controls/QskTreeViewSkinlet.cpp | 13 +++ src/controls/QskTreeViewSkinlet.h | 21 ++++ 17 files changed, 398 insertions(+), 117 deletions(-) create mode 100644 examples/listbox/ListBox.cpp create mode 100644 examples/listbox/ListBox.h create mode 100644 examples/listbox/TreeBox.cpp create mode 100644 examples/listbox/TreeBox.h create mode 100644 src/controls/QskTreeView.cpp create mode 100644 src/controls/QskTreeView.h create mode 100644 src/controls/QskTreeViewSkinlet.cpp create mode 100644 src/controls/QskTreeViewSkinlet.h diff --git a/examples/listbox/CMakeLists.txt b/examples/listbox/CMakeLists.txt index b0064b70..46fabee1 100644 --- a/examples/listbox/CMakeLists.txt +++ b/examples/listbox/CMakeLists.txt @@ -3,4 +3,6 @@ # SPDX-License-Identifier: BSD-3-Clause ############################################################################ -qsk_add_example(listbox main.cpp) +qsk_add_example(listbox main.cpp + ListBox.h ListBox.cpp + TreeBox.h TreeBox.cpp) diff --git a/examples/listbox/ListBox.cpp b/examples/listbox/ListBox.cpp new file mode 100644 index 00000000..21725147 --- /dev/null +++ b/examples/listbox/ListBox.cpp @@ -0,0 +1,44 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include "ListBox.h" +#include + +ListBox::ListBox( QQuickItem* parent ) + : Inherited( parent ) +{ + setAlternatingRowColors( true ); + + // increasing the padding of each row: usually the job of the skin ! + setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) ); + + populate(); + + setSelectedRow( 5 ); +} + +void ListBox::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 ); +} diff --git a/examples/listbox/ListBox.h b/examples/listbox/ListBox.h new file mode 100644 index 00000000..06623e74 --- /dev/null +++ b/examples/listbox/ListBox.h @@ -0,0 +1,17 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include + +class ListBox : public QskSimpleListBox +{ + using Inherited = QskSimpleListBox; + + public: + explicit ListBox( QQuickItem* parent = nullptr ); + + private: + void populate(); +}; \ No newline at end of file diff --git a/examples/listbox/TreeBox.cpp b/examples/listbox/TreeBox.cpp new file mode 100644 index 00000000..a55ca1ad --- /dev/null +++ b/examples/listbox/TreeBox.cpp @@ -0,0 +1,74 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include "TreeBox.h" + +QSK_SUBCONTROL( TreeBox, FirstRow ) +QSK_SUBCONTROL( TreeBox, SecondRow ) + +TreeBox::TreeBox( QQuickItem* const parent ) + : Inherited( parent ) +{ + setAlternatingRowColors( true ); + setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) ); + + setAlternatingRowColors( true ); + setColor( FirstRow, Qt::white ); + setColor( SecondRow, color(Panel) ); + updateScrollableSize(); +}; + +QskAspect::Subcontrol TreeBox::rowSubControl( int row ) const noexcept +{ + if ( alternatingRowColors() ) + { + if ( row == selectedRow() ) + { + return Cell; + } + return row % 2 == 0 ? Cell : QskAspect::NoSubcontrol; + } + return QskAspect::NoSubcontrol; +} + +int TreeBox::rowCount() const +{ + return 100000; +} + +int TreeBox::columnCount() const +{ + return 2; +} + +qreal TreeBox::columnWidth( int col ) const +{ + return col == 0 ? 100: 350; +} + +qreal TreeBox::rowHeight() const +{ + const auto hint = strutSizeHint( Cell ); + const auto padding = paddingHint( Cell ); + + qreal h = effectiveFontHeight( Text ); + h += padding.top() + padding.bottom(); + + return qMax( h, hint.height() ); +} + +Q_INVOKABLE QVariant TreeBox::valueAt( int row, int col ) const +{ + if ( col == 0 ) + { + return QString::number( row ); + } + return QStringLiteral( "The quick brown fox jumps over the lazy dog" ); +} + +qreal TreeBox::rowOffset( int row ) const +{ + return ( row % 4 ) * 10; +} diff --git a/examples/listbox/TreeBox.h b/examples/listbox/TreeBox.h new file mode 100644 index 00000000..d0fe93a8 --- /dev/null +++ b/examples/listbox/TreeBox.h @@ -0,0 +1,25 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#pragma once + +#include + +class TreeBox final : public QskTreeView +{ + using Inherited = QskTreeView; + + public: + QSK_SUBCONTROLS( FirstRow, SecondRow ) + + explicit TreeBox( QQuickItem* parent = nullptr ); + QskAspect::Subcontrol rowSubControl( int row ) const noexcept override; + int rowCount() const override; + int columnCount() const override; + qreal columnWidth( int col ) const override; + qreal rowHeight() const override; + Q_INVOKABLE QVariant valueAt( int row, int col ) const override; + qreal rowOffset( int row ) const override; +}; diff --git a/examples/listbox/main.cpp b/examples/listbox/main.cpp index 8f67688c..1b5952e6 100644 --- a/examples/listbox/main.cpp +++ b/examples/listbox/main.cpp @@ -5,56 +5,16 @@ #include -#include +#ifdef ITEM_STATISTICS #include -#include +#endif #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 ); - } -}; +#include "ListBox.h" +#include "TreeBox.h" int main( int argc, char* argv[] ) { @@ -69,7 +29,12 @@ int main( int argc, char* argv[] ) QskWindow window; window.setColor( "Silver" ); - window.addItem( new ListBox() ); + auto* const layout = new QskLinearBox(Qt::Horizontal); + layout->setSpacing(8); + (void) new ListBox(layout); + (void) new TreeBox(layout); + + window.addItem( layout ); window.resize( 400, 600 ); window.show(); diff --git a/skins/material3/QskMaterial3Skin.cpp b/skins/material3/QskMaterial3Skin.cpp index 431f3dd3..24e65a4d 100644 --- a/skins/material3/QskMaterial3Skin.cpp +++ b/skins/material3/QskMaterial3Skin.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,7 @@ namespace void setupInputPanel(); void setupVirtualKeyboard(); void setupListView(); + void setupTreeView(); void setupMenu(); void setupPageIndicator(); void setupPopup(); @@ -154,6 +156,7 @@ void Editor::setup() setupInputPanel(); setupVirtualKeyboard(); setupListView(); + setupTreeView(); setupMenu(); setupPageIndicator(); setupPopup(); @@ -1160,7 +1163,20 @@ void Editor::setupListView() using Q = QskListView; setPadding( Q::Cell, { 16_dp, 12_dp, 16_dp, 12_dp } ); - setBoxBorderMetrics( Q::Cell, { 0, 0, 0, 1_dp } ); + setBoxBorderMetrics( Q::Cell, { 0, 1_dp, 0, 1_dp } ); + setBoxBorderColors( Q::Cell, m_pal.outline ); + setColor( Q::Cell, m_pal.surface ); + setColor( Q::Cell | Q::Selected, m_pal.primary12 ); + + setColor( Q::Text, m_pal.onSurfaceVariant ); +} + +void Editor::setupTreeView() +{ + using Q = QskTreeView; + + setPadding( Q::Cell, { 16_dp, 12_dp, 16_dp, 12_dp } ); + setBoxBorderMetrics( Q::Cell, { 0, 1_dp, 0, 1_dp } ); setBoxBorderColors( Q::Cell, m_pal.outline ); setColor( Q::Cell, m_pal.surface ); setColor( Q::Cell | Q::Selected, m_pal.primary12 ); diff --git a/skins/squiek/QskSquiekSkin.cpp b/skins/squiek/QskSquiekSkin.cpp index 9e8e137a..f22534b7 100644 --- a/skins/squiek/QskSquiekSkin.cpp +++ b/skins/squiek/QskSquiekSkin.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -156,6 +157,7 @@ namespace void setupInputPredictionBar(); void setupVirtualKeyboard(); void setupListView(); + void setupTreeView(); void setupMenu(); void setupPageIndicator(); void setupPopup(); @@ -280,6 +282,7 @@ void Editor::setup() setupInputPredictionBar(); setupVirtualKeyboard(); setupListView(); + setupTreeView(); setupMenu(); setupPageIndicator(); setupPopup(); @@ -1043,6 +1046,20 @@ void Editor::setupListView() setColor( Q::Text | Q::Selected, m_pal.highlightedText ); } +void Editor::setupTreeView() +{ + using Q = QskTreeView; + + // padding for each cell + setPadding( Q::Cell, QskMargins( 4, 8 ) ); + + setColor( Q::Text, m_pal.themeForeground ); + setColor( Q::Cell, m_pal.contrasted ); + + setColor( Q::Cell | Q::Selected, m_pal.highlighted ); + setColor( Q::Text | Q::Selected, m_pal.highlightedText ); +} + void Editor::setupSubWindow() { using A = QskAspect; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f93b7b48..539142cf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -181,6 +181,8 @@ list(APPEND HEADERS controls/QskInputGrabber.h controls/QskListView.h controls/QskListViewSkinlet.h + controls/QskTreeView.h + controls/QskTreeViewSkinlet.h controls/QskMenu.h controls/QskMenuSkinlet.h controls/QskObjectTree.h @@ -278,6 +280,8 @@ list(APPEND SOURCES controls/QskInputGrabber.cpp controls/QskListView.cpp controls/QskListViewSkinlet.cpp + controls/QskTreeView.cpp + controls/QskTreeViewSkinlet.cpp controls/QskMenuSkinlet.cpp controls/QskMenu.cpp controls/QskObjectTree.cpp diff --git a/src/controls/QskListView.cpp b/src/controls/QskListView.cpp index 0d6a0723..046b7586 100644 --- a/src/controls/QskListView.cpp +++ b/src/controls/QskListView.cpp @@ -151,6 +151,29 @@ QskColorFilter QskListView::graphicFilterAt( int row, int col ) const return QskColorFilter(); } +QskAspect::Subcontrol QskListView::rowSubControl( int row ) const noexcept +{ + if ( alternatingRowColors() ) + { + if ( row == selectedRow() ) + { + return Cell; + } + return row % 2 == 0 ? Cell : QskAspect::NoSubcontrol; + } + return QskAspect::NoSubcontrol; +} + +QskAspect::Subcontrol QskListView::cellSubControl( int row, int col ) const noexcept +{ + return Cell; +} + +QskAspect::Subcontrol QskListView::textSubControl( int row, int col ) const noexcept +{ + return Text; +} + void QskListView::keyPressEvent( QKeyEvent* event ) { if ( m_data->selectionMode == NoSelection ) @@ -374,4 +397,9 @@ void QskListView::componentComplete() } } +qreal QskListView::rowOffset( int row ) const +{ + return 0.0; +} + #include "moc_QskListView.cpp" diff --git a/src/controls/QskListView.h b/src/controls/QskListView.h index 6f9f01b7..1a477c63 100644 --- a/src/controls/QskListView.h +++ b/src/controls/QskListView.h @@ -64,6 +64,7 @@ class QSK_EXPORT QskListView : public QskScrollView virtual qreal columnWidth( int col ) const = 0; virtual qreal rowHeight() const = 0; + virtual qreal rowOffset( int row ) const; Q_INVOKABLE virtual QVariant valueAt( int row, int col ) const = 0; @@ -71,6 +72,10 @@ class QSK_EXPORT QskListView : public QskScrollView virtual QskColorFilter graphicFilterAt( int row, int col ) const; #endif + virtual QskAspect::Subcontrol rowSubControl( int row ) const noexcept; + virtual QskAspect::Subcontrol cellSubControl( int row, int col ) const noexcept; + virtual QskAspect::Subcontrol textSubControl( int row, int col ) const noexcept; + public Q_SLOTS: void setSelectedRow( int row ); diff --git a/src/controls/QskListViewSkinlet.cpp b/src/controls/QskListViewSkinlet.cpp index adcae1b7..a7367bea 100644 --- a/src/controls/QskListViewSkinlet.cpp +++ b/src/controls/QskListViewSkinlet.cpp @@ -110,6 +110,51 @@ QSGNode* QskListViewSkinlet::updateContentsNode( return listViewNode; } +void QskListViewSkinlet::updateBackgroundNode( const QskListView* listView, QSGNode* rowNode, const QRectF& boxRect, const int row ) const +{ + const auto selectedRow = listView->selectedRow(); + const auto subControl = listView->rowSubControl( row ); + + // current row is a selected row + if ( row == selectedRow ) + { + auto* boxNode = rowNode->firstChild(); + auto prepend = boxNode == nullptr; + + QskSkinStateChanger stateChanger( listView ); + stateChanger.setStates( listView->skinStates() | QskListView::Selected ); + boxNode = updateBoxNode( listView, boxNode, boxRect, subControl ); + + if ( boxNode && prepend ) + { + Q_ASSERT(boxNode); + rowNode->prependChildNode( boxNode ); + } + } + // current row should be styled + else if ( subControl != QskAspect::NoSubcontrol) + { + auto* boxNode = rowNode->firstChild(); + auto prepend = boxNode == nullptr; + + const auto color = listView->color(subControl); + const auto gradient = listView->gradientHint(subControl); + + boxNode = updateBoxNode( listView, boxNode, boxRect, subControl ); + + if ( boxNode && prepend ) + { + Q_ASSERT(boxNode); + rowNode->prependChildNode( boxNode ); + } + } + // current row should not be styled + else + { + rowNode->removeAllChildNodes(); + } +} + void QskListViewSkinlet::updateBackgroundNodes( const QskListView* listView, QskListViewNode* listViewNode ) const { @@ -126,58 +171,31 @@ void QskListViewSkinlet::updateBackgroundNodes( rowMax = listView->rowCount() - 1; const int rowSelected = listView->selectedRow(); - const double x0 = viewRect.left() + scrolledPos.x(); + const double x0 = viewRect.left(); const double y0 = viewRect.top(); - auto* rowNode = static_cast< QSGSimpleRectNode* >( backgroundNode->firstChild() ); + auto* rowNode = static_cast< QSGNode* >( backgroundNode->firstChild() ); if ( listView->alternatingRowColors() ) { -#if 1 - /* - Cell might be better for regular cells, while ( Cell | AlternateColor ) - could be used for the alternate color TODO ... - */ -#endif - const auto color = listView->color( QskListView::Cell ); - for ( int row = rowMin; row <= rowMax; row++ ) { - if ( row % 2 ) + const auto offsetX = listView->rowOffset( row ); + const QRectF boxRect{ x0 + offsetX, y0 + row * cellHeight, viewRect.width() - offsetX + scrolledPos.x(), + cellHeight }; + + if ( rowNode == nullptr ) { - if ( rowNode == nullptr ) - { - rowNode = new QSGSimpleRectNode(); - backgroundNode->appendChildNode( rowNode ); - } - - rowNode->setRect( x0, y0 + row * cellHeight, viewRect.width(), cellHeight ); - rowNode->setColor( color ); - - rowNode = static_cast< QSGSimpleRectNode* >( rowNode->nextSibling() ); + rowNode = new QSGNode; + updateBackgroundNode( listView, rowNode, boxRect, row ); + backgroundNode->appendChildNode( rowNode ); } + + updateBackgroundNode( listView, rowNode, boxRect, row ); + rowNode = rowNode->nextSibling(); } } - if ( rowSelected >= rowMin && rowSelected <= rowMax ) - { - QskSkinStateChanger stateChanger( listView ); - stateChanger.setStates( listView->skinStates() | QskListView::Selected ); - - const QColor color = listView->color( QskListView::Cell ); - - if ( rowNode == nullptr ) - { - rowNode = new QSGSimpleRectNode(); - backgroundNode->appendChildNode( rowNode ); - } - - rowNode->setRect( x0, y0 + rowSelected * cellHeight, viewRect.width(), cellHeight ); - rowNode->setColor( color ); - - rowNode = static_cast< QSGSimpleRectNode* >( rowNode->nextSibling() ); - } - QSGNode* nextNode = rowNode; while ( nextNode != nullptr ) { @@ -199,7 +217,8 @@ void QskListViewSkinlet::updateForegroundNodes( return; } - const auto margins = listView->paddingHint( QskListView::Cell ); + const auto subControl = listView->rowSubControl(0); + const auto margins = listView->paddingHint( subControl ); const auto cr = listView->viewContentsRect(); const auto scrolledPos = listView->scrollPos(); @@ -255,8 +274,8 @@ void QskListViewSkinlet::updateForegroundNodes( } } - updateVisibleForegroundNodes( listView, listViewNode, - rowMin, rowMax, colMin, colMax, margins, forwards ); + updateVisibleForegroundNodes( + listView, listViewNode, rowMin, rowMax, colMin, colMax, margins, forwards ); // finally putting the nodes into their position auto node = parentNode->firstChild(); @@ -272,9 +291,10 @@ void QskListViewSkinlet::updateForegroundNodes( { Q_ASSERT( node->type() == QSGNode::TransformNodeType ); auto transformNode = static_cast< QSGTransformNode* >( node ); + const auto offsetX = col == 0 ? listView->rowOffset( row ) : 0.0; QTransform transform; - transform.translate( x + margins.left(), y + margins.top() ); + transform.translate( x + margins.left() + offsetX, y + margins.top() ); transformNode->setMatrix( transform ); @@ -288,10 +308,9 @@ void QskListViewSkinlet::updateForegroundNodes( listViewNode->resetRows( rowMin, rowMax ); } -void QskListViewSkinlet::updateVisibleForegroundNodes( - const QskListView* listView, QskListViewNode* listViewNode, - int rowMin, int rowMax, int colMin, int colMax, const QMarginsF& margins, - bool forward ) const +void QskListViewSkinlet::updateVisibleForegroundNodes( const QskListView* listView, + QskListViewNode* listViewNode, int rowMin, int rowMax, int colMin, int colMax, + const QMarginsF& margins, bool forward ) const { auto parentNode = listViewNode->foregroundNode(); @@ -312,11 +331,12 @@ void QskListViewSkinlet::updateVisibleForegroundNodes( for ( int col = 0; col < listView->columnCount(); col++ ) { - const qreal w = listView->columnWidth( col ) - ( margins.left() + margins.right() ); + const auto offsetX = col == 0 ? listView->rowOffset( row ) : 0.0; + const qreal w = + listView->columnWidth( col ) - ( margins.left() + margins.right() ) - offsetX; - node = updateForegroundNode( listView, - parentNode, static_cast< QSGTransformNode* >( node ), - row, col, QSizeF( w, h ), forward ); + node = updateForegroundNode( listView, parentNode, + static_cast< QSGTransformNode* >( node ), row, col, QSizeF( w, h ), forward ); node = node->nextSibling(); } @@ -335,11 +355,12 @@ void QskListViewSkinlet::updateVisibleForegroundNodes( for ( int col = listView->columnCount() - 1; col >= 0; col-- ) { - const qreal w = listView->columnWidth( col ) - ( margins.left() + margins.right() ); + const auto offsetX = col == 0 ? listView->rowOffset( row ) : 0.0; + const qreal w = + listView->columnWidth( col ) - ( margins.left() + margins.right() ) - offsetX; - node = updateForegroundNode( listView, - parentNode, static_cast< QSGTransformNode* >( node ), - row, col, QSizeF( w, h ), forward ); + node = updateForegroundNode( listView, parentNode, + static_cast< QSGTransformNode* >( node ), row, col, QSizeF( w, h ), forward ); node = node->previousSibling(); } @@ -347,9 +368,9 @@ void QskListViewSkinlet::updateVisibleForegroundNodes( } } -QSGTransformNode* QskListViewSkinlet::updateForegroundNode( - const QskListView* listView, QSGNode* parentNode, QSGTransformNode* cellNode, - int row, int col, const QSizeF& size, bool forward ) const +QSGTransformNode* QskListViewSkinlet::updateForegroundNode( const QskListView* listView, + QSGNode* parentNode, QSGTransformNode* cellNode, int row, int col, const QSizeF& size, + bool forward ) const { const QRectF cellRect( 0.0, 0.0, size.width(), size.height() ); @@ -431,8 +452,8 @@ QSGTransformNode* QskListViewSkinlet::updateForegroundNode( return newCellNode; } -QSGNode* QskListViewSkinlet::updateCellNode( const QskListView* listView, - QSGNode* contentNode, const QRectF& rect, int row, int col ) const +QSGNode* QskListViewSkinlet::updateCellNode( + const QskListView* listView, QSGNode* contentNode, const QRectF& rect, int row, int col ) const { using namespace QskSGNode; @@ -452,8 +473,10 @@ QSGNode* QskListViewSkinlet::updateCellNode( const QskListView* listView, public API of QskListView TODO ... */ #endif - const auto alignment = listView->alignmentHint( - QskListView::Cell, Qt::AlignVCenter | Qt::AlignLeft ); + + const auto subControl = listView->cellSubControl(row, col); + const auto alignment = + listView->alignmentHint( subControl, Qt::AlignVCenter | Qt::AlignLeft ); const auto value = listView->valueAt( row, col ); @@ -464,8 +487,8 @@ QSGNode* QskListViewSkinlet::updateCellNode( const QskListView* listView, const auto colorFilter = listView->graphicFilterAt( row, col ); - newNode = updateGraphicNode( listView, newNode, - value.value< QskGraphic >(), colorFilter, rect, alignment ); + newNode = updateGraphicNode( + listView, newNode, value.value< QskGraphic >(), colorFilter, rect, alignment ); if ( newNode ) setNodeRole( newNode, GraphicRole ); @@ -475,8 +498,10 @@ QSGNode* QskListViewSkinlet::updateCellNode( const QskListView* listView, if ( nodeRole( contentNode ) == TextRole ) newNode = contentNode; - newNode = updateTextNode( listView, newNode, rect, alignment, - value.toString(), QskListView::Text ); + const auto subControl = listView->textSubControl( row, col ); + const auto alignment = listView->alignmentHint( subControl ); + newNode = + updateTextNode( listView, newNode, rect, alignment, value.toString(), subControl ); if ( newNode ) setNodeRole( newNode, TextRole ); @@ -489,8 +514,8 @@ QSGNode* QskListViewSkinlet::updateCellNode( const QskListView* listView, return newNode; } -QSizeF QskListViewSkinlet::sizeHint( const QskSkinnable* skinnable, - Qt::SizeHint which, const QSizeF& ) const +QSizeF QskListViewSkinlet::sizeHint( + const QskSkinnable* skinnable, Qt::SizeHint which, const QSizeF& ) const { const auto listView = static_cast< const QskListView* >( skinnable ); diff --git a/src/controls/QskListViewSkinlet.h b/src/controls/QskListViewSkinlet.h index 7f2f9d88..501297af 100644 --- a/src/controls/QskListViewSkinlet.h +++ b/src/controls/QskListViewSkinlet.h @@ -44,6 +44,7 @@ class QSK_EXPORT QskListViewSkinlet : public QskScrollViewSkinlet virtual QSGNode* updateCellNode( const QskListView*, QSGNode*, const QRectF&, int row, int col ) const; + virtual void updateBackgroundNode( const QskListView* listView, QSGNode* rowNode, const QRectF& boxRect, const int row ) const; private: void updateForegroundNodes( const QskListView*, QskListViewNode* ) const; void updateBackgroundNodes( const QskListView*, QskListViewNode* ) const; diff --git a/src/controls/QskTreeView.cpp b/src/controls/QskTreeView.cpp new file mode 100644 index 00000000..55f345a4 --- /dev/null +++ b/src/controls/QskTreeView.cpp @@ -0,0 +1,11 @@ +#include "QskTreeView.h" + +QSK_SUBCONTROL( QskTreeView, Cell ) +QSK_SUBCONTROL( QskTreeView, Text ) + +QskTreeView::QskTreeView( QQuickItem* const parent ) + : Inherited( parent ) +{ + setSubcontrolProxy( Inherited::Cell, Cell ); + setSubcontrolProxy( Inherited::Text, Text ); +} \ No newline at end of file diff --git a/src/controls/QskTreeView.h b/src/controls/QskTreeView.h new file mode 100644 index 00000000..a66ffe96 --- /dev/null +++ b/src/controls/QskTreeView.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +class QSK_EXPORT QskTreeView : public QskListView +{ + using Inherited = QskListView; + + public: + QSK_SUBCONTROLS( Cell, Text ) + + explicit QskTreeView( QQuickItem* const parent = nullptr ); +}; diff --git a/src/controls/QskTreeViewSkinlet.cpp b/src/controls/QskTreeViewSkinlet.cpp new file mode 100644 index 00000000..bde39a3e --- /dev/null +++ b/src/controls/QskTreeViewSkinlet.cpp @@ -0,0 +1,13 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#include "QskTreeViewSkinlet.h" + +QskTreeViewSkinlet::QskTreeViewSkinlet( QskSkin* skin ) + : Inherited( skin ) +{ +} + +#include "moc_QskTreeViewSkinlet.cpp" diff --git a/src/controls/QskTreeViewSkinlet.h b/src/controls/QskTreeViewSkinlet.h new file mode 100644 index 00000000..be6b73f2 --- /dev/null +++ b/src/controls/QskTreeViewSkinlet.h @@ -0,0 +1,21 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + +#ifndef QSK_TREE_VIEW_SKINLET_H +#define QSK_TREE_VIEW_SKINLET_H + +#include "QskListViewSkinlet.h" + +class QSK_EXPORT QskTreeViewSkinlet : public QskListViewSkinlet +{ + Q_GADGET + + using Inherited = QskListViewSkinlet; + + public: + Q_INVOKABLE QskTreeViewSkinlet( QskSkin* = nullptr ); +}; + +#endif From ed842d07d489c76bdaf5472c5166e544c200cb6e Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Fri, 28 Apr 2023 11:02:02 +0200 Subject: [PATCH 3/5] clang-format + copyright --- examples/listbox/TreeBox.cpp | 10 +++++----- examples/listbox/main.cpp | 10 +++++----- src/controls/QskTreeView.cpp | 5 +++++ src/controls/QskTreeView.h | 5 +++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/listbox/TreeBox.cpp b/examples/listbox/TreeBox.cpp index a55ca1ad..0de2e5e0 100644 --- a/examples/listbox/TreeBox.cpp +++ b/examples/listbox/TreeBox.cpp @@ -11,12 +11,12 @@ QSK_SUBCONTROL( TreeBox, SecondRow ) TreeBox::TreeBox( QQuickItem* const parent ) : Inherited( parent ) { - setAlternatingRowColors( true ); + setAlternatingRowColors( true ); setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) ); setAlternatingRowColors( true ); setColor( FirstRow, Qt::white ); - setColor( SecondRow, color(Panel) ); + setColor( SecondRow, color( Panel ) ); updateScrollableSize(); }; @@ -44,8 +44,8 @@ int TreeBox::columnCount() const } qreal TreeBox::columnWidth( int col ) const -{ - return col == 0 ? 100: 350; +{ + return col == 0 ? 100 : 350; } qreal TreeBox::rowHeight() const @@ -68,7 +68,7 @@ Q_INVOKABLE QVariant TreeBox::valueAt( int row, int col ) const return QStringLiteral( "The quick brown fox jumps over the lazy dog" ); } -qreal TreeBox::rowOffset( int row ) const +qreal TreeBox::rowOffset( int row ) const { return ( row % 4 ) * 10; } diff --git a/examples/listbox/main.cpp b/examples/listbox/main.cpp index 1b5952e6..0b41648c 100644 --- a/examples/listbox/main.cpp +++ b/examples/listbox/main.cpp @@ -8,8 +8,8 @@ #ifdef ITEM_STATISTICS #include #endif -#include #include +#include #include @@ -29,10 +29,10 @@ int main( int argc, char* argv[] ) QskWindow window; window.setColor( "Silver" ); - auto* const layout = new QskLinearBox(Qt::Horizontal); - layout->setSpacing(8); - (void) new ListBox(layout); - (void) new TreeBox(layout); + auto* const layout = new QskLinearBox( Qt::Horizontal ); + layout->setSpacing( 8 ); + ( void ) new ListBox( layout ); + ( void ) new TreeBox( layout ); window.addItem( layout ); window.resize( 400, 600 ); diff --git a/src/controls/QskTreeView.cpp b/src/controls/QskTreeView.cpp index 55f345a4..5762b257 100644 --- a/src/controls/QskTreeView.cpp +++ b/src/controls/QskTreeView.cpp @@ -1,3 +1,8 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + #include "QskTreeView.h" QSK_SUBCONTROL( QskTreeView, Cell ) diff --git a/src/controls/QskTreeView.h b/src/controls/QskTreeView.h index a66ffe96..739dc4e9 100644 --- a/src/controls/QskTreeView.h +++ b/src/controls/QskTreeView.h @@ -1,3 +1,8 @@ +/****************************************************************************** + * QSkinny - Copyright (C) 2016 Uwe Rathmann + * SPDX-License-Identifier: BSD-3-Clause + *****************************************************************************/ + #pragma once #include From f0c7e3690a74c8fccac81b769de40910f5e4ee32 Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Fri, 28 Apr 2023 14:42:08 +0200 Subject: [PATCH 4/5] remove assertions --- src/controls/QskListViewSkinlet.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/controls/QskListViewSkinlet.cpp b/src/controls/QskListViewSkinlet.cpp index a7367bea..e045eeb7 100644 --- a/src/controls/QskListViewSkinlet.cpp +++ b/src/controls/QskListViewSkinlet.cpp @@ -126,8 +126,7 @@ void QskListViewSkinlet::updateBackgroundNode( const QskListView* listView, QSGN boxNode = updateBoxNode( listView, boxNode, boxRect, subControl ); if ( boxNode && prepend ) - { - Q_ASSERT(boxNode); + { rowNode->prependChildNode( boxNode ); } } @@ -144,7 +143,6 @@ void QskListViewSkinlet::updateBackgroundNode( const QskListView* listView, QSGN if ( boxNode && prepend ) { - Q_ASSERT(boxNode); rowNode->prependChildNode( boxNode ); } } From 0e240cafb7b1cfefdff65626ac7ab292809a65a4 Mon Sep 17 00:00:00 2001 From: "Vogel, Rick" Date: Mon, 8 May 2023 13:26:49 +0200 Subject: [PATCH 5/5] remove unused or highlight unused variables --- src/controls/QskListView.cpp | 3 +++ src/controls/QskListViewSkinlet.cpp | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controls/QskListView.cpp b/src/controls/QskListView.cpp index 046b7586..bcd80158 100644 --- a/src/controls/QskListView.cpp +++ b/src/controls/QskListView.cpp @@ -166,6 +166,8 @@ QskAspect::Subcontrol QskListView::rowSubControl( int row ) const noexcept QskAspect::Subcontrol QskListView::cellSubControl( int row, int col ) const noexcept { + Q_UNUSED(row); + Q_UNUSED(col); return Cell; } @@ -399,6 +401,7 @@ void QskListView::componentComplete() qreal QskListView::rowOffset( int row ) const { + Q_UNUSED(row); return 0.0; } diff --git a/src/controls/QskListViewSkinlet.cpp b/src/controls/QskListViewSkinlet.cpp index e045eeb7..3f87079e 100644 --- a/src/controls/QskListViewSkinlet.cpp +++ b/src/controls/QskListViewSkinlet.cpp @@ -136,7 +136,6 @@ void QskListViewSkinlet::updateBackgroundNode( const QskListView* listView, QSGN auto* boxNode = rowNode->firstChild(); auto prepend = boxNode == nullptr; - const auto color = listView->color(subControl); const auto gradient = listView->gradientHint(subControl); boxNode = updateBoxNode( listView, boxNode, boxRect, subControl ); @@ -168,7 +167,6 @@ void QskListViewSkinlet::updateBackgroundNodes( if ( rowMax >= listView->rowCount() ) rowMax = listView->rowCount() - 1; - const int rowSelected = listView->selectedRow(); const double x0 = viewRect.left(); const double y0 = viewRect.top();