this patch removes the centering and makes the tabbar to take up all the
width when it's not like a tabwidget and there is some sizepolicy/preferred sizes setting fixes that makes it behave better in a panel (especially vertical ones) svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=854953
This commit is contained in:
parent
8a0f530641
commit
e037260031
@ -142,6 +142,7 @@ QSize NativeTabBar::tabSizeHint(int index) const
|
||||
QSize hint = tabSize(index);
|
||||
int minwidth = 0;
|
||||
int minheight = 0;
|
||||
int maxwidth = 0;
|
||||
|
||||
Shape s = shape();
|
||||
switch (s) {
|
||||
@ -158,6 +159,7 @@ QSize NativeTabBar::tabSizeHint(int index) const
|
||||
if (minwidth < width()) {
|
||||
hint.rwidth() += (width() - minwidth) / count();
|
||||
}
|
||||
hint.rheight() += d->top + d->bottom;
|
||||
}
|
||||
break;
|
||||
case RoundedWest:
|
||||
@ -167,14 +169,17 @@ QSize NativeTabBar::tabSizeHint(int index) const
|
||||
if (count() > 0) {
|
||||
for (int i = count() - 1; i >= 0; i--) {
|
||||
minheight += tabSize(i).height();
|
||||
if (tabSize(i).width() > maxwidth) {
|
||||
maxwidth = tabSize(i).width();
|
||||
}
|
||||
}
|
||||
minheight += d->top + d->bottom;
|
||||
|
||||
if (minheight < height()) {
|
||||
hint.rheight() += (height() - minheight) / count();
|
||||
}
|
||||
hint.rwidth() = maxwidth + d->left + d->right;
|
||||
}
|
||||
hint.rwidth() = qMax( hint.width(), width() );
|
||||
break;
|
||||
}
|
||||
return hint;
|
||||
@ -183,17 +188,21 @@ QSize NativeTabBar::tabSizeHint(int index) const
|
||||
//FIXME: this shouldn't be necessary but it seems to return wring numbers the base implementation?
|
||||
QSize NativeTabBar::sizeHint() const
|
||||
{
|
||||
if (count() < 1) {
|
||||
return QTabBar::sizeHint();
|
||||
}
|
||||
|
||||
int width = tabRect(0).width();
|
||||
int height = tabRect(0).height();
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
if (isVertical()) {
|
||||
height *= count();
|
||||
for (int i = count() - 1; i >= 0; i--) {
|
||||
height += tabRect(i).height();
|
||||
}
|
||||
|
||||
width = tabRect(0).width();
|
||||
} else {
|
||||
width *= count();
|
||||
for (int i = count() - 1; i >= 0; i--) {
|
||||
width += tabRect(i).width();
|
||||
}
|
||||
|
||||
height = tabRect(0).height();
|
||||
}
|
||||
return QSize(width+d->left+d->right, height+d->top+d->bottom);
|
||||
}
|
||||
|
@ -53,11 +53,15 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void updateTabWidgetMode();
|
||||
void slidingCompleted(QGraphicsItem *item);
|
||||
void shapeChanged(const QTabBar::Shape shape);
|
||||
|
||||
TabBar *q;
|
||||
NativeTabBar *tabBar;
|
||||
QGraphicsProxyWidget *tabProxy;
|
||||
QGraphicsWidget *leftSpacer;
|
||||
QGraphicsWidget *rightSpacer;
|
||||
QList<QGraphicsWidget *> pages;
|
||||
QGraphicsLinearLayout *mainLayout;
|
||||
QGraphicsLinearLayout *tabBarLayout;
|
||||
@ -70,6 +74,31 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
void TabBarPrivate::updateTabWidgetMode()
|
||||
{
|
||||
bool tabWidget = false;
|
||||
|
||||
foreach (QGraphicsWidget *page, pages) {
|
||||
if (page->preferredSize() != QSize(0, 0)) {
|
||||
tabWidget = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tabWidget && tabBarLayout->count() < 3) {
|
||||
tabBarLayout->insertItem(0, leftSpacer);
|
||||
tabBarLayout->insertItem(2, rightSpacer);
|
||||
leftSpacer->show();
|
||||
rightSpacer->show();
|
||||
} else if (!tabWidget && tabBarLayout->count() >= 3) {
|
||||
tabBarLayout->removeItem(leftSpacer);
|
||||
tabBarLayout->removeItem(rightSpacer);
|
||||
leftSpacer->hide();
|
||||
rightSpacer->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void TabBarPrivate::slidingCompleted(QGraphicsItem *item)
|
||||
{
|
||||
if (item == oldPage || item == newPage) {
|
||||
@ -94,9 +123,11 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
|
||||
|
||||
case QTabBar::RoundedEast:
|
||||
case QTabBar::TriangularEast:
|
||||
tabBarLayout->setOrientation(Qt::Vertical);
|
||||
mainLayout->setOrientation(Qt::Horizontal);
|
||||
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
tabProxy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
break;
|
||||
|
||||
case QTabBar::RoundedSouth:
|
||||
@ -105,10 +136,13 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
|
||||
case QTabBar::RoundedNorth:
|
||||
case QTabBar::TriangularNorth:
|
||||
default:
|
||||
tabBarLayout->setOrientation(Qt::Horizontal);
|
||||
mainLayout->setOrientation(Qt::Vertical);
|
||||
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
}
|
||||
tabProxy->setPreferredSize(tabBar->sizeHint());
|
||||
}
|
||||
|
||||
|
||||
@ -125,14 +159,20 @@ TabBar::TabBar(QGraphicsWidget *parent)
|
||||
|
||||
d->mainLayout->addItem(d->tabBarLayout);
|
||||
|
||||
QGraphicsProxyWidget *tabProxy = new QGraphicsProxyWidget(this);
|
||||
tabProxy->setWidget(d->tabBar);
|
||||
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
d->tabProxy = new QGraphicsProxyWidget(this);
|
||||
d->tabProxy->setWidget(d->tabBar);
|
||||
d->tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
|
||||
//tabBar are centered, so a stretch at begin one at the end
|
||||
d->tabBarLayout->addStretch();
|
||||
d->tabBarLayout->addItem(tabProxy);
|
||||
d->tabBarLayout->addStretch();
|
||||
//tabBar is centered, so a stretch at begin one at the end
|
||||
//FIXME: doesn't seem to be possible to remove stretches from a layout
|
||||
d->leftSpacer = new QGraphicsWidget(this);
|
||||
d->rightSpacer = new QGraphicsWidget(this);
|
||||
d->leftSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
d->rightSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
d->tabBarLayout->addItem(d->leftSpacer);
|
||||
d->tabBarLayout->addItem(d->tabProxy);
|
||||
d->tabBarLayout->addItem(d->rightSpacer);
|
||||
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
|
||||
|
||||
connect(d->tabBar, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndex(int)));
|
||||
connect(d->tabBar, SIGNAL(shapeChanged(QTabBar::Shape)), this, SLOT(shapeChanged(QTabBar::Shape)));
|
||||
@ -168,7 +208,13 @@ int TabBar::insertTab(int index, const QIcon &icon, const QString &label, QGraph
|
||||
page->setEnabled(false);
|
||||
}
|
||||
|
||||
return d->tabBar->insertTab(index, icon, label);
|
||||
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
||||
d->updateTabWidgetMode();
|
||||
|
||||
int actualIndex = d->tabBar->insertTab(index, icon, label);
|
||||
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
||||
d->updateTabWidgetMode();
|
||||
return actualIndex;
|
||||
}
|
||||
|
||||
int TabBar::insertTab(int index, const QString &label, QGraphicsLayoutItem *content)
|
||||
@ -221,7 +267,7 @@ void TabBar::setCurrentIndex(int index)
|
||||
}
|
||||
if (d->newPageAnimId != -1) {
|
||||
Animator::self()->stopItemMovement(d->newPageAnimId);
|
||||
}
|
||||
}
|
||||
if (d->oldPageAnimId != -1) {
|
||||
Animator::self()->stopItemMovement(d->oldPageAnimId);
|
||||
}
|
||||
@ -277,6 +323,9 @@ void TabBar::removeTab(int index)
|
||||
|
||||
scene()->removeItem(page);
|
||||
page->deleteLater();
|
||||
|
||||
d->updateTabWidgetMode();
|
||||
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
||||
}
|
||||
|
||||
void TabBar::setTabText(int index, const QString &label)
|
||||
|
Loading…
x
Reference in New Issue
Block a user