]> git.sesse.net Git - kdenlive/blobdiff - src/onmonitoritems/onmonitorrectitem.cpp
Const'ref
[kdenlive] / src / onmonitoritems / onmonitorrectitem.cpp
index acf5c1faf673aa219afdceb31ab1c9543e874676..810fb932e40d5bc9a06792e3e7dbfe83e2a435e0 100644 (file)
 #include <QGraphicsView>
 
 OnMonitorRectItem::OnMonitorRectItem(const QRectF &rect, double dar, QGraphicsItem* parent) :
-        QGraphicsRectItem(rect, parent),
-        m_dar(dar),
-        m_modified(false),
-        m_view(NULL)
+    QGraphicsRectItem(rect, parent)
+  , m_dar(dar)
+  , m_mode(NoAction)
+  , m_modified(false)
+  , m_view(NULL)
 {
     setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
 
@@ -41,7 +42,7 @@ OnMonitorRectItem::OnMonitorRectItem(const QRectF &rect, double dar, QGraphicsIt
     setAcceptHoverEvents(true);
 }
 
-rectActions OnMonitorRectItem::getMode(QPointF pos)
+rectActions OnMonitorRectItem::getMode(const QPointF &pos)
 {
     // Item mapped coordinates
     QPolygonF pol(rect().normalized());
@@ -56,10 +57,13 @@ rectActions OnMonitorRectItem::getMode(QPointF pos)
     right.lineTo(pol.at(2));
 
     QPainterPath mouseArea;
-    qreal size = 8;
-    if (getView())
-        size /= m_view->matrix().m11();
-    mouseArea.addRect(pos.x() - size / 2, pos.y() - size / 2, size, size);
+    qreal xsize = 12;
+    qreal ysize = 12;
+    if (getView()) {
+        xsize /= m_view->matrix().m11();
+        ysize /= m_view->matrix().m22();
+    }
+    mouseArea.addRect(pos.x() - xsize / 2, pos.y() - ysize / 2, xsize, ysize);
 
     // Check for collisions between the mouse and the borders
     if (mouseArea.contains(pol.at(0)))
@@ -172,7 +176,7 @@ void OnMonitorRectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
 
         // Keep aspect ratio
         if (event->modifiers() == Qt::ControlModifier) {
-            // compare to rect during mouse press: 
+            // compare to rect during mouse press:
             // if we subtract rect() we'll get a whole lot of flickering
             // because of diffWidth > diffHeight changing all the time
             int diffWidth = qAbs(r.width() - m_oldRect.width());
@@ -261,16 +265,25 @@ void OnMonitorRectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*
     Q_UNUSED(widget)
 
     painter->setPen(pen());
-    painter->drawRect(option->rect);
-
+    //painter->setClipRect(option->rect);
+    const QRectF r = rect();
+    painter->drawRect(r);
+    QRectF handle = painter->worldTransform().inverted().mapRect(QRectF(0, 0, 6, 6));
     if (isEnabled()) {
-        double handleSize = 6 / painter->worldTransform().m11();
-        double halfHandleSize = handleSize / 2;
-        painter->fillRect(-halfHandleSize, -halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
-        painter->fillRect(option->rect.width() - halfHandleSize, -halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
-        painter->fillRect(option->rect.width() - halfHandleSize, option->rect.height() - halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
-        painter->fillRect(-halfHandleSize, option->rect.height() - halfHandleSize, handleSize, handleSize, QColor(Qt::yellow));
+        handle.moveTopLeft(r.topLeft());
+        painter->fillRect(handle, QColor(Qt::yellow));
+        handle.moveTopRight(r.topRight());
+        painter->fillRect(handle, QColor(Qt::yellow));
+        handle.moveBottomLeft(r.bottomLeft());
+        painter->fillRect(handle, QColor(Qt::yellow));
+        handle.moveBottomRight(r.bottomRight());
+        painter->fillRect(handle, QColor(Qt::yellow));
     }
+    
+    // Draw cross at center
+    QPointF center = r.center();
+    painter->drawLine(center + QPointF(-handle.width(), 0), center + QPointF(handle.width(), 0));
+    painter->drawLine(center + QPointF(0, handle.height()), center + QPointF(0, -handle.height()));
 }
 
 bool OnMonitorRectItem::getView()
@@ -278,8 +291,8 @@ bool OnMonitorRectItem::getView()
     if (m_view)
         return true;
 
-    if (scene() && scene()->views().count()) {
-        m_view = scene()->views()[0];
+    if (scene() && !scene()->views().isEmpty()) {
+        m_view = scene()->views().first();
         return true;
     } else {
         return false;