]> git.sesse.net Git - kdenlive/commitdiff
Display mouse timecode position in statusbar
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 27 Jan 2008 20:27:59 +0000 (20:27 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 27 Jan 2008 20:27:59 +0000 (20:27 +0000)
svn path=/branches/KDE4/; revision=1824

src/clipitem.cpp
src/customtrackview.cpp
src/customtrackview.h
src/mainwindow.cpp
src/mainwindow.h
src/trackview.cpp
src/trackview.h

index d8e0c59f87ee1e41719d2784d8813a74cd34b144..8db033fbc029043702f291e8bc425db9d8f79055 100644 (file)
@@ -205,7 +205,7 @@ int ClipItem::endPos()
     if (isSelected()) {
       fades = QBrush(QColor(200, 50, 50, 150));
     }
-    else fades = QBrush(QColor(200, 200, 200, 150));
+    else fades = QBrush(QColor(200, 200, 200, 200));
 
     if (m_startFade != 0) {
       QPainterPath fadeInPath;
index ae047716e3088900f551a109188665a3da82e635..1ca8a722a49f8771d86edc5d94fe33b04011eb8a 100644 (file)
@@ -81,6 +81,7 @@ void CustomTrackView::wheelEvent ( QWheelEvent * e )
 void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
 {
   int pos = event->x();
+  emit mousePosition(mapToScene(event->pos()).x() / m_scale);
   /*if (event->modifiers() == Qt::ControlModifier)
     setDragMode(QGraphicsView::ScrollHandDrag);
   else if (event->modifiers() == Qt::ShiftModifier) 
@@ -89,9 +90,9 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
 
       if (m_dragItem) { //event->button() == Qt::LeftButton) {
        // a button was pressed, delete visual tips
-
        if (m_operationMode == MOVE) {
-         int moveX = mapToScene(event->pos()).x();
+         int snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
+         int moveX = snappedPos; //mapToScene(event->pos()).x();
          //kDebug()<<"///////  MOVE CLIP, EVENTĀ Y: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
          int moveTrack = (int)  mapToScene(event->pos()).y() / 50;
          int currentTrack = m_dragItem->track();
@@ -101,7 +102,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
 
          int offset = moveTrack - currentTrack;
          if (offset != 0) offset = 50 * offset;
-         m_dragItem->moveTo((moveX - m_clickPoint) / m_scale, m_scale, offset, moveTrack);
+         m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack);
        }
        else if (m_operationMode == RESIZESTART) {
          int pos = mapToScene(event->pos()).x();
@@ -261,6 +262,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
 {
   int pos = event->x();
+  updateSnapPoints();
   if (event->modifiers() == Qt::ControlModifier) 
     setDragMode(QGraphicsView::ScrollHandDrag);
   else if (event->modifiers() == Qt::ShiftModifier) 
@@ -469,6 +471,31 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo
   }
 }
 
+double CustomTrackView::getSnapPointForPos(double pos)
+{
+  for (int i = 0; i < m_snapPoints.size(); ++i) {
+    if (abs(pos - m_snapPoints.at(i) * m_scale) < 6) return m_snapPoints.at(i) * m_scale;
+    if (m_snapPoints.at(i) > pos) break;
+  }
+  return pos;
+}
+
+void CustomTrackView::updateSnapPoints()
+{
+  m_snapPoints.clear();
+  QList<QGraphicsItem *> itemList = items();
+  for (int i = 0; i < itemList.count(); i++) {
+    if (itemList.at(i)->type() == 70000) {
+      ClipItem *item = (ClipItem *)itemList.at(i);
+      m_snapPoints.append(item->startPos());
+      if (item->fadeIn() != 0) m_snapPoints.append(item->startPos() + item->fadeIn());
+      m_snapPoints.append(item->endPos());
+      if (item->fadeOut() != 0) m_snapPoints.append(item->endPos() - item->fadeOut());      
+    }
+  }
+  qSort(m_snapPoints);
+}
+
 
 void CustomTrackView::setScale(double scaleFactor)
 {
index 4ee97e3185bc10b2487dfa1ed01edebe26810de4..b1ab619c3df5117d272a3ea9c4610a9bbf905aea 100644 (file)
@@ -82,11 +82,15 @@ class CustomTrackView : public QGraphicsView
     QColor m_tipColor;
     double m_scale;
     int m_clickPoint;
+    QList <int> m_snapPoints;
+    void updateSnapPoints();
+    double getSnapPointForPos(double pos);
 
   signals:
     void cursorMoved(int);
     void zoomIn();
     void zoomOut();
+    void mousePosition(int);
 
 };
 
index c0aff81386d50ece1e120373c579814733fe3c4d..e9b4509699c49a3bdd2de1218240a0c90abdbdf1 100644 (file)
 #include <KRuler>
 #include <KConfigDialog>
 #include <KXMLGUIFactory>
+#include <KStatusBar>
 
 #include <mlt++/Mlt.h>
 
 #include "mainwindow.h"
 #include "kdenlivesettings.h"
 #include "ui_configmisc_ui.h"
+
+#define ID_STATUS_MSG 1
+#define ID_EDITMODE_MSG 2
+#define ID_TIMELINE_MSG 3
+#define ID_TIMELINE_POS 4
+#define ID_TIMELINE_FORMAT 5
  
 MainWindow::MainWindow(QWidget *parent)
     : KXmlGuiWindow(parent),
@@ -114,6 +121,13 @@ MainWindow::MainWindow(QWidget *parent)
 
   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
   setCentralWidget(m_timelineArea);
+
+  m_timecodeFormat = new KComboBox(this);
+  m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
+  m_timecodeFormat->addItem(i18n("Frames"));
+  statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
+  statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat); 
+
   setupGUI(Default, "kdenliveui.rc");
 
   connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
@@ -287,6 +301,18 @@ void MainWindow::openFile(const KUrl &url) //new
   //connectDocument(trackView, doc);
 }
 
+void MainWindow::slotUpdateMousePosition(int pos)
+{
+  if (m_activeDocument)
+    switch(m_timecodeFormat->currentIndex()) {
+      case 0:
+       statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
+       break;
+    default:
+      statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
+    }
+}
+
 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
 {
   //m_projectMonitor->stop();
@@ -295,6 +321,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang
     m_activeDocument->setProducers(m_projectList->producersList());
     m_activeDocument->setRenderer(NULL);
   }
+  connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
   m_projectList->setDocument(doc);
   m_monitorManager->setTimecode(doc->timecode());
   doc->setRenderer(m_projectMonitor->render);
index 388ea19430440689ec63a2662bba69b2d6ba9283..c7fd6d2f7eda37bb375fa53d12cda967fa8940a6 100644 (file)
@@ -31,6 +31,7 @@
 #include <KTabWidget>
 #include <KUndoStack>
 #include <KRecentFilesAction>
+#include <KComboBox>
 
 #include "projectlist.h"
 #include "monitor.h"
@@ -80,6 +81,8 @@ class MainWindow : public KXmlGuiWindow
     QAction *m_undo;
     QAction *m_redo;
 
+    KComboBox *m_timecodeFormat;
+
     QDockWidget *overviewDock;
     CustomTrackView *m_overView;
 
@@ -103,6 +106,7 @@ class MainWindow : public KXmlGuiWindow
     void slotConnectMonitors();
     void slotRaiseMonitor(bool clipMonitor);
     void slotSetClipDuration(int id, int duration);
+    void slotUpdateMousePosition(int pos);
 };
  
 #endif
index 54c78caf75d8f042372be2f0b74b2c511a086ce2..a6104ddbe709246e3799ea6cadc2ec7409818eb7 100644 (file)
@@ -70,6 +70,7 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
   connect(m_trackview, SIGNAL(zoomIn ()), this, SLOT(slotZoomIn()));
   connect(m_trackview, SIGNAL(zoomOut ()), this, SLOT(slotZoomOut()));
   connect(m_trackview->horizontalScrollBar(), SIGNAL(sliderMoved( int )), m_ruler, SLOT(slotMoveRuler( int )));
+  connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
 
   view->horizontalSlider->setValue(4);
   m_currentZoom = view->horizontalSlider->value();
index 39ca417f87789433bdafb6b5b292ac14590e9267..6c35a58ec099cb67f66d84690b50226d39a381f8 100644 (file)
@@ -95,6 +95,9 @@ class TrackView : public QWidget
     void slotCursorMoved(int pos, bool slotCursorMoved = false);
     void slotZoomIn();
     void slotZoomOut();
+
+  signals:
+    void mousePosition(int);
 };
 
 #endif