takeTab(), removes a tab and returns the tab contents

svn path=/trunk/KDE/kdelibs/; revision=1004310
This commit is contained in:
Marco Martin 2009-07-29 20:30:07 +00:00
parent f8580b442d
commit 6257d4b7a8
2 changed files with 52 additions and 1 deletions

View File

@ -383,6 +383,49 @@ void TabBar::removeTab(int index)
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint()); d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
} }
QGraphicsLayoutItem *TabBar::takeTab(int index)
{
if (index > d->pages.count()) {
return 0;
}
int oldCurrentIndex = d->tabProxy->native->currentIndex();
d->tabProxy->native->removeTab(index);
QGraphicsWidget *page = d->pages.takeAt(index);
int currentIndex = d->tabProxy->native->currentIndex();
if (oldCurrentIndex == index) {
d->tabWidgetLayout->removeAt(1);
}
QGraphicsLayoutItem *returnItem = 0;
QGraphicsLayout *lay = page->layout();
if (lay && lay->count() == 1) {
returnItem = lay->itemAt(0);
lay->removeAt(0);
} else {
returnItem = lay;
}
if (returnItem) {
returnItem->setParentLayoutItem(0);
}
page->setLayout(0);
scene()->removeItem(page);
page->deleteLater();
if (oldCurrentIndex != currentIndex) {
setCurrentIndex(currentIndex);
}
d->updateTabWidgetMode();
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
return returnItem;
}
void TabBar::setTabText(int index, const QString &label) void TabBar::setTabText(int index, const QString &label)
{ {
if (index > d->pages.count()) { if (index > d->pages.count()) {

View File

@ -112,12 +112,20 @@ public:
int addTab(const QString &label, QGraphicsLayoutItem *content = 0); int addTab(const QString &label, QGraphicsLayoutItem *content = 0);
/** /**
* Removes a tab * Removes a tab, contents are deleted
* *
* @arg index the index of the tab to remove * @arg index the index of the tab to remove
*/ */
void removeTab(int index); void removeTab(int index);
/**
* Removes a tab, the page is reparented to 0 and is returned
*
* @arg index the index of the tab to remove
* @since 4.4
*/
QGraphicsLayoutItem *takeTab(int index);
/** /**
* @return the index of the tab currently active * @return the index of the tab currently active
*/ */