From: Till Theato Date: Sat, 29 Jan 2011 18:14:08 +0000 (+0000) Subject: on-monitor editing: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=81be3bf632b306ffd8795f0c81d4372e358e88d2;p=kdenlive on-monitor editing: - let Qt assign mouse event. This makes it possible to add more complex items - lower background update period to 50ms svn path=/trunk/kdenlive/; revision=5362 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df1c2d60..25dd4ed4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -254,7 +254,6 @@ set(kdenlive_SRCS stopmotion/capturehandler.cpp blackmagic/capture.cpp blackmagic/devices.cpp - onmonitoritems/abstractonmonitoritem.cpp onmonitoritems/onmonitorrectitem.cpp onmonitoritems/onmonitorcornersitem.cpp cornerswidget.cpp @@ -347,4 +346,4 @@ install(FILES kdenlivesettings.kcfg DESTINATION ${KCFG_INSTALL_DIR}) install(FILES kdenlive.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) kde4_install_icons(${ICON_INSTALL_DIR}) install(FILES kdenlive_titles.knsrc kdenlive_wipes.knsrc kdenlive_renderprofiles.knsrc kdenlive_projectprofiles.knsrc kdenlivetranscodingrc DESTINATION ${CONFIG_INSTALL_DIR}) -kde4_install_icons(${ICON_INSTALL_DIR}) +kde4_install_icons(${ICON_INSTALL_DIR}) \ No newline at end of file diff --git a/src/cornerswidget.cpp b/src/cornerswidget.cpp index 46f2a133..b588336d 100644 --- a/src/cornerswidget.cpp +++ b/src/cornerswidget.cpp @@ -46,31 +46,18 @@ CornersWidget::CornersWidget(Monitor *monitor, QDomElement e, int minFrame, int edit->showVisibilityButton(true); m_scene = edit->getScene(); - m_item = new OnMonitorCornersItem(m_scene); + m_item = new OnMonitorCornersItem(); m_scene->addItem(m_item); // TODO: Better Icons - QToolButton *buttonShowControls = new QToolButton(); - buttonShowControls->setIcon(KIcon("transform-move")); - buttonShowControls->setToolTip(i18n("Show additional controls")); - buttonShowControls->setCheckable(true); - buttonShowControls->setAutoRaise(true); - buttonShowControls->setChecked(KdenliveSettings::onmonitoreffects_cornersshowcontrols()); - connect(buttonShowControls, SIGNAL(toggled(bool)), this, SLOT(slotShowControls(bool))); - edit->addCustomControl(buttonShowControls); - - QToolButton *buttonShowLines = new QToolButton(); - buttonShowLines->setIcon(KIcon("insert-horizontal-rule")); - buttonShowLines->setToolTip(i18n("Show/Hide the lines connecting the corners")); - buttonShowLines->setCheckable(true); - buttonShowControls->setAutoRaise(true); - buttonShowLines->setChecked(KdenliveSettings::onmonitoreffects_cornersshowlines()); - connect(buttonShowLines, SIGNAL(toggled(bool)), this, SLOT(slotShowLines(bool))); - edit->addCustomControl(buttonShowLines); + edit->addCustomButton(KIcon("transform-move"), i18n("Show additional controls"), this, SLOT(slotShowControls(bool)), + true, KdenliveSettings::onmonitoreffects_cornersshowcontrols()); + edit->addCustomButton(KIcon("insert-horizontal-rule"), i18n("Show/Hide the lines connecting the corners"), this, SLOT(slotShowLines(bool)), + true, KdenliveSettings::onmonitoreffects_cornersshowlines()); connect(edit, SIGNAL(showEdit(bool)), this, SLOT(slotShowScene(bool))); connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int))); - connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties())); + connect(m_item, SIGNAL(changed()), this, SLOT(slotUpdateProperties())); connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotInsertKeyframe())); connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotUpdateItem())); diff --git a/src/geometrywidget.cpp b/src/geometrywidget.cpp index 7e0aca9a..e92e8281 100644 --- a/src/geometrywidget.cpp +++ b/src/geometrywidget.cpp @@ -128,7 +128,6 @@ GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos, connect(edit, SIGNAL(showEdit(bool)), this, SLOT(slotShowScene(bool))); - connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateGeometry())); connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe())); connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int))); connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties())); @@ -185,10 +184,11 @@ void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxfra m_geometry->fetch(&item, 0); delete m_rect; - m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar(), m_scene); + m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar()); m_rect->setPos(item.x(), item.y()); m_rect->setZValue(0); m_scene->addItem(m_rect); + connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry())); slotPositionChanged(0, false); slotCheckMonitorPosition(m_monitor->render->seekFramePosition()); diff --git a/src/monitoreditwidget.cpp b/src/monitoreditwidget.cpp index f72bfacf..25df13dd 100644 --- a/src/monitoreditwidget.cpp +++ b/src/monitoreditwidget.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -42,7 +43,9 @@ MonitorEditWidget::MonitorEditWidget(Render* renderer, QWidget* parent) : ((QVBoxLayout*)m_ui.frameVideo->layout())->addWidget(m_view); - m_customControlsLayout = static_cast(m_ui.frameCustomControls->layout()); + m_customControlsLayout = new QVBoxLayout(m_ui.frameCustomControls); + m_customControlsLayout->setContentsMargins(0, 4, 0, 4); + m_customControlsLayout->setSpacing(0); m_visibilityAction = new QAction(KIcon("video-display"), i18n("Show/Hide edit mode"), this); m_visibilityAction->setCheckable(true); @@ -100,6 +103,21 @@ void MonitorEditWidget::addCustomControl(QWidget* widget) m_customControlsLayout->addWidget(widget); } +void MonitorEditWidget::addCustomButton(const QIcon& icon, const QString& text, const QObject* receiver, const char* member, bool checkable, bool checked) +{ + QToolButton *button = new QToolButton(m_ui.frameCustomControls); + button->setIcon(icon); + button->setToolTip(text); + button->setCheckable(checkable); + button->setChecked(checked); + button->setAutoRaise(true); + if (checkable) + connect(button, SIGNAL(toggled(bool)), receiver, member); + else + connect(button, SIGNAL(clicked()), receiver, member); + m_customControlsLayout->addWidget(button); +} + void MonitorEditWidget::removeCustomControls() { QLayoutItem *child; diff --git a/src/monitoreditwidget.h b/src/monitoreditwidget.h index 843a2bb1..81b5a2ad 100644 --- a/src/monitoreditwidget.h +++ b/src/monitoreditwidget.h @@ -23,6 +23,7 @@ #include +class QIcon; class MonitorScene; class Render; class QGraphicsView; @@ -52,6 +53,7 @@ public: /** @brief Adds a custom widget to the controls. */ void addCustomControl(QWidget *widget); + void addCustomButton(const QIcon &icon, const QString &text, const QObject *receiver, const char *member, bool checkable = true, bool checked = true); /** @brief Empties the list of custom controls. */ void removeCustomControls(); diff --git a/src/monitorscene.cpp b/src/monitorscene.cpp index dfe14a99..fe13181c 100644 --- a/src/monitorscene.cpp +++ b/src/monitorscene.cpp @@ -20,7 +20,6 @@ #include "monitorscene.h" #include "renderer.h" -#include "onmonitoritems/onmonitorrectitem.h" #include "kdenlivesettings.h" #include @@ -85,7 +84,7 @@ void MonitorScene::setEnabled(bool enabled) void MonitorScene::slotUpdateBackground() { if (m_view && m_view->isVisible()) { - if (m_lastUpdate.msecsTo(QTime::currentTime()) > 100) { + if (m_lastUpdate.msecsTo(QTime::currentTime()) > 50) { m_background->setPixmap(QPixmap::fromImage(m_backgroundImage)); m_lastUpdate = QTime::currentTime(); } @@ -137,35 +136,9 @@ void MonitorScene::slotZoomIn(int by) slotZoom(qMin(300, (int)(m_zoom * 100 + by + 0.5))); } -void MonitorScene::slotSetCursor(const QCursor &cursor) -{ - if (m_view) - m_view->setCursor(cursor); -} - - -void MonitorScene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - emit mousePressed(event); - - if (!event->isAccepted()) - QGraphicsScene::mousePressEvent(event); -} - void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - emit mouseMoved(event); - - if (!event->isAccepted()) - QGraphicsScene::mouseMoveEvent(event); -} - -void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - emit mouseReleased(event); - - if (!event->isAccepted()) - QGraphicsScene::mouseReleaseEvent(event); + QGraphicsScene::mouseMoveEvent(event); } void MonitorScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) diff --git a/src/monitorscene.h b/src/monitorscene.h index f96e3f38..c0f75bc4 100644 --- a/src/monitorscene.h +++ b/src/monitorscene.h @@ -44,12 +44,7 @@ public: void resetProfile(); protected: - /** @brief Emits signal mousePressed to be used in onmonitor items. */ - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - /** @brief Emits signal mouseMoveEvent to be used in onmonitor items. */ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - /** @brief Emits signal mouseReleaseEvent to be used in onmonitor items. */ - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); /** @brief Adds a keyframe if scene is disabled. */ virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); /** @brief Reimplemented to allow zooming using ctrl + mouse wheel. */ @@ -74,8 +69,6 @@ public slots: private slots: /** @brief Sets m_backgroundImage to @param image and requests updating the background item. */ void slotSetBackgroundImage(const QImage &image); - /** @brief Sets the mouse curors to @param cursor for the scene. */ - void slotSetCursor(const QCursor &cursor); private: Render *m_renderer; @@ -88,12 +81,8 @@ private: qreal m_zoom; signals: - void actionFinished(); void zoomChanged(int); void addKeyframe(); - void mouseMoved(QGraphicsSceneMouseEvent *event); - void mousePressed(QGraphicsSceneMouseEvent *event); - void mouseReleased(QGraphicsSceneMouseEvent *event); }; #endif diff --git a/src/onmonitoritems/abstractonmonitoritem.cpp b/src/onmonitoritems/abstractonmonitoritem.cpp deleted file mode 100644 index 32360cb8..00000000 --- a/src/onmonitoritems/abstractonmonitoritem.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Till Theato (root@ttill.de) * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "abstractonmonitoritem.h" -#include "monitorscene.h" - -#include - - -AbstractOnMonitorItem::AbstractOnMonitorItem(MonitorScene* scene) : - m_modified(false) -{ - connect(scene, SIGNAL(mousePressed(QGraphicsSceneMouseEvent*)), this, SLOT(slotMousePressed(QGraphicsSceneMouseEvent*))); - connect(scene, SIGNAL(mouseReleased(QGraphicsSceneMouseEvent*)), this, SLOT(slotMouseReleased(QGraphicsSceneMouseEvent*))); - connect(scene, SIGNAL(mouseMoved(QGraphicsSceneMouseEvent*)), this, SLOT(slotMouseMoved(QGraphicsSceneMouseEvent*))); - connect(this, SIGNAL(actionFinished()), scene, SIGNAL(actionFinished())); - connect(this, SIGNAL(requestCursor(const QCursor &)), scene, SLOT(slotSetCursor(const QCursor &))); -} - -void AbstractOnMonitorItem::slotMouseReleased(QGraphicsSceneMouseEvent* event) -{ - if (m_modified) { - m_modified = false; - emit actionFinished(); - } - event->accept(); -} - -#include "abstractonmonitoritem.moc" diff --git a/src/onmonitoritems/abstractonmonitoritem.h b/src/onmonitoritems/abstractonmonitoritem.h deleted file mode 100644 index 0c61e09c..00000000 --- a/src/onmonitoritems/abstractonmonitoritem.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Till Theato (root@ttill.de) * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - - -#ifndef ABSTRACTONMONITORITEM_H -#define ABSTRACTONMONITORITEM_H - -#include -#include - - -class MonitorScene; - -class AbstractOnMonitorItem : public QObject -{ - Q_OBJECT -public: - AbstractOnMonitorItem(MonitorScene *scene); - virtual ~AbstractOnMonitorItem() {}; - -protected slots: - virtual void slotMousePressed(QGraphicsSceneMouseEvent *event) = 0; - /** @brief emits actionFinished signal if item was modified. */ - virtual void slotMouseReleased(QGraphicsSceneMouseEvent *event); - virtual void slotMouseMoved(QGraphicsSceneMouseEvent *event) = 0; - -protected: - bool m_modified; - -signals: - void actionFinished(); - void requestCursor(const QCursor &); -}; - -#endif diff --git a/src/onmonitoritems/onmonitorcornersitem.cpp b/src/onmonitoritems/onmonitorcornersitem.cpp index 43436e21..f37512b8 100644 --- a/src/onmonitoritems/onmonitorcornersitem.cpp +++ b/src/onmonitoritems/onmonitorcornersitem.cpp @@ -27,10 +27,10 @@ #include #include -OnMonitorCornersItem::OnMonitorCornersItem(MonitorScene* scene, QGraphicsItem* parent) : - AbstractOnMonitorItem(scene), +OnMonitorCornersItem::OnMonitorCornersItem(QGraphicsItem* parent) : QGraphicsPolygonItem(parent), - m_selectedCorner(-1) + m_selectedCorner(-1), + m_modified(false) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -38,6 +38,7 @@ OnMonitorCornersItem::OnMonitorCornersItem(MonitorScene* scene, QGraphicsItem* p framepen.setColor(Qt::yellow); setPen(framepen); setBrush(Qt::NoBrush); + setAcceptHoverEvents(true); } OnMonitorCornersItem::cornersActions OnMonitorCornersItem::getMode(QPointF pos, int *corner) @@ -47,7 +48,6 @@ OnMonitorCornersItem::cornersActions OnMonitorCornersItem::getMode(QPointF pos, return NoAction; QPainterPath mouseArea; - pos = mapFromScene(pos); mouseArea.addRect(pos.x() - 6, pos.y() - 6, 12, 12); for (int i = 0; i < 4; ++i) { if (mouseArea.contains(polygon().at(i))) { @@ -72,26 +72,17 @@ OnMonitorCornersItem::cornersActions OnMonitorCornersItem::getMode(QPointF pos, return NoAction; } -void OnMonitorCornersItem::slotMousePressed(QGraphicsSceneMouseEvent* event) +void OnMonitorCornersItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { - event->accept(); - - if (!isEnabled()) - return; - - m_mode = getMode(event->scenePos(), &m_selectedCorner); + m_mode = getMode(event->pos(), &m_selectedCorner); m_lastPoint = event->scenePos(); + + if (m_mode == NoAction) + event->ignore(); } -void OnMonitorCornersItem::slotMouseMoved(QGraphicsSceneMouseEvent* event) +void OnMonitorCornersItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { - event->accept(); - - if (!isEnabled()) { - emit requestCursor(QCursor(Qt::ArrowCursor)); - return; - } - /*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) { * event->accept(); * return; @@ -119,23 +110,41 @@ void OnMonitorCornersItem::slotMouseMoved(QGraphicsSceneMouseEvent* event) } m_lastPoint = mousePos; setPolygon(p); - } else { - int corner; - switch (getMode(event->scenePos(), &corner)) { - case NoAction: - emit requestCursor(QCursor(Qt::ArrowCursor)); - break; - case Move: - emit requestCursor(QCursor(Qt::SizeAllCursor)); - break; - default: - emit requestCursor(QCursor(Qt::OpenHandCursor)); - break; + } + + if (m_modified) { + event->accept(); + if (KdenliveSettings::monitorscene_directupdate()) { + emit changed(); + m_modified = false; } + } else { + event->ignore(); } - if (m_modified && KdenliveSettings::monitorscene_directupdate()) { - emit actionFinished(); +} + +void OnMonitorCornersItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + if (m_modified) { m_modified = false; + emit changed(); + } + event->accept(); +} + +void OnMonitorCornersItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event) +{ + int corner; + switch (getMode(event->pos(), &corner)) { + case NoAction: + unsetCursor(); + break; + case Move: + setCursor(QCursor(Qt::SizeAllCursor)); + break; + default: + setCursor(QCursor(Qt::OpenHandCursor)); + break; } } diff --git a/src/onmonitoritems/onmonitorcornersitem.h b/src/onmonitoritems/onmonitorcornersitem.h index aaade57c..c97114a3 100644 --- a/src/onmonitoritems/onmonitorcornersitem.h +++ b/src/onmonitoritems/onmonitorcornersitem.h @@ -21,16 +21,15 @@ #ifndef ONMONITORCORNERSITEM_H #define ONMONITORCORNERSITEM_H -#include "abstractonmonitoritem.h" #include #include -class OnMonitorCornersItem : public AbstractOnMonitorItem, public QGraphicsPolygonItem +class OnMonitorCornersItem : public QObject, public QGraphicsPolygonItem { Q_OBJECT public: - OnMonitorCornersItem(MonitorScene *scene, QGraphicsItem *parent = 0); + OnMonitorCornersItem(QGraphicsItem *parent = 0); enum cornersActions { Corner, Move, MoveSide, NoAction }; /** @brief Gets The action mode for the area @param pos +- 4. */ @@ -39,11 +38,11 @@ public: /** @brief Reimplemented to draw the handles. */ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0 ); -public slots: - /** @brief Saves current mouse position and mode. */ - void slotMousePressed(QGraphicsSceneMouseEvent *event); - /** @brief Modifies item according to mouse position and mode. */ - void slotMouseMoved(QGraphicsSceneMouseEvent *event); +protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); private: /** @brief Returns the centroid (= 'center of mass') of this polygon. */ @@ -56,6 +55,10 @@ private: /** Number of the selected corner or if in MoveSide mode number of the first corner on this side */ int m_selectedCorner; QPointF m_lastPoint; + bool m_modified; + +signals: + void changed(); }; #endif diff --git a/src/onmonitoritems/onmonitorrectitem.cpp b/src/onmonitoritems/onmonitorrectitem.cpp index ddbb97fc..974d0aae 100644 --- a/src/onmonitoritems/onmonitorrectitem.cpp +++ b/src/onmonitoritems/onmonitorrectitem.cpp @@ -25,10 +25,10 @@ #include #include -OnMonitorRectItem::OnMonitorRectItem(const QRectF &rect, double dar, MonitorScene *scene, QGraphicsItem* parent) : - AbstractOnMonitorItem(scene), +OnMonitorRectItem::OnMonitorRectItem(const QRectF &rect, double dar, QGraphicsItem* parent) : QGraphicsRectItem(rect, parent), - m_dar(dar) + m_dar(dar), + m_modified(false) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -36,34 +36,34 @@ OnMonitorRectItem::OnMonitorRectItem(const QRectF &rect, double dar, MonitorScen framepen.setColor(Qt::yellow); setPen(framepen); setBrush(Qt::transparent); + setAcceptHoverEvents(true); } -rectActions OnMonitorRectItem::getMode(QPoint pos) +rectActions OnMonitorRectItem::getMode(QPointF pos) { - pos = mapFromScene(pos).toPoint(); // Item mapped coordinates - QPolygon pol(rect().normalized().toRect()); + QPolygonF pol(rect().normalized()); - QPainterPath top(pol.point(0)); - top.lineTo(pol.point(1)); - QPainterPath bottom(pol.point(2)); - bottom.lineTo(pol.point(3)); - QPainterPath left(pol.point(0)); - left.lineTo(pol.point(3)); - QPainterPath right(pol.point(1)); - right.lineTo(pol.point(2)); + QPainterPath top(pol.at(0)); + top.lineTo(pol.at(1)); + QPainterPath bottom(pol.at(2)); + bottom.lineTo(pol.at(3)); + QPainterPath left(pol.at(0)); + left.lineTo(pol.at(3)); + QPainterPath right(pol.at(1)); + right.lineTo(pol.at(2)); QPainterPath mouseArea; mouseArea.addRect(pos.x() - 4, pos.y() - 4, 8, 8); // Check for collisions between the mouse and the borders - if (mouseArea.contains(pol.point(0))) + if (mouseArea.contains(pol.at(0))) return ResizeTopLeft; - else if (mouseArea.contains(pol.point(2))) + else if (mouseArea.contains(pol.at(2))) return ResizeBottomRight; - else if (mouseArea.contains(pol.point(1))) + else if (mouseArea.contains(pol.at(1))) return ResizeTopRight; - else if (mouseArea.contains(pol.point(3))) + else if (mouseArea.contains(pol.at(3))) return ResizeBottomLeft; else if (top.intersects(mouseArea)) return ResizeTop; @@ -79,32 +79,17 @@ rectActions OnMonitorRectItem::getMode(QPoint pos) return NoAction; } -/*int OnMonitorRectItem::type() const -{ - return Type; -}*/ - -void OnMonitorRectItem::slotMousePressed(QGraphicsSceneMouseEvent* event) +void OnMonitorRectItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { event->accept(); - if (!isEnabled()) - return; - m_lastPoint = event->scenePos(); m_oldRect = rect().normalized(); - m_mode = getMode(m_lastPoint.toPoint()); + m_mode = getMode(event->pos()); } -void OnMonitorRectItem::slotMouseMoved(QGraphicsSceneMouseEvent* event) +void OnMonitorRectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { - event->accept(); - - if (!isEnabled()) { - emit requestCursor(QCursor(Qt::ArrowCursor)); - return; - } - /*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) { * event->accept(); * return; @@ -114,7 +99,7 @@ void OnMonitorRectItem::slotMouseMoved(QGraphicsSceneMouseEvent* event) QRectF r = rect().normalized(); QPointF p = pos(); QPointF mousePos = event->scenePos(); - QPointF mousePosInRect = mapFromScene(mousePos); + QPointF mousePosInRect = event->pos(); QPointF diff = mousePos - m_lastPoint; m_lastPoint = mousePos; @@ -216,36 +201,53 @@ void OnMonitorRectItem::slotMouseMoved(QGraphicsSceneMouseEvent* event) } setRect(r); - } else { - switch (getMode(event->scenePos().toPoint())) { - case ResizeTopLeft: - case ResizeBottomRight: - emit requestCursor(QCursor(Qt::SizeFDiagCursor)); - break; - case ResizeTopRight: - case ResizeBottomLeft: - emit requestCursor(QCursor(Qt::SizeBDiagCursor)); - break; - case ResizeTop: - case ResizeBottom: - emit requestCursor(QCursor(Qt::SizeVerCursor)); - break; - case ResizeLeft: - case ResizeRight: - emit requestCursor(QCursor(Qt::SizeHorCursor)); - break; - case Move: - emit requestCursor(QCursor(Qt::OpenHandCursor)); - break; - default: - emit requestCursor(QCursor(Qt::ArrowCursor)); - break; + } + + if (m_modified) { + event->accept(); + if (KdenliveSettings::monitorscene_directupdate()) { + emit changed(); + m_modified = false; } + } else { + event->ignore(); } +} - if (m_modified && KdenliveSettings::monitorscene_directupdate()) { - emit actionFinished(); +void OnMonitorRectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + if (m_modified) { m_modified = false; + emit changed(); + } + event->accept(); +} + +void OnMonitorRectItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event) +{ + switch (getMode(event->pos())) { + case ResizeTopLeft: + case ResizeBottomRight: + setCursor(QCursor(Qt::SizeFDiagCursor)); + break; + case ResizeTopRight: + case ResizeBottomLeft: + setCursor(QCursor(Qt::SizeBDiagCursor)); + break; + case ResizeTop: + case ResizeBottom: + setCursor(QCursor(Qt::SizeVerCursor)); + break; + case ResizeLeft: + case ResizeRight: + setCursor(QCursor(Qt::SizeHorCursor)); + break; + case Move: + setCursor(QCursor(Qt::OpenHandCursor)); + break; + default: + unsetCursor(); + break; } } diff --git a/src/onmonitoritems/onmonitorrectitem.h b/src/onmonitoritems/onmonitorrectitem.h index acdee10c..047f3e6a 100644 --- a/src/onmonitoritems/onmonitorrectitem.h +++ b/src/onmonitoritems/onmonitorrectitem.h @@ -21,41 +21,40 @@ #ifndef ONMONITORRECTITEM_H #define ONMONITORRECTITEM_H -#include "abstractonmonitoritem.h" #include #include enum rectActions { Move, ResizeTopLeft, ResizeBottomLeft, ResizeTopRight, ResizeBottomRight, ResizeLeft, ResizeRight, ResizeTop, ResizeBottom, NoAction }; -class OnMonitorRectItem : public AbstractOnMonitorItem, public QGraphicsRectItem +class OnMonitorRectItem : public QObject, public QGraphicsRectItem { Q_OBJECT public: - OnMonitorRectItem(const QRectF &rect, double dar, MonitorScene *scene, QGraphicsItem *parent = 0); + OnMonitorRectItem(const QRectF &rect, double dar, QGraphicsItem *parent = 0); /** @brief Gets The action mode for the area @param pos +- 4. * e.g. pos(0,0) returns ResizeTopLeft */ - rectActions getMode(QPoint pos); - - /*enum { Type = UserType + 1}; - / ** @brief Reimplemented to make sure casting works. * / - int type() const;*/ + rectActions getMode(QPointF pos); /** @brief Reimplemented to draw the handles. */ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0 ); -public slots: - /** @brief Saves current mouse position and mode. */ - void slotMousePressed(QGraphicsSceneMouseEvent *event); - /** @brief Modifies item according to mouse position and mode. */ - void slotMouseMoved(QGraphicsSceneMouseEvent *event); +protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); private: double m_dar; rectActions m_mode; QRectF m_oldRect; QPointF m_lastPoint; + bool m_modified; + +signals: + void changed(); }; #endif diff --git a/src/widgets/monitoreditwidget_ui.ui b/src/widgets/monitoreditwidget_ui.ui index 6b816818..98ad09e4 100644 --- a/src/widgets/monitoreditwidget_ui.ui +++ b/src/widgets/monitoreditwidget_ui.ui @@ -10,9 +10,6 @@ 290 - - Form - 0 @@ -48,22 +45,7 @@ 0 - - - QFrame::NoFrame - - - QFrame::Plain - - - - 0 - - - 0 - - - +