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);
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());
#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();
}
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);
}
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
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
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);
}
}
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>
#ifndef TIMECODEDISPLAY_H_
#define TIMECODEDISPLAY_H_
-#include "ui_timecodedisplay_ui.h"
#include "timecode.h"
#include "gentime.h"
+#include <QAbstractSpinBox>
/**
* @class TimecodeDisplay
* 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
* @param t the new timecode */
void updateTimeCode(Timecode t);
+ virtual void stepBy(int steps);
+
private:
/** timecode for widget */
Timecode m_timecode;
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.
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;
};
+++ /dev/null
-<?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>