• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • workspace API Reference
  • KDE Home
  • Contact Us
 

GroupingDesktop

  • sources
  • kde-4.14
  • workspace
  • kdeplasma-addons
  • containments
  • groupingdesktop
  • lib
handle.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2007 by Kevin Ottens <ervin@kde.org>
3  * Copyright 2009-2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Library General Public License as
7  * published by the Free Software Foundation; either version 2, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "handle.h"
22 
23 #include <QApplication>
24 #include <QtGui/QGraphicsSceneMouseEvent>
25 #include <QtGui/QLinearGradient>
26 #include <QtGui/QPainter>
27 #include <QtGui/QApplication>
28 #include <QtGui/QMenu>
29 #include <QTouchEvent>
30 
31 #include <kcolorscheme.h>
32 #include <kglobalsettings.h>
33 #include <kicon.h>
34 #include <kiconloader.h>
35 #include <kwindowsystem.h>
36 
37 #include <cmath>
38 #include <math.h>
39 
40 #include <Plasma/Corona>
41 #include <Plasma/PaintUtils>
42 #include <Plasma/Theme>
43 #include <Plasma/View>
44 #include <Plasma/FrameSvg>
45 
46 #include "abstractgroup.h"
47 #include "groupingcontainment.h"
48 
49 using namespace Plasma;
50 
51 Handle::Handle(GroupingContainment *parent, Plasma::Applet *applet)
52  : QGraphicsObject(applet),
53  m_containment(parent),
54  m_applet(applet),
55  m_group(0),
56  m_widget(applet),
57  m_currentView(applet->view())
58 {
59  setAcceptsHoverEvents(true);
60  setAcceptTouchEvents(true);
61 }
62 
63 Handle::Handle(GroupingContainment *parent, AbstractGroup *group)
64  : QGraphicsObject(group),
65  m_containment(parent),
66  m_applet(0),
67  m_group(group),
68  m_widget(group),
69  m_currentView(group->view())
70 {
71  setAcceptsHoverEvents(true);
72  setAcceptTouchEvents(true);
73 }
74 
75 Handle::~Handle()
76 {
77  detachWidget();
78 }
79 
80 QGraphicsWidget *Handle::widget() const
81 {
82  return m_widget;
83 }
84 
85 Plasma::Applet *Handle::applet() const
86 {
87  return m_applet;
88 }
89 
90 AbstractGroup *Handle::group() const
91 {
92  return m_group;
93 }
94 
95 GroupingContainment * Handle::containment() const
96 {
97  return m_containment;
98 }
99 
100 QGraphicsView *Handle::currentView() const
101 {
102  return m_currentView;
103 }
104 
105 void Handle::detachWidget()
106 {
107  if (!m_widget) {
108  return;
109  }
110 
111  m_widget->disconnect(this);
112 
113 // if (m_applet && (m_applet->geometry() != m_originalGeom || m_applet->transform() != m_originalTransform)) {
114 // emit m_applet->appletTransformedByUser(); //FIXME: protected!
115 // } else if (m_group && (m_group->geometry() != m_originalGeom || m_group->transform() != m_originalTransform)) {
116 // emit m_group->groupTransformedByUser();
117 // }
118 
119  m_applet = 0;
120  m_group = 0;
121  m_widget = 0;
122 }
123 
124 bool Handle::leaveCurrentView(const QPoint &pos) const
125 {
126  foreach (QWidget *widget, QApplication::topLevelWidgets()) {
127  if (widget->geometry().contains(pos)) {
128  //is this widget a plasma view, a different view then our current one,
129  //AND not a dashboardview?
130  Plasma::View *v = qobject_cast<Plasma::View *>(widget);
131  if (v && v != m_currentView && v->containment() != m_containment) {
132  return true;
133  }
134  }
135  }
136  return false;
137 }
138 
139 //pos relative to scene
140 void Handle::switchContainment(GroupingContainment *containment, const QPointF &pos)
141 {
142  m_containment = containment;
143  if (m_applet) {
144  Applet *applet = m_applet;
145  m_applet = 0; //make sure we don't try to act on the applet again
146  applet->removeSceneEventFilter(this);
147  setAcceptsHoverEvents(false);
148 // forceDisappear(); //takes care of event filter and killing handle
149  applet->disconnect(this); //make sure the applet doesn't tell us to do anything
150  //applet->setZValue(m_zValue);
151  containment->addApplet(applet, containment->mapFromScene(pos), false);
152  } else {
153  AbstractGroup *group = m_group;
154  m_group = 0; //make sure we don't try to act on the applet again
155  group->removeSceneEventFilter(this);
156  setAcceptsHoverEvents(false);
157 // forceDisappear(); //takes care of event filter and killing handle
158  group->disconnect(this); //make sure the applet doesn't tell us to do anything
159  //applet->setZValue(m_zValue);
160  containment->addGroup(group, containment->mapFromScene(pos));
161  }
162 
163  deleteLater();
164 }
165 
166 void Handle::widgetDestroyed()
167 {
168  m_applet = 0;
169  m_group = 0;
170  m_widget = 0;
171 }
172 
173 void Handle::setHoverPos(const QPointF &hoverPos)
174 {
175  if (!boundingRect().contains(hoverPos)) {
176  emit disappearDone(this);
177  }
178 }
179 
180 #include "handle.moc"
181 
QWidget
Handle::disappearDone
void disappearDone(Handle *self)
groupingcontainment.h
GroupingContainment::addGroup
AbstractGroup * addGroup(const QString &plugin, const QPointF &pos=QPointF(0, 0), int id=0)
Creates a new Group and it adds it to this Containment.
Definition: groupingcontainment.cpp:592
QGraphicsItem::setAcceptTouchEvents
void setAcceptTouchEvents(bool enabled)
Handle::detachWidget
virtual void detachWidget()
Definition: handle.cpp:105
Handle::setHoverPos
virtual void setHoverPos(const QPointF &hoverPos)
Definition: handle.cpp:173
QPoint
abstractgroup.h
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
Handle::containment
GroupingContainment * containment() const
Definition: handle.cpp:95
QWidget::geometry
geometry
QPointF
Handle::applet
Plasma::Applet * applet() const
Definition: handle.cpp:85
Handle::currentView
QGraphicsView * currentView() const
Definition: handle.cpp:100
handle.h
Handle::group
AbstractGroup * group() const
Definition: handle.cpp:90
Handle::switchContainment
void switchContainment(GroupingContainment *containment, const QPointF &pos)
move our widget to another containment
Definition: handle.cpp:140
Handle::Handle
Handle(GroupingContainment *parent, Plasma::Applet *applet)
Definition: handle.cpp:51
QGraphicsWidget
QGraphicsItem::removeSceneEventFilter
void removeSceneEventFilter(QGraphicsItem *filterItem)
QObject::deleteLater
void deleteLater()
Handle::widget
QGraphicsWidget * widget() const
Definition: handle.cpp:80
QGraphicsObject
QGraphicsItem::setAcceptsHoverEvents
void setAcceptsHoverEvents(bool enabled)
Handle::leaveCurrentView
bool leaveCurrentView(const QPoint &pos) const
Definition: handle.cpp:124
GroupingContainment
The base Containment class.
Definition: groupingcontainment.h:38
QGraphicsItem::boundingRect
virtual QRectF boundingRect() const =0
Handle::~Handle
virtual ~Handle()
Definition: handle.cpp:75
AbstractGroup
The base Group class.
Definition: abstractgroup.h:43
QGraphicsItem::contains
virtual bool contains(const QPointF &point) const
QGraphicsView
QApplication::topLevelWidgets
QWidgetList topLevelWidgets()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GroupingDesktop

Skip menu "GroupingDesktop"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

workspace API Reference

Skip menu "workspace API Reference"
  • kdeplasma-addons
  •       GroupingDesktop
  •     liblancelot

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal