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);
|
QSize hint = tabSize(index);
|
||||||
int minwidth = 0;
|
int minwidth = 0;
|
||||||
int minheight = 0;
|
int minheight = 0;
|
||||||
|
int maxwidth = 0;
|
||||||
|
|
||||||
Shape s = shape();
|
Shape s = shape();
|
||||||
switch (s) {
|
switch (s) {
|
||||||
@ -158,6 +159,7 @@ QSize NativeTabBar::tabSizeHint(int index) const
|
|||||||
if (minwidth < width()) {
|
if (minwidth < width()) {
|
||||||
hint.rwidth() += (width() - minwidth) / count();
|
hint.rwidth() += (width() - minwidth) / count();
|
||||||
}
|
}
|
||||||
|
hint.rheight() += d->top + d->bottom;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RoundedWest:
|
case RoundedWest:
|
||||||
@ -167,14 +169,17 @@ QSize NativeTabBar::tabSizeHint(int index) const
|
|||||||
if (count() > 0) {
|
if (count() > 0) {
|
||||||
for (int i = count() - 1; i >= 0; i--) {
|
for (int i = count() - 1; i >= 0; i--) {
|
||||||
minheight += tabSize(i).height();
|
minheight += tabSize(i).height();
|
||||||
|
if (tabSize(i).width() > maxwidth) {
|
||||||
|
maxwidth = tabSize(i).width();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
minheight += d->top + d->bottom;
|
minheight += d->top + d->bottom;
|
||||||
|
|
||||||
if (minheight < height()) {
|
if (minheight < height()) {
|
||||||
hint.rheight() += (height() - minheight) / count();
|
hint.rheight() += (height() - minheight) / count();
|
||||||
}
|
}
|
||||||
|
hint.rwidth() = maxwidth + d->left + d->right;
|
||||||
}
|
}
|
||||||
hint.rwidth() = qMax( hint.width(), width() );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return hint;
|
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?
|
//FIXME: this shouldn't be necessary but it seems to return wring numbers the base implementation?
|
||||||
QSize NativeTabBar::sizeHint() const
|
QSize NativeTabBar::sizeHint() const
|
||||||
{
|
{
|
||||||
if (count() < 1) {
|
int width = 0;
|
||||||
return QTabBar::sizeHint();
|
int height = 0;
|
||||||
}
|
|
||||||
|
|
||||||
int width = tabRect(0).width();
|
|
||||||
int height = tabRect(0).height();
|
|
||||||
|
|
||||||
if (isVertical()) {
|
if (isVertical()) {
|
||||||
height *= count();
|
for (int i = count() - 1; i >= 0; i--) {
|
||||||
|
height += tabRect(i).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
width = tabRect(0).width();
|
||||||
} else {
|
} 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);
|
return QSize(width+d->left+d->right, height+d->top+d->bottom);
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,15 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateTabWidgetMode();
|
||||||
void slidingCompleted(QGraphicsItem *item);
|
void slidingCompleted(QGraphicsItem *item);
|
||||||
void shapeChanged(const QTabBar::Shape shape);
|
void shapeChanged(const QTabBar::Shape shape);
|
||||||
|
|
||||||
TabBar *q;
|
TabBar *q;
|
||||||
NativeTabBar *tabBar;
|
NativeTabBar *tabBar;
|
||||||
|
QGraphicsProxyWidget *tabProxy;
|
||||||
|
QGraphicsWidget *leftSpacer;
|
||||||
|
QGraphicsWidget *rightSpacer;
|
||||||
QList<QGraphicsWidget *> pages;
|
QList<QGraphicsWidget *> pages;
|
||||||
QGraphicsLinearLayout *mainLayout;
|
QGraphicsLinearLayout *mainLayout;
|
||||||
QGraphicsLinearLayout *tabBarLayout;
|
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)
|
void TabBarPrivate::slidingCompleted(QGraphicsItem *item)
|
||||||
{
|
{
|
||||||
if (item == oldPage || item == newPage) {
|
if (item == oldPage || item == newPage) {
|
||||||
@ -94,9 +123,11 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
|
|||||||
|
|
||||||
case QTabBar::RoundedEast:
|
case QTabBar::RoundedEast:
|
||||||
case QTabBar::TriangularEast:
|
case QTabBar::TriangularEast:
|
||||||
|
tabBarLayout->setOrientation(Qt::Vertical);
|
||||||
mainLayout->setOrientation(Qt::Horizontal);
|
mainLayout->setOrientation(Qt::Horizontal);
|
||||||
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
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;
|
break;
|
||||||
|
|
||||||
case QTabBar::RoundedSouth:
|
case QTabBar::RoundedSouth:
|
||||||
@ -105,10 +136,13 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
|
|||||||
case QTabBar::RoundedNorth:
|
case QTabBar::RoundedNorth:
|
||||||
case QTabBar::TriangularNorth:
|
case QTabBar::TriangularNorth:
|
||||||
default:
|
default:
|
||||||
|
tabBarLayout->setOrientation(Qt::Horizontal);
|
||||||
mainLayout->setOrientation(Qt::Vertical);
|
mainLayout->setOrientation(Qt::Vertical);
|
||||||
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
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);
|
d->mainLayout->addItem(d->tabBarLayout);
|
||||||
|
|
||||||
QGraphicsProxyWidget *tabProxy = new QGraphicsProxyWidget(this);
|
d->tabProxy = new QGraphicsProxyWidget(this);
|
||||||
tabProxy->setWidget(d->tabBar);
|
d->tabProxy->setWidget(d->tabBar);
|
||||||
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
d->tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
|
|
||||||
//tabBar are centered, so a stretch at begin one at the end
|
//tabBar is centered, so a stretch at begin one at the end
|
||||||
d->tabBarLayout->addStretch();
|
//FIXME: doesn't seem to be possible to remove stretches from a layout
|
||||||
d->tabBarLayout->addItem(tabProxy);
|
d->leftSpacer = new QGraphicsWidget(this);
|
||||||
d->tabBarLayout->addStretch();
|
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(currentChanged(int)), this, SLOT(setCurrentIndex(int)));
|
||||||
connect(d->tabBar, SIGNAL(shapeChanged(QTabBar::Shape)), this, SLOT(shapeChanged(QTabBar::Shape)));
|
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);
|
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)
|
int TabBar::insertTab(int index, const QString &label, QGraphicsLayoutItem *content)
|
||||||
@ -277,6 +323,9 @@ void TabBar::removeTab(int index)
|
|||||||
|
|
||||||
scene()->removeItem(page);
|
scene()->removeItem(page);
|
||||||
page->deleteLater();
|
page->deleteLater();
|
||||||
|
|
||||||
|
d->updateTabWidgetMode();
|
||||||
|
d->tabProxy->setPreferredSize(d->tabBar->sizeHint());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::setTabText(int index, const QString &label)
|
void TabBar::setTabText(int index, const QString &label)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user