2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tabbar.h"
|
|
|
|
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QGraphicsLayoutItem>
|
|
|
|
#include <QString>
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsProxyWidget>
|
|
|
|
#include <QGraphicsSceneWheelEvent>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QPainter>
|
2010-02-05 13:24:46 +01:00
|
|
|
#include <QParallelAnimationGroup>
|
2008-11-04 03:55:37 +01:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <plasma/animator.h>
|
2010-01-22 20:31:42 +01:00
|
|
|
#include <plasma/animations/animation.h>
|
2009-09-13 21:18:29 +02:00
|
|
|
#include <plasma/theme.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include "private/nativetabbar_p.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class TabBarProxy : public QGraphicsProxyWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TabBarProxy(QGraphicsWidget *parent)
|
|
|
|
: QGraphicsProxyWidget(parent)
|
|
|
|
{
|
|
|
|
native = new NativeTabBar();
|
|
|
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
|
|
|
setWidget(native);
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
//Don't paint the child widgets
|
|
|
|
static_cast<NativeTabBar *>(QGraphicsProxyWidget::widget())->render(
|
|
|
|
painter, QPoint(0, 0), QRegion(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeTabBar *native;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TabBarPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TabBarPrivate(TabBar *parent)
|
|
|
|
: q(parent),
|
|
|
|
tabProxy(0),
|
|
|
|
currentIndex(0),
|
2009-02-04 11:32:20 +01:00
|
|
|
tabWidgetMode(true),
|
2008-11-04 00:08:39 +01:00
|
|
|
oldPageAnimId(-1),
|
2009-09-13 21:18:29 +02:00
|
|
|
newPageAnimId(-1),
|
2009-11-10 10:46:14 +01:00
|
|
|
customFont(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~TabBarPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateTabWidgetMode();
|
|
|
|
void slidingCompleted(QGraphicsItem *item);
|
2010-01-22 20:31:42 +01:00
|
|
|
void slidingNewPageCompleted();
|
|
|
|
void slidingOldPageCompleted();
|
2008-11-06 00:28:07 +01:00
|
|
|
void shapeChanged(const KTabBar::Shape shape);
|
2009-09-13 21:18:29 +02:00
|
|
|
void setPalette();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
TabBar *q;
|
|
|
|
TabBarProxy *tabProxy;
|
|
|
|
QList<QGraphicsWidget *> pages;
|
|
|
|
QGraphicsLinearLayout *mainLayout;
|
|
|
|
QGraphicsLinearLayout *tabWidgetLayout;
|
|
|
|
QGraphicsLinearLayout *tabBarLayout;
|
|
|
|
int currentIndex;
|
2009-02-04 11:32:20 +01:00
|
|
|
bool tabWidgetMode;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-08-26 03:22:45 +02:00
|
|
|
QWeakPointer<QGraphicsWidget> oldPage;
|
|
|
|
QWeakPointer<QGraphicsWidget> newPage;
|
2008-11-04 00:08:39 +01:00
|
|
|
int oldPageAnimId;
|
|
|
|
int newPageAnimId;
|
2010-01-22 20:31:42 +01:00
|
|
|
Animation *oldPageAnim;
|
|
|
|
Animation *newPageAnim;
|
2010-02-05 13:24:46 +01:00
|
|
|
QParallelAnimationGroup *animGroup;
|
2009-09-13 21:18:29 +02:00
|
|
|
bool customFont;
|
2010-07-12 10:29:49 +02:00
|
|
|
QWeakPointer<QGraphicsWidget> firstPositionWidget;
|
|
|
|
QWeakPointer<QGraphicsWidget> lastPositionWidget;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void TabBarPrivate::updateTabWidgetMode()
|
|
|
|
{
|
|
|
|
bool tabWidget = false;
|
|
|
|
|
|
|
|
foreach (QGraphicsWidget *page, pages) {
|
|
|
|
if (page->preferredSize() != QSize(0, 0)) {
|
|
|
|
tabWidget = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 11:32:20 +01:00
|
|
|
if (tabWidget != tabWidgetMode) {
|
2008-11-04 00:08:39 +01:00
|
|
|
if (tabWidget) {
|
|
|
|
mainLayout->removeAt(0);
|
|
|
|
tabBarLayout->insertItem(1, tabProxy);
|
|
|
|
mainLayout->addItem(tabWidgetLayout);
|
|
|
|
} else {
|
|
|
|
mainLayout->removeAt(0);
|
|
|
|
tabBarLayout->removeAt(1);
|
|
|
|
mainLayout->addItem(tabProxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 11:32:20 +01:00
|
|
|
//always show the tabbar
|
2009-03-28 20:11:43 +01:00
|
|
|
//FIXME: Qt BUG: calling show on a child of an hidden item it shows it anyways
|
|
|
|
//so we avoid to call it if the parent is hidden
|
|
|
|
if (!tabWidget && q->isVisible()) {
|
2009-02-04 11:32:20 +01:00
|
|
|
q->setTabBarShown(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
tabWidgetMode = tabWidget;
|
2010-04-16 14:51:07 +02:00
|
|
|
if (!tabWidgetMode) {
|
|
|
|
q->setMinimumSize(QSize(0, 0));
|
|
|
|
q->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
|
|
|
} else {
|
|
|
|
tabProxy->native->setMinimumSize(QSize(0,0));
|
|
|
|
tabProxy->setMinimumSize(QSize(0,0));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-01-22 20:31:42 +01:00
|
|
|
void TabBarPrivate::slidingNewPageCompleted()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-05-17 22:46:35 +02:00
|
|
|
if (newPage) {
|
|
|
|
tabWidgetLayout->addItem(newPage.data());
|
|
|
|
}
|
2010-01-22 20:31:42 +01:00
|
|
|
newPageAnimId = -1;
|
|
|
|
mainLayout->invalidate();
|
|
|
|
emit q->currentChanged(currentIndex);
|
|
|
|
|
|
|
|
q->setFlags(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBarPrivate::slidingOldPageCompleted()
|
|
|
|
{
|
2010-02-05 13:24:46 +01:00
|
|
|
QGraphicsWidget *item = oldPageAnim->targetWidget();
|
2010-01-22 20:31:42 +01:00
|
|
|
|
|
|
|
oldPageAnimId = -1;
|
2010-04-27 18:02:51 +02:00
|
|
|
if (item) {
|
|
|
|
item->hide();
|
|
|
|
}
|
2010-01-22 20:31:42 +01:00
|
|
|
q->setFlags(0);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
|
|
|
|
{
|
|
|
|
//FIXME: QGraphicsLinearLayout doesn't have setDirection, so for now
|
|
|
|
// North is equal to south and East is equal to West
|
|
|
|
switch (shape) {
|
|
|
|
case QTabBar::RoundedWest:
|
|
|
|
case QTabBar::TriangularWest:
|
|
|
|
|
|
|
|
case QTabBar::RoundedEast:
|
|
|
|
case QTabBar::TriangularEast:
|
2010-04-21 15:05:57 +02:00
|
|
|
q->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
2008-11-04 00:08:39 +01:00
|
|
|
tabBarLayout->setOrientation(Qt::Vertical);
|
|
|
|
tabWidgetLayout->setOrientation(Qt::Horizontal);
|
|
|
|
tabWidgetLayout->itemAt(0)->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
2009-02-23 12:26:45 +01:00
|
|
|
if (tabWidgetLayout->count() > 1) {
|
2010-04-21 15:05:57 +02:00
|
|
|
tabWidgetLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2009-02-23 12:26:45 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
tabProxy->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QTabBar::RoundedSouth:
|
|
|
|
case QTabBar::TriangularSouth:
|
|
|
|
|
|
|
|
case QTabBar::RoundedNorth:
|
|
|
|
case QTabBar::TriangularNorth:
|
|
|
|
default:
|
2010-04-21 15:05:57 +02:00
|
|
|
q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2008-11-04 00:08:39 +01:00
|
|
|
tabBarLayout->setOrientation(Qt::Horizontal);
|
|
|
|
tabWidgetLayout->setOrientation(Qt::Vertical);
|
2010-04-21 15:05:57 +02:00
|
|
|
tabWidgetLayout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
2009-02-23 12:26:45 +01:00
|
|
|
if (tabWidgetLayout->count() > 1) {
|
2010-04-21 15:05:57 +02:00
|
|
|
tabWidgetLayout->itemAt(1)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2009-02-23 12:26:45 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
tabProxy->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
|
}
|
2010-04-16 14:57:59 +02:00
|
|
|
tabProxy->setPreferredSize(tabProxy->native->sizeHint());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-09-13 21:18:29 +02:00
|
|
|
void TabBarPrivate::setPalette()
|
|
|
|
{
|
|
|
|
QTabBar *native = q->nativeWidget();
|
|
|
|
QColor color = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
|
|
|
QPalette p = native->palette();
|
|
|
|
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Text, color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Text, color);
|
|
|
|
p.setColor(QPalette::Normal, QPalette::ButtonText, color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::ButtonText, color);
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
|
|
|
|
native->setPalette(p);
|
|
|
|
|
|
|
|
if (!customFont) {
|
|
|
|
q->nativeWidget()->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
TabBar::TabBar(QGraphicsWidget *parent)
|
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
d(new TabBarPrivate(this))
|
|
|
|
{
|
2010-04-21 15:05:57 +02:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2009-12-09 18:44:56 +01:00
|
|
|
setContentsMargins(0,0,0,0);
|
2008-11-04 00:08:39 +01:00
|
|
|
d->tabProxy = new TabBarProxy(this);
|
|
|
|
d->tabWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
|
|
d->tabBarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
|
2009-12-09 18:44:56 +01:00
|
|
|
d->tabWidgetLayout->setContentsMargins(0,0,0,0);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
d->mainLayout = new QGraphicsLinearLayout(Qt::Horizontal);
|
|
|
|
d->mainLayout->addItem(d->tabWidgetLayout);
|
|
|
|
|
|
|
|
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
|
|
|
|
d->tabBarLayout->addStretch();
|
|
|
|
d->tabBarLayout->addItem(d->tabProxy);
|
|
|
|
d->tabBarLayout->addStretch();
|
2009-12-09 18:44:56 +01:00
|
|
|
d->tabBarLayout->setContentsMargins(0,0,0,0);
|
2008-11-04 00:08:39 +01:00
|
|
|
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
|
|
|
|
|
2010-01-22 20:31:42 +01:00
|
|
|
|
|
|
|
d->newPageAnim = Animator::create(Animator::SlideAnimation);
|
|
|
|
d->oldPageAnim = Animator::create(Animator::SlideAnimation);
|
2010-02-05 13:24:46 +01:00
|
|
|
d->animGroup = new QParallelAnimationGroup(this);
|
2010-01-22 20:31:42 +01:00
|
|
|
|
|
|
|
d->animGroup->addAnimation(d->newPageAnim);
|
|
|
|
d->animGroup->addAnimation(d->oldPageAnim);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
connect(d->tabProxy->native, SIGNAL(currentChanged(int)),
|
|
|
|
this, SLOT(setCurrentIndex(int)));
|
|
|
|
connect(d->tabProxy->native, SIGNAL(shapeChanged(QTabBar::Shape)),
|
|
|
|
this, SLOT(shapeChanged(QTabBar::Shape)));
|
2010-01-22 20:31:42 +01:00
|
|
|
connect(d->newPageAnim, SIGNAL(finished()), this, SLOT(slidingNewPageCompleted()));
|
|
|
|
connect(d->oldPageAnim, SIGNAL(finished()), this, SLOT(slidingOldPageCompleted()));
|
2009-09-13 21:18:29 +02:00
|
|
|
connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
|
|
|
|
this, SLOT(setPalette()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TabBar::~TabBar()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TabBar::insertTab(int index, const QIcon &icon, const QString &label,
|
|
|
|
QGraphicsLayoutItem *content)
|
|
|
|
{
|
|
|
|
QGraphicsWidget *page = new QGraphicsWidget(this);
|
2009-12-09 18:44:56 +01:00
|
|
|
page->setContentsMargins(0,0,0,0);
|
2010-05-24 23:20:33 +02:00
|
|
|
page->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2008-11-04 00:08:39 +01:00
|
|
|
if (content) {
|
|
|
|
if (content->isLayout()) {
|
|
|
|
page->setLayout(static_cast<QGraphicsLayout *>(content));
|
|
|
|
} else {
|
|
|
|
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, page);
|
2009-12-09 18:44:56 +01:00
|
|
|
layout->setContentsMargins(0,0,0,0);
|
2009-10-29 19:31:27 +01:00
|
|
|
layout->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
2008-11-04 00:08:39 +01:00
|
|
|
layout->addItem(content);
|
|
|
|
page->setLayout(layout);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
page->setPreferredSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->pages.insert(qBound(0, index, d->pages.count()), page);
|
|
|
|
|
|
|
|
if (d->pages.count() == 1) {
|
|
|
|
d->tabWidgetLayout->addItem(page);
|
|
|
|
page->setVisible(true);
|
|
|
|
page->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
page->setVisible(false);
|
|
|
|
page->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
|
|
|
d->updateTabWidgetMode();
|
|
|
|
|
|
|
|
int actualIndex = d->tabProxy->native->insertTab(index, icon, label);
|
2009-09-22 16:04:20 +02:00
|
|
|
d->currentIndex = d->tabProxy->native->currentIndex();
|
2008-11-04 00:08:39 +01:00
|
|
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
|
|
|
d->updateTabWidgetMode();
|
|
|
|
return actualIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabBar::insertTab(int index, const QString &label, QGraphicsLayoutItem *content)
|
|
|
|
{
|
|
|
|
return insertTab(index, QIcon(), label, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabBar::addTab(const QIcon &icon, const QString &label, QGraphicsLayoutItem *content)
|
|
|
|
{
|
|
|
|
return insertTab(d->pages.count(), icon, label, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabBar::addTab(const QString &label, QGraphicsLayoutItem *content)
|
|
|
|
{
|
|
|
|
return insertTab(d->pages.count(), QIcon(), label, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabBar::currentIndex() const
|
|
|
|
{
|
|
|
|
return d->tabProxy->native->currentIndex();
|
|
|
|
}
|
|
|
|
|
2008-11-18 16:27:04 +01:00
|
|
|
void TabBar::resizeEvent(QGraphicsSceneResizeEvent * event)
|
|
|
|
{
|
2009-02-04 11:32:20 +01:00
|
|
|
if (!d->tabWidgetMode) {
|
2009-01-26 14:58:39 +01:00
|
|
|
d->tabProxy->setMinimumSize(event->newSize().toSize());
|
2010-04-21 15:16:46 +02:00
|
|
|
setMinimumSize(QSize(0, 0));
|
2010-04-21 15:05:57 +02:00
|
|
|
setMinimumHeight(d->tabProxy->widget()->minimumSizeHint().height());
|
2009-08-28 19:28:15 +02:00
|
|
|
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
2008-11-18 16:27:04 +01:00
|
|
|
} else {
|
2010-04-21 15:05:57 +02:00
|
|
|
setMinimumSize(QSize(-1, -1));
|
2008-11-18 16:27:04 +01:00
|
|
|
d->tabProxy->native->setMinimumSize(QSize(0,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void TabBar::setCurrentIndex(int index)
|
|
|
|
{
|
2010-08-26 03:22:45 +02:00
|
|
|
if (index >= d->pages.count() ||
|
|
|
|
d->pages.count() < 2 ||
|
2009-01-04 19:43:30 +01:00
|
|
|
d->currentIndex == index) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-26 03:22:45 +02:00
|
|
|
d->oldPage = d->pages.value(d->currentIndex);
|
2009-09-24 19:57:53 +02:00
|
|
|
|
2010-08-26 03:22:45 +02:00
|
|
|
if (d->oldPage) {
|
|
|
|
d->tabWidgetLayout->removeItem(d->oldPage.data());
|
|
|
|
}
|
2009-12-09 22:24:58 +01:00
|
|
|
|
2009-09-24 20:26:48 +02:00
|
|
|
if (index >= 0) {
|
2010-08-26 03:22:45 +02:00
|
|
|
d->newPage = d->pages.value(index);
|
2009-09-24 20:26:48 +02:00
|
|
|
}
|
2009-02-08 14:26:33 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
setFlags(QGraphicsItem::ItemClipsChildrenToShape);
|
|
|
|
|
|
|
|
//if an animation was in rogress hide everything to avoid an inconsistent state
|
2010-01-22 20:31:42 +01:00
|
|
|
|
|
|
|
if (d->animGroup->state() != QAbstractAnimation::Stopped) {
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (QGraphicsWidget *page, d->pages) {
|
|
|
|
page->hide();
|
|
|
|
}
|
2010-01-22 20:31:42 +01:00
|
|
|
d->animGroup->stop();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-09-24 20:26:48 +02:00
|
|
|
if (d->newPage) {
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPage.data()->show();
|
|
|
|
d->newPage.data()->setEnabled(true);
|
2009-09-24 20:26:48 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-24 20:26:48 +02:00
|
|
|
if (d->oldPage) {
|
2010-05-17 22:46:35 +02:00
|
|
|
d->oldPage.data()->show();
|
|
|
|
d->oldPage.data()->setEnabled(false);
|
2009-09-24 20:26:48 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-24 20:26:48 +02:00
|
|
|
if (d->newPage && d->oldPage) {
|
2009-12-09 20:19:00 +01:00
|
|
|
//FIXME: it seems necessary to resiz the thing 2 times to have effect
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPage.data()->resize(1,1);
|
|
|
|
d->newPage.data()->resize(d->oldPage.data()->size());
|
2009-12-09 20:19:00 +01:00
|
|
|
|
2010-05-17 22:46:35 +02:00
|
|
|
QRect beforeCurrentGeom(d->oldPage.data()->geometry().toRect());
|
2009-09-24 20:26:48 +02:00
|
|
|
beforeCurrentGeom.moveTopRight(beforeCurrentGeom.topLeft());
|
|
|
|
|
|
|
|
if (index > d->currentIndex) {
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPage.data()->setPos(d->oldPage.data()->geometry().topRight());
|
2010-06-16 20:00:38 +02:00
|
|
|
d->newPageAnim->setProperty("movementDirection", Animation::MoveLeft);
|
|
|
|
d->newPageAnim->setProperty("distancePointF", QPointF(d->oldPage.data()->size().width(), 0));
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPageAnim->setTargetWidget(d->newPage.data());
|
2010-01-22 20:31:42 +01:00
|
|
|
|
2010-06-16 20:00:38 +02:00
|
|
|
d->oldPageAnim->setProperty("movementDirection", Animation::MoveLeft);
|
|
|
|
d->oldPageAnim->setProperty("distancePointF", QPointF(beforeCurrentGeom.width(), 0));
|
2010-05-17 22:46:35 +02:00
|
|
|
d->oldPageAnim->setTargetWidget(d->oldPage.data());
|
2010-01-22 20:31:42 +01:00
|
|
|
|
|
|
|
d->animGroup->start();
|
2009-09-24 20:26:48 +02:00
|
|
|
} else {
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPage.data()->setPos(beforeCurrentGeom.topLeft());
|
2010-06-16 20:00:38 +02:00
|
|
|
d->newPageAnim->setProperty("movementDirection", Animation::MoveRight);
|
|
|
|
d->newPageAnim->setProperty("distancePointF", QPointF(d->oldPage.data()->size().width(), 0));
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPageAnim->setTargetWidget(d->newPage.data());
|
2010-01-22 20:31:42 +01:00
|
|
|
|
2010-06-16 20:00:38 +02:00
|
|
|
d->oldPageAnim->setProperty("movementDirection", Animation::MoveRight);
|
2010-01-22 20:31:42 +01:00
|
|
|
d->oldPageAnim->setProperty("distancePointF",
|
2010-06-16 20:00:38 +02:00
|
|
|
QPointF(d->oldPage.data()->size().width(), 0));
|
2010-05-17 22:46:35 +02:00
|
|
|
d->oldPageAnim->setTargetWidget(d->oldPage.data());
|
2010-01-22 20:31:42 +01:00
|
|
|
|
|
|
|
d->animGroup->start();
|
2009-09-24 20:26:48 +02:00
|
|
|
}
|
2010-05-17 22:46:35 +02:00
|
|
|
} else if (d->newPage) {
|
|
|
|
d->tabWidgetLayout->addItem(d->newPage.data());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-02-08 14:26:33 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->currentIndex = index;
|
2009-01-04 21:04:37 +01:00
|
|
|
d->tabProxy->native->setCurrentIndex(index);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TabBar::count() const
|
|
|
|
{
|
|
|
|
return d->pages.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::removeTab(int index)
|
|
|
|
{
|
2010-05-17 22:46:35 +02:00
|
|
|
if (index >= d->pages.count() || index < 0) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-17 22:46:35 +02:00
|
|
|
d->newPageAnim->stop();
|
|
|
|
d->oldPageAnim->stop();
|
|
|
|
|
2009-01-25 20:21:14 +01:00
|
|
|
int oldCurrentIndex = d->tabProxy->native->currentIndex();
|
2008-11-04 00:08:39 +01:00
|
|
|
d->tabProxy->native->removeTab(index);
|
|
|
|
|
2010-07-07 17:17:48 +02:00
|
|
|
d->currentIndex = oldCurrentIndex;
|
2009-01-25 20:21:14 +01:00
|
|
|
int currentIndex = d->tabProxy->native->currentIndex();
|
|
|
|
|
|
|
|
if (oldCurrentIndex == index) {
|
|
|
|
d->tabWidgetLayout->removeAt(1);
|
2010-07-07 17:17:48 +02:00
|
|
|
if (d->tabProxy->native->count() > 0) {
|
|
|
|
setCurrentIndex(currentIndex >= oldCurrentIndex ? currentIndex + 1 : currentIndex);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 17:17:48 +02:00
|
|
|
QGraphicsWidget *page = d->pages.takeAt(index);
|
2008-11-04 00:08:39 +01:00
|
|
|
scene()->removeItem(page);
|
|
|
|
page->deleteLater();
|
|
|
|
|
2010-07-07 17:17:48 +02:00
|
|
|
if (d->pages.count() > 0) {
|
|
|
|
d->updateTabWidgetMode();
|
2009-01-25 20:21:14 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
|
|
|
}
|
|
|
|
|
2009-07-29 22:30:07 +02:00
|
|
|
QGraphicsLayoutItem *TabBar::takeTab(int index)
|
|
|
|
{
|
2009-10-17 00:41:39 +02:00
|
|
|
if (index >= d->pages.count()) {
|
2009-07-29 22:30:07 +02:00
|
|
|
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);
|
2010-09-09 22:12:03 +02:00
|
|
|
if (QGraphicsItem *item = returnItem->graphicsItem()) {
|
|
|
|
item->setParentItem(0);
|
|
|
|
}
|
2009-07-29 22:30:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
page->setLayout(0);
|
|
|
|
scene()->removeItem(page);
|
|
|
|
page->deleteLater();
|
|
|
|
|
|
|
|
if (oldCurrentIndex != currentIndex) {
|
|
|
|
setCurrentIndex(currentIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->updateTabWidgetMode();
|
|
|
|
d->tabProxy->setPreferredSize(d->tabProxy->native->sizeHint());
|
|
|
|
|
|
|
|
return returnItem;
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:54:18 +02:00
|
|
|
QGraphicsLayoutItem *TabBar::tabAt(int index)
|
|
|
|
{
|
2009-10-17 00:41:39 +02:00
|
|
|
if (index >= d->pages.count()) {
|
2009-09-02 17:54:18 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *page = d->pages.value(index);
|
|
|
|
|
|
|
|
QGraphicsLayoutItem *returnItem = 0;
|
|
|
|
QGraphicsLayout *lay = page->layout();
|
|
|
|
if (lay && lay->count() == 1) {
|
|
|
|
returnItem = lay->itemAt(0);
|
|
|
|
} else {
|
|
|
|
returnItem = lay;
|
|
|
|
}
|
2009-10-17 00:41:39 +02:00
|
|
|
|
2009-09-02 17:54:18 +02:00
|
|
|
return returnItem;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void TabBar::setTabText(int index, const QString &label)
|
|
|
|
{
|
2009-10-17 00:41:39 +02:00
|
|
|
if (index >= d->pages.count()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->tabProxy->native->setTabText(index, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TabBar::tabText(int index) const
|
|
|
|
{
|
|
|
|
return d->tabProxy->native->tabText(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::setTabIcon(int index, const QIcon &icon)
|
|
|
|
{
|
|
|
|
d->tabProxy->native->setTabIcon(index, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon TabBar::tabIcon(int index) const
|
|
|
|
{
|
|
|
|
return d->tabProxy->native->tabIcon(index);
|
|
|
|
}
|
|
|
|
|
2009-02-04 11:32:20 +01:00
|
|
|
void TabBar::setTabBarShown(bool show)
|
|
|
|
{
|
|
|
|
if (!show && !d->tabWidgetMode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!show && d->tabProxy->isVisible()) {
|
|
|
|
d->tabProxy->hide();
|
2009-12-09 18:44:56 +01:00
|
|
|
d->tabWidgetLayout->removeItem(d->tabBarLayout);
|
2009-02-04 11:32:20 +01:00
|
|
|
} else if (show && !d->tabProxy->isVisible()) {
|
|
|
|
d->tabProxy->show();
|
2009-12-09 18:44:56 +01:00
|
|
|
d->tabWidgetLayout->insertItem(0, d->tabBarLayout);
|
2009-02-04 11:32:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabBar::isTabBarShown() const
|
|
|
|
{
|
|
|
|
return d->tabProxy->isVisible();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void TabBar::setStyleSheet(const QString &stylesheet)
|
|
|
|
{
|
|
|
|
d->tabProxy->native->setStyleSheet(stylesheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TabBar::styleSheet() const
|
|
|
|
{
|
|
|
|
return d->tabProxy->native->styleSheet();
|
|
|
|
}
|
|
|
|
|
2008-11-06 00:28:07 +01:00
|
|
|
KTabBar *TabBar::nativeWidget() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
return d->tabProxy->native;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::wheelEvent(QGraphicsSceneWheelEvent * event)
|
|
|
|
{
|
2009-04-09 08:00:57 +02:00
|
|
|
Q_UNUSED(event)
|
2009-02-13 12:43:58 +01:00
|
|
|
//Still here for binary compatibility
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-09-13 21:18:29 +02:00
|
|
|
void TabBar::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::FontChange) {
|
|
|
|
d->customFont = true;
|
|
|
|
nativeWidget()->setFont(font());
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2010-07-12 10:29:49 +02:00
|
|
|
void TabBar::setFirstPositionWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
if (d->lastPositionWidget.data() == widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->firstPositionWidget) {
|
|
|
|
QGraphicsWidget *widget = d->firstPositionWidget.data();
|
|
|
|
d->tabBarLayout->removeItem(widget);
|
|
|
|
scene()->removeItem(widget);
|
|
|
|
widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->firstPositionWidget = widget;
|
|
|
|
if (widget) {
|
|
|
|
widget->setParentItem(this);
|
|
|
|
if (layoutDirection() == Qt::LeftToRight) {
|
|
|
|
d->tabBarLayout->insertItem(0, widget);
|
|
|
|
} else {
|
|
|
|
d->tabBarLayout->addItem(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QGraphicsWidget *TabBar::firstPositionWidget() const
|
|
|
|
{
|
|
|
|
return d->firstPositionWidget.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::setLastPositionWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
if (d->lastPositionWidget.data() == widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->lastPositionWidget) {
|
|
|
|
QGraphicsWidget *widget = d->lastPositionWidget.data();
|
|
|
|
d->tabBarLayout->removeItem(widget);
|
|
|
|
scene()->removeItem(widget);
|
|
|
|
widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->lastPositionWidget = widget;
|
|
|
|
if (widget) {
|
|
|
|
widget->setParentItem(this);
|
|
|
|
if (layoutDirection() == Qt::LeftToRight) {
|
|
|
|
d->tabBarLayout->addItem(widget);
|
|
|
|
} else {
|
|
|
|
d->tabBarLayout->insertItem(0, widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *TabBar::lastPositionWidget() const
|
|
|
|
{
|
|
|
|
return d->lastPositionWidget.data();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include <tabbar.moc>
|
|
|
|
|