+
+//virtual
+void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
+
+ if (m_selectedItem && e->buttons() & Qt::LeftButton) {
+ if (m_selectedItem->type() == 3 || m_selectedItem->type() == 13 || m_selectedItem->type() == 7) {
+ QRectF newrect;
+ if (m_selectedItem->type() == 3) {
+ newrect = ((QGraphicsRectItem*)m_selectedItem)->rect();
+ } else newrect = m_selectedItem->boundingRect();
+
+ QPointF newpoint = e->scenePos();
+ //newpoint -= m_selectedItem->scenePos();
+ switch (resizeMode) {
+ case TopLeft:
+ newrect.setBottomRight(newrect.bottomRight() + m_selectedItem->pos() - newpoint);
+ m_selectedItem->setPos(newpoint);
+ break;
+ case BottomLeft:
+ newrect.setBottomRight(QPointF(newrect.bottomRight().x() + m_selectedItem->pos().x() - newpoint.x(), newpoint.y() - m_selectedItem->pos().y()));
+ m_selectedItem->setPos(QPointF(newpoint.x(), m_selectedItem->pos().y()));
+ break;
+ case TopRight:
+ newrect.setBottomRight(QPointF(newpoint.x() - m_selectedItem->pos().x(), newrect.bottom() + m_selectedItem->pos().y() - newpoint.y()));
+ m_selectedItem->setPos(QPointF(m_selectedItem->pos().x(), newpoint.y()));
+ break;
+ case BottomRight:
+ newrect.setBottomRight(newpoint - m_selectedItem->pos());
+ break;
+ case Left:
+ newrect.setRight(m_selectedItem->pos().x() + newrect.width() - newpoint.x());
+ m_selectedItem->setPos(QPointF(newpoint.x(), m_selectedItem->pos().y()));
+ break;
+ case Right:
+ newrect.setRight(newpoint.x() - m_selectedItem->pos().x());
+ break;
+ case Up:
+ newrect.setBottom(m_selectedItem->pos().y() + newrect.bottom() - newpoint.y());
+ m_selectedItem->setPos(QPointF(m_selectedItem->pos().x(), newpoint.y()));
+ break;
+ case Down:
+ newrect.setBottom(newpoint.y() - m_selectedItem->pos().y());
+ break;
+ default:
+ QPointF diff = e->scenePos() - m_clickPoint;
+ m_clickPoint = e->scenePos();
+ m_selectedItem->moveBy(diff.x(), diff.y());
+ break;
+ }
+ if (m_selectedItem->type() == 3 && resizeMode != NoResize) {
+ QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
+ gi->setRect(newrect);
+ }
+ /*else {
+ qreal s;
+ if (resizeMode == Left || resizeMode == Right ) s = m_selectedItem->boundingRect().width() / newrect.width();
+ else s = m_selectedItem->boundingRect().height() / newrect.height();
+ m_selectedItem->scale( 1 / s, 1 / s );
+ kDebug()<<"/// SCALING SVG, RESIZE MODE: "<<resizeMode<<", RECT:"<<m_selectedItem->boundingRect();
+ }*/
+ //gi->setPos(m_selectedItem->scenePos());
+ /*if (resizeMode == NoResize) {
+ QGraphicsScene::mouseMoveEvent(e);
+ return;
+ }*/
+ } else if (m_selectedItem->type() == 8) {
+ QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
+ if (t->textInteractionFlags() & Qt::TextEditorInteraction) {
+ QGraphicsScene::mouseMoveEvent(e);
+ return;
+ }
+ QPointF diff = e->scenePos() - m_clickPoint;
+ m_clickPoint = e->scenePos();
+ m_selectedItem->moveBy(diff.x(), diff.y());
+ }
+ emit itemMoved();
+ } else if (m_tool == TITLE_SELECT) {
+
+ QPointF p = e->scenePos();
+ p += QPoint(-2, -2);
+ resizeMode = NoResize;
+ bool itemFound = false;
+ foreach(const QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) {
+ if ((g->type() == 13 || g->type() == 7) && g->zValue() > -1000) {
+ // image or svg item
+ setCursor(Qt::OpenHandCursor);
+ break;
+ } else if (g->type() == 3 && g->zValue() > -1000) {
+ QRectF r = ((QGraphicsRectItem*)g)->rect();
+ r.translate(g->scenePos());
+ itemFound = true;
+ if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+ setCursor(QCursor(Qt::SizeFDiagCursor));
+ } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+ setCursor(QCursor(Qt::SizeBDiagCursor));
+ } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+ setCursor(QCursor(Qt::SizeBDiagCursor));
+ } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+ setCursor(QCursor(Qt::SizeFDiagCursor));
+ } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / zoom) {
+ setCursor(Qt::SizeHorCursor);
+ } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / zoom) {
+ setCursor(Qt::SizeHorCursor);
+ } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / zoom) {
+ setCursor(Qt::SizeVerCursor);
+ } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) {
+ setCursor(Qt::SizeVerCursor);
+ } else setCursor(Qt::OpenHandCursor);
+ break;
+ }
+ if (!itemFound) setCursor(Qt::ArrowCursor);
+ }
+ QGraphicsScene::mouseMoveEvent(e);
+ } else if (m_tool == TITLE_RECTANGLE && e->buttons() & Qt::LeftButton) {
+ if (m_selectedItem == NULL && (m_clickPoint.toPoint() - e->scenePos().toPoint()).manhattanLength() >= QApplication::startDragDistance()) {
+ // create new rect item
+ m_selectedItem = addRect(0, 0, e->scenePos().x() - m_clickPoint.x(), e->scenePos().y() - m_clickPoint.y());
+ emit newRect((QGraphicsRectItem *) m_selectedItem);
+ m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ m_selectedItem->setPos(m_clickPoint);
+ resizeMode = BottomRight;
+ QGraphicsScene::mouseMoveEvent(e);
+ }
+ }
+}
+
+void GraphicsSceneRectMove::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent) {
+ QList<QGraphicsView*> viewlist = views();
+ //kDebug() << wheelEvent->delta() << " " << zoom;
+ double scale = 1.0;
+ if (viewlist.size() > 0) {
+ if (wheelEvent->delta() < 0) emit sceneZoom(true);
+ else emit sceneZoom(false);
+ }