Commit 0bbc19c5 authored by Julius Künzel's avatar Julius Künzel 💬
Browse files

[Timecode Display] Reduce code duplication

parent 245a91f3
......@@ -112,7 +112,7 @@ KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QMode
connect(monitor, &Monitor::seekPosition, this, &KeyframeWidget::monitorSeek, Qt::UniqueConnection);
connect(pCore.get(), &Core::disconnectEffectStack, this, &KeyframeWidget::disconnectEffectStack);
m_time = new TimecodeDisplay(true, this);
m_time = new TimecodeDisplay(this);
m_time->setRange(0, duration - 1);
m_toolbar->addAction(previousKFAction);
......
......@@ -24,7 +24,7 @@ PositionEditWidget::PositionEditWidget(std::shared_ptr<AssetParameterModel> mode
m_slider = new QSlider(Qt::Horizontal, this);
m_slider->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
m_display = new TimecodeDisplay(true, this);
m_display = new TimecodeDisplay(this);
m_display->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
layout->addWidget(label);
......
......@@ -54,7 +54,7 @@ Generators::Generators(const QString &path, QWidget *parent)
m_preview->setPixmap(m_pixmap.scaledToWidth(m_preview->width()));
auto *hlay = new QHBoxLayout;
hlay->addWidget(new QLabel(i18n("Duration:")));
m_timePos = new TimecodeDisplay(true, this);
m_timePos = new TimecodeDisplay(this);
if (base.hasAttribute(QStringLiteral("updateonduration"))) {
connect(m_timePos, &TimecodeDisplay::timeCodeEditingFinished, this, &Generators::updateDuration);
}
......
......@@ -140,7 +140,7 @@ void ClipCreationDialog::createColorClip(KdenliveDoc *doc, const QString &parent
dia->setWindowTitle(i18nc("@title:window", "Color Clip"));
dia_ui.clip_name->setText(i18n("Color Clip"));
QScopedPointer<TimecodeDisplay> t(new TimecodeDisplay(true, dia.get()));
QScopedPointer<TimecodeDisplay> t(new TimecodeDisplay(dia.get()));
t->setValue(KdenliveSettings::color_duration());
dia_ui.clip_durationBox->addWidget(t.data());
dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
......@@ -190,7 +190,7 @@ void ClipCreationDialog::createAnimationClip(KdenliveDoc *doc, const QString &pa
l->addWidget(&fileUrl);
QHBoxLayout *lay = new QHBoxLayout;
lay->addWidget(new QLabel(i18n("Animation duration"), &d));
TimecodeDisplay tCode(pCore->timecode(), &d);
TimecodeDisplay tCode(&d);
tCode.setValue(QStringLiteral("00:00:05:00"));
lay->addWidget(&tCode);
l->addLayout(lay);
......@@ -255,7 +255,7 @@ void ClipCreationDialog::createQTextClip(KdenliveDoc *doc, const QString &parent
QScopedPointer<QDialog> dia(new QDialog(bin));
Ui::QTextClip_UI dia_ui;
dia_ui.setupUi(dia.data());
TimecodeDisplay *duration = new TimecodeDisplay(true, dia.data());
TimecodeDisplay *duration = new TimecodeDisplay(dia.data());
dia_ui.formLayout->addRow(i18n("Duration:"), duration);
dia->setWindowTitle(i18nc("@title:window", "Text Clip"));
dia_ui.fgColor->setAlphaChannelEnabled(true);
......
......@@ -38,7 +38,7 @@ MarkerDialog::MarkerDialog(ClipController *clip, const CommentedTime &t, const T
}
marker_type->setCurrentIndex(t.markerType());
m_in = new TimecodeDisplay(true, this);
m_in = new TimecodeDisplay(this);
inputLayout->addWidget(m_in);
m_in->setValue(t.time());
......
......@@ -69,9 +69,9 @@ SubtitleEdit::SubtitleEdit(QWidget *parent)
connect(buttonStyle, &QToolButton::toggled, this, [this](bool toggle) { stackedWidget->setCurrentIndex(toggle ? 1 : 0); });
m_position = new TimecodeDisplay(true, this);
m_endPosition = new TimecodeDisplay(true, this);
m_duration = new TimecodeDisplay(true, this);
m_position = new TimecodeDisplay(this);
m_endPosition = new TimecodeDisplay(this);
m_duration = new TimecodeDisplay(this);
frame_position->setEnabled(false);
buttonDelete->setEnabled(false);
......
......@@ -1661,9 +1661,9 @@ TimeRemap::TimeRemap(QWidget *parent)
QMetaObject::invokeMethod(pCore->bin(), "requestTranscoding", Qt::QueuedConnection, Q_ARG(QString, QString()), Q_ARG(QString, m_binId), Q_ARG(int, 0),
Q_ARG(bool, false));
});
m_in = new TimecodeDisplay(true, this);
m_in = new TimecodeDisplay(this);
inLayout->addWidget(m_in);
m_out = new TimecodeDisplay(true, this);
m_out = new TimecodeDisplay(this);
outLayout->addWidget(m_out);
m_view = new RemapView(this);
speedBefore->setKeyboardTracking(false);
......
......@@ -129,7 +129,7 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
setIn->setAutoRaise(true);
setIn->setToolTip(i18n("Set zone in"));
layZone->addWidget(setIn);
m_inPos = new TimecodeDisplay(true, this);
m_inPos = new TimecodeDisplay(this);
layZone->addWidget(m_inPos);
layZone->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::MinimumExpanding, QSizePolicy::Maximum));
QLabel *out = new QLabel(i18n("Out:"), this);
......@@ -140,7 +140,7 @@ CollapsibleEffectView::CollapsibleEffectView(const std::shared_ptr<EffectItemMod
setOut->setAutoRaise(true);
setOut->setToolTip(i18n("Set zone out"));
layZone->addWidget(setOut);
m_outPos = new TimecodeDisplay(true, this);
m_outPos = new TimecodeDisplay(this);
layZone->addWidget(m_outPos);
connect(setIn, &QToolButton::clicked, this, [=]() {
......
......@@ -326,7 +326,7 @@ ClipPropertiesController::ClipPropertiesController(ClipController *controller, Q
QCheckBox *box = new QCheckBox(i18n("Duration:"), this);
box->setObjectName(QStringLiteral("force_duration"));
hlay->addWidget(box);
auto *timePos = new TimecodeDisplay(true, this);
auto *timePos = new TimecodeDisplay(this);
timePos->setObjectName(QStringLiteral("force_duration_value"));
timePos->setValue(kdenlive_length > 0 ? kdenlive_length : m_properties->get_int("length"));
int original_length = m_properties->get_int("kdenlive:original_length");
......
......@@ -393,7 +393,7 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
connect(this, &Monitor::scopesClear, m_glMonitor, &GLWidget::releaseAnalyse, Qt::DirectConnection);
connect(m_glMonitor, &GLWidget::analyseFrame, this, &Monitor::frameUpdated);
m_timePos = new TimecodeDisplay(true, this);
m_timePos = new TimecodeDisplay(this);
if (id == Kdenlive::ProjectMonitor) {
connect(m_glMonitor->getControllerProxy(), &MonitorProxy::saveZone, this, &Monitor::zoneUpdated);
......
......@@ -37,7 +37,7 @@ SimpleKeyframeWidget::SimpleKeyframeWidget(int duration, QWidget *parent)
m_buttonNext->setIcon(QIcon::fromTheme(QStringLiteral("media-skip-forward")));
m_buttonNext->setToolTip(i18n("Go to next keyframe"));
m_time = new TimecodeDisplay(true, this);
m_time = new TimecodeDisplay(this);
m_time->setRange(0, duration);
l->addWidget(m_timeline, 0, 0, 1, -1);
......
......@@ -22,10 +22,10 @@ ClipDurationDialog::ClipDurationDialog(int clipId, int pos, int minpos, int in,
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
setupUi(this);
m_pos = new TimecodeDisplay(true, this);
m_cropStart = new TimecodeDisplay(true, this);
m_dur = new TimecodeDisplay(true, this);
m_cropEnd = new TimecodeDisplay(true, this);
m_pos = new TimecodeDisplay(this);
m_cropStart = new TimecodeDisplay(this);
m_dur = new TimecodeDisplay(this);
m_cropEnd = new TimecodeDisplay(this);
clip_position_box->addWidget(m_pos);
crop_start_box->addWidget(m_cropStart);
......
......@@ -17,7 +17,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
// deprecated
SpacerDialog::SpacerDialog(const GenTime &duration, const Timecode &tc, int track, const QList<TrackInfo> &tracks, QWidget *parent)
: QDialog(parent)
, m_in(tc)
, m_in(nullptr, tc)
{
Q_UNUSED(track)
Q_UNUSED(tracks)
......@@ -40,7 +40,7 @@ SpacerDialog::SpacerDialog(const GenTime &duration, const Timecode &tc, int trac
SpacerDialog::SpacerDialog(const GenTime &duration, const Timecode &tc, QWidget *parent)
: QDialog(parent)
, m_in(tc)
, m_in(nullptr, tc)
{
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
setupUi(this);
......
......@@ -50,7 +50,7 @@ SpeedDialog::SpeedDialog(QWidget *parent, double speed, int duration, double min
ui->speedSpin->selectAll();
if (m_duration > 0) {
ui->durationLayout->addWidget(new QLabel(i18n("Duration"), this));
m_durationDisplay = new TimecodeDisplay(true, this);
m_durationDisplay = new TimecodeDisplay(this);
m_durationDisplay->setValue(m_duration);
ui->durationLayout->addWidget(m_durationDisplay);
connect(m_durationDisplay, &TimecodeDisplay::timeCodeEditingFinished, this, [this, infoMessage, speed, minSpeed](int value) {
......
......@@ -165,7 +165,7 @@ TitleWidget::TitleWidget(const QUrl &url, QString projectTitlePath, Monitor *mon
splitter->setStretchFactor(0, 20);
m_duration = new TimecodeDisplay(true, this);
m_duration = new TimecodeDisplay(this);
m_duration->setValue(KdenliveSettings::title_duration());
duration_box->addWidget(m_duration);
auto *spacer = new QSpacerItem(1, 1, QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
......
......@@ -26,7 +26,7 @@ MixStackView::MixStackView(QWidget *parent)
m_position = new PositionWidget(i18n("Position"), 0, 0, 0);
// Duration widget
m_durationLayout = new QHBoxLayout;
m_duration = new TimecodeDisplay(true, this);
m_duration = new TimecodeDisplay(this);
m_duration->setRange(1, -1);
m_durationLayout->addWidget(new QLabel(i18n("Duration:")));
m_durationLayout->addWidget(m_duration);
......
......@@ -22,7 +22,7 @@ PositionWidget::PositionWidget(const QString &name, int pos, int min, int max, c
m_slider->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
m_slider->setRange(min, max);
m_display = new TimecodeDisplay(true, this);
m_display = new TimecodeDisplay(this);
m_display->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred));
m_display->setRange(min, max);
......
......@@ -33,38 +33,15 @@ QValidator::State TimecodeValidator::validate(QString &str, int &) const
return QValidator::Acceptable;
}
TimecodeDisplay::TimecodeDisplay(bool autoAdjust, QWidget *parent)
: QAbstractSpinBox(parent)
, m_timecode(autoAdjust ? pCore->timecode() : Timecode())
, m_frametimecode(false)
, m_minimum(0)
, m_maximum(-1)
, m_value(0)
, m_offset(0)
TimecodeDisplay::TimecodeDisplay(QWidget *parent, bool autoAdjust)
: TimecodeDisplay(parent, autoAdjust ? pCore->timecode() : Timecode())
{
const QFont ft = QFontDatabase::systemFont(QFontDatabase::FixedFont);
lineEdit()->setFont(ft);
setFont(ft);
lineEdit()->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
QFontMetrics fm(ft);
setFrame(false);
QPalette palette;
palette.setColor(QPalette::Base, Qt::transparent); // palette.window().color());
setPalette(palette);
setTimeCodeFormat(KdenliveSettings::frametimecode(), true);
setValue(m_minimum);
setMinimumWidth(fm.horizontalAdvance(QStringLiteral("88:88:88:88")) + contentsMargins().right() + contentsMargins().left() + frameSize().width() -
lineEdit()->contentsRect().width() + (int)QStyle::PM_SpinBoxFrameWidth + 6);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum);
setAccelerated(true);
connect(lineEdit(), &QLineEdit::editingFinished, this, &TimecodeDisplay::slotEditingFinished, Qt::DirectConnection);
if (autoAdjust) {
connect(pCore.get(), &Core::updateProjectTimecode, this, &TimecodeDisplay::refreshTimeCode);
}
}
TimecodeDisplay::TimecodeDisplay(const Timecode &t, QWidget *parent)
TimecodeDisplay::TimecodeDisplay(QWidget *parent, const Timecode &t)
: QAbstractSpinBox(parent)
, m_timecode(t)
, m_frametimecode(false)
......@@ -92,11 +69,6 @@ TimecodeDisplay::TimecodeDisplay(const Timecode &t, QWidget *parent)
connect(lineEdit(), &QLineEdit::editingFinished, this, &TimecodeDisplay::slotEditingFinished, Qt::DirectConnection);
}
TimecodeDisplay::TimecodeDisplay(QWidget *parent)
: TimecodeDisplay(Timecode(), parent)
{
}
// virtual protected
QAbstractSpinBox::StepEnabled TimecodeDisplay::stepEnabled() const
{
......
......@@ -36,20 +36,14 @@ class TimecodeDisplay : public QAbstractSpinBox
public:
/** @brief Constructor for the widget.
* @param autoAdjust if true, the timecode will be set and adjusted according to pCore's timecode
* @param parent parent Widget */
explicit TimecodeDisplay(bool autoAdjust = true, QWidget *parent = nullptr);
* @param parent parent Widget
* @param autoAdjust if true, the timecode will be set and adjusted according to pCore's timecode */
explicit TimecodeDisplay(QWidget *parent = nullptr, bool autoAdjust = true);
/** @brief Constructor for the widget. Beware, this constructor does not automatically adjust its fps!
* @param t Timecode object used to setup correct input (frames or HH:MM:SS:FF)
* @param parent parent Widget */
explicit TimecodeDisplay(const Timecode &t, QWidget *parent = nullptr);
/** @brief Constructor for the widget, sets value to 0.
* This variant of ctor is mainly for the usage in QtDesigner,
* remember to set a correct timecode with setTimecode()
* @param parent parent Widget */
explicit TimecodeDisplay(QWidget *parent = nullptr);
* @param parent parent Widget
* @param t Timecode object used to setup correct input (frames or HH:MM:SS:FF) */
explicit TimecodeDisplay(QWidget *parent, const Timecode &t);
/** @brief Returns the minimum value, which can be entered.
* default is 0 */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment