[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/stage-paulm-test3] stage/part: Add motion path icon in KPrShapeAnimations
From:       Paul Mendez <paulestebanms () gmail ! com>
Date:       2012-08-02 1:28:40
Message-ID: 20120802012840.8EF9EA6094 () git ! kde ! org
[Download RAW message or body]

Git commit 1f684e18893c61f3634bb1d925c94597c1bbde6f by Paul Mendez.
Committed on 02/08/2012 at 03:27.
Pushed by mendez into branch 'stage-paulm-test3'.

Add motion path icon in KPrShapeAnimations

M  +38   -1    stage/part/KPrShapeAnimations.cpp
M  +5    -0    stage/part/animations/KPrAnimateMotion.cpp
M  +1    -0    stage/part/animations/KPrAnimateMotion.h

http://commits.kde.org/calligra/1f684e18893c61f3634bb1d925c94597c1bbde6f

diff --git a/stage/part/KPrShapeAnimations.cpp b/stage/part/KPrShapeAnimations.cpp
index 92b08a1..859761f 100644
--- a/stage/part/KPrShapeAnimations.cpp
+++ b/stage/part/KPrShapeAnimations.cpp
@@ -23,12 +23,14 @@
 #include <QList>
 #include <QSet>
 #include <QPainter>
+#include <QPainterPath>
 
 //Stage Headers
 #include "KPrPage.h"
 #include "KPrView.h"
 #include "KPrDocument.h"
 #include "animations/KPrAnimationSubStep.h"
+#include "animations/KPrAnimateMotion.h"
 #include "commands/KPrAnimationRemoveCommand.h"
 #include "commands/KPrReorderAnimationCommand.h"
 #include <commands/KPrEditAnimationTimeLineCommand.h>
@@ -42,6 +44,7 @@
 #include <KoPADocument.h>
 #include <KoShapePainter.h>
 #include <KoShapeContainer.h>
+#include <KoPathShape.h>
 
 //KDE Headers
 #include <KIcon>
@@ -973,7 +976,41 @@ QPixmap KPrShapeAnimations::getAnimationIcon(KPrShapeAnimation \
*animation) const  return QPixmap();
     }
     QString name = getAnimationName(animation, true);
-    if (!name.isEmpty()) {
+    // Return Path Motion Animation icon
+    if (animation->presetClass() == KPrShapeAnimation::MotionPath) {
+        QPainterPath m_path = QPainterPath();
+        for (int i = 0; i < animation->animationCount(); i++) {
+            if (KPrAnimateMotion *motion = dynamic_cast<KPrAnimateMotion \
*>(animation->animationAt(i))) { +                m_path = motion->path();
+                break;
+            }
+        }
+        if (!m_path.isEmpty()) {
+            const int margin = 8;
+            const int width = 4;
+            QImage thumb(QSize(KIconLoader::SizeHuge, KIconLoader::SizeHuge), \
QImage::Format_RGB32); +            // fill backgroung
+            thumb.fill(QColor(Qt::white).rgb());
+            QRect imageRect = thumb.rect();
+            // adjust to left space for margins
+            imageRect.adjust(margin, margin, -margin, -margin);
+            KoPathShape pathShape = \
*(KoPathShape::createShapeFromPainterPath(m_path)); +            \
pathShape.setSize(imageRect.size()); +            m_path = pathShape.outline();
+            //Center path
+            m_path.translate(-m_path.boundingRect().x() + margin, \
-m_path.boundingRect().y() + margin); +            QPainter painter(&thumb);
+            painter.setPen(QPen(QColor(0, 100, 224), width, Qt::SolidLine,
+                                Qt::FlatCap, Qt::MiterJoin));
+            painter.drawPath(m_path);
+            QPixmap iconPixmap;
+            if (iconPixmap.convertFromImage(thumb)) {
+                return iconPixmap;
+            }
+        }
+    }
+    // Return animation icon
+    else if (!name.isEmpty()) {
         name = name.append("_animation");
         name.replace(" ", "_");
         QString path = KIconLoader::global()->iconPath(name, KIconLoader::Toolbar, \
                true);
diff --git a/stage/part/animations/KPrAnimateMotion.cpp \
b/stage/part/animations/KPrAnimateMotion.cpp index 575cef1..2e9c144 100644
--- a/stage/part/animations/KPrAnimateMotion.cpp
+++ b/stage/part/animations/KPrAnimateMotion.cpp
@@ -84,6 +84,11 @@ void KPrAnimateMotion::init(KPrAnimationCache *animationCache, int \
step)  }
 }
 
+QPainterPath KPrAnimateMotion::path()
+{
+    return m_path;
+}
+
 void KPrAnimateMotion::next(int currentTime)
 {
     Q_ASSERT(m_animationCache);
diff --git a/stage/part/animations/KPrAnimateMotion.h \
b/stage/part/animations/KPrAnimateMotion.h index 29cdd3f..752080c 100644
--- a/stage/part/animations/KPrAnimateMotion.h
+++ b/stage/part/animations/KPrAnimateMotion.h
@@ -33,6 +33,7 @@ public:
     virtual bool loadOdf( const KoXmlElement &element, KoShapeLoadingContext \
&context );  virtual bool saveOdf(KoPASavingContext & paContext) const;
     virtual void init(KPrAnimationCache *animationCache, int step);
+    QPainterPath path();
 
 protected:
     virtual void next(int currentTime);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic