NCL Composer  0.1.5
 All Classes Functions Variables Pages
qnlygraphicsregion.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "qnlygraphicsregion.h"
19 
20 #include <QCursor>
21 
22 QnlyGraphicsRegion::QnlyGraphicsRegion(QMenu* switchMenu,
23  QnlyGraphicsRegion* parent)
24  : QObject(parent), QGraphicsItem(parent)
25 {
26  this->switchMenu = switchMenu;
27 
28  this->switchMenu->setEnabled(true);
29 
30  /* creating */
31  createActions();
32  createMenus();
33  createConnections();
34 
35  /* setting defaults */
36  setFlag(QGraphicsItem::ItemIsMovable, true);
37  setFlag(QGraphicsItem::ItemIsFocusable, true);
38 
39  setMoving(false);
40  setResizing(false);
41  setSelected(false);
42 
43  setValidated(true);
44 
45  setId("");
46  setUid("");
47  setTitle("");
48 
49  setRelativeTop(0);
50  setRelativeLeft(0);
51  setRelativeRight(0);
52  setRelativeBottom(0);
53 
54  setRelativeWidth(1);
55  setRelativeHeight(1);
56 
57  setzIndex(-1);
58  setzIndexTop(0);
59 
60  setColor("#E4E4E4");
61 }
62 
63 QnlyGraphicsRegion::~QnlyGraphicsRegion()
64 {
65  delete(viewMenu);
66  delete(insertMenu);
67  delete(arrangeMenu);
68  delete(contextMenu);
69 }
70 
71 bool QnlyGraphicsRegion::isMoving() const
72 {
73  return moving;
74 }
75 
76 void QnlyGraphicsRegion::setParent(QnlyGraphicsRegion* region)
77 {
78  QObject::setParent(region);
79  setParentItem(region);
80 }
81 
82 void QnlyGraphicsRegion::setMoving(bool moving)
83 {
84  this->moving = moving;
85  if(moving)
86  setCursor(QCursor(Qt::ClosedHandCursor));
87  else
88  setCursor(QCursor(Qt::ArrowCursor));
89 }
90 
91 bool QnlyGraphicsRegion::isResizing() const
92 {
93  return resizing;
94 }
95 
96 void QnlyGraphicsRegion::setResizing(bool resizing)
97 {
98  this->resizing = resizing;
99 }
100 
101 bool QnlyGraphicsRegion::isSelected() const
102 {
103  return selected;
104 }
105 
106 void QnlyGraphicsRegion::setSelected(bool selected)
107 {
108  this->selected = selected;
109 
110  if(this->selected)
111  setFocus(Qt::MouseFocusReason);
112 }
113 
114 bool QnlyGraphicsRegion::isValidated() const
115 {
116  return validated;
117 }
118 
119 void QnlyGraphicsRegion::setValidated(bool validated)
120 {
121  this->validated = validated;
122 }
123 
124 QString QnlyGraphicsRegion::getId() const
125 {
126  return id;
127 }
128 
129 void QnlyGraphicsRegion::setId(const QString &id)
130 {
131  this->id = id;
132 
133  setToolTip(title+" "+"("+id+")");
134 
135  if (parentItem() != NULL)
136  {
137  QnlyGraphicsRegion* parent = (QnlyGraphicsRegion*) parentItem();
138  parent->updateActionText(this);
139  }
140  else
141  {
143 
144  if(s != NULL)
145  s->updateActionText(this);
146  }
147 }
148 
149 QString QnlyGraphicsRegion::getUid() const
150 {
151  return uid;
152 }
153 
154 void QnlyGraphicsRegion::setUid(const QString &uid)
155 {
156  this->uid = uid;
157 }
158 
159 QString QnlyGraphicsRegion::getTitle() const
160 {
161  return title;
162 }
163 
164 void QnlyGraphicsRegion::setTitle(const QString &title)
165 {
166  this->title = title;
167 
168  setToolTip(title+" "+"("+id+")");
169 }
170 
171 QString QnlyGraphicsRegion::getColor() const
172 {
173  return color;
174 }
175 
176 void QnlyGraphicsRegion::setColor(const QString &color)
177 {
178  this->color = color;
179 }
180 
181 bool QnlyGraphicsRegion::isPainted() const
182 {
183  return painted;
184 }
185 
186 void QnlyGraphicsRegion::setPainted(bool painted)
187 {
188  this->painted = painted;
189 }
190 
191 void QnlyGraphicsRegion::setzIndex(int zindex)
192 {
193  this->zindex = zindex;
194 
195  setZValue(zindex);
196 }
197 
198 int QnlyGraphicsRegion::getzIndex() const
199 {
200  return zindex;
201 }
202 
203 void QnlyGraphicsRegion::setzIndexTop(qreal zindexTop)
204 {
205  this->zindexTop = zindexTop;
206 }
207 
208 qreal QnlyGraphicsRegion::getzIndexTop() const
209 {
210  return zindexTop;
211 }
212 
213 qreal QnlyGraphicsRegion::getTop() const
214 {
215  return top;
216 }
217 
218 void QnlyGraphicsRegion::setTop(qreal top)
219 {
220  this->top = top;
221 
222  setY(top-4);
223 }
224 
225 qreal QnlyGraphicsRegion::getMoveTop() const
226 {
227  return moveTop;
228 }
229 
230 void QnlyGraphicsRegion::setMoveTop(qreal moveTop)
231 {
232  this->moveTop = moveTop;
233 }
234 
235 qreal QnlyGraphicsRegion::getPressTop() const
236 {
237  return pressTop;
238 }
239 
240 void QnlyGraphicsRegion::setPressTop(qreal pressTop)
241 {
242  this->pressTop = pressTop;
243 }
244 
245 qreal QnlyGraphicsRegion::getResizeTop() const
246 {
247  return resizeTop;
248 }
249 
250 void QnlyGraphicsRegion::setResizeTop(qreal resizeTop)
251 {
252  this->resizeTop = resizeTop;
253 }
254 
255 qreal QnlyGraphicsRegion::getRelativeTop() const
256 {
257  return relativeTop;
258 }
259 
260 void QnlyGraphicsRegion::setRelativeTop(qreal relativeTop)
261 {
262  this->relativeTop = relativeTop;
263 }
264 
265 qreal QnlyGraphicsRegion::getLeft() const
266 {
267  return left;
268 }
269 
270 void QnlyGraphicsRegion::setLeft(qreal left)
271 {
272  this->left = left;
273 
274  setX(left-4);
275 }
276 
277 qreal QnlyGraphicsRegion::getMoveLeft() const
278 {
279  return moveLeft;
280 }
281 
282 void QnlyGraphicsRegion::setMoveLeft(qreal moveLeft)
283 {
284  this->moveLeft = moveLeft;
285 }
286 
287 qreal QnlyGraphicsRegion::getPressLeft() const
288 {
289  return pressLeft;
290 }
291 
292 void QnlyGraphicsRegion::setPressLeft(qreal pressLeft)
293 {
294  this->pressLeft = pressLeft;
295 }
296 
297 qreal QnlyGraphicsRegion::getResizeLeft() const
298 {
299  return resizeLeft;
300 }
301 
302 void QnlyGraphicsRegion::setResizeLeft(qreal resizeLeft)
303 {
304  this->resizeLeft = resizeLeft;
305 }
306 
307 qreal QnlyGraphicsRegion::getRelativeLeft() const
308 {
309  return relativeLeft;
310 }
311 
312 void QnlyGraphicsRegion::setRelativeLeft(qreal relativeLeft)
313 {
314  this->relativeLeft = relativeLeft;
315 }
316 
317 qreal QnlyGraphicsRegion::getRight() const
318 {
319  return right;
320 }
321 
322 void QnlyGraphicsRegion::setRight(qreal right)
323 {
324  this->right = right;
325 }
326 
327 qreal QnlyGraphicsRegion::getRelativeRight() const
328 {
329  return relativeRight;
330 }
331 
332 void QnlyGraphicsRegion::setRelativeRight(qreal relativeRight)
333 {
334  this->relativeRight = relativeRight;
335 }
336 
337 qreal QnlyGraphicsRegion::getBottom() const
338 {
339  return bottom;
340 }
341 
342 void QnlyGraphicsRegion::setBottom(qreal bottom)
343 {
344  this->bottom = bottom;
345 }
346 
347 qreal QnlyGraphicsRegion::getRelativeBottom() const
348 {
349  return relativeBottom;
350 }
351 
352 void QnlyGraphicsRegion::setRelativeBottom(qreal relativeBottom)
353 {
354  this->relativeBottom = relativeBottom;
355 }
356 
357 qreal QnlyGraphicsRegion::getWidth() const
358 {
359  return width;
360 }
361 
362 void QnlyGraphicsRegion::setWidth(qreal width)
363 {
364  this->width = width;
365 }
366 
367 qreal QnlyGraphicsRegion::getPressWidth() const
368 {
369  return pressWidth;
370 }
371 
372 void QnlyGraphicsRegion::setPressWidth(qreal pressWidth)
373 {
374  this->pressWidth = pressWidth;
375 }
376 
377 qreal QnlyGraphicsRegion::getResizeWidth() const
378 {
379  return resizeWidth;
380 }
381 
382 bool QnlyGraphicsRegion::hasChanged() const
383 {
384  return changed;
385 }
386 
387 void QnlyGraphicsRegion::setChanged(bool changed)
388 {
389  this->changed = changed;
390 }
391 
392 void QnlyGraphicsRegion::setResizeWidth(qreal resizeWidth)
393 {
394  this->resizeWidth = resizeWidth;
395 }
396 
397 qreal QnlyGraphicsRegion::getRelativeWidth() const
398 {
399  return relativeWidth;
400 }
401 
402 void QnlyGraphicsRegion::setRelativeWidth(qreal relativeWidth)
403 {
404  this->relativeWidth = relativeWidth;
405 }
406 
407 qreal QnlyGraphicsRegion::getHeight() const
408 {
409  return height;
410 }
411 
412 void QnlyGraphicsRegion::setHeight(qreal height)
413 {
414  this->height = height;
415 }
416 
417 qreal QnlyGraphicsRegion::getPressHeight() const
418 {
419  return pressHeight;
420 }
421 
422 void QnlyGraphicsRegion::setPressHeight(qreal pressHeight)
423 {
424  this->pressHeight = pressHeight;
425 }
426 
427 qreal QnlyGraphicsRegion::getResizeHeight() const
428 {
429  return resizeHeight;
430 }
431 
432 void QnlyGraphicsRegion::setResizeHeight(qreal resizeHeight)
433 {
434  this->resizeHeight = resizeHeight;
435 }
436 
437 qreal QnlyGraphicsRegion::getRelativeHeight() const
438 {
439  return relativeHeight;
440 }
441 
442 void QnlyGraphicsRegion::setRelativeHeight(qreal relativeHeight)
443 {
444  this->relativeHeight = relativeHeight;
445 }
446 
447 QnlyGraphicsRegion::QnlyResizeType QnlyGraphicsRegion::getResizeType() const
448 {
449  return resizeType;
450 }
451 
452 void QnlyGraphicsRegion::setResizeType(const QnlyResizeType &resizeType)
453 {
454  this->resizeType = resizeType;
455 }
456 
457 void QnlyGraphicsRegion::QnlyGraphicsRegion::createActions()
458 {
459  // help action
460  helpAction = new QAction(this);
461  helpAction->setText(tr("Help"));
462 
463  helpAction->setEnabled(false);
464  helpAction->setShortcut(QKeySequence("F1"));
465 
466  // undo action
467  undoAction = new QAction(this);
468  undoAction->setText(tr("Undo"));
469 
470  undoAction->setEnabled(false);
471  undoAction->setShortcut(QKeySequence("Ctrl+Z"));
472 
473  // redo action
474  redoAction = new QAction(this);
475  redoAction->setText(tr("Redo"));
476 
477  redoAction->setEnabled(false);
478  redoAction->setShortcut(QKeySequence("Ctrl+Shift+Z"));
479 
480  // cut action
481  cutAction = new QAction(this);
482  cutAction->setText(tr("Cut"));
483 
484  cutAction->setEnabled(false);
485  cutAction->setShortcut(QKeySequence("Ctrl+X"));
486 
487  // copy action
488  copyAction = new QAction(this);
489  copyAction->setText(tr("Copy"));
490 
491  copyAction->setEnabled(false);
492  copyAction->setShortcut(QKeySequence("Ctrl+C"));
493 
494  // paste action
495  pasteAction = new QAction(this);
496  pasteAction->setText(tr("Paste"));
497 
498  pasteAction->setEnabled(false);
499  pasteAction->setShortcut(QKeySequence("Ctrl+V"));
500 
501  // delete action
502  deleteAction = new QAction(this);
503  deleteAction->setText(tr("Delete"));
504 
505  deleteAction->setEnabled(true);
506  deleteAction->setShortcut(QKeySequence("Del"));
507 
508  // zoomin action
509  zoominAction = new QAction(this);
510  zoominAction->setText(tr("Zoom In"));
511 
512  zoominAction->setEnabled(true);
513  zoominAction->setShortcut(QKeySequence("Ctrl++"));
514 
515  // zoomout action
516  zoomoutAction = new QAction(this);
517  zoomoutAction->setText(tr("Zoom Out"));
518 
519  zoomoutAction->setEnabled(true);
520  zoomoutAction->setShortcut(QKeySequence("Ctrl+-"));
521 
522  // reset action
523  zoomresetAction = new QAction(this);
524  zoomresetAction->setText(tr("Reset"));
525 
526  zoomresetAction->setEnabled(true);
527  zoomresetAction->setShortcut(QKeySequence("Ctrl+0"));
528 
529  // fullscreen action
530  fullscreenAction = new QAction(this);
531  fullscreenAction->setText(tr("Full Screen"));
532 
533  fullscreenAction->setEnabled(true);
534  fullscreenAction->setShortcut(QKeySequence("F11"));
535 
536  // export action
537  exportAction = new QAction(this);
538  exportAction->setText(tr("Export..."));
539 
540  exportAction->setEnabled(true);
541 
542  // region action
543  regionAction = new QAction(this);
544  regionAction->setText(tr("Region"));
545 
546  regionAction->setEnabled(true);
547 
548  // regionbase action
549  regionbaseAction = new QAction(this);
550  regionbaseAction->setText(tr("Regionbase"));
551 
552  regionbaseAction->setEnabled(true);
553 
554  // bring to front action
555  bringfrontAction = new QAction(this);
556  bringfrontAction->setText(tr("Bring to Front"));
557 
558  bringfrontAction->setEnabled(false);
559  bringfrontAction->setShortcut(QKeySequence("Shift+Ctrl+]"));
560 
561  // bring forward action
562  bringforwardAction = new QAction(this);
563  bringforwardAction->setText(tr("Bring Forward"));
564 
565  bringforwardAction->setEnabled(false);
566  bringforwardAction->setShortcut(QKeySequence("Ctrl+]"));
567 
568  // send backward action
569  sendbackwardAction = new QAction(this);
570  sendbackwardAction->setText(tr("Send Backward"));
571 
572  sendbackwardAction->setEnabled(false);
573  sendbackwardAction->setShortcut(QKeySequence("Ctrl+["));
574 
575  // send to back action
576  sendbackAction = new QAction(this);
577  sendbackAction->setText(tr("Send to Back"));
578 
579  sendbackAction->setEnabled(false);
580  sendbackAction->setShortcut(QKeySequence("Shift+Ctrl+["));
581 
582  // hide action
583  hideAction = new QAction(this);
584  hideAction->setText(tr("Hide"));
585 
586  hideAction->setEnabled(true);
587 
588  // properties action
589  propertiesAction = new QAction(this);
590  propertiesAction->setText(tr("Properties"));
591 
592  propertiesAction->setEnabled(true);
593 
594  regionActionGroup = new QActionGroup(this);
595  regionActionGroup->setExclusive(false);
596 
597  setAcceptDrops(true);
598 }
599 
600 void QnlyGraphicsRegion::setGridAction(QAction* action)
601 {
602  gridAction = action;
603 
604  showMenu->addAction(gridAction);
605 
606 }
607 
608 void QnlyGraphicsRegion::createMenus()
609 {
610  // view menu
611  viewMenu = new QMenu();
612  viewMenu->setTitle(tr("View"));
613 
614  viewMenu->setEnabled(true);
615 
616  viewMenu->addAction(zoominAction);
617  viewMenu->addAction(zoomoutAction);
618  viewMenu->addAction(zoomresetAction);
619  viewMenu->addSeparator();
620  viewMenu->addAction(fullscreenAction);
621 
622  // insert menu
623  insertMenu = new QMenu();
624  insertMenu->setTitle(tr("Insert"));
625 
626  insertMenu->setEnabled(true);
627 
628  insertMenu->addAction(regionAction);
629  insertMenu->addAction(regionbaseAction);
630 
631  // show menu
632  showMenu = new QMenu();
633  showMenu->setTitle(tr("Show"));
634 
635  showMenu->setEnabled(true);
636 
637  // arrange menu
638  arrangeMenu = new QMenu();
639  arrangeMenu->setTitle(tr("Arrange"));
640 
641  arrangeMenu->setEnabled(false);
642 
643  arrangeMenu->addAction(bringfrontAction);
644  arrangeMenu->addAction(bringforwardAction);
645  arrangeMenu->addAction(sendbackwardAction);
646  arrangeMenu->addAction(sendbackAction);
647 
648  // context menu
649  contextMenu = new QMenu();
650  contextMenu->addAction(helpAction);
651  contextMenu->addSeparator();
652  // contextMenu->addAction(undoAction);
653  // contextMenu->addAction(redoAction);
654  // contextMenu->addSeparator();
655  // contextMenu->addAction(cutAction);
656  // contextMenu->addAction(copyAction);
657  // contextMenu->addAction(pasteAction);
658  // contextMenu->addSeparator();
659  contextMenu->addAction(deleteAction);
660  contextMenu->addSeparator();
661  contextMenu->addAction(exportAction);
662  contextMenu->addSeparator();
663  // contextMenu->addMenu(viewMenu); // disabled for while
664  contextMenu->addMenu(insertMenu);
665  contextMenu->addMenu(showMenu);
666  // contextMenu->addMenu(arrangeMenu); // disabled for while
667  contextMenu->addSeparator();
668  contextMenu->addAction(hideAction);
669  contextMenu->addSeparator();
670  contextMenu->addMenu(switchMenu);
671  // contextMenu->addSeparator(); //disabled for now
672  // contextMenu->addAction(propertiesAction); //disabled for now
673 }
674 
675 void QnlyGraphicsRegion::createConnections()
676 {
677  connect(regionActionGroup, SIGNAL(triggered(QAction*)),
678  SLOT(performShow(QAction*)));
679 
680  connect(regionbaseAction, SIGNAL(triggered()),
681  SIGNAL(regionbasePerformed()));
682 
683  connect(regionAction, SIGNAL(triggered()),
684  SLOT(performRegion()));
685 
686  connect(hideAction, SIGNAL(triggered()),
687  SLOT(performHide()));
688 
689  connect(deleteAction, SIGNAL(triggered()),
690  SLOT(performDelete()));
691 
692  connect(exportAction, SIGNAL(triggered()), SLOT(performExport()));
693 }
694 
695 void QnlyGraphicsRegion::updateActionText(QnlyGraphicsRegion *region)
696 {
697  // Update Show Menu
698  if(regionActions.contains(region->getUid()))
699  regionActions[region->getUid()]->setText(region->getId());
700 }
701 
702 void QnlyGraphicsRegion::hideRegion(QnlyGraphicsRegion* region)
703 {
704  regionActions[region->getUid()]->trigger();
705 }
706 
707 void QnlyGraphicsRegion::performDelete()
708 {
709  emit regionDeletionRequested(this);
710 }
711 
712 void QnlyGraphicsRegion::performExport()
713 {
714  QString location = QFileDialog::getSaveFileName(NULL, "Export...", "", tr("Images (*.png)"));
715 
716  if (location != ""){
717 
718  qreal w = getWidth()+8;
719  qreal h = getHeight()+8;
720 
721  QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
722 
723  QPainter painter(&image);
724 
725  QPointF p = mapToScene(0,0);
726 
727  scene()->render(&painter, QRect(), QRect(p.x(),p.y(),w,h));
728 
729  painter.end();
730 
731  image.save(location, "PNG");
732  }
733 }
734 
735 void QnlyGraphicsRegion::performHide()
736 {
737  if (parentItem() != NULL)
738  {
739  QnlyGraphicsRegion* parent = (QnlyGraphicsRegion*) parentItem();
740 
741  parent->hideRegion(this);
742  }
743  else
744  {
746 
747  s->hideRegion(this);
748  }
749 }
750 
751 void QnlyGraphicsRegion::performRegion()
752 {
753  emit regionAdditionRequested(this);
754 }
755 
756 void QnlyGraphicsRegion::performShow(QAction* action)
757 {
758  if (!action->isChecked())
759  {
760  regions[regionActions.key(action)]->setVisible(false);
761  }
762  else
763  {
764  regions[regionActions.key(action)]->setVisible(true);
765  }
766 }
767 
768 void QnlyGraphicsRegion::removeRegion(QnlyGraphicsRegion* region)
769 {
770  if(regionActions.contains(region->getUid()))
771  {
772  QAction *action = regionActions[region->getUid()];
773 
774  showMenu->removeAction(action);
775 
776  regionActionGroup->removeAction(action);
777  }
778 
779  regionActions.remove(region->getUid());
780 }
781 
782 void QnlyGraphicsRegion::addRegion(QnlyGraphicsRegion* region)
783 {
784  if (region != NULL)
785  {
786  region->setParent(this);
787 
788  region->setGridAction(gridAction);
789 
790  regions[region->getUid()] = region;
791 
792  QAction* action = new QAction(this);
793  action->setText(region->getId());
794 
795  showMenu->addAction(action);
796 
797  showMenu->insertAction(showMenu->actions().front(), action);
798 
799  if (showMenu->actions().size() <= 2){
800  showMenu->insertSeparator(showMenu->actions().back());
801  }
802 
803  action->setCheckable(true);
804  action->setChecked(true);
805  action->setEnabled(true);
806 
807  regionActionGroup->addAction(action);
808 
809  regionActions[region->getUid()] = action;
810  }
811 }
812 
813 void QnlyGraphicsRegion::move(QGraphicsSceneMouseEvent* event)
814 {
815  /* setting */
816  qreal x = left;
817  qreal y = top;
818 
819  /* setting minimal position */
820  qreal minx;
821  qreal miny;
822 
823  if (parentItem() != NULL)
824  {
825  minx = 4;
826  miny = 4;
827  }
828  else
829  {
830  minx = 0;
831  miny = 0;
832  }
833 
834  /* setting maximal position */
835  qreal maxx;
836  qreal maxy;
837 
838  if (parentItem() != NULL)
839  {
840  maxx = parentItem()->boundingRect().width() - width - 4;
841  maxy = parentItem()->boundingRect().height() - height - 4;
842  }
843  else
844  {
845  maxx = scene()->width() - width;
846  maxy = scene()->height() - height;
847  }
848 
849  /* setting delta */
850  qreal dx = event->pos().x() - pressLeft; // (x1 - x0)
851  qreal dy = event->pos().y() - pressTop; // (y1 - y0)
852 
853  /* setting next position */
854  qreal nextx = x + dx;
855  qreal nexty = y + dy;
856 
857  /* adjusting */
858  if (nextx < minx)
859  {
860  nextx = minx;
861  }
862 
863  if (nexty < miny)
864  {
865  nexty = miny;
866  }
867 
868  if (nextx > maxx)
869  {
870  nextx = maxx;
871  }
872 
873  if (nexty > maxy)
874  {
875  nexty = maxy;
876  }
877 
878  /* moving */
879  setMoveTop(nexty);
880  setMoveLeft(nextx);
881 
882  scene()->update();
883 }
884 
885 void QnlyGraphicsRegion::resize(QGraphicsSceneMouseEvent* event)
886 {
887  /* setting bounds */
888  qreal x = left;
889  qreal y = top;
890  qreal w = width;
891  qreal h = height;
892 
893  /* setting minimal bounds */
894  qreal minx;
895  qreal miny;
896  qreal minw;
897  qreal minh;
898 
899  if (parentItem() != NULL)
900  {
901  minx = 4;
902  miny = 4;
903  minw = -1; // not used
904  minh = -1; // not used
905  }
906  else
907  {
908  minx = 0;
909  miny = 0;
910  minw = -1; // not used
911  minh = -1; // not used
912  }
913 
914  /* setting maximal bounds */
915  qreal maxx;
916  qreal maxy;
917  qreal maxw;
918  qreal maxh;
919 
920  if (parentItem() != NULL)
921  {
922  maxx = parentItem()->boundingRect().width() - width - 4;
923  maxy = parentItem()->boundingRect().height() - height - 4;
924  maxw = parentItem()->boundingRect().width() - 4;
925  maxh = parentItem()->boundingRect().height() - 4;
926  }
927  else
928  {
929  maxx = scene()->width() - width;
930  maxy = scene()->height() - height;
931  maxw = scene()->width();
932  maxh = scene()->height();
933  }
934 
935  /* setting delta */
936  qreal dx = event->pos().x() - pressLeft; // (x1 - x0)
937  qreal dy = event->pos().y() - pressTop; // (y1 - y0)
938  qreal dw = -dx;
939  qreal dh = -dy;
940 
941  /* setting next bounds */
942  qreal nextx = x + dx;
943  qreal nexty = y + dy;
944  qreal nextw = w + dw;
945  qreal nexth = h + dh;
946 
947  /* adjusting */
948  switch(resizeType)
949  {
950  /* adjusting TOPLEFT */
951  case QnlyGraphicsRegion::TopLeft:
952  {
953  if (nextx < minx)
954  {
955  nextx = minx;
956  nextw = x + w - minx;
957  }
958 
959  if (nexty < miny)
960  {
961  nexty = miny;
962  nexth = y + h - miny;
963  }
964  break;
965  }
966  /* adjusting TOP */
967  case QnlyGraphicsRegion::Top:
968  {
969  nextx = x; // fixed x
970  nextw = w; // fixed width
971 
972  if (nexty < miny)
973  {
974  nexty = miny;
975  nexth = y + h - miny;
976  }
977 
978  break;
979  }
980 
981  /* adjusting TOPRIGHT */
982  case QnlyGraphicsRegion::TopRight:
983  {
984  nextx = x; // fixed x
985 
986  nextw = w - dw;
987  if (x + nextw > maxw)
988  {
989  nextw = maxw - x;
990  }
991 
992  if (nexty < miny)
993  {
994  nexty = miny;
995  nexth = y + h - miny;
996  }
997 
998  break;
999  }
1000 
1001  /* adjusting RIGHT */
1002  case QnlyGraphicsRegion::Right:
1003  {
1004  nextx = x; // fixed x
1005 
1006  nextw = w - dw;
1007  if (x + nextw > maxw)
1008  {
1009  nextw = maxw - x;
1010  }
1011 
1012  nexty = y; // fixed y
1013  nexth = h; // fixed height
1014 
1015  break;
1016  }
1017 
1018  /* adjusting BOTTOMRIGHT */
1019  case QnlyGraphicsRegion::BottomRight:
1020  {
1021  nextx = x; // fixed x
1022 
1023  nextw = w - dw;
1024  if (x + nextw > maxw){
1025  nextw = maxw - x;
1026  }
1027 
1028  nexty = y; // fixed y
1029 
1030  nexth = h - dh;
1031  if (y + nexth > maxh)
1032  {
1033  nexth = maxh - y;
1034  }
1035 
1036  break;
1037  }
1038 
1039  /* adjusting BOTTOM */
1040  case QnlyGraphicsRegion::Bottom:
1041  {
1042  nextx = x; // fixed x
1043  nextw = w; // fixed width
1044 
1045  nexty = y; // fixed y
1046 
1047  nexth = h - dh;
1048  if (y + nexth > maxh)
1049  {
1050  nexth = maxh - y;
1051  }
1052 
1053  break;
1054  }
1055 
1056  /* adjusting BOTTOMLEFT */
1057  case QnlyGraphicsRegion::BottomLeft:
1058  {
1059  if (nextx < minx)
1060  {
1061  nextx = minx;
1062  nextw = x + w - minx;
1063  }
1064 
1065  nexty = y; // fixed y
1066 
1067  nexth = h - dh;
1068  if (y + nexth > maxh)
1069  {
1070  nexth = maxh - y;
1071  }
1072 
1073  break;
1074  }
1075 
1076  /* adjusting LEFT */
1077  case QnlyGraphicsRegion::Left:
1078  {
1079  if (nextx < minx)
1080  {
1081  nextx = minx;
1082  nextw = x + w - minx;
1083  }
1084 
1085  nexty = y; // fixed y
1086  nexth = h; // fixed height
1087 
1088  break;
1089  }
1090  }
1091 
1092  /* resizing */
1093  setResizeTop(nexty);
1094  setResizeLeft(nextx);
1095  setResizeWidth(nextw);
1096  setResizeHeight(nexth);
1097 
1098  scene()->update();
1099 }
1100 
1101 void QnlyGraphicsRegion::adjust(bool repaint)
1102 {
1103  if (parentItem() != NULL)
1104  {
1105  QnlyGraphicsRegion* item = (QnlyGraphicsRegion*) parentItem();
1106 
1107  setTop(qRound(item->getHeight()*relativeTop + 4));
1108  setLeft(qRound(item->getWidth()*relativeLeft + 4));
1109 
1110  setWidth(qRound(item->getWidth()*relativeWidth));
1111  setHeight(qRound(item->getHeight()*relativeHeight));
1112 
1113  setRight(item->getWidth() - (left+width)); // not use to paint
1114  setBottom(item->getHeight() - (top+height)); // not use to paint
1115 
1116  }
1117  else
1118  {
1119  setTop(qRound(scene()->height()*relativeTop));
1120  setLeft(qRound(scene()->width()*relativeLeft));
1121 
1122  setWidth(qRound(scene()->width()*relativeWidth));
1123  setHeight(qRound(scene()->height()*relativeHeight));
1124 
1125  setRight(scene()->width() - (left+width)); // not use to paint
1126  setBottom(scene()->height() - (top+height)); // not use to paint
1127  }
1128 
1129  for (int i=0;i<childItems().size();++i)
1130  {
1131  QnlyGraphicsRegion* item = (QnlyGraphicsRegion*) childItems().at(i);
1132 
1133  item->adjust(false);
1134  }
1135 
1136  if (repaint)
1137  {
1138  scene()->update();
1139  }
1140 }
1141 
1142 QPainterPath QnlyGraphicsRegion::shape() const
1143 {
1144  QPainterPath path;
1145 
1146  path.addRect(4, 4, width, height);
1147 
1148  if (selected)
1149  {
1150  path.setFillRule(Qt::WindingFill);
1151 
1152  path.addRect(0,0,8,8); // topleft
1153  path.addRect((width+8)/2 - 4,0,8,8); // top
1154  path.addRect((width+8) - 8,0,8,8); // topright
1155  path.addRect((width+8) - 8,(height+8)/2 - 4,8,8); // right
1156  path.addRect((width+8) - 8,(height+8) - 8,8,8); // bottomright
1157  path.addRect((width+8)/2 - 4,(height+8) - 8,8,8); // bottom
1158  path.addRect(0,(height+8) - 8,8,8); // bottomleft
1159  path.addRect(0,(height+8)/2 - 4,8,8); // left
1160  }
1161 
1162  return path;
1163 }
1164 
1165 QRectF QnlyGraphicsRegion::boundingRect() const
1166 {
1167  QRectF bounds;
1168 
1169  bounds.setX(0);
1170  bounds.setY(0);
1171  bounds.setWidth(width+8);
1172  bounds.setHeight(height+8);
1173 
1174  return bounds;
1175 }
1176 
1177 void QnlyGraphicsRegion::paint(QPainter *painter,
1178  const QStyleOptionGraphicsItem *option,
1179  QWidget *widget)
1180 {
1181  if (selected)
1182  {
1183  painter->setBrush(QColor(color));
1184  painter->setPen(QPen(QBrush(Qt::black), 0, Qt::DashLine)); // 0px = cosmetic border
1185  painter->drawRect(4,4,width-1,height-1);
1186  }
1187  else
1188  {
1189  painter->setBrush(QColor(color));
1190  painter->setPen(QPen(QBrush(Qt::black), 0)); // 0px = cosmetic border
1191  painter->drawRect(4,4,width-1,height-1);
1192  }
1193 
1194  if (moving)
1195  {
1196  if (parentItem() != NULL)
1197  {
1198  painter->setBrush(Qt::NoBrush);
1199  painter->setPen(QPen(QBrush(Qt::black), 0)); // 0px = cosmetic border
1200  painter->drawRect(moveLeft+4-left,moveTop+4-top,width-1,height-1);
1201  }
1202  else
1203  {
1204  painter->setBrush(Qt::NoBrush);
1205  painter->setPen(QPen(QBrush(Qt::black), 0)); // 0px = cosmetic border
1206  painter->drawRect(moveLeft+4-left,moveTop+4-top,width-1,height-1);
1207  }
1208  }
1209  else if (resizing)
1210  {
1211  painter->setBrush(Qt::NoBrush);
1212  painter->setPen(QPen(QBrush(Qt::black), 0)); // 0px = cosmetic border
1213  painter->drawRect(resizeLeft+4-left,resizeTop+4-top,resizeWidth-1,resizeHeight-1);
1214  }
1215  else if (selected)
1216  {
1217  painter->setBrush(QBrush(Qt::white));
1218  painter->setPen(QPen(QBrush(QBrush(Qt::black)), 0)); // 0px = cosmetic border
1219 
1220  painter->drawRect(0,0,8,8); // topleft
1221  painter->drawRect((width+8)/2-4-1,0,8,8); // top
1222  painter->drawRect((width+8)-8-1,0,8,8); // topright
1223  painter->drawRect((width+8)-8-1,(height+8)/2-4-1,8,8); // right
1224  painter->drawRect((width+8)-8-1,(height+8)-8-1,8,8); // bottomright
1225  painter->drawRect((width+8)/2-4-1,(height+8)-8-1,8,8); // bottom
1226  painter->drawRect(0,(height+8)-8-1,8,8); // bottomleft
1227  painter->drawRect(0,(height+8)/2-4-1,8,8); // left
1228  }
1229 
1230  QString text = "";
1231 
1232  if (width >= 25 && height >= 25 && id != "")
1233  {
1234  text = title+" "+"("+id+")";
1235  }
1236 
1237  painter->drawText(4+6,4+6,width-1-4-6,height-1-4-6,Qt::AlignLeft, text);
1238 }
1239 
1240 void QnlyGraphicsRegion::updateCursor(QGraphicsSceneMouseEvent* event)
1241 {
1242  Qt::CursorShape newShape;
1243  if(!resizing && !moving)
1244  {
1245  QPointF pos = mapFromScene(event->scenePos());
1246 
1247  // in the middle (UP or DOWN)
1248  if (QRectF((width+8)/2 - 4,0,8,8).contains(pos) ||
1249  QRectF((width+8)/2 - 4,(height+8) - 8,8,8).contains(pos))
1250  {
1251  newShape = Qt::SizeVerCursor;
1252  }
1253 
1254  // TOPLEFT or BOTTOM RIGHT
1255  else if (QRectF(0,0,8,8).contains(pos) ||
1256  QRectF((width+8) - 8,(height+8) - 8,8,8).contains(pos))
1257 
1258  {
1259  newShape = Qt::SizeFDiagCursor;
1260  }
1261 
1262  // TOPRIGHT or BOTTOMLEFT
1263  else if (QRectF((width+8) - 8,0,8,8).contains(pos) ||
1264  QRectF(0,(height+8) - 8,8,8).contains(pos))
1265  {
1266  newShape = Qt::SizeBDiagCursor;
1267  }
1268 
1269  // RIGHT OR LEFT
1270  else if (QRectF((width+8)-8-1,(height+8)/2-4-1,8,8).contains(pos) ||
1271  QRectF(0,(height+8)/2-4-1,8,8).contains(pos))
1272  {
1273  newShape = Qt::SizeHorCursor;
1274  }
1275 
1276  else
1277  {
1278  newShape = Qt::ArrowCursor;
1279  }
1280 
1281  if(newShape != cursor().shape())
1282  {
1283  setCursor(newShape);
1284  }
1285  }
1286 }
1287 
1288 void QnlyGraphicsRegion::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
1289 {
1290  if (moving)
1291  {
1292  move(event);
1293  }
1294  else if (resizing)
1295  {
1296  resize(event);
1297  }
1298 }
1299 
1300 void QnlyGraphicsRegion::mousePressEvent(QGraphicsSceneMouseEvent* event)
1301 {
1302  if (event->button() == Qt::RightButton)
1303  {
1304  event->ignore();
1305 
1306  }
1307  else if (event->button() == Qt::LeftButton)
1308  {
1309  emit regionSelectionRequested(this);
1310 
1311  setPressTop(event->pos().y());
1312  setPressLeft(event->pos().x());
1313  setPressWidth(width);
1314  setPressHeight(height);
1315 
1316  /* avoid flickering on first move */
1317  setMoveTop(top);
1318  setMoveLeft(left);
1319 
1320  /* avoid flickering on first resize */
1321  setResizeTop(top);
1322  setResizeLeft(left);
1323  setResizeWidth(width);
1324  setResizeHeight(height);
1325 
1326  /* if over TOPLEFT resize region */
1327  if (QRectF(0,0,8,8).contains(event->pos()))
1328  {
1329  setResizeType(QnlyGraphicsRegion::TopLeft);
1330  setResizing(true);
1331  }
1332  /* if over TOP resize region */
1333  else if (QRectF((width+8)/2 - 4,0,8,8).contains(event->pos()))
1334  {
1335  setResizeType(QnlyGraphicsRegion::Top);
1336  setResizing(true);
1337  }
1338  /* if over TOPRIGHT resize region */
1339  else if (QRectF((width+8) - 8,0,8,8).contains(event->pos()))
1340  {
1341  setResizeType(QnlyGraphicsRegion::TopRight);
1342  setResizing(true);
1343  }
1344  /* if over RIGHT resize region */
1345  else if (QRectF((width+8) - 8,(height+8)/2 - 4,8,8).contains(event->pos()))
1346  {
1347  setResizeType(QnlyGraphicsRegion::Right);
1348  setResizing(true);
1349  }
1350  /* if over BOTTOMRIGHT resize region */
1351  else if (QRectF((width+8) - 8,(height+8) - 8,8,8).contains(event->pos()))
1352  {
1353  setResizeType(QnlyGraphicsRegion::BottomRight);
1354  setResizing(true);
1355  }
1356  /* if over BOTTOM resize region */
1357  else if (QRectF((width+8)/2 - 4,(height+8) - 8,8,8).contains(event->pos()))
1358  {
1359  setResizeType(QnlyGraphicsRegion::Bottom);
1360  setResizing(true);
1361  }
1362  /* if over BOTTOMLEFT resize region */
1363  else if (QRectF(0,(height+8) - 8,8,8).contains(event->pos()))
1364  {
1365  setResizeType(QnlyGraphicsRegion::BottomLeft);
1366  setResizing(true);
1367  }
1368  /* if over LEFT resize region */
1369  else if (QRectF(0,(height+8)/2 - 4,8,8).contains(event->pos()))
1370  {
1371  setResizeType(QnlyGraphicsRegion::Left);
1372  setResizing(true);
1373  }
1374  /* if not over any resize region */
1375  else
1376  {
1377  setMoving(true);
1378  }
1379  }
1380 
1381  event->accept();
1382 
1383  QGraphicsItem::mousePressEvent(event);
1384 }
1385 
1386 void QnlyGraphicsRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
1387 {
1388  if (moving)
1389  {
1390  setMoving(false);
1391 
1392  if ((top != moveTop || left != moveLeft))
1393  {
1394  /*
1395  setTop(moveTop);
1396  setLeft(moveLeft);
1397 
1398  if (parentItem() != NULL){
1399  QnlyGraphicsRegion* item = (QnlyGraphicsRegion*) parentItem();
1400 
1401  setRelativeTop((top-4)/item->getHeight());
1402  setRelativeLeft((left-4)/item->getWidth());
1403 
1404  setRelativeWidth(width/item->getWidth());
1405  setRelativeHeight(height/item->getHeight());
1406 
1407  setRelativeRight(1 - (relativeLeft+relativeWidth));
1408  setRelativeBottom(1 - (relativeTop+relativeHeight));
1409 
1410  }else{
1411  setRelativeTop(top/scene()->height());
1412  setRelativeLeft(left/scene()->width());
1413 
1414  setRelativeWidth(width/scene()->width());
1415  setRelativeHeight(height/scene()->height());
1416 
1417  setRelativeRight(1 - (relativeLeft+relativeWidth));
1418  setRelativeBottom(1 - (relativeTop+relativeHeight));
1419  }
1420 */
1421  QMap<QString, QString> attributes;
1422 
1423  double value = 0.0;
1424  if (parentItem() != NULL)
1425  {
1426  QnlyGraphicsRegion* item = (QnlyGraphicsRegion*) parentItem();
1427 
1428  value = ((moveTop-4)/item->getHeight()) * 100;
1429  ROUND_DOUBLE(value);
1430  attributes["top"] = QString::number(value, 'f', 2) + "%";
1431 
1432  value = ((moveLeft-4)/item->getWidth()) * 100;
1433  ROUND_DOUBLE(value);
1434  attributes["left"] = QString::number(value, 'f', 2) + "%";
1435 
1436  value = (1 - (((moveLeft-4)/item->getWidth())+(width/item->getWidth()))) * 100;
1437  ROUND_DOUBLE(value);
1438  attributes["right"] = QString::number(value, 'f', 2) + "%";
1439 
1440  value = (1 - (((moveTop-4)/item->getHeight())+(height/item->getHeight())))*100;
1441  ROUND_DOUBLE(value);
1442  attributes["bottom"] = QString::number(value, 'f', 2) + "%";
1443 
1444  }
1445  else
1446  {
1447  value = ((moveTop)/scene()->height())*100;
1448  ROUND_DOUBLE(value);
1449  attributes["top"] = QString::number(value, 'f', 2) + "%";
1450 
1451  value = ((moveLeft)/scene()->width())*100;
1452  ROUND_DOUBLE(value);
1453  attributes["left"] = QString::number(value, 'f', 2) + "%";
1454 
1455  value = (1 - (((moveLeft)/scene()->width())+(width/scene()->width())))*100;
1456  ROUND_DOUBLE(value);
1457  attributes["right"] = QString::number(value, 'f', 2) + "%";
1458 
1459  value = (1 - (((moveTop)/scene()->height())+(height/scene()->height())))*100;
1460  ROUND_DOUBLE(value);
1461  attributes["bottom"] = QString::number(value, 'f', 2) + "%";
1462 
1463  }
1464 
1465  attributes["zIndex"] = QString::number(getzIndex());
1466 
1467  setChanged(true);
1468 
1469  emit regionChangeRequested(this,attributes);
1470  }
1471  }
1472 
1473  if (resizing)
1474  {
1475  setResizing(false);
1476 
1477  if ((top != resizeTop || left != resizeLeft ||
1478  width != resizeWidth || height != resizeHeight))
1479  {
1480  if (resizeTop > top + height)
1481  {
1482  setResizeHeight(resizeTop - (top + height));
1483  setResizeTop(top + height);
1484  }
1485 
1486  if (resizeLeft > left + width)
1487  {
1488  setResizeWidth(resizeLeft - (left + width));
1489  setResizeLeft(left + width);
1490  }
1491 
1492  if (resizeWidth < 0)
1493  {
1494  setResizeLeft(resizeLeft + resizeWidth);
1495  setResizeWidth(-resizeWidth);
1496  }
1497 
1498  if (resizeHeight < 0)
1499  {
1500  setResizeTop(resizeTop + resizeHeight);
1501  setResizeHeight(-resizeHeight);
1502  }
1503  /*
1504  setTop(resizeTop);
1505  setLeft(resizeLeft);
1506  setWidth(resizeWidth);
1507  setHeight(resizeHeight);
1508 
1509  if (parentItem() != NULL){
1510  QnlyGraphicsRegion* item = (QnlyGraphicsRegion*) parentItem();
1511 
1512  setRelativeTop((top-4)/item->getHeight());
1513  setRelativeLeft((left-4)/item->getWidth());
1514  setRelativeWidth(width/item->getWidth());
1515  setRelativeHeight(height/item->getHeight());
1516 
1517  setRelativeRight(1 - (relativeLeft+relativeWidth));
1518  setRelativeBottom(1 - (relativeTop+relativeHeight));
1519 
1520  }else{
1521  setRelativeTop(top/scene()->height());
1522  setRelativeLeft(left/scene()->width());
1523  setRelativeWidth(width/scene()->width());
1524  setRelativeHeight(height/scene()->height());
1525 
1526  setRelativeRight(1 - (relativeLeft+relativeWidth));
1527  setRelativeBottom(1 - (relativeTop+relativeHeight));
1528  }
1529  */
1530 
1531  QMap<QString, QString> attributes;
1532 
1533  double value = 0.0;
1534  if (parentItem() != NULL)
1535  {
1536  QnlyGraphicsRegion* item = (QnlyGraphicsRegion*) parentItem();
1537 
1538  value = ((resizeTop-4)/item->getHeight())*100;
1539  ROUND_DOUBLE(value);
1540  attributes["top"] = QString::number(value, 'f', 2) + "%";
1541 
1542  value = ((resizeLeft-4)/item->getWidth())*100;
1543  ROUND_DOUBLE(value);
1544  attributes["left"] = QString::number(value, 'f', 2) + "%";
1545 
1546  value = (resizeHeight/item->getHeight())*100;
1547  ROUND_DOUBLE(value);
1548  attributes["height"] = QString::number(value, 'f', 2) + "%";
1549 
1550  value = (resizeWidth/item->getWidth())*100;
1551  ROUND_DOUBLE(value);
1552  attributes["width"] = QString::number(value, 'f', 2) + "%";
1553 
1554  value = (1 - (((resizeLeft-4)/item->getWidth())+(resizeWidth/item->getWidth())))*100;
1555  ROUND_DOUBLE(value);
1556  attributes["right"] = QString::number(value, 'f', 2) + "%";
1557 
1558  value = (1 - (((resizeTop-4)/item->getHeight())+(resizeHeight/item->getHeight())))*100;
1559  ROUND_DOUBLE(value);
1560  attributes["bottom"] = QString::number(value, 'f', 2) + "%";
1561  }
1562  else
1563  {
1564  value = ((resizeTop)/scene()->height())*100;
1565  ROUND_DOUBLE(value);
1566  attributes["top"] = QString::number(value, 'f', 2) + "%";
1567 
1568  value = ((resizeLeft)/scene()->width())*100;
1569  ROUND_DOUBLE(value);
1570  attributes["left"] = QString::number(value, 'f', 2) + "%";
1571 
1572  value = (resizeHeight/scene()->height())*100;
1573  ROUND_DOUBLE(value);
1574  attributes["height"] = QString::number(value, 'f', 2) + "%";
1575 
1576  value = (resizeWidth/scene()->width())*100;
1577  ROUND_DOUBLE(value);
1578  attributes["width"] = QString::number(value, 'f', 2) + "%";
1579 
1580  value = (1 - (((resizeLeft)/scene()->width())+(resizeWidth/scene()->width())))*100;
1581  ROUND_DOUBLE(value);
1582  attributes["right"] = QString::number(value, 'f', 2) + "%";
1583 
1584  value = (1 - (((resizeTop)/scene()->height())+(resizeHeight/scene()->height())))*100;
1585  ROUND_DOUBLE(value);
1586  attributes["bottom"] = QString::number(value, 'f', 2) + "%";
1587  }
1588 
1589  attributes["zIndex"] = QString::number(getzIndex());
1590 
1591  setChanged(true);
1592 
1593  emit regionChangeRequested(this, attributes);
1594  }
1595  }
1596 
1597  adjust();
1598 
1599  QGraphicsItem::mouseReleaseEvent(event);
1600 }
1601 
1602 void QnlyGraphicsRegion::keyPressEvent( QKeyEvent * event )
1603 {
1604  if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace)
1605  {
1606  performDelete();
1607 
1608  event->accept();
1609  }
1610 
1611  QGraphicsItem::keyPressEvent(event);
1612 }
1613 
1614 void QnlyGraphicsRegion::keyReleaseEvent( QKeyEvent * event )
1615 {
1616  QGraphicsItem::keyReleaseEvent(event);
1617 }
1618 
1619 
1620 void QnlyGraphicsRegion::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
1621 {
1622  QGraphicsItem::contextMenuEvent(event);
1623 
1624  if (!event->isAccepted())
1625  {
1626  emit regionSelectionRequested(this);
1627 
1628  contextMenu->exec(event->screenPos());
1629 
1630  event->accept();
1631  }
1632 }
1633 
1634 void QnlyGraphicsRegion::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1635 {
1636  if (event->mimeData()->hasFormat("nclcomposer/mediaid"))
1637  event->acceptProposedAction();
1638 }
1639 
1640 void QnlyGraphicsRegion::dropEvent(QGraphicsSceneDragDropEvent *event)
1641 {
1642  qDebug() << "dropEvent " << event->mimeData()->data("nclcomposer/mediaid")
1643  << event->mimeData()->data("nclcomposer/qnstuid");
1644 
1645 
1646  emit dragMediaOverRegion(event->mimeData()->data("nclcomposer/mediaid"),
1647  this);
1648 }