• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeplasma-addons API Reference
  • KDE Home
  • Contact Us
 

GroupingDesktop

  • sources
  • kde-4.12
  • kdeplasma-addons
  • containments
  • groupingdesktop
  • lib
abstractgroup.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2010 by Giulio Camuffo <giuliocamuffo@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "abstractgroup.h"
21 #include "abstractgroup_p.h"
22 
23 #include <QtCore/QTimer>
24 #include <QtGui/QGraphicsView>
25 #include <QtGui/QGraphicsScene>
26 #include <QtGui/QGraphicsSceneResizeEvent>
27 
28 #include <KDE/KConfigDialog>
29 #include <KDE/KWindowSystem>
30 #include <kservice.h>
31 #include <kservicetypetrader.h>
32 
33 #include <Plasma/Containment>
34 #include <Plasma/FrameSvg>
35 #include <Plasma/Animator>
36 #include <Plasma/Animation>
37 
38 #include "groupingcontainment.h"
39 #include "freehandle.h"
40 
41 #include <cmath>
42 #include <math.h>
43 
44 AbstractGroupPrivate::AbstractGroupPrivate(AbstractGroup *group)
45  : q(group),
46  parentGroup(0),
47  destroying(false),
48  background(0),
49  immutability(Plasma::Mutable),
50  groupType(AbstractGroup::FreeGroup),
51  interestingGroup(0),
52  isMainGroup(false),
53  backgroundHints(AbstractGroup::NoBackground),
54  isLoading(true),
55  hasInterface(false),
56  simplerBackgroundChildren(false),
57  m_mainConfig(0)
58 {
59 
60 }
61 
62 AbstractGroupPrivate::~AbstractGroupPrivate()
63 {
64  delete m_mainConfig;
65 }
66 
67 KConfigGroup *AbstractGroupPrivate::mainConfigGroup()
68 {
69  if (m_mainConfig) {
70  return m_mainConfig;
71  }
72 
73  KConfigGroup containmentGroup = q->containment()->config();
74  KConfigGroup groupsConfig = KConfigGroup(&containmentGroup, "Groups");
75  m_mainConfig = new KConfigGroup(&groupsConfig, QString::number(id));
76 
77  return m_mainConfig;
78 }
79 
80 void AbstractGroupPrivate::destroyGroup()
81 {
82  mainConfigGroup()->deleteGroup();
83  emit q->configNeedsSaving();
84 
85  q->scene()->removeItem(q);
86  delete q;
87 }
88 
89 void AbstractGroupPrivate::startDestroyAnimation()
90 {
91  Plasma::Animation *zoomAnim = Plasma::Animator::create(Plasma::Animator::ZoomAnimation);
92  q->connect(zoomAnim, SIGNAL(finished()), q, SLOT(destroyGroup()));
93  zoomAnim->setTargetWidget(q);
94  zoomAnim->start();
95 }
96 
97 void AbstractGroupPrivate::appletDestroyed(Plasma::Applet *applet)
98 {
99  if (applets.contains(applet)) {
100  kDebug()<<"removed applet"<<applet->id()<<"from group"<<id<<"of type"<<q->pluginName();
101 
102  applets.removeAll(applet);
103 
104  emit q->appletRemovedFromGroup(applet, q);
105 
106  q->saveChildren();
107  emit q->configNeedsSaving();
108 
109  if (destroying && (q->children().count() == 0)) {
110  startDestroyAnimation();
111  destroying = false;
112  }
113  }
114 }
115 
116 void AbstractGroupPrivate::subGroupDestroyed(AbstractGroup *subGroup)
117 {
118  if (subGroups.contains(subGroup)) {
119  kDebug()<<"removed sub group"<<subGroup->id()<<"from group"<<id<<"of type"<<q->pluginName();
120 
121  subGroups.removeAll(subGroup);
122  KConfigGroup subGroupConfig = subGroup->config().parent();
123  KConfigGroup groupConfig(&subGroupConfig, QString("GroupInformation"));
124  groupConfig.deleteGroup();
125 
126  emit q->subGroupRemovedFromGroup(subGroup, q);
127 
128  q->saveChildren();
129  emit q->configNeedsSaving();
130 
131  if (destroying && (q->children().count() == 0)) {
132  startDestroyAnimation();
133  destroying = false;
134  }
135  }
136 }
137 
138 void AbstractGroupPrivate::addChild(QGraphicsWidget *child)
139 {
140  QPointF newPos = q->mapFromItem(child->parentItem(), child->pos());
141  if (groupType == AbstractGroup::ConstrainedGroup) {
142  child->setTransform(QTransform());
143  } else {
144  QTransform t(child->itemTransform(q));
145  if (t.m11() != 0) {
146  qreal angle = (t.m12() > 0 ? acos(t.m11()) : -acos(t.m11()));
147  QTransform at;
148  QSizeF size(child->size());
149  at.translate(size.width() / 2, size.height() / 2);
150  at.rotateRadians(angle);
151  at.translate(-size.width() / 2, -size.height() / 2);
152  child->setTransform(at);
153  newPos -= QPointF(at.dx(), at.dy());
154  }
155  }
156  child->setParentItem(q);
157  child->setProperty("group", QVariant::fromValue(q));
158  child->setPos(newPos);
159 
160  if (groupType == AbstractGroup::FreeGroup) {
161  q->connect(child, SIGNAL(geometryChanged()), q, SLOT(onChildGeometryChanged()));
162  }
163 }
164 
165 void AbstractGroupPrivate::removeChild(QGraphicsWidget *child)
166 {
167  QPointF newPos = child->scenePos();
168  QGraphicsItem *parent = q->parentItem();
169  QTransform t(child->itemTransform(parent));
170  if (t.m11() != 0) {
171  qreal angle = (t.m12() > 0 ? acos(t.m11()) : -acos(t.m11()));
172  QTransform at;
173  QSizeF size(child->size());
174  at.translate(size.width() / 2, size.height() / 2);
175  at.rotateRadians(angle);
176  at.translate(-size.width() / 2, -size.height() / 2);
177  child->setTransform(at);
178  }
179  child->setParentItem(parent);
180  child->setPos(parent->mapFromScene(newPos));
181 
182  child->disconnect(q);
183 }
184 
185 void AbstractGroupPrivate::restoreChildren()
186 {
187  q->restoreChildren();
188 
189  isLoading = false;
190  setBackground();
191  q->update();
192 }
193 
194 void AbstractGroupPrivate::onChildGeometryChanged()
195 {
196  q->saveChildren();
197  emit q->configNeedsSaving();
198 }
199 
200 QString AbstractGroupPrivate::configDialogId()
201 {
202  return QString("%1settings").arg(id);
203 }
204 
205 void AbstractGroupPrivate::setChildBorders(Plasma::Applet *a, bool added)
206 {
207  if (added) {
208  savedAppletsHints.insert(a, a->backgroundHints());
209  a->setBackgroundHints(Plasma::Applet::NoBackground);
210  } else {
211  if (savedAppletsHints.contains(a)) {
212  a->setBackgroundHints(savedAppletsHints.value(a));
213  }
214  }
215 }
216 
217 void AbstractGroupPrivate::setChildBorders(AbstractGroup *g, bool added)
218 {
219  if (added) {
220  savedGroupsHints.insert(g, g->backgroundHints());
221  g->setBackgroundHints(AbstractGroup::PlainBackground);
222  } else {
223  if (savedGroupsHints.contains(g)) {
224  g->setBackgroundHints(savedGroupsHints.value(g));
225  }
226  }
227 }
228 
229 void AbstractGroupPrivate::setBackground()
230 {
231  if ((backgroundHints & AbstractGroup::StandardBackground) ||
232  (backgroundHints & AbstractGroup::PlainBackground)) {
233  if (!background) {
234  background = new Plasma::FrameSvg(q);
235  background->setEnabledBorders(Plasma::FrameSvg::AllBorders);
236  }
237 
238  if (backgroundHints & AbstractGroup::StandardBackground) {
239  background->setImagePath("widgets/translucentbackground");
240  background->setElementPrefix(QString());
241  } else {
242  background->setImagePath("widgets/frame");
243  background->setElementPrefix("sunken");
244  }
245 
246  qreal left, top, right, bottom;
247  background->getMargins(left, top, right, bottom);
248  q->setContentsMargins(left, right, top, bottom);
249  background->resizeFrame(q->boundingRect().size());
250  } else if (background) {
251  delete background;
252  background = 0;
253  q->setContentsMargins(0, 0, 0, 0);
254  }
255 }
256 
257 //-----------------------------AbstractGroup------------------------------
258 
259 AbstractGroup::AbstractGroup(QGraphicsItem *parent, Qt::WindowFlags wFlags)
260  : QGraphicsWidget(parent, wFlags),
261  d(new AbstractGroupPrivate(this))
262 {
263 
264  setAcceptDrops(true);
265  setAcceptHoverEvents(true);
266  setContentsMargins(10, 10, 10, 10);
267  setBackgroundHints(StandardBackground);
268  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
269  setMinimumSize(20, 20);
270 }
271 
272 AbstractGroup::~AbstractGroup()
273 {
274  emit groupDestroyed(this);
275 
276  delete KConfigDialog::exists(d->configDialogId());
277  delete d;
278 }
279 
280 void AbstractGroup::init()
281 {
282 
283 }
284 
285 void AbstractGroup::setImmutability(Plasma::ImmutabilityType immutability)
286 {
287  if (!isMainGroup()) {
288  setFlag(QGraphicsItem::ItemIsMovable, immutability == Plasma::Mutable);
289  }
290  d->immutability = immutability;
291 
292  foreach (Plasma::Applet *applet, applets()) {
293  applet->setImmutability(immutability);
294  }
295  foreach (AbstractGroup *group, subGroups()) {
296  group->setImmutability(immutability);
297  }
298 
299  emit immutabilityChanged(immutability);
300 }
301 
302 Plasma::ImmutabilityType AbstractGroup::immutability() const
303 {
304  return d->immutability;
305 }
306 
307 uint AbstractGroup::id() const
308 {
309  return d->id;
310 }
311 
312 AbstractGroup *AbstractGroup::parentGroup() const
313 {
314  return d->parentGroup;
315 }
316 
317 void AbstractGroup::addApplet(Plasma::Applet *applet, bool layoutApplet)
318 {
319  if (!applet) {
320  return;
321  }
322 
323  if (applets().contains(applet)) {
324  if (applet->parentItem() != this) {
325  applet->setParentItem(this);
326  }
327 
328  return;
329  }
330 
331  QVariant pGroup = applet->property("group");
332  if (pGroup.isValid()) {
333  pGroup.value<AbstractGroup *>()->removeApplet(applet);
334  }
335 
336  kDebug()<<"adding applet"<<applet->id()<<"in group"<<id()<<"of type"<<pluginName();
337 
338  if (d->simplerBackgroundChildren) {
339  d->setChildBorders(applet, true);
340  }
341 
342  d->applets << applet;
343  d->addChild(applet);
344 
345  emit appletAddedInGroup(applet, this);
346 
347  if (layoutApplet) {
348  layoutChild(applet, applet->pos());
349 
350  save(*(d->mainConfigGroup()));
351  saveChildren();
352  emit configNeedsSaving();
353  }
354 
355  connect(applet, SIGNAL(appletDestroyed(Plasma::Applet*)),
356  this, SLOT(appletDestroyed(Plasma::Applet*)));
357 }
358 
359 void AbstractGroup::addSubGroup(AbstractGroup *group, bool layoutGroup)
360 {
361  if (!group) {
362  return;
363  }
364 
365  if (subGroups().contains(group)) {
366  if (group->parentItem() != this) {
367  group->setParentItem(this);
368  }
369 
370  return;
371  }
372 
373  AbstractGroup *parent = group->parentGroup();
374  if (parent) {
375  parent->removeSubGroup(group);
376  }
377 
378  kDebug()<<"adding sub group"<<group->id()<<"in group"<<id()<<"of type"<<pluginName();
379 
380  if (d->simplerBackgroundChildren) {
381  d->setChildBorders(group, true);
382  }
383 
384  group->d->parentGroup = this;
385  d->subGroups << group;
386  d->addChild(group);
387 
388  emit subGroupAddedInGroup(group, this);
389 
390  if (layoutGroup) {
391  layoutChild(group, group->pos());
392 
393  save(*(d->mainConfigGroup()));
394  saveChildren();
395  emit configNeedsSaving();
396  }
397 
398  connect(group, SIGNAL(groupDestroyed(AbstractGroup*)),
399  this, SLOT(subGroupDestroyed(AbstractGroup*)));
400 }
401 
402 Plasma::Applet::List AbstractGroup::applets() const
403 {
404  return d->applets;
405 }
406 
407 QList<AbstractGroup *> AbstractGroup::subGroups() const
408 {
409  return d->subGroups;
410 }
411 
412 QList<QGraphicsWidget *> AbstractGroup::children() const
413 {
414  QList<QGraphicsWidget *> list;
415  foreach (Plasma::Applet *applet, d->applets) {
416  list << applet;
417  }
418  foreach (AbstractGroup *group, d->subGroups) {
419  list << group;
420  }
421 
422  return list;
423 }
424 
425 void AbstractGroup::removeApplet(Plasma::Applet *applet, AbstractGroup *newGroup)
426 {
427  kDebug()<<"removing applet"<<applet->id()<<"from group"<<id()<<"of type"<<pluginName();
428 
429  if (d->simplerBackgroundChildren) {
430  d->setChildBorders(applet, false);
431  }
432 
433  d->applets.removeAll(applet);
434  KConfigGroup appletConfig = applet->config().parent();
435  KConfigGroup groupConfig(&appletConfig, QString("GroupInformation"));
436  groupConfig.deleteGroup();
437 
438  if (newGroup) {
439  newGroup->addApplet(applet);
440  } else {
441  d->removeChild(applet);
442  }
443 
444  emit appletRemovedFromGroup(applet, this);
445 
446  saveChildren();
447  emit configNeedsSaving();
448 }
449 
450 void AbstractGroup::removeSubGroup(AbstractGroup *subGroup, AbstractGroup *newGroup)
451 {
452  kDebug()<<"removing sub group"<<subGroup->id()<<"from group"<<id()<<"of type"<<pluginName();
453 
454  if (d->simplerBackgroundChildren) {
455  d->setChildBorders(subGroup, false);
456  }
457 
458  d->subGroups.removeAll(subGroup);
459  KConfigGroup subGroupConfig = subGroup->config().parent();
460  KConfigGroup groupConfig(&subGroupConfig, QString("GroupInformation"));
461  groupConfig.deleteGroup();
462 
463  if (newGroup) {
464  newGroup->addSubGroup(subGroup);
465  } else {
466  d->removeChild(subGroup);
467  subGroup->d->parentGroup = 0;
468  }
469 
470  emit subGroupRemovedFromGroup(subGroup, this);
471 
472  saveChildren();
473  emit configNeedsSaving();
474 }
475 
476 void AbstractGroup::destroy()
477 {
478  kDebug()<<"destroying group"<<id()<<"of type"<<pluginName();
479 
480  d->destroying = true;
481 
482  if (children().count() == 0) {
483  d->startDestroyAnimation();
484  return;
485  }
486 
487  foreach (AbstractGroup *group, subGroups()) {
488  group->destroy();
489  }
490  foreach (Plasma::Applet *applet, applets()) {
491  applet->destroy();
492  }
493 }
494 
495 QGraphicsView *AbstractGroup::view() const
496 {
497  // It's assumed that we won't be visible on more than one view here.
498  // Anything that actually needs view() should only really care about
499  // one of them anyway though.
500  if (!scene()) {
501  return 0;
502  }
503 
504  QGraphicsView *found = 0;
505  QGraphicsView *possibleFind = 0;
506  //kDebug() << "looking through" << scene()->views().count() << "views";
507  foreach (QGraphicsView *view, scene()->views()) {
508  //kDebug() << " checking" << view << view->sceneRect()
509  // << "against" << sceneBoundingRect() << scenePos();
510  if (view->sceneRect().intersects(sceneBoundingRect()) ||
511  view->sceneRect().contains(scenePos())) {
512  //kDebug() << " found something!" << view->isActiveWindow();
513  if (view->isActiveWindow()) {
514  found = view;
515  } else {
516  possibleFind = view;
517  }
518  }
519  }
520 
521  return found ? found : possibleFind;
522 }
523 
524 GroupingContainment *AbstractGroup::containment() const
525 {
526  QGraphicsItem *parent = parentItem();
527  GroupingContainment *c = 0;
528 
529  while (parent) {
530  GroupingContainment *possibleC = dynamic_cast<GroupingContainment *>(parent);
531  if (possibleC) {
532  c = possibleC;
533  break;
534  }
535  parent = parent->parentItem();
536  }
537 
538  return c;
539 }
540 
541 KConfigGroup AbstractGroup::config() const
542 {
543  KConfigGroup config = KConfigGroup(d->mainConfigGroup(), "Configuration");
544 
545  return config;
546 }
547 
548 void AbstractGroup::save(KConfigGroup &group) const
549 {
550  if (d->isLoading) {
551  return;
552  }
553 
554  if (!group.isValid()) {
555  group = *d->mainConfigGroup();
556  }
557 
558  group.writeEntry("zvalue", zValue());
559  group.writeEntry("plugin", pluginName());
560  group.writeEntry("geometry", geometry());
561 
562  if (transform() == QTransform()) {
563  group.deleteEntry("transform");
564  } else {
565  QList<qreal> m;
566  QTransform t = transform();
567  m << t.m11() << t.m12() << t.m13() << t.m21() << t.m22() << t.m23() << t.m31() << t.m32() << t.m33();
568  group.writeEntry("transform", m);
569  }
570 }
571 
572 void AbstractGroup::saveChildren() const
573 {
574  foreach (Plasma::Applet *applet, d->applets) {
575  KConfigGroup appletConfig = applet->config().parent();
576  KConfigGroup groupConfig(&appletConfig, QString("GroupInformation"));
577  groupConfig.writeEntry("Group", id());
578  saveChildGroupInfo(applet, groupConfig);
579  }
580  foreach (AbstractGroup *subGroup, d->subGroups) {
581  KConfigGroup subGroupConfig = subGroup->config().parent();
582  KConfigGroup groupConfig(&subGroupConfig, QString("GroupInformation"));
583  groupConfig.writeEntry("Group", id());
584  saveChildGroupInfo(subGroup, groupConfig);
585  }
586 }
587 
588 void AbstractGroup::restore(KConfigGroup &group)
589 {
590  QList<qreal> m = group.readEntry("transform", QList<qreal>());
591  if (m.count() == 9) {
592  QTransform t(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
593  setTransform(t);
594  }
595 
596  qreal z = group.readEntry("zvalue", 0);
597  QRectF geom = group.readEntry("geometry", QRectF());
598  setGeometry(geom);
599 
600  if (z > 0) {
601  setZValue(z);
602  }
603 }
604 
605 void AbstractGroup::restoreChildren()
606 {
607  foreach (Plasma::Applet *applet, d->applets) {
608  KConfigGroup appletConfig = applet->config().parent();
609  KConfigGroup groupConfig(&appletConfig, QString("GroupInformation"));
610  restoreChildGroupInfo(applet, groupConfig);
611  }
612  foreach (AbstractGroup *subGroup, d->subGroups) {
613  KConfigGroup subGroupConfig = subGroup->config().parent();
614  KConfigGroup groupConfig(&subGroupConfig, QString("GroupInformation"));
615  restoreChildGroupInfo(subGroup, groupConfig);
616  }
617 }
618 
619 bool AbstractGroup::showDropZone(const QPointF &pos)
620 {
621  Q_UNUSED(pos)
622 
623  //base implementation does nothing
624 
625  return true;
626 }
627 
628 void AbstractGroup::raise()
629 {
630  containment()->raise(this);
631 }
632 
633 Handle *AbstractGroup::createHandleForChild(QGraphicsWidget *child)
634 {
635  if (!children().contains(child)) {
636  return 0;
637  }
638 
639  Plasma::Applet *a = qobject_cast<Plasma::Applet *>(child);
640  if (a) {
641  return new FreeHandle(containment(), a);
642  }
643 
644  return new FreeHandle(containment(), static_cast<AbstractGroup *>(child));
645 }
646 
647 void AbstractGroup::setGroupType(AbstractGroup::GroupType type)
648 {
649  d->groupType = type;
650 }
651 
652 AbstractGroup::GroupType AbstractGroup::groupType() const
653 {
654  return d->groupType;
655 }
656 
657 void AbstractGroup::setIsMainGroup()
658 {
659  d->isMainGroup = true;
660  setBackgroundHints(AbstractGroup::NoBackground);
661  setFlag(QGraphicsItem::ItemIsMovable, false);
662  setZValue(0);
663  setContentsMargins(0, 0, 0, 0);
664 }
665 
666 bool AbstractGroup::isMainGroup() const
667 {
668  return d->isMainGroup;
669 }
670 
671 void AbstractGroup::setBackgroundHints(BackgroundHints hints)
672 {
673  if (d->backgroundHints == hints) {
674  return;
675  }
676 
677  d->backgroundHints = hints;
678  if (!d->isLoading) {
679  d->setBackground();
680  update();
681  }
682 }
683 
684 AbstractGroup::BackgroundHints AbstractGroup::backgroundHints() const
685 {
686  return d->backgroundHints;
687 }
688 
689 void AbstractGroup::setUseSimplerBackgroundForChildren(bool use)
690 {
691  if (d->simplerBackgroundChildren != use) {
692  foreach (Plasma::Applet *applet, d->applets) {
693  d->setChildBorders(applet, use);
694  }
695  foreach (AbstractGroup *group, d->subGroups) {
696  d->setChildBorders(group, use);
697  }
698 
699  d->simplerBackgroundChildren = use;
700  }
701 }
702 
703 bool AbstractGroup::useSimplerBackgroundForChildren() const
704 {
705  return d->simplerBackgroundChildren;
706 }
707 
708 void AbstractGroup::dragLeaveEvent(QGraphicsSceneDragDropEvent *)
709 {
710  showDropZone(QPointF());
711 }
712 
713 void AbstractGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
714 {
715  if (d->background) {
716  d->background->resizeFrame(event->newSize());
717  }
718 
719  if (!d->isLoading && !d->destroying) {
720  emit geometryChanged();
721 
722  save(*(d->mainConfigGroup()));
723  emit configNeedsSaving();
724  }
725 }
726 
727 void AbstractGroup::constraintsEvent(Plasma::Constraints)
728 {
729 
730 }
731 
732 int AbstractGroup::type() const
733 {
734  return Type;
735 }
736 
737 QVariant AbstractGroup::itemChange(GraphicsItemChange change, const QVariant &value)
738 {
739  switch (change) {
740  case ItemPositionHasChanged:
741  emit geometryChanged();
742 
743  case ItemTransformHasChanged: {
744  // invalid group, will result in save using the default group
745  KConfigGroup cg;
746  save(cg);
747  emit configNeedsSaving();
748  }
749  break;
750 
751  default:
752  break;
753  }
754 
755  return QGraphicsWidget::itemChange(change, value);
756 }
757 
758 void AbstractGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
759 {
760  Q_UNUSED(option);
761  Q_UNUSED(widget);
762 
763  if (d->backgroundHints == NoBackground || !d->background) {
764  return;
765  }
766 
767  if (sceneTransform().isRotating()) {
768  painter->setRenderHint(QPainter::SmoothPixmapTransform);
769  painter->setRenderHint(QPainter::Antialiasing);
770  }
771 
772  d->background->paintFrame(painter);
773 }
774 
775 void AbstractGroup::showConfigurationInterface()
776 {
777  KConfigDialog *dlg = KConfigDialog::exists(d->configDialogId());
778 
779  if (dlg) {
780  KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop());
781  dlg->show();
782  KWindowSystem::activateWindow(dlg->winId());
783  return;
784  }
785 
786  KConfigSkeleton *nullManager = new KConfigSkeleton(0);
787  KConfigDialog *dialog = new KConfigDialog(0, d->configDialogId(), nullManager);
788  dialog->setFaceType(KPageDialog::Auto);
789  dialog->setWindowTitle(i18n("Group Configuration"));
790  dialog->setAttribute(Qt::WA_DeleteOnClose, true);
791  createConfigurationInterface(dialog);
792  //TODO: Apply button does not correctly work for now, so do not show it
793  dialog->showButton(KDialog::Apply, false);
794  dialog->showButton(KDialog::Default, false);
795  QObject::connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater()));
796 
797  dialog->show();
798 }
799 
800 void AbstractGroup::createConfigurationInterface(KConfigDialog *)
801 {
802 
803 }
804 
805 bool AbstractGroup::hasConfigurationInterface() const
806 {
807  return d->hasInterface;
808 }
809 
810 void AbstractGroup::setHasConfigurationInterface(bool hasInterface)
811 {
812  d->hasInterface = hasInterface;
813 }
814 
815 void AbstractGroup::updateConstraints(Plasma::Constraints constraints)
816 {
817  if (constraints & Plasma::FormFactorConstraint) {
818  Plasma::FormFactor f = containment()->formFactor();
819  if (d->background && (f == Plasma::Vertical || f == Plasma::Horizontal)) {
820  if (backgroundHints() == AbstractGroup::StandardBackground) {
821  setBackgroundHints(AbstractGroup::PlainBackground);
822  }
823  }
824  }
825 
826  constraintsEvent(constraints);
827 }
828 
829 void AbstractGroup::releaseChild(QGraphicsWidget *)
830 {
831 
832 }
833 
834 QString AbstractGroup::mimeType()
835 {
836  return QString("plasma/group");
837 }
838 
839 AbstractGroup *AbstractGroup::load(const QString &name, QGraphicsItem *parent)
840 {
841  return GroupFactory::instance()->load(name, parent);
842 }
843 
844 QStringList AbstractGroup::availableGroups()
845 {
846  QStringList groups;
847 
848  foreach (const GroupInfo &gi, GroupFactory::instance()->groupInfos()) {
849  groups << gi.name();
850  }
851 
852  return groups;
853 }
854 
855 GroupInfo AbstractGroup::groupInfo(const QString &name)
856 {
857  foreach (const GroupInfo &gi, GroupFactory::instance()->groupInfos()) {
858  if (gi.name() == name) {
859  return gi;
860  }
861  }
862 
863  return GroupInfo("");
864 }
865 
866 #include "abstractgroup.moc"
AbstractGroup::applets
Plasma::Applet::List applets() const
Returns a list of the applets managed by this Group.
Definition: abstractgroup.cpp:402
AbstractGroup::FreeGroup
The applets can be freely transformed.
Definition: abstractgroup.h:58
AbstractGroup::itemChange
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Reimplemented from QGraphicsItem.
Definition: abstractgroup.cpp:737
AbstractGroup::~AbstractGroup
virtual ~AbstractGroup()
Default destructor.
Definition: abstractgroup.cpp:272
AbstractGroup::hasInterface
bool hasInterface
Definition: abstractgroup.h:46
groupingcontainment.h
AbstractGroup::id
uint id() const
Returns the id of this Group.
AbstractGroup::type
virtual int type() const
Definition: abstractgroup.cpp:732
AbstractGroup::setImmutability
void setImmutability(Plasma::ImmutabilityType immutability)
Sets the immutability type for this Group (not immutable, user immutable or system immutable) ...
Definition: abstractgroup.cpp:285
GroupingContainment::raise
void raise(QGraphicsWidget *widget)
Raises a widget above all the other Applets or Groups.
Definition: groupingcontainment.cpp:996
AbstractGroup::appletRemovedFromGroup
void appletRemovedFromGroup(Plasma::Applet *applet, AbstractGroup *group)
Emitted when an Applet is removed from this Group.
AbstractGroup::showConfigurationInterface
virtual void showConfigurationInterface()
Lets the user interact with the Group options.
Definition: abstractgroup.cpp:775
AbstractGroup::resizeEvent
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
Reimplemented from QGraphicsWidget.
Definition: abstractgroup.cpp:713
AbstractGroup::subGroupAddedInGroup
void subGroupAddedInGroup(AbstractGroup *subGroup, AbstractGroup *group)
Emitted when a Group is assigned to this Group.
AbstractGroup::addApplet
void addApplet(Plasma::Applet *applet, bool layoutApplet=true)
Adds an Applet to this Group.
Definition: abstractgroup.cpp:317
QWidget
AbstractGroup::setIsMainGroup
void setIsMainGroup()
Tells this Group it is a Main Group, causing it to: not paint a background; not be movable; not have ...
Definition: abstractgroup.cpp:657
Handle
Definition: handle.h:41
AbstractGroup::restoreChildren
virtual void restoreChildren()
Calls restoreChildGroupInfo for every child.
Definition: abstractgroup.cpp:605
AbstractGroup::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
Definition: abstractgroup.cpp:758
abstractgroup.h
AbstractGroup::immutability
Plasma::ImmutabilityType immutability() const
Returns the type of immutability of this Group.
Definition: abstractgroup.cpp:302
AbstractGroup::AbstractGroup
AbstractGroup(QGraphicsItem *parent=0, Qt::WindowFlags wFlags=0)
Constructor of the abstract class.
Definition: abstractgroup.cpp:259
AbstractGroup::setGroupType
void setGroupType(GroupType type)
Sets the type of this Group.
Definition: abstractgroup.cpp:647
AbstractGroup::load
static AbstractGroup * load(const QString &name, QGraphicsItem *parent=0)
Creates a new Group.
Definition: abstractgroup.cpp:839
AbstractGroup::groupInfo
static GroupInfo groupInfo(const QString &name)
Definition: abstractgroup.cpp:855
AbstractGroup::geometryChanged
void geometryChanged()
This signal is emitted when the Group's geometry changes.
AbstractGroup::pluginName
virtual QString pluginName() const =0
Returns the plugin name for the Group.
AbstractGroup::configNeedsSaving
void configNeedsSaving()
Emitted when a Group has changed values in its configuration and wishes for them to be saved at the n...
AbstractGroup::setBackgroundHints
void setBackgroundHints(BackgroundHints hint)
Sets the BackgroundHints for this Group.
Definition: abstractgroup.cpp:671
AbstractGroup::containment
GroupingContainment * containment() const
Returns a pointer to the containment this Group is displayed in.
Definition: abstractgroup.cpp:524
AbstractGroup::availableGroups
static QStringList availableGroups()
Returns a list of all identifiers of the available Groups.
Definition: abstractgroup.cpp:844
AbstractGroup::GroupType
GroupType
Defines if the applets inside the group can be freely transformed or not by the user.
Definition: abstractgroup.h:55
AbstractGroup::constraintsEvent
virtual void constraintsEvent(Plasma::Constraints constraints)
Called when any of the geometry constraints have been updated.
Definition: abstractgroup.cpp:727
AbstractGroup::appletAddedInGroup
void appletAddedInGroup(Plasma::Applet *applet, AbstractGroup *group)
Emitted when an Applet is assigned to this Group.
AbstractGroup::backgroundHints
BackgroundHints backgroundHints() const
Returns the BackgroundHints set for this Group.
Definition: abstractgroup.cpp:684
freehandle.h
AbstractGroup::createHandleForChild
virtual Handle * createHandleForChild(QGraphicsWidget *child)
Returns an handle for a child of this Group.
Definition: abstractgroup.cpp:633
AbstractGroup::parentGroup
AbstractGroup * parentGroup() const
Returns the Group that contains this one, 0 if there is no one.
Definition: abstractgroup.cpp:312
AbstractGroup::setHasConfigurationInterface
void setHasConfigurationInterface(bool hasInterface)
Sets whether or not this Group provides a user interface for configuring it.
Definition: abstractgroup.cpp:810
AbstractGroup::releaseChild
virtual void releaseChild(QGraphicsWidget *child)
Called when an Applet or a Group starts to be moved by the user.
Definition: abstractgroup.cpp:829
AbstractGroup::groupType
GroupType groupType() const
Returns the type of this Group.
AbstractGroup::PlainBackground
Draw a plain, simpler background.
Definition: abstractgroup.h:68
AbstractGroup::subGroups
QList< AbstractGroup * > subGroups() const
Returns a list of the groups managed by this Group.
Definition: abstractgroup.cpp:407
AbstractGroup::Type
Definition: abstractgroup.h:327
AbstractGroup::StandardBackground
Draw the translucent background from the theme.
Definition: abstractgroup.h:67
AbstractGroup::view
QGraphicsView * view() const
Returns the view this widget is visible on, or 0 if none can be found.
Definition: abstractgroup.cpp:495
AbstractGroup::ConstrainedGroup
The transformations of the applet are constrained by, e.g.
Definition: abstractgroup.h:56
AbstractGroup::raise
void raise()
Brings this Group on top of the other Groups and Applet.
Definition: abstractgroup.cpp:628
AbstractGroup::mimeType
static QString mimeType()
Definition: abstractgroup.cpp:834
AbstractGroup::isMainGroup
bool isMainGroup() const
Returns true if this Group is a MainGroup.
AbstractGroup::setUseSimplerBackgroundForChildren
void setUseSimplerBackgroundForChildren(bool use)
Sets whether or not this Group should make its children have a simpler background instead of the defa...
Definition: abstractgroup.cpp:689
AbstractGroup::saveChildren
virtual void saveChildren() const
Calls saveChildGroupInfo for every child.
Definition: abstractgroup.cpp:572
AbstractGroup::showDropZone
virtual bool showDropZone(const QPointF &pos)
Shows a visual clue for drag and drop The default implementation does nothing, reimplement it in grou...
Definition: abstractgroup.cpp:619
AbstractGroup::config
KConfigGroup config() const
Returns the KConfigGroup to access the Group configuration.
Definition: abstractgroup.cpp:541
AbstractGroup::init
virtual void init()
Method called a little after the constructor.
Definition: abstractgroup.cpp:280
AbstractGroup::hasConfigurationInterface
bool hasConfigurationInterface() const
Returns true if this Group provides a GUI configuration.
Definition: abstractgroup.cpp:805
AbstractGroup::immutabilityChanged
void immutabilityChanged(Plasma::ImmutabilityType immutability)
Emitted when the immutability changes.
GroupingContainment
The base Containment class.
Definition: groupingcontainment.h:38
AbstractGroup::removeApplet
void removeApplet(Plasma::Applet *applet, AbstractGroup *newGroup=0)
Removes an Applet from this Group.
Definition: abstractgroup.cpp:425
AbstractGroup::restore
virtual void restore(KConfigGroup &group)
Restore the state information about this Group.
Definition: abstractgroup.cpp:588
AbstractGroup::NoBackground
Don't draw anything.
Definition: abstractgroup.h:66
AbstractGroup::subGroupRemovedFromGroup
void subGroupRemovedFromGroup(AbstractGroup *subGroup, AbstractGroup *group)
Emitted when a Group is removed from this Group.
AbstractGroup::addSubGroup
void addSubGroup(AbstractGroup *group, bool layoutGroup=true)
Adds a Group to this Group.
Definition: abstractgroup.cpp:359
AbstractGroup::useSimplerBackgroundForChildren
bool useSimplerBackgroundForChildren() const
Returns true if this Group uses a simpler background for its children.
Definition: abstractgroup.cpp:703
AbstractGroup::layoutChild
virtual void layoutChild(QGraphicsWidget *child, const QPointF &pos)=0
Lays out a child inside the Group A sub class probably wants to reimplement this function.
AbstractGroup::children
QList< QGraphicsWidget * > children() const
Returns a list of all the children managed by this Group.
Definition: abstractgroup.cpp:412
AbstractGroup::id
uint id
Definition: abstractgroup.h:47
AbstractGroup::groupDestroyed
void groupDestroyed(AbstractGroup *group)
This signal is emitted when the Group's destructor is called.
AbstractGroup::destroy
void destroy()
Destroy this Groups and its children, deleting the configurations too.
Definition: abstractgroup.cpp:476
GroupInfo::name
QString name() const
Definition: groupinfo.cpp:67
GroupInfo
Definition: groupinfo.h:30
FreeHandle
Definition: freehandle.h:44
AbstractGroup
The base Group class.
Definition: abstractgroup.h:43
AbstractGroup::dragLeaveEvent
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented from QGraphicsItem.
Definition: abstractgroup.cpp:708
AbstractGroup::saveChildGroupInfo
virtual void saveChildGroupInfo(QGraphicsWidget *child, KConfigGroup config) const =0
Saves the group's specific configurations for a child.
AbstractGroup::save
virtual void save(KConfigGroup &group) const
Saves state information about this Group.
Definition: abstractgroup.cpp:548
AbstractGroup::updateConstraints
void updateConstraints(Plasma::Constraints constraints=Plasma::AllConstraints)
Called when any of the geometry constraints have been updated.
Definition: abstractgroup.cpp:815
AbstractGroup::restoreChildGroupInfo
virtual void restoreChildGroupInfo(QGraphicsWidget *child, const KConfigGroup &group)=0
Restores the group's specific configurations for a chils.
AbstractGroup::createConfigurationInterface
virtual void createConfigurationInterface(KConfigDialog *parent)
Reimplement this method to provide a configuration interface, parented to the supplied widget...
Definition: abstractgroup.cpp:800
AbstractGroup::removeSubGroup
void removeSubGroup(AbstractGroup *group, AbstractGroup *newGroup=0)
Removes a Group from this Group.
Definition: abstractgroup.cpp:450
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Oct 13 2014 22:55:03 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

kdeplasma-addons API Reference

Skip menu "kdeplasma-addons API Reference"
  •     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