Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 135.84 KB | None | 0 0
  1. Index: applet.h
  2. ===================================================================
  3. --- applet.h    (revisione 1171409)
  4. +++ applet.h    (copia locale)
  5. @@ -43,6 +43,10 @@
  6.  class KConfigDialog;
  7.  class QGraphicsView;
  8.  class KActionCollection;
  9. +namespace Plasma {
  10. +    class ControlElement;
  11. +};
  12. +Q_DECLARE_METATYPE(QList<Plasma::ControlElement *>)
  13.  
  14.  namespace Plasma
  15.  {
  16. @@ -55,7 +59,6 @@
  17.  class ExtenderItem;
  18.  class Package;
  19.  
  20. -
  21.  /**
  22.   * @class Applet plasma/applet.h <Plasma/Applet>
  23.   *
  24. @@ -89,6 +92,7 @@
  25.      Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
  26.      Q_PROPERTY(uint id READ id)
  27.      Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
  28. +    Q_PROPERTY(QList<Plasma::ControlElement *> controlElements READ controlElements)
  29.  
  30.      public:
  31.          typedef QList<Applet*> List;
  32. @@ -714,6 +718,8 @@
  33.           */
  34.          bool hasValidAssociatedApplication() const;
  35.  
  36. +        QList<ControlElement *> controlElements() const;
  37. +
  38.      Q_SIGNALS:
  39.          /**
  40.           * This signal indicates that an application launch, window
  41. Index: applet.cpp
  42. ===================================================================
  43. --- applet.cpp  (revisione 1171409)
  44. +++ applet.cpp  (copia locale)
  45. @@ -86,7 +86,7 @@
  46.  #include "svg.h"
  47.  #include "framesvg.h"
  48.  #include "popupapplet.h"
  49. -#include "private/applethandle_p.h"
  50. +#include "private/abstracthandle.h"
  51.  #include "private/extenderitem_p.h"
  52.  #include "private/framesvg_p.h"
  53.  #include "theme.h"
  54. @@ -112,8 +112,14 @@
  55.  #include "private/remotedataengine_p.h"
  56.  #include "private/service_p.h"
  57.  #include "ui_publish.h"
  58. +#include "private/controlelement.h"
  59. +#include "private/movecontrol.h"
  60. +#include "private/configurecontrol.h"
  61. +#include "private/maximizecontrol.h"
  62. +#include "private/removecontrol.h"
  63. +#include "private/resizecontrol.h"
  64. +#include "private/rotatecontrol.h"
  65.  
  66. -
  67.  namespace Plasma
  68.  {
  69.  
  70. @@ -124,6 +130,8 @@
  71.      // WARNING: do not access config() OR globalConfig() in this method!
  72.      //          that requires a scene, which is not available at this point
  73.      d->init();
  74. +
  75. +    d->createControlElements();
  76.  }
  77.  
  78.  Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
  79. @@ -133,6 +141,8 @@
  80.      // WARNING: do not access config() OR globalConfig() in this method!
  81.      //          that requires a scene, which is not available at this point
  82.      d->init();
  83. +
  84. +    d->createControlElements();
  85.  }
  86.  
  87.  Applet::Applet(QGraphicsItem *parent,
  88. @@ -157,6 +167,8 @@
  89.      d->args = mutableArgs;
  90.  
  91.      d->init();
  92. +
  93. +    d->createControlElements();
  94.  }
  95.  
  96.  Applet::Applet(QObject *parentObject, const QVariantList &args)
  97. @@ -185,6 +197,8 @@
  98.      //          that requires a scene, which is not available at this point
  99.      d->init();
  100.  
  101. +    d->createControlElements();
  102. +
  103.      // the brain damage seen in the initialization list is due to the
  104.      // inflexibility of KService::createInstance
  105.  }
  106. @@ -195,6 +209,8 @@
  107.  {
  108.      Q_UNUSED(args) // FIXME?
  109.      d->init(packagePath);
  110. +
  111. +    d->createControlElements();
  112.  }
  113.  
  114.  Applet::~Applet()
  115. @@ -374,7 +390,7 @@
  116.      prepareGeometryChange();
  117.  
  118.      foreach (QGraphicsItem *item, childItems()) {
  119. -        if (!dynamic_cast<AppletHandle *>(item)) {
  120. +        if (!dynamic_cast<AbstractHandle *>(item)) {
  121.              delete item;
  122.          }
  123.      }
  124. @@ -1591,6 +1607,12 @@
  125.      }
  126.  
  127.      d->aspectRatioMode = mode;
  128. +
  129. +    foreach (ControlElement *element, d->controlElements) {
  130. +        if (element->elementType() == ControlElement::ResizeElement) {
  131. +            static_cast<ResizeControl *>(element)->setAspectRatioMode(mode);
  132. +        }
  133. +    }
  134.  }
  135.  
  136.  void Applet::registerAsDragHandle(QGraphicsItem *item)
  137. @@ -2105,6 +2127,37 @@
  138.      return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
  139.  }
  140.  
  141. +QList<ControlElement *> Applet::controlElements() const
  142. +{
  143. +    QList<ControlElement *> elements;
  144. +    foreach (ControlElement *e, d->controlElements) {
  145. +        if (!(e->elementType() == ControlElement::MaximizeElement && !hasValidAssociatedApplication())) {
  146. +           elements << e;
  147. +        }
  148. +    }
  149. +
  150. +    return elements;
  151. +}
  152. +
  153. +void AppletPrivate::createControlElements()
  154. +{
  155. +    MoveControl *move = new MoveControl(q);
  156. +    ConfigureControl *configure = new ConfigureControl(q);
  157. +    MaximizeControl *maximize = new MaximizeControl(q);
  158. +    RemoveControl *remove = new RemoveControl(q);
  159. +    ResizeControl *resize = new ResizeControl(q);
  160. +    RotateControl *rotate = new RotateControl(q);
  161. +
  162. +    q->connect(move, SIGNAL(finished(ControlElement::ElementType)), q, SIGNAL(appletTransformedByUser()));
  163. +    q->connect(configure, SIGNAL(finished(ControlElement::ElementType)), q, SLOT(showConfigurationInterface()));
  164. +    q->connect(maximize, SIGNAL(finished(ControlElement::ElementType)), q, SLOT(runAssociatedApplication()));
  165. +    q->connect(remove, SIGNAL(finished(ControlElement::ElementType)), q, SLOT(destroy()));
  166. +    q->connect(rotate, SIGNAL(finished(ControlElement::ElementType)), q, SIGNAL(appletTransformedByUser()));
  167. +    q->connect(resize, SIGNAL(finished(ControlElement::ElementType)), q, SIGNAL(appletTransformedByUser()));
  168. +
  169. +    controlElements << move << configure << maximize << remove << resize << rotate;
  170. +}
  171. +
  172.  void AppletPrivate::filterOffers(QList<KService::Ptr> &offers)
  173.  {
  174.      KConfigGroup constraintGroup(KGlobal::config(), "Constraints");
  175. Index: private/controlelement.h
  176. ===================================================================
  177. --- private/controlelement.h    (revisione 0)
  178. +++ private/controlelement.h    (revisione 0)
  179. @@ -0,0 +1,137 @@
  180. +/*
  181. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  182. + *
  183. + *   This program is free software; you can redistribute it and/or modify
  184. + *   it under the terms of the GNU Library General Public License as
  185. + *   published by the Free Software Foundation; either version 2, or
  186. + *   (at your option) any later version.
  187. + *
  188. + *   This program is distributed in the hope that it will be useful,
  189. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  190. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  191. + *   GNU General Public License for more details
  192. + *
  193. + *   You should have received a copy of the GNU Library General Public
  194. + *   License along with this program; if not, write to the
  195. + *   Free Software Foundation, Inc.,
  196. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  197. + */
  198. +
  199. +#ifndef CONTROLELEMENT_H
  200. +#define CONTROLELEMENT_H
  201. +
  202. +#include <QtCore/QObject>
  203. +#include <QPoint>
  204. +
  205. +class QGraphicsWidget;
  206. +class QGraphicsSceneMouseEvent;
  207. +
  208. +namespace Plasma
  209. +{
  210. +class ControlElementPrivate;
  211. +class AbstractHandle;
  212. +
  213. +/**
  214. + * @class ControlElement plasma/private/controlelement.h
  215. + *
  216. + * @short The base Handle class
  217. + *
  218. + * A Control Element is an object which takes care of managing a single
  219. + * aspect of a widget, e.g resizing it, moving it, etc.
  220. + */
  221. +class ControlElement : public QObject
  222. +{
  223. +    Q_OBJECT
  224. +    public:
  225. +        /**
  226. +         * Describes the type of the control elements.
  227. +         */
  228. +        enum ElementType {
  229. +            MoveElement,        /**< An element which moves the widget */
  230. +            RotateElement,      /**< An element which rotates the widget */
  231. +            ConfigureElement,   /**< An element which calls the configure dialog for the widget */
  232. +            RemoveElement,      /**< An element which removes the widget */
  233. +            ResizeElement,      /**< An element which resizes the widget */
  234. +            MaximizeElement     /**< An element which calls the associated application of the widget */
  235. +        };
  236. +
  237. +        /**
  238. +         * Build a control element.
  239. +         */
  240. +        ControlElement(QGraphicsWidget *widget);
  241. +
  242. +        /**
  243. +         * Destructor.
  244. +         */
  245. +        virtual ~ControlElement();
  246. +
  247. +        /**
  248. +         * Returns a pointer to the widget managed by this.
  249. +         */
  250. +        QGraphicsWidget *widget() const;
  251. +
  252. +        /**
  253. +         * Returns a pointer to the handle which manages this control element.
  254. +         */
  255. +        AbstractHandle *handle() const;
  256. +
  257. +        /**
  258. +         * Returns the type of the control element.
  259. +         * You must reimplement this in a subclass.
  260. +         */
  261. +        virtual ElementType elementType() const = 0;
  262. +
  263. +    protected:
  264. +        /**
  265. +         * Returns true if the point passed is contained by an other
  266. +         * view than the current one.
  267. +         *
  268. +         * @param pos the position to verify
  269. +         */
  270. +        bool leaveCurrentView(const QPoint &pos) const;
  271. +
  272. +        /**
  273. +         * Reimplement this if you want to receive mouse press events.
  274. +         *
  275. +         * @param event the event passed from the handle
  276. +         */
  277. +        virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
  278. +
  279. +        /**
  280. +         * Reimplement this if you want to receive mouse move events.
  281. +         *
  282. +         * @param event the event passed from the handle
  283. +         */
  284. +        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  285. +
  286. +        /**
  287. +         * Reimplement this if you want to receive mouse release events.
  288. +         *
  289. +         * @param event the event passed from the handle
  290. +         */
  291. +        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  292. +
  293. +        /**
  294. +         * Reimplement this if you want to receive mouse click, that is, mouse press
  295. +         * followed by mouse release, events.
  296. +         *
  297. +         * @param event the event passed from the handle
  298. +         */
  299. +        virtual void mouseClickEvent(QGraphicsSceneMouseEvent *event);
  300. +
  301. +    Q_SIGNALS:
  302. +        /**
  303. +         * Emit this when the control element finished its work.
  304. +         */
  305. +        void finished(ControlElement::ElementType);
  306. +
  307. +    private:
  308. +        ControlElementPrivate *const d;
  309. +
  310. +        friend class AbstractHandle;
  311. +
  312. +};
  313. +
  314. +};
  315. +
  316. +#endif // multiple inclusion guard
  317. Index: private/removecontrol.h
  318. ===================================================================
  319. --- private/removecontrol.h (revisione 0)
  320. +++ private/removecontrol.h (revisione 0)
  321. @@ -0,0 +1,47 @@
  322. +/*
  323. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  324. + *
  325. + *   This program is free software; you can redistribute it and/or modify
  326. + *   it under the terms of the GNU Library General Public License as
  327. + *   published by the Free Software Foundation; either version 2, or
  328. + *   (at your option) any later version.
  329. + *
  330. + *   This program is distributed in the hope that it will be useful,
  331. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  332. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  333. + *   GNU General Public License for more details
  334. + *
  335. + *   You should have received a copy of the GNU Library General Public
  336. + *   License along with this program; if not, write to the
  337. + *   Free Software Foundation, Inc.,
  338. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  339. + */
  340. +
  341. +#ifndef REMOVECONTROL_H
  342. +#define REMOVECONTROL_H
  343. +
  344. +#include "controlelement.h"
  345. +
  346. +class QGraphicsSceneMouseEvent;
  347. +
  348. +namespace Plasma
  349. +{
  350. +class AbstractHandle;
  351. +
  352. +class RemoveControl : public ControlElement
  353. +{
  354. +    Q_OBJECT
  355. +    public:
  356. +        RemoveControl(QGraphicsWidget *widget);
  357. +        virtual ~RemoveControl();
  358. +
  359. +        ControlElement::ElementType elementType() const;
  360. +
  361. +    protected:
  362. +        void mouseClickEvent(QGraphicsSceneMouseEvent *event);
  363. +
  364. +};
  365. +
  366. +};
  367. +
  368. +#endif // multiple inclusion guard
  369. Index: private/rotatecontrol.h
  370. ===================================================================
  371. --- private/rotatecontrol.h (revisione 0)
  372. +++ private/rotatecontrol.h (revisione 0)
  373. @@ -0,0 +1,51 @@
  374. +/*
  375. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  376. + *
  377. + *   This program is free software; you can redistribute it and/or modify
  378. + *   it under the terms of the GNU Library General Public License as
  379. + *   published by the Free Software Foundation; either version 2, or
  380. + *   (at your option) any later version.
  381. + *
  382. + *   This program is distributed in the hope that it will be useful,
  383. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  384. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  385. + *   GNU General Public License for more details
  386. + *
  387. + *   You should have received a copy of the GNU Library General Public
  388. + *   License along with this program; if not, write to the
  389. + *   Free Software Foundation, Inc.,
  390. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  391. + */
  392. +
  393. +#ifndef ROTATECONTROL_H
  394. +#define ROTATECONTROL_H
  395. +
  396. +#include "controlelement.h"
  397. +
  398. +class QGraphicsSceneMouseEvent;
  399. +
  400. +namespace Plasma
  401. +{
  402. +
  403. +class RotateControl : public ControlElement
  404. +{
  405. +    Q_OBJECT
  406. +    public:
  407. +        RotateControl(QGraphicsWidget *widget);
  408. +        virtual ~RotateControl();
  409. +
  410. +        ControlElement::ElementType elementType() const;
  411. +
  412. +    protected:
  413. +        void mousePressEvent(QGraphicsSceneMouseEvent *event);
  414. +        void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  415. +        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  416. +
  417. +    private:
  418. +        qreal m_angle;
  419. +        qreal m_rotateAngleOffset;
  420. +};
  421. +
  422. +};
  423. +
  424. +#endif // multiple inclusion guard
  425. Index: private/applet_p.h
  426. ===================================================================
  427. --- private/applet_p.h  (revisione 1171409)
  428. +++ private/applet_p.h  (copia locale)
  429. @@ -47,6 +47,7 @@
  430.  class AppletScript;
  431.  class Wallpaper;
  432.  class BusyWidget;
  433. +class ControlElement;
  434.  
  435.  class AppletConfigDialog : public KConfigDialog
  436.  {
  437. @@ -139,6 +140,7 @@
  438.      void updateShortcuts();
  439.      void publishCheckboxStateChanged(int state);
  440.      void globalShortcutChanged();
  441. +    void createControlElements();
  442.  
  443.      static KActionCollection* defaultActions(QObject *parent);
  444.      static QSet<QString> knownCategories();
  445. @@ -207,6 +209,8 @@
  446.      QBasicTimer busyWidgetTimer;
  447.      QBasicTimer *modificationsTimer;
  448.  
  449. +    QList<ControlElement *> controlElements;
  450. +
  451.      // a great green field of booleans :)
  452.      bool hasConfigurationInterface : 1;
  453.      bool failed : 1;
  454. Index: private/movecontrol.h
  455. ===================================================================
  456. --- private/movecontrol.h   (revisione 0)
  457. +++ private/movecontrol.h   (revisione 0)
  458. @@ -0,0 +1,54 @@
  459. +/*
  460. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  461. + *
  462. + *   This program is free software; you can redistribute it and/or modify
  463. + *   it under the terms of the GNU Library General Public License as
  464. + *   published by the Free Software Foundation; either version 2, or
  465. + *   (at your option) any later version.
  466. + *
  467. + *   This program is distributed in the hope that it will be useful,
  468. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  469. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  470. + *   GNU General Public License for more details
  471. + *
  472. + *   You should have received a copy of the GNU Library General Public
  473. + *   License along with this program; if not, write to the
  474. + *   Free Software Foundation, Inc.,
  475. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  476. + */
  477. +
  478. +#ifndef MOVECONTROL_H
  479. +#define MOVECONTROL_H
  480. +
  481. +#include <QPointF>
  482. +
  483. +#include "controlelement.h"
  484. +
  485. +class QGraphicsSceneMouseEvent;
  486. +
  487. +namespace Plasma
  488. +{
  489. +class AbstractHandle;
  490. +
  491. +class MoveControl : public ControlElement
  492. +{
  493. +    Q_OBJECT
  494. +    public:
  495. +        MoveControl(QGraphicsWidget *widget);
  496. +        virtual ~MoveControl();
  497. +
  498. +        ControlElement::ElementType elementType() const;
  499. +
  500. +    protected:
  501. +        void mousePressEvent(QGraphicsSceneMouseEvent *event);
  502. +        void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  503. +        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  504. +
  505. +    private:
  506. +        QPoint m_mousePos;
  507. +
  508. +};
  509. +
  510. +};
  511. +
  512. +#endif // multiple inclusion guard
  513. Index: private/abstracthandle.cpp
  514. ===================================================================
  515. --- private/abstracthandle.cpp  (revisione 0)
  516. +++ private/abstracthandle.cpp  (revisione 0)
  517. @@ -0,0 +1,253 @@
  518. +/*
  519. + *   Copyright 2007 by Kevin Ottens <ervin@kde.org>
  520. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  521. + *
  522. + *   This program is free software; you can redistribute it and/or modify
  523. + *   it under the terms of the GNU Library General Public License as
  524. + *   published by the Free Software Foundation; either version 2, or
  525. + *   (at your option) any later version.
  526. + *
  527. + *   This program is distributed in the hope that it will be useful,
  528. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  529. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  530. + *   GNU General Public License for more details
  531. + *
  532. + *   You should have received a copy of the GNU Library General Public
  533. + *   License along with this program; if not, write to the
  534. + *   Free Software Foundation, Inc.,
  535. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  536. + */
  537. +
  538. +#include "abstracthandle.h"
  539. +
  540. +#include <QApplication>
  541. +#include <QtGui/QGraphicsWidget>
  542. +#include <QtGui/QGraphicsSceneMouseEvent>
  543. +
  544. +#include <KDebug>
  545. +
  546. +#include "applet.h"
  547. +#include "containment.h"
  548. +#include "view.h"
  549. +#include "controlelement.h"
  550. +#include "controlelement_p.h"
  551. +
  552. +namespace Plasma
  553. +{
  554. +
  555. +class AbstractHandlePrivate
  556. +{
  557. +    public:
  558. +        AbstractHandlePrivate(AbstractHandle *handle)
  559. +            : q(handle),
  560. +              pressedElement(0)
  561. +        {
  562. +        }
  563. +
  564. +        ~AbstractHandlePrivate()
  565. +        {
  566. +        }
  567. +
  568. +        void widgetDestroyed()
  569. +        {
  570. +            elements.clear();
  571. +            pressedElement = 0;
  572. +            widget = 0;
  573. +        }
  574. +
  575. +        AbstractHandle *q;
  576. +        Containment *containment;
  577. +        QGraphicsWidget *widget;
  578. +        QList<ControlElement *> elements;
  579. +        ControlElement *pressedElement;
  580. +        AbstractHandle::HandlePosition position;
  581. +};
  582. +
  583. +AbstractHandle::AbstractHandle(Containment *containment, QGraphicsWidget *widget)
  584. +              : QGraphicsObject(widget),
  585. +                d(new AbstractHandlePrivate(this))
  586. +{
  587. +    d->containment = containment;
  588. +    d->widget = widget;
  589. +    connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed()));
  590. +
  591. +    d->elements = widget->property("controlElements").value<QList<ControlElement *> >();
  592. +    foreach (ControlElement *e, d->elements) {
  593. +        e->d->handle = this;
  594. +    }
  595. +
  596. +    setAcceptsHoverEvents(true);
  597. +    setAcceptTouchEvents(true);
  598. +    setPosition(Over);
  599. +}
  600. +
  601. +AbstractHandle::~AbstractHandle()
  602. +{
  603. +    if (d->widget) {
  604. +        d->widget->disconnect(this);
  605. +        d->widget = 0;
  606. +    }
  607. +
  608. +    foreach (ControlElement *e, d->elements) {
  609. +        e->d->handle = 0;
  610. +    }
  611. +
  612. +    delete d;
  613. +}
  614. +
  615. +QGraphicsWidget *AbstractHandle::widget() const
  616. +{
  617. +    return d->widget;
  618. +}
  619. +
  620. +Containment *AbstractHandle::containment() const
  621. +{
  622. +    return d->containment;
  623. +}
  624. +
  625. +//pos relative to scene
  626. +void AbstractHandle::switchContainment(Containment *containment, const QPointF &pos)
  627. +{
  628. +    d->containment = containment;
  629. +    if (d->widget) {
  630. +        QGraphicsWidget *widget = d->widget;
  631. +        d->widget = 0; //make sure we don't try to act on the widget again
  632. +        setAcceptsHoverEvents(false);
  633. +        emit disappearDone(this);
  634. +        widget->disconnect(this); //make sure the widget doesn't tell us to do anything
  635. +        Applet *a = qobject_cast<Applet *>(widget);
  636. +        if (a) {
  637. +            containment->addApplet(a, containment->mapFromScene(pos));
  638. +        }
  639. +    }
  640. +}
  641. +
  642. +QList<ControlElement *> AbstractHandle::controlElements() const
  643. +{
  644. +    return d->elements;
  645. +}
  646. +
  647. +ControlElement *AbstractHandle::controlElement(ControlElement::ElementType type) const
  648. +{
  649. +    foreach (ControlElement *element, d->elements) {
  650. +        if (element->elementType() == type) {
  651. +            return element;
  652. +        }
  653. +    }
  654. +
  655. +    return 0;
  656. +}
  657. +
  658. +ControlElement *AbstractHandle::pressedElement() const
  659. +{
  660. +    return d->pressedElement;
  661. +}
  662. +
  663. +AbstractHandle::HandlePosition AbstractHandle::position() const
  664. +{
  665. +    return d->position;
  666. +}
  667. +
  668. +void AbstractHandle::setPosition(HandlePosition pos)
  669. +{
  670. +    d->position = pos;
  671. +}
  672. +
  673. +void AbstractHandle::mousePressEvent(QGraphicsSceneMouseEvent *event)
  674. +{
  675. +    d->pressedElement = controlElementAt(event->pos());
  676. +
  677. +    if (d->pressedElement) {
  678. +        d->pressedElement->mousePressEvent(event);
  679. +    }
  680. +
  681. +    update();
  682. +}
  683. +
  684. +void AbstractHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  685. +{
  686. +    d->pressedElement->mouseMoveEvent(event);
  687. +}
  688. +
  689. +void AbstractHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  690. +{
  691. +    ControlElement *element = controlElementAt(event->pos());
  692. +
  693. +    if (element && element == d->pressedElement) {
  694. +        element->mouseClickEvent(event);
  695. +        element->mouseReleaseEvent(event);
  696. +    }
  697. +
  698. +    d->pressedElement = 0;
  699. +
  700. +    update();
  701. +}
  702. +
  703. +void AbstractHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
  704. +{
  705. +    if (!boundingRect().contains(event->pos())) {
  706. +        emit disappearDone(this);
  707. +    }
  708. +}
  709. +
  710. +bool AbstractHandle::sceneEvent(QEvent *event)
  711. +{
  712. +//     switch (event->type()) {
  713. +//     case QEvent::TouchEnd: {
  714. +//         QTransform t = m_applet->transform();
  715. +//         QRectF geom = m_applet->geometry();
  716. +//         QPointF translation(t.m31(), t.m32());
  717. +//         QPointF center = geom.center();
  718. +//         geom.setWidth(geom.width()*qAbs(t.m11()));
  719. +//         geom.setHeight(geom.height()*qAbs(t.m22()));
  720. +//         geom.moveCenter(center);
  721. +//
  722. +//         m_applet->setGeometry(geom);
  723. +//         t.reset();
  724. +//         t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
  725. +//         t.rotateRadians(m_angle);
  726. +//         t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
  727. +//
  728. +//
  729. +//         m_applet->setTransform(t);
  730. +//         return true;
  731. +//     }
  732. +//     case QEvent::TouchBegin:
  733. +//     case QEvent::TouchUpdate:
  734. +//     {
  735. +//         QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
  736. +//         if (touchPoints.count() == 2) {
  737. +//             const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
  738. +//             const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
  739. +//
  740. +//             //rotation
  741. +//             QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos());
  742. +//             QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos());
  743. +//             m_angle = m_angle+(line1.angleTo(line0)*M_PI_2/90);
  744. +//             QTransform t = m_applet->transform();
  745. +//             t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
  746. +//             t.rotate(line1.angleTo(line0));
  747. +//
  748. +//             //scaling
  749. +//             qreal scaleFactor = 1;
  750. +//             if (line0.length() > 0) {
  751. +//                 scaleFactor = line1.length() / line0.length();
  752. +//             }
  753. +//
  754. +//             t.scale(scaleFactor, scaleFactor);
  755. +//             t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
  756. +//             m_applet->setTransform(t);
  757. +//
  758. +//         }
  759. +//         return true;
  760. +//     }
  761. +//     default:
  762. +//         break;
  763. +//     }
  764. +    return QGraphicsObject::sceneEvent(event);
  765. +}
  766. +
  767. +}
  768. +
  769. +#include "abstracthandle.moc"
  770. +
  771. Index: private/configurecontrol.h
  772. ===================================================================
  773. --- private/configurecontrol.h  (revisione 0)
  774. +++ private/configurecontrol.h  (revisione 0)
  775. @@ -0,0 +1,44 @@
  776. +/*
  777. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  778. + *
  779. + *   This program is free software; you can redistribute it and/or modify
  780. + *   it under the terms of the GNU Library General Public License as
  781. + *   published by the Free Software Foundation; either version 2, or
  782. + *   (at your option) any later version.
  783. + *
  784. + *   This program is distributed in the hope that it will be useful,
  785. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  786. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  787. + *   GNU General Public License for more details
  788. + *
  789. + *   You should have received a copy of the GNU Library General Public
  790. + *   License along with this program; if not, write to the
  791. + *   Free Software Foundation, Inc.,
  792. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  793. + */
  794. +
  795. +#ifndef CONFIGURECONTROL_H
  796. +#define CONFIGURECONTROL_H
  797. +
  798. +#include "controlelement.h"
  799. +
  800. +namespace Plasma
  801. +{
  802. +
  803. +class ConfigureControl : public ControlElement
  804. +{
  805. +    Q_OBJECT
  806. +    public:
  807. +        ConfigureControl(QGraphicsWidget *widget);
  808. +        virtual ~ConfigureControl();
  809. +
  810. +        ControlElement::ElementType elementType() const;
  811. +
  812. +    protected:
  813. +        void mouseClickEvent(QGraphicsSceneMouseEvent *event);
  814. +
  815. +};
  816. +
  817. +};
  818. +
  819. +#endif // multiple inclusion guard
  820. Index: private/desktophandle.h
  821. ===================================================================
  822. --- private/desktophandle.h (revisione 0)
  823. +++ private/desktophandle.h (revisione 0)
  824. @@ -0,0 +1,104 @@
  825. +/*
  826. + *   Copyright 2007 by Kevin Ottens <ervin@kde.org>
  827. + *
  828. + *   This program is free software; you can redistribute it and/or modify
  829. + *   it under the terms of the GNU Library General Public License as
  830. + *   published by the Free Software Foundation; either version 2, or
  831. + *   (at your option) any later version.
  832. + *
  833. + *   This program is distributed in the hope that it will be useful,
  834. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  835. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  836. + *   GNU General Public License for more details
  837. + *
  838. + *   You should have received a copy of the GNU Library General Public
  839. + *   License along with this program; if not, write to the
  840. + *   Free Software Foundation, Inc.,
  841. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  842. + */
  843. +
  844. +#ifndef PLASMA_DESKTOPHANDLE_P_H
  845. +#define PLASMA_DESKTOPHANDLE_P_H
  846. +
  847. +#include <QtCore/QObject>
  848. +#include <QTimer>
  849. +#include <QWeakPointer>
  850. +#include <QPropertyAnimation>
  851. +
  852. +#include "abstracthandle.h"
  853. +#include "animator.h"
  854. +#include "svg.h"
  855. +
  856. +class QGraphicsView;
  857. +
  858. +namespace Plasma
  859. +{
  860. +class Applet;
  861. +class Containment;
  862. +class FrameSvg;
  863. +class View;
  864. +
  865. +class DesktopHandle : public AbstractHandle
  866. +{
  867. +    Q_OBJECT
  868. +    Q_PROPERTY(qreal fadeAnimation READ fadeAnimation WRITE setFadeAnimation)
  869. +    public:
  870. +        enum FadeType {
  871. +            FadeIn,
  872. +            FadeOut
  873. +        };
  874. +
  875. +        DesktopHandle(Containment *containment, QGraphicsWidget *widget, const QPointF &hoverPos);
  876. +        virtual ~DesktopHandle();
  877. +
  878. +        QRectF boundingRect() const;
  879. +        QPainterPath shape() const;
  880. +        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
  881. +        void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
  882. +        void setHoverPos(const QPointF &hoverPos);
  883. +
  884. +    protected:
  885. +        ControlElement *controlElementAt(const QPointF &pos) const;
  886. +        void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
  887. +        void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
  888. +        void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
  889. +        bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
  890. +
  891. +    private Q_SLOTS:
  892. +        void setFadeAnimation(qreal progress);
  893. +        qreal fadeAnimation() const;
  894. +        void appletResized();
  895. +        void hoverTimeout();
  896. +        void leaveTimeout();
  897. +        void emitDisappear();
  898. +
  899. +    private:
  900. +        static const int HANDLE_MARGIN = 3;
  901. +
  902. +        void calculateSize();
  903. +        void forceDisappear();
  904. +        int minimumHeight();
  905. +
  906. +        QRectF m_rect;
  907. +        QRectF m_decorationRect;
  908. +        QRectF m_totalRect;
  909. +        int m_iconSize;
  910. +        qreal m_opacity;
  911. +        FadeType m_animType;
  912. +        QWeakPointer<QPropertyAnimation> m_anim;
  913. +        QColor m_gradientColor;
  914. +        QTimer *m_hoverTimer;
  915. +        QTimer *m_leaveTimer;
  916. +        QPixmap *m_backgroundBuffer;
  917. +
  918. +        Svg *m_configureIcons;
  919. +        FrameSvg *m_background;
  920. +
  921. +        QPointF m_entryPos; //where the hover in event occurred
  922. +
  923. +        bool m_pendingFade : 1;
  924. +};
  925. +
  926. +}
  927. +
  928. +#endif // multiple inclusion guard
  929. Index: private/rotatecontrol.cpp
  930. ===================================================================
  931. --- private/rotatecontrol.cpp   (revisione 0)
  932. +++ private/rotatecontrol.cpp   (revisione 0)
  933. @@ -0,0 +1,106 @@
  934. +/*
  935. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  936. + *
  937. + *   This program is free software; you can redistribute it and/or modify
  938. + *   it under the terms of the GNU Library General Public License as
  939. + *   published by the Free Software Foundation; either version 2, or
  940. + *   (at your option) any later version.
  941. + *
  942. + *   This program is distributed in the hope that it will be useful,
  943. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  944. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  945. + *   GNU General Public License for more details
  946. + *
  947. + *   You should have received a copy of the GNU Library General Public
  948. + *   License along with this program; if not, write to the
  949. + *   Free Software Foundation, Inc.,
  950. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  951. + */
  952. +
  953. +#include "rotatecontrol.h"
  954. +
  955. +#include <math.h>
  956. +#include <cmath>
  957. +
  958. +#include <QtGui/QGraphicsSceneMouseEvent>
  959. +#include <QtGui/QGraphicsWidget>
  960. +
  961. +#include "abstracthandle.h"
  962. +
  963. +namespace Plasma
  964. +{
  965. +qreal _k_pointAngle(QPointF point);
  966. +
  967. +RotateControl::RotateControl(QGraphicsWidget *widget)
  968. +             : ControlElement(widget)
  969. +{
  970. +}
  971. +
  972. +RotateControl::~RotateControl()
  973. +{
  974. +}
  975. +
  976. +ControlElement::ElementType RotateControl::elementType() const
  977. +{
  978. +    return ControlElement::RotateElement;
  979. +}
  980. +
  981. +void RotateControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
  982. +{
  983. +    QPointF origWidgetCenter = handle()->mapToScene(widget()->boundingRect()).boundingRect().center();
  984. +    QPointF center = widget()->boundingRect().center();
  985. +    m_angle = _k_pointAngle(widget()->transform().map(center + QPointF(1.0, 0.0)) - center);
  986. +    m_rotateAngleOffset = m_angle - _k_pointAngle(event->scenePos() - origWidgetCenter);
  987. +}
  988. +
  989. +void RotateControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  990. +{
  991. +    static const qreal snapAngle = M_PI_2 /* $i 3.14159 / 2.0 */;
  992. +
  993. +    QPointF cursorPoint = event->scenePos();
  994. +    qreal newAngle;
  995. +    QSizeF size = widget()->size();
  996. +    QPointF center = handle()->mapToScene(widget()->boundingRect()).boundingRect().center();
  997. +
  998. +    QPointF centerRelativePoint = cursorPoint - center;
  999. +    qreal dist = std::sqrt(centerRelativePoint.x() * centerRelativePoint.x() +
  1000. +                           centerRelativePoint.y() * centerRelativePoint.y());
  1001. +    if (dist < 10) {
  1002. +        newAngle = m_angle;
  1003. +    } else {
  1004. +        qreal cursorAngle = _k_pointAngle(centerRelativePoint);
  1005. +        newAngle = m_rotateAngleOffset + cursorAngle;
  1006. +        if (fabs(remainder(newAngle, snapAngle)) < 0.15) {
  1007. +            newAngle = newAngle - remainder(newAngle, snapAngle);
  1008. +        }
  1009. +    }
  1010. +
  1011. +    // apply angle
  1012. +    QTransform at;
  1013. +    at.translate(size.width()/2, size.height()/2);
  1014. +    at.rotateRadians(newAngle);
  1015. +    at.translate(-size.width()/2, -size.height()/2);
  1016. +    widget()->setTransform(at);
  1017. +    m_angle = newAngle;
  1018. +}
  1019. +
  1020. +void RotateControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  1021. +{
  1022. +    emit finished(ControlElement::RotateElement);
  1023. +}
  1024. +
  1025. +qreal _k_pointAngle(QPointF point)
  1026. +{
  1027. +    qreal r = sqrt(point.x() * point.x() + point.y() * point.y());
  1028. +    qreal cosine = point.x() / r;
  1029. +
  1030. +    if (point.y() >= 0) {
  1031. +        return acos(cosine);
  1032. +    } else {
  1033. +        return -acos(cosine);
  1034. +    }
  1035. +}
  1036. +
  1037. +}
  1038. +
  1039. +#include "rotatecontrol.moc"
  1040. Index: private/resizecontrol.cpp
  1041. ===================================================================
  1042. --- private/resizecontrol.cpp   (revisione 0)
  1043. +++ private/resizecontrol.cpp   (revisione 0)
  1044. @@ -0,0 +1,157 @@
  1045. +/*
  1046. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  1047. + *
  1048. + *   This program is free software; you can redistribute it and/or modify
  1049. + *   it under the terms of the GNU Library General Public License as
  1050. + *   published by the Free Software Foundation; either version 2, or
  1051. + *   (at your option) any later version.
  1052. + *
  1053. + *   This program is distributed in the hope that it will be useful,
  1054. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1055. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1056. + *   GNU General Public License for more details
  1057. + *
  1058. + *   You should have received a copy of the GNU Library General Public
  1059. + *   License along with this program; if not, write to the
  1060. + *   Free Software Foundation, Inc.,
  1061. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  1062. + */
  1063. +
  1064. +#include "resizecontrol.h"
  1065. +
  1066. +#include <math.h>
  1067. +
  1068. +#include <QtGui/QGraphicsSceneMouseEvent>
  1069. +#include <QtGui/QGraphicsWidget>
  1070. +
  1071. +#include <KIconLoader>
  1072. +#include <KDebug>
  1073. +
  1074. +#include "abstracthandle.h"
  1075. +
  1076. +namespace Plasma
  1077. +{
  1078. +
  1079. +ResizeControl::ResizeControl(QGraphicsWidget *widget)
  1080. +             : ControlElement(widget),
  1081. +               aspectRatioMode(IgnoreAspectRatio)
  1082. +{
  1083. +}
  1084. +
  1085. +ResizeControl::~ResizeControl()
  1086. +{
  1087. +}
  1088. +
  1089. +ControlElement::ElementType ResizeControl::elementType() const
  1090. +{
  1091. +    return ControlElement::ResizeElement;
  1092. +}
  1093. +
  1094. +void ResizeControl::setAspectRatioMode(AspectRatioMode mode)
  1095. +{
  1096. +    aspectRatioMode = mode;
  1097. +}
  1098. +
  1099. +void ResizeControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
  1100. +{
  1101. +    m_originalGeom = handle()->mapToScene(widget()->boundingRect()).boundingRect();
  1102. +    m_origWidgetCenter = m_originalGeom.center();
  1103. +    m_origWidgetSize = QPointF(widget()->size().width(), widget()->size().height());
  1104. +
  1105. +    AbstractHandle::HandlePosition pos = handle()->position();
  1106. +    if (pos == AbstractHandle::Right) {
  1107. +        m_resizeStaticPoint = widget()->mapToScene(QPointF(0, widget()->size().height()));
  1108. +    } else {
  1109. +        m_resizeStaticPoint = widget()->mapToScene(m_origWidgetSize);
  1110. +    }
  1111. +    m_resizeGrabPoint = event->scenePos();
  1112. +}
  1113. +
  1114. +void ResizeControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  1115. +{
  1116. +    QPointF cursorPoint = event->scenePos();
  1117. +
  1118. +    QPointF newSize;
  1119. +    QPointF newCenter;
  1120. +
  1121. +    // get size limits
  1122. +    QSizeF min = widget()->minimumSize();
  1123. +    QSizeF max = widget()->maximumSize();
  1124. +
  1125. +    if (min.width() < KIconLoader::SizeSmall || min.height() <  KIconLoader::SizeSmall) {
  1126. +        min = widget()->effectiveSizeHint(Qt::MinimumSize);
  1127. +    }
  1128. +
  1129. +    if (max.isEmpty()) {
  1130. +        max = widget()->effectiveSizeHint(Qt::MaximumSize);
  1131. +    }
  1132. +
  1133. +    // If the widget doesn't have a minimum size, calculate based on a
  1134. +    // minimum content area size of 16x16 (KIconLoader::SizeSmall)
  1135. +    if (min.width() < KIconLoader::SizeSmall || min.height() <  KIconLoader::SizeSmall) {
  1136. +        min = widget()->boundingRect().size() - widget()->contentsRect().size();
  1137. +        min = QSizeF(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
  1138. +    }
  1139. +
  1140. +    // un-rotate screen points so we can read differences of coordinates
  1141. +
  1142. +    QTransform t(widget()->sceneTransform());
  1143. +    //take the angle relative to the scene
  1144. +    qreal angle = (t.m12() > 0 ? acos(t.m11()) : -acos(t.m11()));
  1145. +
  1146. +    QPointF rStaticPoint = QTransform().rotateRadians(-angle).map(m_resizeStaticPoint);
  1147. +    QPointF rCursorPoint = QTransform().rotateRadians(-angle).map(cursorPoint);
  1148. +    QPointF rGrabPoint = QTransform().rotateRadians(-angle).map(m_resizeGrabPoint);
  1149. +
  1150. +    AbstractHandle::HandlePosition pos = handle()->position();
  1151. +    if (pos == AbstractHandle::Right) {
  1152. +        newSize = m_origWidgetSize + QPointF(rCursorPoint.x() - rGrabPoint.x(), rGrabPoint.y() - rCursorPoint.y());
  1153. +    } else {
  1154. +        newSize = m_origWidgetSize + QPointF(rGrabPoint.x() - rCursorPoint.x(), rGrabPoint.y() - rCursorPoint.y());
  1155. +    }
  1156. +
  1157. +    // preserving aspect ratio?
  1158. +    if ((aspectRatioMode != Plasma::IgnoreAspectRatio && !(event->modifiers() & Qt::ControlModifier)) ||
  1159. +        (aspectRatioMode == Plasma::IgnoreAspectRatio && (event->modifiers() & Qt::ControlModifier))) {
  1160. +        // project size to keep ratio
  1161. +
  1162. +        QPointF v = m_origWidgetSize;
  1163. +        v /= sqrt(v.x() * v.x() + v.y() * v.y());
  1164. +        qreal a = v.x() * v.x();
  1165. +        qreal b = v.x() * v.y();
  1166. +        qreal d = v.y() * v.y();
  1167. +        newSize = QMatrix(a, b, b, d, 0., 0.).map(newSize);
  1168. +
  1169. +        // limit size, presering ratio
  1170. +        qreal ratio = m_origWidgetSize.y() / m_origWidgetSize.x();
  1171. +        newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
  1172. +        newSize.ry() = newSize.x() * ratio;
  1173. +        newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
  1174. +        newSize.rx() = newSize.y() / ratio;
  1175. +    } else {
  1176. +        // limit size
  1177. +        newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
  1178. +        newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
  1179. +    }
  1180. +
  1181. +    // move center such that the static corner remains in the same place
  1182. +    if (pos == AbstractHandle::Right) {
  1183. +        newCenter = QTransform().rotateRadians(angle).map(QPointF(rStaticPoint.x() + newSize.x()/2,
  1184. +                    rStaticPoint.y() - newSize.y()/2));
  1185. +    } else {
  1186. +        newCenter = QTransform().rotateRadians(angle).map(QPointF(rStaticPoint.x() - newSize.x()/2,
  1187. +                    rStaticPoint.y() - newSize.y()/2));
  1188. +    }
  1189. +
  1190. +    widget()->resize(newSize.x(), newSize.y());
  1191. +    widget()->setPos(widget()->parentItem()->mapFromScene(newCenter - newSize/2));
  1192. +}
  1193. +
  1194. +void ResizeControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  1195. +{
  1196. +    emit finished(ControlElement::ResizeElement);
  1197. +}
  1198. +
  1199. +}
  1200. +
  1201. +#include "resizecontrol.moc"
  1202. Index: private/movecontrol.cpp
  1203. ===================================================================
  1204. --- private/movecontrol.cpp (revisione 0)
  1205. +++ private/movecontrol.cpp (revisione 0)
  1206. @@ -0,0 +1,116 @@
  1207. +/*
  1208. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  1209. + *
  1210. + *   This program is free software; you can redistribute it and/or modify
  1211. + *   it under the terms of the GNU Library General Public License as
  1212. + *   published by the Free Software Foundation; either version 2, or
  1213. + *   (at your option) any later version.
  1214. + *
  1215. + *   This program is distributed in the hope that it will be useful,
  1216. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1217. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1218. + *   GNU General Public License for more details
  1219. + *
  1220. + *   You should have received a copy of the GNU Library General Public
  1221. + *   License along with this program; if not, write to the
  1222. + *   Free Software Foundation, Inc.,
  1223. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  1224. + */
  1225. +
  1226. +#include "movecontrol.h"
  1227. +
  1228. +#include <QtGui/QGraphicsSceneMouseEvent>
  1229. +#include <QtGui/QGraphicsWidget>
  1230. +
  1231. +#include <Plasma/View>
  1232. +#include <Plasma/Containment>
  1233. +#include <Plasma/Corona>
  1234. +
  1235. +#include "abstracthandle.h"
  1236. +
  1237. +namespace Plasma
  1238. +{
  1239. +
  1240. +MoveControl::MoveControl(QGraphicsWidget *widget)
  1241. +              : ControlElement(widget)
  1242. +{
  1243. +}
  1244. +
  1245. +MoveControl::~MoveControl()
  1246. +{
  1247. +}
  1248. +
  1249. +ControlElement::ElementType MoveControl::elementType() const
  1250. +{
  1251. +    return ControlElement::MoveElement;
  1252. +}
  1253. +
  1254. +void MoveControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
  1255. +{
  1256. +    QGraphicsView *view = handle()->containment()->view();
  1257. +    if (view) {
  1258. +        QPoint localpos = view->mapFromScene(widget()->scenePos());
  1259. +        m_mousePos = event->screenPos() - view->mapToGlobal(localpos);
  1260. +    }
  1261. +}
  1262. +
  1263. +void MoveControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  1264. +{
  1265. +    if (leaveCurrentView(event->screenPos())) {
  1266. +        Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
  1267. +        if (v && v != handle()->containment()->view()) {
  1268. +            Containment *c = v->containment();
  1269. +            if (c) {
  1270. +                QPoint pos = v->mapFromGlobal(event->screenPos());
  1271. +                //we actually have been dropped on another containment, so
  1272. +                //move there: we have a screenpos, we need a scenepos
  1273. +                //FIXME how reliable is this transform?
  1274. +                handle()->switchContainment(c, v->mapToScene(pos));
  1275. +            }
  1276. +        }
  1277. +    }
  1278. +
  1279. +    QPointF curPos = event->pos();
  1280. +    QPointF lastPos = event->lastPos();
  1281. +
  1282. +    QTransform transform = widget()->transform();
  1283. +    //we need to discard translation from the transform
  1284. +    QTransform t(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0);
  1285. +    QPointF delta = t.map(curPos - lastPos);
  1286. +    widget()->moveBy(delta.x(), delta.y());
  1287. +}
  1288. +
  1289. +void MoveControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  1290. +{
  1291. +    // test for containment change
  1292. +    //kDebug() << "testing for containment change, sceneBoundingRect = "
  1293. +    //         << containment()->sceneBoundingRect();
  1294. +    if (!handle()->containment()->sceneBoundingRect().contains(widget()->scenePos())) {
  1295. +        // see which containment it belongs to
  1296. +        Corona *corona = qobject_cast<Corona *>(handle()->scene());
  1297. +        if (corona) {
  1298. +            foreach (Containment *containment, corona->containments()) {
  1299. +                QPointF pos;
  1300. +                QGraphicsView *v = containment->view();
  1301. +                if (v) {
  1302. +                    pos = v->mapToScene(v->mapFromGlobal(event->screenPos() - m_mousePos));
  1303. +
  1304. +                    if (containment->sceneBoundingRect().contains(pos)) {
  1305. +                        //kDebug() << "new containment = " << containments[i];
  1306. +                        //kDebug() << "rect = " << containments[i]->sceneBoundingRect();
  1307. +                        // add the widget to the new containment and take it from the old one
  1308. +                        //kDebug() << "moving to other containment with position" << pos;;
  1309. +                        handle()->switchContainment(containment, pos);
  1310. +                        break;
  1311. +                    }
  1312. +                }
  1313. +            }
  1314. +        }
  1315. +    }
  1316. +
  1317. +    emit finished(ControlElement::MoveElement);
  1318. +}
  1319. +
  1320. +}
  1321. +
  1322. +#include "movecontrol.moc"
  1323. Index: private/controlelement_p.h
  1324. ===================================================================
  1325. --- private/controlelement_p.h  (revisione 0)
  1326. +++ private/controlelement_p.h  (revisione 0)
  1327. @@ -0,0 +1,43 @@
  1328. +/*
  1329. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  1330. + *
  1331. + *   This program is free software; you can redistribute it and/or modify
  1332. + *   it under the terms of the GNU Library General Public License as
  1333. + *   published by the Free Software Foundation; either version 2, or
  1334. + *   (at your option) any later version.
  1335. + *
  1336. + *   This program is distributed in the hope that it will be useful,
  1337. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1338. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1339. + *   GNU General Public License for more details
  1340. + *
  1341. + *   You should have received a copy of the GNU Library General Public
  1342. + *   License along with this program; if not, write to the
  1343. + *   Free Software Foundation, Inc.,
  1344. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  1345. + */
  1346. +
  1347. +#ifndef CONTROLELEMENTPRIVATE_H
  1348. +#define CONTROLELEMENTPRIVATE_H
  1349. +
  1350. +class QGraphicsWidget;
  1351. +
  1352. +namespace Plasma
  1353. +{
  1354. +class AbstractHandle;
  1355. +class ControlElement;
  1356. +
  1357. +class ControlElementPrivate
  1358. +{
  1359. +    public:
  1360. +        ControlElementPrivate(ControlElement *element);
  1361. +        ~ControlElementPrivate();
  1362. +
  1363. +        ControlElement *q;
  1364. +        QGraphicsWidget *widget;
  1365. +        AbstractHandle *handle;
  1366. +};
  1367. +
  1368. +};
  1369. +
  1370. +#endif
  1371. Index: private/desktophandle.cpp
  1372. ===================================================================
  1373. --- private/desktophandle.cpp   (revisione 0)
  1374. +++ private/desktophandle.cpp   (revisione 0)
  1375. @@ -0,0 +1,671 @@
  1376. +/*
  1377. + *   Copyright 2007 by Kevin Ottens <ervin@kde.org>
  1378. + *
  1379. + *   This program is free software; you can redistribute it and/or modify
  1380. + *   it under the terms of the GNU Library General Public License as
  1381. + *   published by the Free Software Foundation; either version 2, or
  1382. + *   (at your option) any later version.
  1383. + *
  1384. + *   This program is distributed in the hope that it will be useful,
  1385. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  1386. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1387. + *   GNU General Public License for more details
  1388. + *
  1389. + *   You should have received a copy of the GNU Library General Public
  1390. + *   License along with this program; if not, write to the
  1391. + *   Free Software Foundation, Inc.,
  1392. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  1393. + */
  1394. +
  1395. +#include "private/desktophandle.h"
  1396. +
  1397. +#include <QApplication>
  1398. +#include <QBitmap>
  1399. +#include <QtGui/QGraphicsSceneMouseEvent>
  1400. +#include <QtGui/QLinearGradient>
  1401. +#include <QtGui/QPainter>
  1402. +#include <QtGui/QApplication>
  1403. +#include <QtGui/QMenu>
  1404. +#include <QTouchEvent>
  1405. +#include <QMatrix>
  1406. +#include <QTransform>
  1407. +#include <QWeakPointer>
  1408. +#include <QPropertyAnimation>
  1409. +
  1410. +#include <kcolorscheme.h>
  1411. +#include <kglobalsettings.h>
  1412. +#include <kicon.h>
  1413. +#include <kiconloader.h>
  1414. +#include <kwindowsystem.h>
  1415. +
  1416. +#include <cmath>
  1417. +#include <math.h>
  1418. +
  1419. +#include "applet.h"
  1420. +#include "applet_p.h"
  1421. +#include "containment.h"
  1422. +#include "corona.h"
  1423. +#include "paintutils.h"
  1424. +#include "theme.h"
  1425. +#include "view.h"
  1426. +#include "framesvg.h"
  1427. +
  1428. +namespace Plasma
  1429. +{
  1430. +
  1431. +DesktopHandle::DesktopHandle(Containment *parent, QGraphicsWidget *widget, const QPointF &hoverPos)
  1432. +    : AbstractHandle(parent, widget),
  1433. +      m_iconSize(KIconLoader::SizeSmall),
  1434. +      m_opacity(0.0),
  1435. +      m_animType(FadeIn),
  1436. +      m_backgroundBuffer(0),
  1437. +      m_pendingFade(false)
  1438. +{
  1439. +    setHoverPos(hoverPos);
  1440. +
  1441. +    setFlags(flags() | QGraphicsItem::ItemStacksBehindParent);
  1442. +    KColorScheme colorScheme(QPalette::Active, KColorScheme::View,
  1443. +                             Theme::defaultTheme()->colorScheme());
  1444. +    setAcceptTouchEvents(true);
  1445. +    m_gradientColor = colorScheme.background(KColorScheme::NormalBackground).color();
  1446. +
  1447. +    QPointF center = QRectF(QPointF(), widget->size()).center();
  1448. +
  1449. +    m_hoverTimer = new QTimer(this);
  1450. +    m_hoverTimer->setSingleShot(true);
  1451. +    m_hoverTimer->setInterval(333);
  1452. +
  1453. +    m_leaveTimer = new QTimer(this);
  1454. +    m_leaveTimer->setSingleShot(true);
  1455. +    m_leaveTimer->setInterval(500);
  1456. +
  1457. +    connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
  1458. +    connect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
  1459. +
  1460. +    setAcceptsHoverEvents(true);
  1461. +    m_hoverTimer->start();
  1462. +
  1463. +    //icons
  1464. +    m_configureIcons = new Svg(this);
  1465. +    m_configureIcons->setImagePath("widgets/configuration-icons");
  1466. +    m_configureIcons->setContainsMultipleImages(true);
  1467. +
  1468. +    m_background = new FrameSvg(this);
  1469. +    m_background->setImagePath("widgets/background");
  1470. +    widget->installSceneEventFilter(this);
  1471. +}
  1472. +
  1473. +DesktopHandle::~DesktopHandle()
  1474. +{
  1475. +    delete m_backgroundBuffer;
  1476. +}
  1477. +
  1478. +QRectF Plasma::DesktopHandle::boundingRect() const
  1479. +{
  1480. +    return m_totalRect;
  1481. +}
  1482. +
  1483. +QPainterPath DesktopHandle::shape() const
  1484. +{
  1485. +    //when the containment changes the applet is reset to 0
  1486. +    if (widget()) {
  1487. +        QPainterPath path = PaintUtils::roundedRectangle(m_decorationRect, 10);
  1488. +        return path.united(widget()->shape());
  1489. +    } else {
  1490. +        return QGraphicsItem::shape();
  1491. +    }
  1492. +}
  1493. +
  1494. +QPainterPath handleRect(const QRectF &rect, int radius, bool onRight)
  1495. +{
  1496. +    QPainterPath path;
  1497. +    if (onRight) {
  1498. +        // make the left side straight
  1499. +        path.moveTo(rect.left(), rect.top());              // Top left
  1500. +        path.lineTo(rect.right() - radius, rect.top());    // Top side
  1501. +        path.quadTo(rect.right(), rect.top(),
  1502. +                    rect.right(), rect.top() + radius);    // Top right corner
  1503. +        path.lineTo(rect.right(), rect.bottom() - radius); // Right side
  1504. +        path.quadTo(rect.right(), rect.bottom(),
  1505. +                    rect.right() - radius, rect.bottom()); // Bottom right corner
  1506. +        path.lineTo(rect.left(), rect.bottom());           // Bottom side
  1507. +    } else {
  1508. +        // make the right side straight
  1509. +        path.moveTo(QPointF(rect.left(), rect.top() + radius));
  1510. +        path.quadTo(rect.left(), rect.top(),
  1511. +                    rect.left() + radius, rect.top());     // Top left corner
  1512. +        path.lineTo(rect.right(), rect.top());             // Top side
  1513. +        path.lineTo(rect.right(), rect.bottom());          // Right side
  1514. +        path.lineTo(rect.left() + radius, rect.bottom());  // Bottom side
  1515. +        path.quadTo(rect.left(), rect.bottom(),
  1516. +                    rect.left(), rect.bottom() - radius);  // Bottom left corner
  1517. +    }
  1518. +
  1519. +    path.closeSubpath();
  1520. +    return path;
  1521. +}
  1522. +
  1523. +void DesktopHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  1524. +{
  1525. +    Q_UNUSED(option);
  1526. +    Q_UNUSED(widget);
  1527. +
  1528. +    //kDebug() << m_opacity << m_anim << FadeOut;
  1529. +    if (qFuzzyCompare(m_opacity + 1.0, 1.0)) {
  1530. +        if (m_animType == FadeOut) {
  1531. +            //kDebug() << "WOOOOOOOOO";
  1532. +            QTimer::singleShot(0, this, SLOT(emitDisappear()));
  1533. +        }
  1534. +        return;
  1535. +    }
  1536. +
  1537. +    qreal translation;
  1538. +
  1539. +    AbstractHandle::HandlePosition pos = position();
  1540. +    if (pos == AbstractHandle::Right) {
  1541. +        //kDebug() << "translating by" << m_opacity
  1542. +        //         << (-(1 - m_opacity) * m_rect.width()) << m_rect.width();
  1543. +        translation = -(1 - m_opacity) * m_rect.width();
  1544. +    } else {
  1545. +        translation = (1 - m_opacity) * m_rect.width();
  1546. +    }
  1547. +
  1548. +    painter->translate(translation, 0);
  1549. +
  1550. +    painter->setPen(Qt::NoPen);
  1551. +    painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
  1552. +
  1553. +    int iconMargin = m_iconSize / 2;
  1554. +
  1555. +    const QSize pixmapSize(int(m_decorationRect.width()),
  1556. +                           int(m_decorationRect.height()) + m_iconSize * 5 + 1);
  1557. +    const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
  1558. +
  1559. +    bool isRunning = false;
  1560. +    if (m_anim.data()) {
  1561. +        isRunning = m_anim.data()->state() == QAbstractAnimation::Running ? \
  1562. +                    true : false;
  1563. +    }
  1564. +
  1565. +    //regenerate our buffer?
  1566. +    if (isRunning || !m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
  1567. +        QColor transparencyColor = Qt::black;
  1568. +        transparencyColor.setAlphaF(qMin(m_opacity, qreal(0.99)));
  1569. +
  1570. +        QLinearGradient g(QPoint(0, 0), QPoint(m_decorationRect.width(), 0));
  1571. +        //fading out panel
  1572. +        if (m_rect.height() > qreal(minimumHeight()) * 1.25) {
  1573. +            AbstractHandle::HandlePosition pos = position();
  1574. +            if (pos == AbstractHandle::Right) {
  1575. +                qreal opaquePoint =
  1576. +                    (m_background->marginSize(LeftMargin) - translation) / m_decorationRect.width();
  1577. +                //kDebug() << "opaquePoint" << opaquePoint
  1578. +                //         << m_background->marginSize(LeftMargin) << m_decorationRect.width();
  1579. +                g.setColorAt(0.0, Qt::transparent);
  1580. +                g.setColorAt(qMax(0.0, opaquePoint - 0.05), Qt::transparent);
  1581. +                g.setColorAt(opaquePoint, transparencyColor);
  1582. +                g.setColorAt(1.0, transparencyColor);
  1583. +            } else {
  1584. +                qreal opaquePoint =
  1585. +                    1 - ((m_background->marginSize(RightMargin) + translation) / m_decorationRect.width());
  1586. +                g.setColorAt(1.0, Qt::transparent);
  1587. +                g.setColorAt(opaquePoint + 0.05, Qt::transparent);
  1588. +                g.setColorAt(qMax(qreal(0), opaquePoint), transparencyColor);
  1589. +                g.setColorAt(0.0, transparencyColor);
  1590. +            }
  1591. +        //complete panel
  1592. +        } else {
  1593. +            g.setColorAt(0.0, transparencyColor);
  1594. +        }
  1595. +
  1596. +        m_background->resizeFrame(m_decorationRect.size());
  1597. +
  1598. +        if (!m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
  1599. +            delete m_backgroundBuffer;
  1600. +            m_backgroundBuffer = new QPixmap(pixmapSize);
  1601. +        }
  1602. +        m_backgroundBuffer->fill(Qt::transparent);
  1603. +        QPainter buffPainter(m_backgroundBuffer);
  1604. +
  1605. +        m_background->paintFrame(&buffPainter);
  1606. +
  1607. +        //+1 because otherwise due to rounding errors when rotated could appear one pixel
  1608. +        //of the icon at the border of the applet
  1609. +        //QRectF iconRect(QPointF(pixmapSize.width() - m_iconSize + 1, m_iconSize), iconSize);
  1610. +        QRectF iconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
  1611. +        AbstractHandle::HandlePosition pos = position();
  1612. +        if (pos == AbstractHandle::Right) {
  1613. +            iconRect.moveLeft(
  1614. +                pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
  1615. +            if (controlElement(ControlElement::ResizeElement)) {
  1616. +                m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tr2bl");
  1617. +            }
  1618. +        } else {
  1619. +            iconRect.moveLeft(m_background->marginSize(RightMargin));
  1620. +            if (controlElement(ControlElement::ResizeElement)) {
  1621. +                m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tl2br");
  1622. +            }
  1623. +        }
  1624. +
  1625. +        iconRect.translate(0, m_iconSize);
  1626. +        m_configureIcons->paint(&buffPainter, iconRect, "rotate");
  1627. +
  1628. +        if (controlElement(ControlElement::ConfigureElement)) {
  1629. +            iconRect.translate(0, m_iconSize);
  1630. +            m_configureIcons->paint(&buffPainter, iconRect, "configure");
  1631. +        }
  1632. +
  1633. +        if (controlElement(ControlElement::MaximizeElement)) {
  1634. +            iconRect.translate(0, m_iconSize);
  1635. +            m_configureIcons->paint(&buffPainter, iconRect, "maximize");
  1636. +        }
  1637. +
  1638. +        iconRect.translate(0, m_iconSize);
  1639. +        m_configureIcons->paint(&buffPainter, iconRect, "close");
  1640. +
  1641. +        buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
  1642. +        //blend the background
  1643. +        buffPainter.fillRect(m_backgroundBuffer->rect(), g);
  1644. +        //blend the icons
  1645. +        //buffPainter.fillRect(QRect(QPoint((int)m_decorationRect.width(), 0), QSize(m_iconSize + 1,
  1646. +        //                                  (int)m_decorationRect.height())), transparencyColor);
  1647. +    }
  1648. +
  1649. +    painter->drawPixmap(m_decorationRect.toRect(), *m_backgroundBuffer,
  1650. +                        QRect(QPoint(0, 0), m_decorationRect.size().toSize()));
  1651. +
  1652. +    //XXX this code is duplicated in the next function
  1653. +    QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
  1654. +    QPointF step = QPointF(0, m_iconSize + iconMargin);
  1655. +    QPointF separator = step + QPointF(0, iconMargin);
  1656. +    //end duplicate code
  1657. +
  1658. +    QPointF shiftC;
  1659. +    QPointF shiftD;
  1660. +    QPointF shiftR;
  1661. +    QPointF shiftM;
  1662. +    QPointF shiftMx;
  1663. +
  1664. +    ControlElement *e = pressedElement();
  1665. +    if (e) {
  1666. +        switch(e->elementType())
  1667. +        {
  1668. +        case ControlElement::ConfigureElement:
  1669. +            shiftC = QPointF(2, 2);
  1670. +            break;
  1671. +        case ControlElement::RemoveElement:
  1672. +            shiftD = QPointF(2, 2);
  1673. +            break;
  1674. +        case ControlElement::RotateElement:
  1675. +            shiftR = QPointF(2, 2);
  1676. +            break;
  1677. +        case ControlElement::ResizeElement:
  1678. +            shiftM = QPointF(2, 2);
  1679. +            break;
  1680. +        case ControlElement::MaximizeElement:
  1681. +            shiftMx = QPointF(2, 2);
  1682. +            break;
  1683. +        default:
  1684. +            break;
  1685. +        }
  1686. +    }
  1687. +
  1688. +    QRectF sourceIconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
  1689. +    if (pos == AbstractHandle::Right) {
  1690. +        sourceIconRect.moveLeft(
  1691. +            pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
  1692. +    } else {
  1693. +        sourceIconRect.moveLeft(m_background->marginSize(RightMargin));
  1694. +    }
  1695. +
  1696. +    if (controlElement(ControlElement::ResizeElement)) {
  1697. +        //resize
  1698. +        painter->drawPixmap(
  1699. +            QRectF(basePoint + shiftM, iconSize), *m_backgroundBuffer, sourceIconRect);
  1700. +        basePoint += step;
  1701. +    }
  1702. +
  1703. +    //rotate
  1704. +    sourceIconRect.translate(0, m_iconSize);
  1705. +    painter->drawPixmap(QRectF(basePoint + shiftR, iconSize), *m_backgroundBuffer, sourceIconRect);
  1706. +
  1707. +    //configure
  1708. +    if (controlElement(ControlElement::ConfigureElement)) {
  1709. +        basePoint += step;
  1710. +        sourceIconRect.translate(0, m_iconSize);
  1711. +        painter->drawPixmap(
  1712. +            QRectF(basePoint + shiftC, iconSize), *m_backgroundBuffer, sourceIconRect);
  1713. +    }
  1714. +
  1715. +    //maximize
  1716. +    if (controlElement(ControlElement::MaximizeElement)) {
  1717. +        basePoint += step;
  1718. +        sourceIconRect.translate(0, m_iconSize);
  1719. +        painter->drawPixmap(
  1720. +            QRectF(basePoint + shiftMx, iconSize), *m_backgroundBuffer, sourceIconRect);
  1721. +    }
  1722. +
  1723. +    //close
  1724. +    basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step;
  1725. +    sourceIconRect.translate(0, m_iconSize);
  1726. +    painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect);
  1727. +}
  1728. +
  1729. +void DesktopHandle::emitDisappear()
  1730. +{
  1731. +    emit disappearDone(this);
  1732. +}
  1733. +
  1734. +ControlElement *DesktopHandle::controlElementAt(const QPointF &point) const
  1735. +{
  1736. +    int iconMargin = m_iconSize / 2;
  1737. +    //XXX this code is duplicated in the prev. function
  1738. +    QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
  1739. +    QPointF step = QPointF(0, m_iconSize + iconMargin);
  1740. +    QPointF separator = step + QPointF(0, iconMargin);
  1741. +   //end duplicate code
  1742. +
  1743. +    QRectF activeArea = QRectF(basePoint, QSizeF(m_iconSize, m_iconSize));
  1744. +
  1745. +    ControlElement *element = controlElement(ControlElement::ResizeElement);
  1746. +    if (element) {
  1747. +        if (activeArea.contains(point)) {
  1748. +            return element;
  1749. +        }
  1750. +        activeArea.translate(step);
  1751. +    }
  1752. +
  1753. +    if (activeArea.contains(point)) {
  1754. +        return controlElement(ControlElement::RotateElement);
  1755. +    }
  1756. +
  1757. +    element = controlElement(ControlElement::ConfigureElement);
  1758. +    if (element) {
  1759. +        activeArea.translate(step);
  1760. +        if (activeArea.contains(point)) {
  1761. +            return element;
  1762. +        }
  1763. +    }
  1764. +
  1765. +    element = controlElement(ControlElement::MaximizeElement);
  1766. +    if (element) {
  1767. +        activeArea.translate(step);
  1768. +        if (activeArea.contains(point)) {
  1769. +            return element;
  1770. +        }
  1771. +    }
  1772. +
  1773. +    activeArea.moveTop(m_rect.bottom() - activeArea.height() - iconMargin);
  1774. +    if (activeArea.contains(point)) {
  1775. +        return controlElement(ControlElement::RemoveElement);
  1776. +    }
  1777. +
  1778. +    return controlElement(ControlElement::MoveElement);
  1779. +}
  1780. +
  1781. +void DesktopHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
  1782. +{
  1783. +    Q_UNUSED(event);
  1784. +    //kDebug() << "hover enter";
  1785. +
  1786. +    //if a disappear was scheduled stop the timer
  1787. +    if (m_leaveTimer->isActive()) {
  1788. +        m_leaveTimer->stop();
  1789. +    }
  1790. +    // if we're already fading out, fade back in
  1791. +    else if (!m_anim.data() && m_animType == FadeOut) {
  1792. +        startFading(FadeIn, m_entryPos, true);
  1793. +    }
  1794. +}
  1795. +
  1796. +void DesktopHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
  1797. +{
  1798. +    hoverEnterEvent(event);
  1799. +}
  1800. +
  1801. +void DesktopHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
  1802. +{
  1803. +    Q_UNUSED(event);
  1804. +
  1805. +    foreach (QWidget *widget, QApplication::topLevelWidgets()) {
  1806. +      QMenu *menu = qobject_cast<QMenu*>(widget);
  1807. +      if (menu && menu->isVisible()) {
  1808. +          connect(menu, SIGNAL(aboutToHide()), this, SLOT(leaveTimeout()));
  1809. +          return;
  1810. +      }
  1811. +    }
  1812. +
  1813. +
  1814. +    // if we haven't even showed up yet, remove the handle
  1815. +    if (m_hoverTimer->isActive()) {
  1816. +        m_hoverTimer->stop();
  1817. +        QTimer::singleShot(0, this, SLOT(emitDisappear()));
  1818. +    } else if (pressedElement()) {
  1819. +        m_pendingFade = true;
  1820. +    } else {
  1821. +        //wait a moment to hide the handle in order to recheck the mouse position
  1822. +        m_leaveTimer->start();
  1823. +    }
  1824. +}
  1825. +
  1826. +bool DesktopHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
  1827. +{
  1828. +    if (watched == widget() && event->type() == QEvent::GraphicsSceneHoverLeave) {
  1829. +        hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent*>(event));
  1830. +    }
  1831. +
  1832. +    return false;
  1833. +}
  1834. +
  1835. +void DesktopHandle::setFadeAnimation(qreal progress)
  1836. +{
  1837. +    m_opacity = progress;
  1838. +    //kDebug() << "progress" << progress << "m_opacity" << m_opacity << m_anim << "(" << FadeIn << ")";
  1839. +    if (qFuzzyCompare(progress, qreal(1.0))) {
  1840. +        delete m_backgroundBuffer;
  1841. +        m_backgroundBuffer = 0;
  1842. +    }
  1843. +
  1844. +    update();
  1845. +}
  1846. +
  1847. +qreal DesktopHandle::fadeAnimation() const
  1848. +{
  1849. +    return m_opacity;
  1850. +}
  1851. +
  1852. +void DesktopHandle::hoverTimeout()
  1853. +{
  1854. +    startFading(FadeIn, m_entryPos);
  1855. +}
  1856. +
  1857. +void DesktopHandle::leaveTimeout()
  1858. +{
  1859. +    if (!isUnderMouse()) {
  1860. +        startFading(FadeOut, m_entryPos);
  1861. +    }
  1862. +}
  1863. +
  1864. +void DesktopHandle::appletResized()
  1865. +{
  1866. +    prepareGeometryChange();
  1867. +    calculateSize();
  1868. +    update();
  1869. +}
  1870. +
  1871. +void DesktopHandle::setHoverPos(const QPointF &hoverPos)
  1872. +{
  1873. +    m_entryPos = hoverPos;
  1874. +}
  1875. +
  1876. +void DesktopHandle::startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide)
  1877. +{
  1878. +    QPropertyAnimation *propAnim = m_anim.data();
  1879. +
  1880. +    if (anim == FadeIn) {
  1881. +        if (propAnim) {
  1882. +            propAnim->stop();
  1883. +        } else {
  1884. +            propAnim = new QPropertyAnimation(this, "fadeAnimation", this);
  1885. +            m_anim = propAnim;
  1886. +        }
  1887. +    }
  1888. +
  1889. +    m_entryPos = hoverPos;
  1890. +    qreal time = 100;
  1891. +
  1892. +    if (!widget()) {
  1893. +        m_animType = FadeOut;
  1894. +        setFadeAnimation(1.0);
  1895. +        return;
  1896. +    }
  1897. +
  1898. +    if (anim == FadeIn) {
  1899. +        //kDebug() << m_entryPos.x() << m_applet->pos().x();
  1900. +        prepareGeometryChange();
  1901. +        AbstractHandle::HandlePosition pos = position();
  1902. +        bool wasOnRight = (pos == AbstractHandle::Right);
  1903. +        if (!preserveSide) {
  1904. +            bool buttonsOnRight = m_entryPos.x() > (widget()->size().width() / 2);
  1905. +            if (buttonsOnRight) {
  1906. +                setPosition(AbstractHandle::Right);
  1907. +            } else {
  1908. +                setPosition(AbstractHandle::Left);
  1909. +            }
  1910. +        }
  1911. +        calculateSize();
  1912. +        QPolygonF region = widget()->mapToParent(m_rect).intersected(widget()->parentWidget()->boundingRect());
  1913. +        //kDebug() << region << m_rect << mapToParent(m_rect) << containmnet->boundingRect();
  1914. +        if (region != widget()->mapToParent(m_rect)) {
  1915. +            // switch sides
  1916. +            //kDebug() << "switch sides";
  1917. +            if (pos == AbstractHandle::Right) {
  1918. +                setPosition(AbstractHandle::Left);
  1919. +            } else {
  1920. +                setPosition(AbstractHandle::Right);
  1921. +            }
  1922. +            calculateSize();
  1923. +            QPolygonF region2 = widget()->mapToParent(m_rect).intersected(widget()->parentWidget()->boundingRect());
  1924. +            if (region2 != mapToParent(m_rect)) {
  1925. +                // ok, both sides failed to be perfect... which one is more perfect?
  1926. +                QRectF f1 = region.boundingRect();
  1927. +                QRectF f2 = region2.boundingRect();
  1928. +                //kDebug() << "still not a perfect world"
  1929. +                //         << f2.width() << f2.height() << f1.width() << f1.height();
  1930. +                if ((f2.width() * f2.height()) < (f1.width() * f1.height())) {
  1931. +                    //kDebug() << "we did better the first time";
  1932. +                    if (pos == AbstractHandle::Right) {
  1933. +                        setPosition(AbstractHandle::Left);
  1934. +                    } else {
  1935. +                        setPosition(AbstractHandle::Right);
  1936. +                    }
  1937. +                    calculateSize();
  1938. +                }
  1939. +            }
  1940. +        }
  1941. +
  1942. +        pos = position();
  1943. +        if (wasOnRight != (pos == AbstractHandle::Right) &&
  1944. +            m_animType == FadeIn &&
  1945. +            anim == FadeIn &&
  1946. +            m_opacity <= 1) {
  1947. +            m_opacity = 0.0;
  1948. +        }
  1949. +
  1950. +        time *= 1.0 - m_opacity;
  1951. +    } else {
  1952. +        time *= m_opacity;
  1953. +    }
  1954. +
  1955. +    if (propAnim) {
  1956. +        propAnim->setStartValue(0);
  1957. +        propAnim->setEndValue(1);
  1958. +        propAnim->setDuration(time);
  1959. +    }
  1960. +
  1961. +    m_animType = anim;
  1962. +    //kDebug() << "animating for " << time << "ms";
  1963. +    if (m_animType == FadeIn) {
  1964. +        propAnim->setDirection(QAbstractAnimation::Forward);
  1965. +        propAnim->start();
  1966. +    } else if (propAnim) {
  1967. +        propAnim->setDirection(QAbstractAnimation::Backward);
  1968. +        propAnim->start(QAbstractAnimation::DeleteWhenStopped);
  1969. +    }
  1970. +}
  1971. +
  1972. +void DesktopHandle::forceDisappear()
  1973. +{
  1974. +    setAcceptsHoverEvents(false);
  1975. +    startFading(FadeOut, m_entryPos);
  1976. +}
  1977. +
  1978. +int DesktopHandle::minimumHeight()
  1979. +{
  1980. +    int iconMargin = m_iconSize / 2;
  1981. +    int requiredHeight =  iconMargin  + //first margin
  1982. +                          (m_iconSize + iconMargin) * 4 + //XXX remember to update this if the number of buttons changes
  1983. +                          iconMargin ;  //blank space before the close button
  1984. +
  1985. +    if (controlElement(ControlElement::ConfigureElement)) {
  1986. +        requiredHeight += (m_iconSize + iconMargin);
  1987. +    }
  1988. +
  1989. +    return requiredHeight;
  1990. +}
  1991. +
  1992. +void DesktopHandle::calculateSize()
  1993. +{
  1994. +    KIconLoader *iconLoader = KIconLoader::global();
  1995. +    //m_iconSize = iconLoader->currentSize(KIconLoader::Small); //does not work with double sized icon
  1996. +    m_iconSize = iconLoader->loadIcon("transform-scale", KIconLoader::Small).width(); //workaround
  1997. +
  1998. +    int handleHeight = qMax(minimumHeight(), int(widget()->contentsRect().height() * 0.8));
  1999. +    int handleWidth = m_iconSize + 2 * HANDLE_MARGIN;
  2000. +    int top = widget()->contentsRect().top() + (widget()->contentsRect().height() - handleHeight) / 2.0;
  2001. +
  2002. +    qreal marginLeft, marginTop, marginRight, marginBottom;
  2003. +    m_background->getMargins(marginLeft, marginTop, marginRight, marginBottom);
  2004. +
  2005. +    AbstractHandle::HandlePosition pos = position();
  2006. +    if (pos == AbstractHandle::Right) {
  2007. +        //put the rect on the right of the applet
  2008. +        m_rect = QRectF(widget()->size().width(), top, handleWidth, handleHeight);
  2009. +    } else {
  2010. +        //put the rect on the left of the applet
  2011. +        m_rect = QRectF(-handleWidth, top, handleWidth, handleHeight);
  2012. +    }
  2013. +
  2014. +    if (widget()->contentsRect().height() > qreal(minimumHeight()) * 1.25) {
  2015. +        int addedMargin = marginLeft / 2;
  2016. +
  2017. +        // now we check to see if the shape is smaller than the contents,
  2018. +        // and that the shape is not just the bounding rect; in those cases
  2019. +        // we have a shaped guy and we draw a full panel;
  2020. +        // TODO: allow applets to mark when they have translucent areas and
  2021. +        //       should therefore skip this test?
  2022. +        if (widget()->shape().contains(widget()->contentsRect())) {
  2023. +            QPainterPath p;
  2024. +            p.addRect(widget()->boundingRect());
  2025. +            if (widget()->shape() != p) {
  2026. +                addedMargin = widget()->contentsRect().width() / 2;
  2027. +            }
  2028. +        }
  2029. +
  2030. +        AbstractHandle::HandlePosition pos = position();
  2031. +        if (pos == AbstractHandle::Right) {
  2032. +            marginLeft += addedMargin;
  2033. +        } else {
  2034. +            marginRight += addedMargin;
  2035. +        }
  2036. +    }
  2037. +
  2038. +    //m_rect = m_applet->mapToParent(m_rect).boundingRect();
  2039. +    m_decorationRect = m_rect.adjusted(-marginLeft, -marginTop, marginRight, marginBottom);
  2040. +    m_totalRect = m_decorationRect.united(widget()->boundingRect());
  2041. +}
  2042. +
  2043. +} // Plasma Namespace
  2044. +
  2045. +#include "desktophandle.moc"
  2046. +
  2047. Index: private/applethandle_p.h
  2048. ===================================================================
  2049. --- private/applethandle_p.h    (revisione 1171409)
  2050. +++ private/applethandle_p.h    (copia locale)
  2051. @@ -1,154 +0,0 @@
  2052. -/*
  2053. - *   Copyright 2007 by Kevin Ottens <ervin@kde.org>
  2054. - *
  2055. - *   This program is free software; you can redistribute it and/or modify
  2056. - *   it under the terms of the GNU Library General Public License as
  2057. - *   published by the Free Software Foundation; either version 2, or
  2058. - *   (at your option) any later version.
  2059. - *
  2060. - *   This program is distributed in the hope that it will be useful,
  2061. - *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2062. - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2063. - *   GNU General Public License for more details
  2064. - *
  2065. - *   You should have received a copy of the GNU Library General Public
  2066. - *   License along with this program; if not, write to the
  2067. - *   Free Software Foundation, Inc.,
  2068. - *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  2069. - */
  2070. -
  2071. -#ifndef PLASMA_APPLETHANDLE_P_H
  2072. -#define PLASMA_APPLETHANDLE_P_H
  2073. -
  2074. -#include <QtCore/QObject>
  2075. -#include <QtGui/QGraphicsObject>
  2076. -#include <QTimer>
  2077. -#include <QWeakPointer>
  2078. -#include <QPropertyAnimation>
  2079. -
  2080. -#include "animator.h"
  2081. -#include "svg.h"
  2082. -
  2083. -class QGraphicsView;
  2084. -
  2085. -namespace Plasma
  2086. -{
  2087. -class Applet;
  2088. -class Containment;
  2089. -class FrameSvg;
  2090. -class View;
  2091. -
  2092. -class AppletHandle : public QGraphicsObject
  2093. -{
  2094. -    Q_OBJECT
  2095. -    Q_PROPERTY(qreal fadeAnimation READ fadeAnimation WRITE setFadeAnimation)
  2096. -    Q_INTERFACES(QGraphicsItem)
  2097. -    public:
  2098. -        enum FadeType {
  2099. -            FadeIn,
  2100. -            FadeOut
  2101. -        };
  2102. -        enum ButtonType {
  2103. -            NoButton,
  2104. -            MoveButton,
  2105. -            RotateButton,
  2106. -            ConfigureButton,
  2107. -            RemoveButton,
  2108. -            ResizeButton,
  2109. -            MaximizeButton
  2110. -        };
  2111. -
  2112. -        AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos);
  2113. -        virtual ~AppletHandle();
  2114. -
  2115. -        void detachApplet ();
  2116. -
  2117. -        Applet *applet() const;
  2118. -
  2119. -        QRectF boundingRect() const;
  2120. -        QPainterPath shape() const;
  2121. -        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
  2122. -        void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
  2123. -        void setHoverPos(const QPointF &hoverPos);
  2124. -
  2125. -    protected:
  2126. -        void mousePressEvent(QGraphicsSceneMouseEvent *event);
  2127. -        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  2128. -        void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  2129. -        void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
  2130. -        void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
  2131. -        void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
  2132. -        bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
  2133. -        bool sceneEvent(QEvent*);
  2134. -
  2135. -    Q_SIGNALS:
  2136. -       void disappearDone(AppletHandle *self);
  2137. -
  2138. -    private Q_SLOTS:
  2139. -        void setFadeAnimation(qreal progress);
  2140. -        qreal fadeAnimation() const;
  2141. -        void appletDestroyed();
  2142. -        void appletResized();
  2143. -        void hoverTimeout();
  2144. -        void leaveTimeout();
  2145. -        void emitDisappear();
  2146. -
  2147. -    private:
  2148. -        static const int HANDLE_MARGIN = 3;
  2149. -
  2150. -        void calculateSize();
  2151. -        ButtonType mapToButton(const QPointF &point) const;
  2152. -        void forceDisappear();
  2153. -        int minimumHeight();
  2154. -
  2155. -        /**
  2156. -         * move our applet to another containment
  2157. -         * @param containment the containment to move to
  2158. -         * @param pos the (scene-relative) position to place it at
  2159. -         */
  2160. -        void switchContainment(Containment *containment, const QPointF &pos);
  2161. -        bool leaveCurrentView(const QPoint &pos) const;
  2162. -
  2163. -        QRectF m_rect;
  2164. -        QRectF m_decorationRect;
  2165. -        QRectF m_totalRect;
  2166. -        ButtonType m_pressedButton;
  2167. -        Containment *m_containment;
  2168. -        Applet *m_applet;
  2169. -        int m_iconSize;
  2170. -        qreal m_opacity;
  2171. -        FadeType m_animType;
  2172. -        QWeakPointer<QPropertyAnimation> m_anim;
  2173. -        qreal m_angle;
  2174. -        QColor m_gradientColor;
  2175. -        QTimer *m_hoverTimer;
  2176. -        QTimer *m_leaveTimer;
  2177. -        QPixmap *m_backgroundBuffer;
  2178. -        QGraphicsView *m_currentView;
  2179. -
  2180. -        Svg *m_configureIcons;
  2181. -        FrameSvg *m_background;
  2182. -
  2183. -        QPoint m_mousePos;  //mousepos relative to applet
  2184. -        QPointF m_entryPos; //where the hover in event occurred
  2185. -        qreal m_zValue;     //current zValue of the applet, so it can be restored after drag.
  2186. -        QRectF m_originalGeom;
  2187. -        QTransform m_originalTransform;
  2188. -
  2189. -        // used for both resize and rotate
  2190. -        QPointF m_origAppletCenter;
  2191. -        QPointF m_origAppletSize;
  2192. -
  2193. -        // used for resize
  2194. -        QPointF m_resizeStaticPoint;
  2195. -        QPointF m_resizeGrabPoint;
  2196. -        // used for rotate
  2197. -        qreal m_rotateAngleOffset; // applet angle minus cursor angle
  2198. -
  2199. -        bool m_buttonsOnRight : 1;
  2200. -        bool m_pendingFade : 1;
  2201. -};
  2202. -
  2203. -}
  2204. -
  2205. -#endif // multiple inclusion guard
  2206. Index: private/containment_p.h
  2207. ===================================================================
  2208. --- private/containment_p.h (revisione 1171409)
  2209. +++ private/containment_p.h (copia locale)
  2210. @@ -37,6 +37,7 @@
  2211.  class Containment;
  2212.  class AbstractToolBox;
  2213.  class Animation;
  2214. +class AbstractHandle;
  2215.  
  2216.  class ContainmentPrivate
  2217.  {
  2218. @@ -89,7 +90,7 @@
  2219.      QPointF preferredPos(Corona *corona) const;
  2220.      QPointF preferredPanelPos(Corona *corona) const;
  2221.      void setLockToolText();
  2222. -    void handleDisappeared(AppletHandle *handle);
  2223. +    void handleDisappeared(AbstractHandle *handle);
  2224.      void appletDestroyed(Applet*);
  2225.      void appletAppearAnimationComplete();
  2226.      void appletAppeared(Applet*);
  2227. @@ -164,7 +165,7 @@
  2228.      Applet::List applets;
  2229.      Applet *focusedApplet;
  2230.      Plasma::Wallpaper *wallpaper;
  2231. -    QMap<Applet*, AppletHandle*> handles;
  2232. +    QMap<QGraphicsWidget*, AbstractHandle*> handles;
  2233.      QHash<QString, ContainmentActions*> actionPlugins;
  2234.      int screen;
  2235.      int lastScreen;
  2236. Index: private/resizecontrol.h
  2237. ===================================================================
  2238. --- private/resizecontrol.h (revisione 0)
  2239. +++ private/resizecontrol.h (revisione 0)
  2240. @@ -0,0 +1,61 @@
  2241. +/*
  2242. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  2243. + *
  2244. + *   This program is free software; you can redistribute it and/or modify
  2245. + *   it under the terms of the GNU Library General Public License as
  2246. + *   published by the Free Software Foundation; either version 2, or
  2247. + *   (at your option) any later version.
  2248. + *
  2249. + *   This program is distributed in the hope that it will be useful,
  2250. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2251. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2252. + *   GNU General Public License for more details
  2253. + *
  2254. + *   You should have received a copy of the GNU Library General Public
  2255. + *   License along with this program; if not, write to the
  2256. + *   Free Software Foundation, Inc.,
  2257. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  2258. + */
  2259. +
  2260. +#ifndef RESIZECONTROL_H
  2261. +#define RESIZECONTROL_H
  2262. +
  2263. +#include <QPointF>
  2264. +#include <QRectF>
  2265. +
  2266. +#include "plasma.h"
  2267. +#include "controlelement.h"
  2268. +
  2269. +class QGraphicsSceneMouseEvent;
  2270. +
  2271. +namespace Plasma
  2272. +{
  2273. +
  2274. +class ResizeControl : public ControlElement
  2275. +{
  2276. +    Q_OBJECT
  2277. +    public:
  2278. +        ResizeControl(QGraphicsWidget *widget);
  2279. +        virtual ~ResizeControl();
  2280. +
  2281. +        ControlElement::ElementType elementType() const;
  2282. +        void setAspectRatioMode(AspectRatioMode mode);
  2283. +
  2284. +    protected:
  2285. +        void mousePressEvent(QGraphicsSceneMouseEvent *event);
  2286. +        void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  2287. +        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  2288. +
  2289. +    private:
  2290. +        QRectF m_originalGeom;
  2291. +        QPointF m_origWidgetCenter;
  2292. +        QPointF m_origWidgetSize;
  2293. +        QPointF m_resizeStaticPoint;
  2294. +        QPointF m_resizeGrabPoint;
  2295. +        AspectRatioMode aspectRatioMode;
  2296. +
  2297. +};
  2298. +
  2299. +};
  2300. +
  2301. +#endif // multiple inclusion guard
  2302. Index: private/maximizecontrol.cpp
  2303. ===================================================================
  2304. --- private/maximizecontrol.cpp (revisione 0)
  2305. +++ private/maximizecontrol.cpp (revisione 0)
  2306. @@ -0,0 +1,46 @@
  2307. +/*
  2308. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  2309. + *
  2310. + *   This program is free software; you can redistribute it and/or modify
  2311. + *   it under the terms of the GNU Library General Public License as
  2312. + *   published by the Free Software Foundation; either version 2, or
  2313. + *   (at your option) any later version.
  2314. + *
  2315. + *   This program is distributed in the hope that it will be useful,
  2316. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2317. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2318. + *   GNU General Public License for more details
  2319. + *
  2320. + *   You should have received a copy of the GNU Library General Public
  2321. + *   License along with this program; if not, write to the
  2322. + *   Free Software Foundation, Inc.,
  2323. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  2324. + */
  2325. +
  2326. +#include "maximizecontrol.h"
  2327. +
  2328. +namespace Plasma
  2329. +{
  2330. +
  2331. +MaximizeControl::MaximizeControl(QGraphicsWidget *widget)
  2332. +                : ControlElement(widget)
  2333. +{
  2334. +}
  2335. +
  2336. +MaximizeControl::~MaximizeControl()
  2337. +{
  2338. +}
  2339. +
  2340. +ControlElement::ElementType MaximizeControl::elementType() const
  2341. +{
  2342. +    return ControlElement::MaximizeElement;
  2343. +}
  2344. +
  2345. +void MaximizeControl::mouseClickEvent(QGraphicsSceneMouseEvent *)
  2346. +{
  2347. +    emit finished(ControlElement::MaximizeElement);
  2348. +}
  2349. +
  2350. +}
  2351. +
  2352. +#include "maximizecontrol.moc"
  2353. Index: private/controlelement.cpp
  2354. ===================================================================
  2355. --- private/controlelement.cpp  (revisione 0)
  2356. +++ private/controlelement.cpp  (revisione 0)
  2357. @@ -0,0 +1,107 @@
  2358. +/*
  2359. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  2360. + *
  2361. + *   This program is free software; you can redistribute it and/or modify
  2362. + *   it under the terms of the GNU Library General Public License as
  2363. + *   published by the Free Software Foundation; either version 2, or
  2364. + *   (at your option) any later version.
  2365. + *
  2366. + *   This program is distributed in the hope that it will be useful,
  2367. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2368. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2369. + *   GNU General Public License for more details
  2370. + *
  2371. + *   You should have received a copy of the GNU Library General Public
  2372. + *   License along with this program; if not, write to the
  2373. + *   Free Software Foundation, Inc.,
  2374. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  2375. + */
  2376. +
  2377. +#include "controlelement.h"
  2378. +#include "controlelement_p.h"
  2379. +
  2380. +#include <QtGui/QWidget>
  2381. +#include <QtGui/QGraphicsWidget>
  2382. +
  2383. +#include <Plasma/View>
  2384. +#include <Plasma/Containment>
  2385. +
  2386. +#include "abstracthandle.h"
  2387. +
  2388. +namespace Plasma
  2389. +{
  2390. +
  2391. +ControlElementPrivate::ControlElementPrivate(ControlElement *e)
  2392. +                     : q(e)
  2393. +{
  2394. +
  2395. +}
  2396. +
  2397. +ControlElementPrivate::~ControlElementPrivate()
  2398. +{
  2399. +
  2400. +}
  2401. +
  2402. +
  2403. +
  2404. +ControlElement::ControlElement(QGraphicsWidget *widget)
  2405. +              : QObject(widget),
  2406. +                d(new ControlElementPrivate(this))
  2407. +{
  2408. +    d->widget = widget;
  2409. +    d->handle = 0;
  2410. +}
  2411. +
  2412. +ControlElement::~ControlElement()
  2413. +{
  2414. +    delete d;
  2415. +}
  2416. +
  2417. +QGraphicsWidget *ControlElement::widget() const
  2418. +{
  2419. +    return d->widget;
  2420. +}
  2421. +
  2422. +AbstractHandle *ControlElement::handle() const
  2423. +{
  2424. +    return d->handle;
  2425. +}
  2426. +
  2427. +bool ControlElement::leaveCurrentView(const QPoint &pos) const
  2428. +{
  2429. +    foreach (QWidget *widget, QApplication::topLevelWidgets()) {
  2430. +        if (widget->geometry().contains(pos)) {
  2431. +            //is this widget a plasma view, a different view then our current one,
  2432. +            //AND not a dashboardview?
  2433. +            Plasma::View *v = qobject_cast<Plasma::View *>(widget);
  2434. +            if (v && v != d->handle->containment()->view() && v->containment() != d->handle->containment()) {
  2435. +                return true;
  2436. +            }
  2437. +        }
  2438. +    }
  2439. +    return false;
  2440. +}
  2441. +
  2442. +void ControlElement::mousePressEvent(QGraphicsSceneMouseEvent *)
  2443. +{
  2444. +
  2445. +}
  2446. +
  2447. +void ControlElement::mouseMoveEvent(QGraphicsSceneMouseEvent *)
  2448. +{
  2449. +
  2450. +}
  2451. +
  2452. +void ControlElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
  2453. +{
  2454. +
  2455. +}
  2456. +
  2457. +void ControlElement::mouseClickEvent(QGraphicsSceneMouseEvent *)
  2458. +{
  2459. +
  2460. +}
  2461. +
  2462. +}
  2463. +
  2464. +#include "controlelement.moc"
  2465. Index: private/removecontrol.cpp
  2466. ===================================================================
  2467. --- private/removecontrol.cpp   (revisione 0)
  2468. +++ private/removecontrol.cpp   (revisione 0)
  2469. @@ -0,0 +1,46 @@
  2470. +/*
  2471. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  2472. + *
  2473. + *   This program is free software; you can redistribute it and/or modify
  2474. + *   it under the terms of the GNU Library General Public License as
  2475. + *   published by the Free Software Foundation; either version 2, or
  2476. + *   (at your option) any later version.
  2477. + *
  2478. + *   This program is distributed in the hope that it will be useful,
  2479. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2480. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2481. + *   GNU General Public License for more details
  2482. + *
  2483. + *   You should have received a copy of the GNU Library General Public
  2484. + *   License along with this program; if not, write to the
  2485. + *   Free Software Foundation, Inc.,
  2486. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  2487. + */
  2488. +
  2489. +#include "removecontrol.h"
  2490. +
  2491. +namespace Plasma
  2492. +{
  2493. +
  2494. +RemoveControl::RemoveControl(QGraphicsWidget *widget)
  2495. +             : ControlElement(widget)
  2496. +{
  2497. +}
  2498. +
  2499. +RemoveControl::~RemoveControl()
  2500. +{
  2501. +}
  2502. +
  2503. +ControlElement::ElementType RemoveControl::elementType() const
  2504. +{
  2505. +    return ControlElement::RemoveElement;
  2506. +}
  2507. +
  2508. +void RemoveControl::mouseClickEvent(QGraphicsSceneMouseEvent *)
  2509. +{
  2510. +    emit finished(ControlElement::RemoveElement);
  2511. +}
  2512. +
  2513. +}
  2514. +
  2515. +#include "removecontrol.moc"
  2516. Index: private/applethandle.cpp
  2517. ===================================================================
  2518. --- private/applethandle.cpp    (revisione 1171409)
  2519. +++ private/applethandle.cpp    (copia locale)
  2520. @@ -1,1056 +0,0 @@
  2521. -/*
  2522. - *   Copyright 2007 by Kevin Ottens <ervin@kde.org>
  2523. - *
  2524. - *   This program is free software; you can redistribute it and/or modify
  2525. - *   it under the terms of the GNU Library General Public License as
  2526. - *   published by the Free Software Foundation; either version 2, or
  2527. - *   (at your option) any later version.
  2528. - *
  2529. - *   This program is distributed in the hope that it will be useful,
  2530. - *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  2531. - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2532. - *   GNU General Public License for more details
  2533. - *
  2534. - *   You should have received a copy of the GNU Library General Public
  2535. - *   License along with this program; if not, write to the
  2536. - *   Free Software Foundation, Inc.,
  2537. - *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  2538. - */
  2539. -
  2540. -#include "private/applethandle_p.h"
  2541. -
  2542. -#include <QApplication>
  2543. -#include <QBitmap>
  2544. -#include <QtGui/QGraphicsSceneMouseEvent>
  2545. -#include <QtGui/QLinearGradient>
  2546. -#include <QtGui/QPainter>
  2547. -#include <QtGui/QApplication>
  2548. -#include <QtGui/QMenu>
  2549. -#include <QTouchEvent>
  2550. -#include <QMatrix>
  2551. -#include <QTransform>
  2552. -#include <QWeakPointer>
  2553. -#include <QPropertyAnimation>
  2554. -
  2555. -#include <kcolorscheme.h>
  2556. -#include <kglobalsettings.h>
  2557. -#include <kicon.h>
  2558. -#include <kiconloader.h>
  2559. -#include <kwindowsystem.h>
  2560. -
  2561. -#include <cmath>
  2562. -#include <math.h>
  2563. -
  2564. -#include "applet.h"
  2565. -#include "applet_p.h"
  2566. -#include "containment.h"
  2567. -#include "corona.h"
  2568. -#include "paintutils.h"
  2569. -#include "theme.h"
  2570. -#include "view.h"
  2571. -#include "framesvg.h"
  2572. -
  2573. -namespace Plasma
  2574. -{
  2575. -
  2576. -qreal _k_distanceForPoint(QPointF point);
  2577. -qreal _k_pointAngle(QPointF point);
  2578. -QPointF _k_rotatePoint(QPointF point, qreal angle);
  2579. -QPointF _k_projectPoint(QPointF point, QPointF v);
  2580. -
  2581. -AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos)
  2582. -    : QGraphicsObject(applet),
  2583. -      m_pressedButton(NoButton),
  2584. -      m_containment(parent),
  2585. -      m_applet(applet),
  2586. -      m_iconSize(KIconLoader::SizeSmall),
  2587. -      m_opacity(0.0),
  2588. -      m_animType(FadeIn),
  2589. -      m_backgroundBuffer(0),
  2590. -      m_currentView(applet->view()),
  2591. -      m_entryPos(hoverPos),
  2592. -      m_buttonsOnRight(false),
  2593. -      m_pendingFade(false)
  2594. -{
  2595. -    setFlags(flags() | QGraphicsItem::ItemStacksBehindParent);
  2596. -    KColorScheme colorScheme(QPalette::Active, KColorScheme::View,
  2597. -                             Theme::defaultTheme()->colorScheme());
  2598. -    setAcceptTouchEvents(true);
  2599. -    m_gradientColor = colorScheme.background(KColorScheme::NormalBackground).color();
  2600. -    m_originalGeom = mapToScene(QRectF(QPoint(0,0), m_applet->size())).boundingRect();
  2601. -    m_originalTransform = m_applet->transform();
  2602. -
  2603. -    QPointF center = QRectF(QPointF(), m_applet->size()).center();
  2604. -    m_angle = _k_pointAngle(m_originalTransform.map(center + QPointF(1.0, 0.0)) - center);
  2605. -
  2606. -    m_hoverTimer = new QTimer(this);
  2607. -    m_hoverTimer->setSingleShot(true);
  2608. -    m_hoverTimer->setInterval(333);
  2609. -
  2610. -    m_leaveTimer = new QTimer(this);
  2611. -    m_leaveTimer->setSingleShot(true);
  2612. -    m_leaveTimer->setInterval(500);
  2613. -
  2614. -    connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
  2615. -    connect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
  2616. -    connect(m_applet, SIGNAL(appletDestroyed(Plasma::Applet*)), this, SLOT(appletDestroyed()));
  2617. -
  2618. -    setAcceptsHoverEvents(true);
  2619. -    m_hoverTimer->start();
  2620. -
  2621. -    //icons
  2622. -    m_configureIcons = new Svg(this);
  2623. -    m_configureIcons->setImagePath("widgets/configuration-icons");
  2624. -    m_configureIcons->setContainsMultipleImages(true);
  2625. -
  2626. -    m_background = new FrameSvg(this);
  2627. -    m_background->setImagePath("widgets/background");
  2628. -    m_applet->installSceneEventFilter(this);
  2629. -}
  2630. -
  2631. -AppletHandle::~AppletHandle()
  2632. -{
  2633. -    detachApplet();
  2634. -    delete m_backgroundBuffer;
  2635. -}
  2636. -
  2637. -Applet *AppletHandle::applet() const
  2638. -{
  2639. -    return m_applet;
  2640. -}
  2641. -
  2642. -void AppletHandle::detachApplet()
  2643. -{
  2644. -    if (!m_applet) {
  2645. -        return;
  2646. -    }
  2647. -
  2648. -    disconnect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
  2649. -    disconnect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
  2650. -    m_applet->disconnect(this);
  2651. -
  2652. -    if (m_applet->geometry() != m_originalGeom || m_applet->transform() != m_originalTransform) {
  2653. -        emit m_applet->appletTransformedByUser();
  2654. -    }
  2655. -
  2656. -    m_applet = 0;
  2657. -}
  2658. -
  2659. -QRectF Plasma::AppletHandle::boundingRect() const
  2660. -{
  2661. -    return m_totalRect;
  2662. -}
  2663. -
  2664. -QPainterPath AppletHandle::shape() const
  2665. -{
  2666. -    //when the containment changes the applet is reset to 0
  2667. -    if (m_applet) {
  2668. -        QPainterPath path = PaintUtils::roundedRectangle(m_decorationRect, 10);
  2669. -        return path.united(m_applet->shape());
  2670. -    } else {
  2671. -        return QGraphicsItem::shape();
  2672. -    }
  2673. -}
  2674. -
  2675. -QPainterPath handleRect(const QRectF &rect, int radius, bool onRight)
  2676. -{
  2677. -    QPainterPath path;
  2678. -    if (onRight) {
  2679. -        // make the left side straight
  2680. -        path.moveTo(rect.left(), rect.top());              // Top left
  2681. -        path.lineTo(rect.right() - radius, rect.top());    // Top side
  2682. -        path.quadTo(rect.right(), rect.top(),
  2683. -                    rect.right(), rect.top() + radius);    // Top right corner
  2684. -        path.lineTo(rect.right(), rect.bottom() - radius); // Right side
  2685. -        path.quadTo(rect.right(), rect.bottom(),
  2686. -                    rect.right() - radius, rect.bottom()); // Bottom right corner
  2687. -        path.lineTo(rect.left(), rect.bottom());           // Bottom side
  2688. -    } else {
  2689. -        // make the right side straight
  2690. -        path.moveTo(QPointF(rect.left(), rect.top() + radius));
  2691. -        path.quadTo(rect.left(), rect.top(),
  2692. -                    rect.left() + radius, rect.top());     // Top left corner
  2693. -        path.lineTo(rect.right(), rect.top());             // Top side
  2694. -        path.lineTo(rect.right(), rect.bottom());          // Right side
  2695. -        path.lineTo(rect.left() + radius, rect.bottom());  // Bottom side
  2696. -        path.quadTo(rect.left(), rect.bottom(),
  2697. -                    rect.left(), rect.bottom() - radius);  // Bottom left corner
  2698. -    }
  2699. -
  2700. -    path.closeSubpath();
  2701. -    return path;
  2702. -}
  2703. -
  2704. -void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2705. -{
  2706. -    Q_UNUSED(option);
  2707. -    Q_UNUSED(widget);
  2708. -
  2709. -    //kDebug() << m_opacity << m_anim << FadeOut;
  2710. -    if (qFuzzyCompare(m_opacity + 1.0, 1.0)) {
  2711. -        if (m_animType == FadeOut) {
  2712. -            //kDebug() << "WOOOOOOOOO";
  2713. -            QTimer::singleShot(0, this, SLOT(emitDisappear()));
  2714. -        }
  2715. -        return;
  2716. -    }
  2717. -
  2718. -    qreal translation;
  2719. -
  2720. -    if (m_buttonsOnRight) {
  2721. -        //kDebug() << "translating by" << m_opacity
  2722. -        //         << (-(1 - m_opacity) * m_rect.width()) << m_rect.width();
  2723. -        translation = -(1 - m_opacity) * m_rect.width();
  2724. -    } else {
  2725. -        translation = (1 - m_opacity) * m_rect.width();
  2726. -    }
  2727. -
  2728. -    painter->translate(translation, 0);
  2729. -
  2730. -    painter->setPen(Qt::NoPen);
  2731. -    painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
  2732. -
  2733. -    int iconMargin = m_iconSize / 2;
  2734. -
  2735. -    const QSize pixmapSize(int(m_decorationRect.width()),
  2736. -                           int(m_decorationRect.height()) + m_iconSize * 5 + 1);
  2737. -    const QSize iconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
  2738. -
  2739. -    bool isRunning = false;
  2740. -    if (m_anim.data()) {
  2741. -        isRunning = m_anim.data()->state() == QAbstractAnimation::Running ? \
  2742. -                    true : false;
  2743. -    }
  2744. -
  2745. -    //regenerate our buffer?
  2746. -    if (isRunning || !m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
  2747. -        QColor transparencyColor = Qt::black;
  2748. -        transparencyColor.setAlphaF(qMin(m_opacity, qreal(0.99)));
  2749. -
  2750. -        QLinearGradient g(QPoint(0, 0), QPoint(m_decorationRect.width(), 0));
  2751. -        //fading out panel
  2752. -        if (m_rect.height() > qreal(minimumHeight()) * 1.25) {
  2753. -            if (m_buttonsOnRight) {
  2754. -                qreal opaquePoint =
  2755. -                    (m_background->marginSize(LeftMargin) - translation) / m_decorationRect.width();
  2756. -                //kDebug() << "opaquePoint" << opaquePoint
  2757. -                //         << m_background->marginSize(LeftMargin) << m_decorationRect.width();
  2758. -                g.setColorAt(0.0, Qt::transparent);
  2759. -                g.setColorAt(qMax(0.0, opaquePoint - 0.05), Qt::transparent);
  2760. -                g.setColorAt(opaquePoint, transparencyColor);
  2761. -                g.setColorAt(1.0, transparencyColor);
  2762. -            } else {
  2763. -                qreal opaquePoint =
  2764. -                    1 - ((m_background->marginSize(RightMargin) + translation) / m_decorationRect.width());
  2765. -                g.setColorAt(1.0, Qt::transparent);
  2766. -                g.setColorAt(opaquePoint + 0.05, Qt::transparent);
  2767. -                g.setColorAt(qMax(qreal(0), opaquePoint), transparencyColor);
  2768. -                g.setColorAt(0.0, transparencyColor);
  2769. -            }
  2770. -        //complete panel
  2771. -        } else {
  2772. -            g.setColorAt(0.0, transparencyColor);
  2773. -        }
  2774. -
  2775. -        m_background->resizeFrame(m_decorationRect.size());
  2776. -
  2777. -        if (!m_backgroundBuffer || m_backgroundBuffer->size() != pixmapSize) {
  2778. -            delete m_backgroundBuffer;
  2779. -            m_backgroundBuffer = new QPixmap(pixmapSize);
  2780. -        }
  2781. -        m_backgroundBuffer->fill(Qt::transparent);
  2782. -        QPainter buffPainter(m_backgroundBuffer);
  2783. -
  2784. -        m_background->paintFrame(&buffPainter);
  2785. -
  2786. -        //+1 because otherwise due to rounding errors when rotated could appear one pixel
  2787. -        //of the icon at the border of the applet
  2788. -        //QRectF iconRect(QPointF(pixmapSize.width() - m_iconSize + 1, m_iconSize), iconSize);
  2789. -        QRectF iconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
  2790. -        if (m_buttonsOnRight) {
  2791. -            iconRect.moveLeft(
  2792. -                pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
  2793. -            m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tr2bl");
  2794. -        } else {
  2795. -            iconRect.moveLeft(m_background->marginSize(RightMargin));
  2796. -            m_configureIcons->paint(&buffPainter, iconRect, "size-diagonal-tl2br");
  2797. -        }
  2798. -
  2799. -        iconRect.translate(0, m_iconSize);
  2800. -        m_configureIcons->paint(&buffPainter, iconRect, "rotate");
  2801. -
  2802. -        if (m_applet && m_applet->hasConfigurationInterface()) {
  2803. -            iconRect.translate(0, m_iconSize);
  2804. -            m_configureIcons->paint(&buffPainter, iconRect, "configure");
  2805. -        }
  2806. -
  2807. -        if (m_applet && m_applet->hasValidAssociatedApplication()) {
  2808. -            iconRect.translate(0, m_iconSize);
  2809. -            m_configureIcons->paint(&buffPainter, iconRect, "maximize");
  2810. -        }
  2811. -
  2812. -        iconRect.translate(0, m_iconSize);
  2813. -        m_configureIcons->paint(&buffPainter, iconRect, "close");
  2814. -
  2815. -        buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
  2816. -        //blend the background
  2817. -        buffPainter.fillRect(m_backgroundBuffer->rect(), g);
  2818. -        //blend the icons
  2819. -        //buffPainter.fillRect(QRect(QPoint((int)m_decorationRect.width(), 0), QSize(m_iconSize + 1,
  2820. -        //                                  (int)m_decorationRect.height())), transparencyColor);
  2821. -    }
  2822. -
  2823. -    painter->drawPixmap(m_decorationRect.toRect(), *m_backgroundBuffer,
  2824. -                        QRect(QPoint(0, 0), m_decorationRect.size().toSize()));
  2825. -
  2826. -    //XXX this code is duplicated in the next function
  2827. -    QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
  2828. -    QPointF step = QPointF(0, m_iconSize + iconMargin);
  2829. -    QPointF separator = step + QPointF(0, iconMargin);
  2830. -    //end duplicate code
  2831. -
  2832. -    QPointF shiftC;
  2833. -    QPointF shiftD;
  2834. -    QPointF shiftR;
  2835. -    QPointF shiftM;
  2836. -    QPointF shiftMx;
  2837. -
  2838. -    switch(m_pressedButton)
  2839. -    {
  2840. -    case ConfigureButton:
  2841. -        shiftC = QPointF(2, 2);
  2842. -        break;
  2843. -    case RemoveButton:
  2844. -        shiftD = QPointF(2, 2);
  2845. -        break;
  2846. -    case RotateButton:
  2847. -        shiftR = QPointF(2, 2);
  2848. -        break;
  2849. -    case ResizeButton:
  2850. -        shiftM = QPointF(2, 2);
  2851. -        break;
  2852. -    case MaximizeButton:
  2853. -        shiftMx = QPointF(2, 2);
  2854. -        break;
  2855. -    default:
  2856. -        break;
  2857. -    }
  2858. -
  2859. -    QRectF sourceIconRect(QPointF(0, m_decorationRect.height() + 1), iconSize);
  2860. -    if (m_buttonsOnRight) {
  2861. -        sourceIconRect.moveLeft(
  2862. -            pixmapSize.width() - m_iconSize - m_background->marginSize(LeftMargin));
  2863. -    } else {
  2864. -        sourceIconRect.moveLeft(m_background->marginSize(RightMargin));
  2865. -    }
  2866. -
  2867. -    if (m_applet && m_applet->aspectRatioMode() != FixedSize) {
  2868. -        //resize
  2869. -        painter->drawPixmap(
  2870. -            QRectF(basePoint + shiftM, iconSize), *m_backgroundBuffer, sourceIconRect);
  2871. -        basePoint += step;
  2872. -    }
  2873. -
  2874. -    //rotate
  2875. -    sourceIconRect.translate(0, m_iconSize);
  2876. -    painter->drawPixmap(QRectF(basePoint + shiftR, iconSize), *m_backgroundBuffer, sourceIconRect);
  2877. -
  2878. -    //configure
  2879. -    if (m_applet && m_applet->hasConfigurationInterface()) {
  2880. -        basePoint += step;
  2881. -        sourceIconRect.translate(0, m_iconSize);
  2882. -        painter->drawPixmap(
  2883. -            QRectF(basePoint + shiftC, iconSize), *m_backgroundBuffer, sourceIconRect);
  2884. -    }
  2885. -
  2886. -    //maximize
  2887. -    if (m_applet && m_applet->hasValidAssociatedApplication()) {
  2888. -        basePoint += step;
  2889. -        sourceIconRect.translate(0, m_iconSize);
  2890. -        painter->drawPixmap(
  2891. -            QRectF(basePoint + shiftMx, iconSize), *m_backgroundBuffer, sourceIconRect);
  2892. -    }
  2893. -
  2894. -    //close
  2895. -    basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step;
  2896. -    sourceIconRect.translate(0, m_iconSize);
  2897. -    painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect);
  2898. -}
  2899. -
  2900. -void AppletHandle::emitDisappear()
  2901. -{
  2902. -    emit disappearDone(this);
  2903. -}
  2904. -
  2905. -AppletHandle::ButtonType AppletHandle::mapToButton(const QPointF &point) const
  2906. -{
  2907. -    int iconMargin = m_iconSize / 2;
  2908. -    //XXX this code is duplicated in the prev. function
  2909. -    QPointF basePoint = m_rect.topLeft() + QPointF(HANDLE_MARGIN, iconMargin);
  2910. -    QPointF step = QPointF(0, m_iconSize + iconMargin);
  2911. -    QPointF separator = step + QPointF(0, iconMargin);
  2912. -   //end duplicate code
  2913. -
  2914. -    QRectF activeArea = QRectF(basePoint, QSizeF(m_iconSize, m_iconSize));
  2915. -
  2916. -    if (m_applet && m_applet->aspectRatioMode() != FixedSize) {
  2917. -        if (activeArea.contains(point)) {
  2918. -            return ResizeButton;
  2919. -        }
  2920. -        activeArea.translate(step);
  2921. -    }
  2922. -
  2923. -    if (activeArea.contains(point)) {
  2924. -        return RotateButton;
  2925. -    }
  2926. -
  2927. -    if (m_applet && m_applet->hasConfigurationInterface()) {
  2928. -        activeArea.translate(step);
  2929. -        if (activeArea.contains(point)) {
  2930. -            return ConfigureButton;
  2931. -        }
  2932. -    }
  2933. -
  2934. -    if (m_applet && m_applet->hasValidAssociatedApplication()) {
  2935. -        activeArea.translate(step);
  2936. -        if (activeArea.contains(point)) {
  2937. -            return MaximizeButton;
  2938. -        }
  2939. -    }
  2940. -
  2941. -    activeArea.moveTop(m_rect.bottom() - activeArea.height() - iconMargin);
  2942. -    if (activeArea.contains(point)) {
  2943. -        return RemoveButton;
  2944. -    }
  2945. -
  2946. -    return MoveButton;
  2947. -    //return m_applet->mapToParent(m_applet->shape()).contains(point) ? NoButton : MoveButton;
  2948. -}
  2949. -
  2950. -void AppletHandle::mousePressEvent(QGraphicsSceneMouseEvent *event)
  2951. -{
  2952. -    //containment recently switched?
  2953. -    if (!m_applet) {
  2954. -        QGraphicsItem::mousePressEvent(event);
  2955. -        return;
  2956. -    }
  2957. -
  2958. -    if (m_pendingFade) {
  2959. -        //m_pendingFade = false;
  2960. -        return;
  2961. -    }
  2962. -
  2963. -    if (event->button() == Qt::LeftButton) {
  2964. -        m_pressedButton = mapToButton(event->pos());
  2965. -        //kDebug() << "button pressed:" << m_pressedButton;
  2966. -        if (m_pressedButton != NoButton) {
  2967. -            m_applet->raise();
  2968. -            m_zValue = m_applet->zValue();
  2969. -            setZValue(m_zValue);
  2970. -        }
  2971. -
  2972. -        if (m_pressedButton == ResizeButton || m_pressedButton == RotateButton) {
  2973. -            m_originalGeom = mapToScene(QRectF(QPoint(0,0), m_applet->size())).boundingRect();
  2974. -            m_origAppletCenter = m_originalGeom.center();
  2975. -            m_origAppletSize = QPointF(m_applet->size().width(), m_applet->size().height());
  2976. -
  2977. -            // resize
  2978. -            if (m_buttonsOnRight) {
  2979. -                m_resizeStaticPoint = m_applet->mapToScene(QPointF(0, m_applet->size().height()));
  2980. -            } else {
  2981. -                m_resizeStaticPoint = m_applet->mapToScene(m_origAppletSize);
  2982. -            }
  2983. -            m_resizeGrabPoint = event->scenePos();
  2984. -
  2985. -            // rotate
  2986. -            m_rotateAngleOffset = m_angle - _k_pointAngle(event->scenePos() - m_origAppletCenter);
  2987. -        }
  2988. -
  2989. -        event->accept();
  2990. -
  2991. -        //set mousePos to the position in the applet, in screencoords, so it becomes easy
  2992. -        //to reposition the toplevel view to the correct position.
  2993. -        if (m_currentView && m_applet) {
  2994. -            QPoint localpos = m_currentView->mapFromScene(m_applet->scenePos());
  2995. -            m_mousePos = event->screenPos() - m_currentView->mapToGlobal(localpos);
  2996. -        }
  2997. -        return;
  2998. -    }
  2999. -
  3000. -    QGraphicsItem::mousePressEvent(event);
  3001. -}
  3002. -
  3003. -bool AppletHandle::leaveCurrentView(const QPoint &pos) const
  3004. -{
  3005. -    foreach (QWidget *widget, QApplication::topLevelWidgets()) {
  3006. -        if (widget->geometry().contains(pos)) {
  3007. -            //is this widget a plasma view, a different view then our current one,
  3008. -            //AND not a dashboardview?
  3009. -            Plasma::View *v = qobject_cast<Plasma::View *>(widget);
  3010. -            if (v && v != m_currentView && v->containment() != m_containment) {
  3011. -                return true;
  3012. -            }
  3013. -        }
  3014. -    }
  3015. -    return false;
  3016. -}
  3017. -
  3018. -void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  3019. -{
  3020. -    //kDebug() << "button pressed:" << m_pressedButton << ", fade pending?" << m_pendingFade;
  3021. -
  3022. -    if (m_pendingFade) {
  3023. -        startFading(FadeOut, m_entryPos);
  3024. -        m_pendingFade = false;
  3025. -    }
  3026. -
  3027. -    ButtonType releasedAtButton = mapToButton(event->pos());
  3028. -
  3029. -    if (m_applet && event->button() == Qt::LeftButton) {
  3030. -        switch (m_pressedButton) {
  3031. -        case ConfigureButton:
  3032. -            //FIXME: Remove this call once the configuration management change was done
  3033. -            if (m_pressedButton == releasedAtButton) {
  3034. -                m_applet->showConfigurationInterface();
  3035. -            }
  3036. -            break;
  3037. -        case RemoveButton:
  3038. -            if (m_pressedButton == releasedAtButton) {
  3039. -                forceDisappear();
  3040. -                m_applet->destroy();
  3041. -            }
  3042. -            break;
  3043. -        case MoveButton:
  3044. -        {
  3045. -                // test for containment change
  3046. -                //kDebug() << "testing for containment change, sceneBoundingRect = "
  3047. -                //         << m_containment->sceneBoundingRect();
  3048. -                if (!m_containment->sceneBoundingRect().contains(m_applet->scenePos())) {
  3049. -                    // see which containment it belongs to
  3050. -                    Corona * corona = qobject_cast<Corona*>(scene());
  3051. -                    if (corona) {
  3052. -                        foreach (Containment *containment, corona->containments()) {
  3053. -                            QPointF pos;
  3054. -                            QGraphicsView *v = containment->view();
  3055. -                            if (v) {
  3056. -                                pos = v->mapToScene(v->mapFromGlobal(event->screenPos() - m_mousePos));
  3057. -
  3058. -                                if (containment->sceneBoundingRect().contains(pos)) {
  3059. -                                    //kDebug() << "new containment = " << containments[i];
  3060. -                                    //kDebug() << "rect = " << containments[i]->sceneBoundingRect();
  3061. -                                    // add the applet to the new containment and take it from the old one
  3062. -                                    //kDebug() << "moving to other containment with position" << pos;;
  3063. -                                    switchContainment(containment, pos);
  3064. -                                    break;
  3065. -                                }
  3066. -                            }
  3067. -                        }
  3068. -                    }
  3069. -                }
  3070. -            break;
  3071. -        }
  3072. -        case MaximizeButton:
  3073. -            if (m_applet) {
  3074. -                m_applet->runAssociatedApplication();
  3075. -            }
  3076. -            break;
  3077. -        default:
  3078. -            break;
  3079. -        }
  3080. -    }
  3081. -
  3082. -    m_pressedButton = NoButton;
  3083. -    update();
  3084. -}
  3085. -
  3086. -qreal _k_distanceForPoint(QPointF point)
  3087. -{
  3088. -    return std::sqrt(point.x() * point.x() + point.y() * point.y());
  3089. -}
  3090. -
  3091. -qreal _k_pointAngle(QPointF point)
  3092. -{
  3093. -    qreal r = sqrt(point.x() * point.x() + point.y() * point.y());
  3094. -    qreal cosine = point.x() / r;
  3095. -
  3096. -    if (point.y() >= 0) {
  3097. -        return acos(cosine);
  3098. -    } else {
  3099. -        return -acos(cosine);
  3100. -    }
  3101. -}
  3102. -
  3103. -QPointF _k_rotatePoint(QPointF point, qreal angle)
  3104. -{
  3105. -    return QTransform().rotateRadians(angle).map(point);
  3106. -}
  3107. -
  3108. -QPointF _k_projectPoint(QPointF point, QPointF v)
  3109. -{
  3110. -    v /= sqrt(v.x() * v.x() + v.y() * v.y());
  3111. -    qreal a = v.x() * v.x();
  3112. -    qreal b = v.x() * v.y();
  3113. -    qreal d = v.y() * v.y();
  3114. -    return QMatrix(a, b, b, d, 0., 0.).map(point);
  3115. -}
  3116. -
  3117. -void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  3118. -{
  3119. -    static const qreal snapAngle = M_PI_2 /* $i 3.14159 / 2.0 */;
  3120. -
  3121. -    if (!m_applet) {
  3122. -        QGraphicsItem::mouseMoveEvent(event);
  3123. -        return;
  3124. -    }
  3125. -
  3126. -    //Track how much the mouse has moved.
  3127. -    QPointF deltaScene  = event->scenePos() - event->lastScenePos();
  3128. -
  3129. -    if (m_pressedButton == MoveButton) {
  3130. -        if (leaveCurrentView(event->screenPos())) {
  3131. -            Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
  3132. -            if (v && v != m_currentView) {
  3133. -                Containment *c = v->containment();
  3134. -                if (c) {
  3135. -                    QPoint pos = v->mapFromGlobal(event->screenPos());
  3136. -                    //we actually have been dropped on another containment, so
  3137. -                    //move there: we have a screenpos, we need a scenepos
  3138. -                    //FIXME how reliable is this transform?
  3139. -                    switchContainment(c, v->mapToScene(pos));
  3140. -                }
  3141. -            }
  3142. -        }
  3143. -
  3144. -        if (m_applet) {
  3145. -            QPointF mappedPoint = transform().map(QPointF(deltaScene.x(), deltaScene.y()));
  3146. -            m_applet->moveBy(mappedPoint.x(), mappedPoint.y());
  3147. -        }
  3148. -    } else if (m_pressedButton == ResizeButton || m_pressedButton == RotateButton) {
  3149. -        QPointF cursorPoint = event->scenePos();
  3150. -
  3151. -        // the code below will adjust these based on the type of operation
  3152. -        QPointF newSize;
  3153. -        QPointF newCenter;
  3154. -        qreal newAngle;
  3155. -
  3156. -        // get size limits
  3157. -        QSizeF min = m_applet->minimumSize();
  3158. -        QSizeF max = m_applet->maximumSize();
  3159. -
  3160. -        if (min.width() < KIconLoader::SizeSmall || min.height() <  KIconLoader::SizeSmall) {
  3161. -            min = m_applet->effectiveSizeHint(Qt::MinimumSize);
  3162. -        }
  3163. -
  3164. -        if (max.isEmpty()) {
  3165. -            max = m_applet->effectiveSizeHint(Qt::MaximumSize);
  3166. -        }
  3167. -
  3168. -        // If the applet doesn't have a minimum size, calculate based on a
  3169. -        // minimum content area size of 16x16 (KIconLoader::SizeSmall)
  3170. -        if (min.width() < KIconLoader::SizeSmall || min.height() <  KIconLoader::SizeSmall) {
  3171. -            min = m_applet->boundingRect().size() - m_applet->contentsRect().size();
  3172. -            min = QSizeF(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
  3173. -        }
  3174. -
  3175. -        if (m_pressedButton == RotateButton) {
  3176. -            newSize = m_origAppletSize;
  3177. -            newCenter = m_origAppletCenter;
  3178. -
  3179. -            QPointF centerRelativePoint = cursorPoint - m_origAppletCenter;
  3180. -            if (_k_distanceForPoint(centerRelativePoint) < 10) {
  3181. -                newAngle = m_angle;
  3182. -            } else {
  3183. -                qreal cursorAngle = _k_pointAngle(centerRelativePoint);
  3184. -                newAngle = m_rotateAngleOffset + cursorAngle;
  3185. -                if (fabs(remainder(newAngle, snapAngle)) < 0.15) {
  3186. -                    newAngle = newAngle - remainder(newAngle, snapAngle);
  3187. -                }
  3188. -            }
  3189. -        } else {
  3190. -            // un-rotate screen points so we can read differences of coordinates
  3191. -            QPointF rStaticPoint = _k_rotatePoint(m_resizeStaticPoint, -m_angle);
  3192. -            QPointF rCursorPoint = _k_rotatePoint(cursorPoint, -m_angle);
  3193. -            QPointF rGrabPoint = _k_rotatePoint(m_resizeGrabPoint, -m_angle);
  3194. -
  3195. -            if (m_buttonsOnRight) {
  3196. -                newSize = m_origAppletSize + QPointF(rCursorPoint.x() - rGrabPoint.x(), rGrabPoint.y() - rCursorPoint.y());
  3197. -            } else {
  3198. -                newSize = m_origAppletSize + QPointF(rGrabPoint.x() - rCursorPoint.x(), rGrabPoint.y() - rCursorPoint.y());
  3199. -            }
  3200. -
  3201. -            // preserving aspect ratio?
  3202. -            if ((m_applet->aspectRatioMode() != Plasma::IgnoreAspectRatio &&
  3203. -                 !(event->modifiers() & Qt::ControlModifier)) ||
  3204. -                 (m_applet->aspectRatioMode() == Plasma::IgnoreAspectRatio &&
  3205. -                  (event->modifiers() & Qt::ControlModifier))) {
  3206. -                // project size to keep ratio
  3207. -                newSize = _k_projectPoint(newSize, m_origAppletSize);
  3208. -                // limit size, presering ratio
  3209. -                qreal ratio = m_origAppletSize.y() / m_origAppletSize.x();
  3210. -                newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
  3211. -                newSize.ry() = newSize.x() * ratio;
  3212. -                newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
  3213. -                newSize.rx() = newSize.y() / ratio;
  3214. -            } else {
  3215. -                // limit size
  3216. -                newSize.rx() = qMin(max.width(), qMax(min.width(), newSize.x()));
  3217. -                newSize.ry() = qMin(max.height(), qMax(min.height(), newSize.y()));
  3218. -            }
  3219. -
  3220. -            // move center such that the static corner remains in the same place
  3221. -            if (m_buttonsOnRight) {
  3222. -                newCenter =  _k_rotatePoint(QPointF(rStaticPoint.x() + newSize.x()/2,
  3223. -                            rStaticPoint.y() - newSize.y()/2), m_angle);
  3224. -            } else {
  3225. -                newCenter =  _k_rotatePoint(QPointF(rStaticPoint.x() - newSize.x()/2,
  3226. -                            rStaticPoint.y() - newSize.y()/2), m_angle);
  3227. -            }
  3228. -
  3229. -            newAngle = m_angle;
  3230. -        }
  3231. -
  3232. -        // apply size
  3233. -        m_applet->resize(newSize.x(), newSize.y());
  3234. -        // apply position, no need if we're rotating
  3235. -        if (m_pressedButton != RotateButton) {
  3236. -            m_applet->setPos(m_containment->mapFromScene(newCenter - newSize/2));
  3237. -        }
  3238. -
  3239. -        // apply angle
  3240. -        QTransform at;
  3241. -        at.translate(newSize.x()/2, newSize.y()/2);
  3242. -        at.rotateRadians(newAngle);
  3243. -        at.translate(-newSize.x()/2, -newSize.y()/2);
  3244. -        m_applet->setTransform(at);
  3245. -        m_angle = newAngle;
  3246. -    } else {
  3247. -        QGraphicsItem::mouseMoveEvent(event);
  3248. -    }
  3249. -}
  3250. -
  3251. -bool AppletHandle::sceneEvent(QEvent *event)
  3252. -{
  3253. -    switch (event->type()) {
  3254. -    case QEvent::TouchEnd: {
  3255. -        QTransform t = m_applet->transform();
  3256. -        QRectF geom = m_applet->geometry();
  3257. -        QPointF translation(t.m31(), t.m32());
  3258. -        QPointF center = geom.center();
  3259. -        geom.setWidth(geom.width()*qAbs(t.m11()));
  3260. -        geom.setHeight(geom.height()*qAbs(t.m22()));
  3261. -        geom.moveCenter(center);
  3262. -
  3263. -        m_applet->setGeometry(geom);
  3264. -        t.reset();
  3265. -        t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
  3266. -        t.rotateRadians(m_angle);
  3267. -        t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
  3268. -
  3269. -
  3270. -        m_applet->setTransform(t);
  3271. -        return true;
  3272. -    }
  3273. -    case QEvent::TouchBegin:
  3274. -    case QEvent::TouchUpdate:
  3275. -    {
  3276. -        QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
  3277. -        if (touchPoints.count() == 2) {
  3278. -            const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
  3279. -            const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
  3280. -
  3281. -            //rotation
  3282. -            QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos());
  3283. -            QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos());
  3284. -            m_angle = m_angle+(line1.angleTo(line0)*M_PI_2/90);
  3285. -            QTransform t = m_applet->transform();
  3286. -            t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
  3287. -            t.rotate(line1.angleTo(line0));
  3288. -
  3289. -            //scaling
  3290. -            qreal scaleFactor = 1;
  3291. -            if (line0.length() > 0) {
  3292. -                scaleFactor = line1.length() / line0.length();
  3293. -            }
  3294. -
  3295. -            t.scale(scaleFactor, scaleFactor);
  3296. -            t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
  3297. -            m_applet->setTransform(t);
  3298. -
  3299. -        }
  3300. -        return true;
  3301. -    }
  3302. -    default:
  3303. -        break;
  3304. -    }
  3305. -    return QGraphicsItem::sceneEvent(event);
  3306. -}
  3307. -
  3308. -//pos relative to scene
  3309. -void AppletHandle::switchContainment(Containment *containment, const QPointF &pos)
  3310. -{
  3311. -    m_containment = containment;
  3312. -    Applet *applet = m_applet;
  3313. -    m_applet = 0; //make sure we don't try to act on the applet again
  3314. -    applet->removeSceneEventFilter(this);
  3315. -    forceDisappear(); //takes care of event filter and killing handle
  3316. -    applet->disconnect(this); //make sure the applet doesn't tell us to do anything
  3317. -    //applet->setZValue(m_zValue);
  3318. -    containment->addApplet(applet, containment->mapFromScene(pos), false);
  3319. -    deleteLater();
  3320. -}
  3321. -
  3322. -void AppletHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
  3323. -{
  3324. -    Q_UNUSED(event);
  3325. -    //kDebug() << "hover enter";
  3326. -
  3327. -    //if a disappear was scheduled stop the timer
  3328. -    if (m_leaveTimer->isActive()) {
  3329. -        m_leaveTimer->stop();
  3330. -    }
  3331. -    // if we're already fading out, fade back in
  3332. -    else if (!m_anim.data() && m_animType == FadeOut) {
  3333. -        startFading(FadeIn, m_entryPos, true);
  3334. -    }
  3335. -}
  3336. -
  3337. -void AppletHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
  3338. -{
  3339. -    hoverEnterEvent(event);
  3340. -}
  3341. -
  3342. -void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
  3343. -{
  3344. -    Q_UNUSED(event);
  3345. -
  3346. -    foreach (QWidget *widget, QApplication::topLevelWidgets()) {
  3347. -      QMenu *menu = qobject_cast<QMenu*>(widget);
  3348. -      if (menu && menu->isVisible()) {
  3349. -          connect(menu, SIGNAL(aboutToHide()), this, SLOT(leaveTimeout()));
  3350. -          return;
  3351. -      }
  3352. -    }
  3353. -
  3354. -
  3355. -    // if we haven't even showed up yet, remove the handle
  3356. -    if (m_hoverTimer->isActive()) {
  3357. -        m_hoverTimer->stop();
  3358. -        QTimer::singleShot(0, this, SLOT(emitDisappear()));
  3359. -    } else if (m_pressedButton != NoButton) {
  3360. -        m_pendingFade = true;
  3361. -    } else {
  3362. -        //wait a moment to hide the handle in order to recheck the mouse position
  3363. -        m_leaveTimer->start();
  3364. -    }
  3365. -}
  3366. -
  3367. -bool AppletHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
  3368. -{
  3369. -    if (watched == m_applet && event->type() == QEvent::GraphicsSceneHoverLeave) {
  3370. -        hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent*>(event));
  3371. -    }
  3372. -
  3373. -    return false;
  3374. -}
  3375. -
  3376. -void AppletHandle::setFadeAnimation(qreal progress)
  3377. -{
  3378. -    m_opacity = progress;
  3379. -    //kDebug() << "progress" << progress << "m_opacity" << m_opacity << m_anim << "(" << FadeIn << ")";
  3380. -    if (qFuzzyCompare(progress, qreal(1.0))) {
  3381. -        delete m_backgroundBuffer;
  3382. -        m_backgroundBuffer = 0;
  3383. -    }
  3384. -
  3385. -    update();
  3386. -}
  3387. -
  3388. -qreal AppletHandle::fadeAnimation() const
  3389. -{
  3390. -    return m_opacity;
  3391. -}
  3392. -
  3393. -void AppletHandle::hoverTimeout()
  3394. -{
  3395. -    startFading(FadeIn, m_entryPos);
  3396. -}
  3397. -
  3398. -void AppletHandle::leaveTimeout()
  3399. -{
  3400. -    if (!isUnderMouse()) {
  3401. -        startFading(FadeOut, m_entryPos);
  3402. -    }
  3403. -}
  3404. -
  3405. -void AppletHandle::appletDestroyed()
  3406. -{
  3407. -    m_applet = 0;
  3408. -}
  3409. -
  3410. -void AppletHandle::appletResized()
  3411. -{
  3412. -    prepareGeometryChange();
  3413. -    calculateSize();
  3414. -    update();
  3415. -}
  3416. -
  3417. -void AppletHandle::setHoverPos(const QPointF &hoverPos)
  3418. -{
  3419. -    m_entryPos = hoverPos;
  3420. -}
  3421. -
  3422. -void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide)
  3423. -{
  3424. -    QPropertyAnimation *propAnim = m_anim.data();
  3425. -
  3426. -    if (anim == FadeIn) {
  3427. -        if (propAnim) {
  3428. -            propAnim->stop();
  3429. -        } else {
  3430. -            propAnim = new QPropertyAnimation(this, "fadeAnimation", this);
  3431. -            m_anim = propAnim;
  3432. -        }
  3433. -    }
  3434. -
  3435. -    m_entryPos = hoverPos;
  3436. -    qreal time = 100;
  3437. -
  3438. -    if (!m_applet) {
  3439. -        m_animType = FadeOut;
  3440. -        setFadeAnimation(1.0);
  3441. -        return;
  3442. -    }
  3443. -
  3444. -    if (anim == FadeIn) {
  3445. -        //kDebug() << m_entryPos.x() << m_applet->pos().x();
  3446. -        prepareGeometryChange();
  3447. -        bool wasOnRight = m_buttonsOnRight;
  3448. -        if (!preserveSide) {
  3449. -            m_buttonsOnRight = m_entryPos.x() > (m_applet->size().width() / 2);
  3450. -        }
  3451. -        calculateSize();
  3452. -        QPolygonF region = m_applet->mapToParent(m_rect).intersected(m_applet->parentWidget()->boundingRect());
  3453. -        //kDebug() << region << m_rect << mapToParent(m_rect) << containmnet->boundingRect();
  3454. -        if (region != m_applet->mapToParent(m_rect)) {
  3455. -            // switch sides
  3456. -            //kDebug() << "switch sides";
  3457. -            m_buttonsOnRight = !m_buttonsOnRight;
  3458. -            calculateSize();
  3459. -            QPolygonF region2 = m_applet->mapToParent(m_rect).intersected(m_applet->parentWidget()->boundingRect());
  3460. -            if (region2 != mapToParent(m_rect)) {
  3461. -                // ok, both sides failed to be perfect... which one is more perfect?
  3462. -                QRectF f1 = region.boundingRect();
  3463. -                QRectF f2 = region2.boundingRect();
  3464. -                //kDebug() << "still not a perfect world"
  3465. -                //         << f2.width() << f2.height() << f1.width() << f1.height();
  3466. -                if ((f2.width() * f2.height()) < (f1.width() * f1.height())) {
  3467. -                    //kDebug() << "we did better the first time";
  3468. -                    m_buttonsOnRight = !m_buttonsOnRight;
  3469. -                    calculateSize();
  3470. -                }
  3471. -            }
  3472. -        }
  3473. -
  3474. -        if (wasOnRight != m_buttonsOnRight &&
  3475. -            m_animType == FadeIn &&
  3476. -            anim == FadeIn &&
  3477. -            m_opacity <= 1) {
  3478. -            m_opacity = 0.0;
  3479. -        }
  3480. -
  3481. -        time *= 1.0 - m_opacity;
  3482. -    } else {
  3483. -        time *= m_opacity;
  3484. -    }
  3485. -
  3486. -    if (propAnim) {
  3487. -        propAnim->setStartValue(0);
  3488. -        propAnim->setEndValue(1);
  3489. -        propAnim->setDuration(time);
  3490. -    }
  3491. -
  3492. -    m_animType = anim;
  3493. -    //kDebug() << "animating for " << time << "ms";
  3494. -    if (m_animType == FadeIn) {
  3495. -        propAnim->setDirection(QAbstractAnimation::Forward);
  3496. -        propAnim->start();
  3497. -    } else if (propAnim) {
  3498. -        propAnim->setDirection(QAbstractAnimation::Backward);
  3499. -        propAnim->start(QAbstractAnimation::DeleteWhenStopped);
  3500. -    }
  3501. -}
  3502. -
  3503. -void AppletHandle::forceDisappear()
  3504. -{
  3505. -    setAcceptsHoverEvents(false);
  3506. -    startFading(FadeOut, m_entryPos);
  3507. -}
  3508. -
  3509. -int AppletHandle::minimumHeight()
  3510. -{
  3511. -    int iconMargin = m_iconSize / 2;
  3512. -    int requiredHeight =  iconMargin  + //first margin
  3513. -                          (m_iconSize + iconMargin) * 4 + //XXX remember to update this if the number of buttons changes
  3514. -                          iconMargin ;  //blank space before the close button
  3515. -
  3516. -    if (m_applet && m_applet->hasConfigurationInterface()) {
  3517. -        requiredHeight += (m_iconSize + iconMargin);
  3518. -    }
  3519. -
  3520. -    return requiredHeight;
  3521. -}
  3522. -
  3523. -void AppletHandle::calculateSize()
  3524. -{
  3525. -    KIconLoader *iconLoader = KIconLoader::global();
  3526. -    //m_iconSize = iconLoader->currentSize(KIconLoader::Small); //does not work with double sized icon
  3527. -    m_iconSize = iconLoader->loadIcon("transform-scale", KIconLoader::Small).width(); //workaround
  3528. -
  3529. -    int handleHeight = qMax(minimumHeight(), int(m_applet->contentsRect().height() * 0.8));
  3530. -    int handleWidth = m_iconSize + 2 * HANDLE_MARGIN;
  3531. -    int top =
  3532. -        m_applet->contentsRect().top() + (m_applet->contentsRect().height() - handleHeight) / 2.0;
  3533. -
  3534. -    qreal marginLeft, marginTop, marginRight, marginBottom;
  3535. -    m_background->getMargins(marginLeft, marginTop, marginRight, marginBottom);
  3536. -
  3537. -    if (m_buttonsOnRight) {
  3538. -        //put the rect on the right of the applet
  3539. -        m_rect = QRectF(m_applet->size().width(), top, handleWidth, handleHeight);
  3540. -    } else {
  3541. -        //put the rect on the left of the applet
  3542. -        m_rect = QRectF(-handleWidth, top, handleWidth, handleHeight);
  3543. -    }
  3544. -
  3545. -    if (m_applet->contentsRect().height() > qreal(minimumHeight()) * 1.25) {
  3546. -        int addedMargin = marginLeft / 2;
  3547. -
  3548. -        // now we check to see if the shape is smaller than the contents,
  3549. -        // and that the shape is not just the bounding rect; in those cases
  3550. -        // we have a shaped guy and we draw a full panel;
  3551. -        // TODO: allow applets to mark when they have translucent areas and
  3552. -        //       should therefore skip this test?
  3553. -        if (!m_applet->shape().contains(m_applet->contentsRect())) {
  3554. -            QPainterPath p;
  3555. -            p.addRect(m_applet->boundingRect());
  3556. -            if (m_applet->shape() != p) {
  3557. -                addedMargin = m_applet->contentsRect().width() / 2;
  3558. -            }
  3559. -        }
  3560. -
  3561. -        if (m_buttonsOnRight) {
  3562. -            marginLeft += addedMargin;
  3563. -        } else {
  3564. -            marginRight += addedMargin;
  3565. -        }
  3566. -    }
  3567. -
  3568. -    //m_rect = m_applet->mapToParent(m_rect).boundingRect();
  3569. -    m_decorationRect = m_rect.adjusted(-marginLeft, -marginTop, marginRight, marginBottom);
  3570. -    m_totalRect = m_decorationRect.united(m_applet->boundingRect());
  3571. -}
  3572. -
  3573. -} // Plasma Namespace
  3574. -
  3575. -#include "applethandle_p.moc"
  3576. -
  3577. Index: private/configurecontrol.cpp
  3578. ===================================================================
  3579. --- private/configurecontrol.cpp    (revisione 0)
  3580. +++ private/configurecontrol.cpp    (revisione 0)
  3581. @@ -0,0 +1,46 @@
  3582. +/*
  3583. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  3584. + *
  3585. + *   This program is free software; you can redistribute it and/or modify
  3586. + *   it under the terms of the GNU Library General Public License as
  3587. + *   published by the Free Software Foundation; either version 2, or
  3588. + *   (at your option) any later version.
  3589. + *
  3590. + *   This program is distributed in the hope that it will be useful,
  3591. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  3592. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  3593. + *   GNU General Public License for more details
  3594. + *
  3595. + *   You should have received a copy of the GNU Library General Public
  3596. + *   License along with this program; if not, write to the
  3597. + *   Free Software Foundation, Inc.,
  3598. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  3599. + */
  3600. +
  3601. +#include "configurecontrol.h"
  3602. +
  3603. +namespace Plasma
  3604. +{
  3605. +
  3606. +ConfigureControl::ConfigureControl(QGraphicsWidget *widget)
  3607. +                : ControlElement(widget)
  3608. +{
  3609. +}
  3610. +
  3611. +ConfigureControl::~ConfigureControl()
  3612. +{
  3613. +}
  3614. +
  3615. +ControlElement::ElementType ConfigureControl::elementType() const
  3616. +{
  3617. +    return ControlElement::ConfigureElement;
  3618. +}
  3619. +
  3620. +void ConfigureControl::mouseClickEvent(QGraphicsSceneMouseEvent *)
  3621. +{
  3622. +    emit finished(ControlElement::ConfigureElement);
  3623. +}
  3624. +
  3625. +}
  3626. +
  3627. +#include "configurecontrol.moc"
  3628. Index: private/abstracthandle.h
  3629. ===================================================================
  3630. --- private/abstracthandle.h    (revisione 0)
  3631. +++ private/abstracthandle.h    (revisione 0)
  3632. @@ -0,0 +1,184 @@
  3633. +/*
  3634. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  3635. + *
  3636. + *   This program is free software; you can redistribute it and/or modify
  3637. + *   it under the terms of the GNU Library General Public License as
  3638. + *   published by the Free Software Foundation; either version 2, or
  3639. + *   (at your option) any later version.
  3640. + *
  3641. + *   This program is distributed in the hope that it will be useful,
  3642. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  3643. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  3644. + *   GNU General Public License for more details
  3645. + *
  3646. + *   You should have received a copy of the GNU Library General Public
  3647. + *   License along with this program; if not, write to the
  3648. + *   Free Software Foundation, Inc.,
  3649. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  3650. + */
  3651. +
  3652. +#ifndef ABSTRACTHANDLE_H
  3653. +#define ABSTRACTHANDLE_H
  3654. +
  3655. +#include <QtGui/QGraphicsObject>
  3656. +
  3657. +#include "controlelement.h"
  3658. +
  3659. +class QGraphicsView;
  3660. +
  3661. +namespace Plasma
  3662. +{
  3663. +
  3664. +class AbstractHandlePrivate;
  3665. +class Containment;
  3666. +
  3667. +/**
  3668. + * @class AbstractHandle plasma/private/abstracthandle.h
  3669. + *
  3670. + * @short The base Handle class
  3671. + *
  3672. + * AbstractHandle is a base class providing all the conveniences needed
  3673. + * to build an handle used by Plasma to provide the user a way to manage
  3674. + * the Applets and maybe other widgets inside the Containments.
  3675. + *
  3676. + * An AbstractHandle subclass has some Control Elements which do the actual
  3677. + * work of managing the widget. The handle takes care only of the eye-candy.
  3678. + *
  3679. + * A widget that wants to be managed by an handle must create some Control
  3680. + * Elements and must provide them through a property "controlElements"
  3681. + * returning a QList<ControlElement *>.
  3682. + */
  3683. +class AbstractHandle : public QGraphicsObject
  3684. +{
  3685. +    Q_OBJECT
  3686. +    Q_INTERFACES(QGraphicsItem)
  3687. +    public:
  3688. +        /**
  3689. +         * Describes where the handle will draw relative to the widget.
  3690. +         */
  3691. +        enum HandlePosition {
  3692. +            Top,         /**< It will be drawn on the top of the widget */
  3693. +            Right,       /**< It will be drawn on the right of the widget */
  3694. +            Bottom,      /**< It will be drawn on the bottom of the widget */
  3695. +            Left,        /**< It will be drawn on the left of the widget */
  3696. +            Over         /**< It will be drawn overthe widget, overlapping it */
  3697. +        };
  3698. +
  3699. +        /**
  3700. +         * Constructs an handle with the passed widget attached to it.
  3701. +         *
  3702. +         * @param containment the containment in which the widget is placed
  3703. +         * @param widget the widget that will be attached to this handle
  3704. +         */
  3705. +        AbstractHandle(Containment *containment, QGraphicsWidget *widget);
  3706. +
  3707. +        /**
  3708. +         * Default destructor.
  3709. +         */
  3710. +        virtual ~AbstractHandle();
  3711. +
  3712. +        /**
  3713. +         * Returns a pointer to the widget attached to this handle.
  3714. +         */
  3715. +        QGraphicsWidget *widget() const;
  3716. +
  3717. +        /**
  3718. +         * Returns a pointer to the containment the handle is working on.
  3719. +         */
  3720. +        Containment *containment() const;
  3721. +
  3722. +        /**
  3723. +         * Returns a list of the control elements of the attached widget.
  3724. +         *
  3725. +         * @see controlElement
  3726. +         */
  3727. +        QList<ControlElement *> controlElements() const;
  3728. +
  3729. +        /**
  3730. +         * Return the control element for the passed type. If there is no control element
  3731. +         * for that type it returns 0.
  3732. +         *
  3733. +         * @param type the type of the control element
  3734. +         *
  3735. +         * @see controlElements
  3736. +         */
  3737. +        ControlElement *controlElement(ControlElement::ElementType type) const;
  3738. +
  3739. +        /**
  3740. +         * Returns the location of the handle relative to the attached widget.
  3741. +         *
  3742. +         * @see setPosition
  3743. +         */
  3744. +        virtual HandlePosition position() const;
  3745. +
  3746. +        /**
  3747. +         * Move our widget to another containment.
  3748. +         *
  3749. +         * @param containment the containment to move to
  3750. +         * @param pos the (scene-relative) position to place it at
  3751. +         */
  3752. +        virtual void switchContainment(Containment *containment, const QPointF &pos);
  3753. +
  3754. +    protected:
  3755. +        /**
  3756. +         * Returns a control element based on the position passed.
  3757. +         * You must reimplement this in a subclass.
  3758. +         *
  3759. +         * @param pos the position where to look for contro elements
  3760. +         */
  3761. +        virtual ControlElement *controlElementAt(const QPointF &pos) const = 0;
  3762. +
  3763. +        /**
  3764. +         * Returns a pointer to a control element that received a mouse press,
  3765. +         * 0 otherwise.
  3766. +         */
  3767. +        ControlElement *pressedElement() const;
  3768. +
  3769. +        /**
  3770. +         * Sets the location where the handle will be painted.
  3771. +         *
  3772. +         * @see position
  3773. +         * @see HandlePosition
  3774. +         */
  3775. +        void setPosition(HandlePosition loc);
  3776. +
  3777. +        /**
  3778. +         * Reimplemented from QGraphicsItem.
  3779. +         */
  3780. +        virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
  3781. +
  3782. +        /**
  3783. +         * Reimplemented from QGraphicsItem.
  3784. +         */
  3785. +        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  3786. +
  3787. +        /**
  3788. +         * Reimplemented from QGraphicsItem.
  3789. +         */
  3790. +        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
  3791. +
  3792. +        /**
  3793. +         * Reimplemented from QGraphicsItem
  3794. +         */
  3795. +        virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
  3796. +
  3797. +        /**
  3798. +         * Reimplemented from QGraphicsItem.
  3799. +         */
  3800. +        virtual bool sceneEvent(QEvent *event);
  3801. +
  3802. +    Q_SIGNALS:
  3803. +        /**
  3804. +         * Emit this when you want the handle do die.
  3805. +         */
  3806. +        void disappearDone(AbstractHandle *self);
  3807. +
  3808. +    private:
  3809. +        AbstractHandlePrivate *const d;
  3810. +
  3811. +        Q_PRIVATE_SLOT(d, void widgetDestroyed())
  3812. +};
  3813. +
  3814. +};
  3815. +
  3816. +#endif // multiple inclusion guard
  3817. Index: private/maximizecontrol.h
  3818. ===================================================================
  3819. --- private/maximizecontrol.h   (revisione 0)
  3820. +++ private/maximizecontrol.h   (revisione 0)
  3821. @@ -0,0 +1,44 @@
  3822. +/*
  3823. + *   Copyright 2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
  3824. + *
  3825. + *   This program is free software; you can redistribute it and/or modify
  3826. + *   it under the terms of the GNU Library General Public License as
  3827. + *   published by the Free Software Foundation; either version 2, or
  3828. + *   (at your option) any later version.
  3829. + *
  3830. + *   This program is distributed in the hope that it will be useful,
  3831. + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  3832. + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  3833. + *   GNU General Public License for more details
  3834. + *
  3835. + *   You should have received a copy of the GNU Library General Public
  3836. + *   License along with this program; if not, write to the
  3837. + *   Free Software Foundation, Inc.,
  3838. + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  3839. + */
  3840. +
  3841. +#ifndef MAXIMIZECONTROL_H
  3842. +#define MAXIMIZECONTROL_H
  3843. +
  3844. +#include "controlelement.h"
  3845. +
  3846. +namespace Plasma
  3847. +{
  3848. +
  3849. +class MaximizeControl : public ControlElement
  3850. +{
  3851. +    Q_OBJECT
  3852. +    public:
  3853. +        MaximizeControl(QGraphicsWidget *widget);
  3854. +        virtual ~MaximizeControl();
  3855. +
  3856. +        ControlElement::ElementType elementType() const;
  3857. +
  3858. +    protected:
  3859. +        void mouseClickEvent(QGraphicsSceneMouseEvent *event);
  3860. +
  3861. +};
  3862. +
  3863. +};
  3864. +
  3865. +#endif // multiple inclusion guard
  3866. Index: containment.h
  3867. ===================================================================
  3868. --- containment.h   (revisione 1171409)
  3869. +++ containment.h   (copia locale)
  3870. @@ -42,7 +42,7 @@
  3871.  {
  3872.  
  3873.  class AccessAppletJob;
  3874. -class AppletHandle;
  3875. +class AbstractHandle;
  3876.  class DataEngine;
  3877.  class Package;
  3878.  class Corona;
  3879. @@ -632,7 +632,7 @@
  3880.          Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))
  3881.          Q_PRIVATE_SLOT(d, void appletAppearAnimationComplete())
  3882.          Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
  3883. -        Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
  3884. +        Q_PRIVATE_SLOT(d, void handleDisappeared(AbstractHandle *handle))
  3885.          Q_PRIVATE_SLOT(d, void positionToolBox())
  3886.          Q_PRIVATE_SLOT(d, void requestConfiguration())
  3887.          Q_PRIVATE_SLOT(d, void updateToolBoxVisibility())
  3888. Index: CMakeLists.txt
  3889. ===================================================================
  3890. --- CMakeLists.txt  (revisione 1171409)
  3891. +++ CMakeLists.txt  (copia locale)
  3892. @@ -113,7 +113,6 @@
  3893.      plasma.cpp
  3894.      popupapplet.cpp
  3895.      private/animablegraphicswebview.cpp
  3896. -    private/applethandle.cpp
  3897.      private/associatedapplicationmanager.cpp
  3898.      private/datacontainer_p.cpp
  3899.      private/dataengineconsumer.cpp
  3900. @@ -142,6 +141,15 @@
  3901.      private/kineticscroll.cpp
  3902.      private/effects/halopainter.cpp
  3903.      private/effects/ripple.cpp
  3904. +    private/abstracthandle.cpp
  3905. +    private/desktophandle.cpp
  3906. +    private/controlelement.cpp
  3907. +    private/configurecontrol.cpp
  3908. +    private/maximizecontrol.cpp
  3909. +    private/movecontrol.cpp
  3910. +    private/removecontrol.cpp
  3911. +    private/resizecontrol.cpp
  3912. +    private/rotatecontrol.cpp
  3913.      querymatch.cpp
  3914.      remote/accessmanager.cpp
  3915.      remote/accessappletjob.cpp
  3916. Index: containment.cpp
  3917. ===================================================================
  3918. --- containment.cpp (revisione 1171409)
  3919. +++ containment.cpp (copia locale)
  3920. @@ -63,10 +63,11 @@
  3921.  #include "remote/accessmanager.h"
  3922.  
  3923.  #include "private/applet_p.h"
  3924. -#include "private/applethandle_p.h"
  3925. +#include "private/desktophandle.h"
  3926.  #include "private/containmentactionspluginsconfig_p.h"
  3927.  #include "private/extenderitemmimedata_p.h"
  3928.  #include "private/extenderapplet_p.h"
  3929. +#include "private/abstracthandle.h"
  3930.  
  3931.  #include "plasma/plasma.h"
  3932.  #include "animations/animation.h"
  3933. @@ -751,10 +752,10 @@
  3934.                  break;
  3935.              }
  3936.          }
  3937. -        AppletHandle *handle = dynamic_cast<AppletHandle*>(item);
  3938. +        AbstractHandle *handle = dynamic_cast<AbstractHandle*>(item);
  3939.          if (handle) {
  3940.              //pretend it was on the applet
  3941. -            applet = handle->applet();
  3942. +            applet = qobject_cast<Applet*>(handle->widget());
  3943.              break;
  3944.          }
  3945.          item = item->parentItem();
  3946. @@ -1712,33 +1713,17 @@
  3947.          //kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability();
  3948.          if (immutability() == Mutable && applet->immutability() == Mutable) {
  3949.              QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
  3950. -            if (d->handles.contains(applet)) {
  3951. -                AppletHandle *handle = d->handles.value(applet);
  3952. -                if (handle) {
  3953. -                    handle->setHoverPos(he->pos());
  3954. -                }
  3955. -            } else {
  3956. +            if (!d->handles.contains(applet)) {
  3957.                  //kDebug() << "generated applet handle";
  3958. -                AppletHandle *handle = new AppletHandle(this, applet, he->pos());
  3959. +                AbstractHandle *handle = new DesktopHandle(this, applet, he->pos());
  3960.                  d->handles[applet] = handle;
  3961. -                connect(handle, SIGNAL(disappearDone(AppletHandle*)),
  3962. -                        this, SLOT(handleDisappeared(AppletHandle*)));
  3963. +                connect(handle, SIGNAL(disappearDone(AbstractHandle*)),
  3964. +                        this, SLOT(handleDisappeared(AbstractHandle*)));
  3965.                  connect(applet, SIGNAL(geometryChanged()),
  3966.                          handle, SLOT(appletResized()));
  3967.              }
  3968.          }
  3969.          break;
  3970. -    case QEvent::GraphicsSceneHoverMove:
  3971. -        if (immutability() == Mutable && applet->immutability() == Mutable) {
  3972. -            QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
  3973. -            if (d->handles.contains(applet)) {
  3974. -                AppletHandle *handle = d->handles.value(applet);
  3975. -                if (handle) {
  3976. -                    handle->setHoverPos(he->pos());
  3977. -                }
  3978. -            }
  3979. -        }
  3980. -        break;
  3981.      default:
  3982.          break;
  3983.      }
  3984. @@ -2197,11 +2182,10 @@
  3985.      emit q->showAddWidgetsInterface(QPointF());
  3986.  }
  3987.  
  3988. -void ContainmentPrivate::handleDisappeared(AppletHandle *handle)
  3989. +void ContainmentPrivate::handleDisappeared(AbstractHandle *handle)
  3990.  {
  3991. -    if (handles.contains(handle->applet())) {
  3992. -        handles.remove(handle->applet());
  3993. -        handle->detachApplet();
  3994. +    if (handles.contains(handle->widget())) {
  3995. +        handles.remove(handle->widget());
  3996.          QGraphicsScene *scene = q->scene();
  3997.          if (scene && handle->scene() == scene) {
  3998.              scene->removeItem(handle);
  3999. @@ -2237,10 +2221,10 @@
  4000.  
  4001.          //clear handles on lock
  4002.          if (!unlocked) {
  4003. -            QMap<Applet*, AppletHandle*> h = handles;
  4004. +            QMap<QGraphicsWidget*, AbstractHandle*> h = handles;
  4005.              handles.clear();
  4006.  
  4007. -            foreach (AppletHandle *handle, h) {
  4008. +            foreach (AbstractHandle *handle, h) {
  4009.                  handle->disconnect(q);
  4010.  
  4011.                  if (q->scene()) {
  4012. @@ -2334,7 +2318,7 @@
  4013.      }
  4014.  
  4015.      if (handles.contains(applet)) {
  4016. -        AppletHandle *handle = handles.value(applet);
  4017. +        AbstractHandle *handle = handles.value(applet);
  4018.          handles.remove(applet);
  4019.          if (q->scene()) {
  4020.              q->scene()->removeItem(handle);
  4021. Index: extenders/extender.cpp
  4022. ===================================================================
  4023. --- extenders/extender.cpp  (revisione 1171409)
  4024. +++ extenders/extender.cpp  (copia locale)
  4025. @@ -439,7 +439,7 @@
  4026.                  extenderApplet->formFactor() != Plasma::Vertical) {
  4027.                  kDebug() << "leaving the internal extender container, so hide the applet and it's handle.";
  4028.                  extenderApplet->hide();
  4029. -                AppletHandle *handle = dynamic_cast<AppletHandle*>(extenderApplet->parentItem());
  4030. +                AbstractHandle *handle = dynamic_cast<AbstractHandle*>(extenderApplet->parentItem());
  4031.                  if (handle) {
  4032.                      handle->hide();
  4033.                  }
  4034. Index: extenders/extenderitem.cpp
  4035. ===================================================================
  4036. --- extenders/extenderitem.cpp  (revisione 1171409)
  4037. +++ extenders/extenderitem.cpp  (copia locale)
  4038. @@ -49,7 +49,6 @@
  4039.  
  4040.  #include "widgets/iconwidget.h"
  4041.  
  4042. -#include "private/applethandle_p.h"
  4043.  #include "private/extender_p.h"
  4044.  #include "private/extenderapplet_p.h"
  4045.  #include "private/extendergroup_p.h"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement