Commit 60304ef7 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Remove code duplication (merge multiMarkerDialog with standard MarkerDialod)

parent 52ac5f04
Pipeline #259768 passed with stage
in 6 minutes and 34 seconds
......@@ -9,7 +9,6 @@
#include "core.h"
#include "dialogs/exportguidesdialog.h"
#include "dialogs/markerdialog.h"
#include "dialogs/multiplemarkerdialog.h"
#include "doc/docundostack.hpp"
#include "kdenlivesettings.h"
#include "macros.hpp"
......@@ -802,7 +801,7 @@ bool MarkerListModel::editMarkerGui(const GenTime &pos, QWidget *parent, bool cr
marker = CommentedTime(pos, clip == nullptr ? i18n("guide") : QString(), KdenliveSettings::default_marker_type());
}
QScopedPointer<MarkerDialog> dialog(new MarkerDialog(clip, marker, m_guide ? i18n("Edit Guide") : i18n("Edit Marker"), parent));
QScopedPointer<MarkerDialog> dialog(new MarkerDialog(clip, marker, m_guide ? i18n("Edit Guide") : i18n("Edit Marker"), false, parent));
if (dialog->exec() == QDialog::Accepted) {
marker = dialog->newMarker();
......@@ -826,12 +825,12 @@ bool MarkerListModel::addMultipleMarkersGui(const GenTime &pos, QWidget *parent,
marker = CommentedTime(pos, clip == nullptr ? i18n("guide") : QString(), KdenliveSettings::default_marker_type());
}
QScopedPointer<MultipleMarkerDialog> dialog(new MultipleMarkerDialog(clip, marker, m_guide ? i18n("Add Guides") : i18n("Add Markers"), parent));
QScopedPointer<MarkerDialog> dialog(new MarkerDialog(clip, marker, m_guide ? i18n("Add Guides") : i18n("Add Markers"), true, parent));
if (dialog->exec() == QDialog::Accepted) {
int max = dialog->getOccurrences();
int max = dialog->addMultiMarker() ? dialog->getOccurrences() : 1;
GenTime interval = dialog->getInterval();
KdenliveSettings::setMultipleguidesinterval(interval.seconds());
marker = dialog->startMarker();
marker = dialog->newMarker();
GenTime startTime = marker.time();
QWriteLocker locker(&m_lock);
Fun undo = []() { return true; };
......
......@@ -4,7 +4,6 @@ set(kdenlive_SRCS
dialogs/encodingprofilesdialog.cpp
dialogs/kdenlivesettingsdialog.cpp
dialogs/markerdialog.cpp
dialogs/multiplemarkerdialog.cpp
dialogs/exportguidesdialog.cpp
dialogs/profilesdialog.cpp
dialogs/proxytest.cpp
......
......@@ -20,7 +20,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "klocalizedstring.h"
MarkerDialog::MarkerDialog(ClipController *clip, const CommentedTime &t, const QString &caption, QWidget *parent)
MarkerDialog::MarkerDialog(ClipController *clip, const CommentedTime &t, const QString &caption, bool allowMultipleMarksers, QWidget *parent)
: QDialog(parent)
, m_clip(clip)
{
......@@ -32,7 +32,10 @@ MarkerDialog::MarkerDialog(ClipController *clip, const CommentedTime &t, const Q
marker_category->setCurrentCategory(t.markerType());
m_in->setValue(t.time());
if (!allowMultipleMarksers) {
multimarker_box->setVisible(false);
}
interval->setValue(GenTime(KdenliveSettings::multipleguidesinterval()));
m_previewTimer = new QTimer(this);
if (m_clip != nullptr) {
......@@ -106,3 +109,18 @@ CommentedTime MarkerDialog::newMarker()
KdenliveSettings::setDefault_marker_type(marker_category->currentCategory());
return CommentedTime(m_in->gentime(), marker_comment->text(), marker_category->currentCategory());
}
GenTime MarkerDialog::getInterval() const
{
return interval->gentime();
}
int MarkerDialog::getOccurrences() const
{
return occurrences->value();
}
bool MarkerDialog::addMultiMarker() const
{
return multimarker_box->isExpanded();
}
......@@ -27,11 +27,14 @@ class MarkerDialog : public QDialog, public Ui::MarkerDialog_UI
Q_OBJECT
public:
explicit MarkerDialog(ClipController *clip, const CommentedTime &t, const QString &caption, QWidget *parent = nullptr);
explicit MarkerDialog(ClipController *clip, const CommentedTime &t, const QString &caption, bool allowMultipleMarksers = false, QWidget *parent = nullptr);
~MarkerDialog() override;
CommentedTime newMarker();
QImage markerImage() const;
bool addMultiMarker() const;
GenTime getInterval() const;
int getOccurrences() const;
private slots:
void slotUpdateThumb();
......
/*
SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "multiplemarkerdialog.h"
#include "bin/model/markerlistmodel.hpp"
#include "core.h"
#include "doc/kthumb.h"
#include "kdenlivesettings.h"
#include "mltcontroller/clipcontroller.h"
#include "project/projectmanager.h"
#include "kdenlive_debug.h"
#include <QFontDatabase>
#include <QTimer>
#include <QWheelEvent>
#include "klocalizedstring.h"
MultipleMarkerDialog::MultipleMarkerDialog(ClipController *clip, const CommentedTime &t, const QString &caption, QWidget *parent)
: QDialog(parent)
, m_clip(clip)
{
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
setupUi(this);
setWindowTitle(caption);
// Set up categories
marker_category->setCurrentCategory(t.markerType());
m_in->setValue(t.time());
if (m_clip != nullptr) {
m_in->setRange(0, m_clip->getFramePlaytime());
}
interval->setValue(GenTime(KdenliveSettings::multipleguidesinterval()));
marker_comment->setText(t.comment());
marker_comment->selectAll();
marker_comment->setFocus();
adjustSize();
}
MultipleMarkerDialog::~MultipleMarkerDialog() {}
CommentedTime MultipleMarkerDialog::startMarker()
{
KdenliveSettings::setDefault_marker_type(marker_category->currentCategory());
return CommentedTime(m_in->gentime(), marker_comment->text(), marker_category->currentCategory());
}
GenTime MultipleMarkerDialog::getInterval() const
{
return interval->gentime();
}
int MultipleMarkerDialog::getOccurrences() const
{
return occurrences->value();
}
/*
SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include "ui_multiplemarkerdialog_ui.h"
#include "definitions.h"
#include "utils/timecode.h"
#include "widgets/timecodedisplay.h"
class ClipController;
namespace Mlt {
}
/**
* @class MultipleMarkerDialog
* @brief A dialog for editing markers and guides.
* @author Jean-Baptiste Mardelle
*/
class MultipleMarkerDialog : public QDialog, public Ui::MultipleMarkerDialog_UI
{
Q_OBJECT
public:
explicit MultipleMarkerDialog(ClipController *clip, const CommentedTime &t, const QString &caption, QWidget *parent = nullptr);
~MultipleMarkerDialog() override;
CommentedTime startMarker();
GenTime getInterval() const;
int getOccurrences() const;
private:
ClipController *m_clip;
};
......@@ -53,11 +53,6 @@ GuidesList::GuidesList(QWidget *parent)
connect(guide_save, &QToolButton::clicked, this, &GuidesList::saveGuides);
connect(configure, &QToolButton::clicked, this, &GuidesList::configureGuides);
connect(filter_line, &QLineEdit::textChanged, this, &GuidesList::filterView);
QMenu *menu = new QMenu(this);
QAction *ac = new QAction(i18n("add multiple guides"), this);
connect(ac, &QAction::triggered, this, &GuidesList::addMutipleGuides);
menu->addAction(ac);
guide_add->setMenu(menu);
// Sort menu
m_filterGroup = new QActionGroup(this);
......@@ -147,18 +142,7 @@ void GuidesList::addGuide()
if (frame >= 0) {
GenTime pos(frame, pCore->getCurrentFps());
if (auto markerModel = m_model.lock()) {
markerModel->addMarker(pos, i18n("guide"));
}
}
}
void GuidesList::addMutipleGuides()
{
int frame = pCore->getTimelinePosition();
if (frame >= 0) {
GenTime pos(frame, pCore->getCurrentFps());
if (auto markerModel = m_model.lock()) {
markerModel->addMultipleMarkersGui(pos, qApp->activeWindow(), true);
markerModel->addMultipleMarkersGui(pos, this, true);
}
}
}
......
......@@ -34,7 +34,6 @@ private slots:
void selectionChanged(const QItemSelection &selected, const QItemSelection &);
void removeGuide();
void addGuide();
void addMutipleGuides();
void configureGuides();
void rebuildCategories();
void updateFilter(QAbstractButton *, bool);
......
......@@ -85,7 +85,8 @@
<string>...</string>
</property>
<property name="icon">
<iconset theme="view-sort"/>
<iconset theme="view-sort">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
......@@ -119,14 +120,11 @@
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
<enum>QToolButton::DelayedPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item row="2" column="0" colspan="7">
......
......@@ -10,33 +10,20 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
<rect>
<x>0</x>
<y>0</y>
<width>332</width>
<height>164</height>
<width>389</width>
<height>210</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Marker</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="clip_thumb">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Image preview</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
......@@ -105,20 +92,92 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
</item>
</layout>
</item>
<item row="1" column="1">
<item row="1" column="0" colspan="2">
<widget class="KCollapsibleGroupBox" name="multimarker_box">
<property name="title">
<string>Add multiple markers</string>
</property>
<property name="expanded">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="clip_filesize_5">
<property name="text">
<string>Count</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="occurrences">
<property name="minimum">
<number>2</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="clip_filesize_4">
<property name="text">
<string>Interval</string>
</property>
</widget>
</item>
<item>
<widget class="TimecodeDisplay" name="interval"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="clip_thumb">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Image preview</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>218</width>
<height>1</height>
<width>20</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -141,6 +200,12 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
<extends>QComboBox</extends>
<header>widgets/markercategorychooser.h</header>
</customwidget>
<customwidget>
<class>KCollapsibleGroupBox</class>
<extends>QWidget</extends>
<header>kcollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
......
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