]> git.sesse.net Git - kdenlive/commitdiff
* Cleanup timecode display widget
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 15 Feb 2011 00:25:08 +0000 (00:25 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 15 Feb 2011 00:25:08 +0000 (00:25 +0000)
* Fix guide inserted at wrong pos when editing time in dialog

svn path=/trunk/kdenlive/; revision=5409

src/CMakeLists.txt
src/abstractscopewidget.cpp
src/clipdurationdialog.cpp
src/customtrackview.cpp
src/geometrywidget.cpp
src/positionedit.cpp
src/smallruler.cpp
src/timecodedisplay.cpp
src/timecodedisplay.h
src/widgets/timecodedisplay_ui.ui [deleted file]

index 817fb835807743246d354e955c247d1f60577398..555e3b48c81cf810741dfcdf4de5cdd853697243 100644 (file)
@@ -120,7 +120,6 @@ kde4_add_ui_files(kdenlive_UI
   widgets/cliptranscode_ui.ui
   widgets/templateclip_ui.ui
   widgets/keyframeeditor_ui.ui
-  widgets/timecodedisplay_ui.ui
   widgets/tracksconfigdialog_ui.ui
   widgets/urlval_ui.ui
   widgets/vectorscope_ui.ui
index a3b328cd9357485094f40cc1916595ae925e5613..2ef642bbcae1e2232a52cc0c144110de57cf127e 100644 (file)
@@ -20,6 +20,8 @@
 #include <QMouseEvent>
 #include <QPainter>
 
+#include <KConfigGroup>
+
 // Uncomment for Scope debugging.
 //#define DEBUG_ASW
 
index 920ca288e522d709fc35e3bc3ffeaaf176a09172..6365bdf1cc2636e3d45ba7b520045b534cb9cf38 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <KDebug>
 #include <KMessageBox>
+#include <KGlobalSettings>
 
 #include <QWheelEvent>
 
index b7cda93f09a83aed1f94e537cc4b39be3a801ebf..fa1076947c584798158245a2241724006430e1bd 100644 (file)
@@ -4997,7 +4997,8 @@ void CustomTrackView::slotAddGuide(bool dialog)
     if (dialog) {
         MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
         if (d.exec() != QDialog::Accepted) return;
-        marker.setComment(d.newMarker().comment());
+        marker = d.newMarker();
+        
     } else {
         marker.setComment(m_document->timecode().getDisplayTimecodeFromFrames(m_cursorPos, false));
     }
index efb8613c25e4e0636a9295d2ae4d4d9e2a45fb03..7eae9fd88d833f12a51ed73132166204efa141a0 100644 (file)
@@ -300,12 +300,14 @@ void GeometryWidget::slotPositionChanged(int pos, bool seek)
             m_scene->removeItem(m_previous);
         }
     }
+    else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
+        // previous frame already here, do nothing
+    }
     else {
         if (m_previous == NULL) {
             m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
             m_previous->setBrush(QColor(200, 200, 0, 20));
             m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
-            
             m_previous->setPos(previousItem.x(), previousItem.y());
             m_previous->setZValue(-1);
             m_previous->setEnabled(false);
@@ -314,7 +316,8 @@ void GeometryWidget::slotPositionChanged(int pos, bool seek)
             m_previous->setPos(previousItem.x(), previousItem.y());
             m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
         }
-        m_scene->addItem(m_previous);
+        m_previous->setData(Qt::UserRole, previousItem.frame());
+        if (m_previous->scene() == 0) m_scene->addItem(m_previous);
     }
 
     m_rect->setPos(item.x(), item.y());
index 51ac2dfb98c011628fc565f7573ede9627c625e7..f03b8da3c8135a7dde1b4a4bbb7380b9de7e0fa3 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <QLabel>
 #include <QSlider>
+#include <QHBoxLayout>
 
 PositionEdit::PositionEdit(const QString name, int pos, int min, int max, const Timecode tc, QWidget* parent) :
         QWidget(parent)
index 4011bf3c7b537deec8d1967ed77eeb8cbaacc44d..5f287b352388227586478e786c116840d0469cbb 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <KDebug>
 #include <KColorScheme>
+#include <KLocale>
 
 #include <QMouseEvent>
 #include <QStylePainter>
index 55d5fd08525d8a6f3ea6fd8067e388164616e925..72cb9a5b36f4b9ab0c2b8897799ff6c2472b606e 100644 (file)
 #include <kglobal.h>
 #include <klocale.h>
 #include <kdebug.h>
-
+#include <krestrictedline.h>
+#include <KColorScheme>
+#include <KRestrictedLine>
 
 TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent)
-        : QWidget(parent),
+        : QAbstractSpinBox(parent),
         m_timecode(t),
         m_minimum(0),
         m_maximum(-1)
 {
-    setupUi(this);
-    lineedit->setFont(KGlobalSettings::toolBarFont());
-    QFontMetrics fm = lineedit->fontMetrics();
-    lineedit->setMaximumWidth(fm.width("88:88:88:888"));
-    setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
+    lineEdit()->setFont(KGlobalSettings::toolBarFont());
+    lineEdit()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+    QFontMetrics fm = lineEdit()->fontMetrics();
+    setMinimumWidth(fm.width("88:88:88:88888888") + contentsMargins().right() + contentsMargins().right());
+    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+    setAccelerated(true);
 
     setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
 
-    connect(uparrow, SIGNAL(clicked()), this, SLOT(slotValueUp()));
-    connect(downarrow, SIGNAL(clicked()), this, SLOT(slotValueDown()));
-    connect(lineedit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
-    connect(lineedit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(slotCursorPositionChanged(int, int)));
+    connect(lineEdit(), SIGNAL(returnPressed()), this, SLOT(slotEditingFinished()));
+    connect(lineEdit(), SIGNAL(cursorPositionChanged(int, int)), this, SLOT(slotCursorPositionChanged(int, int)));
 }
 
-void TimecodeDisplay::slotValueUp()
+// virtual protected
+QAbstractSpinBox::StepEnabled TimecodeDisplay::stepEnabled () const
 {
-    int val = getValue();
-    val++;
-    setValue(val);
-    lineedit->clearFocus();
-    emit editingFinished();
+    QAbstractSpinBox::StepEnabled result = QAbstractSpinBox::StepNone;
+    if (getValue() > m_minimum) result |= QAbstractSpinBox::StepDownEnabled;
+    if (m_maximum == -1 || getValue() < m_maximum) result |= QAbstractSpinBox::StepUpEnabled;
+    return result;
 }
 
-void TimecodeDisplay::slotValueDown()
+// virtual
+void TimecodeDisplay::stepBy(int steps)
 {
     int val = getValue();
-    val--;
+    val += steps;
     setValue(val);
-    lineedit->clearFocus();
     emit editingFinished();
 }
 
@@ -73,11 +74,11 @@ void TimecodeDisplay::setTimeCodeFormat(bool frametimecode, bool init)
     int val = getValue();
     m_frametimecode = frametimecode;
     if (m_frametimecode) {
-        QIntValidator *valid = new QIntValidator(lineedit);
+        QIntValidator *valid = new QIntValidator(lineEdit());
         valid->setBottom(0);
-        lineedit->setValidator(valid);
+        lineEdit()->setValidator(valid);
     } else {
-        lineedit->setValidator(m_timecode.validator());
+        lineEdit()->setValidator(m_timecode.validator());
     }
     setValue(val);
 }
@@ -95,21 +96,28 @@ void TimecodeDisplay::updateTimeCode(Timecode t)
 
 void TimecodeDisplay::keyPressEvent(QKeyEvent *e)
 {
-    if (e->key() == Qt::Key_Up)
-        slotValueUp();
-    else if (e->key() == Qt::Key_Down)
-        slotValueDown();
+    if (e->key() == Qt::Key_Return)
+        slotEditingFinished();
     else
-        QWidget::keyPressEvent(e);
+        QAbstractSpinBox::keyPressEvent(e);
 }
 
+void TimecodeDisplay::mouseReleaseEvent(QMouseEvent *e)
+{
+    QAbstractSpinBox::mouseReleaseEvent(e);
+    if (!lineEdit()->underMouse()) {
+        clearFocus();
+    }
+}
+
+/*
 void TimecodeDisplay::wheelEvent(QWheelEvent *e)
 {
     if (e->delta() > 0)
         slotValueUp();
     else
         slotValueDown();
-}
+}*/
 
 
 int TimecodeDisplay::maximum() const
@@ -124,8 +132,8 @@ int TimecodeDisplay::minimum() const
 
 int TimecodeDisplay::getValue() const
 {
-    if (m_frametimecode) return lineedit->text().toInt();
-    else return m_timecode.getFrameCount(lineedit->text());
+    if (m_frametimecode) return lineEdit()->text().toInt();
+    else return m_timecode.getFrameCount(lineEdit()->text());
 }
 
 GenTime TimecodeDisplay::gentime() const
@@ -156,15 +164,15 @@ void TimecodeDisplay::setValue(int value)
     if (m_maximum > m_minimum && value > m_maximum)
         value = m_maximum;
 
-    if (value == getValue() && !lineedit->text().isEmpty()) return;
-    downarrow->setEnabled(value > m_minimum);
-    uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum);
+    if (value == getValue() && !lineEdit()->text().isEmpty()) return;
+    //downarrow->setEnabled(value > m_minimum);
+    //uparrow->setEnabled(m_maximum < m_minimum || value < m_maximum);
 
     if (m_frametimecode)
-        lineedit->setText(QString::number(value));
+        lineEdit()->setText(QString::number(value));
     else {
         QString v = m_timecode.getTimecodeFromFrames(value);
-        lineedit->setText(v);
+        lineEdit()->setText(v);
     }
 }
 
@@ -175,24 +183,32 @@ void TimecodeDisplay::setValue(GenTime value)
 
 void TimecodeDisplay::slotCursorPositionChanged(int oldPos, int newPos)
 {
-    lineedit->blockSignals(true);
-    QString text = lineedit->text();
+    if (!lineEdit()->hasFocus()) return;
+    lineEdit()->blockSignals(true);
+    QString text = lineEdit()->text();
 
     if (newPos < text.size() && !text.at(newPos).isDigit()) {
         // char at newPos is a separator (':' or ';')
 
         // make it possible move the cursor backwards at separators
         if (newPos == oldPos - 1)
-            lineedit->setSelection(newPos, -1);
+            lineEdit()->setSelection(newPos, -1);
         else
-            lineedit->setSelection(newPos + 2, -1);
+            lineEdit()->setSelection(newPos + 2, -1);
     } else if (newPos < text.size()) {
-        lineedit->setSelection(newPos + 1, -1);
+        lineEdit()->setSelection(newPos + 1, -1);
     } else {
-        lineedit->setSelection(newPos, -1);
+        lineEdit()->setSelection(newPos, -1);
     }
 
-    lineedit->blockSignals(false);
+    lineEdit()->blockSignals(false);
+}
+
+void TimecodeDisplay::slotEditingFinished()
+{
+    clearFocus();
+    lineEdit()->deselect();
+    emit editingFinished();
 }
 
 #include <timecodedisplay.moc>
index 28045886efa149c6ee5bd9e824efe6a84c30a2c8..a18f757f08ddb464db497d33b7c06375be83bb61 100644 (file)
 #ifndef TIMECODEDISPLAY_H_
 #define TIMECODEDISPLAY_H_
 
-#include "ui_timecodedisplay_ui.h"
 #include "timecode.h"
 #include "gentime.h"
 
+#include <QAbstractSpinBox>
 
 /**
  * @class TimecodeDisplay
@@ -33,7 +33,7 @@
  * TimecodeDisplay can be used to insert eigther frames
  * or a timecode in the format HH:MM:SS:FF
  */
-class TimecodeDisplay : public QWidget, public Ui::TimecodeDisplay_UI
+class TimecodeDisplay : public QAbstractSpinBox
 {
     Q_OBJECT
 
@@ -74,6 +74,8 @@ public:
      * @param t the new timecode */
     void updateTimeCode(Timecode t);
 
+    virtual void stepBy(int steps);
+
 private:
     /** timecode for widget */
     Timecode m_timecode;
@@ -95,8 +97,7 @@ public slots:
     void slotUpdateTimeCodeFormat();
 
 private slots:
-    void slotValueUp();
-    void slotValueDown();
+    void slotEditingFinished();
 
     /** @brief Updates the selection when the cursor position changed.
      * The digit after the cursor will be selected.
@@ -115,7 +116,9 @@ signals:
 
 protected:
     virtual void keyPressEvent(QKeyEvent *e);
-    virtual void wheelEvent(QWheelEvent *e);
+    virtual void mouseReleaseEvent(QMouseEvent *);
+//    virtual void wheelEvent(QWheelEvent *e);
+    virtual QAbstractSpinBox::StepEnabled stepEnabled () const;
 
 };
 
diff --git a/src/widgets/timecodedisplay_ui.ui b/src/widgets/timecodedisplay_ui.ui
deleted file mode 100644 (file)
index b31dbc8..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>TimecodeDisplay_UI</class>
- <widget class="QWidget" name="TimecodeDisplay_UI">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>128</width>
-    <height>25</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <layout class="QGridLayout" name="gridLayout_2">
-   <property name="margin">
-    <number>0</number>
-   </property>
-   <property name="horizontalSpacing">
-    <number>-1</number>
-   </property>
-   <item row="0" column="0">
-    <widget class="QFrame" name="frame">
-     <property name="styleSheet">
-      <string notr="true">QToolButton {border: 0px;}</string>
-     </property>
-     <property name="frameShape">
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow">
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QGridLayout" name="gridLayout">
-      <property name="margin">
-       <number>0</number>
-      </property>
-      <property name="spacing">
-       <number>0</number>
-      </property>
-      <item row="0" column="0">
-       <widget class="KRestrictedLine" name="lineedit">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="autoFillBackground">
-         <bool>false</bool>
-        </property>
-        <property name="frame">
-         <bool>false</bool>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="2">
-       <layout class="QVBoxLayout" name="verticalLayout">
-        <property name="spacing">
-         <number>1</number>
-        </property>
-        <item>
-         <widget class="QToolButton" name="uparrow">
-          <property name="text">
-           <string>...</string>
-          </property>
-          <property name="iconSize">
-           <size>
-            <width>4</width>
-            <height>4</height>
-           </size>
-          </property>
-          <property name="autoRaise">
-           <bool>true</bool>
-          </property>
-          <property name="arrowType">
-           <enum>Qt::UpArrow</enum>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QToolButton" name="downarrow">
-          <property name="text">
-           <string>...</string>
-          </property>
-          <property name="iconSize">
-           <size>
-            <width>4</width>
-            <height>4</height>
-           </size>
-          </property>
-          <property name="autoRaise">
-           <bool>true</bool>
-          </property>
-          <property name="arrowType">
-           <enum>Qt::DownArrow</enum>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-      <item row="0" column="1">
-       <widget class="Line" name="line">
-        <property name="orientation">
-         <enum>Qt::Vertical</enum>
-        </property>
-       </widget>
-      </item>
-     </layout>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <customwidgets>
-  <customwidget>
-   <class>KLineEdit</class>
-   <extends>QLineEdit</extends>
-   <header>klineedit.h</header>
-  </customwidget>
-  <customwidget>
-   <class>KRestrictedLine</class>
-   <extends>KLineEdit</extends>
-   <header>krestrictedline.h</header>
-  </customwidget>
- </customwidgets>
- <resources/>
- <connections/>
-</ui>