]> git.sesse.net Git - kdenlive/blob - src/onmonitoritems/onmonitorcornersitem.cpp
419f6b6028ee4971a9b7690e24ff71ba9bd36d74
[kdenlive] / src / onmonitoritems / onmonitorcornersitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program 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         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include "onmonitorcornersitem.h"
21 #include "kdenlivesettings.h"
22
23 #include <QGraphicsSceneMouseEvent>
24 #include <QPainter>
25 #include <QStyleOptionGraphicsItem>
26 #include <QCursor>
27
28 OnMonitorCornersItem::OnMonitorCornersItem(MonitorScene* scene, QGraphicsItem* parent) :
29         AbstractOnMonitorItem(scene),
30         QGraphicsPolygonItem(parent)
31 {
32     setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
33
34     QPen framepen(Qt::SolidLine);
35     framepen.setColor(Qt::yellow);
36     setPen(framepen);
37     setBrush(Qt::transparent);
38 }
39
40 cornersActions OnMonitorCornersItem::getMode(QPoint pos)
41 {
42     /*pos = mapFromScene(pos).toPoint();
43     // Item mapped coordinates
44     QPolygon pol(rect().normalized().toRect());
45
46     QPainterPath top(pol.point(0));
47     top.lineTo(pol.point(1));
48     QPainterPath bottom(pol.point(2));
49     bottom.lineTo(pol.point(3));
50     QPainterPath left(pol.point(0));
51     left.lineTo(pol.point(3));
52     QPainterPath right(pol.point(1));
53     right.lineTo(pol.point(2));
54
55     QPainterPath mouseArea;
56     mouseArea.addRect(pos.x() - 4, pos.y() - 4, 8, 8);
57
58     // Check for collisions between the mouse and the borders
59     if (mouseArea.contains(pol.point(0)))
60         return ResizeTopLeft;
61     else if (mouseArea.contains(pol.point(2)))
62         return ResizeBottomRight;
63     else if (mouseArea.contains(pol.point(1)))
64         return ResizeTopRight;
65     else if (mouseArea.contains(pol.point(3)))
66         return ResizeBottomLeft;
67     else if (top.intersects(mouseArea))
68         return ResizeTop;
69     else if (bottom.intersects(mouseArea))
70         return ResizeBottom;
71     else if (right.intersects(mouseArea))
72         return ResizeRight;
73     else if (left.intersects(mouseArea))
74         return ResizeLeft;
75     else if (rect().normalized().contains(pos))
76         return Move;
77     else
78         return NoAction;*/
79     return NoAction;
80 }
81
82 void OnMonitorCornersItem::slotMousePressed(QGraphicsSceneMouseEvent* event)
83 {
84     event->accept();
85
86     if (!isEnabled())
87         return;
88
89     m_clickPoint = event->scenePos();
90     m_mode = getMode(m_clickPoint.toPoint());
91 }
92
93 void OnMonitorCornersItem::slotMouseMoved(QGraphicsSceneMouseEvent* event)
94 {
95     event->accept();
96
97     if (!isEnabled()) {
98         emit requestCursor(QCursor(Qt::ArrowCursor));
99         return;
100     }
101
102     /*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) {
103      *   event->accept();
104      *   return;
105     }*/
106
107     QPointF mousePos = event->scenePos();
108
109     if (event->buttons() & Qt::LeftButton) {
110         m_clickPoint = mousePos;
111         switch (m_mode) {
112         case Corner1:
113             
114             break;
115         case Corner2:
116             
117             break;
118         case Corner3:
119             
120             break;
121         case Corner4:
122             
123             break;
124         default:
125             break;
126         }
127     } else {
128         switch (getMode(event->scenePos().toPoint())) {
129         case NoAction:
130             emit requestCursor(QCursor(Qt::ArrowCursor));
131             break;
132         default:
133             emit requestCursor(QCursor(Qt::OpenHandCursor));
134             break;
135         }
136     }
137     if (m_modified && KdenliveSettings::monitorscene_directupdate()) {
138         emit actionFinished();
139         m_modified = false;
140     }
141 }
142
143 /*void OnMonitorRectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
144 {
145     Q_UNUSED(widget);
146
147     painter->setPen(pen());
148     painter->drawRect(option->rect);
149
150     if (isEnabled()) {
151         double handleSize = 6 / painter->matrix().m11();
152         double halfHandleSize = handleSize / 2;
153         painter->fillRect(-halfHandleSize, -halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
154         painter->fillRect(option->rect.width() - halfHandleSize, -halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
155         painter->fillRect(option->rect.width() - halfHandleSize, option->rect.height() - halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
156         painter->fillRect(-halfHandleSize, option->rect.height() - halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
157     }
158 }*/
159
160 #include "onmonitorcornersitem.moc"