From b12518af9edac459b2fbdd44d65f96c3ce33839b Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Tue, 15 Dec 2020 19:51:36 +0000 Subject: [PATCH 01/24] Initial implementation. --- app/widget/slider/CMakeLists.txt | 2 + app/widget/slider/rationalslider.cpp | 142 +++++++++++++++++++++++++++ app/widget/slider/rationalslider.h | 80 +++++++++++++++ app/widget/slider/sliderbase.cpp | 6 ++ app/widget/slider/sliderbase.h | 3 +- 5 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 app/widget/slider/rationalslider.cpp create mode 100644 app/widget/slider/rationalslider.h diff --git a/app/widget/slider/CMakeLists.txt b/app/widget/slider/CMakeLists.txt index ef2b3443c..0d9d22944 100644 --- a/app/widget/slider/CMakeLists.txt +++ b/app/widget/slider/CMakeLists.txt @@ -20,6 +20,8 @@ set(OLIVE_SOURCES widget/slider/floatslider.cpp widget/slider/integerslider.h widget/slider/integerslider.cpp + widget/slider/rationalslider.h + widget/slider/rationalslider.cpp widget/slider/sliderbase.h widget/slider/sliderbase.cpp widget/slider/sliderlabel.h diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp new file mode 100644 index 000000000..a2650207e --- /dev/null +++ b/app/widget/slider/rationalslider.cpp @@ -0,0 +1,142 @@ +/*** + Olive - Non-Linear Video Editor + Copyright (C) 2020 Olive Team + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#include "rationalslider.h" + +#include "common/timecodefunctions.h" +#include "core.h" + +namespace olive { + +RationalSlider::RationalSlider(rational timebase, QWidget *parent) : + SliderBase(SliderBase::kRational, parent), + display_type_(kTimecode), + decimal_places_(2), + autotrim_decimal_places_(false), + timebase_(timebase) +{ + connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); +} + +rational RationalSlider::GetValue() +{ + return Value().value(); +} + +void RationalSlider::SetValue(const rational &d) +{ + QVariant r; + r.setValue(d); + SliderBase::SetValue(r); +} + +void RationalSlider::SetMinimum(const rational &d) +{ + QVariant r; + r.setValue(d); + SetMinimumInternal(r); +} + +void RationalSlider::SetMaximum(const rational &d) +{ + QVariant r; + r.setValue(d); + SetMaximumInternal(r); +} + +void RationalSlider::SetDecimalPlaces(int i) +{ + decimal_places_ = i; + + ForceLabelUpdate(); +} + +void RationalSlider::SetTimebase(const rational &timebase) +{ + timebase_ = timebase; + + // Refresh label since we have a new timebase to generate a timecode with + UpdateLabel(Value()); +} + +void RationalSlider::SetAutoTrimDecimalPlaces(bool e) { + autotrim_decimal_places_ = e; + + ForceLabelUpdate(); +} + +void RationalSlider::SetDisplayType(const RationalSlider::DisplayType &type) +{ + display_type_ = type; + + switch (display_type_) { + case kTimecode: + case kRational: + ClearFormat(); + break; + case kTimestamp: + SetFormat("%1 Frames"); + break; + case kFloat: + SetFormat("%1 Seconds"); + break; + } +} + +QString RationalSlider::ValueToString(const QVariant &v) +{ + rational r = v.value(); + switch (display_type_) { + case kTimecode: + return Timecode::time_to_timecode(r, timebase_, Core::instance()->GetTimecodeDisplay()); + case kTimestamp: + return QString::number(Timecode::time_to_timestamp(r, timebase_)); + case kRational: + // Might we want to call reduce() on r here? + return r.toString(); + case kFloat: + { + QString s = QString::number(r.toDouble(), 'f', decimal_places_); + + if (autotrim_decimal_places_) { + while (s.endsWith('0') && s.at(s.size() - 2).isDigit()) { + s = s.left(s.size() - 1); + } + } + return s; + } + } + return r.toString(); +} + +QVariant RationalSlider::StringToValue(const QString &s, bool *ok) +{ + // Just try to convert the string to a double + // REMEMBER TO IMPLEMENT!!!! + return s.toDouble(ok); +} + +double RationalSlider::AdjustDragDistanceInternal(const double &start, const double &drag) +{ + // Assume we want smallest increment to be timebase or 1 frame + return start + drag*timebase_.toDouble(); +} + +void RationalSlider::ConvertValue(QVariant v) +{ + emit ValueChanged(v.value()); +} + +} diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h new file mode 100644 index 000000000..916b06513 --- /dev/null +++ b/app/widget/slider/rationalslider.h @@ -0,0 +1,80 @@ +/*** + Olive - Non-Linear Video Editor + Copyright (C) 2020 Olive Team + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#ifndef RATIONALSLIDER_H +#define RATIONALSLIDER_H + +#include "sliderbase.h" + +#include "common/rational.h" + +namespace olive { + +class RationalSlider : public SliderBase +{ + Q_OBJECT +public: + RationalSlider(QWidget* parent = nullptr); + + enum DisplayType { + kTimecode, + kTimestamp, + kRational, + kFloat + }; + + rational GetValue(); + + void SetValue(const rational& d); + + void SetMinimum(const rational& d); + + void SetMaximum(const rational& d); + + void SetDecimalPlaces(int i); + + void SetTimebase(const rational& timebase); + + void SetDisplayType(const DisplayType& type); + + void SetAutoTrimDecimalPlaces(bool e); + +protected: + virtual QString ValueToString(const QVariant& v) override; + + virtual QVariant StringToValue(const QString& s, bool* ok) override; + + virtual double AdjustDragDistanceInternal(const double& start, const double& drag) override; + +signals: + void ValueChanged(rational); + +private slots: + void ConvertValue(QVariant v); + +private: + DisplayType display_type_; + + int decimal_places_; + + bool autotrim_decimal_places_; + + rational timebase_; + +}; + +} + +#endif // RATIONALSLIDER_H diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 25d36f10b..5d1781b27 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -65,6 +65,7 @@ SliderBase::SliderBase(Mode mode, QWidget *parent) : break; case kInteger: case kFloat: + case kRational: setCursor(Qt::SizeHorCursor); break; } @@ -276,6 +277,7 @@ void SliderBase::LadderDragged(int value, double multiplier) break; case kInteger: case kFloat: + case kRational: { dragged_diff_ += value * drag_multiplier_ * multiplier; @@ -322,6 +324,10 @@ void SliderBase::LadderReleased() case kFloat: SetValue(clamped_temp_dragged_value_.toDouble()); break; + case kRational: + QVariant r; + r.setValue(rational(temp_dragged_value_.toDouble())); + SetValue(r); } emit ValueChanged(value_); diff --git a/app/widget/slider/sliderbase.h b/app/widget/slider/sliderbase.h index 5d5a9fc95..19d7dd897 100644 --- a/app/widget/slider/sliderbase.h +++ b/app/widget/slider/sliderbase.h @@ -35,7 +35,8 @@ public: enum Mode { kString, kInteger, - kFloat + kFloat, + kRational }; SliderBase(Mode mode, QWidget* parent = nullptr); From 3bc26f6ce0cf67b6ff0d0ac379ba4316339dcddb Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 17 Dec 2020 14:55:10 +0000 Subject: [PATCH 02/24] Finish implementation --- .../sequence/sequencedialogparametertab.cpp | 2 + app/widget/slider/rationalslider.cpp | 66 +++++++++++++--- app/widget/slider/rationalslider.h | 45 ++++++++++- app/widget/slider/sliderbase.cpp | 77 ++++++++++++++++--- app/widget/slider/sliderbase.h | 3 + app/widget/slider/sliderlabel.cpp | 4 +- app/widget/slider/sliderlabel.h | 2 + 7 files changed, 174 insertions(+), 25 deletions(-) diff --git a/app/dialog/sequence/sequencedialogparametertab.cpp b/app/dialog/sequence/sequencedialogparametertab.cpp index 2617cae4c..143b4a924 100644 --- a/app/dialog/sequence/sequencedialogparametertab.cpp +++ b/app/dialog/sequence/sequencedialogparametertab.cpp @@ -7,6 +7,8 @@ #include "core.h" +#include "widget//slider/rationalslider.h" + namespace olive { SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidget* parent) : diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index a2650207e..b24d99725 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -20,14 +20,18 @@ namespace olive { -RationalSlider::RationalSlider(rational timebase, QWidget *parent) : +RationalSlider::RationalSlider(DisplayType display_type, rational timebase, QWidget *parent) : SliderBase(SliderBase::kRational, parent), - display_type_(kTimecode), + display_type_(display_type), decimal_places_(2), autotrim_decimal_places_(false), timebase_(timebase) { connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); + connect(this, &SliderBase::changeRationalDisplayType, this, &RationalSlider::changeDisplayType); + connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &RationalSlider::ChangeTimecodeDisplayType); + + SetDisplayType(display_type_); } rational RationalSlider::GetValue() @@ -90,25 +94,26 @@ void RationalSlider::SetDisplayType(const RationalSlider::DisplayType &type) SetFormat("%1 Frames"); break; case kFloat: - SetFormat("%1 Seconds"); + SetFormat("%1 s"); break; } } QString RationalSlider::ValueToString(const QVariant &v) { - rational r = v.value(); + double time = v.value().toDouble(); + switch (display_type_) { case kTimecode: - return Timecode::time_to_timecode(r, timebase_, Core::instance()->GetTimecodeDisplay()); + return Timecode::time_to_timecode(v.value(), timebase_, Core::instance()->GetTimecodeDisplay()); case kTimestamp: - return QString::number(Timecode::time_to_timestamp(r, timebase_)); + return QString::number(Timecode::time_to_timestamp(time, timebase_)); case kRational: // Might we want to call reduce() on r here? - return r.toString(); + return v.value().toString(); case kFloat: { - QString s = QString::number(r.toDouble(), 'f', decimal_places_); + QString s = QString::number(time, 'f', decimal_places_); if (autotrim_decimal_places_) { while (s.endsWith('0') && s.at(s.size() - 2).isDigit()) { @@ -118,14 +123,40 @@ QString RationalSlider::ValueToString(const QVariant &v) return s; } } - return r.toString(); + return v.toString(); } QVariant RationalSlider::StringToValue(const QString &s, bool *ok) { - // Just try to convert the string to a double - // REMEMBER TO IMPLEMENT!!!! - return s.toDouble(ok); + QVariant v; + rational r; + *ok = false; + + switch (display_type_) { + case kTimecode: + { + int t = Timecode::timecode_to_timestamp(s, timebase_, Core::instance()->GetTimecodeDisplay(), ok); + r = rational(t, timebase_.denominator()); + break; + } + case kTimestamp: + r = rational(s.toInt(ok), timebase_.denominator()); + break; + case kRational: + r = rational::fromString(s); + if (!r.isNull()) { + *ok = true; + } + break; + case kFloat: + r = rational::fromDouble(s.toDouble(ok)); + if (!r.isNull()) { + *ok = true; + } + break; + } + v.setValue(r); + return v; } double RationalSlider::AdjustDragDistanceInternal(const double &start, const double &drag) @@ -139,4 +170,15 @@ void RationalSlider::ConvertValue(QVariant v) emit ValueChanged(v.value()); } +void RationalSlider::changeDisplayType() +{ + SetDisplayType(static_cast(((int)(display_type_)+1)%4)); + ForceLabelUpdate(); +} + +void RationalSlider::ChangeTimecodeDisplayType() +{ + ForceLabelUpdate(); +} + } diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index 916b06513..220bf2b44 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -18,16 +18,27 @@ #include "sliderbase.h" +#include + #include "common/rational.h" namespace olive { + /** + * @brief A olive::rational based slider + * + * A slider that can display rationals as either timecode, a timestamp (frames), a rational (a/b) + * or a float (seconds). + * + * Control clikcing the slider (see sliderlabel.h) changes thedisplay type + */ class RationalSlider : public SliderBase { Q_OBJECT public: - RationalSlider(QWidget* parent = nullptr); - + /** + * @brief enum containing the possibly display types + */ enum DisplayType { kTimecode, kTimestamp, @@ -35,18 +46,41 @@ public: kFloat }; + RationalSlider(DisplayType display_type, rational timebase, QWidget* parent = nullptr); + + /** + * @brief Returns the sliders value as a rational + */ rational GetValue(); + /** + * @brief Sets the sliders value + */ void SetValue(const rational& d); + /** + * @brief Sets the sliders minimum value + */ void SetMinimum(const rational& d); + /** + * @brief Sets the sliders maximum value + */ void SetMaximum(const rational& d); + /** + * @brief Sets the number of decimal places the slider shows when displaying a float + */ void SetDecimalPlaces(int i); + /** + * @brief Sets the sliders timebase which is also the minimum increment of the slider + */ void SetTimebase(const rational& timebase); + /** + * @brief Sets the display type of the slider + */ void SetDisplayType(const DisplayType& type); void SetAutoTrimDecimalPlaces(bool e); @@ -64,6 +98,13 @@ signals: private slots: void ConvertValue(QVariant v); + void changeDisplayType(); + + /** + * @brief Changes the timecodes display type (e.g. drop frome to none drop frame) + */ + void ChangeTimecodeDisplayType(); + private: DisplayType display_type_; diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 5d1781b27..32b926909 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -55,6 +55,7 @@ SliderBase::SliderBase(Mode mode, QWidget *parent) : connect(label_, &SliderLabel::LabelPressed, this, &SliderBase::LabelPressed); connect(label_, &SliderLabel::focused, this, &SliderBase::ShowEditor); connect(label_, &SliderLabel::RequestReset, this, &SliderBase::ResetValue); + connect(label_, &SliderLabel::ChangeSliderType, this, &SliderBase::ChangeSliderType); connect(editor_, &FocusableLineEdit::Confirmed, this, &SliderBase::LineEditConfirmed); connect(editor_, &FocusableLineEdit::Cancelled, this, &SliderBase::LineEditCancelled); @@ -160,8 +161,14 @@ void SliderBase::SetMinimumInternal(const QVariant &v) has_min_ = true; // Limit value by this new minimum value - if (value_.toDouble() < min_value_.toDouble()) { - SetValue(min_value_); + if (mode_ == kRational) { + if (value_.value().toDouble() < min_value_.value().toDouble()) { + SetValue(min_value_); + } + } else { + if (value_.toDouble() < min_value_.toDouble()) { + SetValue(min_value_); + } } } @@ -171,8 +178,14 @@ void SliderBase::SetMaximumInternal(const QVariant &v) has_max_ = true; // Limit value by this new maximum value - if (value_.toDouble() > max_value_.toDouble()) { - SetValue(max_value_); + if (mode_ == kRational) { + if (value_.value().toDouble() > max_value_.value().toDouble()) { + SetValue(max_value_); + } + } else { + if (value_.toDouble() > max_value_.toDouble()) { + SetValue(max_value_); + } } } @@ -186,11 +199,22 @@ void SliderBase::changeEvent(QEvent *e) const QVariant &SliderBase::ClampValue(const QVariant &v) { - if (has_min_ && v.toDouble() < min_value_.toDouble()) { - return min_value_; + double value, min, max; + + if (mode_ == kRational) { + value = v.value().toDouble(); + min = min_value_.value().toDouble(); + max = max_value_.value().toDouble(); + } else { + value = v.toDouble(); + min = min_value_.toDouble(); + max = max_value_.toDouble(); } - - if (has_max_ && v.toDouble() > max_value_.toDouble()) { + + if (has_min_ && value < min) { + return min_value_; + }else if (has_max_ && value > max) { + printf("MAX: %f\n", max_value_.value().toDouble()); return max_value_; } @@ -253,6 +277,7 @@ void SliderBase::LabelPressed() break; case kInteger: case kFloat: + case kRational: { drag_ladder_ = new SliderLadder(drag_multiplier_, ladder_element_count_); drag_ladder_->SetValue(ValueToString(value_)); @@ -277,7 +302,6 @@ void SliderBase::LadderDragged(int value, double multiplier) break; case kInteger: case kFloat: - case kRational: { dragged_diff_ += value * drag_multiplier_ * multiplier; @@ -303,6 +327,32 @@ void SliderBase::LadderDragged(int value, double multiplier) emit ValueChanged(clamped_temp_dragged_value_); break; } + + case kRational: + { + double old_dragged_diff = dragged_diff_; + dragged_diff_ += value * drag_multiplier_ * multiplier; + + double drag_val = AdjustDragDistanceInternal(value_.value().toDouble(), dragged_diff_); + + rational d_v; + d_v = rational::fromDouble(drag_val); + temp_dragged_value_.setValue(d_v); + + QVariant clamped = ClampValue(temp_dragged_value_); + if (clamped.value() != temp_dragged_value_.value()) { + temp_dragged_value_ = clamped; + dragged_diff_ = old_dragged_diff; + } + + UpdateLabel(temp_dragged_value_); + + drag_ladder_->SetValue(ValueToString(temp_dragged_value_)); + RepositionLadder(); + + emit ValueChanged(temp_dragged_value_); + break; + } } } @@ -326,7 +376,7 @@ void SliderBase::LadderReleased() break; case kRational: QVariant r; - r.setValue(rational(temp_dragged_value_.toDouble())); + r.setValue(rational::fromDouble(temp_dragged_value_.value().toDouble())); SetValue(r); } @@ -407,4 +457,11 @@ void SliderBase::RepositionLadder() } } +void SliderBase::ChangeSliderType() +{ + if (mode_ == kRational) { + emit changeRationalDisplayType(); + } +} + } diff --git a/app/widget/slider/sliderbase.h b/app/widget/slider/sliderbase.h index 19d7dd897..c28fc48a7 100644 --- a/app/widget/slider/sliderbase.h +++ b/app/widget/slider/sliderbase.h @@ -72,6 +72,8 @@ public: signals: void ValueChanged(QVariant v); + void changeRationalDisplayType(); + protected: const QVariant& Value() const; @@ -151,6 +153,7 @@ private slots: void RepositionLadder(); + void ChangeSliderType(); }; } diff --git a/app/widget/slider/sliderlabel.cpp b/app/widget/slider/sliderlabel.cpp index 11048658f..2d4de040b 100644 --- a/app/widget/slider/sliderlabel.cpp +++ b/app/widget/slider/sliderlabel.cpp @@ -54,7 +54,9 @@ void SliderLabel::mousePressEvent(QMouseEvent *e) if (e->button() == Qt::LeftButton) { if (e->modifiers() & Qt::AltModifier) { emit RequestReset(); - } else { + } else if (e->modifiers() & Qt::ControlModifier) { + emit ChangeSliderType(); + } else { emit LabelPressed(); } } diff --git a/app/widget/slider/sliderlabel.h b/app/widget/slider/sliderlabel.h index 2f698eb2c..533208a3b 100644 --- a/app/widget/slider/sliderlabel.h +++ b/app/widget/slider/sliderlabel.h @@ -45,6 +45,8 @@ signals: void RequestReset(); + void ChangeSliderType(); + }; } From 50c4586fe0f41c18520d573f7d5215c591afc206 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 17 Dec 2020 15:04:24 +0000 Subject: [PATCH 03/24] Cleanup --- app/widget/slider/rationalslider.cpp | 1 + app/widget/slider/sliderbase.cpp | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index b24d99725..c9e8b19cb 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -172,6 +172,7 @@ void RationalSlider::ConvertValue(QVariant v) void RationalSlider::changeDisplayType() { + // Loop through the display types SetDisplayType(static_cast(((int)(display_type_)+1)%4)); ForceLabelUpdate(); } diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 32b926909..5f5ec3dbe 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -375,9 +375,7 @@ void SliderBase::LadderReleased() SetValue(clamped_temp_dragged_value_.toDouble()); break; case kRational: - QVariant r; - r.setValue(rational::fromDouble(temp_dragged_value_.value().toDouble())); - SetValue(r); + SetValue(temp_dragged_value_); } emit ValueChanged(value_); From 3b2cf9d0a789ac549aab52e57320ed49ab372ba4 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 17 Dec 2020 16:12:46 +0000 Subject: [PATCH 04/24] Overload set default to allow rationals. --- app/widget/slider/rationalslider.cpp | 7 +++++++ app/widget/slider/rationalslider.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index c9e8b19cb..30eaeaf40 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -46,6 +46,13 @@ void RationalSlider::SetValue(const rational &d) SliderBase::SetValue(r); } +void RationalSlider::SetDefaultValue(const rational &r) +{ + QVariant v; + v.setValue(r); + SliderBase::SetDefaultValue(v); +} + void RationalSlider::SetMinimum(const rational &d) { QVariant r; diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index 220bf2b44..40ef1d98e 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -58,6 +58,8 @@ public: */ void SetValue(const rational& d); + void SetDefaultValue(const rational& r); + /** * @brief Sets the sliders minimum value */ From fae7ead0217b802f09c2b61d8def706d0e381a06 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 17 Dec 2020 17:50:59 +0000 Subject: [PATCH 05/24] Add a lock on changing the display type --- app/widget/slider/rationalslider.cpp | 25 +++++++++++++++++++------ app/widget/slider/rationalslider.h | 10 +++++++++- app/widget/slider/sliderbase.cpp | 1 - 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 30eaeaf40..a289e1e2a 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -20,12 +20,13 @@ namespace olive { -RationalSlider::RationalSlider(DisplayType display_type, rational timebase, QWidget *parent) : +RationalSlider::RationalSlider(rational timebase, QWidget *parent) : SliderBase(SliderBase::kRational, parent), - display_type_(display_type), + display_type_(kTimecode), decimal_places_(2), autotrim_decimal_places_(false), - timebase_(timebase) + timebase_(timebase), + lock_display_type_(false) { connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); connect(this, &SliderBase::changeRationalDisplayType, this, &RationalSlider::changeDisplayType); @@ -106,6 +107,16 @@ void RationalSlider::SetDisplayType(const RationalSlider::DisplayType &type) } } +void RationalSlider::SetLockDisplayType(bool e) +{ + lock_display_type_ = e; +} + +bool RationalSlider::LockDisplayType() +{ + return lock_display_type_; +} + QString RationalSlider::ValueToString(const QVariant &v) { double time = v.value().toDouble(); @@ -179,9 +190,11 @@ void RationalSlider::ConvertValue(QVariant v) void RationalSlider::changeDisplayType() { - // Loop through the display types - SetDisplayType(static_cast(((int)(display_type_)+1)%4)); - ForceLabelUpdate(); + if (!LockDisplayType()) { + // Loop through the display types + SetDisplayType(static_cast(((int)(display_type_) + 1) % 4)); + ForceLabelUpdate(); + } } void RationalSlider::ChangeTimecodeDisplayType() diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index 40ef1d98e..093714541 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -46,7 +46,7 @@ public: kFloat }; - RationalSlider(DisplayType display_type, rational timebase, QWidget* parent = nullptr); + RationalSlider(rational timebase, QWidget* parent = nullptr); /** * @brief Returns the sliders value as a rational @@ -58,6 +58,9 @@ public: */ void SetValue(const rational& d); + /** + * @brief Sets the sliders default value + */ void SetDefaultValue(const rational& r); /** @@ -85,6 +88,10 @@ public: */ void SetDisplayType(const DisplayType& type); + void SetLockDisplayType(bool e); + + bool LockDisplayType(); + void SetAutoTrimDecimalPlaces(bool e); protected: @@ -116,6 +123,7 @@ private: rational timebase_; + bool lock_display_type_; }; } diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 5f5ec3dbe..770fc57ed 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -214,7 +214,6 @@ const QVariant &SliderBase::ClampValue(const QVariant &v) if (has_min_ && value < min) { return min_value_; }else if (has_max_ && value > max) { - printf("MAX: %f\n", max_value_.value().toDouble()); return max_value_; } From f381d3ddeae5b9f23ccbb5c5975be679f292b089 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Fri, 18 Dec 2020 15:04:50 +0000 Subject: [PATCH 06/24] Add extra documentation --- app/widget/slider/rationalslider.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index 093714541..bdff39d4b 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -88,8 +88,14 @@ public: */ void SetDisplayType(const DisplayType& type); + /** + * @brief Set whether the user can change the display type or not + */ void SetLockDisplayType(bool e); + /** + * @brief Get whether the user can change the display type or not + */ bool LockDisplayType(); void SetAutoTrimDecimalPlaces(bool e); From 191a8bb6ff50c249462c8675a210e8afb8066aa7 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 19 Dec 2020 17:00:45 +0000 Subject: [PATCH 07/24] Use QVariant::fromValue(). --- app/widget/slider/rationalslider.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index a289e1e2a..8cfa2f740 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -42,30 +42,22 @@ rational RationalSlider::GetValue() void RationalSlider::SetValue(const rational &d) { - QVariant r; - r.setValue(d); - SliderBase::SetValue(r); + SliderBase::SetValue(QVariant::fromValue(d)); } void RationalSlider::SetDefaultValue(const rational &r) { - QVariant v; - v.setValue(r); - SliderBase::SetDefaultValue(v); + SliderBase::SetDefaultValue(QVariant::fromValue(r)); } void RationalSlider::SetMinimum(const rational &d) { - QVariant r; - r.setValue(d); - SetMinimumInternal(r); + SetMinimumInternal(QVariant::fromValue(d)); } void RationalSlider::SetMaximum(const rational &d) { - QVariant r; - r.setValue(d); - SetMaximumInternal(r); + SetMaximumInternal(QVariant::fromValue(d)); } void RationalSlider::SetDecimalPlaces(int i) @@ -173,8 +165,8 @@ QVariant RationalSlider::StringToValue(const QString &s, bool *ok) } break; } - v.setValue(r); - return v; + + return QVariant::fromValue(r); } double RationalSlider::AdjustDragDistanceInternal(const double &start, const double &drag) From b636b77fbef3623c7f4a39cfa69cdd7dc6a1f9cf Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 19 Dec 2020 17:14:20 +0000 Subject: [PATCH 08/24] Cleanup unused variable --- app/widget/slider/rationalslider.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 8cfa2f740..62fd2548c 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -138,7 +138,6 @@ QString RationalSlider::ValueToString(const QVariant &v) QVariant RationalSlider::StringToValue(const QString &s, bool *ok) { - QVariant v; rational r; *ok = false; From 24726bee24590afb4c5d364ab47161180e379516 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 20 Mar 2021 20:13:44 +0000 Subject: [PATCH 09/24] Remove test --- app/dialog/sequence/sequencedialogparametertab.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/dialog/sequence/sequencedialogparametertab.cpp b/app/dialog/sequence/sequencedialogparametertab.cpp index 143b4a924..2617cae4c 100644 --- a/app/dialog/sequence/sequencedialogparametertab.cpp +++ b/app/dialog/sequence/sequencedialogparametertab.cpp @@ -7,8 +7,6 @@ #include "core.h" -#include "widget//slider/rationalslider.h" - namespace olive { SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidget* parent) : From 7c123c56c3195219d6dd8cef4f0eff004f48e45f Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 20 Mar 2021 23:58:04 +0000 Subject: [PATCH 10/24] Get rational slider mostly working with new slider changes --- .../nodeparamviewwidgetbridge.cpp | 27 ++++++++++++++----- app/widget/slider/rationalslider.cpp | 15 ++++++++--- app/widget/slider/rationalslider.h | 7 ++++- app/widget/slider/sliderbase.cpp | 9 ++++--- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index a6b1240b7..e27059353 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -37,6 +37,7 @@ #include "widget/filefield/filefield.h" #include "widget/slider/floatslider.h" #include "widget/slider/integerslider.h" +#include "widget/slider/rationalslider.h" #include "widget/videoparamedit/videoparamedit.h" namespace olive { @@ -76,7 +77,6 @@ void NodeParamViewWidgetBridge::CreateWidgets() case NodeValue::kNone: case NodeValue::kTexture: case NodeValue::kMatrix: - case NodeValue::kRational: case NodeValue::kSamples: case NodeValue::kFootageJob: case NodeValue::kShaderJob: @@ -93,6 +93,11 @@ void NodeParamViewWidgetBridge::CreateWidgets() CreateSliders(1); break; } + case NodeValue::kRational: + { + CreateSliders(1); + break; + } case NodeValue::kVec2: { CreateSliders(2); @@ -258,7 +263,6 @@ void NodeParamViewWidgetBridge::WidgetCallback() case NodeValue::kTexture: case NodeValue::kMatrix: case NodeValue::kSamples: - case NodeValue::kRational: case NodeValue::kFootageJob: case NodeValue::kShaderJob: case NodeValue::kSampleJob: @@ -280,6 +284,13 @@ void NodeParamViewWidgetBridge::WidgetCallback() ProcessSlider(slider, slider->GetValue()); break; } + case NodeValue::kRational: + { + // Widget is a RationalSlider + RationalSlider* slider = static_cast(sender()); + ProcessSlider(slider, QVariant::fromValue(slider->GetValue()));; + break; + } case NodeValue::kVec2: { // Widget is a FloatSlider @@ -404,7 +415,6 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues() case NodeValue::kNone: case NodeValue::kTexture: case NodeValue::kMatrix: - case NodeValue::kRational: case NodeValue::kSamples: case NodeValue::kFootageJob: case NodeValue::kShaderJob: @@ -421,6 +431,11 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues() static_cast(widgets_.first())->SetValue(input_.GetValueAtTime(node_time).toDouble()); break; } + case NodeValue::kRational: + { + static_cast(widgets_.first())->SetValue(input_.GetValueAtTime(node_time).value()); + break; + } case NodeValue::kVec2: { QVector2D vec2 = input_.GetValueAtTime(node_time).value(); @@ -560,7 +575,7 @@ void NodeParamViewWidgetBridge::PropertyChanged(const QString& input, const QStr static_cast(widgets_.first())->SetMinimum(value.toDouble()); break; case NodeValue::kRational: - // FIXME: Rational doesn't have a UI implementation yet + static_cast(widgets_.first())->SetMinimum(value.value()); break; case NodeValue::kVec2: { @@ -598,7 +613,7 @@ void NodeParamViewWidgetBridge::PropertyChanged(const QString& input, const QStr static_cast(widgets_.first())->SetMaximum(value.toDouble()); break; case NodeValue::kRational: - // FIXME: Rational doesn't have a UI implementation yet + static_cast(widgets_.first())->SetMaximum(value.value()); break; case NodeValue::kVec2: { @@ -636,7 +651,7 @@ void NodeParamViewWidgetBridge::PropertyChanged(const QString& input, const QStr static_cast(widgets_.first())->SetOffset(value); break; case NodeValue::kRational: - // FIXME: Rational doesn't have a UI implementation yet + static_cast(widgets_.first())->SetOffset(value); break; case NodeValue::kVec2: { diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 62fd2548c..71dd834ab 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -20,12 +20,12 @@ namespace olive { -RationalSlider::RationalSlider(rational timebase, QWidget *parent) : +RationalSlider::RationalSlider(QWidget *parent) : SliderBase(SliderBase::kRational, parent), display_type_(kTimecode), decimal_places_(2), autotrim_decimal_places_(false), - timebase_(timebase), + timebase_(rational(1,24)), lock_display_type_(false) { connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); @@ -33,6 +33,8 @@ RationalSlider::RationalSlider(rational timebase, QWidget *parent) : connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &RationalSlider::ChangeTimecodeDisplayType); SetDisplayType(display_type_); + + SetValue(rational(0, 0)); } rational RationalSlider::GetValue() @@ -50,6 +52,11 @@ void RationalSlider::SetDefaultValue(const rational &r) SliderBase::SetDefaultValue(QVariant::fromValue(r)); } +void RationalSlider::SetDefaultValue(const QVariant &v) { + rational r = v.value(); + SetDefaultValue(r); +} + void RationalSlider::SetMinimum(const rational &d) { SetMinimumInternal(QVariant::fromValue(d)); @@ -111,7 +118,7 @@ bool RationalSlider::LockDisplayType() QString RationalSlider::ValueToString(const QVariant &v) { - double time = v.value().toDouble(); + double time = v.value().toDouble() + GetOffset().value().toDouble(); switch (display_type_) { case kTimecode: @@ -165,7 +172,7 @@ QVariant RationalSlider::StringToValue(const QString &s, bool *ok) break; } - return QVariant::fromValue(r); + return QVariant::fromValue(r - GetOffset().value()); } double RationalSlider::AdjustDragDistanceInternal(const double &start, const double &drag) diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index bdff39d4b..3f171f5c2 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -46,7 +46,7 @@ public: kFloat }; - RationalSlider(rational timebase, QWidget* parent = nullptr); + RationalSlider(QWidget* parent = nullptr); /** * @brief Returns the sliders value as a rational @@ -63,6 +63,11 @@ public: */ void SetDefaultValue(const rational& r); + /** + * @brief Sets the sliders default value + */ + void SetDefaultValue(const QVariant& v); + /** * @brief Sets the sliders minimum value */ diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 770fc57ed..61d240e10 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -331,9 +331,7 @@ void SliderBase::LadderDragged(int value, double multiplier) { double old_dragged_diff = dragged_diff_; dragged_diff_ += value * drag_multiplier_ * multiplier; - double drag_val = AdjustDragDistanceInternal(value_.value().toDouble(), dragged_diff_); - rational d_v; d_v = rational::fromDouble(drag_val); temp_dragged_value_.setValue(d_v); @@ -341,13 +339,16 @@ void SliderBase::LadderDragged(int value, double multiplier) QVariant clamped = ClampValue(temp_dragged_value_); if (clamped.value() != temp_dragged_value_.value()) { temp_dragged_value_ = clamped; - dragged_diff_ = old_dragged_diff; + dragged_diff_ = (temp_dragged_value_.value() - value_.value()).toDouble(); } UpdateLabel(temp_dragged_value_); drag_ladder_->SetValue(ValueToString(temp_dragged_value_)); - RepositionLadder(); + + if (!Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) { + RepositionLadder(); + } emit ValueChanged(temp_dragged_value_); break; From c62389e6325353b74f8e99ef96324a9844f85bc9 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sun, 21 Mar 2021 00:44:17 +0000 Subject: [PATCH 11/24] Fix Linux build issue --- app/widget/slider/sliderbase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 61d240e10..be204b546 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -329,7 +329,6 @@ void SliderBase::LadderDragged(int value, double multiplier) case kRational: { - double old_dragged_diff = dragged_diff_; dragged_diff_ += value * drag_multiplier_ * multiplier; double drag_val = AdjustDragDistanceInternal(value_.value().toDouble(), dragged_diff_); rational d_v; From f9b423f73124b2698f2ccf3a9b0b9fcf1230cc40 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Wed, 7 Apr 2021 18:04:06 +0100 Subject: [PATCH 12/24] Link RationalSlider timebase with nodeparamview --- app/widget/nodeparamview/nodeparamview.cpp | 4 ++++ app/widget/nodeparamview/nodeparamviewitem.cpp | 11 +++++++++++ app/widget/nodeparamview/nodeparamviewitem.h | 4 ++++ .../nodeparamview/nodeparamviewwidgetbridge.cpp | 7 +++++++ app/widget/nodeparamview/nodeparamviewwidgetbridge.h | 2 ++ 5 files changed, 28 insertions(+) diff --git a/app/widget/nodeparamview/nodeparamview.cpp b/app/widget/nodeparamview/nodeparamview.cpp index 2df568671..28466f778 100644 --- a/app/widget/nodeparamview/nodeparamview.cpp +++ b/app/widget/nodeparamview/nodeparamview.cpp @@ -214,6 +214,10 @@ void NodeParamView::TimebaseChangedEvent(const rational &timebase) keyframe_view_->SetTimebase(timebase); + foreach (NodeParamViewItem* item, items_) { + item->SetTimebase(timebase); + } + UpdateItemTime(GetTimestamp()); } diff --git a/app/widget/nodeparamview/nodeparamviewitem.cpp b/app/widget/nodeparamview/nodeparamviewitem.cpp index 70b96e1c4..1d9b16f15 100644 --- a/app/widget/nodeparamview/nodeparamviewitem.cpp +++ b/app/widget/nodeparamview/nodeparamviewitem.cpp @@ -81,6 +81,11 @@ void NodeParamViewItem::SetTime(const rational &time) body_->SetTime(time_); } +void NodeParamViewItem::SetTimebase(const rational& timebase) +{ + body_->SetTimebase(timebase); +} + Node *NodeParamViewItem::GetNode() const { return node_; @@ -505,6 +510,12 @@ void NodeParamViewItemBody::ToggleArrayExpanded() } } +void NodeParamViewItemBody::SetTimebase(const rational& timebase) { + foreach (const InputUI& ui_obj, input_ui_map_) { + ui_obj.widget_bridge->SetTimebase(timebase); + } +} + NodeParamViewItemBody::InputUI::InputUI() : main_label(nullptr), widget_bridge(nullptr), diff --git a/app/widget/nodeparamview/nodeparamviewitem.h b/app/widget/nodeparamview/nodeparamviewitem.h index 2a72134ef..0b4729bd0 100644 --- a/app/widget/nodeparamview/nodeparamviewitem.h +++ b/app/widget/nodeparamview/nodeparamviewitem.h @@ -85,6 +85,8 @@ public: int GetElementY(NodeInput c) const; + void SetTimebase(const rational& timebase); + signals: void RequestSetTime(const rational& time); @@ -159,6 +161,8 @@ public: void SetTime(const rational& time); + void SetTimebase(const rational& timebase); + Node* GetNode() const; bool IsExpanded() const; diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index e27059353..b0469d8d0 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -526,6 +526,13 @@ rational NodeParamViewWidgetBridge::GetCurrentTimeAsNodeTime() const return GetAdjustedTime(GetTimeTarget(), input_.node(), time_, true); } +void NodeParamViewWidgetBridge::SetTimebase(const rational& timebase) +{ + if (input_.GetDataType() == NodeValue::kRational) { + static_cast(widgets_.first())->SetTimebase(timebase); + } +} + void NodeParamViewWidgetBridge::InputValueChanged(const NodeInput &input, const TimeRange &range) { if (input_ == input diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h index 7b191f143..d985eb52d 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h @@ -49,6 +49,8 @@ public: return widgets_; } + void SetTimebase(const rational& timebase); + signals: void ArrayWidgetDoubleClicked(); From 76f8c12a963b9304904145d1cc0c813d55799bd5 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 8 Apr 2021 00:27:59 +0100 Subject: [PATCH 13/24] Initilise timbase when creating nodeparamviewitem --- app/widget/nodeparamview/nodeparamview.cpp | 4 ++++ app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp | 2 ++ app/widget/nodeparamview/nodeparamviewwidgetbridge.h | 2 ++ app/widget/slider/rationalslider.cpp | 1 - 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/widget/nodeparamview/nodeparamview.cpp b/app/widget/nodeparamview/nodeparamview.cpp index 28466f778..98f835529 100644 --- a/app/widget/nodeparamview/nodeparamview.cpp +++ b/app/widget/nodeparamview/nodeparamview.cpp @@ -133,6 +133,7 @@ NodeParamView::NodeParamView(QWidget *parent) : &QApplication::focusChanged, this, &NodeParamView::FocusChanged); + } void NodeParamView::SelectNodes(const QVector &nodes) @@ -315,6 +316,9 @@ void NodeParamView::AddNode(Node *n) // Set time target item->SetTimeTarget(GetTimeTarget()); + // Set the timebase + item->SetTimebase(timebase()); + items_.insert(n, item); param_widget_area_->addDockWidget(Qt::LeftDockWidgetArea, item); diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index b0469d8d0..73d4f3a57 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -528,6 +528,8 @@ rational NodeParamViewWidgetBridge::GetCurrentTimeAsNodeTime() const void NodeParamViewWidgetBridge::SetTimebase(const rational& timebase) { + timebase_ = timebase; + if (input_.GetDataType() == NodeValue::kRational) { static_cast(widgets_.first())->SetTimebase(timebase); } diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h index d985eb52d..90102dd07 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h @@ -76,6 +76,8 @@ private: rational time_; + rational timebase_; + NodeInputDragger dragger_; NodeParamViewScrollBlocker scroll_filter_; diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 71dd834ab..43ce05ba0 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -25,7 +25,6 @@ RationalSlider::RationalSlider(QWidget *parent) : display_type_(kTimecode), decimal_places_(2), autotrim_decimal_places_(false), - timebase_(rational(1,24)), lock_display_type_(false) { connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); From f560beef607bdf391921b5519d41d0c5f33744aa Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 8 Apr 2021 11:41:42 +0100 Subject: [PATCH 14/24] Increase ladder width if displaying timeciode --- app/widget/slider/sliderladder.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/widget/slider/sliderladder.cpp b/app/widget/slider/sliderladder.cpp index af630dedf..65e25876c 100644 --- a/app/widget/slider/sliderladder.cpp +++ b/app/widget/slider/sliderladder.cpp @@ -291,6 +291,12 @@ void SliderLadderElement::UpdateLabel() } else { label_->setText(value_); } + + // Increase the ladder width if displaying timecode + if (value_.contains(":")) { + label_->setFixedWidth(QtUtils::QFontMetricsWidth(label_->fontMetrics(), QStringLiteral("00:00:00:00"))); + } + } } From 2cea45268f1837706053db09c8edb4efed85c17c Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Thu, 8 Apr 2021 12:56:26 +0100 Subject: [PATCH 15/24] TimeLineRulerMenu: only show drop or non-drop timecode depending on timebase --- app/panel/timebased/timebased.cpp | 5 +++++ app/panel/timebased/timebased.h | 2 ++ app/widget/menu/menushared.cpp | 21 ++++++++++++++++++--- app/widget/menu/menushared.h | 3 ++- app/widget/timeruler/timeruler.cpp | 2 +- app/window/mainwindow/mainmenu.cpp | 12 +++++++++--- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/panel/timebased/timebased.cpp b/app/panel/timebased/timebased.cpp index f569fc2ac..f731e0f44 100644 --- a/app/panel/timebased/timebased.cpp +++ b/app/panel/timebased/timebased.cpp @@ -34,6 +34,11 @@ rational TimeBasedPanel::GetTime() return widget_->GetTime(); } +rational TimeBasedPanel::timebase() +{ + return widget_->timebase(); +} + void TimeBasedPanel::GoToStart() { widget_->GoToStart(); diff --git a/app/panel/timebased/timebased.h b/app/panel/timebased/timebased.h index 30b5e208b..5fe4eb49e 100644 --- a/app/panel/timebased/timebased.h +++ b/app/panel/timebased/timebased.h @@ -41,6 +41,8 @@ public: rational GetTime(); + rational timebase(); + ViewerOutput *GetConnectedViewer() const { return widget_->GetConnectedNode(); diff --git a/app/widget/menu/menushared.cpp b/app/widget/menu/menushared.cpp index 1ccf5f37d..e202f1aec 100644 --- a/app/widget/menu/menushared.cpp +++ b/app/widget/menu/menushared.cpp @@ -21,6 +21,7 @@ #include "menushared.h" #include "core.h" +#include "common/timecodefunctions.h" #include "panel/panelmanager.h" #include "panel/timeline/timeline.h" @@ -159,10 +160,24 @@ void MenuShared::AddItemsForClipEditMenu(Menu *m) m->addAction(clip_nest_item_); } -void MenuShared::AddItemsForTimeRulerMenu(Menu *m) +void MenuShared::AddItemsForTimeRulerMenu(Menu *m, const rational& timebase) { - m->addAction(view_timecode_view_dropframe_item_); - m->addAction(view_timecode_view_nondropframe_item_); + // If menu is already created (such as the view menu) we need to remove the instance + // of dropfram or non-dropframe timecode that is already there to avoid double displays + + if (m->actions().contains(view_timecode_view_dropframe_item_)) { + m->removeAction(view_timecode_view_dropframe_item_); + } + + if (m->actions().contains(view_timecode_view_nondropframe_item_)) { + m->removeAction(view_timecode_view_nondropframe_item_); + } + + if (Timecode::TimebaseIsDropFrame(timebase)) { + m->addAction(view_timecode_view_dropframe_item_); + } else { + m->addAction(view_timecode_view_nondropframe_item_); + } m->addAction(view_timecode_view_seconds_item_); m->addAction(view_timecode_view_frames_item_); m->addAction(view_timecode_view_milliseconds_item_); diff --git a/app/widget/menu/menushared.h b/app/widget/menu/menushared.h index ae0707833..5d1cb7a1e 100644 --- a/app/widget/menu/menushared.h +++ b/app/widget/menu/menushared.h @@ -21,6 +21,7 @@ #ifndef MENUSHARED_H #define MENUSHARED_H +#include "common/rational.h" #include "widget/colorlabelmenu/colorlabelmenu.h" #include "widget/menu/menu.h" @@ -45,7 +46,7 @@ public: void AddItemsForInOutMenu(Menu* m); void AddColorCodingMenu(Menu* m); void AddItemsForClipEditMenu(Menu* m); - void AddItemsForTimeRulerMenu(Menu* m); + void AddItemsForTimeRulerMenu(Menu* m, const rational& timebase); void AboutToShowTimeRulerActions(); diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index 3b3f92635..18e1948f6 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -306,7 +306,7 @@ void TimeRuler::ShowContextMenu() { Menu m(this); - MenuShared::instance()->AddItemsForTimeRulerMenu(&m); + MenuShared::instance()->AddItemsForTimeRulerMenu(&m, timebase()); MenuShared::instance()->AboutToShowTimeRulerActions(); m.exec(QCursor::pos()); diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index f207adf6f..246dd91ed 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -112,9 +112,6 @@ MainMenu::MainMenu(MainWindow *parent) : view_decrease_track_height_item_ = view_menu_->AddItem("vzoomout", this, &MainMenu::DecreaseTrackHeightTriggered, "Ctrl+-"); view_show_all_item_ = view_menu_->AddItem("showall", this, &MainMenu::ToggleShowAllTriggered, "\\"); view_show_all_item_->setCheckable(true); - view_menu_->addSeparator(); - - MenuShared::instance()->AddItemsForTimeRulerMenu(view_menu_); view_menu_->addSeparator(); @@ -308,6 +305,15 @@ void MainMenu::ViewMenuAboutToShow() // Ensure checked timecode display mode is correct MenuShared::instance()->AboutToShowTimeRulerActions(); + + + TimeBasedPanel* p = PanelManager::instance()->MostRecentlyFocused(); + if (p) { + if (p->timebase().denominator() != 0) { + view_menu_->addSeparator(); + MenuShared::instance()->AddItemsForTimeRulerMenu(view_menu_, p->timebase()); + } + } } void MainMenu::ToolsMenuAboutToShow() From 4d8233e7ac8950ca900f3bf241f79b3fc86b1717 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Fri, 9 Apr 2021 10:52:07 +0100 Subject: [PATCH 16/24] Add display type context menu to RationalSlider --- app/widget/menu/menushared.cpp | 2 +- app/widget/slider/rationalslider.cpp | 9 ++++++++- app/widget/slider/sliderlabel.cpp | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/widget/menu/menushared.cpp b/app/widget/menu/menushared.cpp index e202f1aec..cdb3b3527 100644 --- a/app/widget/menu/menushared.cpp +++ b/app/widget/menu/menushared.cpp @@ -162,7 +162,7 @@ void MenuShared::AddItemsForClipEditMenu(Menu *m) void MenuShared::AddItemsForTimeRulerMenu(Menu *m, const rational& timebase) { - // If menu is already created (such as the view menu) we need to remove the instance + // If a menu is already created (such as the view menu) we need to remove the instance // of dropfram or non-dropframe timecode that is already there to avoid double displays if (m->actions().contains(view_timecode_view_dropframe_item_)) { diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 43ce05ba0..fbe6f9ba4 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -17,6 +17,8 @@ #include "common/timecodefunctions.h" #include "core.h" +#include "widget/menu/menu.h" +#include "widget/menu/menushared.h" namespace olive { @@ -189,7 +191,12 @@ void RationalSlider::changeDisplayType() { if (!LockDisplayType()) { // Loop through the display types - SetDisplayType(static_cast(((int)(display_type_) + 1) % 4)); + //SetDisplayType(static_cast(((int)(display_type_) + 1) % 4)); + Menu m(this); + MenuShared::instance()->AddItemsForTimeRulerMenu(&m, timebase_); + MenuShared::instance()->AboutToShowTimeRulerActions(); + + m.exec(QCursor::pos()); ForceLabelUpdate(); } } diff --git a/app/widget/slider/sliderlabel.cpp b/app/widget/slider/sliderlabel.cpp index 2d4de040b..276a2bc75 100644 --- a/app/widget/slider/sliderlabel.cpp +++ b/app/widget/slider/sliderlabel.cpp @@ -54,11 +54,11 @@ void SliderLabel::mousePressEvent(QMouseEvent *e) if (e->button() == Qt::LeftButton) { if (e->modifiers() & Qt::AltModifier) { emit RequestReset(); - } else if (e->modifiers() & Qt::ControlModifier) { - emit ChangeSliderType(); } else { emit LabelPressed(); } + } else if (e->button() == Qt::RightButton) { + emit ChangeSliderType(); } } From cb0cfebf40a80e4d7bcc334ea27d6176ece378eb Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Fri, 9 Apr 2021 11:57:49 +0100 Subject: [PATCH 17/24] Fix clamping bug, --- app/node/block/block.cpp | 1 + app/widget/slider/rationalslider.cpp | 2 -- app/widget/slider/sliderbase.cpp | 10 +++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/node/block/block.cpp b/app/node/block/block.cpp index 4ce6ec91b..3d1194d80 100644 --- a/app/node/block/block.cpp +++ b/app/node/block/block.cpp @@ -42,6 +42,7 @@ Block::Block() : out_transition_(nullptr) { AddInput(kLengthInput, NodeValue::kRational, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable)); + SetInputProperty(kLengthInput, "min", QVariant::fromValue(rational(0, 1))); IgnoreInvalidationsFrom(kLengthInput); IgnoreHashingFrom(kLengthInput); diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index fbe6f9ba4..87073187d 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -190,8 +190,6 @@ void RationalSlider::ConvertValue(QVariant v) void RationalSlider::changeDisplayType() { if (!LockDisplayType()) { - // Loop through the display types - //SetDisplayType(static_cast(((int)(display_type_) + 1) % 4)); Menu m(this); MenuShared::instance()->AddItemsForTimeRulerMenu(&m, timebase_); MenuShared::instance()->AboutToShowTimeRulerActions(); diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index be204b546..713ae15f3 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -335,21 +335,17 @@ void SliderBase::LadderDragged(int value, double multiplier) d_v = rational::fromDouble(drag_val); temp_dragged_value_.setValue(d_v); - QVariant clamped = ClampValue(temp_dragged_value_); - if (clamped.value() != temp_dragged_value_.value()) { - temp_dragged_value_ = clamped; - dragged_diff_ = (temp_dragged_value_.value() - value_.value()).toDouble(); - } + clamped_temp_dragged_value_ = ClampValue(temp_dragged_value_); UpdateLabel(temp_dragged_value_); - drag_ladder_->SetValue(ValueToString(temp_dragged_value_)); + drag_ladder_->SetValue(ValueToString(clamped_temp_dragged_value_)); if (!Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) { RepositionLadder(); } - emit ValueChanged(temp_dragged_value_); + emit ValueChanged(clamped_temp_dragged_value_); break; } } From b9ebc6be18e3b8a0b74944124622c7fd73920738 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 12 Apr 2021 10:14:18 +0100 Subject: [PATCH 18/24] Fix the easy comments. --- app/panel/timebased/timebased.cpp | 2 +- app/panel/timebased/timebased.h | 2 +- app/widget/menu/menushared.cpp | 1 + app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp | 4 +--- app/widget/nodeparamview/nodeparamviewwidgetbridge.h | 2 -- app/window/mainwindow/mainmenu.cpp | 8 ++++---- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/panel/timebased/timebased.cpp b/app/panel/timebased/timebased.cpp index f731e0f44..cc31d9fe2 100644 --- a/app/panel/timebased/timebased.cpp +++ b/app/panel/timebased/timebased.cpp @@ -34,7 +34,7 @@ rational TimeBasedPanel::GetTime() return widget_->GetTime(); } -rational TimeBasedPanel::timebase() +const rational& TimeBasedPanel::timebase() { return widget_->timebase(); } diff --git a/app/panel/timebased/timebased.h b/app/panel/timebased/timebased.h index 5fe4eb49e..7394bc280 100644 --- a/app/panel/timebased/timebased.h +++ b/app/panel/timebased/timebased.h @@ -41,7 +41,7 @@ public: rational GetTime(); - rational timebase(); + const rational& timebase(); ViewerOutput *GetConnectedViewer() const { diff --git a/app/widget/menu/menushared.cpp b/app/widget/menu/menushared.cpp index cdb3b3527..c61f22335 100644 --- a/app/widget/menu/menushared.cpp +++ b/app/widget/menu/menushared.cpp @@ -175,6 +175,7 @@ void MenuShared::AddItemsForTimeRulerMenu(Menu *m, const rational& timebase) if (Timecode::TimebaseIsDropFrame(timebase)) { m->addAction(view_timecode_view_dropframe_item_); + m->addAction(view_timecode_view_nondropframe_item_); } else { m->addAction(view_timecode_view_nondropframe_item_); } diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index 73d4f3a57..c2a5d8c8d 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -288,7 +288,7 @@ void NodeParamViewWidgetBridge::WidgetCallback() { // Widget is a RationalSlider RationalSlider* slider = static_cast(sender()); - ProcessSlider(slider, QVariant::fromValue(slider->GetValue()));; + ProcessSlider(slider, QVariant::fromValue(slider->GetValue())); break; } case NodeValue::kVec2: @@ -528,8 +528,6 @@ rational NodeParamViewWidgetBridge::GetCurrentTimeAsNodeTime() const void NodeParamViewWidgetBridge::SetTimebase(const rational& timebase) { - timebase_ = timebase; - if (input_.GetDataType() == NodeValue::kRational) { static_cast(widgets_.first())->SetTimebase(timebase); } diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h index 90102dd07..d985eb52d 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h @@ -76,8 +76,6 @@ private: rational time_; - rational timebase_; - NodeInputDragger dragger_; NodeParamViewScrollBlocker scroll_filter_; diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index 246dd91ed..c471c2ea2 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -303,10 +303,7 @@ void MainMenu::ViewMenuAboutToShow() // Parent is QMainWindow view_full_screen_item_->setChecked(parentWidget()->isFullScreen()); - // Ensure checked timecode display mode is correct - MenuShared::instance()->AboutToShowTimeRulerActions(); - - + // Make sure we're displaying the correct options for the timebase TimeBasedPanel* p = PanelManager::instance()->MostRecentlyFocused(); if (p) { if (p->timebase().denominator() != 0) { @@ -314,6 +311,9 @@ void MainMenu::ViewMenuAboutToShow() MenuShared::instance()->AddItemsForTimeRulerMenu(view_menu_, p->timebase()); } } + + // Ensure checked timecode display mode is correct + MenuShared::instance()->AboutToShowTimeRulerActions(); } void MainMenu::ToolsMenuAboutToShow() From a297dd0e533537fd3284753b4af97c05502dcd8c Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 12 Apr 2021 10:23:56 +0100 Subject: [PATCH 19/24] Add width hint to slider ladder for custom display widths --- app/widget/slider/sliderbase.cpp | 6 +++++- app/widget/slider/sliderladder.cpp | 24 ++++++++++-------------- app/widget/slider/sliderladder.h | 8 ++++++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 713ae15f3..6818b1696 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -278,7 +278,11 @@ void SliderBase::LabelPressed() case kFloat: case kRational: { - drag_ladder_ = new SliderLadder(drag_multiplier_, ladder_element_count_); + if (mode_ == kRational) { + drag_ladder_ = new SliderLadder(drag_multiplier_, ladder_element_count_, "00:00:00:00"); + } else { + drag_ladder_ = new SliderLadder(drag_multiplier_, ladder_element_count_, "00000000"); + } drag_ladder_->SetValue(ValueToString(value_)); drag_ladder_->show(); diff --git a/app/widget/slider/sliderladder.cpp b/app/widget/slider/sliderladder.cpp index 65e25876c..949a09ba9 100644 --- a/app/widget/slider/sliderladder.cpp +++ b/app/widget/slider/sliderladder.cpp @@ -37,8 +37,9 @@ namespace olive { -SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QWidget* parent) : - QFrame(parent, Qt::Popup) +SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QString width_hint, QWidget* parent) : + QFrame(parent, Qt::Popup), + width_hint_(width_hint) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setMargin(0); @@ -52,17 +53,17 @@ SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QWidget* } for (int i=nb_outer_values-1;i>=0;i--) { - elements_.append(new SliderLadderElement(qPow(10, i + 1) * drag_multiplier)); + elements_.append(new SliderLadderElement(qPow(10, i + 1) * drag_multiplier, width_hint_)); } // Create center entry - SliderLadderElement* start_element = new SliderLadderElement(drag_multiplier); + SliderLadderElement* start_element = new SliderLadderElement(drag_multiplier, width_hint_); active_element_ = elements_.size(); start_element->SetHighlighted(true); elements_.append(start_element); for (int i=0;isetAlignment(Qt::AlignCenter); - label_->setFixedWidth(QtUtils::QFontMetricsWidth(label_->fontMetrics(), QStringLiteral("0000000"))); + label_->setFixedWidth(QtUtils::QFontMetricsWidth(label_->fontMetrics(), width_hint)); layout->addWidget(label_); QPalette p = palette(); @@ -291,12 +293,6 @@ void SliderLadderElement::UpdateLabel() } else { label_->setText(value_); } - - // Increase the ladder width if displaying timecode - if (value_.contains(":")) { - label_->setFixedWidth(QtUtils::QFontMetricsWidth(label_->fontMetrics(), QStringLiteral("00:00:00:00"))); - } - } } diff --git a/app/widget/slider/sliderladder.h b/app/widget/slider/sliderladder.h index ca67c303d..e98150544 100644 --- a/app/widget/slider/sliderladder.h +++ b/app/widget/slider/sliderladder.h @@ -33,7 +33,7 @@ class SliderLadderElement : public QWidget { Q_OBJECT public: - SliderLadderElement(const double& multiplier, QWidget* parent = nullptr); + SliderLadderElement(const double& multiplier, QString width_hint, QWidget* parent = nullptr); void SetHighlighted(bool e); @@ -58,13 +58,15 @@ private: bool multiplier_visible_; + QString width_hint; + }; class SliderLadder : public QFrame { Q_OBJECT public: - SliderLadder(double drag_multiplier, int nb_outer_values, QWidget* parent = nullptr); + SliderLadder(double drag_multiplier, int nb_outer_values, QString width_hint, QWidget* parent = nullptr); virtual ~SliderLadder() override; @@ -92,6 +94,8 @@ private: QTimer drag_timer_; + QString width_hint_; + private slots: void TimerUpdate(); From 6a4f292ae29fbf2bc45df9fa76372c01cda394ba Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 12 Apr 2021 10:35:44 +0100 Subject: [PATCH 20/24] Use customContextMenu for changing the display type --- app/widget/slider/rationalslider.cpp | 1 + app/widget/slider/sliderbase.h | 2 ++ app/widget/slider/sliderlabel.cpp | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 87073187d..cebb193c1 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -32,6 +32,7 @@ RationalSlider::RationalSlider(QWidget *parent) : connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); connect(this, &SliderBase::changeRationalDisplayType, this, &RationalSlider::changeDisplayType); connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &RationalSlider::ChangeTimecodeDisplayType); + connect(SliderBase::label(), &SliderLabel::customContextMenuRequested, this, &RationalSlider::changeDisplayType); SetDisplayType(display_type_); diff --git a/app/widget/slider/sliderbase.h b/app/widget/slider/sliderbase.h index c28fc48a7..e3475efdf 100644 --- a/app/widget/slider/sliderbase.h +++ b/app/widget/slider/sliderbase.h @@ -85,6 +85,8 @@ protected: void UpdateLabel(const QVariant& v); + QLabel* label() { return label_; } + virtual double AdjustDragDistanceInternal(const double& start, const double& drag); virtual QString ValueToString(const QVariant &v) = 0; diff --git a/app/widget/slider/sliderlabel.cpp b/app/widget/slider/sliderlabel.cpp index 276a2bc75..fbccd3c53 100644 --- a/app/widget/slider/sliderlabel.cpp +++ b/app/widget/slider/sliderlabel.cpp @@ -47,6 +47,9 @@ SliderLabel::SliderLabel(QWidget *parent) : // Allow users to tab to this widget setFocusPolicy(Qt::TabFocus); + + // Add ccustom context menu + setContextMenuPolicy(Qt::CustomContextMenu); } void SliderLabel::mousePressEvent(QMouseEvent *e) @@ -57,8 +60,6 @@ void SliderLabel::mousePressEvent(QMouseEvent *e) } else { emit LabelPressed(); } - } else if (e->button() == Qt::RightButton) { - emit ChangeSliderType(); } } From 48f841db9c89febd4c8f54a2fdb2f6746340703f Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 12 Apr 2021 10:40:49 +0100 Subject: [PATCH 21/24] Remove unused signals and slots --- app/widget/slider/rationalslider.cpp | 1 - app/widget/slider/sliderbase.cpp | 8 -------- app/widget/slider/sliderbase.h | 4 ---- 3 files changed, 13 deletions(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index cebb193c1..bb5f093c1 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -30,7 +30,6 @@ RationalSlider::RationalSlider(QWidget *parent) : lock_display_type_(false) { connect(this, SIGNAL(ValueChanged(QVariant)), this, SLOT(ConvertValue(QVariant))); - connect(this, &SliderBase::changeRationalDisplayType, this, &RationalSlider::changeDisplayType); connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &RationalSlider::ChangeTimecodeDisplayType); connect(SliderBase::label(), &SliderLabel::customContextMenuRequested, this, &RationalSlider::changeDisplayType); diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 6818b1696..06853c5a9 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -55,7 +55,6 @@ SliderBase::SliderBase(Mode mode, QWidget *parent) : connect(label_, &SliderLabel::LabelPressed, this, &SliderBase::LabelPressed); connect(label_, &SliderLabel::focused, this, &SliderBase::ShowEditor); connect(label_, &SliderLabel::RequestReset, this, &SliderBase::ResetValue); - connect(label_, &SliderLabel::ChangeSliderType, this, &SliderBase::ChangeSliderType); connect(editor_, &FocusableLineEdit::Confirmed, this, &SliderBase::LineEditConfirmed); connect(editor_, &FocusableLineEdit::Cancelled, this, &SliderBase::LineEditCancelled); @@ -454,11 +453,4 @@ void SliderBase::RepositionLadder() } } -void SliderBase::ChangeSliderType() -{ - if (mode_ == kRational) { - emit changeRationalDisplayType(); - } -} - } diff --git a/app/widget/slider/sliderbase.h b/app/widget/slider/sliderbase.h index e3475efdf..c5ac8dd58 100644 --- a/app/widget/slider/sliderbase.h +++ b/app/widget/slider/sliderbase.h @@ -72,8 +72,6 @@ public: signals: void ValueChanged(QVariant v); - void changeRationalDisplayType(); - protected: const QVariant& Value() const; @@ -154,8 +152,6 @@ private slots: void ResetValue(); void RepositionLadder(); - - void ChangeSliderType(); }; } From 2820f45bcaf7761480aef4e1afc93429be23d1f4 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Mon, 12 Apr 2021 10:57:57 +0100 Subject: [PATCH 22/24] Fix shadowed variable --- app/widget/slider/sliderladder.cpp | 3 +-- app/widget/slider/sliderladder.h | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/widget/slider/sliderladder.cpp b/app/widget/slider/sliderladder.cpp index 949a09ba9..1e1145d36 100644 --- a/app/widget/slider/sliderladder.cpp +++ b/app/widget/slider/sliderladder.cpp @@ -231,8 +231,7 @@ SliderLadderElement::SliderLadderElement(const double &multiplier, QString width QWidget(parent), multiplier_(multiplier), highlighted_(false), - multiplier_visible_(true), - width_hint(width_hint) + multiplier_visible_(true) { QVBoxLayout* layout = new QVBoxLayout(this); diff --git a/app/widget/slider/sliderladder.h b/app/widget/slider/sliderladder.h index e98150544..6587400bd 100644 --- a/app/widget/slider/sliderladder.h +++ b/app/widget/slider/sliderladder.h @@ -58,8 +58,6 @@ private: bool multiplier_visible_; - QString width_hint; - }; class SliderLadder : public QFrame From 139adbdb31bc356c4f6856a0df3daabe544c98fe Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Wed, 14 Apr 2021 12:43:34 +0100 Subject: [PATCH 23/24] Cleanup for merge. --- app/panel/timebased/timebased.h | 1 + app/widget/menu/menushared.cpp | 2 +- app/widget/nodeparamview/nodeparamview.cpp | 1 - app/widget/nodeparamview/nodeparamviewitem.h | 2 ++ app/widget/nodeparamview/nodeparamviewwidgetbridge.h | 1 + app/widget/slider/rationalslider.cpp | 3 +-- app/widget/slider/rationalslider.h | 7 ++----- app/widget/slider/sliderlabel.cpp | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/panel/timebased/timebased.h b/app/panel/timebased/timebased.h index 7394bc280..984e2ba6e 100644 --- a/app/panel/timebased/timebased.h +++ b/app/panel/timebased/timebased.h @@ -41,6 +41,7 @@ public: rational GetTime(); + // Get the timebase of this panels widget const rational& timebase(); ViewerOutput *GetConnectedViewer() const diff --git a/app/widget/menu/menushared.cpp b/app/widget/menu/menushared.cpp index c61f22335..51260c9b0 100644 --- a/app/widget/menu/menushared.cpp +++ b/app/widget/menu/menushared.cpp @@ -163,7 +163,7 @@ void MenuShared::AddItemsForClipEditMenu(Menu *m) void MenuShared::AddItemsForTimeRulerMenu(Menu *m, const rational& timebase) { // If a menu is already created (such as the view menu) we need to remove the instance - // of dropfram or non-dropframe timecode that is already there to avoid double displays + // of dropframe or non-dropframe timecode that is already there to avoid double displays if (m->actions().contains(view_timecode_view_dropframe_item_)) { m->removeAction(view_timecode_view_dropframe_item_); diff --git a/app/widget/nodeparamview/nodeparamview.cpp b/app/widget/nodeparamview/nodeparamview.cpp index bbb9b7fb2..eb37ef242 100644 --- a/app/widget/nodeparamview/nodeparamview.cpp +++ b/app/widget/nodeparamview/nodeparamview.cpp @@ -133,7 +133,6 @@ NodeParamView::NodeParamView(QWidget *parent) : &QApplication::focusChanged, this, &NodeParamView::FocusChanged); - } void NodeParamView::SelectNodes(const QVector &nodes) diff --git a/app/widget/nodeparamview/nodeparamviewitem.h b/app/widget/nodeparamview/nodeparamviewitem.h index 813da7221..12899525f 100644 --- a/app/widget/nodeparamview/nodeparamviewitem.h +++ b/app/widget/nodeparamview/nodeparamviewitem.h @@ -85,6 +85,7 @@ public: int GetElementY(NodeInput c) const; + // Set the timebase of any timebased widgets contained here void SetTimebase(const rational& timebase); signals: @@ -169,6 +170,7 @@ public: void SetTime(const rational& time); + // Set the timebase of the NodeParamViewItemBody void SetTimebase(const rational& timebase); Node* GetNode() const; diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h index cba43e1a6..e12892702 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.h +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.h @@ -49,6 +49,7 @@ public: return widgets_; } + // Set the timebase of certain Timebased widgets void SetTimebase(const rational& timebase); signals: diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index bb5f093c1..d7f2299e7 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -1,6 +1,6 @@ /*** Olive - Non-Linear Video Editor - Copyright (C) 2020 Olive Team + Copyright (C) 2021 Olive Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -127,7 +127,6 @@ QString RationalSlider::ValueToString(const QVariant &v) case kTimestamp: return QString::number(Timecode::time_to_timestamp(time, timebase_)); case kRational: - // Might we want to call reduce() on r here? return v.value().toString(); case kFloat: { diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index 3f171f5c2..5a077c76c 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -1,6 +1,6 @@ /*** Olive - Non-Linear Video Editor - Copyright (C) 2020 Olive Team + Copyright (C) 2021 Olive Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -27,10 +27,8 @@ namespace olive { /** * @brief A olive::rational based slider * - * A slider that can display rationals as either timecode, a timestamp (frames), a rational (a/b) + * A slider that can display rationals as either timecode (drop or non-drop), a timestamp (frames), * or a float (seconds). - * - * Control clikcing the slider (see sliderlabel.h) changes thedisplay type */ class RationalSlider : public SliderBase { @@ -42,7 +40,6 @@ public: enum DisplayType { kTimecode, kTimestamp, - kRational, kFloat }; diff --git a/app/widget/slider/sliderlabel.cpp b/app/widget/slider/sliderlabel.cpp index fbccd3c53..3aa37ecca 100644 --- a/app/widget/slider/sliderlabel.cpp +++ b/app/widget/slider/sliderlabel.cpp @@ -57,7 +57,7 @@ void SliderLabel::mousePressEvent(QMouseEvent *e) if (e->button() == Qt::LeftButton) { if (e->modifiers() & Qt::AltModifier) { emit RequestReset(); - } else { + } else { emit LabelPressed(); } } From 579a409078b13dc37458d151be9803672bbe6fa5 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Wed, 14 Apr 2021 13:24:18 +0100 Subject: [PATCH 24/24] Properly remove a/b display type --- app/widget/slider/rationalslider.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index d7f2299e7..d9b659d37 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -95,7 +95,6 @@ void RationalSlider::SetDisplayType(const RationalSlider::DisplayType &type) switch (display_type_) { case kTimecode: - case kRational: ClearFormat(); break; case kTimestamp: @@ -126,8 +125,6 @@ QString RationalSlider::ValueToString(const QVariant &v) return Timecode::time_to_timecode(v.value(), timebase_, Core::instance()->GetTimecodeDisplay()); case kTimestamp: return QString::number(Timecode::time_to_timestamp(time, timebase_)); - case kRational: - return v.value().toString(); case kFloat: { QString s = QString::number(time, 'f', decimal_places_); @@ -158,12 +155,6 @@ QVariant RationalSlider::StringToValue(const QString &s, bool *ok) case kTimestamp: r = rational(s.toInt(ok), timebase_.denominator()); break; - case kRational: - r = rational::fromString(s); - if (!r.isNull()) { - *ok = true; - } - break; case kFloat: r = rational::fromDouble(s.toDouble(ok)); if (!r.isNull()) {