18 #include "qnlygraphicsregionbase.h"
20 QnlyGraphicsRegionBase::QnlyGraphicsRegionBase(QObject* parent,
22 : QGraphicsScene(parent)
24 this->switchMenu = switchMenu;
26 this->switchMenu->setEnabled(
true);
32 graphicsRegionBaseId = NULL;
34 selectedRegion = NULL;
36 setSceneRect(0,0,854,480);
38 bgrect =
new QGraphicsRectItem(0,
this);
39 bgrect->setRect(0,0,854,480);
41 bgrect->setBrush(QBrush(Qt::white));
42 bgrect->setPen(QPen(QColor(
"#BBBBBB")));
43 bgrect->setZValue(-1);
47 grid->setPen(QPen(QBrush(Qt::gray), 1.5,Qt::DotLine));
48 grid->setRect(0,0,854,480);
49 grid->setZValue(1000);
50 grid->setVisible(
false);
53 QnlyGraphicsRegionBase::~QnlyGraphicsRegionBase()
58 QString QnlyGraphicsRegionBase::getId()
const
63 void QnlyGraphicsRegionBase::setId(
const QString &
id)
74 QString QnlyGraphicsRegionBase::getUid()
const
79 void QnlyGraphicsRegionBase::setUid(
const QString &uid)
84 QString QnlyGraphicsRegionBase::getRegion()
const
89 void QnlyGraphicsRegionBase::setRegion(
const QString ®ion)
91 this->region = region;
94 QString QnlyGraphicsRegionBase::getDevice()
const
99 void QnlyGraphicsRegionBase::setDevice(
const QString &device)
101 this->device = device;
106 if (!region->isSelected())
108 if (selectedRegion != NULL)
110 selectedRegion->setSelected(
false);
113 region->setSelected(
true);
115 selectedRegion = region;
120 const QMap<QString, QString> attributes)
125 region->setId(attributes[
"id"]);
129 region->setTitle(attributes[
"title"]);
132 if (!attributes[
"color"].isEmpty())
133 region->setColor(attributes[
"color"]);
135 if (!attributes[
"top"].isEmpty())
137 if (attributes[
"top"].contains(QRegExp(
"\\d+(.\\d+)?%")))
139 QString attribute = attributes[
"top"];
140 attribute.remove(attribute.length()-1,1);
142 qreal top = attribute.toDouble();
144 if (top >= 0 && top <= 100)
145 region->setRelativeTop(top/100);
147 else if (attributes[
"top"].contains(QRegExp(
"\\d+(.\\d+)?")))
149 QString attribute = attributes[
"top"];
151 qreal top = attribute.toDouble();
153 if (top >= 0 && top <= 1)
154 region->setRelativeTop(top);
158 if (!attributes[
"left"].isEmpty())
160 if (attributes[
"left"].contains(QRegExp(
"\\d+(.\\d+)?%")))
162 QString attribute = attributes[
"left"];
163 attribute.remove(attribute.length()-1,1);
165 qreal left = attribute.toDouble();
167 if (left >= 0 && left <= 100)
168 region->setRelativeLeft(left/100);
170 else if (attributes[
"left"].contains(QRegExp(
"\\d+(.\\d+)?")))
172 QString attribute = attributes[
"left"];
174 qreal left = attribute.toDouble();
176 if (left >= 0 && left <= 1)
177 region->setRelativeLeft(left);
181 if (!attributes[
"right"].isEmpty())
183 if (attributes[
"right"].contains(QRegExp(
"\\d+(.\\d+)?%")))
185 QString attribute = attributes[
"right"];
186 attribute.remove(attribute.length()-1,1);
188 qreal right = attribute.toDouble();
190 if (right >= 0 && right <= 100)
191 region->setRelativeRight(right/100);
193 else if (attributes[
"right"].contains(QRegExp(
"\\d+(.\\d+)?")))
195 QString attribute = attributes[
"right"];
197 qreal right = attribute.toDouble();
199 if (right >= 0 && right <= 1)
200 region->setRelativeRight(right);
204 if (!attributes[
"bottom"].isEmpty())
206 if (attributes[
"bottom"].contains(QRegExp(
"\\d+(.\\d+)?%")))
208 QString attribute = attributes[
"bottom"];
209 attribute.remove(attribute.length()-1,1);
211 qreal bottom = attribute.toDouble();
213 if (bottom >= 0 && bottom <= 100)
214 region->setRelativeBottom(bottom/100);
217 else if (attributes[
"bottom"].contains(QRegExp(
"\\d+(.\\d+)?")))
219 QString attribute = attributes[
"bottom"];
221 qreal bottom = attribute.toDouble();
223 if (bottom >= 0 && bottom <= 1)
224 region->setRelativeBottom(bottom);
228 if (!attributes[
"width"].isEmpty())
230 if (attributes[
"width"].contains(QRegExp(
"\\d+(.\\d+)?%")))
232 QString attribute = attributes[
"width"];
233 attribute.remove(attribute.length()-1,1);
235 qreal width = attribute.toDouble();
237 if (width >= 0 && width <= 100)
238 region->setRelativeWidth(width/100);
241 else if (attributes[
"width"].contains(QRegExp(
"\\d+(.\\d+)?")))
243 QString attribute = attributes[
"width"];
245 qreal width = attribute.toDouble();
247 if (width >= 0 && width <= 1)
248 region->setRelativeWidth(width);
252 if (!attributes[
"height"].isEmpty())
254 if (attributes[
"height"].contains(QRegExp(
"\\d+(.\\d+)?%")))
256 QString attribute = attributes[
"height"];
257 attribute.remove(attribute.length()-1,1);
259 qreal height = attribute.toDouble();
261 if (height >= 0 && height <= 100)
262 region->setRelativeHeight(height/100);
265 else if (attributes[
"height"].contains(QRegExp(
"\\d+(.\\d+)?")))
267 QString attribute = attributes[
"height"];
269 qreal height = attribute.toDouble();
271 if (height >= 0 && height <= 1)
272 region->setRelativeHeight(height);
277 if(attributes.contains(
"zIndex"))
278 region->setzIndex(attributes[
"zIndex"].toInt());
285 QMap<QString, QString> attributes)
288 QMap<QString, QString> full;
291 if (attributes.contains(
"id"))
292 full[
"id"] = attributes[
"id"];
293 else if (!region->getId().isEmpty())
294 full[
"id"] = region->getId();
301 if (attributes.contains(
"color"))
302 full[
"color"] = attributes[
"color"];
303 else if (!region->getColor().isEmpty())
304 full[
"color"] = region->getColor();
306 if (attributes.contains(
"top"))
307 full[
"top"] = attributes[
"top"];
310 value = region->getRelativeTop()*100;
312 full[
"top"] = QString::number(value,
'f', 2) +
"%";
315 if (attributes.contains(
"left"))
316 full[
"left"] = attributes[
"left"];
319 value = region->getRelativeLeft()*100;
321 full[
"left"] = QString::number(value,
'f', 2) +
"%";
342 if (attributes.contains(
"width"))
343 full[
"width"] = attributes[
"width"];
346 value = region->getRelativeWidth()*100;
348 full[
"width"] = QString::number(value,
'f', 2) +
"%";
351 if (attributes.contains(
"height"))
352 full[
"height"] = attributes[
"height"];
355 value = region->getRelativeHeight()*100;
357 full[
"height"] = QString::number(value,
'f', 2) +
"%";
361 if(attributes.contains(
"zIndex"))
363 full[
"zIndex"] = attributes[
"zIndex"];
367 value = region->getzIndex();
368 full[
"zIndex"] = QString::number(value);
371 emit regionChangeRequested( region->getUid(), uid, full );
376 emit regionSelectionRequested(region->getUid(),uid);
379 void QnlyGraphicsRegionBase::QnlyGraphicsRegionBase::createActions()
382 helpAction =
new QAction(
this);
383 helpAction->setText(tr(
"Help"));
385 helpAction->setEnabled(
true);
386 helpAction->setShortcut(QKeySequence(
"F1"));
389 undoAction =
new QAction(
this);
390 undoAction->setText(tr(
"Undo"));
392 undoAction->setEnabled(
false);
393 undoAction->setShortcut(QKeySequence(
"Ctrl+Z"));
396 redoAction =
new QAction(
this);
397 redoAction->setText(tr(
"Redo"));
399 redoAction->setEnabled(
false);
400 redoAction->setShortcut(QKeySequence(
"Ctrl+Shift+Z"));
403 cutAction =
new QAction(
this);
404 cutAction->setText(tr(
"Cut"));
406 cutAction->setEnabled(
false);
407 cutAction->setShortcut(QKeySequence(
"Ctrl+X"));
410 copyAction =
new QAction(
this);
411 copyAction->setText(tr(
"Copy"));
413 copyAction->setEnabled(
false);
414 copyAction->setShortcut(QKeySequence(
"Ctrl+C"));
417 pasteAction =
new QAction(
this);
418 pasteAction->setText(tr(
"Paste"));
420 pasteAction->setEnabled(
false);
421 pasteAction->setShortcut(QKeySequence(
"Ctrl+V"));
424 deleteAction =
new QAction(
this);
425 deleteAction->setText(tr(
"Delete"));
427 deleteAction->setEnabled(
true);
428 deleteAction->setShortcut(QKeySequence(
"Del"));
431 zoominAction =
new QAction(
this);
432 zoominAction->setText(tr(
"Zoom In"));
434 zoominAction->setEnabled(
true);
435 zoominAction->setShortcut(QKeySequence(
"Ctrl++"));
438 zoomoutAction =
new QAction(
this);
439 zoomoutAction->setText(tr(
"Zoom Out"));
441 zoomoutAction->setEnabled(
true);
442 zoomoutAction->setShortcut(QKeySequence(
"Ctrl+-"));
445 zoomresetAction =
new QAction(
this);
446 zoomresetAction->setText(tr(
"Reset"));
448 zoomresetAction->setEnabled(
true);
449 zoomresetAction->setShortcut(QKeySequence(
"Ctrl+0"));
452 fullscreenAction =
new QAction(
this);
453 fullscreenAction->setText(tr(
"Full Screen"));
455 fullscreenAction->setEnabled(
true);
456 fullscreenAction->setShortcut(QKeySequence(
"F11"));
459 exportAction =
new QAction(
this);
460 exportAction->setText(tr(
"Export..."));
462 exportAction->setEnabled(
true);
465 regionAction =
new QAction(
this);
466 regionAction->setText(tr(
"Region"));
468 regionAction->setEnabled(
true);
471 regionbaseAction =
new QAction(
this);
472 regionbaseAction->setText(tr(
"Regionbase"));
474 regionbaseAction->setEnabled(
true);
477 bringfrontAction =
new QAction(
this);
478 bringfrontAction->setText(tr(
"Bring to Front"));
480 bringfrontAction->setEnabled(
false);
481 bringfrontAction->setShortcut(QKeySequence(
"Shift+Ctrl+]"));
484 bringforwardAction =
new QAction(
this);
485 bringforwardAction->setText(tr(
"Bring Forward"));
487 bringforwardAction->setEnabled(
false);
488 bringforwardAction->setShortcut(QKeySequence(
"Ctrl+]"));
491 sendbackwardAction =
new QAction(
this);
492 sendbackwardAction->setText(tr(
"Send Backward"));
494 sendbackwardAction->setEnabled(
false);
495 sendbackwardAction->setShortcut(QKeySequence(
"Ctrl+["));
498 sendbackAction =
new QAction(
this);
499 sendbackAction->setText(tr(
"Send to Back"));
501 sendbackAction->setEnabled(
false);
502 sendbackAction->setShortcut(QKeySequence(
"Shift+Ctrl+["));
504 re640x480 =
new QAction(
this);
505 re640x480->setText(tr(
"640x480 (4:3)"));
506 re640x480->setCheckable(
true);
507 re640x480->setChecked(
false);
509 re800x600 =
new QAction(
this);
510 re800x600->setText(tr(
"800x600 (4:3)"));
511 re800x600->setCheckable(
true);
512 re800x600->setChecked(
false);
514 re1024x768 =
new QAction(
this);
515 re1024x768->setText(tr(
"1024x768 (4:3)"));
516 re1024x768->setCheckable(
true);
517 re1024x768->setChecked(
false);
519 re854x480 =
new QAction(
this);
520 re854x480->setText(tr(
"854x480 (16:9)"));
521 re854x480->setCheckable(
true);
522 re854x480->setChecked(
true);
524 re1280x720 =
new QAction(
this);
525 re1280x720->setText(tr(
"1280x720 (16:9)"));
526 re1280x720->setCheckable(
true);
527 re1280x720->setChecked(
false);
529 re1920x1080 =
new QAction(
this);
530 re1920x1080->setText(tr(
"1920x1080 (16:9)"));
531 re1920x1080->setCheckable(
true);
532 re1920x1080->setChecked(
false);
534 re320x400 =
new QAction(
this);
535 re320x400->setText(tr(
"320x400 (4:5)"));
536 re320x400->setCheckable(
true);
537 re320x400->setChecked(
false);
540 hideAction =
new QAction(
this);
541 hideAction->setText(tr(
"Hide"));
543 hideAction->setEnabled(
false);
545 gridAction =
new QAction(
this);
546 gridAction->setText(tr(
"Grid"));
548 gridAction->setEnabled(
true);
549 gridAction->setCheckable(
true);
550 gridAction->setChecked(
false);
553 propertiesAction =
new QAction(
this);
554 propertiesAction->setText(tr(
"Properties"));
556 propertiesAction->setEnabled(
true);
558 regionActionGroup =
new QActionGroup(
this);
559 regionActionGroup->setExclusive(
false);
561 screensizeGroup =
new QActionGroup(
this);
562 screensizeGroup->setExclusive(
true);
564 screensizeGroup->addAction(re640x480);
565 screensizeGroup->addAction(re800x600);
566 screensizeGroup->addAction(re1024x768);
567 screensizeGroup->addAction(re854x480);
568 screensizeGroup->addAction(re1280x720);
569 screensizeGroup->addAction(re1920x1080);
570 screensizeGroup->addAction(re320x400);
573 void QnlyGraphicsRegionBase::createMenus()
576 viewMenu =
new QMenu();
577 viewMenu->setTitle(tr(
"View"));
579 viewMenu->setEnabled(
true);
581 viewMenu->addAction(zoominAction);
582 viewMenu->addAction(zoomoutAction);
583 viewMenu->addAction(zoomresetAction);
584 viewMenu->addSeparator();
585 viewMenu->addAction(fullscreenAction);
588 insertMenu =
new QMenu();
589 insertMenu->setTitle(tr(
"Insert"));
591 insertMenu->setEnabled(
true);
593 insertMenu->addAction(regionAction);
594 insertMenu->addAction(regionbaseAction);
597 showMenu =
new QMenu();
598 showMenu->setTitle(tr(
"Show"));
600 showMenu->addAction(gridAction);
602 showMenu->setEnabled(
true);
605 arrangeMenu =
new QMenu();
606 arrangeMenu->setTitle(tr(
"Arrange"));
608 arrangeMenu->setEnabled(
false);
610 arrangeMenu->addAction(bringfrontAction);
611 arrangeMenu->addAction(bringforwardAction);
612 arrangeMenu->addAction(sendbackwardAction);
613 arrangeMenu->addAction(sendbackAction);
616 screensizeMenu =
new QMenu();
617 screensizeMenu->setTitle(tr(
"Screen Size"));
619 screensizeMenu->setEnabled(
true);
621 screensizeMenu->addAction(re640x480);
622 screensizeMenu->addAction(re800x600);
623 screensizeMenu->addAction(re1024x768);
624 screensizeMenu->addAction(re854x480);
625 screensizeMenu->addAction(re1280x720);
626 screensizeMenu->addAction(re1920x1080);
627 screensizeMenu->addAction(re320x400);
631 contextMenu =
new QMenu();
641 contextMenu->addAction(deleteAction);
642 contextMenu->addSeparator();
643 contextMenu->addAction(exportAction);
644 contextMenu->addSeparator();
646 contextMenu->addMenu(insertMenu);
647 contextMenu->addMenu(showMenu);
648 contextMenu->addMenu(screensizeMenu);
650 contextMenu->addSeparator();
651 contextMenu->addAction(hideAction);
652 contextMenu->addSeparator();
653 contextMenu->addMenu(switchMenu);
658 void QnlyGraphicsRegionBase::createConnections()
660 connect(regionAction, SIGNAL(triggered()),
661 SLOT(performRegion()));
663 connect(regionbaseAction, SIGNAL(triggered()),
664 SIGNAL(regionbasePerformed()));
666 connect(regionActionGroup, SIGNAL(triggered(QAction*)),
667 SLOT(performShow(QAction*)));
669 connect(deleteAction, SIGNAL(triggered()),
670 SLOT(performDelete()));
672 re640x480->setData(QSize(640, 480));
673 connect(re640x480, SIGNAL(triggered()), SLOT(performChangeResolution()));
675 re800x600->setData(QSize(800, 600));
676 connect(re800x600, SIGNAL(triggered()), SLOT(performChangeResolution()));
678 re1024x768->setData(QSize(1024, 768));
679 connect(re1024x768, SIGNAL(triggered()), SLOT(performChangeResolution()));
681 re854x480->setData(QSize(854, 480));
682 connect(re854x480, SIGNAL(triggered()), SLOT(performChangeResolution()));
684 re1280x720->setData(QSize(1280, 720));
685 connect(re1280x720, SIGNAL(triggered()), SLOT(performChangeResolution()));
687 re1920x1080->setData(QSize(1920, 1080));
688 connect(re1920x1080, SIGNAL(triggered()), SLOT(performChangeResolution()));
690 re320x400->setData(QSize(320, 400));
691 connect(re320x400, SIGNAL(triggered()), SLOT(performChangeResolution()));
693 connect(exportAction, SIGNAL(triggered()), SLOT(performExport()));
695 connect(gridAction, SIGNAL(triggered()), SLOT(performGrid()));
698 void QnlyGraphicsRegionBase::performShow(QAction* action)
700 if (!action->isChecked())
701 regions[regionActions.key(action)]->setVisible(
false);
703 regions[regionActions.key(action)]->setVisible(
true);
708 QMap<QString, QString> attributes;
710 attributes[
"top"] =
"10%";
711 attributes[
"left"] =
"10%";
714 attributes[
"width"] =
"80%";
715 attributes[
"height"] =
"80%";
721 zIndex = zIndex > region->getzIndex() ? zIndex : region->getzIndex() + 1;
723 attributes[
"zIndex"] = QString::number(zIndex);
725 emit regionAdditionRequested(
"", parent->getUid(), uid, attributes);
730 emit regionDeletionRequested(region->getUid(), uid);
736 if(regionActions.contains(region->getUid()))
737 regionActions[region->getUid()]->setText(region->getId());
742 regionActions[region->getUid()]->trigger();
749 if (region->parentItem() != NULL)
754 foreach(QGraphicsItem* item, region->childItems())
759 regions.remove(child->getUid());
761 qWarning() <<
"Trying to remove an element that is not of the type QnlyGraphicsRegion " << __FILE__ << __LINE__;
764 parent->removeRegion(region);
768 foreach(QGraphicsItem* item, region->childItems())
773 regions.remove(child->getUid());
775 qWarning() <<
"Trying to remove an element that is not of the type QnlyGraphicsRegion " << __FILE__ << __LINE__;
778 if(regionActions.contains(region->getUid()))
780 QAction *action = regionActions[region->getUid()];
782 showMenu->removeAction(action);
784 regionActionGroup->removeAction(action);
786 regionActions.remove(region->getUid());
792 regions.remove(region->getUid());
796 selectedRegion = NULL;
798 emit regionBaseSelectionRequested(uid);
802 QGraphicsItem* QnlyGraphicsRegionBase::getBackgroundItem()
807 void QnlyGraphicsRegionBase::performDelete()
809 emit regionBaseDeletionRequested(uid);
812 void QnlyGraphicsRegionBase::performRegion()
814 QMap<QString, QString> attributes;
816 attributes[
"top"] =
"10%";
817 attributes[
"left"] =
"10%";
818 attributes[
"right"] =
"10%";
819 attributes[
"bottom"] =
"10%";
820 attributes[
"width"] =
"80%";
821 attributes[
"height"] =
"80%";
827 zIndex = zIndex > region->getzIndex() ? zIndex : region->getzIndex() + 1;
829 attributes[
"zIndex"] = QString::number(zIndex);
831 emit regionAdditionRequested(
"",
"", uid, attributes);
836 const QMap<QString, QString> attributes)
841 if (!attributes[
"id"].isEmpty())
842 region->setId(attributes[
"id"]);
844 if (!attributes[
"title"].isEmpty())
845 region->setTitle(attributes[
"title"]);
847 if (!attributes[
"color"].isEmpty())
848 region->setColor(attributes[
"color"]);
850 if (!attributes[
"top"].isEmpty())
852 if (attributes[
"top"].contains(QRegExp(
"\\d+(.\\d+)?%")))
854 QString attribute = attributes[
"top"];
855 attribute.remove(attribute.length()-1,1);
857 qreal top = attribute.toDouble();
859 if (top >= 0 && top <= 100)
860 region->setRelativeTop(top/100);
862 else if (attributes[
"top"].contains(QRegExp(
"\\d+(.\\d+)?")))
864 QString attribute = attributes[
"top"];
866 qreal top = attribute.toDouble();
868 if (top >= 0 && top <= 1)
869 region->setRelativeTop(top);
873 if (!attributes[
"left"].isEmpty())
875 if (attributes[
"left"].contains(QRegExp(
"\\d+(.\\d+)?%")))
877 QString attribute = attributes[
"left"];
878 attribute.remove(attribute.length()-1,1);
880 qreal left = attribute.toDouble();
882 if (left >= 0 && left <= 100)
883 region->setRelativeLeft(left/100);
885 else if (attributes[
"left"].contains(QRegExp(
"\\d+(.\\d+)?")))
887 QString attribute = attributes[
"left"];
889 qreal left = attribute.toDouble();
891 if (left >= 0 && left <= 1)
892 region->setRelativeLeft(left);
896 if (!attributes[
"right"].isEmpty())
898 if (attributes[
"right"].contains(QRegExp(
"\\d+(.\\d+)?%")))
900 QString attribute = attributes[
"right"];
901 attribute.remove(attribute.length()-1,1);
903 qreal right = attribute.toDouble();
905 if (right >= 0 && right <= 100)
906 region->setRelativeRight(right/100);
908 else if (attributes[
"right"].contains(QRegExp(
"\\d+(.\\d+)?")))
910 QString attribute = attributes[
"right"];
912 qreal right = attribute.toDouble();
914 if (right >= 0 && right <= 1)
915 region->setRelativeRight(right);
919 if (!attributes[
"bottom"].isEmpty())
921 if (attributes[
"bottom"].contains(QRegExp(
"\\d+(.\\d+)?%")))
923 QString attribute = attributes[
"bottom"];
924 attribute.remove(attribute.length()-1,1);
926 qreal bottom = attribute.toDouble();
928 if (bottom >= 0 && bottom <= 100)
929 region->setRelativeBottom(bottom/100);
931 else if (attributes[
"bottom"].contains(QRegExp(
"\\d+(.\\d+)?")))
933 QString attribute = attributes[
"bottom"];
935 qreal bottom = attribute.toDouble();
937 if (bottom >= 0 && bottom <= 1)
938 region->setRelativeBottom(bottom);
942 if (!attributes[
"width"].isEmpty())
944 if (attributes[
"width"].contains(QRegExp(
"\\d+(.\\d+)?%")))
946 QString attribute = attributes[
"width"];
947 attribute.remove(attribute.length()-1,1);
949 qreal width = attribute.toDouble();
951 if (width >= 0.0 && width <= 100.0)
952 region->setRelativeWidth(width/100);
954 else if (attributes[
"width"].contains(QRegExp(
"\\d+(.\\d+)?")))
956 QString attribute = attributes[
"width"];
958 qreal width = attribute.toDouble();
960 if (width >= 0 && width <= 1)
961 region->setRelativeWidth(width);
965 if (!attributes[
"height"].isEmpty()){
966 if (attributes[
"height"].contains(QRegExp(
"\\d+(.\\d+)?%")))
968 QString attribute = attributes[
"height"];
969 attribute.remove(attribute.length()-1,1);
971 qreal height = attribute.toDouble();
973 if (height >= 0 && height <= 100)
974 region->setRelativeHeight(height/100);
977 else if (attributes[
"height"].contains(QRegExp(
"\\d+(.\\d+)?")))
979 QString attribute = attributes[
"height"];
981 qreal height = attribute.toDouble();
983 if (height >= 0 && height <= 1)
984 region->setRelativeHeight(height);
988 if(attributes.contains(
"zIndex"))
989 region->setzIndex(attributes[
"zIndex"].toInt());
991 region->setGridAction(gridAction);
995 parent->addRegion(region);
1001 action =
new QAction(
this);
1002 action->setText(region->getId());
1004 showMenu->insertAction(showMenu->actions().front(), action);
1006 if (showMenu->actions().size() <= 2)
1008 showMenu->insertSeparator(showMenu->actions().back());
1011 action->setCheckable(
true);
1012 action->setChecked(
true);
1013 action->setEnabled(
true);
1015 regionActionGroup->addAction(action);
1017 regionActions[region->getUid()] = action;
1022 regions[region->getUid()] = region;
1033 SIGNAL(regionbasePerformed()),
1034 SIGNAL(regionbasePerformed()));
1052 QMap<QString, QString> noChangeAtts;
1054 requestRegionChange(region,noChangeAtts);
1056 emit requestRegionSelection(region);
1060 void QnlyGraphicsRegionBase::performChangeResolution()
1062 QAction* action =
dynamic_cast<QAction*
> (QObject::sender());
1065 QSize size = action->data().toSize();
1066 changeResolution(size.width(), size.height());
1070 void QnlyGraphicsRegionBase::changeResolution(
int w,
int h)
1072 setSceneRect(0, 0, w, h);
1073 bgrect->setRect(0, 0, w, h);
1074 grid->setRect(0, 0, w, h);
1083 if(re640x480->data().toSize() == size)
1085 re640x480->setChecked(
true);
1087 else if(re800x600->data().toSize() == size)
1089 re800x600->setChecked(
true);
1091 else if(re1024x768->data().toSize() == size)
1093 re1024x768->setChecked(
true);
1095 else if(re854x480->data().toSize() == size)
1097 re854x480->setChecked(
true);
1099 else if(re1280x720->data().toSize() == size)
1101 re1280x720->setChecked(
true);
1103 else if(re1920x1080->data().toSize() == size)
1105 re1920x1080->setChecked(
true);
1107 else if(re320x400->data().toSize() == size)
1109 re320x400->setChecked(
true);
1113 void QnlyGraphicsRegionBase::performGrid()
1115 setGridVisible(!isGridVisible());
1116 emit gridVisibilityChanged(isGridVisible());
1119 bool QnlyGraphicsRegionBase::isGridVisible()
1121 return grid->isVisible();
1124 void QnlyGraphicsRegionBase::setGridVisible(
bool visible)
1126 gridAction->setChecked(visible);
1127 grid->setVisible(visible);
1130 void QnlyGraphicsRegionBase::performExport()
1133 QFileDialog::getSaveFileName(NULL,
"Export...",
"", tr(
"Images (*.png)"));
1137 QImage image(width(), height(), QImage::Format_ARGB32_Premultiplied);
1139 QPainter painter(&image);
1141 render(&painter, QRect(), QRect(0,0,width(),height()));
1145 image.save(location,
"PNG");
1149 void QnlyGraphicsRegionBase::mousePressEvent(QGraphicsSceneMouseEvent* event)
1151 QGraphicsScene::mousePressEvent(event);
1153 if (!event->isAccepted())
1155 if (event->button() == Qt::RightButton)
1160 else if (event->button() == Qt::LeftButton){
1161 emit regionBaseSelectionRequested(uid);
1168 void QnlyGraphicsRegionBase::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
1170 if(selectedRegion != NULL)
1172 selectedRegion->updateCursor(event);
1175 QGraphicsScene::mouseMoveEvent(event);
1178 void QnlyGraphicsRegionBase::contextMenuEvent(
1179 QGraphicsSceneContextMenuEvent* event)
1181 QGraphicsScene::contextMenuEvent(event);
1183 if (!event->isAccepted())
1185 emit regionBaseSelectionRequested(uid);
1187 contextMenu->exec(event->screenPos());
1193 void QnlyGraphicsRegionBase::requestMediaOverRegionAction(QString mediaId,
1196 emit mediaOverRegion(mediaId, region->getUid());