]> git.sesse.net Git - kdenlive/commitdiff
Make communication between timeline and its ruler easier
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 6 Mar 2008 20:42:03 +0000 (20:42 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 6 Mar 2008 20:42:03 +0000 (20:42 +0000)
svn path=/branches/KDE4/; revision=2001

src/customruler.cpp
src/customruler.h
src/customtrackview.cpp
src/customtrackview.h
src/trackview.cpp
src/trackview.h

index 88713f23432ba5103a418f092a498af257790561..12a0c06530fe039710537f23edb30589c2049e68 100644 (file)
@@ -74,8 +74,8 @@ const int CustomRuler::comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 725,
                                         12000
                                       };
 
-CustomRuler::CustomRuler(Timecode tc, QWidget *parent)
-        : KRuler(parent), m_timecode(tc) {
+CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent)
+        : KRuler(parent), m_timecode(tc), m_view(parent) {
     slotNewOffset(0);
     setRulerMetricStyle(KRuler::Pixel);
     setLength(1024);
@@ -88,43 +88,29 @@ CustomRuler::CustomRuler(Timecode tc, QWidget *parent)
 
 // virtual
 void CustomRuler::mousePressEvent(QMouseEvent * event) {
-    int pos = event->x();
-    slotMoveCursor(pos, true);
+    int pos = (event->x() + offset());
+    m_view->setCursorPos(pos);
 }
 
 // virtual
 void CustomRuler::mouseMoveEvent(QMouseEvent * event) {
-    int pos = event->x();
-    slotMoveCursor(pos, true);
+    int pos = (event->x() + offset());
+    m_view->setCursorPos(pos);
 }
 
 void CustomRuler::slotMoveRuler(int newPos) {
     int diff = offset() - newPos;
     KRuler::slotNewOffset(newPos);
-    KRuler::slotNewValue(m_cursorPosition * FRAME_SIZE * pixelPerMark() - offset());//value() + diff);
 }
 
-void CustomRuler::slotMoveCursor(int _value, bool emitSignal) {
-    m_cursorPosition = (_value + offset()) / pixelPerMark() / FRAME_SIZE;
-    kDebug() << "RULER FR SZ: " << FRAME_SIZE << ", PPM: " << pixelPerMark();
-    KRuler::slotNewValue(m_cursorPosition * FRAME_SIZE * pixelPerMark() - offset());
-
-    if (emitSignal) emit cursorMoved(m_cursorPosition);
-}
-
-
-void CustomRuler::slotNewValue(int _value, bool emitSignal) {
-    m_cursorPosition = _value / pixelPerMark();
-    if (emitSignal) emit cursorMoved(m_cursorPosition / FRAME_SIZE);
-    KRuler::slotNewValue(_value * pixelPerMark() - offset());
+void CustomRuler::slotCursorMoved(int oldpos, int newpos) {
+    //TODO: optimize (redraw only around cursor positions
+    update();
 }
 
 void CustomRuler::setPixelPerMark(double rate) {
     int scale = comboScale[(int) rate];
-    int newPos = m_cursorPosition * (1.0 / scale);
     KRuler::setPixelPerMark(1.0 / scale);
-    KRuler::slotNewValue(m_cursorPosition * FRAME_SIZE * pixelPerMark() - offset());
-    //KRuler::slotNewValue( newPos );
 }
 
 // virtual
@@ -133,8 +119,7 @@ void CustomRuler::paintEvent(QPaintEvent * /*e*/) {
 
     QStylePainter p(this);
 
-
-    int value  = this->value();
+    int value  = m_view->cursorPos() - offset();
     int minval = minimum();
     int maxval = maximum() + offset() - endOffset();
 
index 5fd642c585867ada07ceef1a2c1e8c098e623eba..b0b28198872881ea9d527751f6e972dd3dbd3c9f 100644 (file)
@@ -3,13 +3,14 @@
 
 #include <KRuler>
 
-#include <timecode.h>
+#include "customtrackview.h"
+#include "timecode.h"
 
 class CustomRuler : public KRuler {
     Q_OBJECT
 
 public:
-    CustomRuler(Timecode tc, QWidget *parent = 0);
+    CustomRuler(Timecode tc, CustomTrackView *parent);
     virtual void mousePressEvent(QMouseEvent * event);
     virtual void mouseMoveEvent(QMouseEvent * event);
     void setPixelPerMark(double rate);
@@ -20,15 +21,12 @@ protected:
 private:
     int m_cursorPosition;
     Timecode m_timecode;
-    void slotMoveCursor(int _value, bool emitSignal);
+    CustomTrackView *m_view;
 
 public slots:
-    void slotNewValue(int _value, bool emitSignal = false);
     void slotMoveRuler(int newPos);
+    void slotCursorMoved(int oldpos, int newpos);
 
-
-signals:
-    void cursorMoved(int);
 };
 
 #endif
index 54aa7b6d8218b11dbfd62f5b2584dc40baa81549..74488776aa2f2ccbf0851a5c6ef7f055f24865e7 100644 (file)
@@ -256,7 +256,6 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             m_moveOpMode = NONE;
             if (event->buttons() != Qt::NoButton) {
                 setCursorPos((int) mapToScene(event->pos().x(), 0).x());
-                emit cursorMoved(cursorPos());
             }
             if (m_visualTip) {
                 if (m_animation) delete m_animation;
@@ -319,7 +318,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
                 itemList.at(i)->setSelected(false);
             emit clipItemSelected(NULL);
             setCursorPos((int) mapToScene(event->x(), 0).x());
-            emit cursorMoved(cursorPos());
         }
     }
     updateSnapPoints(m_dragItem);
@@ -515,6 +513,7 @@ void CustomTrackView::deleteClip(int clipId) {
 }
 
 void CustomTrackView::setCursorPos(int pos, bool seek) {
+    emit cursorMoved(m_cursorPos, pos);
     m_cursorPos = pos;
     m_cursorLine->setPos(pos, 0);
     int frame =  pos / m_scale;
index 1436f3b01ccf7ba67c64a97028e528644f0b817a..e7a703ca2f53a380cacd3e3054ffc9e2efb5ed11 100644 (file)
@@ -103,7 +103,7 @@ private:
 
 
 signals:
-    void cursorMoved(int);
+    void cursorMoved(int, int);
     void zoomIn();
     void zoomOut();
     void mousePosition(int);
index fbdb7cc3381acdfed1db56d8440848ac31d759eb..2d5ade5b3e3d83040d374bb45465667d0d4614ee 100644 (file)
@@ -34,10 +34,6 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
     setMouseTracking(true);
     view = new Ui::TimeLine_UI();
     view->setupUi(this);
-    m_ruler = new CustomRuler(doc->timecode());
-    QVBoxLayout *layout = new QVBoxLayout;
-    view->ruler_frame->setLayout(layout);
-    layout->addWidget(m_ruler);
 
     m_scene = new QGraphicsScene();
     m_trackview = new CustomTrackView(doc, m_scene, this);
@@ -45,6 +41,11 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
     m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
     //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
 
+    m_ruler = new CustomRuler(doc->timecode(), m_trackview);
+    QVBoxLayout *layout = new QVBoxLayout;
+    view->ruler_frame->setLayout(layout);
+    layout->addWidget(m_ruler);
+
     m_headersLayout = new QVBoxLayout;
     m_headersLayout->setContentsMargins(0, 0, 0, 0);
     view->headers_frame->setLayout(m_headersLayout);
@@ -61,8 +62,7 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
       setEditMode("move");*/
 
     connect(view->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeZoom(int)));
-    connect(m_ruler, SIGNAL(cursorMoved(int)), this, SLOT(setCursorPos(int)));
-    connect(m_trackview, SIGNAL(cursorMoved(int)), this, SLOT(slotCursorMoved(int)));
+    connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
     connect(m_trackview, SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
     connect(m_trackview, SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
     connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
@@ -107,7 +107,7 @@ void TrackView::parseDocument(QDomDocument doc) {
         if (duration > m_projectDuration) m_projectDuration = duration;
     }
     m_trackview->setDuration(m_projectDuration);
-    slotCursorMoved(cursorPos, true);
+    //m_trackview->setCursorPos(cursorPos);
     //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
 }
 
@@ -116,19 +116,11 @@ void TrackView::slotDeleteClip(int clipId) {
 }
 
 void TrackView::setCursorPos(int pos) {
-    emit cursorMoved();
     m_trackview->setCursorPos(pos * m_scale);
 }
 
 void TrackView::moveCursorPos(int pos) {
     m_trackview->setCursorPos(pos * m_scale, false);
-    m_ruler->slotNewValue(pos * FRAME_SIZE, false);
-}
-
-void TrackView::slotCursorMoved(int pos, bool emitSignal) {
-    m_ruler->slotNewValue(pos * FRAME_SIZE / m_scale, emitSignal); //(int) m_trackview->mapToScene(QPoint(pos, 0)).x());
-    //m_trackview->setCursorPos(pos);
-    //m_trackview->invalidateScene(QRectF(), QGraphicsScene::ForegroundLayer);
 }
 
 void TrackView::slotChangeZoom(int factor) {
@@ -138,7 +130,6 @@ void TrackView::slotChangeZoom(int factor) {
     m_currentZoom = factor;
     m_trackview->setScale(m_scale);
     m_trackview->setCursorPos(pos * m_scale, false);
-    m_ruler->slotNewValue(pos * FRAME_SIZE, false);
     m_trackview->centerOn(QPointF(m_trackview->cursorPos(), 50));
 }
 
index 6777640d6060f3f4e92a3e87c412a4aab976246b..ee581858cd66feeef87d2f6cc559ea0717854770 100644 (file)
@@ -80,7 +80,6 @@ private:
 
 private slots:
     void slotChangeZoom(int factor);
-    void slotCursorMoved(int pos, bool slotCursorMoved = false);
     void slotZoomIn();
     void slotZoomOut();
     void setCursorPos(int pos);