1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
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. *
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. *
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 ***************************************************************************/
20 #include "onmonitorcornersitem.h"
21 #include "kdenlivesettings.h"
23 #include <QGraphicsSceneMouseEvent>
25 #include <QStyleOptionGraphicsItem>
28 OnMonitorCornersItem::OnMonitorCornersItem(MonitorScene* scene, QGraphicsItem* parent) :
29 AbstractOnMonitorItem(scene),
30 QGraphicsPolygonItem(parent)
32 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
34 QPen framepen(Qt::SolidLine);
35 framepen.setColor(Qt::yellow);
37 setBrush(Qt::transparent);
40 cornersActions OnMonitorCornersItem::getMode(QPoint pos)
42 /*pos = mapFromScene(pos).toPoint();
43 // Item mapped coordinates
44 QPolygon pol(rect().normalized().toRect());
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));
55 QPainterPath mouseArea;
56 mouseArea.addRect(pos.x() - 4, pos.y() - 4, 8, 8);
58 // Check for collisions between the mouse and the borders
59 if (mouseArea.contains(pol.point(0)))
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))
69 else if (bottom.intersects(mouseArea))
71 else if (right.intersects(mouseArea))
73 else if (left.intersects(mouseArea))
75 else if (rect().normalized().contains(pos))
82 void OnMonitorCornersItem::slotMousePressed(QGraphicsSceneMouseEvent* event)
89 m_clickPoint = event->scenePos();
90 m_mode = getMode(m_clickPoint.toPoint());
93 void OnMonitorCornersItem::slotMouseMoved(QGraphicsSceneMouseEvent* event)
98 emit requestCursor(QCursor(Qt::ArrowCursor));
102 /*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) {
107 QPointF mousePos = event->scenePos();
109 if (event->buttons() & Qt::LeftButton) {
110 m_clickPoint = mousePos;
128 switch (getMode(event->scenePos().toPoint())) {
130 emit requestCursor(QCursor(Qt::ArrowCursor));
133 emit requestCursor(QCursor(Qt::OpenHandCursor));
137 if (m_modified && KdenliveSettings::monitorscene_directupdate()) {
138 emit actionFinished();
143 /*void OnMonitorRectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
147 painter->setPen(pen());
148 painter->drawRect(option->rect);
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));
160 #include "onmonitorcornersitem.moc"