ability to hide the tabbar, now can be used like it's a QStackedWidget :)

svn path=/trunk/KDE/kdelibs/; revision=921018
This commit is contained in:
Marco Martin 2009-02-04 10:32:20 +00:00
parent 0b4e10e9b0
commit 9c971e11ba
2 changed files with 45 additions and 5 deletions

View File

@ -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);

View File

@ -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
*