[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/plasma/applets/kickoff/ui
From: Mohammad Mehdi Salem Naraghi <momesana () googlemail ! com>
Date: 2009-03-19 11:35:38
Message-ID: 1237462538.761378.20124.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 941290 by momesana:
simple animation of tabbar icons everytime kickoff is launched by pressing the KDE \
start button.
M +107 -35 tabbar.cpp
M +8 -2 tabbar.h
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/tabbar.cpp #941289:941290
@@ -37,6 +37,7 @@
#include <Plasma/Theme>
#include <Plasma/FrameSvg>
+
using namespace Kickoff;
TabBar::TabBar(QWidget *parent)
@@ -44,12 +45,14 @@
m_hoveredTabIndex(-1),
m_switchOnHover(true),
m_animateSwitch(true),
- m_animProgress(1.0)
+ m_animProgress(1.0),
+ m_introAnimProgress(0.0)
{
m_lastIndex[0] = -1;
connect(this, SIGNAL(currentChanged(int)), this, SLOT(startAnimation()));
m_tabSwitchTimer.setSingleShot(true);
+ m_startAnimationTimer.setSingleShot(true);
connect(&m_tabSwitchTimer, SIGNAL(timeout()), this, SLOT(switchToHoveredTab()));
setMouseTracking(true);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
@@ -193,78 +196,84 @@
return QSize(width, height);
}
-QPainterPath TabBar::tabPath(const QRect &_r)
+QPainterPath TabBar::tabPath(const QRectF &_r)
{
- const int radius = 6;
+ const qreal radius = 6 * m_introAnimProgress;
Shape s = shape();
QPainterPath path;
- QRect r = _r;
+ QRectF r = _r;
switch (s) {
case RoundedSouth:
case TriangularSouth:
+ r.setHeight(r.height() * m_introAnimProgress);
r.adjust(0, 0, 0, -3);
path.moveTo(r.topLeft());
// Top left corner
- path.quadTo(r.topLeft() + QPoint(radius, 0), r.topLeft() + QPoint(radius, \
radius));
- path.lineTo(r.bottomLeft() + QPoint(radius, -radius));
+ path.quadTo(r.topLeft() + QPointF(radius, 0), r.topLeft() + QPointF(radius, \
radius)); + path.lineTo(r.bottomLeft() + QPointF(radius, -radius));
// Bottom left corner
- path.quadTo(r.bottomLeft() + QPoint(radius, 0), r.bottomLeft() + \
QPoint(radius * 2, 0)); + path.quadTo(r.bottomLeft() + QPointF(radius, 0), \
r.bottomLeft() + QPointF(radius * 2, 0)); path.lineTo(r.bottomRight() + \
QPoint(-radius * 2, 0)); // Bottom right corner
- path.quadTo(r.bottomRight() + QPoint(-radius, 0), r.bottomRight() + \
QPoint(-radius, -radius));
- path.lineTo(r.topRight() + QPoint(-radius, radius));
+ path.quadTo(r.bottomRight() + QPointF(-radius, 0), r.bottomRight() + \
QPointF(-radius, -radius)); + path.lineTo(r.topRight() + QPointF(-radius, \
radius)); // Top right corner
- path.quadTo(r.topRight() + QPoint(-radius, 0), r.topRight());
+ path.quadTo(r.topRight() + QPointF(-radius, 0), r.topRight());
break;
case RoundedNorth:
case TriangularNorth:
+ r.setHeight(r.height() * m_introAnimProgress);
+ r.moveBottom(_r.bottom());
r.adjust(0, 3, 0, 1);
path.moveTo(r.bottomLeft());
// Bottom left corner
- path.quadTo(r.bottomLeft() + QPoint(radius, 0), r.bottomLeft() + \
QPoint(radius, -radius)); + path.quadTo(r.bottomLeft() + QPointF(radius, 0), \
r.bottomLeft() + QPointF(radius, -radius)); // Top left corner
- path.lineTo(r.topLeft() + QPoint(radius, radius));
- path.quadTo(r.topLeft() + QPoint(radius, 0), r.topLeft() + QPoint(radius * \
2, 0)); + path.lineTo(r.topLeft() + QPointF(radius, radius));
+ path.quadTo(r.topLeft() + QPoint(radius, 0), r.topLeft() + QPointF(radius * \
2, 0)); // Top right corner
- path.lineTo(r.topRight() + QPoint(-radius * 2, 0));
- path.quadTo(r.topRight() + QPoint(-radius, 0), r.topRight() + \
QPoint(-radius, radius)); + path.lineTo(r.topRight() + QPointF(-radius * 2, \
0)); + path.quadTo(r.topRight() + QPointF(-radius, 0), r.topRight() + \
QPointF(-radius, radius)); // Bottom right corner
- path.lineTo(r.bottomRight() + QPoint(-radius, -radius));
- path.quadTo(r.bottomRight() + QPoint(-radius, 0), r.bottomRight());
+ path.lineTo(r.bottomRight() + QPointF(-radius, -radius));
+ path.quadTo(r.bottomRight() + QPointF(-radius, 0), r.bottomRight());
break;
case RoundedWest:
case TriangularWest:
+ r.setWidth(r.width() * m_introAnimProgress);
+ r.moveRight(_r.right());
r.adjust(3, 0, 1, 0);
path.moveTo(r.topRight());
// Top right corner
path.lineTo(r.topRight());
- path.quadTo(r.topRight() + QPoint(0, radius), r.topRight() + QPoint(-radius, \
radius)); + path.quadTo(r.topRight() + QPointF(0, radius), r.topRight() + \
QPointF(-radius, radius)); // Top left corner
- path.lineTo(r.topLeft() + QPoint(radius, radius));
- path.quadTo(r.topLeft() + QPoint(0, radius), r.topLeft() + QPoint(0, radius \
* 2)); + path.lineTo(r.topLeft() + QPointF(radius, radius));
+ path.quadTo(r.topLeft() + QPointF(0, radius), r.topLeft() + QPointF(0, \
radius * 2)); // Bottom left corner
- path.lineTo(r.bottomLeft() + QPoint(0, -radius * 2));
- path.quadTo(r.bottomLeft() + QPoint(0, -radius), r.bottomLeft() + \
QPoint(radius, -radius)); + path.lineTo(r.bottomLeft() + QPointF(0, -radius * \
2)); + path.quadTo(r.bottomLeft() + QPointF(0, -radius), r.bottomLeft() + \
QPointF(radius, -radius)); // Bottom right corner
- path.lineTo(r.bottomRight() + QPoint(-radius, -radius));
- path.quadTo(r.bottomRight() + QPoint(0, -radius), r.bottomRight());
+ path.lineTo(r.bottomRight() + QPointF(-radius, -radius));
+ path.quadTo(r.bottomRight() + QPointF(0, -radius), r.bottomRight());
break;
case RoundedEast:
case TriangularEast:
+ r.setWidth(r.width() * m_introAnimProgress);
r.adjust(0, 0, -3, 0);
path.moveTo(r.topLeft());
// Top left corner
- path.quadTo(r.topLeft() + QPoint(0, radius), r.topLeft() + QPoint(radius, \
radius)); + path.quadTo(r.topLeft() + QPointF(0, radius), r.topLeft() + \
QPointF(radius, radius)); // Top right corner
- path.lineTo(r.topRight() + QPoint(-radius, radius));
- path.quadTo(r.topRight() + QPoint(0, radius), r.topRight() + QPoint(0, \
radius * 2)); + path.lineTo(r.topRight() + QPointF(-radius, radius));
+ path.quadTo(r.topRight() + QPointF(0, radius), r.topRight() + QPointF(0, \
radius * 2)); // Bottom right corner
- path.lineTo(r.bottomRight() + QPoint(0, -radius * 2));
- path.quadTo(r.bottomRight() + QPoint(0, -radius), r.bottomRight() + \
QPoint(-radius, -radius)); + path.lineTo(r.bottomRight() + QPointF(0, -radius \
* 2)); + path.quadTo(r.bottomRight() + QPointF(0, -radius), r.bottomRight() + \
QPointF(-radius, -radius)); // Bottom left corner
- path.lineTo(r.bottomLeft() + QPoint(radius, -radius));
- path.quadTo(r.bottomLeft() + QPoint(0, -radius), r.bottomLeft());
+ path.lineTo(r.bottomLeft() + QPointF(radius, -radius));
+ path.quadTo(r.bottomLeft() + QPointF(0, -radius), r.bottomLeft());
break;
}
@@ -284,7 +293,7 @@
painter.setFont(KGlobalSettings::smallestReadableFont());
// Drawing Tabborders
- QRect movingRect;
+ QRectF movingRect;
if (m_currentAnimRect.isNull()) {
movingRect = tabRect(currentIndex());
@@ -297,6 +306,7 @@
painter.setPen(QPen(palette().base(), 1));
painter.setRenderHint(QPainter::Antialiasing);
+
painter.fillPath(path, palette().base());
painter.restore();
@@ -308,11 +318,53 @@
QRect rect = tabRect(i).adjusted(TAB_CONTENTS_MARGIN, TAB_CONTENTS_MARGIN,
-TAB_CONTENTS_MARGIN, \
-TAB_CONTENTS_MARGIN); // draw tab icon
- QRect iconRect = rect;
+ QRectF iconRect = rect;
iconRect.setBottom(iconRect.bottom() - textHeight);
iconRect.adjust(0, (isVertical() ? 1 : 0) * TAB_CONTENTS_MARGIN + 3, 0, 0);
- tabIcon(i).paint(&painter, iconRect);
+ if (!qFuzzyCompare(m_introAnimProgress, 1.0)) {
+ QRectF centerRect = iconRect;
+ centerRect.moveCenter(this->rect().center());
+
+ qreal distance = QLineF(iconRect.center(), centerRect.center()).length() \
* m_introAnimProgress; +
+ Shape s = shape();
+ switch (s) {
+ case RoundedNorth:
+ case RoundedSouth:
+ case TriangularNorth:
+ case TriangularSouth:
+ centerRect.moveTop(iconRect.top());
+ if (iconRect.left() < centerRect.left()) {
+ iconRect.moveCenter(centerRect.center() - QPoint(distance, \
0)); + } else {
+ iconRect.moveCenter(centerRect.center() + QPoint(distance, \
0)); + }
+ break;
+ case RoundedEast:
+ case RoundedWest:
+ case TriangularEast:
+ case TriangularWest:
+ centerRect.moveLeft(iconRect.left());
+ if (iconRect.top() < centerRect.top()) {
+ iconRect.moveCenter(centerRect.center() - QPoint(0, \
distance)); + } else {
+ iconRect.moveCenter(centerRect.center() + QPoint(0, \
distance)); + }
+ break;
+ }
+
+ // icon zoom effect
+ QPointF iconCenter = iconRect.center();
+ const qreal MIN_ZOOM = 0.8;
+ iconRect.setWidth(iconRect.width() * MIN_ZOOM + iconRect.width() * (1.0 \
- MIN_ZOOM) * m_introAnimProgress); + iconRect.setHeight(iconRect.height() \
* MIN_ZOOM + iconRect.height() * (1.0 - MIN_ZOOM) * m_introAnimProgress); + \
iconRect.moveCenter(iconCenter); +
+ painter.setOpacity(m_introAnimProgress);
+ }
+ tabIcon(i).paint(&painter, iconRect.toRect());
+
// draw tab text
if (i != currentTab || m_animProgress < 0.9) {
//painter.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), \
0)); @@ -368,16 +420,29 @@
{
storeLastIndex();
Plasma::Animator::self()->customAnimation(10, 150, \
Plasma::Animator::EaseInOutCurve, this, "onValueChanged"); +}
+void TabBar::startIntroAnimation()
+{
+ Plasma::Animator::self()->customAnimation(10, 200, \
Plasma::Animator::EaseInCurve, this, "onIntroValueChanged"); }
+void TabBar::showEvent(QShowEvent* event)
+{
+ QTimer::singleShot(250, this, SLOT(startIntroAnimation()));
+}
+
+void TabBar::hideEvent(QHideEvent* event)
+{
+ m_introAnimProgress = 0.0;
+}
+
void TabBar::onValueChanged(qreal value)
{
if ((m_animProgress = value) == 1.0) {
animationFinished();
return;
}
-
// animation rect
QRect rect = tabRect(currentIndex());
QRect lastRect = tabRect(lastIndex());
@@ -388,6 +453,13 @@
update();
}
+void TabBar::onIntroValueChanged(qreal value)
+{
+ m_introAnimProgress = value;
+
+ update();
+}
+
void TabBar::animationFinished()
{
m_currentAnimRect = QRect();
--- trunk/KDE/kdebase/workspace/plasma/applets/kickoff/ui/tabbar.h #941289:941290
@@ -60,6 +60,8 @@
virtual void leaveEvent(QEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent* event);
+ virtual void showEvent(QShowEvent* event);
+ virtual void hideEvent(QHideEvent* event);
bool isHorizontal() const;
bool isVertical() const;
@@ -69,18 +71,22 @@
void animationFinished();
void startAnimation();
void onValueChanged(qreal val);
+ void onIntroValueChanged(qreal val);
+ void startIntroAnimation();
private:
- QPainterPath tabPath(const QRect &r);
+ QPainterPath tabPath(const QRectF &r);
static const int TAB_CONTENTS_MARGIN = 6;
int m_hoveredTabIndex;
QTimer m_tabSwitchTimer;
+ QTimer m_startAnimationTimer;
bool m_switchOnHover;
bool m_animateSwitch;
- QRect m_currentAnimRect;
+ QRectF m_currentAnimRect;
int m_lastIndex[2];
qreal m_animProgress;
+ qreal m_introAnimProgress;
Plasma::FrameSvg *background;
QSize tabSize(int index) const;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic