Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: applet.h
- ===================================================================
- --- applet.h (revisione 1171409)
- +++ applet.h (copia locale)
- @@ -43,6 +43,10 @@
- class KConfigDialog;
- class QGraphicsView;
- class KActionCollection;
- +namespace Plasma {
- + class ControlElement;
- +};
- +Q_DECLARE_METATYPE(QList<Plasma::ControlElement *>)
- namespace Plasma
- {
- @@ -55,7 +59,6 @@
- class ExtenderItem;
- class Package;
- -
- /**
- * @class Applet plasma/applet.h <Plasma/Applet>
- *
- @@ -89,6 +92,7 @@
- Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
- Q_PROPERTY(uint id READ id)
- Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
- + Q_PROPERTY(QList<Plasma::ControlElement *> controlElements READ controlElements)
- public:
- typedef QList<Applet*> List;
- @@ -714,6 +718,8 @@
- */
- bool hasValidAssociatedApplication() const;
- + QList<ControlElement *> controlElements() const;
- +
- Q_SIGNALS:
- /**
- * This signal indicates that an application launch, window
- Index: applet.cpp
- ===================================================================
- --- applet.cpp (revisione 1171409)
- +++ applet.cpp (copia locale)
- @@ -86,7 +86,7 @@
- #include "svg.h"
- #include "framesvg.h"
- #include "popupapplet.h"
- -#include "private/applethandle_p.h"
- +#include "private/abstracthandle.h"
- #include "private/extenderitem_p.h"
- #include "private/framesvg_p.h"
- #include "theme.h"
- @@ -112,8 +112,14 @@
- #include "private/remotedataengine_p.h"
- #include "private/service_p.h"
- #include "ui_publish.h"
- +#include "private/controlelement.h"
- +#include "private/movecontrol.h"
- +#include "private/configurecontrol.h"
- +#include "private/maximizecontrol.h"
- +#include "private/removecontrol.h"
- +#include "private/resizecontrol.h"
- +#include "private/rotatecontrol.h"
- -
- namespace Plasma
- {
- @@ -124,6 +130,8 @@
- // WARNING: do not access config() OR globalConfig() in this method!
- // that requires a scene, which is not available at this point
- d->init();
- +
- + d->createControlElements();
- }
- Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
- @@ -133,6 +141,8 @@
- // WARNING: do not access config() OR globalConfig() in this method!
- // that requires a scene, which is not available at this point
- d->init();
- +
- + d->createControlElements();
- }
- Applet::Applet(QGraphicsItem *parent,
- @@ -157,6 +167,8 @@
- d->args = mutableArgs;
- d->init();
- +
- + d->createControlElements();
- }
- Applet::Applet(QObject *parentObject, const QVariantList &args)
- @@ -185,6 +197,8 @@
- // that requires a scene, which is not available at this point
- d->init();
- + d->createControlElements();
- +
- // the brain damage seen in the initialization list is due to the
- // inflexibility of KService::createInstance
- }
- @@ -195,6 +209,8 @@
- {
- Q_UNUSED(args) // FIXME?
- d->init(packagePath);
- +
- + d->createControlElements();
- }
- Applet::~Applet()
- @@ -374,7 +390,7 @@
- prepareGeometryChange();
- foreach (QGraphicsItem *item, childItems()) {
- - if (!dynamic_cast<AppletHandle *>(item)) {
- + if (!dynamic_cast<AbstractHandle *>(item)) {
- delete item;
- }
- }
- @@ -1591,6 +1607,12 @@
- }
- d->aspectRatioMode = mode;
- +
- + foreach (ControlElement *element, d->controlElements) {
- + if (element->elementType() == ControlElement::ResizeElement) {
- + static_cast<ResizeControl *>(element)->setAspectRatioMode(mode);
- + }
- + }
- }
- void Applet::registerAsDragHandle(QGraphicsItem *item)
- @@ -2105,6 +2127,37 @@
- return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
- }
- +QList<ControlElement *> Applet::controlElements() const
- +{
- + QList<ControlElement *> elements;
- + foreach (ControlElement *e, d->controlElements) {
- + if (!(e->elementType() == ControlElement::MaximizeElement && !hasValidAssociatedApplication())) {
- + elements << e;
- + }
- + }
- +
- + return elements;
- +}
- +
- +void AppletPrivate::createControlElements()
- +{
- + MoveControl *move = new MoveControl(q);
- + ConfigureControl *configure = new ConfigureControl(q);
- + MaximizeControl *maximize = new MaximizeControl(q);
- + RemoveControl *remove = new RemoveControl(q);
- + ResizeControl *resize = new ResizeControl(q);
- + RotateControl *rotate = new RotateControl(q);
- +
- + q->connect(move, SIGNAL(finished(ControlElement::ElementType)), q, SIGNAL(appletTransformedByUser()));
- + q->connect(configure, SIGNAL(finished(ControlElement::ElementType)), q, SLOT(showConfigurationInterface()));
- + q->connect(maximize, SIGNAL(finished(ControlElement::ElementType)), q, SLOT(runAssociatedApplication()));
- + q->connect(remove, SIGNAL(finished(ControlElement::ElementType)), q, SLOT(destroy()));
- + q->connect(rotate, SIGNAL(finished(ControlElement::ElementType)), q, SIGNAL(appletTransformedByUser()));
- + q->connect(resize, SIGNAL(finished(ControlElement::ElementType)), q, SIGNAL(appletTransformedByUser()));
- +
- + controlElements << move << configure << maximize << remove << resize << rotate;
- +}
- +
- void AppletPrivate::filterOffers(QList<KService::Ptr> &offers)
- {
- KConfigGroup constraintGroup(KGlobal::config(), "Constraints");
- Index: private/controlelement.h
- ===================================================================
- --- private/controlelement.h (revisione 0)
- +++ private/controlelement.h (revisione 0)
- @@ -0,0 +1,137 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 CONTROLELEMENT_H
- +#define CONTROLELEMENT_H
- +
- +#include <QtCore/QObject>
- +#include <QPoint>
- +
- +class QGraphicsWidget;
- +class QGraphicsSceneMouseEvent;
- +
- +namespace Plasma
- +{
- +class ControlElementPrivate;
- +class AbstractHandle;
- +
- +/**
- + * @class ControlElement plasma/private/controlelement.h
- + *
- + * @short The base Handle class
- + *
- + * A Control Element is an object which takes care of managing a single
- + * aspect of a widget, e.g resizing it, moving it, etc.
- + */
- +class ControlElement : public QObject
- +{
- + Q_OBJECT
- + public:
- + /**
- + * Describes the type of the control elements.
- + */
- + enum ElementType {
- + MoveElement, /**< An element which moves the widget */
- + RotateElement, /**< An element which rotates the widget */
- + ConfigureElement, /**< An element which calls the configure dialog for the widget */
- + RemoveElement, /**< An element which removes the widget */
- + ResizeElement, /**< An element which resizes the widget */
- + MaximizeElement /**< An element which calls the associated application of the widget */
- + };
- +
- + /**
- + * Build a control element.
- + */
- + ControlElement(QGraphicsWidget *widget);
- +
- + /**
- + * Destructor.
- + */
- + virtual ~ControlElement();
- +
- + /**
- + * Returns a pointer to the widget managed by this.
- + */
- + QGraphicsWidget *widget() const;
- +
- + /**
- + * Returns a pointer to the handle which manages this control element.
- + */
- + AbstractHandle *handle() const;
- +
- + /**
- + * Returns the type of the control element.
- + * You must reimplement this in a subclass.
- + */
- + virtual ElementType elementType() const = 0;
- +
- + protected:
- + /**
- + * Returns true if the point passed is contained by an other
- + * view than the current one.
- + *
- + * @param pos the position to verify
- + */
- + bool leaveCurrentView(const QPoint &pos) const;
- +
- + /**
- + * Reimplement this if you want to receive mouse press events.
- + *
- + * @param event the event passed from the handle
- + */
- + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
- +
- + /**
- + * Reimplement this if you want to receive mouse move events.
- + *
- + * @param event the event passed from the handle
- + */
- + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- +
- + /**
- + * Reimplement this if you want to receive mouse release events.
- + *
- + * @param event the event passed from the handle
- + */
- + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- +
- + /**
- + * Reimplement this if you want to receive mouse click, that is, mouse press
- + * followed by mouse release, events.
- + *
- + * @param event the event passed from the handle
- + */
- + virtual void mouseClickEvent(QGraphicsSceneMouseEvent *event);
- +
- + Q_SIGNALS:
- + /**
- + * Emit this when the control element finished its work.
- + */
- + void finished(ControlElement::ElementType);
- +
- + private:
- + ControlElementPrivate *const d;
- +
- + friend class AbstractHandle;
- +
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/removecontrol.h
- ===================================================================
- --- private/removecontrol.h (revisione 0)
- +++ private/removecontrol.h (revisione 0)
- @@ -0,0 +1,47 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 REMOVECONTROL_H
- +#define REMOVECONTROL_H
- +
- +#include "controlelement.h"
- +
- +class QGraphicsSceneMouseEvent;
- +
- +namespace Plasma
- +{
- +class AbstractHandle;
- +
- +class RemoveControl : public ControlElement
- +{
- + Q_OBJECT
- + public:
- + RemoveControl(QGraphicsWidget *widget);
- + virtual ~RemoveControl();
- +
- + ControlElement::ElementType elementType() const;
- +
- + protected:
- + void mouseClickEvent(QGraphicsSceneMouseEvent *event);
- +
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/rotatecontrol.h
- ===================================================================
- --- private/rotatecontrol.h (revisione 0)
- +++ private/rotatecontrol.h (revisione 0)
- @@ -0,0 +1,51 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 ROTATECONTROL_H
- +#define ROTATECONTROL_H
- +
- +#include "controlelement.h"
- +
- +class QGraphicsSceneMouseEvent;
- +
- +namespace Plasma
- +{
- +
- +class RotateControl : public ControlElement
- +{
- + Q_OBJECT
- + public:
- + RotateControl(QGraphicsWidget *widget);
- + virtual ~RotateControl();
- +
- + ControlElement::ElementType elementType() const;
- +
- + protected:
- + void mousePressEvent(QGraphicsSceneMouseEvent *event);
- + void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- +
- + private:
- + qreal m_angle;
- + qreal m_rotateAngleOffset;
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/applet_p.h
- ===================================================================
- --- private/applet_p.h (revisione 1171409)
- +++ private/applet_p.h (copia locale)
- @@ -47,6 +47,7 @@
- class AppletScript;
- class Wallpaper;
- class BusyWidget;
- +class ControlElement;
- class AppletConfigDialog : public KConfigDialog
- {
- @@ -139,6 +140,7 @@
- void updateShortcuts();
- void publishCheckboxStateChanged(int state);
- void globalShortcutChanged();
- + void createControlElements();
- static KActionCollection* defaultActions(QObject *parent);
- static QSet<QString> knownCategories();
- @@ -207,6 +209,8 @@
- QBasicTimer busyWidgetTimer;
- QBasicTimer *modificationsTimer;
- + QList<ControlElement *> controlElements;
- +
- // a great green field of booleans :)
- bool hasConfigurationInterface : 1;
- bool failed : 1;
- Index: private/movecontrol.h
- ===================================================================
- --- private/movecontrol.h (revisione 0)
- +++ private/movecontrol.h (revisione 0)
- @@ -0,0 +1,54 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 MOVECONTROL_H
- +#define MOVECONTROL_H
- +
- +#include <QPointF>
- +
- +#include "controlelement.h"
- +
- +class QGraphicsSceneMouseEvent;
- +
- +namespace Plasma
- +{
- +class AbstractHandle;
- +
- +class MoveControl : public ControlElement
- +{
- + Q_OBJECT
- + public:
- + MoveControl(QGraphicsWidget *widget);
- + virtual ~MoveControl();
- +
- + ControlElement::ElementType elementType() const;
- +
- + protected:
- + void mousePressEvent(QGraphicsSceneMouseEvent *event);
- + void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- +
- + private:
- + QPoint m_mousePos;
- +
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/abstracthandle.cpp
- ===================================================================
- --- private/abstracthandle.cpp (revisione 0)
- +++ private/abstracthandle.cpp (revisione 0)
- @@ -0,0 +1,253 @@
- +/*
- + * Copyright 2007 by Kevin Ottens <ervin@kde.org>
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "abstracthandle.h"
- +
- +#include <QApplication>
- +#include <QtGui/QGraphicsWidget>
- +#include <QtGui/QGraphicsSceneMouseEvent>
- +
- +#include <KDebug>
- +
- +#include "applet.h"
- +#include "containment.h"
- +#include "view.h"
- +#include "controlelement.h"
- +#include "controlelement_p.h"
- +
- +namespace Plasma
- +{
- +
- +class AbstractHandlePrivate
- +{
- + public:
- + AbstractHandlePrivate(AbstractHandle *handle)
- + : q(handle),
- + pressedElement(0)
- + {
- + }
- +
- + ~AbstractHandlePrivate()
- + {
- + }
- +
- + void widgetDestroyed()
- + {
- + elements.clear();
- + pressedElement = 0;
- + widget = 0;
- + }
- +
- + AbstractHandle *q;
- + Containment *containment;
- + QGraphicsWidget *widget;
- + QList<ControlElement *> elements;
- + ControlElement *pressedElement;
- + AbstractHandle::HandlePosition position;
- +};
- +
- +AbstractHandle::AbstractHandle(Containment *containment, QGraphicsWidget *widget)
- + : QGraphicsObject(widget),
- + d(new AbstractHandlePrivate(this))
- +{
- + d->containment = containment;
- + d->widget = widget;
- + connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed()));
- +
- + d->elements = widget->property("controlElements").value<QList<ControlElement *> >();
- + foreach (ControlElement *e, d->elements) {
- + e->d->handle = this;
- + }
- +
- + setAcceptsHoverEvents(true);
- + setAcceptTouchEvents(true);
- + setPosition(Over);
- +}
- +
- +AbstractHandle::~AbstractHandle()
- +{
- + if (d->widget) {
- + d->widget->disconnect(this);
- + d->widget = 0;
- + }
- +
- + foreach (ControlElement *e, d->elements) {
- + e->d->handle = 0;
- + }
- +
- + delete d;
- +}
- +
- +QGraphicsWidget *AbstractHandle::widget() const
- +{
- + return d->widget;
- +}
- +
- +Containment *AbstractHandle::containment() const
- +{
- + return d->containment;
- +}
- +
- +//pos relative to scene
- +void AbstractHandle::switchContainment(Containment *containment, const QPointF &pos)
- +{
- + d->containment = containment;
- + if (d->widget) {
- + QGraphicsWidget *widget = d->widget;
- + d->widget = 0; //make sure we don't try to act on the widget again
- + setAcceptsHoverEvents(false);
- + emit disappearDone(this);
- + widget->disconnect(this); //make sure the widget doesn't tell us to do anything
- + Applet *a = qobject_cast<Applet *>(widget);
- + if (a) {
- + containment->addApplet(a, containment->mapFromScene(pos));
- + }
- + }
- +}
- +
- +QList<ControlElement *> AbstractHandle::controlElements() const
- +{
- + return d->elements;
- +}
- +
- +ControlElement *AbstractHandle::controlElement(ControlElement::ElementType type) const
- +{
- + foreach (ControlElement *element, d->elements) {
- + if (element->elementType() == type) {
- + return element;
- + }
- + }
- +
- + return 0;
- +}
- +
- +ControlElement *AbstractHandle::pressedElement() const
- +{
- + return d->pressedElement;
- +}
- +
- +AbstractHandle::HandlePosition AbstractHandle::position() const
- +{
- + return d->position;
- +}
- +
- +void AbstractHandle::setPosition(HandlePosition pos)
- +{
- + d->position = pos;
- +}
- +
- +void AbstractHandle::mousePressEvent(QGraphicsSceneMouseEvent *event)
- +{
- + d->pressedElement = controlElementAt(event->pos());
- +
- + if (d->pressedElement) {
- + d->pressedElement->mousePressEvent(event);
- + }
- +
- + update();
- +}
- +
- +void AbstractHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
- +{
- + d->pressedElement->mouseMoveEvent(event);
- +}
- +
- +void AbstractHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
- +{
- + ControlElement *element = controlElementAt(event->pos());
- +
- + if (element && element == d->pressedElement) {
- + element->mouseClickEvent(event);
- + element->mouseReleaseEvent(event);
- + }
- +
- + d->pressedElement = 0;
- +
- + update();
- +}
- +
- +void AbstractHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
- +{
- + if (!boundingRect().contains(event->pos())) {
- + emit disappearDone(this);
- + }
- +}
- +
- +bool AbstractHandle::sceneEvent(QEvent *event)
- +{
- +// switch (event->type()) {
- +// case QEvent::TouchEnd: {
- +// QTransform t = m_applet->transform();
- +// QRectF geom = m_applet->geometry();
- +// QPointF translation(t.m31(), t.m32());
- +// QPointF center = geom.center();
- +// geom.setWidth(geom.width()*qAbs(t.m11()));
- +// geom.setHeight(geom.height()*qAbs(t.m22()));
- +// geom.moveCenter(center);
- +//
- +// m_applet->setGeometry(geom);
- +// t.reset();
- +// t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
- +// t.rotateRadians(m_angle);
- +// t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
- +//
- +//
- +// m_applet->setTransform(t);
- +// return true;
- +// }
- +// case QEvent::TouchBegin:
- +// case QEvent::TouchUpdate:
- +// {
- +// QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
- +// if (touchPoints.count() == 2) {
- +// const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
- +// const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
- +//
- +// //rotation
- +// QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos());
- +// QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos());
- +// m_angle = m_angle+(line1.angleTo(line0)*M_PI_2/90);
- +// QTransform t = m_applet->transform();
- +// t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
- +// t.rotate(line1.angleTo(line0));
- +//
- +// //scaling
- +// qreal scaleFactor = 1;
- +// if (line0.length() > 0) {
- +// scaleFactor = line1.length() / line0.length();
- +// }
- +//
- +// t.scale(scaleFactor, scaleFactor);
- +// t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
- +// m_applet->setTransform(t);
- +//
- +// }
- +// return true;
- +// }
- +// default:
- +// break;
- +// }
- + return QGraphicsObject::sceneEvent(event);
- +}
- +
- +}
- +
- +#include "abstracthandle.moc"
- +
- Index: private/configurecontrol.h
- ===================================================================
- --- private/configurecontrol.h (revisione 0)
- +++ private/configurecontrol.h (revisione 0)
- @@ -0,0 +1,44 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 CONFIGURECONTROL_H
- +#define CONFIGURECONTROL_H
- +
- +#include "controlelement.h"
- +
- +namespace Plasma
- +{
- +
- +class ConfigureControl : public ControlElement
- +{
- + Q_OBJECT
- + public:
- + ConfigureControl(QGraphicsWidget *widget);
- + virtual ~ConfigureControl();
- +
- + ControlElement::ElementType elementType() const;
- +
- + protected:
- + void mouseClickEvent(QGraphicsSceneMouseEvent *event);
- +
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/desktophandle.h
- ===================================================================
- --- private/desktophandle.h (revisione 0)
- +++ private/desktophandle.h (revisione 0)
- @@ -0,0 +1,104 @@
- +/*
- + * Copyright 2007 by Kevin Ottens <ervin@kde.org>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 PLASMA_DESKTOPHANDLE_P_H
- +#define PLASMA_DESKTOPHANDLE_P_H
- +
- +#include <QtCore/QObject>
- +#include <QTimer>
- +#include <QWeakPointer>
- +#include <QPropertyAnimation>
- +
- +#include "abstracthandle.h"
- +#include "animator.h"
- +#include "svg.h"
- +
- +class QGraphicsView;
- +
- +namespace Plasma
- +{
- +class Applet;
- +class Containment;
- +class FrameSvg;
- +class View;
- +
- +class DesktopHandle : public AbstractHandle
- +{
- + Q_OBJECT
- + Q_PROPERTY(qreal fadeAnimation READ fadeAnimation WRITE setFadeAnimation)
- + public:
- + enum FadeType {
- + FadeIn,
- + FadeOut
- + };
- +
- + DesktopHandle(Containment *containment, QGraphicsWidget *widget, const QPointF &hoverPos);
- + virtual ~DesktopHandle();
- +
- + QRectF boundingRect() const;
- + QPainterPath shape() const;
- + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- + void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
- + void setHoverPos(const QPointF &hoverPos);
- +
- + protected:
- + ControlElement *controlElementAt(const QPointF &pos) const;
- + void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
- + void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
- + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
- + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
- +
- + private Q_SLOTS:
- + void setFadeAnimation(qreal progress);
- + qreal fadeAnimation() const;
- + void appletResized();
- + void hoverTimeout();
- + void leaveTimeout();
- + void emitDisappear();
- +
- + private:
- + static const int HANDLE_MARGIN = 3;
- +
- + void calculateSize();
- + void forceDisappear();
- + int minimumHeight();
- +
- + QRectF m_rect;
- + QRectF m_decorationRect;
- + QRectF m_totalRect;
- + int m_iconSize;
- + qreal m_opacity;
- + FadeType m_animType;
- + QWeakPointer<QPropertyAnimation> m_anim;
- + QColor m_gradientColor;
- + QTimer *m_hoverTimer;
- + QTimer *m_leaveTimer;
- + QPixmap *m_backgroundBuffer;
- +
- + Svg *m_configureIcons;
- + FrameSvg *m_background;
- +
- + QPointF m_entryPos; //where the hover in event occurred
- +
- + bool m_pendingFade : 1;
- +};
- +
- +}
- +
- +#endif // multiple inclusion guard
- Index: private/rotatecontrol.cpp
- ===================================================================
- --- private/rotatecontrol.cpp (revisione 0)
- +++ private/rotatecontrol.cpp (revisione 0)
- @@ -0,0 +1,106 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "rotatecontrol.h"
- +
- +#include <math.h>
- +#include <cmath>
- +
- +#include <QtGui/QGraphicsSceneMouseEvent>
- +#include <QtGui/QGraphicsWidget>
- +
- +#include "abstracthandle.h"
- +
- +namespace Plasma
- +{
- +qreal _k_pointAngle(QPointF point);
- +
- +RotateControl::RotateControl(QGraphicsWidget *widget)
- + : ControlElement(widget)
- +{
- +}
- +
- +RotateControl::~RotateControl()
- +{
- +}
- +
- +ControlElement::ElementType RotateControl::elementType() const
- +{
- + return ControlElement::RotateElement;
- +}
- +
- +void RotateControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
- +{
- + QPointF origWidgetCenter = handle()->mapToScene(widget()->boundingRect()).boundingRect().center();
- + QPointF center = widget()->boundingRect().center();
- + m_angle = _k_pointAngle(widget()->transform().map(center + QPointF(1.0, 0.0)) - center);
- + m_rotateAngleOffset = m_angle - _k_pointAngle(event->scenePos() - origWidgetCenter);
- +}
- +
- +void RotateControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
- +{
- + static const qreal snapAngle = M_PI_2 /* $i 3.14159 / 2.0 */;
- +
- + QPointF cursorPoint = event->scenePos();
- + qreal newAngle;
- + QSizeF size = widget()->size();
- + QPointF center = handle()->mapToScene(widget()->boundingRect()).boundingRect().center();
- +
- + QPointF centerRelativePoint = cursorPoint - center;
- + qreal dist = std::sqrt(centerRelativePoint.x() * centerRelativePoint.x() +
- + centerRelativePoint.y() * centerRelativePoint.y());
- + if (dist < 10) {
- + newAngle = m_angle;
- + } else {
- + qreal cursorAngle = _k_pointAngle(centerRelativePoint);
- + newAngle = m_rotateAngleOffset + cursorAngle;
- + if (fabs(remainder(newAngle, snapAngle)) < 0.15) {
- + newAngle = newAngle - remainder(newAngle, snapAngle);
- + }
- + }
- +
- + // apply angle
- + QTransform at;
- + at.translate(size.width()/2, size.height()/2);
- + at.rotateRadians(newAngle);
- + at.translate(-size.width()/2, -size.height()/2);
- + widget()->setTransform(at);
- + m_angle = newAngle;
- +}
- +
- +void RotateControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
- +{
- + emit finished(ControlElement::RotateElement);
- +}
- +
- +qreal _k_pointAngle(QPointF point)
- +{
- + qreal r = sqrt(point.x() * point.x() + point.y() * point.y());
- + qreal cosine = point.x() / r;
- +
- + if (point.y() >= 0) {
- + return acos(cosine);
- + } else {
- + return -acos(cosine);
- + }
- +}
- +
- +}
- +
- +#include "rotatecontrol.moc"
- Index: private/resizecontrol.cpp
- ===================================================================
- --- private/resizecontrol.cpp (revisione 0)
- +++ private/resizecontrol.cpp (revisione 0)
- @@ -0,0 +1,157 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "resizecontrol.h"
- +
- +#include <math.h>
- +
- +#include <QtGui/QGraphicsSceneMouseEvent>
- +#include <QtGui/QGraphicsWidget>
- +
- +#include <KIconLoader>
- +#include <KDebug>
- +
- +#include "abstracthandle.h"
- +
- +namespace Plasma
- +{
- +
- +ResizeControl::ResizeControl(QGraphicsWidget *widget)
- + : ControlElement(widget),
- + aspectRatioMode(IgnoreAspectRatio)
- +{
- +}
- +
- +ResizeControl::~ResizeControl()
- +{
- +}
- +
- +ControlElement::ElementType ResizeControl::elementType() const
- +{
- + return ControlElement::ResizeElement;
- +}
- +
- +void ResizeControl::setAspectRatioMode(AspectRatioMode mode)
- +{
- + aspectRatioMode = mode;
- +}
- +
- +void ResizeControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
- +{
- + m_originalGeom = handle()->mapToScene(widget()->boundingRect()).boundingRect();
- + m_origWidgetCenter = m_originalGeom.center();
- + m_origWidgetSize = QPointF(widget()->size().width(), widget()->size().height());
- +
- + AbstractHandle::HandlePosition pos = handle()->position();
- + if (pos == AbstractHandle::Right) {
- + m_resizeStaticPoint = widget()->mapToScene(QPointF(0, widget()->size().height()));
- + } else {
- + m_resizeStaticPoint = widget()->mapToScene(m_origWidgetSize);
- + }
- + m_resizeGrabPoint = event->scenePos();
- +}
- +
- +void ResizeControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
- +{
- + QPointF cursorPoint = event->scenePos();
- +
- + QPointF newSize;
- + QPointF newCenter;
- +
- + // get size limits
- + QSizeF min = widget()->minimumSize();
- + QSizeF max = widget()->maximumSize();
- +
- + if (min.width() < KIconLoader::SizeSmall || min.height() < KIconLoader::SizeSmall) {
- + min = widget()->effectiveSizeHint(Qt::MinimumSize);
- + }
- +
- + if (max.isEmpty()) {
- + max = widget()->effectiveSizeHint(Qt::MaximumSize);
- + }
- +
- + // If the widget doesn't have a minimum size, calculate based on a
- + // minimum content area size of 16x16 (KIconLoader::SizeSmall)
- + if (min.width() < KIconLoader::SizeSmall || min.height() < KIconLoader::SizeSmall) {
- + min = widget()->boundingRect().size() - widget()->contentsRect().size();
- + min = QSizeF(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
- + }
- +
- + // un-rotate screen points so we can read differences of coordinates
- +
- + QTransform t(widget()->sceneTransform());
- + //take the angle relative to the scene
- + qreal angle = (t.m12() > 0 ? acos(t.m11()) : -acos(t.m11()));
- +
- + QPointF rStaticPoint = QTransform().rotateRadians(-angle).map(m_resizeStaticPoint);
- + QPointF rCursorPoint = QTransform().rotateRadians(-angle).map(cursorPoint);
- + QPointF rGrabPoint = QTransform().rotateRadians(-angle).map(m_resizeGrabPoint);
- +
- + AbstractHandle::HandlePosition pos = handle()->position();
- + if (pos == AbstractHandle::Right) {
- + newSize = m_origWidgetSize + QPointF(rCursorPoint.x() - rGrabPoint.x(), rGrabPoint.y() - rCursorPoint.y());
- + } else {
- + newSize = m_origWidgetSize + QPointF(rGrabPoint.x() - rCursorPoint.x(), rGrabPoint.y() - rCursorPoint.y());
- + }
- +
- + // preserving aspect ratio?
- + if ((aspectRatioMode != Plasma::IgnoreAspectRatio && !(event->modifiers() & Qt::ControlModifier)) ||
- + (aspectRatioMode == Plasma::IgnoreAspectRatio && (event->modifiers() & Qt::ControlModifier))) {
- + // project size to keep ratio
- +
- + QPointF v = m_origWidgetSize;
- + v /= sqrt(v.x() * v.x() + v.y() * v.y());
- + qreal a = v.x() * v.x();
- + qreal b = v.x() * v.y();
- + qreal d = v.y() * v.y();
- + newSize = QMatrix(a, b, b, d, 0., 0.).map(newSize);
- +
- + // limit size, presering ratio
- + qreal ratio = m_origWidgetSize.y() / m_origWidgetSize.x();
- + newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
- + newSize.ry() = newSize.x() * ratio;
- + newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
- + newSize.rx() = newSize.y() / ratio;
- + } else {
- + // limit size
- + newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
- + newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
- + }
- +
- + // move center such that the static corner remains in the same place
- + if (pos == AbstractHandle::Right) {
- + newCenter = QTransform().rotateRadians(angle).map(QPointF(rStaticPoint.x() + newSize.x()/2,
- + rStaticPoint.y() - newSize.y()/2));
- + } else {
- + newCenter = QTransform().rotateRadians(angle).map(QPointF(rStaticPoint.x() - newSize.x()/2,
- + rStaticPoint.y() - newSize.y()/2));
- + }
- +
- + widget()->resize(newSize.x(), newSize.y());
- + widget()->setPos(widget()->parentItem()->mapFromScene(newCenter - newSize/2));
- +}
- +
- +void ResizeControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
- +{
- + emit finished(ControlElement::ResizeElement);
- +}
- +
- +}
- +
- +#include "resizecontrol.moc"
- Index: private/movecontrol.cpp
- ===================================================================
- --- private/movecontrol.cpp (revisione 0)
- +++ private/movecontrol.cpp (revisione 0)
- @@ -0,0 +1,116 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "movecontrol.h"
- +
- +#include <QtGui/QGraphicsSceneMouseEvent>
- +#include <QtGui/QGraphicsWidget>
- +
- +#include <Plasma/View>
- +#include <Plasma/Containment>
- +#include <Plasma/Corona>
- +
- +#include "abstracthandle.h"
- +
- +namespace Plasma
- +{
- +
- +MoveControl::MoveControl(QGraphicsWidget *widget)
- + : ControlElement(widget)
- +{
- +}
- +
- +MoveControl::~MoveControl()
- +{
- +}
- +
- +ControlElement::ElementType MoveControl::elementType() const
- +{
- + return ControlElement::MoveElement;
- +}
- +
- +void MoveControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
- +{
- + QGraphicsView *view = handle()->containment()->view();
- + if (view) {
- + QPoint localpos = view->mapFromScene(widget()->scenePos());
- + m_mousePos = event->screenPos() - view->mapToGlobal(localpos);
- + }
- +}
- +
- +void MoveControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
- +{
- + if (leaveCurrentView(event->screenPos())) {
- + Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
- + if (v && v != handle()->containment()->view()) {
- + Containment *c = v->containment();
- + if (c) {
- + QPoint pos = v->mapFromGlobal(event->screenPos());
- + //we actually have been dropped on another containment, so
- + //move there: we have a screenpos, we need a scenepos
- + //FIXME how reliable is this transform?
- + handle()->switchContainment(c, v->mapToScene(pos));
- + }
- + }
- + }
- +
- + QPointF curPos = event->pos();
- + QPointF lastPos = event->lastPos();
- +
- + QTransform transform = widget()->transform();
- + //we need to discard translation from the transform
- + QTransform t(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0);
- + QPointF delta = t.map(curPos - lastPos);
- + widget()->moveBy(delta.x(), delta.y());
- +}
- +
- +void MoveControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
- +{
- + // test for containment change
- + //kDebug() << "testing for containment change, sceneBoundingRect = "
- + // << containment()->sceneBoundingRect();
- + if (!handle()->containment()->sceneBoundingRect().contains(widget()->scenePos())) {
- + // see which containment it belongs to
- + Corona *corona = qobject_cast<Corona *>(handle()->scene());
- + if (corona) {
- + foreach (Containment *containment, corona->containments()) {
- + QPointF pos;
- + QGraphicsView *v = containment->view();
- + if (v) {
- + pos = v->mapToScene(v->mapFromGlobal(event->screenPos() - m_mousePos));
- +
- + if (containment->sceneBoundingRect().contains(pos)) {
- + //kDebug() << "new containment = " << containments[i];
- + //kDebug() << "rect = " << containments[i]->sceneBoundingRect();
- + // add the widget to the new containment and take it from the old one
- + //kDebug() << "moving to other containment with position" << pos;;
- + handle()->switchContainment(containment, pos);
- + break;
- + }
- + }
- + }
- + }
- + }
- +
- + emit finished(ControlElement::MoveElement);
- +}
- +
- +}
- +
- +#include "movecontrol.moc"
- Index: private/controlelement_p.h
- ===================================================================
- --- private/controlelement_p.h (revisione 0)
- +++ private/controlelement_p.h (revisione 0)
- @@ -0,0 +1,43 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 CONTROLELEMENTPRIVATE_H
- +#define CONTROLELEMENTPRIVATE_H
- +
- +class QGraphicsWidget;
- +
- +namespace Plasma
- +{
- +class AbstractHandle;
- +class ControlElement;
- +
- +class ControlElementPrivate
- +{
- + public:
- + ControlElementPrivate(ControlElement *element);
- + ~ControlElementPrivate();
- +
- + ControlElement *q;
- + QGraphicsWidget *widget;
- + AbstractHandle *handle;
- +};
- +
- +};
- +
- +#endif
- Index: private/desktophandle.cpp
- ===================================================================
- --- private/desktophandle.cpp (revisione 0)
- +++ private/desktophandle.cpp (revisione 0)
- @@ -0,0 +1,671 @@
- +/*
- + * Copyright 2007 by Kevin Ottens <ervin@kde.org>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "private/desktophandle.h"
- +
- +#include <QApplication>
- +#include <QBitmap>
- +#include <QtGui/QGraphicsSceneMouseEvent>
- +#include <QtGui/QLinearGradient>
- +#include <QtGui/QPainter>
- +#include <QtGui/QApplication>
- +#include <QtGui/QMenu>
- +#include <QTouchEvent>
- +#include <QMatrix>
- +#include <QTransform>
- +#include <QWeakPointer>
- +#include <QPropertyAnimation>
- +
- +#include <kcolorscheme.h>
- +#include <kglobalsettings.h>
- +#include <kicon.h>
- +#include <kiconloader.h>
- +#include <kwindowsystem.h>
- +
- +#include <cmath>
- +#include <math.h>
- +
- +#include "applet.h"
- +#include "applet_p.h"
- +#include "containment.h"
- +#include "corona.h"
- +#include "paintutils.h"
- +#include "theme.h"
- +#include "view.h"
- +#include "framesvg.h"
- +
- +namespace Plasma
- +{
- +
- +DesktopHandle::DesktopHandle(Containment *parent, QGraphicsWidget *widget, const QPointF &hoverPos)
- + : AbstractHandle(parent, widget),
- + m_iconSize(KIconLoader::SizeSmall),
- + m_opacity(0.0),
- + m_animType(FadeIn),
- + m_backgroundBuffer(0),
- + m_pendingFade(false)
- +{
- + setHoverPos(hoverPos);
- +
- + setFlags(flags() | QGraphicsItem::ItemStacksBehindParent);
- + KColorScheme colorScheme(QPalette::Active, KColorScheme::View,
- + Theme::defaultTheme()->colorScheme());
- + setAcceptTouchEvents(true);
- + m_gradientColor = colorScheme.background(KColorScheme::NormalBackground).color();
- +
- + QPointF center = QRectF(QPointF(), widget->size()).center();
- +
- + m_hoverTimer = new QTimer(this);
- + m_hoverTimer->setSingleShot(true);
- + m_hoverTimer->setInterval(333);
- +
- + m_leaveTimer = new QTimer(this);
- + m_leaveTimer->setSingleShot(true);
- + m_leaveTimer->setInterval(500);
- +
- + connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
- + connect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
- +
- + setAcceptsHoverEvents(true);
- + m_hoverTimer->start();
- +
- + //icons
- + m_configureIcons = new Svg(this);
- + m_configureIcons->setImagePath("widgets/configuration-icons");
- + m_configureIcons->setContainsMultipleImages(true);
- +
- + m_background = new FrameSvg(this);
- + m_background->setImagePath("widgets/background");
- + widget->installSceneEventFilter(this);
- +}
- +
- +DesktopHandle::~DesktopHandle()
- +{
- + delete m_backgroundBuffer;
- +}
- +
- +QRectF Plasma::DesktopHandle::boundingRect() const
- +{
- + return m_totalRect;
- +}
- +
- +QPainterPath DesktopHandle::shape() const
- +{
- + //when the containment changes the applet is reset to 0
- + if (widget()) {
- + QPainterPath path = PaintUtils::roundedRectangle(m_decorationRect, 10);
- + return path.united(widget()->shape());
- + } else {
- + return QGraphicsItem::shape();
- + }
- +}
- +
- +QPainterPath handleRect(const QRectF &rect, int radius, bool onRight)
- +{
- + QPainterPath path;
- + if (onRight) {
- + // make the left side straight
- + path.moveTo(rect.left(), rect.top()); // Top left
- + path.lineTo(rect.right() - radius, rect.top()); // Top side
- + path.quadTo(rect.right(), rect.top(),
- + rect.right(), rect.top() + radius); // Top right corner
- + path.lineTo(rect.right(), rect.bottom() - radius); // Right side
- + path.quadTo(rect.right(), rect.bottom(),
- + rect.right() - radius, rect.bottom()); // Bottom right corner
- + path.lineTo(rect.left(), rect.bottom()); // Bottom side
- + } else {
- + // make the right side straight
- + path.moveTo(QPointF(rect.left(), rect.top() + radius));
- + path.quadTo(rect.left(), rect.top(),
- + rect.left() + radius, rect.top()); // Top left corner
- + path.lineTo(rect.right(), rect.top()); // Top side
- + path.lineTo(rect.right(), rect.bottom()); // Right side
- + path.lineTo(rect.left() + radius, rect.bottom()); // Bottom side
- + path.quadTo(rect.left(), rect.bottom(),
- + rect.left(), rect.bottom() - radius); // Bottom left corner
- + }
- +
- + path.closeSubpath();
- + return path;
- +}
- +
- +void DesktopHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
- +{
- + Q_UNUSED(option);
- + Q_UNUSED(widget);
- +
- + //kDebug() << m_opacity << m_anim << FadeOut;
- + if (qFuzzyCompare(m_opacity + 1.0, 1.0)) {
- + if (m_animType == FadeOut) {
- + //kDebug() << "WOOOOOOOOO";
- + QTimer::singleShot(0, this, SLOT(emitDisappear()));
- + }
- + return;
- + }
- +
- + qreal translation;
- +
- + AbstractHandle::HandlePosition pos = position();
- + if (pos == AbstractHandle::Right) {
- + //kDebug() << "translating by" << m_opacity
- + // << (-(1 - m_opacity) * m_rect.width()) << m_rect.width();
- + translation = -(1 - m_opacity) * m_rect.width();
- + } else {
- + translation = (1 - m_opacity) * m_rect.width();
- + }
- +
- + painter->translate(translation, 0);
- +
- + painter->setPen(Qt::NoPen);
- + painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
- +
- + int iconMargin = m_iconSize / 2;
- +
- + const QSize pixmapSize(int(m_decorationRect.width()),
- + int(m_decorationRect.height()) + m_iconSize * 5 + 1);
- + const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
- +
- + bool isRunning = false;
- + if (m_anim.data()) {
- + isRunning = m_anim.data()->state() == QAbstractAnimation::Running ? \
- + true : false;
- + }
- +
- + //regenerate our buffer?
- + if (isRunning || !m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
- + QColor transparencyColor = Qt::black;
- + transparencyColor.setAlphaF(qMin(m_opacity, qreal(0.99)));
- +
- + QLinearGradient g(QPoint(0, 0), QPoint(m_decorationRect.width(), 0));
- + //fading out panel
- + if (m_rect.height() > qreal(minimumHeight()) * 1.25) {
- + AbstractHandle::HandlePosition pos = position();
- + if (pos == AbstractHandle::Right) {
- + qreal opaquePoint =
- + (m_background->marginSize(LeftMargin) - translation) / m_decorationRect.width();
- + //kDebug() << "opaquePoint" << opaquePoint
- + // << m_background->marginSize(LeftMargin) << m_decorationRect.width();
- + g.setColorAt(0.0, Qt::transparent);
- + g.setColorAt(qMax(0.0, opaquePoint - 0.05), Qt::transparent);
- + g.setColorAt(opaquePoint, transparencyColor);
- + g.setColorAt(1.0, transparencyColor);
- + } else {
- + qreal opaquePoint =
- + 1 - ((m_background->marginSize(RightMargin) + translation) / m_decorationRect.width());
- + g.setColorAt(1.0, Qt::transparent);
- + g.setColorAt(opaquePoint + 0.05, Qt::transparent);
- + g.setColorAt(qMax(qreal(0), opaquePoint), transparencyColor);
- + g.setColorAt(0.0, transparencyColor);
- + }
- + //complete panel
- + } else {
- + g.setColorAt(0.0, transparencyColor);
- + }
- +
- + m_background->resizeFrame(m_decorationRect.size());
- +
- + if (!m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
- + delete m_backgroundBuffer;
- + m_backgroundBuffer = new QPixmap(pixmapSize);
- + }
- + m_backgroundBuffer->fill(Qt::transparent);
- + QPainter buffPainter(m_backgroundBuffer);
- +
- + m_background->paintFrame(&buffPainter);
- +
- + //+1 because otherwise due to rounding errors when rotated could appear one pixel
- + //of the icon at the border of the applet
- + //QRectF iconRect(QPointF(pixmapSize.width() - m_iconSize + 1, m_iconSize), iconSize);
- + QRectF iconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
- + AbstractHandle::HandlePosition pos = position();
- + if (pos == AbstractHandle::Right) {
- + iconRect.moveLeft(
- + pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
- + if (controlElement(ControlElement::ResizeElement)) {
- + m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tr2bl");
- + }
- + } else {
- + iconRect.moveLeft(m_background->marginSize(RightMargin));
- + if (controlElement(ControlElement::ResizeElement)) {
- + m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tl2br");
- + }
- + }
- +
- + iconRect.translate(0, m_iconSize);
- + m_configureIcons->paint(&buffPainter, iconRect, "rotate");
- +
- + if (controlElement(ControlElement::ConfigureElement)) {
- + iconRect.translate(0, m_iconSize);
- + m_configureIcons->paint(&buffPainter, iconRect, "configure");
- + }
- +
- + if (controlElement(ControlElement::MaximizeElement)) {
- + iconRect.translate(0, m_iconSize);
- + m_configureIcons->paint(&buffPainter, iconRect, "maximize");
- + }
- +
- + iconRect.translate(0, m_iconSize);
- + m_configureIcons->paint(&buffPainter, iconRect, "close");
- +
- + buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
- + //blend the background
- + buffPainter.fillRect(m_backgroundBuffer->rect(), g);
- + //blend the icons
- + //buffPainter.fillRect(QRect(QPoint((int)m_decorationRect.width(), 0), QSize(m_iconSize + 1,
- + // (int)m_decorationRect.height())), transparencyColor);
- + }
- +
- + painter->drawPixmap(m_decorationRect.toRect(), *m_backgroundBuffer,
- + QRect(QPoint(0, 0), m_decorationRect.size().toSize()));
- +
- + //XXX this code is duplicated in the next function
- + QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
- + QPointF step = QPointF(0, m_iconSize + iconMargin);
- + QPointF separator = step + QPointF(0, iconMargin);
- + //end duplicate code
- +
- + QPointF shiftC;
- + QPointF shiftD;
- + QPointF shiftR;
- + QPointF shiftM;
- + QPointF shiftMx;
- +
- + ControlElement *e = pressedElement();
- + if (e) {
- + switch(e->elementType())
- + {
- + case ControlElement::ConfigureElement:
- + shiftC = QPointF(2, 2);
- + break;
- + case ControlElement::RemoveElement:
- + shiftD = QPointF(2, 2);
- + break;
- + case ControlElement::RotateElement:
- + shiftR = QPointF(2, 2);
- + break;
- + case ControlElement::ResizeElement:
- + shiftM = QPointF(2, 2);
- + break;
- + case ControlElement::MaximizeElement:
- + shiftMx = QPointF(2, 2);
- + break;
- + default:
- + break;
- + }
- + }
- +
- + QRectF sourceIconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
- + if (pos == AbstractHandle::Right) {
- + sourceIconRect.moveLeft(
- + pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
- + } else {
- + sourceIconRect.moveLeft(m_background->marginSize(RightMargin));
- + }
- +
- + if (controlElement(ControlElement::ResizeElement)) {
- + //resize
- + painter->drawPixmap(
- + QRectF(basePoint + shiftM, iconSize), *m_backgroundBuffer, sourceIconRect);
- + basePoint += step;
- + }
- +
- + //rotate
- + sourceIconRect.translate(0, m_iconSize);
- + painter->drawPixmap(QRectF(basePoint + shiftR, iconSize), *m_backgroundBuffer, sourceIconRect);
- +
- + //configure
- + if (controlElement(ControlElement::ConfigureElement)) {
- + basePoint += step;
- + sourceIconRect.translate(0, m_iconSize);
- + painter->drawPixmap(
- + QRectF(basePoint + shiftC, iconSize), *m_backgroundBuffer, sourceIconRect);
- + }
- +
- + //maximize
- + if (controlElement(ControlElement::MaximizeElement)) {
- + basePoint += step;
- + sourceIconRect.translate(0, m_iconSize);
- + painter->drawPixmap(
- + QRectF(basePoint + shiftMx, iconSize), *m_backgroundBuffer, sourceIconRect);
- + }
- +
- + //close
- + basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step;
- + sourceIconRect.translate(0, m_iconSize);
- + painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect);
- +}
- +
- +void DesktopHandle::emitDisappear()
- +{
- + emit disappearDone(this);
- +}
- +
- +ControlElement *DesktopHandle::controlElementAt(const QPointF &point) const
- +{
- + int iconMargin = m_iconSize / 2;
- + //XXX this code is duplicated in the prev. function
- + QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
- + QPointF step = QPointF(0, m_iconSize + iconMargin);
- + QPointF separator = step + QPointF(0, iconMargin);
- + //end duplicate code
- +
- + QRectF activeArea = QRectF(basePoint, QSizeF(m_iconSize, m_iconSize));
- +
- + ControlElement *element = controlElement(ControlElement::ResizeElement);
- + if (element) {
- + if (activeArea.contains(point)) {
- + return element;
- + }
- + activeArea.translate(step);
- + }
- +
- + if (activeArea.contains(point)) {
- + return controlElement(ControlElement::RotateElement);
- + }
- +
- + element = controlElement(ControlElement::ConfigureElement);
- + if (element) {
- + activeArea.translate(step);
- + if (activeArea.contains(point)) {
- + return element;
- + }
- + }
- +
- + element = controlElement(ControlElement::MaximizeElement);
- + if (element) {
- + activeArea.translate(step);
- + if (activeArea.contains(point)) {
- + return element;
- + }
- + }
- +
- + activeArea.moveTop(m_rect.bottom() - activeArea.height() - iconMargin);
- + if (activeArea.contains(point)) {
- + return controlElement(ControlElement::RemoveElement);
- + }
- +
- + return controlElement(ControlElement::MoveElement);
- +}
- +
- +void DesktopHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
- +{
- + Q_UNUSED(event);
- + //kDebug() << "hover enter";
- +
- + //if a disappear was scheduled stop the timer
- + if (m_leaveTimer->isActive()) {
- + m_leaveTimer->stop();
- + }
- + // if we're already fading out, fade back in
- + else if (!m_anim.data() && m_animType == FadeOut) {
- + startFading(FadeIn, m_entryPos, true);
- + }
- +}
- +
- +void DesktopHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
- +{
- + hoverEnterEvent(event);
- +}
- +
- +void DesktopHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
- +{
- + Q_UNUSED(event);
- +
- + foreach (QWidget *widget, QApplication::topLevelWidgets()) {
- + QMenu *menu = qobject_cast<QMenu*>(widget);
- + if (menu && menu->isVisible()) {
- + connect(menu, SIGNAL(aboutToHide()), this, SLOT(leaveTimeout()));
- + return;
- + }
- + }
- +
- +
- + // if we haven't even showed up yet, remove the handle
- + if (m_hoverTimer->isActive()) {
- + m_hoverTimer->stop();
- + QTimer::singleShot(0, this, SLOT(emitDisappear()));
- + } else if (pressedElement()) {
- + m_pendingFade = true;
- + } else {
- + //wait a moment to hide the handle in order to recheck the mouse position
- + m_leaveTimer->start();
- + }
- +}
- +
- +bool DesktopHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
- +{
- + if (watched == widget() && event->type() == QEvent::GraphicsSceneHoverLeave) {
- + hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent*>(event));
- + }
- +
- + return false;
- +}
- +
- +void DesktopHandle::setFadeAnimation(qreal progress)
- +{
- + m_opacity = progress;
- + //kDebug() << "progress" << progress << "m_opacity" << m_opacity << m_anim << "(" << FadeIn << ")";
- + if (qFuzzyCompare(progress, qreal(1.0))) {
- + delete m_backgroundBuffer;
- + m_backgroundBuffer = 0;
- + }
- +
- + update();
- +}
- +
- +qreal DesktopHandle::fadeAnimation() const
- +{
- + return m_opacity;
- +}
- +
- +void DesktopHandle::hoverTimeout()
- +{
- + startFading(FadeIn, m_entryPos);
- +}
- +
- +void DesktopHandle::leaveTimeout()
- +{
- + if (!isUnderMouse()) {
- + startFading(FadeOut, m_entryPos);
- + }
- +}
- +
- +void DesktopHandle::appletResized()
- +{
- + prepareGeometryChange();
- + calculateSize();
- + update();
- +}
- +
- +void DesktopHandle::setHoverPos(const QPointF &hoverPos)
- +{
- + m_entryPos = hoverPos;
- +}
- +
- +void DesktopHandle::startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide)
- +{
- + QPropertyAnimation *propAnim = m_anim.data();
- +
- + if (anim == FadeIn) {
- + if (propAnim) {
- + propAnim->stop();
- + } else {
- + propAnim = new QPropertyAnimation(this, "fadeAnimation", this);
- + m_anim = propAnim;
- + }
- + }
- +
- + m_entryPos = hoverPos;
- + qreal time = 100;
- +
- + if (!widget()) {
- + m_animType = FadeOut;
- + setFadeAnimation(1.0);
- + return;
- + }
- +
- + if (anim == FadeIn) {
- + //kDebug() << m_entryPos.x() << m_applet->pos().x();
- + prepareGeometryChange();
- + AbstractHandle::HandlePosition pos = position();
- + bool wasOnRight = (pos == AbstractHandle::Right);
- + if (!preserveSide) {
- + bool buttonsOnRight = m_entryPos.x() > (widget()->size().width() / 2);
- + if (buttonsOnRight) {
- + setPosition(AbstractHandle::Right);
- + } else {
- + setPosition(AbstractHandle::Left);
- + }
- + }
- + calculateSize();
- + QPolygonF region = widget()->mapToParent(m_rect).intersected(widget()->parentWidget()->boundingRect());
- + //kDebug() << region << m_rect << mapToParent(m_rect) << containmnet->boundingRect();
- + if (region != widget()->mapToParent(m_rect)) {
- + // switch sides
- + //kDebug() << "switch sides";
- + if (pos == AbstractHandle::Right) {
- + setPosition(AbstractHandle::Left);
- + } else {
- + setPosition(AbstractHandle::Right);
- + }
- + calculateSize();
- + QPolygonF region2 = widget()->mapToParent(m_rect).intersected(widget()->parentWidget()->boundingRect());
- + if (region2 != mapToParent(m_rect)) {
- + // ok, both sides failed to be perfect... which one is more perfect?
- + QRectF f1 = region.boundingRect();
- + QRectF f2 = region2.boundingRect();
- + //kDebug() << "still not a perfect world"
- + // << f2.width() << f2.height() << f1.width() << f1.height();
- + if ((f2.width() * f2.height()) < (f1.width() * f1.height())) {
- + //kDebug() << "we did better the first time";
- + if (pos == AbstractHandle::Right) {
- + setPosition(AbstractHandle::Left);
- + } else {
- + setPosition(AbstractHandle::Right);
- + }
- + calculateSize();
- + }
- + }
- + }
- +
- + pos = position();
- + if (wasOnRight != (pos == AbstractHandle::Right) &&
- + m_animType == FadeIn &&
- + anim == FadeIn &&
- + m_opacity <= 1) {
- + m_opacity = 0.0;
- + }
- +
- + time *= 1.0 - m_opacity;
- + } else {
- + time *= m_opacity;
- + }
- +
- + if (propAnim) {
- + propAnim->setStartValue(0);
- + propAnim->setEndValue(1);
- + propAnim->setDuration(time);
- + }
- +
- + m_animType = anim;
- + //kDebug() << "animating for " << time << "ms";
- + if (m_animType == FadeIn) {
- + propAnim->setDirection(QAbstractAnimation::Forward);
- + propAnim->start();
- + } else if (propAnim) {
- + propAnim->setDirection(QAbstractAnimation::Backward);
- + propAnim->start(QAbstractAnimation::DeleteWhenStopped);
- + }
- +}
- +
- +void DesktopHandle::forceDisappear()
- +{
- + setAcceptsHoverEvents(false);
- + startFading(FadeOut, m_entryPos);
- +}
- +
- +int DesktopHandle::minimumHeight()
- +{
- + int iconMargin = m_iconSize / 2;
- + int requiredHeight = iconMargin + //first margin
- + (m_iconSize + iconMargin) * 4 + //XXX remember to update this if the number of buttons changes
- + iconMargin ; //blank space before the close button
- +
- + if (controlElement(ControlElement::ConfigureElement)) {
- + requiredHeight += (m_iconSize + iconMargin);
- + }
- +
- + return requiredHeight;
- +}
- +
- +void DesktopHandle::calculateSize()
- +{
- + KIconLoader *iconLoader = KIconLoader::global();
- + //m_iconSize = iconLoader->currentSize(KIconLoader::Small); //does not work with double sized icon
- + m_iconSize = iconLoader->loadIcon("transform-scale", KIconLoader::Small).width(); //workaround
- +
- + int handleHeight = qMax(minimumHeight(), int(widget()->contentsRect().height() * 0.8));
- + int handleWidth = m_iconSize + 2 * HANDLE_MARGIN;
- + int top = widget()->contentsRect().top() + (widget()->contentsRect().height() - handleHeight) / 2.0;
- +
- + qreal marginLeft, marginTop, marginRight, marginBottom;
- + m_background->getMargins(marginLeft, marginTop, marginRight, marginBottom);
- +
- + AbstractHandle::HandlePosition pos = position();
- + if (pos == AbstractHandle::Right) {
- + //put the rect on the right of the applet
- + m_rect = QRectF(widget()->size().width(), top, handleWidth, handleHeight);
- + } else {
- + //put the rect on the left of the applet
- + m_rect = QRectF(-handleWidth, top, handleWidth, handleHeight);
- + }
- +
- + if (widget()->contentsRect().height() > qreal(minimumHeight()) * 1.25) {
- + int addedMargin = marginLeft / 2;
- +
- + // now we check to see if the shape is smaller than the contents,
- + // and that the shape is not just the bounding rect; in those cases
- + // we have a shaped guy and we draw a full panel;
- + // TODO: allow applets to mark when they have translucent areas and
- + // should therefore skip this test?
- + if (widget()->shape().contains(widget()->contentsRect())) {
- + QPainterPath p;
- + p.addRect(widget()->boundingRect());
- + if (widget()->shape() != p) {
- + addedMargin = widget()->contentsRect().width() / 2;
- + }
- + }
- +
- + AbstractHandle::HandlePosition pos = position();
- + if (pos == AbstractHandle::Right) {
- + marginLeft += addedMargin;
- + } else {
- + marginRight += addedMargin;
- + }
- + }
- +
- + //m_rect = m_applet->mapToParent(m_rect).boundingRect();
- + m_decorationRect = m_rect.adjusted(-marginLeft, -marginTop, marginRight, marginBottom);
- + m_totalRect = m_decorationRect.united(widget()->boundingRect());
- +}
- +
- +} // Plasma Namespace
- +
- +#include "desktophandle.moc"
- +
- Index: private/applethandle_p.h
- ===================================================================
- --- private/applethandle_p.h (revisione 1171409)
- +++ private/applethandle_p.h (copia locale)
- @@ -1,154 +0,0 @@
- -/*
- - * Copyright 2007 by Kevin Ottens <ervin@kde.org>
- - *
- - * This program is free software; you can redistribute it and/or modify
- - * it under the terms of the GNU Library General Public License as
- - * published by the Free Software Foundation; either version 2, 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 Library 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 PLASMA_APPLETHANDLE_P_H
- -#define PLASMA_APPLETHANDLE_P_H
- -
- -#include <QtCore/QObject>
- -#include <QtGui/QGraphicsObject>
- -#include <QTimer>
- -#include <QWeakPointer>
- -#include <QPropertyAnimation>
- -
- -#include "animator.h"
- -#include "svg.h"
- -
- -class QGraphicsView;
- -
- -namespace Plasma
- -{
- -class Applet;
- -class Containment;
- -class FrameSvg;
- -class View;
- -
- -class AppletHandle : public QGraphicsObject
- -{
- - Q_OBJECT
- - Q_PROPERTY(qreal fadeAnimation READ fadeAnimation WRITE setFadeAnimation)
- - Q_INTERFACES(QGraphicsItem)
- - public:
- - enum FadeType {
- - FadeIn,
- - FadeOut
- - };
- - enum ButtonType {
- - NoButton,
- - MoveButton,
- - RotateButton,
- - ConfigureButton,
- - RemoveButton,
- - ResizeButton,
- - MaximizeButton
- - };
- -
- - AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos);
- - virtual ~AppletHandle();
- -
- - void detachApplet ();
- -
- - Applet *applet() const;
- -
- - QRectF boundingRect() const;
- - QPainterPath shape() const;
- - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
- - void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
- - void setHoverPos(const QPointF &hoverPos);
- -
- - protected:
- - void mousePressEvent(QGraphicsSceneMouseEvent *event);
- - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- - void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- - void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
- - void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
- - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
- - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
- - bool sceneEvent(QEvent*);
- -
- - Q_SIGNALS:
- - void disappearDone(AppletHandle *self);
- -
- - private Q_SLOTS:
- - void setFadeAnimation(qreal progress);
- - qreal fadeAnimation() const;
- - void appletDestroyed();
- - void appletResized();
- - void hoverTimeout();
- - void leaveTimeout();
- - void emitDisappear();
- -
- - private:
- - static const int HANDLE_MARGIN = 3;
- -
- - void calculateSize();
- - ButtonType mapToButton(const QPointF &point) const;
- - void forceDisappear();
- - int minimumHeight();
- -
- - /**
- - * move our applet to another containment
- - * @param containment the containment to move to
- - * @param pos the (scene-relative) position to place it at
- - */
- - void switchContainment(Containment *containment, const QPointF &pos);
- - bool leaveCurrentView(const QPoint &pos) const;
- -
- - QRectF m_rect;
- - QRectF m_decorationRect;
- - QRectF m_totalRect;
- - ButtonType m_pressedButton;
- - Containment *m_containment;
- - Applet *m_applet;
- - int m_iconSize;
- - qreal m_opacity;
- - FadeType m_animType;
- - QWeakPointer<QPropertyAnimation> m_anim;
- - qreal m_angle;
- - QColor m_gradientColor;
- - QTimer *m_hoverTimer;
- - QTimer *m_leaveTimer;
- - QPixmap *m_backgroundBuffer;
- - QGraphicsView *m_currentView;
- -
- - Svg *m_configureIcons;
- - FrameSvg *m_background;
- -
- - QPoint m_mousePos; //mousepos relative to applet
- - QPointF m_entryPos; //where the hover in event occurred
- - qreal m_zValue; //current zValue of the applet, so it can be restored after drag.
- - QRectF m_originalGeom;
- - QTransform m_originalTransform;
- -
- - // used for both resize and rotate
- - QPointF m_origAppletCenter;
- - QPointF m_origAppletSize;
- -
- - // used for resize
- - QPointF m_resizeStaticPoint;
- - QPointF m_resizeGrabPoint;
- - // used for rotate
- - qreal m_rotateAngleOffset; // applet angle minus cursor angle
- -
- - bool m_buttonsOnRight : 1;
- - bool m_pendingFade : 1;
- -};
- -
- -}
- -
- -#endif // multiple inclusion guard
- Index: private/containment_p.h
- ===================================================================
- --- private/containment_p.h (revisione 1171409)
- +++ private/containment_p.h (copia locale)
- @@ -37,6 +37,7 @@
- class Containment;
- class AbstractToolBox;
- class Animation;
- +class AbstractHandle;
- class ContainmentPrivate
- {
- @@ -89,7 +90,7 @@
- QPointF preferredPos(Corona *corona) const;
- QPointF preferredPanelPos(Corona *corona) const;
- void setLockToolText();
- - void handleDisappeared(AppletHandle *handle);
- + void handleDisappeared(AbstractHandle *handle);
- void appletDestroyed(Applet*);
- void appletAppearAnimationComplete();
- void appletAppeared(Applet*);
- @@ -164,7 +165,7 @@
- Applet::List applets;
- Applet *focusedApplet;
- Plasma::Wallpaper *wallpaper;
- - QMap<Applet*, AppletHandle*> handles;
- + QMap<QGraphicsWidget*, AbstractHandle*> handles;
- QHash<QString, ContainmentActions*> actionPlugins;
- int screen;
- int lastScreen;
- Index: private/resizecontrol.h
- ===================================================================
- --- private/resizecontrol.h (revisione 0)
- +++ private/resizecontrol.h (revisione 0)
- @@ -0,0 +1,61 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 RESIZECONTROL_H
- +#define RESIZECONTROL_H
- +
- +#include <QPointF>
- +#include <QRectF>
- +
- +#include "plasma.h"
- +#include "controlelement.h"
- +
- +class QGraphicsSceneMouseEvent;
- +
- +namespace Plasma
- +{
- +
- +class ResizeControl : public ControlElement
- +{
- + Q_OBJECT
- + public:
- + ResizeControl(QGraphicsWidget *widget);
- + virtual ~ResizeControl();
- +
- + ControlElement::ElementType elementType() const;
- + void setAspectRatioMode(AspectRatioMode mode);
- +
- + protected:
- + void mousePressEvent(QGraphicsSceneMouseEvent *event);
- + void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- +
- + private:
- + QRectF m_originalGeom;
- + QPointF m_origWidgetCenter;
- + QPointF m_origWidgetSize;
- + QPointF m_resizeStaticPoint;
- + QPointF m_resizeGrabPoint;
- + AspectRatioMode aspectRatioMode;
- +
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/maximizecontrol.cpp
- ===================================================================
- --- private/maximizecontrol.cpp (revisione 0)
- +++ private/maximizecontrol.cpp (revisione 0)
- @@ -0,0 +1,46 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "maximizecontrol.h"
- +
- +namespace Plasma
- +{
- +
- +MaximizeControl::MaximizeControl(QGraphicsWidget *widget)
- + : ControlElement(widget)
- +{
- +}
- +
- +MaximizeControl::~MaximizeControl()
- +{
- +}
- +
- +ControlElement::ElementType MaximizeControl::elementType() const
- +{
- + return ControlElement::MaximizeElement;
- +}
- +
- +void MaximizeControl::mouseClickEvent(QGraphicsSceneMouseEvent *)
- +{
- + emit finished(ControlElement::MaximizeElement);
- +}
- +
- +}
- +
- +#include "maximizecontrol.moc"
- Index: private/controlelement.cpp
- ===================================================================
- --- private/controlelement.cpp (revisione 0)
- +++ private/controlelement.cpp (revisione 0)
- @@ -0,0 +1,107 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "controlelement.h"
- +#include "controlelement_p.h"
- +
- +#include <QtGui/QWidget>
- +#include <QtGui/QGraphicsWidget>
- +
- +#include <Plasma/View>
- +#include <Plasma/Containment>
- +
- +#include "abstracthandle.h"
- +
- +namespace Plasma
- +{
- +
- +ControlElementPrivate::ControlElementPrivate(ControlElement *e)
- + : q(e)
- +{
- +
- +}
- +
- +ControlElementPrivate::~ControlElementPrivate()
- +{
- +
- +}
- +
- +
- +
- +ControlElement::ControlElement(QGraphicsWidget *widget)
- + : QObject(widget),
- + d(new ControlElementPrivate(this))
- +{
- + d->widget = widget;
- + d->handle = 0;
- +}
- +
- +ControlElement::~ControlElement()
- +{
- + delete d;
- +}
- +
- +QGraphicsWidget *ControlElement::widget() const
- +{
- + return d->widget;
- +}
- +
- +AbstractHandle *ControlElement::handle() const
- +{
- + return d->handle;
- +}
- +
- +bool ControlElement::leaveCurrentView(const QPoint &pos) const
- +{
- + foreach (QWidget *widget, QApplication::topLevelWidgets()) {
- + if (widget->geometry().contains(pos)) {
- + //is this widget a plasma view, a different view then our current one,
- + //AND not a dashboardview?
- + Plasma::View *v = qobject_cast<Plasma::View *>(widget);
- + if (v && v != d->handle->containment()->view() && v->containment() != d->handle->containment()) {
- + return true;
- + }
- + }
- + }
- + return false;
- +}
- +
- +void ControlElement::mousePressEvent(QGraphicsSceneMouseEvent *)
- +{
- +
- +}
- +
- +void ControlElement::mouseMoveEvent(QGraphicsSceneMouseEvent *)
- +{
- +
- +}
- +
- +void ControlElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
- +{
- +
- +}
- +
- +void ControlElement::mouseClickEvent(QGraphicsSceneMouseEvent *)
- +{
- +
- +}
- +
- +}
- +
- +#include "controlelement.moc"
- Index: private/removecontrol.cpp
- ===================================================================
- --- private/removecontrol.cpp (revisione 0)
- +++ private/removecontrol.cpp (revisione 0)
- @@ -0,0 +1,46 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "removecontrol.h"
- +
- +namespace Plasma
- +{
- +
- +RemoveControl::RemoveControl(QGraphicsWidget *widget)
- + : ControlElement(widget)
- +{
- +}
- +
- +RemoveControl::~RemoveControl()
- +{
- +}
- +
- +ControlElement::ElementType RemoveControl::elementType() const
- +{
- + return ControlElement::RemoveElement;
- +}
- +
- +void RemoveControl::mouseClickEvent(QGraphicsSceneMouseEvent *)
- +{
- + emit finished(ControlElement::RemoveElement);
- +}
- +
- +}
- +
- +#include "removecontrol.moc"
- Index: private/applethandle.cpp
- ===================================================================
- --- private/applethandle.cpp (revisione 1171409)
- +++ private/applethandle.cpp (copia locale)
- @@ -1,1056 +0,0 @@
- -/*
- - * Copyright 2007 by Kevin Ottens <ervin@kde.org>
- - *
- - * This program is free software; you can redistribute it and/or modify
- - * it under the terms of the GNU Library General Public License as
- - * published by the Free Software Foundation; either version 2, 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 Library 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 "private/applethandle_p.h"
- -
- -#include <QApplication>
- -#include <QBitmap>
- -#include <QtGui/QGraphicsSceneMouseEvent>
- -#include <QtGui/QLinearGradient>
- -#include <QtGui/QPainter>
- -#include <QtGui/QApplication>
- -#include <QtGui/QMenu>
- -#include <QTouchEvent>
- -#include <QMatrix>
- -#include <QTransform>
- -#include <QWeakPointer>
- -#include <QPropertyAnimation>
- -
- -#include <kcolorscheme.h>
- -#include <kglobalsettings.h>
- -#include <kicon.h>
- -#include <kiconloader.h>
- -#include <kwindowsystem.h>
- -
- -#include <cmath>
- -#include <math.h>
- -
- -#include "applet.h"
- -#include "applet_p.h"
- -#include "containment.h"
- -#include "corona.h"
- -#include "paintutils.h"
- -#include "theme.h"
- -#include "view.h"
- -#include "framesvg.h"
- -
- -namespace Plasma
- -{
- -
- -qreal _k_distanceForPoint(QPointF point);
- -qreal _k_pointAngle(QPointF point);
- -QPointF _k_rotatePoint(QPointF point, qreal angle);
- -QPointF _k_projectPoint(QPointF point, QPointF v);
- -
- -AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos)
- - : QGraphicsObject(applet),
- - m_pressedButton(NoButton),
- - m_containment(parent),
- - m_applet(applet),
- - m_iconSize(KIconLoader::SizeSmall),
- - m_opacity(0.0),
- - m_animType(FadeIn),
- - m_backgroundBuffer(0),
- - m_currentView(applet->view()),
- - m_entryPos(hoverPos),
- - m_buttonsOnRight(false),
- - m_pendingFade(false)
- -{
- - setFlags(flags() | QGraphicsItem::ItemStacksBehindParent);
- - KColorScheme colorScheme(QPalette::Active, KColorScheme::View,
- - Theme::defaultTheme()->colorScheme());
- - setAcceptTouchEvents(true);
- - m_gradientColor = colorScheme.background(KColorScheme::NormalBackground).color();
- - m_originalGeom = mapToScene(QRectF(QPoint(0,0), m_applet->size())).boundingRect();
- - m_originalTransform = m_applet->transform();
- -
- - QPointF center = QRectF(QPointF(), m_applet->size()).center();
- - m_angle = _k_pointAngle(m_originalTransform.map(center + QPointF(1.0, 0.0)) - center);
- -
- - m_hoverTimer = new QTimer(this);
- - m_hoverTimer->setSingleShot(true);
- - m_hoverTimer->setInterval(333);
- -
- - m_leaveTimer = new QTimer(this);
- - m_leaveTimer->setSingleShot(true);
- - m_leaveTimer->setInterval(500);
- -
- - connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
- - connect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
- - connect(m_applet, SIGNAL(appletDestroyed(Plasma::Applet*)), this, SLOT(appletDestroyed()));
- -
- - setAcceptsHoverEvents(true);
- - m_hoverTimer->start();
- -
- - //icons
- - m_configureIcons = new Svg(this);
- - m_configureIcons->setImagePath("widgets/configuration-icons");
- - m_configureIcons->setContainsMultipleImages(true);
- -
- - m_background = new FrameSvg(this);
- - m_background->setImagePath("widgets/background");
- - m_applet->installSceneEventFilter(this);
- -}
- -
- -AppletHandle::~AppletHandle()
- -{
- - detachApplet();
- - delete m_backgroundBuffer;
- -}
- -
- -Applet *AppletHandle::applet() const
- -{
- - return m_applet;
- -}
- -
- -void AppletHandle::detachApplet()
- -{
- - if (!m_applet) {
- - return;
- - }
- -
- - disconnect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
- - disconnect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
- - m_applet->disconnect(this);
- -
- - if (m_applet->geometry() != m_originalGeom || m_applet->transform() != m_originalTransform) {
- - emit m_applet->appletTransformedByUser();
- - }
- -
- - m_applet = 0;
- -}
- -
- -QRectF Plasma::AppletHandle::boundingRect() const
- -{
- - return m_totalRect;
- -}
- -
- -QPainterPath AppletHandle::shape() const
- -{
- - //when the containment changes the applet is reset to 0
- - if (m_applet) {
- - QPainterPath path = PaintUtils::roundedRectangle(m_decorationRect, 10);
- - return path.united(m_applet->shape());
- - } else {
- - return QGraphicsItem::shape();
- - }
- -}
- -
- -QPainterPath handleRect(const QRectF &rect, int radius, bool onRight)
- -{
- - QPainterPath path;
- - if (onRight) {
- - // make the left side straight
- - path.moveTo(rect.left(), rect.top()); // Top left
- - path.lineTo(rect.right() - radius, rect.top()); // Top side
- - path.quadTo(rect.right(), rect.top(),
- - rect.right(), rect.top() + radius); // Top right corner
- - path.lineTo(rect.right(), rect.bottom() - radius); // Right side
- - path.quadTo(rect.right(), rect.bottom(),
- - rect.right() - radius, rect.bottom()); // Bottom right corner
- - path.lineTo(rect.left(), rect.bottom()); // Bottom side
- - } else {
- - // make the right side straight
- - path.moveTo(QPointF(rect.left(), rect.top() + radius));
- - path.quadTo(rect.left(), rect.top(),
- - rect.left() + radius, rect.top()); // Top left corner
- - path.lineTo(rect.right(), rect.top()); // Top side
- - path.lineTo(rect.right(), rect.bottom()); // Right side
- - path.lineTo(rect.left() + radius, rect.bottom()); // Bottom side
- - path.quadTo(rect.left(), rect.bottom(),
- - rect.left(), rect.bottom() - radius); // Bottom left corner
- - }
- -
- - path.closeSubpath();
- - return path;
- -}
- -
- -void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
- -{
- - Q_UNUSED(option);
- - Q_UNUSED(widget);
- -
- - //kDebug() << m_opacity << m_anim << FadeOut;
- - if (qFuzzyCompare(m_opacity + 1.0, 1.0)) {
- - if (m_animType == FadeOut) {
- - //kDebug() << "WOOOOOOOOO";
- - QTimer::singleShot(0, this, SLOT(emitDisappear()));
- - }
- - return;
- - }
- -
- - qreal translation;
- -
- - if (m_buttonsOnRight) {
- - //kDebug() << "translating by" << m_opacity
- - // << (-(1 - m_opacity) * m_rect.width()) << m_rect.width();
- - translation = -(1 - m_opacity) * m_rect.width();
- - } else {
- - translation = (1 - m_opacity) * m_rect.width();
- - }
- -
- - painter->translate(translation, 0);
- -
- - painter->setPen(Qt::NoPen);
- - painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
- -
- - int iconMargin = m_iconSize / 2;
- -
- - const QSize pixmapSize(int(m_decorationRect.width()),
- - int(m_decorationRect.height()) + m_iconSize * 5 + 1);
- - const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
- -
- - bool isRunning = false;
- - if (m_anim.data()) {
- - isRunning = m_anim.data()->state() == QAbstractAnimation::Running ? \
- - true : false;
- - }
- -
- - //regenerate our buffer?
- - if (isRunning || !m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
- - QColor transparencyColor = Qt::black;
- - transparencyColor.setAlphaF(qMin(m_opacity, qreal(0.99)));
- -
- - QLinearGradient g(QPoint(0, 0), QPoint(m_decorationRect.width(), 0));
- - //fading out panel
- - if (m_rect.height() > qreal(minimumHeight()) * 1.25) {
- - if (m_buttonsOnRight) {
- - qreal opaquePoint =
- - (m_background->marginSize(LeftMargin) - translation) / m_decorationRect.width();
- - //kDebug() << "opaquePoint" << opaquePoint
- - // << m_background->marginSize(LeftMargin) << m_decorationRect.width();
- - g.setColorAt(0.0, Qt::transparent);
- - g.setColorAt(qMax(0.0, opaquePoint - 0.05), Qt::transparent);
- - g.setColorAt(opaquePoint, transparencyColor);
- - g.setColorAt(1.0, transparencyColor);
- - } else {
- - qreal opaquePoint =
- - 1 - ((m_background->marginSize(RightMargin) + translation) / m_decorationRect.width());
- - g.setColorAt(1.0, Qt::transparent);
- - g.setColorAt(opaquePoint + 0.05, Qt::transparent);
- - g.setColorAt(qMax(qreal(0), opaquePoint), transparencyColor);
- - g.setColorAt(0.0, transparencyColor);
- - }
- - //complete panel
- - } else {
- - g.setColorAt(0.0, transparencyColor);
- - }
- -
- - m_background->resizeFrame(m_decorationRect.size());
- -
- - if (!m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
- - delete m_backgroundBuffer;
- - m_backgroundBuffer = new QPixmap(pixmapSize);
- - }
- - m_backgroundBuffer->fill(Qt::transparent);
- - QPainter buffPainter(m_backgroundBuffer);
- -
- - m_background->paintFrame(&buffPainter);
- -
- - //+1 because otherwise due to rounding errors when rotated could appear one pixel
- - //of the icon at the border of the applet
- - //QRectF iconRect(QPointF(pixmapSize.width() - m_iconSize + 1, m_iconSize), iconSize);
- - QRectF iconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
- - if (m_buttonsOnRight) {
- - iconRect.moveLeft(
- - pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
- - m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tr2bl");
- - } else {
- - iconRect.moveLeft(m_background->marginSize(RightMargin));
- - m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tl2br");
- - }
- -
- - iconRect.translate(0, m_iconSize);
- - m_configureIcons->paint(&buffPainter, iconRect, "rotate");
- -
- - if (m_applet && m_applet->hasConfigurationInterface()) {
- - iconRect.translate(0, m_iconSize);
- - m_configureIcons->paint(&buffPainter, iconRect, "configure");
- - }
- -
- - if (m_applet && m_applet->hasValidAssociatedApplication()) {
- - iconRect.translate(0, m_iconSize);
- - m_configureIcons->paint(&buffPainter, iconRect, "maximize");
- - }
- -
- - iconRect.translate(0, m_iconSize);
- - m_configureIcons->paint(&buffPainter, iconRect, "close");
- -
- - buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
- - //blend the background
- - buffPainter.fillRect(m_backgroundBuffer->rect(), g);
- - //blend the icons
- - //buffPainter.fillRect(QRect(QPoint((int)m_decorationRect.width(), 0), QSize(m_iconSize + 1,
- - // (int)m_decorationRect.height())), transparencyColor);
- - }
- -
- - painter->drawPixmap(m_decorationRect.toRect(), *m_backgroundBuffer,
- - QRect(QPoint(0, 0), m_decorationRect.size().toSize()));
- -
- - //XXX this code is duplicated in the next function
- - QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
- - QPointF step = QPointF(0, m_iconSize + iconMargin);
- - QPointF separator = step + QPointF(0, iconMargin);
- - //end duplicate code
- -
- - QPointF shiftC;
- - QPointF shiftD;
- - QPointF shiftR;
- - QPointF shiftM;
- - QPointF shiftMx;
- -
- - switch(m_pressedButton)
- - {
- - case ConfigureButton:
- - shiftC = QPointF(2, 2);
- - break;
- - case RemoveButton:
- - shiftD = QPointF(2, 2);
- - break;
- - case RotateButton:
- - shiftR = QPointF(2, 2);
- - break;
- - case ResizeButton:
- - shiftM = QPointF(2, 2);
- - break;
- - case MaximizeButton:
- - shiftMx = QPointF(2, 2);
- - break;
- - default:
- - break;
- - }
- -
- - QRectF sourceIconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
- - if (m_buttonsOnRight) {
- - sourceIconRect.moveLeft(
- - pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
- - } else {
- - sourceIconRect.moveLeft(m_background->marginSize(RightMargin));
- - }
- -
- - if (m_applet && m_applet->aspectRatioMode() != FixedSize) {
- - //resize
- - painter->drawPixmap(
- - QRectF(basePoint + shiftM, iconSize), *m_backgroundBuffer, sourceIconRect);
- - basePoint += step;
- - }
- -
- - //rotate
- - sourceIconRect.translate(0, m_iconSize);
- - painter->drawPixmap(QRectF(basePoint + shiftR, iconSize), *m_backgroundBuffer, sourceIconRect);
- -
- - //configure
- - if (m_applet && m_applet->hasConfigurationInterface()) {
- - basePoint += step;
- - sourceIconRect.translate(0, m_iconSize);
- - painter->drawPixmap(
- - QRectF(basePoint + shiftC, iconSize), *m_backgroundBuffer, sourceIconRect);
- - }
- -
- - //maximize
- - if (m_applet && m_applet->hasValidAssociatedApplication()) {
- - basePoint += step;
- - sourceIconRect.translate(0, m_iconSize);
- - painter->drawPixmap(
- - QRectF(basePoint + shiftMx, iconSize), *m_backgroundBuffer, sourceIconRect);
- - }
- -
- - //close
- - basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step;
- - sourceIconRect.translate(0, m_iconSize);
- - painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect);
- -}
- -
- -void AppletHandle::emitDisappear()
- -{
- - emit disappearDone(this);
- -}
- -
- -AppletHandle::ButtonType AppletHandle::mapToButton(const QPointF &point) const
- -{
- - int iconMargin = m_iconSize / 2;
- - //XXX this code is duplicated in the prev. function
- - QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
- - QPointF step = QPointF(0, m_iconSize + iconMargin);
- - QPointF separator = step + QPointF(0, iconMargin);
- - //end duplicate code
- -
- - QRectF activeArea = QRectF(basePoint, QSizeF(m_iconSize, m_iconSize));
- -
- - if (m_applet && m_applet->aspectRatioMode() != FixedSize) {
- - if (activeArea.contains(point)) {
- - return ResizeButton;
- - }
- - activeArea.translate(step);
- - }
- -
- - if (activeArea.contains(point)) {
- - return RotateButton;
- - }
- -
- - if (m_applet && m_applet->hasConfigurationInterface()) {
- - activeArea.translate(step);
- - if (activeArea.contains(point)) {
- - return ConfigureButton;
- - }
- - }
- -
- - if (m_applet && m_applet->hasValidAssociatedApplication()) {
- - activeArea.translate(step);
- - if (activeArea.contains(point)) {
- - return MaximizeButton;
- - }
- - }
- -
- - activeArea.moveTop(m_rect.bottom() - activeArea.height() - iconMargin);
- - if (activeArea.contains(point)) {
- - return RemoveButton;
- - }
- -
- - return MoveButton;
- - //return m_applet->mapToParent(m_applet->shape()).contains(point) ? NoButton : MoveButton;
- -}
- -
- -void AppletHandle::mousePressEvent(QGraphicsSceneMouseEvent *event)
- -{
- - //containment recently switched?
- - if (!m_applet) {
- - QGraphicsItem::mousePressEvent(event);
- - return;
- - }
- -
- - if (m_pendingFade) {
- - //m_pendingFade = false;
- - return;
- - }
- -
- - if (event->button() == Qt::LeftButton) {
- - m_pressedButton = mapToButton(event->pos());
- - //kDebug() << "button pressed:" << m_pressedButton;
- - if (m_pressedButton != NoButton) {
- - m_applet->raise();
- - m_zValue = m_applet->zValue();
- - setZValue(m_zValue);
- - }
- -
- - if (m_pressedButton == ResizeButton || m_pressedButton == RotateButton) {
- - m_originalGeom = mapToScene(QRectF(QPoint(0,0), m_applet->size())).boundingRect();
- - m_origAppletCenter = m_originalGeom.center();
- - m_origAppletSize = QPointF(m_applet->size().width(), m_applet->size().height());
- -
- - // resize
- - if (m_buttonsOnRight) {
- - m_resizeStaticPoint = m_applet->mapToScene(QPointF(0, m_applet->size().height()));
- - } else {
- - m_resizeStaticPoint = m_applet->mapToScene(m_origAppletSize);
- - }
- - m_resizeGrabPoint = event->scenePos();
- -
- - // rotate
- - m_rotateAngleOffset = m_angle - _k_pointAngle(event->scenePos() - m_origAppletCenter);
- - }
- -
- - event->accept();
- -
- - //set mousePos to the position in the applet, in screencoords, so it becomes easy
- - //to reposition the toplevel view to the correct position.
- - if (m_currentView && m_applet) {
- - QPoint localpos = m_currentView->mapFromScene(m_applet->scenePos());
- - m_mousePos = event->screenPos() - m_currentView->mapToGlobal(localpos);
- - }
- - return;
- - }
- -
- - QGraphicsItem::mousePressEvent(event);
- -}
- -
- -bool AppletHandle::leaveCurrentView(const QPoint &pos) const
- -{
- - foreach (QWidget *widget, QApplication::topLevelWidgets()) {
- - if (widget->geometry().contains(pos)) {
- - //is this widget a plasma view, a different view then our current one,
- - //AND not a dashboardview?
- - Plasma::View *v = qobject_cast<Plasma::View *>(widget);
- - if (v && v != m_currentView && v->containment() != m_containment) {
- - return true;
- - }
- - }
- - }
- - return false;
- -}
- -
- -void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
- -{
- - //kDebug() << "button pressed:" << m_pressedButton << ", fade pending?" << m_pendingFade;
- -
- - if (m_pendingFade) {
- - startFading(FadeOut, m_entryPos);
- - m_pendingFade = false;
- - }
- -
- - ButtonType releasedAtButton = mapToButton(event->pos());
- -
- - if (m_applet && event->button() == Qt::LeftButton) {
- - switch (m_pressedButton) {
- - case ConfigureButton:
- - //FIXME: Remove this call once the configuration management change was done
- - if (m_pressedButton == releasedAtButton) {
- - m_applet->showConfigurationInterface();
- - }
- - break;
- - case RemoveButton:
- - if (m_pressedButton == releasedAtButton) {
- - forceDisappear();
- - m_applet->destroy();
- - }
- - break;
- - case MoveButton:
- - {
- - // test for containment change
- - //kDebug() << "testing for containment change, sceneBoundingRect = "
- - // << m_containment->sceneBoundingRect();
- - if (!m_containment->sceneBoundingRect().contains(m_applet->scenePos())) {
- - // see which containment it belongs to
- - Corona * corona = qobject_cast<Corona*>(scene());
- - if (corona) {
- - foreach (Containment *containment, corona->containments()) {
- - QPointF pos;
- - QGraphicsView *v = containment->view();
- - if (v) {
- - pos = v->mapToScene(v->mapFromGlobal(event->screenPos() - m_mousePos));
- -
- - if (containment->sceneBoundingRect().contains(pos)) {
- - //kDebug() << "new containment = " << containments[i];
- - //kDebug() << "rect = " << containments[i]->sceneBoundingRect();
- - // add the applet to the new containment and take it from the old one
- - //kDebug() << "moving to other containment with position" << pos;;
- - switchContainment(containment, pos);
- - break;
- - }
- - }
- - }
- - }
- - }
- - break;
- - }
- - case MaximizeButton:
- - if (m_applet) {
- - m_applet->runAssociatedApplication();
- - }
- - break;
- - default:
- - break;
- - }
- - }
- -
- - m_pressedButton = NoButton;
- - update();
- -}
- -
- -qreal _k_distanceForPoint(QPointF point)
- -{
- - return std::sqrt(point.x() * point.x() + point.y() * point.y());
- -}
- -
- -qreal _k_pointAngle(QPointF point)
- -{
- - qreal r = sqrt(point.x() * point.x() + point.y() * point.y());
- - qreal cosine = point.x() / r;
- -
- - if (point.y() >= 0) {
- - return acos(cosine);
- - } else {
- - return -acos(cosine);
- - }
- -}
- -
- -QPointF _k_rotatePoint(QPointF point, qreal angle)
- -{
- - return QTransform().rotateRadians(angle).map(point);
- -}
- -
- -QPointF _k_projectPoint(QPointF point, QPointF v)
- -{
- - v /= sqrt(v.x() * v.x() + v.y() * v.y());
- - qreal a = v.x() * v.x();
- - qreal b = v.x() * v.y();
- - qreal d = v.y() * v.y();
- - return QMatrix(a, b, b, d, 0., 0.).map(point);
- -}
- -
- -void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
- -{
- - static const qreal snapAngle = M_PI_2 /* $i 3.14159 / 2.0 */;
- -
- - if (!m_applet) {
- - QGraphicsItem::mouseMoveEvent(event);
- - return;
- - }
- -
- - //Track how much the mouse has moved.
- - QPointF deltaScene = event->scenePos() - event->lastScenePos();
- -
- - if (m_pressedButton == MoveButton) {
- - if (leaveCurrentView(event->screenPos())) {
- - Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
- - if (v && v != m_currentView) {
- - Containment *c = v->containment();
- - if (c) {
- - QPoint pos = v->mapFromGlobal(event->screenPos());
- - //we actually have been dropped on another containment, so
- - //move there: we have a screenpos, we need a scenepos
- - //FIXME how reliable is this transform?
- - switchContainment(c, v->mapToScene(pos));
- - }
- - }
- - }
- -
- - if (m_applet) {
- - QPointF mappedPoint = transform().map(QPointF(deltaScene.x(), deltaScene.y()));
- - m_applet->moveBy(mappedPoint.x(), mappedPoint.y());
- - }
- - } else if (m_pressedButton == ResizeButton || m_pressedButton == RotateButton) {
- - QPointF cursorPoint = event->scenePos();
- -
- - // the code below will adjust these based on the type of operation
- - QPointF newSize;
- - QPointF newCenter;
- - qreal newAngle;
- -
- - // get size limits
- - QSizeF min = m_applet->minimumSize();
- - QSizeF max = m_applet->maximumSize();
- -
- - if (min.width() < KIconLoader::SizeSmall || min.height() < KIconLoader::SizeSmall) {
- - min = m_applet->effectiveSizeHint(Qt::MinimumSize);
- - }
- -
- - if (max.isEmpty()) {
- - max = m_applet->effectiveSizeHint(Qt::MaximumSize);
- - }
- -
- - // If the applet doesn't have a minimum size, calculate based on a
- - // minimum content area size of 16x16 (KIconLoader::SizeSmall)
- - if (min.width() < KIconLoader::SizeSmall || min.height() < KIconLoader::SizeSmall) {
- - min = m_applet->boundingRect().size() - m_applet->contentsRect().size();
- - min = QSizeF(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
- - }
- -
- - if (m_pressedButton == RotateButton) {
- - newSize = m_origAppletSize;
- - newCenter = m_origAppletCenter;
- -
- - QPointF centerRelativePoint = cursorPoint - m_origAppletCenter;
- - if (_k_distanceForPoint(centerRelativePoint) < 10) {
- - newAngle = m_angle;
- - } else {
- - qreal cursorAngle = _k_pointAngle(centerRelativePoint);
- - newAngle = m_rotateAngleOffset + cursorAngle;
- - if (fabs(remainder(newAngle, snapAngle)) < 0.15) {
- - newAngle = newAngle - remainder(newAngle, snapAngle);
- - }
- - }
- - } else {
- - // un-rotate screen points so we can read differences of coordinates
- - QPointF rStaticPoint = _k_rotatePoint(m_resizeStaticPoint, -m_angle);
- - QPointF rCursorPoint = _k_rotatePoint(cursorPoint, -m_angle);
- - QPointF rGrabPoint = _k_rotatePoint(m_resizeGrabPoint, -m_angle);
- -
- - if (m_buttonsOnRight) {
- - newSize = m_origAppletSize + QPointF(rCursorPoint.x() - rGrabPoint.x(), rGrabPoint.y() - rCursorPoint.y());
- - } else {
- - newSize = m_origAppletSize + QPointF(rGrabPoint.x() - rCursorPoint.x(), rGrabPoint.y() - rCursorPoint.y());
- - }
- -
- - // preserving aspect ratio?
- - if ((m_applet->aspectRatioMode() != Plasma::IgnoreAspectRatio &&
- - !(event->modifiers() & Qt::ControlModifier)) ||
- - (m_applet->aspectRatioMode() == Plasma::IgnoreAspectRatio &&
- - (event->modifiers() & Qt::ControlModifier))) {
- - // project size to keep ratio
- - newSize = _k_projectPoint(newSize, m_origAppletSize);
- - // limit size, presering ratio
- - qreal ratio = m_origAppletSize.y() / m_origAppletSize.x();
- - newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
- - newSize.ry() = newSize.x() * ratio;
- - newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
- - newSize.rx() = newSize.y() / ratio;
- - } else {
- - // limit size
- - newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
- - newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
- - }
- -
- - // move center such that the static corner remains in the same place
- - if (m_buttonsOnRight) {
- - newCenter = _k_rotatePoint(QPointF(rStaticPoint.x() + newSize.x()/2,
- - rStaticPoint.y() - newSize.y()/2), m_angle);
- - } else {
- - newCenter = _k_rotatePoint(QPointF(rStaticPoint.x() - newSize.x()/2,
- - rStaticPoint.y() - newSize.y()/2), m_angle);
- - }
- -
- - newAngle = m_angle;
- - }
- -
- - // apply size
- - m_applet->resize(newSize.x(), newSize.y());
- - // apply position, no need if we're rotating
- - if (m_pressedButton != RotateButton) {
- - m_applet->setPos(m_containment->mapFromScene(newCenter - newSize/2));
- - }
- -
- - // apply angle
- - QTransform at;
- - at.translate(newSize.x()/2, newSize.y()/2);
- - at.rotateRadians(newAngle);
- - at.translate(-newSize.x()/2, -newSize.y()/2);
- - m_applet->setTransform(at);
- - m_angle = newAngle;
- - } else {
- - QGraphicsItem::mouseMoveEvent(event);
- - }
- -}
- -
- -bool AppletHandle::sceneEvent(QEvent *event)
- -{
- - switch (event->type()) {
- - case QEvent::TouchEnd: {
- - QTransform t = m_applet->transform();
- - QRectF geom = m_applet->geometry();
- - QPointF translation(t.m31(), t.m32());
- - QPointF center = geom.center();
- - geom.setWidth(geom.width()*qAbs(t.m11()));
- - geom.setHeight(geom.height()*qAbs(t.m22()));
- - geom.moveCenter(center);
- -
- - m_applet->setGeometry(geom);
- - t.reset();
- - t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
- - t.rotateRadians(m_angle);
- - t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
- -
- -
- - m_applet->setTransform(t);
- - return true;
- - }
- - case QEvent::TouchBegin:
- - case QEvent::TouchUpdate:
- - {
- - QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
- - if (touchPoints.count() == 2) {
- - const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
- - const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
- -
- - //rotation
- - QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos());
- - QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos());
- - m_angle = m_angle+(line1.angleTo(line0)*M_PI_2/90);
- - QTransform t = m_applet->transform();
- - t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
- - t.rotate(line1.angleTo(line0));
- -
- - //scaling
- - qreal scaleFactor = 1;
- - if (line0.length() > 0) {
- - scaleFactor = line1.length() / line0.length();
- - }
- -
- - t.scale(scaleFactor, scaleFactor);
- - t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
- - m_applet->setTransform(t);
- -
- - }
- - return true;
- - }
- - default:
- - break;
- - }
- - return QGraphicsItem::sceneEvent(event);
- -}
- -
- -//pos relative to scene
- -void AppletHandle::switchContainment(Containment *containment, const QPointF &pos)
- -{
- - m_containment = containment;
- - Applet *applet = m_applet;
- - m_applet = 0; //make sure we don't try to act on the applet again
- - applet->removeSceneEventFilter(this);
- - forceDisappear(); //takes care of event filter and killing handle
- - applet->disconnect(this); //make sure the applet doesn't tell us to do anything
- - //applet->setZValue(m_zValue);
- - containment->addApplet(applet, containment->mapFromScene(pos), false);
- - deleteLater();
- -}
- -
- -void AppletHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
- -{
- - Q_UNUSED(event);
- - //kDebug() << "hover enter";
- -
- - //if a disappear was scheduled stop the timer
- - if (m_leaveTimer->isActive()) {
- - m_leaveTimer->stop();
- - }
- - // if we're already fading out, fade back in
- - else if (!m_anim.data() && m_animType == FadeOut) {
- - startFading(FadeIn, m_entryPos, true);
- - }
- -}
- -
- -void AppletHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
- -{
- - hoverEnterEvent(event);
- -}
- -
- -void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
- -{
- - Q_UNUSED(event);
- -
- - foreach (QWidget *widget, QApplication::topLevelWidgets()) {
- - QMenu *menu = qobject_cast<QMenu*>(widget);
- - if (menu && menu->isVisible()) {
- - connect(menu, SIGNAL(aboutToHide()), this, SLOT(leaveTimeout()));
- - return;
- - }
- - }
- -
- -
- - // if we haven't even showed up yet, remove the handle
- - if (m_hoverTimer->isActive()) {
- - m_hoverTimer->stop();
- - QTimer::singleShot(0, this, SLOT(emitDisappear()));
- - } else if (m_pressedButton != NoButton) {
- - m_pendingFade = true;
- - } else {
- - //wait a moment to hide the handle in order to recheck the mouse position
- - m_leaveTimer->start();
- - }
- -}
- -
- -bool AppletHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
- -{
- - if (watched == m_applet && event->type() == QEvent::GraphicsSceneHoverLeave) {
- - hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent*>(event));
- - }
- -
- - return false;
- -}
- -
- -void AppletHandle::setFadeAnimation(qreal progress)
- -{
- - m_opacity = progress;
- - //kDebug() << "progress" << progress << "m_opacity" << m_opacity << m_anim << "(" << FadeIn << ")";
- - if (qFuzzyCompare(progress, qreal(1.0))) {
- - delete m_backgroundBuffer;
- - m_backgroundBuffer = 0;
- - }
- -
- - update();
- -}
- -
- -qreal AppletHandle::fadeAnimation() const
- -{
- - return m_opacity;
- -}
- -
- -void AppletHandle::hoverTimeout()
- -{
- - startFading(FadeIn, m_entryPos);
- -}
- -
- -void AppletHandle::leaveTimeout()
- -{
- - if (!isUnderMouse()) {
- - startFading(FadeOut, m_entryPos);
- - }
- -}
- -
- -void AppletHandle::appletDestroyed()
- -{
- - m_applet = 0;
- -}
- -
- -void AppletHandle::appletResized()
- -{
- - prepareGeometryChange();
- - calculateSize();
- - update();
- -}
- -
- -void AppletHandle::setHoverPos(const QPointF &hoverPos)
- -{
- - m_entryPos = hoverPos;
- -}
- -
- -void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide)
- -{
- - QPropertyAnimation *propAnim = m_anim.data();
- -
- - if (anim == FadeIn) {
- - if (propAnim) {
- - propAnim->stop();
- - } else {
- - propAnim = new QPropertyAnimation(this, "fadeAnimation", this);
- - m_anim = propAnim;
- - }
- - }
- -
- - m_entryPos = hoverPos;
- - qreal time = 100;
- -
- - if (!m_applet) {
- - m_animType = FadeOut;
- - setFadeAnimation(1.0);
- - return;
- - }
- -
- - if (anim == FadeIn) {
- - //kDebug() << m_entryPos.x() << m_applet->pos().x();
- - prepareGeometryChange();
- - bool wasOnRight = m_buttonsOnRight;
- - if (!preserveSide) {
- - m_buttonsOnRight = m_entryPos.x() > (m_applet->size().width() / 2);
- - }
- - calculateSize();
- - QPolygonF region = m_applet->mapToParent(m_rect).intersected(m_applet->parentWidget()->boundingRect());
- - //kDebug() << region << m_rect << mapToParent(m_rect) << containmnet->boundingRect();
- - if (region != m_applet->mapToParent(m_rect)) {
- - // switch sides
- - //kDebug() << "switch sides";
- - m_buttonsOnRight = !m_buttonsOnRight;
- - calculateSize();
- - QPolygonF region2 = m_applet->mapToParent(m_rect).intersected(m_applet->parentWidget()->boundingRect());
- - if (region2 != mapToParent(m_rect)) {
- - // ok, both sides failed to be perfect... which one is more perfect?
- - QRectF f1 = region.boundingRect();
- - QRectF f2 = region2.boundingRect();
- - //kDebug() << "still not a perfect world"
- - // << f2.width() << f2.height() << f1.width() << f1.height();
- - if ((f2.width() * f2.height()) < (f1.width() * f1.height())) {
- - //kDebug() << "we did better the first time";
- - m_buttonsOnRight = !m_buttonsOnRight;
- - calculateSize();
- - }
- - }
- - }
- -
- - if (wasOnRight != m_buttonsOnRight &&
- - m_animType == FadeIn &&
- - anim == FadeIn &&
- - m_opacity <= 1) {
- - m_opacity = 0.0;
- - }
- -
- - time *= 1.0 - m_opacity;
- - } else {
- - time *= m_opacity;
- - }
- -
- - if (propAnim) {
- - propAnim->setStartValue(0);
- - propAnim->setEndValue(1);
- - propAnim->setDuration(time);
- - }
- -
- - m_animType = anim;
- - //kDebug() << "animating for " << time << "ms";
- - if (m_animType == FadeIn) {
- - propAnim->setDirection(QAbstractAnimation::Forward);
- - propAnim->start();
- - } else if (propAnim) {
- - propAnim->setDirection(QAbstractAnimation::Backward);
- - propAnim->start(QAbstractAnimation::DeleteWhenStopped);
- - }
- -}
- -
- -void AppletHandle::forceDisappear()
- -{
- - setAcceptsHoverEvents(false);
- - startFading(FadeOut, m_entryPos);
- -}
- -
- -int AppletHandle::minimumHeight()
- -{
- - int iconMargin = m_iconSize / 2;
- - int requiredHeight = iconMargin + //first margin
- - (m_iconSize + iconMargin) * 4 + //XXX remember to update this if the number of buttons changes
- - iconMargin ; //blank space before the close button
- -
- - if (m_applet && m_applet->hasConfigurationInterface()) {
- - requiredHeight += (m_iconSize + iconMargin);
- - }
- -
- - return requiredHeight;
- -}
- -
- -void AppletHandle::calculateSize()
- -{
- - KIconLoader *iconLoader = KIconLoader::global();
- - //m_iconSize = iconLoader->currentSize(KIconLoader::Small); //does not work with double sized icon
- - m_iconSize = iconLoader->loadIcon("transform-scale", KIconLoader::Small).width(); //workaround
- -
- - int handleHeight = qMax(minimumHeight(), int(m_applet->contentsRect().height() * 0.8));
- - int handleWidth = m_iconSize + 2 * HANDLE_MARGIN;
- - int top =
- - m_applet->contentsRect().top() + (m_applet->contentsRect().height() - handleHeight) / 2.0;
- -
- - qreal marginLeft, marginTop, marginRight, marginBottom;
- - m_background->getMargins(marginLeft, marginTop, marginRight, marginBottom);
- -
- - if (m_buttonsOnRight) {
- - //put the rect on the right of the applet
- - m_rect = QRectF(m_applet->size().width(), top, handleWidth, handleHeight);
- - } else {
- - //put the rect on the left of the applet
- - m_rect = QRectF(-handleWidth, top, handleWidth, handleHeight);
- - }
- -
- - if (m_applet->contentsRect().height() > qreal(minimumHeight()) * 1.25) {
- - int addedMargin = marginLeft / 2;
- -
- - // now we check to see if the shape is smaller than the contents,
- - // and that the shape is not just the bounding rect; in those cases
- - // we have a shaped guy and we draw a full panel;
- - // TODO: allow applets to mark when they have translucent areas and
- - // should therefore skip this test?
- - if (!m_applet->shape().contains(m_applet->contentsRect())) {
- - QPainterPath p;
- - p.addRect(m_applet->boundingRect());
- - if (m_applet->shape() != p) {
- - addedMargin = m_applet->contentsRect().width() / 2;
- - }
- - }
- -
- - if (m_buttonsOnRight) {
- - marginLeft += addedMargin;
- - } else {
- - marginRight += addedMargin;
- - }
- - }
- -
- - //m_rect = m_applet->mapToParent(m_rect).boundingRect();
- - m_decorationRect = m_rect.adjusted(-marginLeft, -marginTop, marginRight, marginBottom);
- - m_totalRect = m_decorationRect.united(m_applet->boundingRect());
- -}
- -
- -} // Plasma Namespace
- -
- -#include "applethandle_p.moc"
- -
- Index: private/configurecontrol.cpp
- ===================================================================
- --- private/configurecontrol.cpp (revisione 0)
- +++ private/configurecontrol.cpp (revisione 0)
- @@ -0,0 +1,46 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 "configurecontrol.h"
- +
- +namespace Plasma
- +{
- +
- +ConfigureControl::ConfigureControl(QGraphicsWidget *widget)
- + : ControlElement(widget)
- +{
- +}
- +
- +ConfigureControl::~ConfigureControl()
- +{
- +}
- +
- +ControlElement::ElementType ConfigureControl::elementType() const
- +{
- + return ControlElement::ConfigureElement;
- +}
- +
- +void ConfigureControl::mouseClickEvent(QGraphicsSceneMouseEvent *)
- +{
- + emit finished(ControlElement::ConfigureElement);
- +}
- +
- +}
- +
- +#include "configurecontrol.moc"
- Index: private/abstracthandle.h
- ===================================================================
- --- private/abstracthandle.h (revisione 0)
- +++ private/abstracthandle.h (revisione 0)
- @@ -0,0 +1,184 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 ABSTRACTHANDLE_H
- +#define ABSTRACTHANDLE_H
- +
- +#include <QtGui/QGraphicsObject>
- +
- +#include "controlelement.h"
- +
- +class QGraphicsView;
- +
- +namespace Plasma
- +{
- +
- +class AbstractHandlePrivate;
- +class Containment;
- +
- +/**
- + * @class AbstractHandle plasma/private/abstracthandle.h
- + *
- + * @short The base Handle class
- + *
- + * AbstractHandle is a base class providing all the conveniences needed
- + * to build an handle used by Plasma to provide the user a way to manage
- + * the Applets and maybe other widgets inside the Containments.
- + *
- + * An AbstractHandle subclass has some Control Elements which do the actual
- + * work of managing the widget. The handle takes care only of the eye-candy.
- + *
- + * A widget that wants to be managed by an handle must create some Control
- + * Elements and must provide them through a property "controlElements"
- + * returning a QList<ControlElement *>.
- + */
- +class AbstractHandle : public QGraphicsObject
- +{
- + Q_OBJECT
- + Q_INTERFACES(QGraphicsItem)
- + public:
- + /**
- + * Describes where the handle will draw relative to the widget.
- + */
- + enum HandlePosition {
- + Top, /**< It will be drawn on the top of the widget */
- + Right, /**< It will be drawn on the right of the widget */
- + Bottom, /**< It will be drawn on the bottom of the widget */
- + Left, /**< It will be drawn on the left of the widget */
- + Over /**< It will be drawn overthe widget, overlapping it */
- + };
- +
- + /**
- + * Constructs an handle with the passed widget attached to it.
- + *
- + * @param containment the containment in which the widget is placed
- + * @param widget the widget that will be attached to this handle
- + */
- + AbstractHandle(Containment *containment, QGraphicsWidget *widget);
- +
- + /**
- + * Default destructor.
- + */
- + virtual ~AbstractHandle();
- +
- + /**
- + * Returns a pointer to the widget attached to this handle.
- + */
- + QGraphicsWidget *widget() const;
- +
- + /**
- + * Returns a pointer to the containment the handle is working on.
- + */
- + Containment *containment() const;
- +
- + /**
- + * Returns a list of the control elements of the attached widget.
- + *
- + * @see controlElement
- + */
- + QList<ControlElement *> controlElements() const;
- +
- + /**
- + * Return the control element for the passed type. If there is no control element
- + * for that type it returns 0.
- + *
- + * @param type the type of the control element
- + *
- + * @see controlElements
- + */
- + ControlElement *controlElement(ControlElement::ElementType type) const;
- +
- + /**
- + * Returns the location of the handle relative to the attached widget.
- + *
- + * @see setPosition
- + */
- + virtual HandlePosition position() const;
- +
- + /**
- + * Move our widget to another containment.
- + *
- + * @param containment the containment to move to
- + * @param pos the (scene-relative) position to place it at
- + */
- + virtual void switchContainment(Containment *containment, const QPointF &pos);
- +
- + protected:
- + /**
- + * Returns a control element based on the position passed.
- + * You must reimplement this in a subclass.
- + *
- + * @param pos the position where to look for contro elements
- + */
- + virtual ControlElement *controlElementAt(const QPointF &pos) const = 0;
- +
- + /**
- + * Returns a pointer to a control element that received a mouse press,
- + * 0 otherwise.
- + */
- + ControlElement *pressedElement() const;
- +
- + /**
- + * Sets the location where the handle will be painted.
- + *
- + * @see position
- + * @see HandlePosition
- + */
- + void setPosition(HandlePosition loc);
- +
- + /**
- + * Reimplemented from QGraphicsItem.
- + */
- + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
- +
- + /**
- + * Reimplemented from QGraphicsItem.
- + */
- + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- +
- + /**
- + * Reimplemented from QGraphicsItem.
- + */
- + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- +
- + /**
- + * Reimplemented from QGraphicsItem
- + */
- + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
- +
- + /**
- + * Reimplemented from QGraphicsItem.
- + */
- + virtual bool sceneEvent(QEvent *event);
- +
- + Q_SIGNALS:
- + /**
- + * Emit this when you want the handle do die.
- + */
- + void disappearDone(AbstractHandle *self);
- +
- + private:
- + AbstractHandlePrivate *const d;
- +
- + Q_PRIVATE_SLOT(d, void widgetDestroyed())
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: private/maximizecontrol.h
- ===================================================================
- --- private/maximizecontrol.h (revisione 0)
- +++ private/maximizecontrol.h (revisione 0)
- @@ -0,0 +1,44 @@
- +/*
- + * Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
- + *
- + * This program is free software; you can redistribute it and/or modify
- + * it under the terms of the GNU Library General Public License as
- + * published by the Free Software Foundation; either version 2, 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 Library 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 MAXIMIZECONTROL_H
- +#define MAXIMIZECONTROL_H
- +
- +#include "controlelement.h"
- +
- +namespace Plasma
- +{
- +
- +class MaximizeControl : public ControlElement
- +{
- + Q_OBJECT
- + public:
- + MaximizeControl(QGraphicsWidget *widget);
- + virtual ~MaximizeControl();
- +
- + ControlElement::ElementType elementType() const;
- +
- + protected:
- + void mouseClickEvent(QGraphicsSceneMouseEvent *event);
- +
- +};
- +
- +};
- +
- +#endif // multiple inclusion guard
- Index: containment.h
- ===================================================================
- --- containment.h (revisione 1171409)
- +++ containment.h (copia locale)
- @@ -42,7 +42,7 @@
- {
- class AccessAppletJob;
- -class AppletHandle;
- +class AbstractHandle;
- class DataEngine;
- class Package;
- class Corona;
- @@ -632,7 +632,7 @@
- Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))
- Q_PRIVATE_SLOT(d, void appletAppearAnimationComplete())
- Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
- - Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
- + Q_PRIVATE_SLOT(d, void handleDisappeared(AbstractHandle *handle))
- Q_PRIVATE_SLOT(d, void positionToolBox())
- Q_PRIVATE_SLOT(d, void requestConfiguration())
- Q_PRIVATE_SLOT(d, void updateToolBoxVisibility())
- Index: CMakeLists.txt
- ===================================================================
- --- CMakeLists.txt (revisione 1171409)
- +++ CMakeLists.txt (copia locale)
- @@ -113,7 +113,6 @@
- plasma.cpp
- popupapplet.cpp
- private/animablegraphicswebview.cpp
- - private/applethandle.cpp
- private/associatedapplicationmanager.cpp
- private/datacontainer_p.cpp
- private/dataengineconsumer.cpp
- @@ -142,6 +141,15 @@
- private/kineticscroll.cpp
- private/effects/halopainter.cpp
- private/effects/ripple.cpp
- + private/abstracthandle.cpp
- + private/desktophandle.cpp
- + private/controlelement.cpp
- + private/configurecontrol.cpp
- + private/maximizecontrol.cpp
- + private/movecontrol.cpp
- + private/removecontrol.cpp
- + private/resizecontrol.cpp
- + private/rotatecontrol.cpp
- querymatch.cpp
- remote/accessmanager.cpp
- remote/accessappletjob.cpp
- Index: containment.cpp
- ===================================================================
- --- containment.cpp (revisione 1171409)
- +++ containment.cpp (copia locale)
- @@ -63,10 +63,11 @@
- #include "remote/accessmanager.h"
- #include "private/applet_p.h"
- -#include "private/applethandle_p.h"
- +#include "private/desktophandle.h"
- #include "private/containmentactionspluginsconfig_p.h"
- #include "private/extenderitemmimedata_p.h"
- #include "private/extenderapplet_p.h"
- +#include "private/abstracthandle.h"
- #include "plasma/plasma.h"
- #include "animations/animation.h"
- @@ -751,10 +752,10 @@
- break;
- }
- }
- - AppletHandle *handle = dynamic_cast<AppletHandle*>(item);
- + AbstractHandle *handle = dynamic_cast<AbstractHandle*>(item);
- if (handle) {
- //pretend it was on the applet
- - applet = handle->applet();
- + applet = qobject_cast<Applet*>(handle->widget());
- break;
- }
- item = item->parentItem();
- @@ -1712,33 +1713,17 @@
- //kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability();
- if (immutability() == Mutable && applet->immutability() == Mutable) {
- QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
- - if (d->handles.contains(applet)) {
- - AppletHandle *handle = d->handles.value(applet);
- - if (handle) {
- - handle->setHoverPos(he->pos());
- - }
- - } else {
- + if (!d->handles.contains(applet)) {
- //kDebug() << "generated applet handle";
- - AppletHandle *handle = new AppletHandle(this, applet, he->pos());
- + AbstractHandle *handle = new DesktopHandle(this, applet, he->pos());
- d->handles[applet] = handle;
- - connect(handle, SIGNAL(disappearDone(AppletHandle*)),
- - this, SLOT(handleDisappeared(AppletHandle*)));
- + connect(handle, SIGNAL(disappearDone(AbstractHandle*)),
- + this, SLOT(handleDisappeared(AbstractHandle*)));
- connect(applet, SIGNAL(geometryChanged()),
- handle, SLOT(appletResized()));
- }
- }
- break;
- - case QEvent::GraphicsSceneHoverMove:
- - if (immutability() == Mutable && applet->immutability() == Mutable) {
- - QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
- - if (d->handles.contains(applet)) {
- - AppletHandle *handle = d->handles.value(applet);
- - if (handle) {
- - handle->setHoverPos(he->pos());
- - }
- - }
- - }
- - break;
- default:
- break;
- }
- @@ -2197,11 +2182,10 @@
- emit q->showAddWidgetsInterface(QPointF());
- }
- -void ContainmentPrivate::handleDisappeared(AppletHandle *handle)
- +void ContainmentPrivate::handleDisappeared(AbstractHandle *handle)
- {
- - if (handles.contains(handle->applet())) {
- - handles.remove(handle->applet());
- - handle->detachApplet();
- + if (handles.contains(handle->widget())) {
- + handles.remove(handle->widget());
- QGraphicsScene *scene = q->scene();
- if (scene && handle->scene() == scene) {
- scene->removeItem(handle);
- @@ -2237,10 +2221,10 @@
- //clear handles on lock
- if (!unlocked) {
- - QMap<Applet*, AppletHandle*> h = handles;
- + QMap<QGraphicsWidget*, AbstractHandle*> h = handles;
- handles.clear();
- - foreach (AppletHandle *handle, h) {
- + foreach (AbstractHandle *handle, h) {
- handle->disconnect(q);
- if (q->scene()) {
- @@ -2334,7 +2318,7 @@
- }
- if (handles.contains(applet)) {
- - AppletHandle *handle = handles.value(applet);
- + AbstractHandle *handle = handles.value(applet);
- handles.remove(applet);
- if (q->scene()) {
- q->scene()->removeItem(handle);
- Index: extenders/extender.cpp
- ===================================================================
- --- extenders/extender.cpp (revisione 1171409)
- +++ extenders/extender.cpp (copia locale)
- @@ -439,7 +439,7 @@
- extenderApplet->formFactor() != Plasma::Vertical) {
- kDebug() << "leaving the internal extender container, so hide the applet and it's handle.";
- extenderApplet->hide();
- - AppletHandle *handle = dynamic_cast<AppletHandle*>(extenderApplet->parentItem());
- + AbstractHandle *handle = dynamic_cast<AbstractHandle*>(extenderApplet->parentItem());
- if (handle) {
- handle->hide();
- }
- Index: extenders/extenderitem.cpp
- ===================================================================
- --- extenders/extenderitem.cpp (revisione 1171409)
- +++ extenders/extenderitem.cpp (copia locale)
- @@ -49,7 +49,6 @@
- #include "widgets/iconwidget.h"
- -#include "private/applethandle_p.h"
- #include "private/extender_p.h"
- #include "private/extenderapplet_p.h"
- #include "private/extendergroup_p.h"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement