core: added signalling for timecode display changes

Allows targeted application-wide UI updates for when the user changes the
timecode display so that the response is immediate.
This commit is contained in:
itsmattkc
2020-03-18 14:09:31 +11:00
parent eb871ceccc
commit abb4c440fb
16 changed files with 71 additions and 36 deletions
-10
View File
@@ -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<Timecode::Display>(Config::Current()["TimecodeDisplay"].toInt());
}
void Timecode::SetCurrentDisplay(Timecode::Display d)
{
Config::Current()["TimecodeDisplay"] = d;
}
-3
View File
@@ -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
*/
+12
View File
@@ -482,6 +482,18 @@ Folder *Core::GetSelectedFolderInActiveProject()
}
}
Timecode::Display Core::GetTimecodeDisplay() const
{
return static_cast<Timecode::Display>(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);
+16
View File
@@ -26,6 +26,7 @@
#include <QTimer>
#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
+3 -5
View File
@@ -23,9 +23,9 @@
#include <QCoreApplication>
#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<quintptr, StreamPtr>& footage_ptrs, QList<NodeParam::FootageConnection>&, 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<AudioStream>(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;
+1 -1
View File
@@ -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()
@@ -24,7 +24,7 @@
#include <QEvent>
#include <QHBoxLayout>
#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_);
}
@@ -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();
};
+10 -2
View File
@@ -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());
}
+4
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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)
+4 -1
View File
@@ -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<void (TimeRuler::*)()>(&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;
+2 -6
View File
@@ -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<Timecode::Display>(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<QAction*> 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"));
-1
View File
@@ -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_;