]> git.sesse.net Git - kdenlive/blobdiff - src/smallruler.cpp
Changing the timecode format in statur bar (from hh:mm:ss:ff to frames) now also...
[kdenlive] / src / smallruler.cpp
index 7575927a012d07b803cdb96c3fc51dd793771ca0..8881329c08bb330997879da4bf2fcb17697d87bd 100644 (file)
  ***************************************************************************/
 
 
-#include <QMouseEvent>
-#include <QStylePainter>
+#include "smallruler.h"
 
 #include <KDebug>
 
-#include "smallruler.h"
-
+#include <QMouseEvent>
+#include <QStylePainter>
 
-SmallRuler::SmallRuler(QWidget *parent)
-        : QWidget(parent), m_scale(1), m_maxval(25) {
+SmallRuler::SmallRuler(QWidget *parent) :
+        QWidget(parent),
+        m_scale(1),
+        m_maxval(25)
+{
     m_zoneStart = 10;
     m_zoneEnd = 60;
+    m_zoneColor = QColor(133, 255, 143);
 }
 
-void SmallRuler::adjustScale(int maximum) {
+void SmallRuler::adjustScale(int maximum)
+{
     m_maxval = maximum;
     m_scale = (double) width() / (double) maximum;
     if (m_scale == 0) m_scale = 1;
@@ -51,37 +55,57 @@ void SmallRuler::adjustScale(int maximum) {
     update();
 }
 
-void SmallRuler::setZone(int start, int end) {
+void SmallRuler::setZone(int start, int end)
+{
     if (start != -1) {
-        if (end != -1 && start >= end) return;
-        else if (end == -1 && start >= m_zoneEnd) return;
-        m_zoneStart = start;
+        if (end != -1 && start >= end) {
+            m_zoneEnd = qMin(m_maxval, end + (start - m_zoneStart));
+            m_zoneStart = start;
+        } else if (end == -1 && start >= m_zoneEnd) {
+            m_zoneEnd = qMin(m_maxval, m_zoneEnd + (start - m_zoneStart));
+            m_zoneStart = start;
+        } else m_zoneStart = start;
     }
     if (end != -1) {
-        if (start != -1 && end <= start) end = m_zoneEnd;
-        else if (start == -1 && end <= m_zoneStart) end = m_zoneEnd;
-        m_zoneEnd = end;
+        if (start != -1 && end <= start) {
+            m_zoneStart = qMax(0, start - (m_zoneEnd - end));
+            m_zoneEnd = end;
+        } else if (start == -1 && end <= m_zoneStart) {
+            m_zoneStart = qMax(0, m_zoneStart - (m_zoneEnd - end));
+            m_zoneEnd = end;
+        } else m_zoneEnd = end;
     }
     update();
 }
 
-QPoint SmallRuler::zone() {
+QPoint SmallRuler::zone()
+{
     return QPoint(m_zoneStart, m_zoneEnd);
 }
 
 // virtual
-void SmallRuler::mousePressEvent(QMouseEvent * event) {
+void SmallRuler::mousePressEvent(QMouseEvent * event)
+{
     const int pos = event->x() / m_scale;
-    emit seekRenderer((int) pos);
+    if (event->button() == Qt::RightButton) {
+        // Right button clicked, move selection zone
+        if (qAbs(pos - m_zoneStart) < qAbs(pos - m_zoneEnd)) m_zoneStart = pos;
+        else m_zoneEnd = pos;
+        emit zoneChanged(QPoint(m_zoneStart, m_zoneEnd));
+        update();
+
+    } else emit seekRenderer((int) pos);
 }
 
 // virtual
-void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
+void SmallRuler::mouseMoveEvent(QMouseEvent * event)
+{
     const int pos = event->x() / m_scale;
-    emit seekRenderer((int) pos);
+    if (event->buttons() & Qt::LeftButton) emit seekRenderer((int) pos);
 }
 
-void SmallRuler::slotNewValue(int value) {
+void SmallRuler::slotNewValue(int value)
+{
     m_cursorFramePosition = value;
     int oldPos = m_cursorPosition;
     m_cursorPosition = value * m_scale;
@@ -93,12 +117,14 @@ void SmallRuler::slotNewValue(int value) {
 }
 
 //virtual
-void SmallRuler::resizeEvent(QResizeEvent *) {
+void SmallRuler::resizeEvent(QResizeEvent *)
+{
     adjustScale(m_maxval);
 }
 
 // virtual
-void SmallRuler::paintEvent(QPaintEvent *e) {
+void SmallRuler::paintEvent(QPaintEvent *e)
+{
 
     QPainter p(this);
     QRect r = e->rect();
@@ -110,7 +136,7 @@ void SmallRuler::paintEvent(QPaintEvent *e) {
     const int zoneStart = (int)(m_zoneStart * m_scale);
     const int zoneEnd = (int)(m_zoneEnd * m_scale);
 
-    p.fillRect(QRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2), QBrush(QColor(133, 255, 143)));
+    p.fillRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2, m_zoneColor);
 
     if (r.top() < 9) {
         // draw the little marks