From 4ef3fe3164a3c512a5a5510d02af471e3c238dda Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 15 Jul 2022 10:44:32 +0200 Subject: [PATCH] initial tabbar position as skin hint ( QskTabBar::Panel | QskAspect::Style ) --- examples/gallery/main.cpp | 1 - skins/material3/QskMaterial3Skin.cpp | 2 ++ src/controls/QskTabBar.cpp | 48 ++++++++++++++++------------ src/controls/QskTabBar.h | 4 ++- src/controls/QskTabView.cpp | 2 +- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/examples/gallery/main.cpp b/examples/gallery/main.cpp index 1bbccc71..7915631d 100644 --- a/examples/gallery/main.cpp +++ b/examples/gallery/main.cpp @@ -41,7 +41,6 @@ namespace TabView( QQuickItem* parent = nullptr ) : QskTabView( parent ) { - setTabBarEdge( Qt::BottomEdge ); setAutoFitTabs( true ); } diff --git a/skins/material3/QskMaterial3Skin.cpp b/skins/material3/QskMaterial3Skin.cpp index f408d154..532184ec 100644 --- a/skins/material3/QskMaterial3Skin.cpp +++ b/skins/material3/QskMaterial3Skin.cpp @@ -712,6 +712,8 @@ void Editor::setupTabBar() setGradient( Q::Panel, m_pal.secondaryContainer ); setPadding( Q::Panel, 0 ); + setFlagHint( Q::Panel | A::Style, Qt::BottomEdge ); + // when flicking setAnimation( Q::Panel | A::Metric, QskAnimationHint( 200, QEasingCurve::InCubic ) ); } diff --git a/src/controls/QskTabBar.cpp b/src/controls/QskTabBar.cpp index 36717d8b..c469441d 100644 --- a/src/controls/QskTabBar.cpp +++ b/src/controls/QskTabBar.cpp @@ -250,11 +250,6 @@ namespace class QskTabBar::PrivateData { public: - PrivateData( Qt::Edge edge ) - : edge( edge ) - { - } - void connectButton( QskTabButton* button, QskTabBar* tabBar, bool on ) { if ( on ) @@ -274,21 +269,15 @@ class QskTabBar::PrivateData int currentIndex = -1; QskTextOptions textOptions; - Qt::Edge edge; }; QskTabBar::QskTabBar( QQuickItem* parent ) - : QskTabBar( Qt::TopEdge, parent ) -{ -} - -QskTabBar::QskTabBar( Qt::Edge edge, QQuickItem* parent ) : Inherited( parent ) - , m_data( new PrivateData( edge ) ) + , m_data( new PrivateData() ) { setAutoLayoutChildren( true ); - const auto orientation = qskOrientation( edge ); + const auto orientation = qskOrientation( edge() ); if ( orientation == Qt::Horizontal ) initSizePolicy( QskSizePolicy::Preferred, QskSizePolicy::Fixed ); @@ -306,16 +295,24 @@ QskTabBar::QskTabBar( Qt::Edge edge, QQuickItem* parent ) m_data->buttonBox, &ButtonBox::restack, Qt::QueuedConnection ); } +QskTabBar::QskTabBar( Qt::Edge edge, QQuickItem* parent ) + : QskTabBar( parent ) +{ + setEdge( edge ); +} + QskTabBar::~QskTabBar() { } void QskTabBar::setEdge( Qt::Edge edge ) { - if ( edge == m_data->edge ) - return; + const auto oldEdge = this->edge(); - m_data->edge = edge; + setFlagHint( Panel | QskAspect::Style, edge ); + + if ( edge == oldEdge ) + return; const auto orientation = qskOrientation( edge ); @@ -337,14 +334,25 @@ void QskTabBar::setEdge( Qt::Edge edge ) Q_EMIT edgeChanged( edge ); } +void QskTabBar::resetEdge() +{ + if ( resetFlagHint( Panel | QskAspect::Style ) ) + Q_EMIT edgeChanged( edge() ); +} + Qt::Edge QskTabBar::edge() const { - return m_data->edge; + /* + We add a meaningless QskAspect::Vertical bit to avoid that effectivePlacement + gets called finally ending up in an endless recursion ... + */ + const auto aspect = Panel | QskAspect::Style | QskAspect::Vertical; + return flagHint< Qt::Edge > ( aspect, Qt::TopEdge ); } Qt::Orientation QskTabBar::orientation() const { - return qskOrientation( m_data->edge ); + return qskOrientation( edge() ); } void QskTabBar::setAutoScrollFocusedButton( bool on ) @@ -363,7 +371,7 @@ bool QskTabBar::autoScrollFocusButton() const void QskTabBar::setAutoFitTabs( bool on ) { - const auto orientation = qskOrientation( m_data->edge ); + const auto orientation = qskOrientation( edge() ); int policy = m_data->buttonBox->sizePolicy( orientation ); if ( ( policy & QskSizePolicy::GrowFlag ) != on ) @@ -682,7 +690,7 @@ QskAspect::Subcontrol QskTabBar::substitutedSubcontrol( QskAspect::Placement QskTabBar::effectivePlacement() const { - switch ( m_data->edge ) + switch ( edge() ) { case Qt::LeftEdge: return QskAspect::Left; diff --git a/src/controls/QskTabBar.h b/src/controls/QskTabBar.h index b2368b6a..c54337e0 100644 --- a/src/controls/QskTabBar.h +++ b/src/controls/QskTabBar.h @@ -16,7 +16,8 @@ class QSK_EXPORT QskTabBar : public QskBox { Q_OBJECT - Q_PROPERTY( Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL ) + Q_PROPERTY( Qt::Edge edge READ edge + WRITE setEdge RESET resetEdge NOTIFY edgeChanged FINAL ) Q_PROPERTY( Qt::Orientation orientation READ orientation ) @@ -45,6 +46,7 @@ class QSK_EXPORT QskTabBar : public QskBox ~QskTabBar() override; void setEdge( Qt::Edge ); + void resetEdge(); Qt::Edge edge() const; Qt::Orientation orientation() const; diff --git a/src/controls/QskTabView.cpp b/src/controls/QskTabView.cpp index 5fb3a442..af9c4cad 100644 --- a/src/controls/QskTabView.cpp +++ b/src/controls/QskTabView.cpp @@ -34,7 +34,7 @@ QskTabView::QskTabView( QQuickItem* parent ) { setPolishOnResize( true ); - m_data->tabBar = new QskTabBar( Qt::TopEdge, this ); + m_data->tabBar = new QskTabBar( this ); m_data->stackBox = new QskStackBox( this ); m_data->stackBox->setObjectName( QStringLiteral( "QskTabViewStackBox" ) );