diff --git a/app/common/timecodefunctions.cpp b/app/common/timecodefunctions.cpp index c2725290b..86c9eaf36 100644 --- a/app/common/timecodefunctions.cpp +++ b/app/common/timecodefunctions.cpp @@ -258,13 +258,3 @@ int64_t Timecode::time_to_timestamp(const double &time, const rational &timebase { return qRound64(time * timebase.flipped().toDouble()); } - -Timecode::Display Timecode::CurrentDisplay() -{ - return static_cast(Config::Current()["TimecodeDisplay"].toInt()); -} - -void Timecode::SetCurrentDisplay(Timecode::Display d) -{ - Config::Current()["TimecodeDisplay"] = d; -} diff --git a/app/common/timecodefunctions.h b/app/common/timecodefunctions.h index e9bb4d35d..0d1748394 100644 --- a/app/common/timecodefunctions.h +++ b/app/common/timecodefunctions.h @@ -45,9 +45,6 @@ public: kMilliseconds }; - static Display CurrentDisplay(); - static void SetCurrentDisplay(Display d); - /** * @brief Convert a timestamp (according to a rational timebase) to a user-friendly string representation */ diff --git a/app/core.cpp b/app/core.cpp index e87e1d755..7854a5271 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -482,6 +482,18 @@ Folder *Core::GetSelectedFolderInActiveProject() } } +Timecode::Display Core::GetTimecodeDisplay() const +{ + return static_cast(Config::Current()["TimecodeDisplay"].toInt()); +} + +void Core::SetTimecodeDisplay(Timecode::Display d) +{ + Config::Current()["TimecodeDisplay"] = d; + + emit TimecodeDisplayChanged(d); +} + void Core::SetProjectModified(bool e) { main_window()->setWindowModified(e); diff --git a/app/core.h b/app/core.h index 9fdb85501..5cb9bc6cf 100644 --- a/app/core.h +++ b/app/core.h @@ -26,6 +26,7 @@ #include #include "common/rational.h" +#include "common/timecodefunctions.h" #include "project/item/footage/footage.h" #include "project/item/sequence/sequence.h" #include "project/project.h" @@ -125,6 +126,16 @@ public: ProjectViewModel* GetActiveProjectModel(); Folder* GetSelectedFolderInActiveProject(); + /** + * @brief Gets current timecode display mode + */ + Timecode::Display GetTimecodeDisplay() const; + + /** + * @brief Sets current timecode display mode + */ + void SetTimecodeDisplay(Timecode::Display d); + /** * @brief Sets state to "modified" so that the GUI will prompt the user to save before closing * @@ -269,6 +280,11 @@ signals: */ void SnappingChanged(const bool& b); + /** + * @brief Signal emitted when the default timecode display mode changed + */ + void TimecodeDisplayChanged(Timecode::Display d); + private: /** * @brief Get the file filter than can be used with QFileDialog to open and save compatible projects diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index e0b98a9ac..4434eb531 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -23,9 +23,9 @@ #include #include "codec/decoder.h" -#include "common/timecodefunctions.h" #include "common/xmlutils.h" #include "config/config.h" +#include "core.h" #include "ui/icons/icons.h" Footage::Footage() @@ -40,8 +40,6 @@ Footage::~Footage() void Footage::Load(QXmlStreamReader *reader, QHash& footage_ptrs, QList&, const QAtomicInt* cancelled) { - qDebug() << "Hello?"; - QXmlStreamAttributes attributes = reader->attributes(); foreach (const QXmlStreamAttribute& attr, attributes) { @@ -234,12 +232,12 @@ QString Footage::duration() return Timecode::timestamp_to_timecode(duration, frame_rate_timebase, - Timecode::CurrentDisplay()); + Core::instance()->GetTimecodeDisplay()); } else if (streams_.first()->type() == Stream::kAudio) { AudioStreamPtr audio_stream = std::static_pointer_cast(streams_.first()); // If we're showing in a timecode, we prefer showing audio in seconds instead - Timecode::Display display = Timecode::CurrentDisplay(); + Timecode::Display display = Core::instance()->GetTimecodeDisplay(); if (display == Timecode::kTimecodeDropFrame || display == Timecode::kTimecodeNonDropFrame) { display = Timecode::kTimecodeSeconds; diff --git a/app/project/item/sequence/sequence.cpp b/app/project/item/sequence/sequence.cpp index f15344310..00101f126 100644 --- a/app/project/item/sequence/sequence.cpp +++ b/app/project/item/sequence/sequence.cpp @@ -199,7 +199,7 @@ QString Sequence::duration() int64_t timestamp = Timecode::time_to_timestamp(timeline_length, video_params().time_base()); - return Timecode::timestamp_to_timecode(timestamp, video_params().time_base(), Timecode::CurrentDisplay()); + return Timecode::timestamp_to_timecode(timestamp, video_params().time_base(), Core::instance()->GetTimecodeDisplay()); } QString Sequence::rate() diff --git a/app/widget/playbackcontrols/playbackcontrols.cpp b/app/widget/playbackcontrols/playbackcontrols.cpp index 523a7a9e5..400fdedba 100644 --- a/app/widget/playbackcontrols/playbackcontrols.cpp +++ b/app/widget/playbackcontrols/playbackcontrols.cpp @@ -24,7 +24,7 @@ #include #include -#include "common/timecodefunctions.h" +#include "core.h" #include "config/config.h" #include "ui/icons/icons.h" @@ -120,6 +120,8 @@ PlaybackControls::PlaybackControls(QWidget *parent) : UpdateIcons(); SetTimebase(0); + + connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &PlaybackControls::TimecodeChanged); } void PlaybackControls::SetTimecodeEnabled(bool enabled) @@ -147,9 +149,11 @@ void PlaybackControls::SetEndTime(const int64_t &r) return; } - end_tc_lbl_->setText(Timecode::timestamp_to_timecode(r, + end_time_ = r; + + end_tc_lbl_->setText(Timecode::timestamp_to_timecode(end_time_, time_base_, - Timecode::CurrentDisplay())); + Core::instance()->GetTimecodeDisplay())); } void PlaybackControls::ShowPauseButton() @@ -181,3 +185,9 @@ void PlaybackControls::UpdateIcons() next_frame_btn_->setIcon(icon::NextFrame); go_to_end_btn_->setIcon(icon::GoToEnd); } + +void PlaybackControls::TimecodeChanged() +{ + // Update end time + SetEndTime(end_time_); +} diff --git a/app/widget/playbackcontrols/playbackcontrols.h b/app/widget/playbackcontrols/playbackcontrols.h index 2c9701d91..9ad983f0b 100644 --- a/app/widget/playbackcontrols/playbackcontrols.h +++ b/app/widget/playbackcontrols/playbackcontrols.h @@ -101,6 +101,8 @@ private: TimeSlider* cur_tc_lbl_; QLabel* end_tc_lbl_; + int64_t end_time_; + rational time_base_; QPushButton* go_to_start_btn_; @@ -113,7 +115,7 @@ private: QStackedWidget* playpause_stack_; private slots: - + void TimecodeChanged(); }; diff --git a/app/widget/slider/timeslider.cpp b/app/widget/slider/timeslider.cpp index 5899596db..4d59c007c 100644 --- a/app/widget/slider/timeslider.cpp +++ b/app/widget/slider/timeslider.cpp @@ -1,11 +1,14 @@ #include "timeslider.h" #include "common/timecodefunctions.h" +#include "core.h" TimeSlider::TimeSlider(QWidget *parent) : IntegerSlider(parent) { SetMinimum(0); + + connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &TimeSlider::TimecodeDisplayChanged); } void TimeSlider::SetTimebase(const rational &timebase) @@ -25,10 +28,15 @@ QString TimeSlider::ValueToString(const QVariant &v) return Timecode::timestamp_to_timecode(v.toLongLong(), timebase_, - Timecode::CurrentDisplay()); + Core::instance()->GetTimecodeDisplay()); } QVariant TimeSlider::StringToValue(const QString &s, bool *ok) { - return QVariant::fromValue(Timecode::timecode_to_timestamp(s, timebase_, Timecode::CurrentDisplay(), ok)); + return QVariant::fromValue(Timecode::timecode_to_timestamp(s, timebase_, Core::instance()->GetTimecodeDisplay(), ok)); +} + +void TimeSlider::TimecodeDisplayChanged() +{ + UpdateLabel(Value()); } diff --git a/app/widget/slider/timeslider.h b/app/widget/slider/timeslider.h index 331572d96..a69c0f31b 100644 --- a/app/widget/slider/timeslider.h +++ b/app/widget/slider/timeslider.h @@ -6,6 +6,7 @@ class TimeSlider : public IntegerSlider { + Q_OBJECT public: TimeSlider(QWidget* parent = nullptr); @@ -19,6 +20,9 @@ protected: private: rational timebase_; +private slots: + void TimecodeDisplayChanged(); + }; #endif // TIMESLIDER_H diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index 366f46277..92293cbd4 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -143,7 +143,7 @@ void TimelineWidget::ImportTool::DragMove(TimelineViewMouseEvent *event) int64_t earliest_timestamp = Timecode::time_to_timestamp(earliest_ghost, parent()->timebase()); QString tooltip_text = Timecode::timestamp_to_timecode(earliest_timestamp, parent()->timebase(), - Timecode::CurrentDisplay()); + Core::instance()->GetTimecodeDisplay()); // Force tooltip to update (otherwise the tooltip won't move as written in the documentation, and could get in the way // of the cursor) diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index e88cad283..80fd34194 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -404,7 +404,7 @@ void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_po int64_t earliest_timestamp = Timecode::time_to_timestamp(time_movement, parent()->timebase()); QString tooltip_text = Timecode::timestamp_to_timecode(earliest_timestamp, parent()->timebase(), - Timecode::CurrentDisplay(), + Core::instance()->GetTimecodeDisplay(), true); // Force tooltip to update (otherwise the tooltip won't move as written in the documentation, and could get in the way diff --git a/app/widget/timelinewidget/tool/slip.cpp b/app/widget/timelinewidget/tool/slip.cpp index b13f5297e..299ed5f22 100644 --- a/app/widget/timelinewidget/tool/slip.cpp +++ b/app/widget/timelinewidget/tool/slip.cpp @@ -54,7 +54,7 @@ void TimelineWidget::SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos) int64_t earliest_timestamp = Timecode::time_to_timestamp(time_movement, parent()->timebase()); QString tooltip_text = Timecode::timestamp_to_timecode(earliest_timestamp, parent()->timebase(), - Timecode::CurrentDisplay(), + Core::instance()->GetTimecodeDisplay(), true); // Force tooltip to update (otherwise the tooltip won't move as written in the documentation, and could get in the way // of the cursor) diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index c9ff31939..25b504995 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -47,6 +47,9 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare // Text visibility affects height, so we set that here UpdateHeight(); + + // Force update if the default timecode display mode changes + connect(Core::instance(), &Core::TimecodeDisplayChanged, this, static_cast(&TimeRuler::update)); } void TimeRuler::SetCacheStatusLength(const rational &length) @@ -203,7 +206,7 @@ void TimeRuler::paintEvent(QPaintEvent *) if (text_visible_) { QRect text_rect; Qt::Alignment text_align; - QString timecode_str = Timecode::timestamp_to_timecode(ScreenToUnit(i), timebase(), Timecode::CurrentDisplay()); + QString timecode_str = Timecode::timestamp_to_timecode(ScreenToUnit(i), timebase(), Core::instance()->GetTimecodeDisplay()); int timecode_width = QFontMetricsWidth(fm, timecode_str); int timecode_left; diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index 95c4eba68..1034fe378 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -100,9 +100,6 @@ MainMenu::MainMenu(QMainWindow *parent) : view_show_all_item_ = view_menu_->AddItem("showall", nullptr, nullptr, "\\"); view_show_all_item_->setCheckable(true); view_menu_->addSeparator(); - view_rectified_waveforms_item_ = view_menu_->AddItem("rectifiedwaveforms", nullptr, nullptr); - view_rectified_waveforms_item_->setCheckable(true); - view_menu_->addSeparator(); frame_view_mode_group_ = new QActionGroup(this); @@ -327,7 +324,7 @@ void MainMenu::TimecodeDisplayTriggered() Timecode::Display display = static_cast(action->data().toInt()); // Set the current display mode - Timecode::SetCurrentDisplay(display); + Core::instance()->SetTimecodeDisplay(display); } void MainMenu::FileMenuAboutToShow() @@ -343,7 +340,7 @@ void MainMenu::ViewMenuAboutToShow() // Ensure checked timecode display mode is correct QList timecode_display_actions = frame_view_mode_group_->actions(); foreach (QAction* a, timecode_display_actions) { - if (a->data() == Timecode::CurrentDisplay()) { + if (a->data() == Core::instance()->GetTimecodeDisplay()) { a->setChecked(true); break; } @@ -553,7 +550,6 @@ void MainMenu::Retranslate() view_increase_track_height_item_->setText(tr("Increase Track Height")); view_decrease_track_height_item_->setText(tr("Decrease Track Height")); view_show_all_item_->setText(tr("Toggle Show All")); - view_rectified_waveforms_item_->setText(tr("Rectified Waveforms")); view_timecode_view_frames_item_->setText(tr("Frames")); view_timecode_view_dropframe_item_->setText(tr("Drop Frame")); view_timecode_view_nondropframe_item_->setText(tr("Non-Drop Frame")); diff --git a/app/window/mainwindow/mainmenu.h b/app/window/mainwindow/mainmenu.h index 2f4eea741..d45b0818a 100644 --- a/app/window/mainwindow/mainmenu.h +++ b/app/window/mainwindow/mainmenu.h @@ -181,7 +181,6 @@ private: QAction* view_increase_track_height_item_; QAction* view_decrease_track_height_item_; QAction* view_show_all_item_; - QAction* view_rectified_waveforms_item_; QActionGroup* frame_view_mode_group_; QAction* view_timecode_view_dropframe_item_; QAction* view_timecode_view_nondropframe_item_;