]> git.sesse.net Git - kdenlive/blob - src/graphicsscenerectmove.cpp
Fix a couple of compile warnings because of unused and uninitialized variables.
[kdenlive] / src / graphicsscenerectmove.cpp
1 /***************************************************************************
2  *   copyright (C) 2008 by Marco Gittler (g.marco@freenet.de)                                 *
3  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
19  ***************************************************************************/
20
21 #include "graphicsscenerectmove.h"
22
23 #include <KDebug>
24 #include <QGraphicsSceneMouseEvent>
25 #include <QGraphicsRectItem>
26 #include <QGraphicsSvgItem>
27 #include <QGraphicsView>
28 #include <QCursor>
29 #include <QTextCursor>
30 #include <QList>
31 #include <QKeyEvent>
32 #include <QApplication>
33 #include <QTextBlock>
34
35
36 GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent) :
37         QGraphicsScene(parent),
38         m_selectedItem(NULL),
39         m_resizeMode(NoResize),
40         m_tool(TITLE_RECTANGLE)
41 {
42     //grabMouse();
43     m_zoom = 1.0;
44     setBackgroundBrush(QBrush(Qt::transparent));
45     m_fontSize = 0;
46 }
47
48 void GraphicsSceneRectMove::setSelectedItem(QGraphicsItem *item)
49 {
50     clearSelection();
51     m_selectedItem = item;
52     item->setSelected(true);
53     update();
54 }
55
56 TITLETOOL GraphicsSceneRectMove::tool()
57 {
58     return m_tool;
59 }
60
61 void GraphicsSceneRectMove::setTool(TITLETOOL tool)
62 {
63     m_tool = tool;
64     switch (m_tool) {
65     case TITLE_RECTANGLE:
66         setCursor(Qt::CrossCursor);
67         break;
68     case TITLE_TEXT:
69         setCursor(Qt::IBeamCursor);
70         break;
71     default:
72         setCursor(Qt::ArrowCursor);
73     }
74 }
75
76 void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent)
77 {
78     if (m_selectedItem == NULL || !(m_selectedItem->flags() & QGraphicsItem::ItemIsMovable)) {
79         QGraphicsScene::keyPressEvent(keyEvent);
80         return;
81     }
82     int diff = 1;
83     if (m_selectedItem->type() == 8) {
84         QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
85         if (t->textInteractionFlags() & Qt::TextEditorInteraction) {
86             QGraphicsScene::keyPressEvent(keyEvent);
87             return;
88         }
89     }
90     if (keyEvent->modifiers() & Qt::ControlModifier) diff = 10;
91     switch (keyEvent->key()) {
92     case Qt::Key_Left:
93         m_selectedItem->setPos(m_selectedItem->pos() - QPointF(diff, 0));
94         emit itemMoved();
95         break;
96     case Qt::Key_Right:
97         m_selectedItem->setPos(m_selectedItem->pos() + QPointF(diff, 0));
98         emit itemMoved();
99         break;
100     case Qt::Key_Up:
101         m_selectedItem->setPos(m_selectedItem->pos() - QPointF(0, diff));
102         emit itemMoved();
103         break;
104     case Qt::Key_Down:
105         m_selectedItem->setPos(m_selectedItem->pos() + QPointF(0, diff));
106         emit itemMoved();
107         break;
108     case Qt::Key_Delete:
109     case Qt::Key_Backspace:
110         delete m_selectedItem;
111         m_selectedItem = NULL;
112         emit selectionChanged();
113         break;
114     default:
115         QGraphicsScene::keyPressEvent(keyEvent);
116     }
117     emit actionFinished();
118 }
119
120 void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e)
121 {
122     QPointF p = e->scenePos();
123     p += QPoint(-2, -2);
124     m_resizeMode = NoResize;
125     m_selectedItem = NULL;
126
127     // http://www.kdenlive.org/mantis/view.php?id=1035
128     QList<QGraphicsItem*> i = items(QRectF(p , QSizeF(4, 4)).toRect());
129     if (i.size() <= 0) return;
130
131     QGraphicsItem* g = i.at(0);
132     if (g) {
133         if (g->type() == 8) {
134             QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(g);
135             m_selectedItem = g;
136             t->setTextInteractionFlags(Qt::TextEditorInteraction);
137         } else emit doubleClickEvent();
138     }
139     QGraphicsScene::mouseDoubleClickEvent(e);
140 }
141
142 void GraphicsSceneRectMove::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
143 {
144     if (m_tool == TITLE_RECTANGLE && m_selectedItem) setSelectedItem(m_selectedItem);
145     QGraphicsScene::mouseReleaseEvent(e);
146     emit actionFinished();
147 }
148
149 void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e)
150 {
151     m_clickPoint = e->screenPos();
152     QPointF p = e->scenePos();
153     p += QPoint(-2, -2);
154     m_resizeMode = NoResize;
155     const QList <QGraphicsItem *> list = items(QRectF(p , QSizeF(4, 4)).toRect());
156     QGraphicsItem *item = NULL;
157
158     if (m_tool == TITLE_SELECT) {
159         foreach(QGraphicsItem *g, list) {
160             kDebug() << " - - CHECKING ITEM Z:" << g->zValue() << ", TYPE: " << g->type();
161             // check is there is a selected item in list
162             if (g->zValue() > -1000 && g->isSelected()) {
163                 item = g;
164                 break;
165             }
166         }
167         if (item == NULL  || !(item->flags() & QGraphicsItem::ItemIsSelectable)) {
168             if (m_selectedItem && m_selectedItem->type() == 8) {
169                 // disable text editing
170                 QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
171                 t->textCursor().setPosition(0);
172                 QTextBlock cur = t->textCursor().block();
173                 t->setTextCursor(QTextCursor(cur));
174                 t->setTextInteractionFlags(Qt::NoTextInteraction);
175             }
176             m_selectedItem = NULL;
177             foreach(QGraphicsItem* g, list) {
178                 if (g->zValue() > -1000) {
179                     item = g;
180                     break;
181                 }
182             }
183         }
184         if (item != NULL && item->flags() & QGraphicsItem::ItemIsMovable) {
185             m_sceneClickPoint = e->scenePos();
186             m_selectedItem = item;
187             kDebug() << "/////////  ITEM TYPE: " << item->type();
188             if (item->type() == 8) {
189                 QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(item);
190                 if (t->textInteractionFlags() == Qt::TextEditorInteraction) {
191                     QGraphicsScene::mousePressEvent(e);
192                     return;
193                 }
194                 t->setTextInteractionFlags(Qt::NoTextInteraction);
195                 setCursor(Qt::ClosedHandCursor);
196             } else if (item->type() == 3 || item->type() == 13 || item->type() == 7) {
197                 QRectF r1;
198                 if (m_selectedItem->type() == 3)
199                     r1 = ((QGraphicsRectItem*)m_selectedItem)->rect().normalized();
200                 else
201                     r1 = m_selectedItem->boundingRect().normalized();
202
203                 QList<QGraphicsView*> viewlist = views();
204                 QGraphicsView *view = NULL;
205                 if (viewlist.size() > 0) view = viewlist[0];
206                 if (view == NULL) return;
207                 // Item mapped coordinates
208                 QPolygon r = m_selectedItem->deviceTransform(view->viewportTransform()).map(r1).toPolygon();
209                 QPainterPath top(r.point(0));
210                 top.lineTo(r.point(1));
211                 QPainterPath bottom(r.point(2));
212                 bottom.lineTo(r.point(3));
213                 QPainterPath left(r.point(0));
214                 left.lineTo(r.point(3));
215                 QPainterPath right(r.point(1));
216                 right.lineTo(r.point(2));
217
218
219                 // The area interested by the mouse pointer
220                 QPoint viewPos = view->mapFromScene(e->scenePos());
221                 QPainterPath mouseArea;
222                 mouseArea.addRect(viewPos.x() - 4, viewPos.y() - 4, 8, 8);
223
224                 // Check for collisions between the mouse and the borders
225                 if (mouseArea.contains(r.point(0))) m_resizeMode = TopLeft;
226                 else if (mouseArea.contains(r.point(2))) m_resizeMode = BottomRight;
227                 else if (mouseArea.contains(r.point(1))) m_resizeMode = TopRight;
228                 else if (mouseArea.contains(r.point(3))) m_resizeMode = BottomLeft;
229                 else if (top.intersects(mouseArea)) m_resizeMode = Up;
230                 else if (bottom.intersects(mouseArea)) m_resizeMode = Down;
231                 else if (right.intersects(mouseArea)) m_resizeMode = Right;
232                 else if (left.intersects(mouseArea)) m_resizeMode = Left;
233
234                 else
235                     setCursor(Qt::ClosedHandCursor);
236             }
237         }
238         QGraphicsScene::mousePressEvent(e);
239     } else if (m_tool == TITLE_RECTANGLE) {
240         m_sceneClickPoint = e->scenePos();
241         m_selectedItem = NULL;
242     } else if (m_tool == TITLE_TEXT) {
243         m_selectedItem = addText(QString());
244         emit newText((QGraphicsTextItem *) m_selectedItem);
245         m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
246         ((QGraphicsTextItem *)m_selectedItem)->setTextInteractionFlags(Qt::TextEditorInteraction);
247         m_selectedItem->setPos(e->scenePos() - QPointF(0, (int)(m_fontSize / 2)));
248         QGraphicsScene::mousePressEvent(e);
249     }
250
251     kDebug() << "//////  MOUSE CLICK, RESIZE MODE: " << m_resizeMode;
252
253 }
254
255 void GraphicsSceneRectMove::clearTextSelection()
256 {
257     if (m_selectedItem && m_selectedItem->type() == 8) {
258         // disable text editing
259         QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
260         t->textCursor().setPosition(0);
261         QTextBlock cur = t->textCursor().block();
262         t->setTextCursor(QTextCursor(cur));
263         t->setTextInteractionFlags(Qt::NoTextInteraction);
264     }
265     m_selectedItem = NULL;
266     clearSelection();
267 }
268
269 void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
270 {
271     if (e->buttons() != Qt::NoButton && (e->screenPos() - m_clickPoint).manhattanLength() < QApplication::startDragDistance()) {
272         e->accept();
273         return;
274     }
275     if (m_selectedItem && e->buttons() & Qt::LeftButton) {
276         if (m_selectedItem->type() == 3 || m_selectedItem->type() == 13 || m_selectedItem->type() == 7) {
277             QRectF newrect;
278             if (m_selectedItem->type() == 3)
279                 newrect = ((QGraphicsRectItem*)m_selectedItem)->rect();
280             else
281                 newrect = m_selectedItem->boundingRect();
282             QPointF newpoint = e->scenePos();
283             /*
284              * The vertices of the rectangle (check for matrix
285              * transformation); to be replaced by QTransform::map()?
286              */
287             QPointF itemOrigin = m_selectedItem->scenePos();
288             QTransform transform = m_selectedItem->transform();
289             QPointF topLeft(transform.m11() * newrect.toRect().left() + transform.m21() * newrect.toRect().top() + transform.m31() + itemOrigin.x(), transform.m22() * newrect.toRect().top() + transform.m12() * newrect.toRect().left() + transform.m32() + itemOrigin.y());
290             QPointF bottomLeft(transform.m11() * newrect.toRect().left() + transform.m21() * newrect.toRect().bottom() + transform.m31() + itemOrigin.x(), transform.m22() * newrect.toRect().bottom() + transform.m12() * newrect.toRect().left() + transform.m32() + itemOrigin.y());
291             QPointF topRight(transform.m11() * newrect.toRect().right() + transform.m21() * newrect.toRect().top() + transform.m31() + itemOrigin.x(), transform.m22() * newrect.toRect().top() + transform.m12() * newrect.toRect().right() + transform.m32() + itemOrigin.y());
292             QPointF bottomRight(transform.m11() * newrect.toRect().right() + transform.m21() * newrect.toRect().bottom() + transform.m31() + itemOrigin.x(), transform.m22() * newrect.toRect().bottom() + transform.m12() * newrect.toRect().right() + transform.m32() + itemOrigin.y());
293             // Convert the mouse coordinates applying inverted transformation
294             QPointF newPointRelative = newpoint - itemOrigin;
295             QPointF resizePoint(transform.inverted().m11() * newPointRelative.x() + transform.inverted().m21() * newPointRelative.y() + transform.inverted().m31(), transform.inverted().m22() * newPointRelative.y() + transform.inverted().m12() * newPointRelative.x() + transform.inverted().m32());
296             /*
297              * Will check if the mouse is on the right of the limit lines with a
298              * determinant (it must be less than zero because the Y axis is
299              * inverted)
300              */
301             int determinantH, determinantV;
302             // Check whether to resize or to just move the item(s)
303             switch (m_resizeMode) {
304             case TopLeft:
305                 determinantV = (bottomRight.x() - newpoint.x()) * (topRight.y() - newpoint.y()) - (bottomRight.y() - newpoint.y()) * (topRight.x() - newpoint.x());
306                 determinantH = (bottomLeft.x() - newpoint.x()) * (bottomRight.y() - newpoint.y()) - (bottomLeft.y() - newpoint.y()) * (bottomRight.x() - newpoint.x());
307                 if (determinantV < 0) {
308                     if (determinantH < 0) {
309                         // resizePoint is not working for some reason
310                         newrect.setBottomRight(QPointF(newrect.width() - (transform.inverted().m11() * resizePoint.x() + transform.inverted().m21() * resizePoint.y() + transform.inverted().m31()), newrect.bottom() - (transform.inverted().m22() * resizePoint.y() + transform.inverted().m12() * resizePoint.x() + transform.inverted().m32())));
311                         m_selectedItem->setPos(resizePoint + itemOrigin);
312                     } else
313                         m_resizeMode = BottomLeft;
314                 } else {
315                     if (determinantH < 0)
316                         m_resizeMode = TopRight;
317                     else
318                         m_resizeMode = BottomRight;
319                 }
320                 break;
321             case BottomLeft:
322                 determinantV = (bottomRight.x() - newpoint.x()) * (topRight.y() - newpoint.y()) - (bottomRight.y() - newpoint.y()) * (topRight.x() - newpoint.x());
323                 determinantH = (topRight.x() - newpoint.x()) * (topLeft.y() - newpoint.y()) - (topRight.y() - newpoint.y()) * (topLeft.x() - newpoint.x());
324                 if (determinantV < 0) {
325                     if (determinantH < 0) {
326                         newrect.setBottomRight(QPointF(newrect.width() - resizePoint.x(), resizePoint.y()));
327                         m_selectedItem->setPos(QPointF(transform.m11() * resizePoint.x() + transform.m21() *(newrect.bottom() - resizePoint.y()) + transform.m31() + itemOrigin.x(), transform.m22() *(newrect.bottom() - resizePoint.y()) + transform.m12() * resizePoint.x() + transform.m32() + itemOrigin.y()));
328                     } else
329                         m_resizeMode = TopLeft;
330                 } else {
331                     if (determinantH < 0)
332                         m_resizeMode = BottomRight;
333                     else
334                         m_resizeMode = TopRight;
335                 }
336                 break;
337             case TopRight:
338                 determinantV = (topLeft.x() - newpoint.x()) * (bottomLeft.y() - newpoint.y()) - (topLeft.y() - newpoint.y()) * (bottomLeft.x() - newpoint.x());
339                 determinantH = (bottomLeft.x() - newpoint.x()) * (bottomRight.y() - newpoint.y()) - (bottomLeft.y() - newpoint.y()) * (bottomRight.x() - newpoint.x());
340                 if (determinantV < 0) {
341                     if (determinantH < 0) {
342                         newrect.setBottomRight(QPointF(resizePoint.x(), newrect.bottom() - resizePoint.y()));
343                         m_selectedItem->setPos(QPointF(transform.m11() *(newrect.width() - resizePoint.x()) + transform.m21() * resizePoint.y() + transform.m31() + itemOrigin.x(), transform.m22() * resizePoint.y() + transform.m12() *(newrect.width() - resizePoint.x()) + transform.m32() + itemOrigin.y()));
344                     } else
345                         m_resizeMode = BottomRight;
346                 } else {
347                     if (determinantH < 0)
348                         m_resizeMode = TopLeft;
349                     else
350                         m_resizeMode = BottomLeft;
351                 }
352                 break;
353             case BottomRight:
354                 determinantV = (topLeft.x() - newpoint.x()) * (bottomLeft.y() - newpoint.y()) - (topLeft.y() - newpoint.y()) * (bottomLeft.x() - newpoint.x());
355                 determinantH = (topRight.x() - newpoint.x()) * (topLeft.y() - newpoint.y()) - (topRight.y() - newpoint.y()) * (topLeft.x() - newpoint.x());
356                 if (determinantV < 0) {
357                     if (determinantH < 0)
358                         newrect.setBottomRight(resizePoint);
359                     else
360                         m_resizeMode = TopRight;
361                 } else {
362                     if (determinantH < 0)
363                         m_resizeMode = BottomLeft;
364                     else
365                         m_resizeMode = TopLeft;
366                 }
367                 break;
368             case Left:
369                 determinantV = (bottomRight.x() - newpoint.x()) * (topRight.y() - newpoint.y()) - (bottomRight.y() - newpoint.y()) * (topRight.x() - newpoint.x());
370                 if (determinantV < 0) {
371                     newrect.setRight(newrect.width() - resizePoint.x());
372                     m_selectedItem->setPos(QPointF(transform.m11() * resizePoint.x() + transform.m31() + itemOrigin.x(), transform.m12() * resizePoint.x() + transform.m32() + itemOrigin.y()));
373                 } else
374                     m_resizeMode = Right;
375                 break;
376             case Right:
377                 determinantV = (topLeft.x() - newpoint.x()) * (bottomLeft.y() - newpoint.y()) - (topLeft.y() - newpoint.y()) * (bottomLeft.x() - newpoint.x());
378                 if (determinantV < 0)
379                     newrect.setRight(resizePoint.x());
380                 else
381                     m_resizeMode = Left;
382                 break;
383             case Up:
384                 determinantH = (bottomLeft.x() - newpoint.x()) * (bottomRight.y() - newpoint.y()) - (bottomLeft.y() - newpoint.y()) * (bottomRight.x() - newpoint.x());
385                 if (determinantH < 0) {
386                     newrect.setBottom(newrect.bottom() - resizePoint.y());
387                     m_selectedItem->setPos(QPointF(transform.m21() * resizePoint.y() + transform.m31() + itemOrigin.x(), transform.m22() * resizePoint.y() + transform.m32() + itemOrigin.y()));
388                 } else
389                     m_resizeMode = Down;
390                 break;
391             case Down:
392                 determinantH = (topRight.x() - newpoint.x()) * (topLeft.y() - newpoint.y()) - (topRight.y() - newpoint.y()) * (topLeft.x() - newpoint.x());
393                 if (determinantH < 0)
394                     newrect.setBottom(resizePoint.y());
395                 else
396                     m_resizeMode = Up;
397                 break;
398             default:
399                 QPointF diff = e->scenePos() - m_sceneClickPoint;
400                 m_sceneClickPoint = e->scenePos();
401                 m_selectedItem->moveBy(diff.x(), diff.y());
402                 break;
403             }
404             if (m_selectedItem->type() == 3 && m_resizeMode != NoResize) {
405                 QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
406                 // Resize using aspect ratio
407                 if (!m_selectedItem->data(0).isNull()) {
408                     // we want to keep aspect ratio
409                     double hRatio = (double) newrect.width() / m_selectedItem->data(0).toInt();
410                     double vRatio = (double) newrect.height() / m_selectedItem->data(1).toInt();
411                     if (hRatio < vRatio) newrect.setHeight(m_selectedItem->data(1).toInt() * hRatio);
412                     else newrect.setWidth(m_selectedItem->data(0).toInt() * vRatio);
413                 }
414
415                 gi->setRect(newrect);
416             }
417             /*else {
418             qreal s;
419             if (resizeMode == Left || resizeMode == Right ) s = m_selectedItem->boundingRect().width() / newrect.width();
420             else s = m_selectedItem->boundingRect().height() / newrect.height();
421             m_selectedItem->scale( 1 / s, 1 / s );
422             kDebug()<<"/// SCALING SVG, RESIZE MODE: "<<resizeMode<<", RECT:"<<m_selectedItem->boundingRect();
423             }*/
424             //gi->setPos(m_selectedItem->scenePos());
425             /*if (resizeMode == NoResize) {
426                 QGraphicsScene::mouseMoveEvent(e);
427                 return;
428             }*/
429         } else if (m_selectedItem->type() == 8) {
430             QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
431             if (t->textInteractionFlags() & Qt::TextEditorInteraction) {
432                 QGraphicsScene::mouseMoveEvent(e);
433                 return;
434             }
435             QPointF diff = e->scenePos() - m_sceneClickPoint;
436             m_sceneClickPoint = e->scenePos();
437             m_selectedItem->moveBy(diff.x(), diff.y());
438         }
439         emit itemMoved();
440     } else if (m_tool == TITLE_SELECT) {
441         QList<QGraphicsView*> viewlist = views();
442         QGraphicsView *view = NULL;
443         if (viewlist.size() > 0) view = viewlist[0];
444
445         QPointF p = e->scenePos();
446         p += QPoint(-2, -2);
447         m_resizeMode = NoResize;
448         bool itemFound = false;
449         QList<QGraphicsItem *> list = items(QRectF(p , QSizeF(4, 4)).toRect());
450         foreach(const QGraphicsItem* g, list) {
451             if ((g->type() == 13 || g->type() == 7) && g->zValue() > -1000) {
452                 // image or svg item
453                 setCursor(Qt::OpenHandCursor);
454                 break;
455             } else if (g->type() == 3 && g->zValue() > -1000) {
456                 if (view == NULL) continue;
457                 QRectF r1 = ((const QGraphicsRectItem*)g)->rect().normalized();
458                 itemFound = true;
459
460                 // Item mapped coordinates
461                 QPolygon r = g->deviceTransform(view->viewportTransform()).map(r1).toPolygon();
462                 QPainterPath top(r.point(0));
463                 top.lineTo(r.point(1));
464                 QPainterPath bottom(r.point(2));
465                 bottom.lineTo(r.point(3));
466                 QPainterPath left(r.point(0));
467                 left.lineTo(r.point(3));
468                 QPainterPath right(r.point(1));
469                 right.lineTo(r.point(2));
470
471                 // The area interested by the mouse pointer
472                 QPoint viewPos = view->mapFromScene(e->scenePos());
473                 QPainterPath mouseArea;
474                 mouseArea.addRect(viewPos.x() - 4, viewPos.y() - 4, 8, 8);
475
476                 // Check for collisions between the mouse and the borders
477                 if (mouseArea.contains(r.point(0)) || mouseArea.contains(r.point(2))) setCursor(Qt::SizeFDiagCursor);
478                 else if (mouseArea.contains(r.point(1)) || mouseArea.contains(r.point(3))) setCursor(Qt::SizeBDiagCursor);
479                 else if (top.intersects(mouseArea) || bottom.intersects(mouseArea)) setCursor(Qt::SizeVerCursor);
480                 else if (right.intersects(mouseArea) || left.intersects(mouseArea)) setCursor(Qt::SizeHorCursor);
481                 else
482                     setCursor(Qt::OpenHandCursor);
483                 break;
484             }
485             if (!itemFound) setCursor(Qt::ArrowCursor);
486         }
487         QGraphicsScene::mouseMoveEvent(e);
488     } else if (m_tool == TITLE_RECTANGLE && e->buttons() & Qt::LeftButton) {
489         if (m_selectedItem == NULL) {
490             // create new rect item
491             QRectF r(0, 0, e->scenePos().x() - m_sceneClickPoint.x(), e->scenePos().y() - m_sceneClickPoint.y());
492             r = r.normalized();
493             m_selectedItem = addRect(QRectF(0, 0, r.width(), r.height()));
494             emit newRect((QGraphicsRectItem *) m_selectedItem);
495             m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
496             m_selectedItem->setPos(m_sceneClickPoint);
497             m_resizeMode = BottomRight;
498             QGraphicsScene::mouseMoveEvent(e);
499         }
500     }
501 }
502
503 void GraphicsSceneRectMove::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)
504 {
505     if (wheelEvent->modifiers() == Qt::ControlModifier) {
506         QList<QGraphicsView*> viewlist = views();
507         //kDebug() << wheelEvent->delta() << " " << zoom;
508         if (viewlist.size() > 0) {
509             if (wheelEvent->delta() > 0) emit sceneZoom(true);
510             else emit sceneZoom(false);
511         }
512     } else wheelEvent->setAccepted(false);
513 }
514
515 void GraphicsSceneRectMove::setScale(double s)
516 {
517     if (m_zoom < 1.0 / 7.0 && s < 1.0) return;
518     else if (m_zoom > 10.0 / 7.9 && s > 1.0) return;
519     QList<QGraphicsView*> viewlist = views();
520     if (viewlist.size() > 0) {
521         viewlist[0]->scale(s, s);
522         m_zoom = m_zoom * s;
523     }
524     //kDebug()<<"//////////  ZOOM: "<<zoom;
525 }
526
527 void GraphicsSceneRectMove::setZoom(double s)
528 {
529     QList<QGraphicsView*> viewlist = views();
530     if (viewlist.size() > 0) {
531         viewlist[0]->resetTransform();
532         viewlist[0]->scale(s, s);
533         m_zoom = s;
534     }
535
536     //kDebug()<<"//////////  ZOOM: "<<zoom;
537 }
538
539 void GraphicsSceneRectMove::setCursor(QCursor c)
540 {
541     const QList<QGraphicsView*> l = views();
542     foreach(QGraphicsView* v, l) {
543         v->setCursor(c);
544     }
545 }
546
547 void GraphicsSceneRectMove::setResizeCursor(qreal angle)
548 {
549     // % is not working...
550     while (angle < 0)
551         angle += 180;
552     while (angle >= 180)
553         angle -= 180;
554     if (angle > 157.5 || angle <= 22.5)
555         setCursor(Qt::SizeVerCursor);
556     else if (angle > 22.5 && angle <= 67.5)
557         setCursor(Qt::SizeFDiagCursor);
558     else if (angle > 67.5 && angle <= 112.5)
559         setCursor(Qt::SizeHorCursor);
560     else if (angle > 112.5 && angle <= 157.5)
561         setCursor(Qt::SizeBDiagCursor);
562 }
563
564 void GraphicsSceneRectMove::slotUpdateFontSize(int s)
565 {
566     m_fontSize = s;
567 }
568
569 #include "graphicsscenerectmove.moc"