From fc28900c9cb175bf56e8c759caeb0fbad933ef26 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 14 Oct 2018 02:20:25 +1100 Subject: [PATCH] made interlacing configurable --- dialogs/mediapropertiesdialog.cpp | 46 +++++++++++++++++++++++++------ dialogs/mediapropertiesdialog.h | 10 ++++++- io/previewgenerator.cpp | 7 +---- panels/project.cpp | 2 +- project/undo.cpp | 28 +++++++++++++++++++ project/undo.h | 22 +++++++++++++++ 6 files changed, 98 insertions(+), 17 deletions(-) diff --git a/dialogs/mediapropertiesdialog.cpp b/dialogs/mediapropertiesdialog.cpp index 094ea9019..46e1c19b0 100644 --- a/dialogs/mediapropertiesdialog.cpp +++ b/dialogs/mediapropertiesdialog.cpp @@ -5,31 +5,59 @@ #include #include #include +#include #include "io/media.h" #include "panels/project.h" +#include "project/undo.h" -MediaPropertiesDialog::MediaPropertiesDialog(QWidget *parent) { +MediaPropertiesDialog::MediaPropertiesDialog(QWidget *parent, QTreeWidgetItem *i, Media *m) : + QDialog(parent), + item(i), + media(m) +{ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QGridLayout* grid = new QGridLayout(); setLayout(grid); - interlacing_box = new QComboBox(); - interlacing_box->addItem(get_interlacing_name(VIDEO_PROGRESSIVE), VIDEO_PROGRESSIVE); - interlacing_box->addItem(get_interlacing_name(VIDEO_TOP_FIELD_FIRST), VIDEO_TOP_FIELD_FIRST); - interlacing_box->addItem(get_interlacing_name(VIDEO_BOTTOM_FIELD_FIRST), VIDEO_BOTTOM_FIELD_FIRST); + if (m->video_tracks.size() > 0) { + interlacing_box = new QComboBox(); + interlacing_box->addItem(get_interlacing_name(VIDEO_PROGRESSIVE)); + interlacing_box->addItem(get_interlacing_name(VIDEO_TOP_FIELD_FIRST)); + interlacing_box->addItem(get_interlacing_name(VIDEO_BOTTOM_FIELD_FIRST)); + interlacing_box->setCurrentIndex(media->video_tracks.at(0)->video_interlacing); - grid->addWidget(new QLabel("Interlacing:"), 0, 0); - grid->addWidget(interlacing_box, 0, 1); + grid->addWidget(new QLabel("Interlacing:"), 0, 0); + grid->addWidget(interlacing_box, 0, 1); + } + name_box = new QLineEdit(m->name); grid->addWidget(new QLabel("Name:"), 1, 0); - grid->addWidget(new QLineEdit("h"), 1, 1); + grid->addWidget(name_box, 1, 1); QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); buttons->setCenterButtons(true); grid->addWidget(buttons, 2, 0, 1, 2); connect(buttons, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); + connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); +} + +void MediaPropertiesDialog::accept() { + ComboAction* ca = new ComboAction(); + ca->append(new SetInt(&media->video_tracks.at(0)->video_interlacing, interlacing_box->currentIndex())); + ca->append(new SetString(&media->name, name_box->text())); + + item->setText(0, name_box->text()); + + MediaRename* mr = new MediaRename(); + mr->from = media->name; + mr->item = item; + mr->to = name_box->text(); + ca->append(mr); + + undo_stack.push(ca); + + QDialog::accept(); } diff --git a/dialogs/mediapropertiesdialog.h b/dialogs/mediapropertiesdialog.h index edc29653c..de5c5f92b 100644 --- a/dialogs/mediapropertiesdialog.h +++ b/dialogs/mediapropertiesdialog.h @@ -3,14 +3,22 @@ #include +struct Media; class QComboBox; +class QLineEdit; +class QTreeWidgetItem; class MediaPropertiesDialog : public QDialog { Q_OBJECT public: - explicit MediaPropertiesDialog(QWidget *parent = 0); + MediaPropertiesDialog(QWidget *parent, QTreeWidgetItem* i, Media *m); private: QComboBox* interlacing_box; + QLineEdit* name_box; + QTreeWidgetItem* item; + Media* media; +private slots: + void accept(); }; #endif // MEDIAPROPERTIESDIALOG_H diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index 1c010d5ad..90c2b9bdb 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -173,12 +173,7 @@ void PreviewGenerator::generate_waveform() { s->video_preview = QImage(data, dstW, dstH, linesize[0], QImage::Format_RGB888); // is video interlaced? - if (temp_frame->interlaced_frame) { - s->video_interlacing = (temp_frame->top_field_first) ? VIDEO_TOP_FIELD_FIRST : VIDEO_BOTTOM_FIELD_FIRST; - s->video_frame_rate *= 2; - } else { - s->video_interlacing = VIDEO_PROGRESSIVE; - } + s->video_interlacing = (temp_frame->interlaced_frame) ? ((temp_frame->top_field_first) ? VIDEO_TOP_FIELD_FIRST : VIDEO_BOTTOM_FIELD_FIRST) : VIDEO_PROGRESSIVE; s->preview_done = true; diff --git a/panels/project.cpp b/panels/project.cpp index 6a20612a3..9bf91d2be 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -149,7 +149,7 @@ void Project::open_properties() { switch (get_type_from_tree(item)) { case MEDIA_TYPE_FOOTAGE: { - MediaPropertiesDialog mpd(this); + MediaPropertiesDialog mpd(this, item, get_footage_from_tree(item)); mpd.exec(); } break; diff --git a/project/undo.cpp b/project/undo.cpp index 0bdbc2d83..c31f6c6a6 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -1591,3 +1591,31 @@ void EditSequenceCommand::update() { set_sequence(seq); } } + +SetInt::SetInt(int* pointer, int new_value) : + p(pointer), + oldval(*pointer), + newval(new_value) +{} + +void SetInt::undo() { + *p = oldval; +} + +void SetInt::redo() { + *p = newval; +} + +SetString::SetString(QString* pointer, QString new_value) : + p(pointer), + oldval(*pointer), + newval(new_value) +{} + +void SetString::undo() { + *p = oldval; +} + +void SetString::redo() { + *p = newval; +} diff --git a/project/undo.h b/project/undo.h index 30dffb627..b535c764a 100644 --- a/project/undo.h +++ b/project/undo.h @@ -493,4 +493,26 @@ private: int old_audio_layout; }; +class SetInt : public QUndoCommand { +public: + SetInt(int* pointer, int new_value); + void undo(); + void redo(); +private: + int* p; + int oldval; + int newval; +}; + +class SetString : public QUndoCommand { +public: + SetString(QString* pointer, QString new_value); + void undo(); + void redo(); +private: + QString* p; + QString oldval; + QString newval; +}; + #endif // UNDO_H