a bit more cleaner

more fitts law friendly when is in a top panel (still some resizing
issues)

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=871308
This commit is contained in:
Marco Martin 2008-10-14 13:16:56 +00:00
parent a87be2379a
commit 9c6184b1bf

View File

@ -70,6 +70,7 @@ public:
: q(parent), : q(parent),
tabProxy(0), tabProxy(0),
currentIndex(0), currentIndex(0),
isTabWidget(true),
oldPage(0), oldPage(0),
newPage(0), newPage(0),
oldPageAnimId(-1), oldPageAnimId(-1),
@ -87,12 +88,12 @@ public:
TabBar *q; TabBar *q;
TabBarProxy *tabProxy; TabBarProxy *tabProxy;
QGraphicsWidget *leftSpacer;
QGraphicsWidget *rightSpacer;
QList<QGraphicsWidget *> pages; QList<QGraphicsWidget *> pages;
QGraphicsLinearLayout *mainLayout; QGraphicsLinearLayout *mainLayout;
QGraphicsLinearLayout *tabWidgetLayout;
QGraphicsLinearLayout *tabBarLayout; QGraphicsLinearLayout *tabBarLayout;
int currentIndex; int currentIndex;
bool isTabWidget;
QGraphicsWidget *oldPage; QGraphicsWidget *oldPage;
QGraphicsWidget *newPage; QGraphicsWidget *newPage;
@ -111,24 +112,26 @@ void TabBarPrivate::updateTabWidgetMode()
} }
} }
if (tabWidget && tabBarLayout->count() < 3) { if (tabWidget != isTabWidget) {
tabBarLayout->insertItem(0, leftSpacer); if (tabWidget) {
tabBarLayout->insertItem(2, rightSpacer); mainLayout->removeAt(0);
leftSpacer->show(); tabBarLayout->insertItem(1, tabProxy);
rightSpacer->show(); mainLayout->addItem(tabWidgetLayout);
} else if (!tabWidget && tabBarLayout->count() >= 3) { } else {
tabBarLayout->removeItem(leftSpacer); mainLayout->removeAt(0);
tabBarLayout->removeItem(rightSpacer); tabBarLayout->removeAt(1);
leftSpacer->hide(); mainLayout->addItem(tabProxy);
rightSpacer->hide();
} }
} }
isTabWidget = tabWidget;
}
void TabBarPrivate::slidingCompleted(QGraphicsItem *item) void TabBarPrivate::slidingCompleted(QGraphicsItem *item)
{ {
if (item == oldPage || item == newPage) { if (item == oldPage || item == newPage) {
if (item == newPage) { if (item == newPage) {
mainLayout->addItem(newPage); tabWidgetLayout->addItem(newPage);
newPageAnimId = -1; newPageAnimId = -1;
} else { } else {
oldPageAnimId = -1; oldPageAnimId = -1;
@ -149,9 +152,9 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
case QTabBar::RoundedEast: case QTabBar::RoundedEast:
case QTabBar::TriangularEast: case QTabBar::TriangularEast:
tabBarLayout->setOrientation(Qt::Vertical); tabBarLayout->setOrientation(Qt::Vertical);
mainLayout->setOrientation(Qt::Horizontal); tabWidgetLayout->setOrientation(Qt::Horizontal);
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); tabWidgetLayout->itemAt(0)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tabWidgetLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tabProxy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); tabProxy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
break; break;
@ -162,9 +165,9 @@ void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
case QTabBar::TriangularNorth: case QTabBar::TriangularNorth:
default: default:
tabBarLayout->setOrientation(Qt::Horizontal); tabBarLayout->setOrientation(Qt::Horizontal);
mainLayout->setOrientation(Qt::Vertical); tabWidgetLayout->setOrientation(Qt::Vertical);
mainLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); tabWidgetLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
mainLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tabWidgetLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
} }
tabProxy->setPreferredSize(tabProxy->native->sizeHint()); tabProxy->setPreferredSize(tabProxy->native->sizeHint());
@ -175,22 +178,21 @@ TabBar::TabBar(QGraphicsWidget *parent)
d(new TabBarPrivate(this)) d(new TabBarPrivate(this))
{ {
d->tabProxy = new TabBarProxy(this); d->tabProxy = new TabBarProxy(this);
d->mainLayout = new QGraphicsLinearLayout(Qt::Vertical); d->tabWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical);
d->tabBarLayout = new QGraphicsLinearLayout(Qt::Horizontal); d->tabBarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
setLayout(d->mainLayout); d->mainLayout = new QGraphicsLinearLayout(Qt::Horizontal);
d->mainLayout->addItem(d->tabWidgetLayout);
d->mainLayout->addItem(d->tabBarLayout); setLayout(d->mainLayout);
d->mainLayout->setContentsMargins(0,0,0,0);
d->tabWidgetLayout->addItem(d->tabBarLayout);
//tabBar is centered, so a stretch at begin one at the end //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->tabBarLayout->addStretch();
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->tabProxy);
d->tabBarLayout->addItem(d->rightSpacer); d->tabBarLayout->addStretch();
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2); //d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
connect(d->tabProxy->native, SIGNAL(currentChanged(int)), connect(d->tabProxy->native, SIGNAL(currentChanged(int)),
@ -206,6 +208,7 @@ TabBar::~TabBar()
delete d; delete d;
} }
int TabBar::insertTab(int index, const QIcon &icon, const QString &label, int TabBar::insertTab(int index, const QIcon &icon, const QString &label,
QGraphicsLayoutItem *content) QGraphicsLayoutItem *content)
{ {
@ -223,7 +226,7 @@ int TabBar::insertTab(int index, const QIcon &icon, const QString &label,
d->pages.insert(qBound(0, index, d->pages.count()), page); d->pages.insert(qBound(0, index, d->pages.count()), page);
if (d->pages.count() == 1) { if (d->pages.count() == 1) {
d->mainLayout->addItem(page); d->tabWidgetLayout->addItem(page);
page->setVisible(true); page->setVisible(true);
page->setEnabled(true); page->setEnabled(true);
} else { } else {
@ -270,7 +273,7 @@ void TabBar::setCurrentIndex(int index)
d->tabProxy->native->setCurrentIndex(index); d->tabProxy->native->setCurrentIndex(index);
} }
d->mainLayout->removeAt(1); d->tabWidgetLayout->removeAt(1);
d->oldPage = d->pages[d->currentIndex]; d->oldPage = d->pages[d->currentIndex];
d->newPage = d->pages[index]; d->newPage = d->pages[index];
@ -320,7 +323,7 @@ void TabBar::setCurrentIndex(int index)
d->oldPage->geometry().topRight().toPoint()); d->oldPage->geometry().topRight().toPoint());
} }
#else #else
d->mainLayout->addItem(d->pages[index]); d->tabWidgetLayout->addItem(d->pages[index]);
d->oldPage->hide(); d->oldPage->hide();
d->newPage->show(); d->newPage->show();
d->newPage->setEnabled(true); d->newPage->setEnabled(true);