From: Jean-Baptiste Mardelle Date: Sun, 23 May 2010 21:57:55 +0000 (+0000) Subject: Add widget for easier timecode display X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=997748156e63b2e28c313521d7ff43e5ed77cb41;p=kdenlive Add widget for easier timecode display svn path=/trunk/kdenlive/; revision=4480 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2c97a22..36189bed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,6 +88,7 @@ kde4_add_ui_files(kdenlive_UI widgets/geometryposition_ui.ui widgets/templateclip_ui.ui widgets/keyframeeditor_ui.ui + widgets/timecodedisplay_ui.ui ) set(kdenlive_SRCS @@ -187,6 +188,7 @@ set(kdenlive_SRCS KoSliderCombo.cpp kis_cubic_curve.cpp kis_curve_widget.cpp + timecodedisplay.cpp ) add_definitions( ${KDE4_DEFINITIONS} ) diff --git a/src/geometryval.cpp b/src/geometryval.cpp index 037b4ebd..b6c5e823 100644 --- a/src/geometryval.cpp +++ b/src/geometryval.cpp @@ -37,9 +37,14 @@ Geometryval::Geometryval(const MltVideoProfile profile, Timecode t, QPoint frame m_path(NULL), m_fixedMode(false), m_frameSize(frame_size), - m_startPoint(startPoint) + m_startPoint(startPoint), + m_timePos(t) { setupUi(this); + m_timePos.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); + toolbarlayout->addWidget(&m_timePos); + toolbarlayout->insertStretch(-1); + QVBoxLayout* vbox = new QVBoxLayout(widget); m_sceneview = new QGraphicsView(this); m_sceneview->setBackgroundBrush(QBrush(Qt::black)); @@ -107,8 +112,6 @@ Geometryval::Geometryval(const MltVideoProfile profile, Timecode t, QPoint frame connect(buttonAdd , SIGNAL(clicked()) , this , SLOT(slotAddFrame())); connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateTransitionProperties())); connect(m_scene, SIGNAL(doubleClickEvent()), this, SLOT(slotGeometry())); - connect(pos_up, SIGNAL(clicked()), this, SLOT(slotPosUp())); - connect(pos_down, SIGNAL(clicked()), this, SLOT(slotPosDown())); buttonhcenter->setIcon(KIcon("kdenlive-align-hor")); buttonhcenter->setToolTip(i18n("Align item horizontally")); @@ -224,9 +227,7 @@ void Geometryval::slotResizeCustom() void Geometryval::slotTransparencyChanged(int transp) { - int pos; - if (KdenliveSettings::frametimecode()) pos = timePos->text().toInt(); - else pos = m_timecode.getFrameCount(timePos->text()); + int pos = m_timePos.value(); Mlt::GeometryItem item; int error = m_geom->fetch(&item, pos); if (error || item.key() == false) { @@ -246,57 +247,16 @@ void Geometryval::slotSyncCursor() void Geometryval::updateTimecodeFormat() { - timePos->setInputMask(""); - if (KdenliveSettings::frametimecode()) { - int frames = m_timecode.getFrameCount(timePos->text()); - QIntValidator *valid = new QIntValidator(this); - valid->setBottom(0); - timePos->setValidator(valid); - timePos->setText(QString::number(frames)); - } else { - int pos = timePos->text().toInt(); - timePos->setValidator(m_timecode.validator()); - timePos->setText(m_timecode.getTimecodeFromFrames(pos)); - } -} - -void Geometryval::slotPosUp() -{ - int pos; - if (KdenliveSettings::frametimecode()) pos = timePos->text().toInt(); - else pos = m_timecode.getFrameCount(timePos->text()); - pos ++; - if (pos > m_helper->frameLength) pos = m_helper->frameLength; - if (KdenliveSettings::frametimecode()) { - timePos->setText(QString::number(pos)); - } else timePos->setText(m_timecode.getTimecodeFromFrames(pos)); - slotPositionChanged(); -} - -void Geometryval::slotPosDown() -{ - int pos; - if (KdenliveSettings::frametimecode()) pos = timePos->text().toInt(); - else pos = m_timecode.getFrameCount(timePos->text()); - pos --; - if (pos < 0) pos = 0; - if (KdenliveSettings::frametimecode()) { - timePos->setText(QString::number(pos)); - } else timePos->setText(m_timecode.getTimecodeFromFrames(pos)); - slotPositionChanged(); + m_timePos.slotPrepareTimeCodeFormat(m_timecode); } void Geometryval::slotPositionChanged(int pos, bool seek) { if (pos == -1) { - if (KdenliveSettings::frametimecode()) pos = timePos->text().toInt(); - else pos = m_timecode.getFrameCount(timePos->text()); + pos = m_timePos.value(); } if (seek && KdenliveSettings::transitionfollowcursor()) emit seekToPos(pos + m_startPoint); - if (KdenliveSettings::frametimecode()) { - timePos->setText(QString::number(pos)); - } else timePos->setText(m_timecode.getTimecodeFromFrames(pos)); - + m_timePos.setValue(pos); //spinPos->setValue(pos); m_helper->setValue(pos); Mlt::GeometryItem item; @@ -329,9 +289,7 @@ void Geometryval::slotDeleteFrame(int pos) { // check there is more than one keyframe Mlt::GeometryItem item; - int frame; - if (KdenliveSettings::frametimecode()) frame = timePos->text().toInt(); - else frame = m_timecode.getFrameCount(timePos->text()); + int frame = m_timePos.value(); if (pos == -1) pos = frame; int error = m_geom->next_key(&item, pos + 1); @@ -355,9 +313,7 @@ void Geometryval::slotDeleteFrame(int pos) void Geometryval::slotAddFrame(int pos) { - int frame; - if (KdenliveSettings::frametimecode()) frame = timePos->text().toInt(); - else frame = m_timecode.getFrameCount(timePos->text()); + int frame = m_timePos.value(); if (pos == -1) pos = frame; Mlt::GeometryItem item; item.frame(pos); @@ -389,10 +345,7 @@ void Geometryval::slotNextFrame() // Go to end pos = m_helper->frameLength; } else pos = item.frame(); - - if (KdenliveSettings::frametimecode()) { - timePos->setText(QString::number(pos)); - } else timePos->setText(m_timecode.getTimecodeFromFrames(pos)); + m_timePos.setValue(pos); slotPositionChanged(); } @@ -403,9 +356,7 @@ void Geometryval::slotPreviousFrame() kDebug() << "// SEEK TO NEXT KFR: " << error; if (error) return; int pos = item.frame(); - if (KdenliveSettings::frametimecode()) { - timePos->setText(QString::number(pos)); - } else timePos->setText(m_timecode.getTimecodeFromFrames(pos)); + m_timePos.setValue(pos); slotPositionChanged(); } @@ -427,7 +378,7 @@ void Geometryval::setupParam(const QDomElement par, int minFrame, int maxFrame) spinTransp->setMaximum(500); label_pos->setHidden(true); m_helper->setHidden(true); - timePos->setHidden(true); + m_timePos.setHidden(true); } if (par.attribute("opacity") == "false") { label_opacity->setHidden(true); @@ -469,7 +420,8 @@ void Geometryval::setupParam(const QDomElement par, int minFrame, int maxFrame) slotPositionChanged(0, false); slotUpdateGeometry(); if (!m_fixedMode) { - connect(timePos, SIGNAL(editingFinished()), this , SLOT(slotPositionChanged())); + m_timePos.setMaximum(maxFrame - minFrame - 1); + connect(&m_timePos, SIGNAL(editingFinished()), this , SLOT(slotPositionChanged())); } connect(spinTransp, SIGNAL(valueChanged(int)), this , SLOT(slotTransparencyChanged(int))); } @@ -497,9 +449,7 @@ void Geometryval::updateTransitionPath() void Geometryval::slotUpdateTransitionProperties() { - int pos; - if (KdenliveSettings::frametimecode()) pos = timePos->text().toInt(); - else pos = m_timecode.getFrameCount(timePos->text()); + int pos = m_timePos.value(); Mlt::GeometryItem item; int error = m_geom->next_key(&item, pos); if (error || item.frame() != pos) { @@ -613,9 +563,7 @@ void Geometryval::slotUpdateGeometry() bool Geometryval::keyframeSelected() { Mlt::GeometryItem item; - int pos; - if (KdenliveSettings::frametimecode()) pos = timePos->text().toInt(); - else pos = m_timecode.getFrameCount(timePos->text()); + int pos = m_timePos.value(); if (m_geom->fetch(&item, pos) || item.key() == false) return false; return true; } diff --git a/src/geometryval.h b/src/geometryval.h index 4ba289e7..654bcd91 100644 --- a/src/geometryval.h +++ b/src/geometryval.h @@ -29,6 +29,7 @@ #include "ui_geometryval_ui.h" #include "definitions.h" #include "keyframehelper.h" +#include "timecodedisplay.h" #include "ui_geometryposition_ui.h" //class QGraphicsScene; @@ -69,6 +70,7 @@ private: double m_dar; int m_startPoint; QGraphicsView *m_sceneview; + TimecodeDisplay m_timePos; bool keyframeSelected(); public slots: @@ -99,8 +101,6 @@ private slots: void slotGeometryY(int value); void slotGeometryWidth(int value); void slotGeometryHeight(int value); - void slotPosUp(); - void slotPosDown(); signals: void parameterChanged(); diff --git a/src/monitor.cpp b/src/monitor.cpp index 5a88b826..924e25d9 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -112,19 +112,9 @@ Monitor::Monitor(QString name, MonitorManager *manager, QString profile, QWidget QWidget *spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); toolbar->addWidget(spacer); - m_timePos = new KRestrictedLine(this); + m_timePos = new TimecodeDisplay(m_monitorManager->timecode(), this); m_timePos->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); - m_frametimecode = KdenliveSettings::frametimecode(); - m_timePos->setInputMask(""); - if (m_frametimecode) { - QIntValidator *valid = new QIntValidator(this); - valid->setBottom(0); - m_timePos->setValidator(valid); - } else - m_timePos->setValidator(m_monitorManager->timecode().validator()); - toolbar->addWidget(m_timePos); - connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotSeek())); layout2->addWidget(toolbar); @@ -507,20 +497,13 @@ void Monitor::activateMonitor() void Monitor::setTimePos(const QString &pos) { - if (m_frametimecode) { - int frames = m_monitorManager->timecode().getFrameCount(pos); - m_timePos->setText(QString::number(frames)); - } else m_timePos->setText(pos); + m_timePos->setValue(pos); slotSeek(); } void Monitor::slotSeek() { - int frames; - if (m_frametimecode) frames = m_timePos->text().toInt(); - else frames = m_monitorManager->timecode().getFrameCount(m_timePos->text()); - //kDebug() << "// / / SEEK TO: " << frames; - slotSeek(frames); + slotSeek(m_timePos->value()); } void Monitor::slotSeek(int pos) @@ -624,8 +607,7 @@ void Monitor::seekCursor(int pos) activateMonitor(); if (m_ruler->slotNewValue(pos)) { checkOverlay(); - if (m_frametimecode) m_timePos->setText(QString::number(pos)); - else m_timePos->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); + m_timePos->setValue(pos); } } @@ -633,8 +615,7 @@ void Monitor::rendererStopped(int pos) { if (m_ruler->slotNewValue(pos)) { checkOverlay(); - if (m_frametimecode) m_timePos->setText(QString::number(pos)); - else m_timePos->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); + m_timePos->setValue(pos); } disconnect(m_playAction, SIGNAL(triggered()), this, SLOT(slotPlay())); m_playAction->setChecked(false); @@ -825,19 +806,7 @@ void Monitor::slotSwitchMonitorInfo(bool show) void Monitor::updateTimecodeFormat() { - m_frametimecode = KdenliveSettings::frametimecode(); - m_timePos->setInputMask(""); - if (m_frametimecode) { - int frames = m_monitorManager->timecode().getFrameCount(m_timePos->text()); - QIntValidator *valid = new QIntValidator(this); - valid->setBottom(0); - m_timePos->setValidator(valid); - m_timePos->setText(QString::number(frames)); - } else { - int pos = m_timePos->text().toInt(); - m_timePos->setValidator(m_monitorManager->timecode().validator()); - m_timePos->setText(m_monitorManager->timecode().getTimecodeFromFrames(pos)); - } + m_timePos->slotPrepareTimeCodeFormat(m_monitorManager->timecode()); } QStringList Monitor::getZoneInfo() const diff --git a/src/monitor.h b/src/monitor.h index 898754ee..2d113081 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -30,6 +30,7 @@ #include "gentime.h" #include "ui_monitor_ui.h" +#include "timecodedisplay.h" #ifdef Q_WS_MAC #include "videoglwidget.h" #endif @@ -117,7 +118,7 @@ private: MonitorRefresh *m_monitorRefresh; KIcon m_playIcon; KIcon m_pauseIcon; - KRestrictedLine *m_timePos; + TimecodeDisplay *m_timePos; QAction *m_playAction; QMenu *m_contextMenu; QMenu *m_configMenu; @@ -128,7 +129,6 @@ private: VideoGLWidget *m_glWidget; #endif GenTime getSnapForPos(bool previous); - bool m_frametimecode; private slots: void seekCursor(int pos); diff --git a/src/timecodedisplay.cpp b/src/timecodedisplay.cpp new file mode 100644 index 00000000..d0c6e22c --- /dev/null +++ b/src/timecodedisplay.cpp @@ -0,0 +1,162 @@ +/* This file is part of the KDE project + Copyright (c) 2010 Jean-Baptiste Mardelle + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "timecodedisplay.h" +#include "kdenlivesettings.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +TimecodeDisplay::TimecodeDisplay(Timecode t, QWidget *parent) + : QWidget(parent), + m_minimum(0), + m_maximum(-1) +{ + setupUi(this); + lineedit->setFont(KGlobalSettings::toolBarFont()); + QFontMetrics fm = lineedit->fontMetrics(); + lineedit->setMaximumWidth(fm.width("88:88:88:888")); + slotPrepareTimeCodeFormat(t); + connect(uparrow, SIGNAL(clicked()), this, SLOT(slotValueUp())); + connect(downarrow, SIGNAL(clicked()), this, SLOT(slotValueDown())); + connect(lineedit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished())); +} + +TimecodeDisplay::~TimecodeDisplay() +{ +} + +void TimecodeDisplay::slotValueUp() +{ + int val = value(); + val++; + if (m_maximum > -1 && val > m_maximum) val = m_maximum; + setValue(val); + lineedit->clearFocus(); + emit editingFinished(); +} + +void TimecodeDisplay::slotValueDown() +{ + int val = value(); + val--; + if (val < m_minimum) val = m_minimum; + setValue(val); + lineedit->clearFocus(); + emit editingFinished(); +} + +void TimecodeDisplay::slotPrepareTimeCodeFormat(Timecode t) +{ + m_timecode = t; + m_frametimecode = KdenliveSettings::frametimecode(); + QString val = lineedit->text(); + lineedit->setInputMask(""); + if (m_frametimecode) { + int frames = m_timecode.getFrameCount(lineedit->text()); + QIntValidator *valid = new QIntValidator(lineedit); + valid->setBottom(0); + lineedit->setValidator(valid); + lineedit->setText(QString::number(frames)); + } else { + int pos = lineedit->text().toInt(); + lineedit->setValidator(m_timecode.validator()); + lineedit->setText(m_timecode.getTimecodeFromFrames(pos)); + } +} + +void TimecodeDisplay::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Up) slotValueUp(); + else if (e->key() == Qt::Key_Down) slotValueDown(); + else QWidget::keyPressEvent(e); +} + +void TimecodeDisplay::wheelEvent(QWheelEvent *e) +{ + if (e->delta() > 0) slotValueUp(); + else slotValueDown(); +} + + +int TimecodeDisplay::maximum() const +{ + return m_maximum; +} + +int TimecodeDisplay::minimum() const +{ + return m_minimum; +} + +int TimecodeDisplay::value() const +{ + int frames; + if (m_frametimecode) frames = lineedit->text().toInt(); + else frames = m_timecode.getFrameCount(lineedit->text()); + return frames; +} + +void TimecodeDisplay::setMinimum(int min) +{ + m_minimum = min; +} + +void TimecodeDisplay::setMaximum(int max) +{ + m_maximum = max; +} + +void TimecodeDisplay::setValue(const QString &value) +{ + if (m_frametimecode) { + lineedit->setText(QString::number(m_timecode.getFrameCount(value))); + } else lineedit->setText(value); +} + +void TimecodeDisplay::setValue(int value) +{ + /* if (value < m_minimum) + value = m_minimum; + if (value > m_maximum) + value = m_maximum;*/ + if (m_frametimecode) lineedit->setText(QString::number(value)); + else lineedit->setText(m_timecode.getTimecodeFromFrames(value)); + + /* setEditText(KGlobal::locale()->formatNumber(value, d->decimals)); + d->slider->blockSignals(true); + d->slider->setValue(int((value - d->minimum) * 256 / (d->maximum - d->minimum) + 0.5)); + d->slider->blockSignals(false);*/ + //emit valueChanged(value, true); +} + +#include diff --git a/src/timecodedisplay.h b/src/timecodedisplay.h new file mode 100644 index 00000000..394e27c0 --- /dev/null +++ b/src/timecodedisplay.h @@ -0,0 +1,134 @@ +/* This file is part of the KDE project + Copyright (c) 2010 Jean-Baptiste Mardelle + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef TIMECODEDISPLAY_H_ +#define TIMECODEDISPLAY_H_ + +#include "ui_timecodedisplay_ui.h" +#include "timecode.h" + +#include + + +/** + * @short A widget for qreal values with a popup slider + * + * TimecodeDisplay combines a numerical input and a dropdown slider in a way that takes up as + * little screen space as possible. + * + * It allows the user to either enter a floating point value or quickly set the value using a slider + * + * One signal is emitted when the value changes. The signal is even emitted when the slider + * is moving. The second argument of the signal however tells you if the value is final or not. A + * final value is produced by entering a value numerically or by releasing the slider. + * + * The input of the numerical line edit is constrained to numbers and decimal signs. + */ +class TimecodeDisplay : public QWidget, public Ui::TimecodeDisplay_UI +{ + + Q_OBJECT + +public: + + /** + * Constructor for the widget, where value is set to 0 + * + * @param parent parent QWidget + */ + TimecodeDisplay(Timecode t, QWidget *parent = 0); + + /** + * Destructor + */ + virtual ~TimecodeDisplay(); + + /** + * The minimum value that can be entered. + * default is 0 + */ + int minimum() const; + + /** + * The maximum value that can be entered. + * default is 100 + */ + int maximum() const; + + /** + * Sets the minimum value that can be entered. + * @param min the minimum value + */ + void setMinimum(int min); + + /** + * Sets the maximum value that can be entered. + * @param max the maximum value + */ + void setMaximum(int max); + + /** + * The value shown. + */ + int value() const; + + //virtual QSize minimumSizeHint() const; ///< reimplemented from QComboBox + //virtual QSize sizeHint() const; ///< reimplemented from QComboBox + +private: + /** timecode for widget */ + Timecode m_timecode; + /** Should we display the timecode in frames or in format hh:mm:ss:ff */ + bool m_frametimecode; + int m_minimum; + int m_maximum; + +public slots: + + /** + * Sets the value. + * The value actually set is forced to be within the legal range: minimum <= value <= maximum + * @param value the new value + */ + void setValue(int value); + void setValue(const QString &value); + void slotPrepareTimeCodeFormat(Timecode t); + +private slots: + void slotValueUp(); + void slotValueDown(); + +signals: + + /** + * Emitted every time the value changes (by calling setValue() or + * by user interaction). + * @param value the new value + * @param final if the value is final ie not produced during sliding (on slider release it's final) + */ + void valueChanged(int value, bool final); + void editingFinished(); + +protected: + virtual void keyPressEvent(QKeyEvent *e); + virtual void wheelEvent(QWheelEvent *e); + +}; + +#endif diff --git a/src/widgets/geometryval_ui.ui b/src/widgets/geometryval_ui.ui index 70f39545..8e74d5d2 100644 --- a/src/widgets/geometryval_ui.ui +++ b/src/widgets/geometryval_ui.ui @@ -53,7 +53,7 @@ - + -1 @@ -128,78 +128,6 @@ - - - - 0 - - - - - - 0 - 0 - - - - - - - - - - ... - - - - 3 - 2 - - - - true - - - Qt::UpArrow - - - - - - - ... - - - - 3 - 2 - - - - true - - - Qt::DownArrow - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -383,16 +311,6 @@ QSpinBox
knuminput.h
- - KLineEdit - QLineEdit -
klineedit.h
-
- - KRestrictedLine - KLineEdit -
krestrictedline.h
-
diff --git a/src/widgets/timecodedisplay_ui.ui b/src/widgets/timecodedisplay_ui.ui new file mode 100644 index 00000000..1a333add --- /dev/null +++ b/src/widgets/timecodedisplay_ui.ui @@ -0,0 +1,125 @@ + + + TimecodeDisplay_UI + + + + 0 + 0 + 132 + 31 + + + + Form + + + + + + QToolButton {border: 0px;} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + false + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 1 + + + + + ... + + + + 4 + 4 + + + + true + + + Qt::UpArrow + + + + + + + ... + + + + 4 + 4 + + + + true + + + Qt::DownArrow + + + + + + + + + Qt::Vertical + + + + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
+ + KRestrictedLine + KLineEdit +
krestrictedline.h
+
+
+ + +