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

List:       kde-commits
Subject:    [declarative-plasmoids] tasks: wheel in C++ wrapper for qml tasks
From:       Shaun Reich <shaun.reich () kdemail ! net>
Date:       2012-02-10 16:32:05
Message-ID: 20120210163205.2A335A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 57016b2ffa07b89a57b71e443e0070f540714c6e by Shaun Reich.
Committed on 10/02/2012 at 17:31.
Pushed by sreich into branch 'master'.

wheel in C++ wrapper for qml tasks

M  +10   -2    tasks/CMakeLists.txt
C  +1    -1    tasks/qml/CMakeLists.txt [from: tasks/CMakeLists.txt - 091% \
similarity] R  +0    -0    tasks/qml/Messages.sh [from: tasks/Messages.sh - 100% \
similarity] R  +0    -0    tasks/qml/package/contents/config/main.xml [from: \
tasks/package/contents/config/main.xml - 100% similarity] R  +0    -0    \
tasks/qml/package/contents/ui/main.qml [from: tasks/package/contents/ui/main.qml - \
100% similarity] C  +0    -0    tasks/qml/package/metadata.desktop [from: \
tasks/package/metadata.desktop - 100% similarity] R  +0    -0    \
tasks/qml/plasma-applet-tasks-qml.desktop [from: tasks/package/metadata.desktop - \
100% similarity] A  +188  -0    tasks/tasks.cpp     [License: GPL (v2+)]
A  +48   -0    tasks/tasks.h     [License: GPL (v2+)]

http://commits.kde.org/declarative-plasmoids/57016b2ffa07b89a57b71e443e0070f540714c6e

diff --git a/tasks/CMakeLists.txt b/tasks/CMakeLists.txt
index bf8b2ac..014f559 100644
--- a/tasks/CMakeLists.txt
+++ b/tasks/CMakeLists.txt
@@ -1,6 +1,14 @@
-project(dictionary)
+project(tasks-qml)
 
-install(DIRECTORY package/ DESTINATION \
${DATA_INSTALL_DIR}/plasma/plasmoids/org.kde.tasks-qml PATTERN .svn EXCLUDE) +
+set(tasks_qml_SRCS tasks.cpp)
+
+kde4_add_plugin(plasma_applet_tasks_qml ${tasks_qml_SRCS})
+target_link_libraries(plasma_applet_tasks_qml
+                      ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS})
+
+install(TARGETS plasma_applet_tasks_qml
+        DESTINATION ${PLUGIN_INSTALL_DIR})
 
 install(FILES plasma-applet-tasks-qml.desktop
         DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/tasks/CMakeLists.txt b/tasks/qml/CMakeLists.txt
similarity index 91%
copy from tasks/CMakeLists.txt
copy to tasks/qml/CMakeLists.txt
index bf8b2ac..ceb2c88 100644
--- a/tasks/CMakeLists.txt
+++ b/tasks/qml/CMakeLists.txt
@@ -1,4 +1,4 @@
-project(dictionary)
+project(tasks-qml)
 
 install(DIRECTORY package/ DESTINATION \
${DATA_INSTALL_DIR}/plasma/plasmoids/org.kde.tasks-qml PATTERN .svn EXCLUDE)  
diff --git a/tasks/Messages.sh b/tasks/qml/Messages.sh
similarity index 100%
rename from tasks/Messages.sh
rename to tasks/qml/Messages.sh
diff --git a/tasks/package/contents/config/main.xml \
b/tasks/qml/package/contents/config/main.xml similarity index 100%
rename from tasks/package/contents/config/main.xml
rename to tasks/qml/package/contents/config/main.xml
diff --git a/tasks/package/contents/ui/main.qml \
b/tasks/qml/package/contents/ui/main.qml similarity index 100%
rename from tasks/package/contents/ui/main.qml
rename to tasks/qml/package/contents/ui/main.qml
diff --git a/tasks/package/metadata.desktop b/tasks/qml/package/metadata.desktop
similarity index 100%
copy from tasks/package/metadata.desktop
copy to tasks/qml/package/metadata.desktop
diff --git a/tasks/package/metadata.desktop \
b/tasks/qml/plasma-applet-tasks-qml.desktop similarity index 100%
rename from tasks/package/metadata.desktop
rename to tasks/qml/plasma-applet-tasks-qml.desktop
diff --git a/tasks/tasks.cpp b/tasks/tasks.cpp
new file mode 100644
index 0000000..5a7229f
--- /dev/null
+++ b/tasks/tasks.cpp
@@ -0,0 +1,188 @@
+/***************************************************************************
+ *   Copyright 2008-2009 by Olivier Goffart <ogoffart@kde.org>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, 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 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 "eyes.h"
+
+#include <QPainter>
+#include <QGraphicsView>
+
+#include <Plasma/Theme>
+#include <KDebug>
+
+#include <math.h>
+
+Eyes::Eyes(QObject *parent, const QVariantList &args)
+    : Plasma::Applet(parent, args) , timerInterval(50),  previousMousePos(-1,-1)
+{
+    resize(192, 128);
+
+    m_svg = new Plasma::Svg(this);
+    m_svg->setImagePath(QLatin1String( "widgets/eyes" ));
+    m_svg->setContainsMultipleImages(true);
+
+    rightPupil = new Plasma::SvgWidget(this);
+    rightPupil->setSvg(m_svg);
+    rightPupil->setElementID(QLatin1String( "rightPupil" ));
+
+    leftPupil = new Plasma::SvgWidget(this);
+    leftPupil->setSvg(m_svg);
+    leftPupil->setElementID(QLatin1String( "leftPupil" ));
+
+    timerId = startTimer(50);
+    setAspectRatioMode(Plasma::IgnoreAspectRatio);
+    setHasConfigurationInterface(false);
+}
+
+Eyes::~Eyes()
+{
+
+}
+
+void Eyes::constraintsEvent(Plasma::Constraints constraints)
+{
+    Q_UNUSED(constraints)
+
+    if (constraints & Plasma::FormFactorConstraint) {
+        setBackgroundHints(NoBackground);
+    }
+
+    if (constraints & Plasma::SizeConstraint) {
+        if(formFactor() == Plasma::Vertical) {
+            setMinimumSize(QSizeF(0, boundingRect().width()/1.5));
+            setMaximumSize(QSizeF(-1, boundingRect().width()/1.5));
+        } else if(formFactor() == Plasma::Horizontal) {
+            setMinimumSize(QSizeF(boundingRect().height()*1.5,0));
+            setMaximumSize(QSizeF(boundingRect().height()*1.5,-1));
+        } else {
+            setMinimumSize(QSizeF());
+            setMaximumSize(QSizeF());
+        }
+
+        double pupilSize = qMin( qMin(boundingRect().width()/2, \
boundingRect().height()) / 5, +                                 \
(boundingRect().width()/2 + boundingRect().height()) / 12); +
+        leftPupil->resize(pupilSize, pupilSize);
+        rightPupil->resize(pupilSize, pupilSize);
+    }
+    previousMousePos = QPoint(-1,-1);
+}
+
+void Eyes::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option,
+                        const QRect &contentsRect)
+{
+    Q_UNUSED(option)
+    QRect rect = contentsRect;
+    rect.setWidth(rect.width()/2 - 2);
+    m_svg->paint(p, rect, QLatin1String( "leftEye" ));
+    rect.translate(rect.width() + 2*2 , 0);
+    m_svg->paint(p, rect, QLatin1String( "rightEye" ));
+}
+
+
+
+static QPointF pupilPos( const QRectF &eyesRect, const QPointF &mousePos)
+{
+    const QPointF vect = mousePos - eyesRect.center();     //cursor position \
relative to the center of the eyes +    const qreal abs_vect = vect.x() * vect.x() + \
vect.y() * vect.y(); +
+    if (qFuzzyCompare(vect.x() + 1 , qreal(1.0))) {
+        if (vect.y() > eyesRect.height()/2) {
+            return eyesRect.center() + QPoint( 0, eyesRect.height()/2);
+        } else if (vect.y() < -eyesRect.height()/2) {
+            return eyesRect.center() + QPoint( 0, -eyesRect.height()/2);
+        } else {
+            return mousePos;
+        }
+    }
+
+    const qreal a = eyesRect.width() / 2;
+    const qreal b = eyesRect.height() / 2;
+    const qreal tan_alpha = vect.y() / vect.x();
+
+    /*
+        the pupil need to be on the intersection between the line
+           y = x * tan_alpha
+        and the ellipse
+           x^2/a^2 + y^2/b^2
+    */
+
+    qreal x = a*b / sqrt(b*b + a*a * tan_alpha*tan_alpha);
+    if (vect.x() < 0) {
+        x = -x;
+    }
+    const qreal y = x*tan_alpha;
+
+    if (abs_vect < (x * x) + (y * y)) {
+        return mousePos;
+    }
+
+    return eyesRect.center() + QPointF(x, y);
+}
+
+void Eyes::timerEvent(QTimerEvent *e)
+{
+    if (e->timerId() != timerId) {
+        Plasma::Applet::timerEvent(e);
+        return;
+    }
+
+    QPoint absMousePos = QCursor::pos();
+
+    if (absMousePos == previousMousePos) {
+        if (timerInterval > 300)
+            return;
+        timerInterval += 50;
+        killTimer(timerId);
+        timerId = startTimer(timerInterval);
+        return;
+    }
+
+    if (timerInterval != 50) {
+        timerInterval = 50;
+        killTimer(timerId);
+        timerId = startTimer(timerInterval);
+    }
+
+    QGraphicsView *myview = view();
+    if (!myview) {
+        return;
+    }
+
+    previousMousePos = absMousePos;
+    //cursor position relative to the item coordonate
+    QPointF mousePos = mapFromScene( myview->mapToScene( myview->mapFromGlobal( \
absMousePos ) ) ); +
+    const QRectF bounding = boundingRect();
+    const qreal paddingX = bounding.width() / 9;
+    const qreal paddingY = bounding.height() / 5;
+
+    QRectF eyesRect = boundingRect();
+    // left pupil
+    eyesRect.setWidth(eyesRect.width()/2 - 2);
+    leftPupil->setPos(pupilPos(eyesRect.adjusted(paddingX,paddingY,-paddingX,-paddingY), \
mousePos) +                           - leftPupil->boundingRect().center());
+
+    //right pupil
+    eyesRect.translate(eyesRect.width() + 2*2 , 0);
+    rightPupil->setPos(pupilPos(eyesRect.adjusted(paddingX,paddingY,-paddingX,-paddingY), \
mousePos) +                             - rightPupil->boundingRect().center());
+}
+
+
+#include "eyes.moc"
diff --git a/tasks/tasks.h b/tasks/tasks.h
new file mode 100644
index 0000000..892cdda
--- /dev/null
+++ b/tasks/tasks.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *   Copyright 2008 by Olivier Goffart <ogoffart@kde.org>                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, 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 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 .        *
+ ***************************************************************************/
+
+#ifndef EYES_H
+#define EYES_H
+
+#include <Plasma/Applet>
+#include <Plasma/Svg>
+#include <Plasma/SvgWidget>
+
+class Eyes : public Plasma::Applet
+{
+    Q_OBJECT
+    public:
+        Eyes(QObject *parent, const QVariantList &args);
+        ~Eyes();
+
+        void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem \
*option, const QRect& contentsRect); +        void \
constraintsEvent(Plasma::Constraints constraints); +        
+    protected:
+        void timerEvent(QTimerEvent *);
+        Plasma::SvgWidget *leftPupil, *rightPupil;
+        int timerId;
+        int timerInterval;
+        QPoint previousMousePos;
+        Plasma::Svg *m_svg;
+};
+
+K_EXPORT_PLASMA_APPLET(eyes, Eyes)
+
+#endif


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

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