18 #include "qnlygraphicsregion.h"
22 QnlyGraphicsRegion::QnlyGraphicsRegion(QMenu* switchMenu,
24 : QObject(parent), QGraphicsItem(parent)
26 this->switchMenu = switchMenu;
28 this->switchMenu->setEnabled(
true);
36 setFlag(QGraphicsItem::ItemIsMovable,
true);
37 setFlag(QGraphicsItem::ItemIsFocusable,
true);
63 QnlyGraphicsRegion::~QnlyGraphicsRegion()
71 bool QnlyGraphicsRegion::isMoving()
const
78 QObject::setParent(region);
79 setParentItem(region);
82 void QnlyGraphicsRegion::setMoving(
bool moving)
84 this->moving = moving;
86 setCursor(QCursor(Qt::ClosedHandCursor));
88 setCursor(QCursor(Qt::ArrowCursor));
91 bool QnlyGraphicsRegion::isResizing()
const
96 void QnlyGraphicsRegion::setResizing(
bool resizing)
98 this->resizing = resizing;
101 bool QnlyGraphicsRegion::isSelected()
const
106 void QnlyGraphicsRegion::setSelected(
bool selected)
108 this->selected = selected;
111 setFocus(Qt::MouseFocusReason);
114 bool QnlyGraphicsRegion::isValidated()
const
119 void QnlyGraphicsRegion::setValidated(
bool validated)
121 this->validated = validated;
124 QString QnlyGraphicsRegion::getId()
const
129 void QnlyGraphicsRegion::setId(
const QString &
id)
133 setToolTip(title+
" "+
"("+
id+
")");
135 if (parentItem() != NULL)
138 parent->updateActionText(
this);
145 s->updateActionText(
this);
149 QString QnlyGraphicsRegion::getUid()
const
154 void QnlyGraphicsRegion::setUid(
const QString &uid)
159 QString QnlyGraphicsRegion::getTitle()
const
164 void QnlyGraphicsRegion::setTitle(
const QString &title)
168 setToolTip(title+
" "+
"("+
id+
")");
171 QString QnlyGraphicsRegion::getColor()
const
176 void QnlyGraphicsRegion::setColor(
const QString &color)
181 bool QnlyGraphicsRegion::isPainted()
const
186 void QnlyGraphicsRegion::setPainted(
bool painted)
188 this->painted = painted;
191 void QnlyGraphicsRegion::setzIndex(
int zindex)
193 this->zindex = zindex;
198 int QnlyGraphicsRegion::getzIndex()
const
203 void QnlyGraphicsRegion::setzIndexTop(qreal zindexTop)
205 this->zindexTop = zindexTop;
208 qreal QnlyGraphicsRegion::getzIndexTop()
const
213 qreal QnlyGraphicsRegion::getTop()
const
218 void QnlyGraphicsRegion::setTop(qreal top)
225 qreal QnlyGraphicsRegion::getMoveTop()
const
230 void QnlyGraphicsRegion::setMoveTop(qreal moveTop)
232 this->moveTop = moveTop;
235 qreal QnlyGraphicsRegion::getPressTop()
const
240 void QnlyGraphicsRegion::setPressTop(qreal pressTop)
242 this->pressTop = pressTop;
245 qreal QnlyGraphicsRegion::getResizeTop()
const
250 void QnlyGraphicsRegion::setResizeTop(qreal resizeTop)
252 this->resizeTop = resizeTop;
255 qreal QnlyGraphicsRegion::getRelativeTop()
const
260 void QnlyGraphicsRegion::setRelativeTop(qreal relativeTop)
262 this->relativeTop = relativeTop;
265 qreal QnlyGraphicsRegion::getLeft()
const
270 void QnlyGraphicsRegion::setLeft(qreal left)
277 qreal QnlyGraphicsRegion::getMoveLeft()
const
282 void QnlyGraphicsRegion::setMoveLeft(qreal moveLeft)
284 this->moveLeft = moveLeft;
287 qreal QnlyGraphicsRegion::getPressLeft()
const
292 void QnlyGraphicsRegion::setPressLeft(qreal pressLeft)
294 this->pressLeft = pressLeft;
297 qreal QnlyGraphicsRegion::getResizeLeft()
const
302 void QnlyGraphicsRegion::setResizeLeft(qreal resizeLeft)
304 this->resizeLeft = resizeLeft;
307 qreal QnlyGraphicsRegion::getRelativeLeft()
const
312 void QnlyGraphicsRegion::setRelativeLeft(qreal relativeLeft)
314 this->relativeLeft = relativeLeft;
317 qreal QnlyGraphicsRegion::getRight()
const
322 void QnlyGraphicsRegion::setRight(qreal right)
327 qreal QnlyGraphicsRegion::getRelativeRight()
const
329 return relativeRight;
332 void QnlyGraphicsRegion::setRelativeRight(qreal relativeRight)
334 this->relativeRight = relativeRight;
337 qreal QnlyGraphicsRegion::getBottom()
const
342 void QnlyGraphicsRegion::setBottom(qreal bottom)
344 this->bottom = bottom;
347 qreal QnlyGraphicsRegion::getRelativeBottom()
const
349 return relativeBottom;
352 void QnlyGraphicsRegion::setRelativeBottom(qreal relativeBottom)
354 this->relativeBottom = relativeBottom;
357 qreal QnlyGraphicsRegion::getWidth()
const
362 void QnlyGraphicsRegion::setWidth(qreal width)
367 qreal QnlyGraphicsRegion::getPressWidth()
const
372 void QnlyGraphicsRegion::setPressWidth(qreal pressWidth)
374 this->pressWidth = pressWidth;
377 qreal QnlyGraphicsRegion::getResizeWidth()
const
382 bool QnlyGraphicsRegion::hasChanged()
const
387 void QnlyGraphicsRegion::setChanged(
bool changed)
389 this->changed = changed;
392 void QnlyGraphicsRegion::setResizeWidth(qreal resizeWidth)
394 this->resizeWidth = resizeWidth;
397 qreal QnlyGraphicsRegion::getRelativeWidth()
const
399 return relativeWidth;
402 void QnlyGraphicsRegion::setRelativeWidth(qreal relativeWidth)
404 this->relativeWidth = relativeWidth;
407 qreal QnlyGraphicsRegion::getHeight()
const
412 void QnlyGraphicsRegion::setHeight(qreal height)
414 this->height = height;
417 qreal QnlyGraphicsRegion::getPressHeight()
const
422 void QnlyGraphicsRegion::setPressHeight(qreal pressHeight)
424 this->pressHeight = pressHeight;
427 qreal QnlyGraphicsRegion::getResizeHeight()
const
432 void QnlyGraphicsRegion::setResizeHeight(qreal resizeHeight)
434 this->resizeHeight = resizeHeight;
437 qreal QnlyGraphicsRegion::getRelativeHeight()
const
439 return relativeHeight;
442 void QnlyGraphicsRegion::setRelativeHeight(qreal relativeHeight)
444 this->relativeHeight = relativeHeight;
447 QnlyGraphicsRegion::QnlyResizeType QnlyGraphicsRegion::getResizeType()
const
452 void QnlyGraphicsRegion::setResizeType(
const QnlyResizeType &resizeType)
454 this->resizeType = resizeType;
457 void QnlyGraphicsRegion::QnlyGraphicsRegion::createActions()
460 helpAction =
new QAction(
this);
461 helpAction->setText(tr(
"Help"));
463 helpAction->setEnabled(
false);
464 helpAction->setShortcut(QKeySequence(
"F1"));
467 undoAction =
new QAction(
this);
468 undoAction->setText(tr(
"Undo"));
470 undoAction->setEnabled(
false);
471 undoAction->setShortcut(QKeySequence(
"Ctrl+Z"));
474 redoAction =
new QAction(
this);
475 redoAction->setText(tr(
"Redo"));
477 redoAction->setEnabled(
false);
478 redoAction->setShortcut(QKeySequence(
"Ctrl+Shift+Z"));
481 cutAction =
new QAction(
this);
482 cutAction->setText(tr(
"Cut"));
484 cutAction->setEnabled(
false);
485 cutAction->setShortcut(QKeySequence(
"Ctrl+X"));
488 copyAction =
new QAction(
this);
489 copyAction->setText(tr(
"Copy"));
491 copyAction->setEnabled(
false);
492 copyAction->setShortcut(QKeySequence(
"Ctrl+C"));
495 pasteAction =
new QAction(
this);
496 pasteAction->setText(tr(
"Paste"));
498 pasteAction->setEnabled(
false);
499 pasteAction->setShortcut(QKeySequence(
"Ctrl+V"));
502 deleteAction =
new QAction(
this);
503 deleteAction->setText(tr(
"Delete"));
505 deleteAction->setEnabled(
true);
506 deleteAction->setShortcut(QKeySequence(
"Del"));
509 zoominAction =
new QAction(
this);
510 zoominAction->setText(tr(
"Zoom In"));
512 zoominAction->setEnabled(
true);
513 zoominAction->setShortcut(QKeySequence(
"Ctrl++"));
516 zoomoutAction =
new QAction(
this);
517 zoomoutAction->setText(tr(
"Zoom Out"));
519 zoomoutAction->setEnabled(
true);
520 zoomoutAction->setShortcut(QKeySequence(
"Ctrl+-"));
523 zoomresetAction =
new QAction(
this);
524 zoomresetAction->setText(tr(
"Reset"));
526 zoomresetAction->setEnabled(
true);
527 zoomresetAction->setShortcut(QKeySequence(
"Ctrl+0"));
530 fullscreenAction =
new QAction(
this);
531 fullscreenAction->setText(tr(
"Full Screen"));
533 fullscreenAction->setEnabled(
true);
534 fullscreenAction->setShortcut(QKeySequence(
"F11"));
537 exportAction =
new QAction(
this);
538 exportAction->setText(tr(
"Export..."));
540 exportAction->setEnabled(
true);
543 regionAction =
new QAction(
this);
544 regionAction->setText(tr(
"Region"));
546 regionAction->setEnabled(
true);
549 regionbaseAction =
new QAction(
this);
550 regionbaseAction->setText(tr(
"Regionbase"));
552 regionbaseAction->setEnabled(
true);
555 bringfrontAction =
new QAction(
this);
556 bringfrontAction->setText(tr(
"Bring to Front"));
558 bringfrontAction->setEnabled(
false);
559 bringfrontAction->setShortcut(QKeySequence(
"Shift+Ctrl+]"));
562 bringforwardAction =
new QAction(
this);
563 bringforwardAction->setText(tr(
"Bring Forward"));
565 bringforwardAction->setEnabled(
false);
566 bringforwardAction->setShortcut(QKeySequence(
"Ctrl+]"));
569 sendbackwardAction =
new QAction(
this);
570 sendbackwardAction->setText(tr(
"Send Backward"));
572 sendbackwardAction->setEnabled(
false);
573 sendbackwardAction->setShortcut(QKeySequence(
"Ctrl+["));
576 sendbackAction =
new QAction(
this);
577 sendbackAction->setText(tr(
"Send to Back"));
579 sendbackAction->setEnabled(
false);
580 sendbackAction->setShortcut(QKeySequence(
"Shift+Ctrl+["));
583 hideAction =
new QAction(
this);
584 hideAction->setText(tr(
"Hide"));
586 hideAction->setEnabled(
true);
589 propertiesAction =
new QAction(
this);
590 propertiesAction->setText(tr(
"Properties"));
592 propertiesAction->setEnabled(
true);
594 regionActionGroup =
new QActionGroup(
this);
595 regionActionGroup->setExclusive(
false);
597 setAcceptDrops(
true);
600 void QnlyGraphicsRegion::setGridAction(QAction* action)
604 showMenu->addAction(gridAction);
608 void QnlyGraphicsRegion::createMenus()
611 viewMenu =
new QMenu();
612 viewMenu->setTitle(tr(
"View"));
614 viewMenu->setEnabled(
true);
616 viewMenu->addAction(zoominAction);
617 viewMenu->addAction(zoomoutAction);
618 viewMenu->addAction(zoomresetAction);
619 viewMenu->addSeparator();
620 viewMenu->addAction(fullscreenAction);
623 insertMenu =
new QMenu();
624 insertMenu->setTitle(tr(
"Insert"));
626 insertMenu->setEnabled(
true);
628 insertMenu->addAction(regionAction);
629 insertMenu->addAction(regionbaseAction);
632 showMenu =
new QMenu();
633 showMenu->setTitle(tr(
"Show"));
635 showMenu->setEnabled(
true);
638 arrangeMenu =
new QMenu();
639 arrangeMenu->setTitle(tr(
"Arrange"));
641 arrangeMenu->setEnabled(
false);
643 arrangeMenu->addAction(bringfrontAction);
644 arrangeMenu->addAction(bringforwardAction);
645 arrangeMenu->addAction(sendbackwardAction);
646 arrangeMenu->addAction(sendbackAction);
649 contextMenu =
new QMenu();
650 contextMenu->addAction(helpAction);
651 contextMenu->addSeparator();
659 contextMenu->addAction(deleteAction);
660 contextMenu->addSeparator();
661 contextMenu->addAction(exportAction);
662 contextMenu->addSeparator();
664 contextMenu->addMenu(insertMenu);
665 contextMenu->addMenu(showMenu);
667 contextMenu->addSeparator();
668 contextMenu->addAction(hideAction);
669 contextMenu->addSeparator();
670 contextMenu->addMenu(switchMenu);
675 void QnlyGraphicsRegion::createConnections()
677 connect(regionActionGroup, SIGNAL(triggered(QAction*)),
678 SLOT(performShow(QAction*)));
680 connect(regionbaseAction, SIGNAL(triggered()),
681 SIGNAL(regionbasePerformed()));
683 connect(regionAction, SIGNAL(triggered()),
684 SLOT(performRegion()));
686 connect(hideAction, SIGNAL(triggered()),
687 SLOT(performHide()));
689 connect(deleteAction, SIGNAL(triggered()),
690 SLOT(performDelete()));
692 connect(exportAction, SIGNAL(triggered()), SLOT(performExport()));
698 if(regionActions.contains(region->getUid()))
699 regionActions[region->getUid()]->setText(region->getId());
704 regionActions[region->getUid()]->trigger();
707 void QnlyGraphicsRegion::performDelete()
709 emit regionDeletionRequested(
this);
712 void QnlyGraphicsRegion::performExport()
714 QString location = QFileDialog::getSaveFileName(NULL,
"Export...",
"", tr(
"Images (*.png)"));
718 qreal w = getWidth()+8;
719 qreal h = getHeight()+8;
721 QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
723 QPainter painter(&image);
725 QPointF p = mapToScene(0,0);
727 scene()->render(&painter, QRect(), QRect(p.x(),p.y(),w,h));
731 image.save(location,
"PNG");
735 void QnlyGraphicsRegion::performHide()
737 if (parentItem() != NULL)
741 parent->hideRegion(
this);
751 void QnlyGraphicsRegion::performRegion()
753 emit regionAdditionRequested(
this);
756 void QnlyGraphicsRegion::performShow(QAction* action)
758 if (!action->isChecked())
760 regions[regionActions.key(action)]->setVisible(
false);
764 regions[regionActions.key(action)]->setVisible(
true);
770 if(regionActions.contains(region->getUid()))
772 QAction *action = regionActions[region->getUid()];
774 showMenu->removeAction(action);
776 regionActionGroup->removeAction(action);
779 regionActions.remove(region->getUid());
786 region->setParent(
this);
788 region->setGridAction(gridAction);
790 regions[region->getUid()] = region;
792 QAction* action =
new QAction(
this);
793 action->setText(region->getId());
795 showMenu->addAction(action);
797 showMenu->insertAction(showMenu->actions().front(), action);
799 if (showMenu->actions().size() <= 2){
800 showMenu->insertSeparator(showMenu->actions().back());
803 action->setCheckable(
true);
804 action->setChecked(
true);
805 action->setEnabled(
true);
807 regionActionGroup->addAction(action);
809 regionActions[region->getUid()] = action;
813 void QnlyGraphicsRegion::move(QGraphicsSceneMouseEvent* event)
823 if (parentItem() != NULL)
838 if (parentItem() != NULL)
840 maxx = parentItem()->boundingRect().width() - width - 4;
841 maxy = parentItem()->boundingRect().height() - height - 4;
845 maxx = scene()->width() - width;
846 maxy = scene()->height() - height;
850 qreal dx =
event->pos().x() - pressLeft;
851 qreal dy =
event->pos().y() - pressTop;
854 qreal nextx = x + dx;
855 qreal nexty = y + dy;
885 void QnlyGraphicsRegion::resize(QGraphicsSceneMouseEvent* event)
899 if (parentItem() != NULL)
920 if (parentItem() != NULL)
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;
929 maxx = scene()->width() - width;
930 maxy = scene()->height() - height;
931 maxw = scene()->width();
932 maxh = scene()->height();
936 qreal dx =
event->pos().x() - pressLeft;
937 qreal dy =
event->pos().y() - pressTop;
942 qreal nextx = x + dx;
943 qreal nexty = y + dy;
944 qreal nextw = w + dw;
945 qreal nexth = h + dh;
951 case QnlyGraphicsRegion::TopLeft:
956 nextw = x + w - minx;
962 nexth = y + h - miny;
967 case QnlyGraphicsRegion::Top:
975 nexth = y + h - miny;
982 case QnlyGraphicsRegion::TopRight:
987 if (x + nextw > maxw)
995 nexth = y + h - miny;
1002 case QnlyGraphicsRegion::Right:
1007 if (x + nextw > maxw)
1019 case QnlyGraphicsRegion::BottomRight:
1024 if (x + nextw > maxw){
1031 if (y + nexth > maxh)
1040 case QnlyGraphicsRegion::Bottom:
1048 if (y + nexth > maxh)
1057 case QnlyGraphicsRegion::BottomLeft:
1062 nextw = x + w - minx;
1068 if (y + nexth > maxh)
1077 case QnlyGraphicsRegion::Left:
1082 nextw = x + w - minx;
1093 setResizeTop(nexty);
1094 setResizeLeft(nextx);
1095 setResizeWidth(nextw);
1096 setResizeHeight(nexth);
1101 void QnlyGraphicsRegion::adjust(
bool repaint)
1103 if (parentItem() != NULL)
1107 setTop(qRound(item->getHeight()*relativeTop + 4));
1108 setLeft(qRound(item->getWidth()*relativeLeft + 4));
1110 setWidth(qRound(item->getWidth()*relativeWidth));
1111 setHeight(qRound(item->getHeight()*relativeHeight));
1113 setRight(item->getWidth() - (left+width));
1114 setBottom(item->getHeight() - (top+height));
1119 setTop(qRound(scene()->height()*relativeTop));
1120 setLeft(qRound(scene()->width()*relativeLeft));
1122 setWidth(qRound(scene()->width()*relativeWidth));
1123 setHeight(qRound(scene()->height()*relativeHeight));
1125 setRight(scene()->width() - (left+width));
1126 setBottom(scene()->height() - (top+height));
1129 for (
int i=0;i<childItems().size();++i)
1133 item->adjust(
false);
1142 QPainterPath QnlyGraphicsRegion::shape()
const
1146 path.addRect(4, 4, width, height);
1150 path.setFillRule(Qt::WindingFill);
1152 path.addRect(0,0,8,8);
1153 path.addRect((width+8)/2 - 4,0,8,8);
1154 path.addRect((width+8) - 8,0,8,8);
1155 path.addRect((width+8) - 8,(height+8)/2 - 4,8,8);
1156 path.addRect((width+8) - 8,(height+8) - 8,8,8);
1157 path.addRect((width+8)/2 - 4,(height+8) - 8,8,8);
1158 path.addRect(0,(height+8) - 8,8,8);
1159 path.addRect(0,(height+8)/2 - 4,8,8);
1165 QRectF QnlyGraphicsRegion::boundingRect()
const
1171 bounds.setWidth(width+8);
1172 bounds.setHeight(height+8);
1177 void QnlyGraphicsRegion::paint(QPainter *painter,
1178 const QStyleOptionGraphicsItem *option,
1183 painter->setBrush(QColor(color));
1184 painter->setPen(QPen(QBrush(Qt::black), 0, Qt::DashLine));
1185 painter->drawRect(4,4,width-1,height-1);
1189 painter->setBrush(QColor(color));
1190 painter->setPen(QPen(QBrush(Qt::black), 0));
1191 painter->drawRect(4,4,width-1,height-1);
1196 if (parentItem() != NULL)
1198 painter->setBrush(Qt::NoBrush);
1199 painter->setPen(QPen(QBrush(Qt::black), 0));
1200 painter->drawRect(moveLeft+4-left,moveTop+4-top,width-1,height-1);
1204 painter->setBrush(Qt::NoBrush);
1205 painter->setPen(QPen(QBrush(Qt::black), 0));
1206 painter->drawRect(moveLeft+4-left,moveTop+4-top,width-1,height-1);
1211 painter->setBrush(Qt::NoBrush);
1212 painter->setPen(QPen(QBrush(Qt::black), 0));
1213 painter->drawRect(resizeLeft+4-left,resizeTop+4-top,resizeWidth-1,resizeHeight-1);
1217 painter->setBrush(QBrush(Qt::white));
1218 painter->setPen(QPen(QBrush(QBrush(Qt::black)), 0));
1220 painter->drawRect(0,0,8,8);
1221 painter->drawRect((width+8)/2-4-1,0,8,8);
1222 painter->drawRect((width+8)-8-1,0,8,8);
1223 painter->drawRect((width+8)-8-1,(height+8)/2-4-1,8,8);
1224 painter->drawRect((width+8)-8-1,(height+8)-8-1,8,8);
1225 painter->drawRect((width+8)/2-4-1,(height+8)-8-1,8,8);
1226 painter->drawRect(0,(height+8)-8-1,8,8);
1227 painter->drawRect(0,(height+8)/2-4-1,8,8);
1232 if (width >= 25 && height >= 25 &&
id !=
"")
1234 text = title+
" "+
"("+
id+
")";
1237 painter->drawText(4+6,4+6,width-1-4-6,height-1-4-6,Qt::AlignLeft, text);
1240 void QnlyGraphicsRegion::updateCursor(QGraphicsSceneMouseEvent* event)
1242 Qt::CursorShape newShape;
1243 if(!resizing && !moving)
1245 QPointF pos = mapFromScene(event->scenePos());
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))
1251 newShape = Qt::SizeVerCursor;
1255 else if (QRectF(0,0,8,8).contains(pos) ||
1256 QRectF((width+8) - 8,(height+8) - 8,8,8).contains(pos))
1259 newShape = Qt::SizeFDiagCursor;
1263 else if (QRectF((width+8) - 8,0,8,8).contains(pos) ||
1264 QRectF(0,(height+8) - 8,8,8).contains(pos))
1266 newShape = Qt::SizeBDiagCursor;
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))
1273 newShape = Qt::SizeHorCursor;
1278 newShape = Qt::ArrowCursor;
1281 if(newShape != cursor().shape())
1283 setCursor(newShape);
1288 void QnlyGraphicsRegion::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
1300 void QnlyGraphicsRegion::mousePressEvent(QGraphicsSceneMouseEvent* event)
1302 if (event->button() == Qt::RightButton)
1307 else if (event->button() == Qt::LeftButton)
1309 emit regionSelectionRequested(
this);
1311 setPressTop(event->pos().y());
1312 setPressLeft(event->pos().x());
1313 setPressWidth(width);
1314 setPressHeight(height);
1322 setResizeLeft(left);
1323 setResizeWidth(width);
1324 setResizeHeight(height);
1327 if (QRectF(0,0,8,8).contains(event->pos()))
1329 setResizeType(QnlyGraphicsRegion::TopLeft);
1333 else if (QRectF((width+8)/2 - 4,0,8,8).contains(event->pos()))
1335 setResizeType(QnlyGraphicsRegion::Top);
1339 else if (QRectF((width+8) - 8,0,8,8).contains(event->pos()))
1341 setResizeType(QnlyGraphicsRegion::TopRight);
1345 else if (QRectF((width+8) - 8,(height+8)/2 - 4,8,8).contains(event->pos()))
1347 setResizeType(QnlyGraphicsRegion::Right);
1351 else if (QRectF((width+8) - 8,(height+8) - 8,8,8).contains(event->pos()))
1353 setResizeType(QnlyGraphicsRegion::BottomRight);
1357 else if (QRectF((width+8)/2 - 4,(height+8) - 8,8,8).contains(event->pos()))
1359 setResizeType(QnlyGraphicsRegion::Bottom);
1363 else if (QRectF(0,(height+8) - 8,8,8).contains(event->pos()))
1365 setResizeType(QnlyGraphicsRegion::BottomLeft);
1369 else if (QRectF(0,(height+8)/2 - 4,8,8).contains(event->pos()))
1371 setResizeType(QnlyGraphicsRegion::Left);
1383 QGraphicsItem::mousePressEvent(event);
1386 void QnlyGraphicsRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
1392 if ((top != moveTop || left != moveLeft))
1421 QMap<QString, QString> attributes;
1424 if (parentItem() != NULL)
1428 value = ((moveTop-4)/item->getHeight()) * 100;
1429 ROUND_DOUBLE(value);
1430 attributes[
"top"] = QString::number(value,
'f', 2) +
"%";
1432 value = ((moveLeft-4)/item->getWidth()) * 100;
1433 ROUND_DOUBLE(value);
1434 attributes[
"left"] = QString::number(value,
'f', 2) +
"%";
1436 value = (1 - (((moveLeft-4)/item->getWidth())+(width/item->getWidth()))) * 100;
1437 ROUND_DOUBLE(value);
1438 attributes[
"right"] = QString::number(value,
'f', 2) +
"%";
1440 value = (1 - (((moveTop-4)/item->getHeight())+(height/item->getHeight())))*100;
1441 ROUND_DOUBLE(value);
1442 attributes[
"bottom"] = QString::number(value,
'f', 2) +
"%";
1447 value = ((moveTop)/scene()->height())*100;
1448 ROUND_DOUBLE(value);
1449 attributes[
"top"] = QString::number(value,
'f', 2) +
"%";
1451 value = ((moveLeft)/scene()->width())*100;
1452 ROUND_DOUBLE(value);
1453 attributes[
"left"] = QString::number(value,
'f', 2) +
"%";
1455 value = (1 - (((moveLeft)/scene()->width())+(width/scene()->width())))*100;
1456 ROUND_DOUBLE(value);
1457 attributes[
"right"] = QString::number(value,
'f', 2) +
"%";
1459 value = (1 - (((moveTop)/scene()->height())+(height/scene()->height())))*100;
1460 ROUND_DOUBLE(value);
1461 attributes[
"bottom"] = QString::number(value,
'f', 2) +
"%";
1465 attributes[
"zIndex"] = QString::number(getzIndex());
1469 emit regionChangeRequested(
this,attributes);
1477 if ((top != resizeTop || left != resizeLeft ||
1478 width != resizeWidth || height != resizeHeight))
1480 if (resizeTop > top + height)
1482 setResizeHeight(resizeTop - (top + height));
1483 setResizeTop(top + height);
1486 if (resizeLeft > left + width)
1488 setResizeWidth(resizeLeft - (left + width));
1489 setResizeLeft(left + width);
1492 if (resizeWidth < 0)
1494 setResizeLeft(resizeLeft + resizeWidth);
1495 setResizeWidth(-resizeWidth);
1498 if (resizeHeight < 0)
1500 setResizeTop(resizeTop + resizeHeight);
1501 setResizeHeight(-resizeHeight);
1531 QMap<QString, QString> attributes;
1534 if (parentItem() != NULL)
1538 value = ((resizeTop-4)/item->getHeight())*100;
1539 ROUND_DOUBLE(value);
1540 attributes[
"top"] = QString::number(value,
'f', 2) +
"%";
1542 value = ((resizeLeft-4)/item->getWidth())*100;
1543 ROUND_DOUBLE(value);
1544 attributes[
"left"] = QString::number(value,
'f', 2) +
"%";
1546 value = (resizeHeight/item->getHeight())*100;
1547 ROUND_DOUBLE(value);
1548 attributes[
"height"] = QString::number(value,
'f', 2) +
"%";
1550 value = (resizeWidth/item->getWidth())*100;
1551 ROUND_DOUBLE(value);
1552 attributes[
"width"] = QString::number(value,
'f', 2) +
"%";
1554 value = (1 - (((resizeLeft-4)/item->getWidth())+(resizeWidth/item->getWidth())))*100;
1555 ROUND_DOUBLE(value);
1556 attributes[
"right"] = QString::number(value,
'f', 2) +
"%";
1558 value = (1 - (((resizeTop-4)/item->getHeight())+(resizeHeight/item->getHeight())))*100;
1559 ROUND_DOUBLE(value);
1560 attributes[
"bottom"] = QString::number(value,
'f', 2) +
"%";
1564 value = ((resizeTop)/scene()->height())*100;
1565 ROUND_DOUBLE(value);
1566 attributes[
"top"] = QString::number(value,
'f', 2) +
"%";
1568 value = ((resizeLeft)/scene()->width())*100;
1569 ROUND_DOUBLE(value);
1570 attributes[
"left"] = QString::number(value,
'f', 2) +
"%";
1572 value = (resizeHeight/scene()->height())*100;
1573 ROUND_DOUBLE(value);
1574 attributes[
"height"] = QString::number(value,
'f', 2) +
"%";
1576 value = (resizeWidth/scene()->width())*100;
1577 ROUND_DOUBLE(value);
1578 attributes[
"width"] = QString::number(value,
'f', 2) +
"%";
1580 value = (1 - (((resizeLeft)/scene()->width())+(resizeWidth/scene()->width())))*100;
1581 ROUND_DOUBLE(value);
1582 attributes[
"right"] = QString::number(value,
'f', 2) +
"%";
1584 value = (1 - (((resizeTop)/scene()->height())+(resizeHeight/scene()->height())))*100;
1585 ROUND_DOUBLE(value);
1586 attributes[
"bottom"] = QString::number(value,
'f', 2) +
"%";
1589 attributes[
"zIndex"] = QString::number(getzIndex());
1593 emit regionChangeRequested(
this, attributes);
1599 QGraphicsItem::mouseReleaseEvent(event);
1602 void QnlyGraphicsRegion::keyPressEvent( QKeyEvent * event )
1604 if (event->key() == Qt::Key_Delete ||
event->key() == Qt::Key_Backspace)
1611 QGraphicsItem::keyPressEvent(event);
1614 void QnlyGraphicsRegion::keyReleaseEvent( QKeyEvent * event )
1616 QGraphicsItem::keyReleaseEvent(event);
1620 void QnlyGraphicsRegion::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
1622 QGraphicsItem::contextMenuEvent(event);
1624 if (!event->isAccepted())
1626 emit regionSelectionRequested(
this);
1628 contextMenu->exec(event->screenPos());
1634 void QnlyGraphicsRegion::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1636 if (event->mimeData()->hasFormat(
"nclcomposer/mediaid"))
1637 event->acceptProposedAction();
1640 void QnlyGraphicsRegion::dropEvent(QGraphicsSceneDragDropEvent *event)
1642 qDebug() <<
"dropEvent " <<
event->mimeData()->data(
"nclcomposer/mediaid")
1643 <<
event->mimeData()->data(
"nclcomposer/qnstuid");
1646 emit dragMediaOverRegion(event->mimeData()->data(
"nclcomposer/mediaid"),