[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [sflphone-kde/october2012_ui] src/klib: [ #16349 ] Add full animation support to on canvas tips
From: Emmanuel Lepage Vallee <emmanuel.lepage () savoirfairelinux ! com>
Date: 2012-10-31 20:09:16
Message-ID: 20121031200916.11729A6078 () git ! kde ! org
[Download RAW message or body]
Git commit 78a358b48b3e28d9e9b6cd0e7d8edde42f83647f by Emmanuel Lepage Vallee.
Committed on 31/10/2012 at 21:08.
Pushed by lepagevalleeemmanuel into branch 'october2012_ui'.
[ #16349 ] Add full animation support to on canvas tips
M +5 -5 src/klib/svgtiploader.cpp
M +9 -9 src/klib/svgtiploader.h
M +1 -1 src/klib/tip.cpp
M +2 -0 src/klib/tip.h
M +72 -3 src/klib/tipanimationwrapper.cpp
M +10 -6 src/klib/tipanimationwrapper.h
http://commits.kde.org/sflphone-kde/78a358b48b3e28d9e9b6cd0e7d8edde42f83647f
diff --git a/src/klib/svgtiploader.cpp b/src/klib/svgtiploader.cpp
index b4ba193..71da381 100644
--- a/src/klib/svgtiploader.cpp
+++ b/src/klib/svgtiploader.cpp
@@ -63,7 +63,7 @@ void SvgTipLoader::reload()
m_CurrentImage.fill( m_OriginalPalette.base().color() );
QPainter p(&m_CurrentImage);
- if (effectiveHeight >= m_pAnim.tipSize().height() && m_pCurrentTip) {
+ if (effectiveHeight >= m_pAnim.tipSize().height() /*&& m_pCurrentTip*/) {
p.setOpacity(0.1*m_CurrentFrame.opacity);
p.drawImage(m_CurrentFrame.point.x(),m_CurrentFrame.point.y(),m_pAnim.currentImage());
}
@@ -124,12 +124,12 @@ void SvgTipLoader::setBottomMargin(int margin)
void SvgTipLoader::setCurrentTip(bool tip)
{
m_pCurrentTip = tip;
- if (tip) {
- m_pAnim.start();
+ /*if (tip) {
}
else {
- m_CurrentFrame = {QPoint(0,0),QRect(0,0,0,0),0};
- }
+ //m_CurrentFrame = {QPoint(0,0),QRect(0,0,0,0),0};
+ }*/
+ m_pAnim.start(tip);
changeSize();
}
diff --git a/src/klib/svgtiploader.h b/src/klib/svgtiploader.h
index 8ba7d11..5c44486 100644
--- a/src/klib/svgtiploader.h
+++ b/src/klib/svgtiploader.h
@@ -71,15 +71,15 @@ private:
void reload();
//Attributes
- QPalette m_OriginalPalette;
- QTreeView* m_pParent ;
- int m_TopMargin ;
- int m_BottomMargin ;
- QImage m_CurrentImage ;
- Tip m_Tip ;
- bool m_pCurrentTip;
- TipAnimationWrapper m_pAnim;
- FrameDescription m_CurrentFrame;
+ QPalette m_OriginalPalette;
+ QTreeView* m_pParent ;
+ int m_TopMargin ;
+ int m_BottomMargin ;
+ QImage m_CurrentImage ;
+ Tip m_Tip ;
+ bool m_pCurrentTip ;
+ TipAnimationWrapper m_pAnim ;
+ FrameDescription m_CurrentFrame ;
private slots:
void animationStep(FrameDescription desc);
diff --git a/src/klib/tip.cpp b/src/klib/tip.cpp
index 12ac8e2..691572b 100644
--- a/src/klib/tip.cpp
+++ b/src/klib/tip.cpp
@@ -30,7 +30,7 @@
///Constructor
Tip::Tip(QWidget* parent,const QString& path, const QString& text, int maxLine) : \
QObject(parent),m_OriginalText(text),m_MaxLine(maxLine),m_Position(TipPosition::Bottom),m_IsMaxSize(false),m_pR(nullptr),
-m_OriginalPalette(parent->palette()),m_AnimationIn(TipAnimation::TranslationTop),m_AnimationOut(TipAnimation::Fade)
+m_OriginalPalette(parent->palette()),m_AnimationIn(TipAnimation::TranslationTop),m_AnimationOut(TipAnimation::TranslationTop)
{
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
diff --git a/src/klib/tip.h b/src/klib/tip.h
index 19447dd..b49a5a2 100644
--- a/src/klib/tip.h
+++ b/src/klib/tip.h
@@ -53,6 +53,8 @@ public:
Fade,
TranslationTop,
TranslationBottom,
+ TranslationLeft,
+ TranslationRight,
None
};
diff --git a/src/klib/tipanimationwrapper.cpp b/src/klib/tipanimationwrapper.cpp
index 286e306..e3a8c20 100644
--- a/src/klib/tipanimationwrapper.cpp
+++ b/src/klib/tipanimationwrapper.cpp
@@ -54,13 +54,26 @@ QSize TipAnimationWrapper::tipSize()
return m_TipSize;
}
-void TipAnimationWrapper::start()
+/**
+ * Start the animation (if any)
+ * @param show start the 'in' or 'out' animation
+ */
+void TipAnimationWrapper::start(bool show)
{
if (!m_pTimer) {
m_pTimer = new QTimer(this);
connect(m_pTimer,SIGNAL(timeout()),this,SLOT(step()));
}
- m_pTimer->start(33);
+
+ m_Step = 0;
+ m_CurrentAnimation = show?m_pTip->m_AnimationIn:m_pTip->m_AnimationOut;
+ m_FadeDirection = show;
+ if (m_CurrentAnimation != Tip::None)
+ m_pTimer->start(33);
+ else {
+ step();
+ emit animationEnded();
+ }
}
void TipAnimationWrapper::step()
@@ -69,6 +82,7 @@ void TipAnimationWrapper::step()
if (m_Step > m_MaxStep && m_pTimer) {
m_Step = 0;
m_pTimer->stop();
+ emit animationEnded();
}
else {
int wy = 0;
@@ -90,6 +104,61 @@ void TipAnimationWrapper::step()
break;
}
- emit animationStep({QPoint(wx,wy),QRect(0,0,0,0),(float)m_Step/m_MaxStep});
+ //Set opacity
+ float opacity = (float)((m_FadeDirection)?0.0:1.0)-((float)m_Step/m_MaxStep);
+ opacity = (opacity<0)?-opacity:opacity;
+
+ //In animations
+ if (m_FadeDirection) {
+ switch (m_CurrentAnimation) {
+ case Tip::Fade:
+ break;
+ case Tip::TranslationTop:
+ wy += -m_MaxStep+m_Step;
+ break;
+ case Tip::TranslationBottom:
+ wy += m_MaxStep-m_Step;
+ break;
+ case Tip::TranslationLeft:
+ wx += -m_MaxStep+m_Step;
+ break;
+ case Tip::TranslationRight:
+ wx += m_MaxStep-m_Step;
+ break;
+ case Tip::None:
+ opacity = 1;
+ m_Step = 0;
+ break;
+ }
+ }
+ //Out animations
+ else {switch (m_CurrentAnimation) {
+ case Tip::Fade:
+ break;
+ case Tip::TranslationTop:
+ wy += m_Step;
+ break;
+ case Tip::TranslationBottom:
+ wy += -m_Step;
+ break;
+ case Tip::TranslationLeft:
+ wx += m_Step;
+ break;
+ case Tip::TranslationRight:
+ wx += -m_Step;
+ break;
+ case Tip::None:
+ opacity = 0;
+ m_Step = 0;
+ break;
+ }
+ }
+
+ emit animationStep({QPoint(wx,wy),QRect(0,0,0,0),opacity});
}
+}
+
+bool TipAnimationWrapper::isRunning()
+{
+ return m_Step!=0;
}
\ No newline at end of file
diff --git a/src/klib/tipanimationwrapper.h b/src/klib/tipanimationwrapper.h
index 1ff4bca..a006050 100644
--- a/src/klib/tipanimationwrapper.h
+++ b/src/klib/tipanimationwrapper.h
@@ -26,7 +26,7 @@
class QTimer;
//SFLPhone
-class Tip;
+#include "tip.h"
class SvgTipLoader;
//Structs
@@ -44,17 +44,20 @@ public:
virtual ~TipAnimationWrapper();
//Mutator
- void start();
+ void start(bool show = true);
//Getter
const QImage& currentImage();
- QSize tipSize();
+ QSize tipSize();
+ bool isRunning();
private:
//Attributes
- QTimer* m_pTimer;
- Tip* m_pTip;
- int m_Step;
+ QTimer* m_pTimer;
+ Tip* m_pTip;
+ int m_Step;
+ Tip::TipAnimation m_CurrentAnimation;
+ bool m_FadeDirection;
QRect m_ParentRect;
QSize m_TipSize;
@@ -69,5 +72,6 @@ private slots:
signals:
void animationStep(FrameDescription desc);
+ void animationEnded();
};
#endif
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic