]> git.sesse.net Git - kdenlive/commitdiff
on-monitor editing:
authorTill Theato <root@ttill.de>
Sat, 29 Jan 2011 18:14:08 +0000 (18:14 +0000)
committerTill Theato <root@ttill.de>
Sat, 29 Jan 2011 18:14:08 +0000 (18:14 +0000)
- 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

14 files changed:
src/CMakeLists.txt
src/cornerswidget.cpp
src/geometrywidget.cpp
src/monitoreditwidget.cpp
src/monitoreditwidget.h
src/monitorscene.cpp
src/monitorscene.h
src/onmonitoritems/abstractonmonitoritem.cpp [deleted file]
src/onmonitoritems/abstractonmonitoritem.h [deleted file]
src/onmonitoritems/onmonitorcornersitem.cpp
src/onmonitoritems/onmonitorcornersitem.h
src/onmonitoritems/onmonitorrectitem.cpp
src/onmonitoritems/onmonitorrectitem.h
src/widgets/monitoreditwidget_ui.ui

index df1c2d60882757e0f1dcc75f3e09c47ceb8f4def..25dd4ed4fe689ee30a891ea146f3ef9581034e10 100644 (file)
@@ -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
index 46f2a1336131621ccf160432f3a63f8f5b2c79f1..b588336d09b2a7e14d47d321b78aa533fa4a90ae 100644 (file)
@@ -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()));
index 7e0aca9aff49f0cf32dfff0c56d699fdf8331c4e..e92e8281442e9dcb38c22eb326da8b0f9c54c1ae 100644 (file)
@@ -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());
index f72bfacff0a74de0c5139062b73984768df2397a..25df13dd2827b30a7b9bfe005731bc839e8f7db0 100644 (file)
@@ -25,6 +25,7 @@
 #include <QGraphicsView>
 #include <QVBoxLayout>
 #include <QAction>
+#include <QToolButton>
 
 #include <KIcon>
 
@@ -42,7 +43,9 @@ MonitorEditWidget::MonitorEditWidget(Render* renderer, QWidget* parent) :
 
     ((QVBoxLayout*)m_ui.frameVideo->layout())->addWidget(m_view);
 
-    m_customControlsLayout = static_cast<QVBoxLayout *>(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;
index 843a2bb13e31d6ca80d117d86e971f22dd28b03a..81b5a2ad547bd7888b7a6ff3a4bfd45e5adabaf7 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <QWidget>
 
+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();
 
index dfe14a99fc5e4194df5a18d3b5b760859658764d..fe13181cba3675ae6fef42195f8e972b0ad3bb2f 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "monitorscene.h"
 #include "renderer.h"
-#include "onmonitoritems/onmonitorrectitem.h"
 #include "kdenlivesettings.h"
 
 #include <QGraphicsView>
@@ -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)
index f96e3f387ed9fc104459be09309e9b8574f1d926..c0f75bc49460d7f5d95dd67a6c3e867d2b89fa9a 100644 (file)
@@ -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 (file)
index 32360cb..0000000
+++ /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 <QGraphicsSceneMouseEvent>
-
-
-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 (file)
index 0c61e09..0000000
+++ /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 <QtCore>
-#include <QGraphicsItem>
-
-
-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
index 43436e21b05664f1fe02ba8aebf1aa61d040500f..f37512b85b581c37c658f2e7ce89c902b70cebb9 100644 (file)
 #include <QStyleOptionGraphicsItem>
 #include <QCursor>
 
-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;
     }
 }
 
index aaade57c3746002cac43078d4856efa3f4f603cf..c97114a3766dcf2ea0a4cbb2fca1bde90e6e0495 100644 (file)
 #ifndef ONMONITORCORNERSITEM_H
 #define ONMONITORCORNERSITEM_H
 
-#include "abstractonmonitoritem.h"
 
 #include <QtCore>
 #include <QGraphicsPolygonItem>
 
-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
index ddbb97fc261e5597609908f585ca0d4125ca53c9..974d0aae136dd4b8416986e27fa19202d417e4ac 100644 (file)
 #include <QStyleOptionGraphicsItem>
 #include <QCursor>
 
-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;
     }
 }
 
index acdee10cacc25e09edfb30e0d201d24906a2f3e4..047f3e6a191c8a894bb5a0e663be06b60322e26d 100644 (file)
 #ifndef ONMONITORRECTITEM_H
 #define ONMONITORRECTITEM_H
 
-#include "abstractonmonitoritem.h"
 
 #include <QtCore>
 #include <QGraphicsRectItem>
 
 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
index 6b81681824cce2c2048ecb898cad05151cb53801..98ad09e4e91d3361c030cb8ddd4c16412909a7b9 100644 (file)
@@ -10,9 +10,6 @@
     <height>290</height>
    </rect>
   </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
   <layout class="QHBoxLayout" name="horizontalLayout">
    <property name="spacing">
     <number>0</number>
        <number>0</number>
       </property>
       <item>
-       <widget class="QFrame" name="frameCustomControls">
-        <property name="frameShape">
-         <enum>QFrame::NoFrame</enum>
-        </property>
-        <property name="frameShadow">
-         <enum>QFrame::Plain</enum>
-        </property>
-        <layout class="QVBoxLayout" name="verticalLayout_2">
-         <property name="spacing">
-          <number>0</number>
-         </property>
-         <property name="margin">
-          <number>0</number>
-         </property>
-        </layout>
-       </widget>
+       <widget class="QFrame" name="frameCustomControls"/>
       </item>
       <item>
        <widget class="QToolButton" name="buttonDirectUpdate">