diff --git a/CMakeLists.txt b/CMakeLists.txt index 72a1b5b13..cb2a619db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,8 @@ set(plasma_LIB_SRCS animations/pause.cpp animations/pulser.cpp animations/rotation.cpp + animations/rotationstacked.cpp + animations/stackedlayout.cpp applet.cpp configloader.cpp containment.cpp @@ -353,6 +355,7 @@ install(FILES animations/abstractanimation.h animations/animation.h animations/animationgroup.h + animations/rotationstacked.h DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/animations COMPONENT Devel) diff --git a/animations/rotationstacked.cpp b/animations/rotationstacked.cpp new file mode 100644 index 000000000..0f1188c00 --- /dev/null +++ b/animations/rotationstacked.cpp @@ -0,0 +1,152 @@ +/***********************************************************************/ +/* stackedlayout.h */ +/* */ +/* Copyright(C) 2009 Igor Trindade Oliveira */ +/* */ +/* This library is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU Lesser General Public */ +/* License as published by the Free Software Foundation; either */ +/* version 2.1 of the License, or (at your option) any later version. */ +/* */ +/* This library 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 */ +/* Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public */ +/* License along with this library; if not, write to the Free Software */ +/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA */ +/* 02110-1301 USA */ +/***********************************************************************/ + +#include "rotationstacked.h" +#include "stackedlayout.h" + +#include +#include + +namespace Plasma +{ + +class RotationStackedAnimationPrivate { + public: + QGraphicsRotation *backRotation; + QGraphicsRotation *frontRotation; + + AbstractAnimation::Reference reference; + + QPair animObjects; + + StackedLayout *sLayout; +}; + +RotationStackedAnimation::RotationStackedAnimation(QObject *parent) + : d(new RotationStackedAnimationPrivate) +{ + d->backRotation = new QGraphicsRotation(this); + d->frontRotation = new QGraphicsRotation(this); + + d->sLayout = new StackedLayout; +} + +RotationStackedAnimation::~RotationStackedAnimation() +{ + delete d->sLayout; + delete d; +} + +void RotationStackedAnimation::setReference(AbstractAnimation::Reference reference) +{ + d->reference = reference; +} + +AbstractAnimation::Reference RotationStackedAnimation::reference() +{ + return d->reference; +} + +void RotationStackedAnimation::setWidgetsToAnimate(QGraphicsWidget *front, QGraphicsWidget *back) +{ + d->animObjects = qMakePair(front, back); + + d->sLayout->addWidget(front); + d->sLayout->addWidget(back); +} + +QGraphicsLayoutItem *RotationStackedAnimation::layout() +{ + return d->sLayout; +} + +QPair RotationStackedAnimation::widgetsToAnimate() +{ + return d->animObjects; +} + +QAbstractAnimation *RotationStackedAnimation::render(QObject *parent) +{ + Q_UNUSED(parent); + + QPair widgets = widgetsToAnimate(); + + QSequentialAnimationGroup *groupAnim = new QSequentialAnimationGroup(parent); + + QPropertyAnimation *frontAnim = new QPropertyAnimation(d->frontRotation, "angle", groupAnim); + QPropertyAnimation *backAnim = new QPropertyAnimation(d->backRotation, "angle", groupAnim); + + const qreal widgetFrontWidth = widgets.first->size().width(); + const qreal widgetFrontHeight = widgets.first->size().height(); + + const qreal widgetBackWidth = widgets.second->size().width(); + const qreal widgetBackHeight = widgets.second->size().height(); + + QPair vector; + + if(reference() == Center) { + + vector.first = QVector3D(widgetFrontWidth/2, widgetFrontHeight/2, 0); + vector.second = QVector3D(widgetBackWidth/2, widgetBackHeight/2, 0); + + if(direction() == MoveLeft || direction() == MoveRight) { + d->frontRotation->setAxis(Qt::YAxis); + d->backRotation->setAxis(Qt::YAxis); + + if(direction() == MoveLeft) { + d->backRotation->setAngle(265); + backAnim->setEndValue(360); + frontAnim->setEndValue(90); + } else { + d->backRotation->setAngle(-90); + } + } + } + + d->frontRotation->setOrigin(vector.first); + d->backRotation->setOrigin(vector.second); + + QList backTransformation; + QList frontTransformation; + + frontTransformation.append(d->frontRotation); + backTransformation.append(d->backRotation); + + widgets.first->setTransformations(frontTransformation); + widgets.second->setTransformations(backTransformation); + + frontAnim->setDuration(duration()/2); + backAnim->setDuration(duration()/2); + + connect(frontAnim, SIGNAL(finished()), this, SLOT(rotateBackWidget())); + + groupAnim->addAnimation(frontAnim); + groupAnim->addAnimation(backAnim); + + return groupAnim; +} + +void RotationStackedAnimation::rotateBackWidget() +{ + d->sLayout->setCurrentWidgetIndex(1); +} + +} diff --git a/animations/rotationstacked.h b/animations/rotationstacked.h new file mode 100644 index 000000000..b6ff724e8 --- /dev/null +++ b/animations/rotationstacked.h @@ -0,0 +1,59 @@ +#//////////////////////////////////////////////////////////////////////// +// rotation.cpp // +// // +// Copyright(C) 2009 Igor Trindade Oliveira // +// // +// This library is free software; you can redistribute it and/or // +// modify it under the terms of the GNU Lesser General Public // +// License as published by the Free Software Foundation; either // +// version 2.1 of the License, or (at your option) any later version. // +// // +// This library 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 // +// Lesser General Public License for more details. // +// // +// You should have received a copy of the GNU Lesser General Public // +// License along with this library; if not, write to the Free Software // +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // +// 02110-1301 USA // +///////////////////////////////////////////////////////////////////////// + +#ifndef ROTATIONSTACKED_H +#define ROTATIONSTACKED_H + +#include +#include + +namespace Plasma { + +class RotationStackedAnimationPrivate; + +class RotationStackedAnimation : public Animation +{ + Q_OBJECT + + public: + RotationStackedAnimation(QObject *parent = 0); + ~RotationStackedAnimation(); + + QAbstractAnimation *render(QObject *parent = 0); + + void setReference(Reference reference); + Reference reference(); + + QGraphicsLayoutItem *layout(); + + void setWidgetsToAnimate(QGraphicsWidget *front, QGraphicsWidget *back); + + QPair widgetsToAnimate(); + + public Q_SLOTS: + void rotateBackWidget(); + + private: + RotationStackedAnimationPrivate *d; +}; +} // Plasma + +#endif diff --git a/animations/stackedlayout.cpp b/animations/stackedlayout.cpp new file mode 100644 index 000000000..fa8bc040c --- /dev/null +++ b/animations/stackedlayout.cpp @@ -0,0 +1,103 @@ +/***********************************************************************/ +/* stackedlayout.h */ +/* */ +/* Copyright(C) 2009 Igor Trindade Oliveira */ +/* */ +/* This library is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU Lesser General Public */ +/* License as published by the Free Software Foundation; either */ +/* version 2.1 of the License, or (at your option) any later version. */ +/* */ +/* This library 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 */ +/* Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public */ +/* License along with this library; if not, write to the Free Software */ +/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA */ +/* 02110-1301 USA */ +/***********************************************************************/ + +#include "stackedlayout.h" + +#include +#include + +StackedLayout::StackedLayout(QGraphicsLayoutItem *parent) + : QGraphicsLayout(parent), m_currentWidgetIndex(-1) +{ +} + +StackedLayout::~StackedLayout() +{ +} + +void StackedLayout::setGeometry(const QRectF &rect) +{ + QGraphicsLayout::setGeometry(rect); + + for(int i = 0; i < items.size(); i++) { + itemAt(i)->setGeometry(rect); + } +} + +QSizeF StackedLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + Q_UNUSED(which); + Q_UNUSED(constraint); + + qreal left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + + QSizeF currentWidgetSize = itemAt(m_currentWidgetIndex)->effectiveSizeHint(which, constraint); + + return QSizeF( left + right + currentWidgetSize.width(), right + bottom + currentWidgetSize.height()); +} + +int StackedLayout::count() const +{ + return items.count(); +} + +QGraphicsLayoutItem *StackedLayout::itemAt(int i) const +{ + return items.at(i); +} + +void StackedLayout::insertWidget(QGraphicsLayoutItem *item, int pos) +{ + if(!pos && (m_currentWidgetIndex == -1)) { + m_currentWidgetIndex = 0; + } else { + item->graphicsItem()->hide(); + } + + items.insert(pos, item); +} + +void StackedLayout::addWidget(QGraphicsLayoutItem *item) +{ + insertWidget(item, items.size()); +} + +void StackedLayout::removeAt(int index) +{ + items.removeAt(index); +} + +void StackedLayout::setCurrentWidgetIndex(qint32 index) +{ + QGraphicsItem *currentWidget = itemAt(m_currentWidgetIndex)->graphicsItem(); + QGraphicsItem *hidenWidget = itemAt(index)->graphicsItem(); + + currentWidget->hide(); + hidenWidget->show(); + + m_currentWidgetIndex = index; +} + +qint32 StackedLayout::currentWidgetIndex() const +{ + return m_currentWidgetIndex; +} diff --git a/animations/stackedlayout.h b/animations/stackedlayout.h new file mode 100644 index 000000000..4d14b16f1 --- /dev/null +++ b/animations/stackedlayout.h @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////////////////// +// rotation.cpp // +// // +// Copyright(C) 2009 Igor Trindade Oliveira // +// // +// This library is free software; you can redistribute it and/or // +// modify it under the terms of the GNU Lesser General Public // +// License as published by the Free Software Foundation; either // +// version 2.1 of the License, or (at your option) any later version. // +// // +// This library 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 // +// Lesser General Public License for more details. // +// // +// You should have received a copy of the GNU Lesser General Public // +// License along with this library; if not, write to the Free Software // +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // +// 02110-1301 USA // +///////////////////////////////////////////////////////////////////////// + +#ifndef STACKEDLAYOUT_H +#define STACKEDLAYOUT_H + +#include +#include + +class StackedLayout : public QGraphicsLayout { + public: + StackedLayout(QGraphicsLayoutItem *parent = 0); + ~StackedLayout(); + + void setGeometry(const QRectF &rect); + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const; + int count() const; + QGraphicsLayoutItem *itemAt(int i) const; + + void insertWidget(QGraphicsLayoutItem *item, int pos); + void addWidget(QGraphicsLayoutItem *item); + + void removeAt(int index); + + qint32 currentWidgetIndex() const; + void setCurrentWidgetIndex(qint32 index); + + private: + QList items; + qint32 m_currentWidgetIndex; +}; + +#endif