From 9c971e11babc8b5db14e6817c03a157f39143a4e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 4 Feb 2009 10:32:20 +0000 Subject: [PATCH] ability to hide the tabbar, now can be used like it's a QStackedWidget :) svn path=/trunk/KDE/kdelibs/; revision=921018 --- widgets/tabbar.cpp | 35 ++++++++++++++++++++++++++++++----- widgets/tabbar.h | 15 +++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/widgets/tabbar.cpp b/widgets/tabbar.cpp index 8af7e068d..2a664f436 100644 --- a/widgets/tabbar.cpp +++ b/widgets/tabbar.cpp @@ -71,7 +71,7 @@ public: : q(parent), tabProxy(0), currentIndex(0), - isTabWidget(true), + tabWidgetMode(true), oldPage(0), newPage(0), oldPageAnimId(-1), @@ -94,7 +94,7 @@ public: QGraphicsLinearLayout *tabWidgetLayout; QGraphicsLinearLayout *tabBarLayout; int currentIndex; - bool isTabWidget; + bool tabWidgetMode; QGraphicsWidget *oldPage; QGraphicsWidget *newPage; @@ -113,7 +113,7 @@ void TabBarPrivate::updateTabWidgetMode() } } - if (tabWidget != isTabWidget) { + if (tabWidget != tabWidgetMode) { if (tabWidget) { mainLayout->removeAt(0); tabBarLayout->insertItem(1, tabProxy); @@ -125,7 +125,12 @@ void TabBarPrivate::updateTabWidgetMode() } } - isTabWidget = tabWidget; + //always show the tabbar + if (!tabWidget) { + q->setTabBarShown(true); + } + + tabWidgetMode = tabWidget; } void TabBarPrivate::slidingCompleted(QGraphicsItem *item) @@ -270,7 +275,7 @@ int TabBar::currentIndex() const void TabBar::resizeEvent(QGraphicsSceneResizeEvent * event) { - if (!d->isTabWidget) { + if (!d->tabWidgetMode) { d->tabProxy->setMinimumSize(event->newSize().toSize()); } else { d->tabProxy->native->setMinimumSize(QSize(0,0)); @@ -405,6 +410,26 @@ QIcon TabBar::tabIcon(int index) const return d->tabProxy->native->tabIcon(index); } +void TabBar::setTabBarShown(bool show) +{ + if (!show && !d->tabWidgetMode) { + return; + } + + if (!show && d->tabProxy->isVisible()) { + d->tabProxy->hide(); + d->tabBarLayout->removeItem(d->tabProxy); + } else if (show && !d->tabProxy->isVisible()) { + d->tabProxy->show(); + d->tabBarLayout->insertItem(0, d->tabProxy); + } +} + +bool TabBar::isTabBarShown() const +{ + return d->tabProxy->isVisible(); +} + void TabBar::setStyleSheet(const QString &stylesheet) { d->tabProxy->native->setStyleSheet(stylesheet); diff --git a/widgets/tabbar.h b/widgets/tabbar.h index 706c435f7..6426d421c 100644 --- a/widgets/tabbar.h +++ b/widgets/tabbar.h @@ -51,6 +51,7 @@ class PLASMA_EXPORT TabBar : public QGraphicsWidget Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex) Q_PROPERTY(int count READ count) Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) + Q_PROPERTY(bool tabBarShown READ isTabBarShown WRITE setTabBarShown) public: /** @@ -157,6 +158,20 @@ public: */ QIcon tabIcon(int index) const; + /** + * shows or hides the tabbar, used if you just want to display the + * pages, when the tabbar doesn't have content pages at all this + * function has no effect + * + * @arg show true if we want to show the tabbar + */ + void setTabBarShown(bool show); + + /** + * @return true if the tabbar is shown + */ + bool isTabBarShown() const; + /** * Sets the stylesheet used to control the visual display of this TabBar *