[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdeplasma-addons/bettio/qml-gsoc-eyes] applets/eyes: Replacing old C++ applet with a QML port.
From: Davide Bettio <bettio () kde ! org>
Date: 2012-07-05 12:19:16
Message-ID: 20120705121916.CF647A6094 () git ! kde ! org
[Download RAW message or body]
Git commit 2cb8077ab6ab6fc818a369660d1cce65bc28948e by Davide Bettio.
Committed on 05/07/2012 at 14:17.
Pushed by bettio into branch 'bettio/qml-gsoc-eyes'.
Replacing old C++ applet with a QML port.
M +6 -12 applets/eyes/CMakeLists.txt
D +0 -188 applets/eyes/eyes.cpp
D +0 -48 applets/eyes/eyes.h
A +84 -0 applets/eyes/package/contents/ui/eyes.qml [License: GPL (v2+)]
R +2 -1 applets/eyes/package/metadata.desktop [from: \
applets/eyes/plasma-applet-eyes.desktop - 097% similarity]
http://commits.kde.org/kdeplasma-addons/2cb8077ab6ab6fc818a369660d1cce65bc28948e
diff --git a/applets/eyes/CMakeLists.txt b/applets/eyes/CMakeLists.txt
index f4c9057..9cb3b59 100644
--- a/applets/eyes/CMakeLists.txt
+++ b/applets/eyes/CMakeLists.txt
@@ -1,19 +1,13 @@
project(eyes)
-
-set(eyes_SRCS eyes.cpp)
+install(DIRECTORY package/
+ DESTINATION ${DATA_INSTALL_DIR}/plasma/plasmoids/eyes)
-kde4_add_plugin(plasma_applet_eyes ${eyes_SRCS})
-target_link_libraries(plasma_applet_eyes
- ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS})
-
-install(TARGETS plasma_applet_eyes
- DESTINATION ${PLUGIN_INSTALL_DIR})
-
-install(FILES plasma-applet-eyes.desktop
- DESTINATION ${SERVICES_INSTALL_DIR})
+install(FILES package/metadata.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR}
+ RENAME plasma-applet-eyes.desktop)
install(FILES eyes.svg
- DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
+ DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
kde4_install_icons(${ICON_INSTALL_DIR})
diff --git a/applets/eyes/eyes.cpp b/applets/eyes/eyes.cpp
deleted file mode 100644
index 5a7229f..0000000
--- a/applets/eyes/eyes.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/***************************************************************************
- * 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/applets/eyes/eyes.h b/applets/eyes/eyes.h
deleted file mode 100644
index 892cdda..0000000
--- a/applets/eyes/eyes.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/***************************************************************************
- * 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
diff --git a/applets/eyes/package/contents/ui/eyes.qml \
b/applets/eyes/package/contents/ui/eyes.qml new file mode 100644
index 0000000..4b2ceca
--- /dev/null
+++ b/applets/eyes/package/contents/ui/eyes.qml
@@ -0,0 +1,84 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Davide Bettio <davide.bettio@kdemail.net> *
+ * Copyright (C) 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 . *
+ ***************************************************************************/
+
+import QtQuick 1.0;
+import org.kde.plasma.core 0.1 as PlasmaCore;
+
+Item {
+ property int pupilSize: Math.min( Math.min(width / 2, height) / 5, (width / 2 + \
height) / 12); +
+ PlasmaCore.Svg {
+ id: eyesSvg;
+ imagePath: "widgets/eyes";
+ }
+
+ PlasmaCore.SvgItem {
+ id: leftEye;
+
+ anchors {
+ left: parent.left;
+ top: parent.top;
+ bottom: parent.bottom;
+ }
+ width: parent.width/2 - 2;
+
+ svg: eyesSvg;
+ elementId: "leftEye";
+
+ PlasmaCore.SvgItem {
+ id: leftPupil;
+
+ anchors.centerIn: leftEye;
+
+ width: pupilSize;
+ height: pupilSize;
+
+ svg: eyesSvg;
+ elementId: "leftPupil";
+ }
+ }
+
+ PlasmaCore.SvgItem {
+ id: rightEye;
+
+ anchors {
+ right: parent.right;
+ top: parent.top;
+ bottom: parent.bottom;
+ }
+ width: parent.width/2 - 2;
+
+ svg: eyesSvg;
+ elementId: "rightEye";
+
+ PlasmaCore.SvgItem {
+ id: rightPupil;
+
+ anchors.centerIn: rightEye;
+
+ width: pupilSize;
+ height: pupilSize;
+
+ svg: eyesSvg;
+ elementId: "rightPupil";
+ }
+ }
+}
+
diff --git a/applets/eyes/plasma-applet-eyes.desktop \
b/applets/eyes/package/metadata.desktop similarity index 97%
rename from applets/eyes/plasma-applet-eyes.desktop
rename to applets/eyes/package/metadata.desktop
index ee4640f..98c9372 100644
--- a/applets/eyes/plasma-applet-eyes.desktop
+++ b/applets/eyes/package/metadata.desktop
@@ -114,7 +114,6 @@ Comment[zh_TW]=XEyes 的複製品
Icon=eyes
Type=Service
ServiceTypes=Plasma/Applet
-X-KDE-Library=plasma_applet_eyes
X-KDE-PluginInfo-Author=Olivier Goffart
X-KDE-PluginInfo-Email=ogoffart@kde.org
X-KDE-PluginInfo-Name=eyes
@@ -122,5 +121,7 @@ X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-License=GPL
+X-Plasma-API=declarativeappletscript
+X-Plasma-MainScript=ui/eyes.qml
X-Plasma-Requires-FileDialog=Unused
X-Plasma-Requires-LaunchApp=Unused
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic