change: change code style to Linux style except indent.
This commit is contained in:
@@ -20,44 +20,44 @@
|
||||
|
||||
#include "decimalsliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super NumericSliderBase
|
||||
|
||||
DecimalSliderBase::DecimalSliderBase(QWidget *parent) :
|
||||
super(parent),
|
||||
decimal_places_(2),
|
||||
autotrim_decimal_places_(false)
|
||||
DecimalSliderBase::DecimalSliderBase(QWidget *parent)
|
||||
: super(parent)
|
||||
, decimal_places_(2)
|
||||
, autotrim_decimal_places_(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DecimalSliderBase::SetAutoTrimDecimalPlaces(bool e)
|
||||
{
|
||||
autotrim_decimal_places_ = e;
|
||||
autotrim_decimal_places_ = e;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
QString DecimalSliderBase::FloatToString(double val, int decimal_places, bool autotrim_decimal_places)
|
||||
QString DecimalSliderBase::FloatToString(double val, int decimal_places,
|
||||
bool autotrim_decimal_places)
|
||||
{
|
||||
QString s = QString::number(val, 'f', decimal_places);
|
||||
QString s = QString::number(val, 'f', decimal_places);
|
||||
|
||||
if (autotrim_decimal_places) {
|
||||
while (s.endsWith('0')
|
||||
&& s.at(s.size() - 2).isDigit()) {
|
||||
s = s.left(s.size() - 1);
|
||||
}
|
||||
}
|
||||
if (autotrim_decimal_places) {
|
||||
while (s.endsWith('0') && s.at(s.size() - 2).isDigit()) {
|
||||
s = s.left(s.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
|
||||
void DecimalSliderBase::SetDecimalPlaces(int i)
|
||||
{
|
||||
decimal_places_ = i;
|
||||
decimal_places_ = i;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,26 +23,32 @@
|
||||
|
||||
#include "numericsliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class DecimalSliderBase : public NumericSliderBase
|
||||
namespace olive
|
||||
{
|
||||
|
||||
class DecimalSliderBase : public NumericSliderBase {
|
||||
public:
|
||||
DecimalSliderBase(QWidget* parent = nullptr);
|
||||
DecimalSliderBase(QWidget *parent = nullptr);
|
||||
|
||||
int GetDecimalPlaces() const { return decimal_places_; }
|
||||
void SetDecimalPlaces(int i);
|
||||
int GetDecimalPlaces() const
|
||||
{
|
||||
return decimal_places_;
|
||||
}
|
||||
void SetDecimalPlaces(int i);
|
||||
|
||||
bool GetAutoTrimDecimalPlaces() const { return autotrim_decimal_places_; };
|
||||
void SetAutoTrimDecimalPlaces(bool e);
|
||||
bool GetAutoTrimDecimalPlaces() const
|
||||
{
|
||||
return autotrim_decimal_places_;
|
||||
};
|
||||
void SetAutoTrimDecimalPlaces(bool e);
|
||||
|
||||
static QString FloatToString(double val, int decimal_places, bool autotrim_decimal_places);
|
||||
static QString FloatToString(double val, int decimal_places,
|
||||
bool autotrim_decimal_places);
|
||||
|
||||
private:
|
||||
int decimal_places_;
|
||||
|
||||
bool autotrim_decimal_places_;
|
||||
int decimal_places_;
|
||||
|
||||
bool autotrim_decimal_places_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,182 +24,199 @@
|
||||
#include "config/config.h"
|
||||
#include "core.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
bool NumericSliderBase::effects_slider_is_being_dragged_ = false;
|
||||
|
||||
NumericSliderBase::NumericSliderBase(QWidget *parent) :
|
||||
SliderBase(parent),
|
||||
drag_ladder_(nullptr),
|
||||
ladder_element_count_(0),
|
||||
dragged_(false),
|
||||
has_min_(false),
|
||||
has_max_(false),
|
||||
dragged_diff_(0),
|
||||
drag_multiplier_(1.0),
|
||||
setting_drag_value_(false)
|
||||
NumericSliderBase::NumericSliderBase(QWidget *parent)
|
||||
: SliderBase(parent)
|
||||
, drag_ladder_(nullptr)
|
||||
, ladder_element_count_(0)
|
||||
, dragged_(false)
|
||||
, has_min_(false)
|
||||
, has_max_(false)
|
||||
, dragged_diff_(0)
|
||||
, drag_multiplier_(1.0)
|
||||
, setting_drag_value_(false)
|
||||
{
|
||||
// Numeric sliders are draggable, so we have a cursor that indicates that
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
// Numeric sliders are draggable, so we have a cursor that indicates that
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
|
||||
connect(label(), &SliderLabel::LabelPressed, this, &NumericSliderBase::LabelPressed);
|
||||
connect(label(), &SliderLabel::LabelPressed, this,
|
||||
&NumericSliderBase::LabelPressed);
|
||||
}
|
||||
|
||||
void NumericSliderBase::SetDragMultiplier(const double &d)
|
||||
{
|
||||
drag_multiplier_ = d;
|
||||
drag_multiplier_ = d;
|
||||
}
|
||||
|
||||
void NumericSliderBase::LabelPressed()
|
||||
{
|
||||
drag_ladder_ = new SliderLadder(drag_multiplier_, ladder_element_count_, GetFormattedValueToString(99999999));
|
||||
connect(drag_ladder_, &SliderLadder::DraggedByValue, this, &NumericSliderBase::LadderDragged);
|
||||
connect(drag_ladder_, &SliderLadder::Released, this, &NumericSliderBase::LadderReleased);
|
||||
drag_ladder_ = new SliderLadder(drag_multiplier_, ladder_element_count_,
|
||||
GetFormattedValueToString(99999999));
|
||||
connect(drag_ladder_, &SliderLadder::DraggedByValue, this,
|
||||
&NumericSliderBase::LadderDragged);
|
||||
connect(drag_ladder_, &SliderLadder::Released, this,
|
||||
&NumericSliderBase::LadderReleased);
|
||||
|
||||
drag_ladder_->SetValue(GetFormattedValueToString());
|
||||
drag_ladder_->resize(drag_ladder_->sizeHint());
|
||||
RepositionLadder();
|
||||
drag_ladder_->show();
|
||||
drag_ladder_->SetValue(GetFormattedValueToString());
|
||||
drag_ladder_->resize(drag_ladder_->sizeHint());
|
||||
RepositionLadder();
|
||||
drag_ladder_->show();
|
||||
|
||||
drag_start_value_ = GetValueInternal();
|
||||
drag_start_value_ = GetValueInternal();
|
||||
}
|
||||
|
||||
void NumericSliderBase::LadderDragged(int value, double multiplier)
|
||||
{
|
||||
dragged_ = true;
|
||||
dragged_ = true;
|
||||
|
||||
dragged_diff_ += value * multiplier;
|
||||
dragged_diff_ += value * multiplier;
|
||||
|
||||
// Store current value to try and prevent any unnecessary signalling if the value doesn't change
|
||||
QVariant pre_set_value = GetValueInternal();
|
||||
// Store current value to try and prevent any unnecessary signalling if the value doesn't change
|
||||
QVariant pre_set_value = GetValueInternal();
|
||||
|
||||
setting_drag_value_ = true;
|
||||
SetValueInternal(AdjustDragDistanceInternal(drag_start_value_, dragged_diff_));
|
||||
setting_drag_value_ = false;
|
||||
setting_drag_value_ = true;
|
||||
SetValueInternal(
|
||||
AdjustDragDistanceInternal(drag_start_value_, dragged_diff_));
|
||||
setting_drag_value_ = false;
|
||||
|
||||
if (GetValueInternal() != pre_set_value) {
|
||||
// We retrieve the value instead of storing it ourselves because SetValueInternal may do extra
|
||||
// processing (such as clamping).
|
||||
drag_ladder_->SetValue(GetFormattedValueToString());
|
||||
if (GetValueInternal() != pre_set_value) {
|
||||
// We retrieve the value instead of storing it ourselves because SetValueInternal may do extra
|
||||
// processing (such as clamping).
|
||||
drag_ladder_->SetValue(GetFormattedValueToString());
|
||||
|
||||
if (!UsingLadders()) {
|
||||
RepositionLadder();
|
||||
}
|
||||
if (!UsingLadders()) {
|
||||
RepositionLadder();
|
||||
}
|
||||
|
||||
ValueSignalEvent(GetValueInternal());
|
||||
}
|
||||
ValueSignalEvent(GetValueInternal());
|
||||
}
|
||||
}
|
||||
|
||||
void NumericSliderBase::LadderReleased()
|
||||
{
|
||||
drag_ladder_->deleteLater();
|
||||
drag_ladder_ = nullptr;
|
||||
dragged_diff_ = 0;
|
||||
drag_ladder_->deleteLater();
|
||||
drag_ladder_ = nullptr;
|
||||
dragged_diff_ = 0;
|
||||
|
||||
if (dragged_) {
|
||||
// This was a drag, send another value changed event
|
||||
ValueSignalEvent(GetValueInternal());
|
||||
if (dragged_) {
|
||||
// This was a drag, send another value changed event
|
||||
ValueSignalEvent(GetValueInternal());
|
||||
|
||||
dragged_ = false;
|
||||
} else {
|
||||
ShowEditor();
|
||||
}
|
||||
dragged_ = false;
|
||||
} else {
|
||||
ShowEditor();
|
||||
}
|
||||
}
|
||||
|
||||
void NumericSliderBase::RepositionLadder()
|
||||
{
|
||||
if (drag_ladder_) {
|
||||
if (UsingLadders()) {
|
||||
drag_ladder_->move(QCursor::pos() - QPoint(drag_ladder_->width()/2, drag_ladder_->height()/2));
|
||||
} else {
|
||||
QPoint label_global_pos = label()->mapToGlobal(label()->pos());
|
||||
int text_width = QtUtils::QFontMetricsWidth(label()->fontMetrics(), label()->text());
|
||||
if (drag_ladder_) {
|
||||
if (UsingLadders()) {
|
||||
drag_ladder_->move(
|
||||
QCursor::pos() -
|
||||
QPoint(drag_ladder_->width() / 2, drag_ladder_->height() / 2));
|
||||
} else {
|
||||
QPoint label_global_pos = label()->mapToGlobal(label()->pos());
|
||||
int text_width = QtUtils::QFontMetricsWidth(label()->fontMetrics(),
|
||||
label()->text());
|
||||
|
||||
if (label()->alignment() & Qt::AlignRight) {
|
||||
label_global_pos.setX(label_global_pos.x() + label()->width() - text_width);
|
||||
} else if (label()->alignment() & Qt::AlignHCenter) {
|
||||
label_global_pos.setX(label_global_pos.x() + label()->width()/2 - text_width/2);
|
||||
}
|
||||
if (label()->alignment() & Qt::AlignRight) {
|
||||
label_global_pos.setX(label_global_pos.x() + label()->width() -
|
||||
text_width);
|
||||
} else if (label()->alignment() & Qt::AlignHCenter) {
|
||||
label_global_pos.setX(label_global_pos.x() +
|
||||
label()->width() / 2 - text_width / 2);
|
||||
}
|
||||
|
||||
int ladder_x = label_global_pos.x() + text_width / 2 - drag_ladder_->width() / 2;
|
||||
int ladder_y = label_global_pos.y() + label()->height() / 2 - drag_ladder_->height() / 2;
|
||||
int ladder_x = label_global_pos.x() + text_width / 2 -
|
||||
drag_ladder_->width() / 2;
|
||||
int ladder_y = label_global_pos.y() + label()->height() / 2 -
|
||||
drag_ladder_->height() / 2;
|
||||
|
||||
drag_ladder_->move(ladder_x, ladder_y);
|
||||
}
|
||||
drag_ladder_->move(ladder_x, ladder_y);
|
||||
}
|
||||
|
||||
drag_ladder_->StartListeningToMouseInput();
|
||||
}
|
||||
drag_ladder_->StartListeningToMouseInput();
|
||||
}
|
||||
}
|
||||
|
||||
bool NumericSliderBase::IsDragging() const
|
||||
{
|
||||
return drag_ladder_;
|
||||
return drag_ladder_;
|
||||
}
|
||||
|
||||
bool NumericSliderBase::UsingLadders() const
|
||||
{
|
||||
return ladder_element_count_ > 0 && OLIVE_CONFIG("UseSliderLadders").toBool();
|
||||
return ladder_element_count_ > 0 &&
|
||||
OLIVE_CONFIG("UseSliderLadders").toBool();
|
||||
}
|
||||
|
||||
QVariant NumericSliderBase::AdjustValue(const QVariant &value) const
|
||||
{
|
||||
// Clamps between min/max
|
||||
if (has_min_ && ValueLessThan(value, min_value_)) {
|
||||
return min_value_;
|
||||
} else if (has_max_ && ValueGreaterThan(value, max_value_)) {
|
||||
return max_value_;
|
||||
}
|
||||
// Clamps between min/max
|
||||
if (has_min_ && ValueLessThan(value, min_value_)) {
|
||||
return min_value_;
|
||||
} else if (has_max_ && ValueGreaterThan(value, max_value_)) {
|
||||
return max_value_;
|
||||
}
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
void NumericSliderBase::SetOffset(const QVariant &v)
|
||||
{
|
||||
offset_ = v;
|
||||
offset_ = v;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
QVariant NumericSliderBase::AdjustDragDistanceInternal(const QVariant &start, const double &drag) const
|
||||
QVariant NumericSliderBase::AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const
|
||||
{
|
||||
return start.toDouble() + drag;
|
||||
return start.toDouble() + drag;
|
||||
}
|
||||
|
||||
void NumericSliderBase::SetMinimumInternal(const QVariant &v)
|
||||
{
|
||||
min_value_ = v;
|
||||
has_min_ = true;
|
||||
min_value_ = v;
|
||||
has_min_ = true;
|
||||
|
||||
// Limit value by this new minimum value
|
||||
if (ValueLessThan(GetValueInternal(), min_value_)) {
|
||||
SetValueInternal(min_value_);
|
||||
}
|
||||
// Limit value by this new minimum value
|
||||
if (ValueLessThan(GetValueInternal(), min_value_)) {
|
||||
SetValueInternal(min_value_);
|
||||
}
|
||||
}
|
||||
|
||||
void NumericSliderBase::SetMaximumInternal(const QVariant &v)
|
||||
{
|
||||
max_value_ = v;
|
||||
has_max_ = true;
|
||||
max_value_ = v;
|
||||
has_max_ = true;
|
||||
|
||||
// Limit value by this new maximum value
|
||||
if (ValueGreaterThan(GetValueInternal(), max_value_)) {
|
||||
SetValueInternal(max_value_);
|
||||
}
|
||||
// Limit value by this new maximum value
|
||||
if (ValueGreaterThan(GetValueInternal(), max_value_)) {
|
||||
SetValueInternal(max_value_);
|
||||
}
|
||||
}
|
||||
|
||||
bool NumericSliderBase::ValueGreaterThan(const QVariant &lhs, const QVariant &rhs) const
|
||||
bool NumericSliderBase::ValueGreaterThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const
|
||||
{
|
||||
return lhs.toDouble() > rhs.toDouble();
|
||||
return lhs.toDouble() > rhs.toDouble();
|
||||
}
|
||||
|
||||
bool NumericSliderBase::ValueLessThan(const QVariant &lhs, const QVariant &rhs) const
|
||||
bool NumericSliderBase::ValueLessThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const
|
||||
{
|
||||
return lhs.toDouble() < rhs.toDouble();
|
||||
return lhs.toDouble() < rhs.toDouble();
|
||||
}
|
||||
|
||||
bool NumericSliderBase::CanSetValue() const
|
||||
{
|
||||
return !IsDragging() || setting_drag_value_;
|
||||
return !IsDragging() || setting_drag_value_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,84 +23,85 @@
|
||||
|
||||
#include "sliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class NumericSliderBase : public SliderBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class NumericSliderBase : public SliderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
NumericSliderBase(QWidget *parent = nullptr);
|
||||
NumericSliderBase(QWidget *parent = nullptr);
|
||||
|
||||
void SetLadderElementCount(int b)
|
||||
{
|
||||
ladder_element_count_ = b;
|
||||
}
|
||||
void SetLadderElementCount(int b)
|
||||
{
|
||||
ladder_element_count_ = b;
|
||||
}
|
||||
|
||||
void SetDragMultiplier(const double& d);
|
||||
void SetDragMultiplier(const double &d);
|
||||
|
||||
void SetOffset(const QVariant& v);
|
||||
void SetOffset(const QVariant &v);
|
||||
|
||||
bool IsDragging() const;
|
||||
bool IsDragging() const;
|
||||
|
||||
protected:
|
||||
const QVariant& GetOffset() const
|
||||
{
|
||||
return offset_;
|
||||
}
|
||||
const QVariant &GetOffset() const
|
||||
{
|
||||
return offset_;
|
||||
}
|
||||
|
||||
virtual QVariant AdjustDragDistanceInternal(const QVariant &start, const double &drag) const;
|
||||
virtual QVariant AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const;
|
||||
|
||||
void SetMinimumInternal(const QVariant& v);
|
||||
void SetMinimumInternal(const QVariant &v);
|
||||
|
||||
void SetMaximumInternal(const QVariant& v);
|
||||
void SetMaximumInternal(const QVariant &v);
|
||||
|
||||
virtual bool ValueGreaterThan(const QVariant& lhs, const QVariant& rhs) const;
|
||||
virtual bool ValueGreaterThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const;
|
||||
|
||||
virtual bool ValueLessThan(const QVariant& lhs, const QVariant& rhs) const;
|
||||
virtual bool ValueLessThan(const QVariant &lhs, const QVariant &rhs) const;
|
||||
|
||||
virtual bool CanSetValue() const override;
|
||||
virtual bool CanSetValue() const override;
|
||||
|
||||
private:
|
||||
bool UsingLadders() const;
|
||||
bool UsingLadders() const;
|
||||
|
||||
virtual QVariant AdjustValue(const QVariant& value) const override;
|
||||
virtual QVariant AdjustValue(const QVariant &value) const override;
|
||||
|
||||
SliderLadder* drag_ladder_;
|
||||
SliderLadder *drag_ladder_;
|
||||
|
||||
int ladder_element_count_;
|
||||
int ladder_element_count_;
|
||||
|
||||
bool dragged_;
|
||||
bool dragged_;
|
||||
|
||||
bool has_min_;
|
||||
QVariant min_value_;
|
||||
bool has_min_;
|
||||
QVariant min_value_;
|
||||
|
||||
bool has_max_;
|
||||
QVariant max_value_;
|
||||
bool has_max_;
|
||||
QVariant max_value_;
|
||||
|
||||
double dragged_diff_;
|
||||
double dragged_diff_;
|
||||
|
||||
QVariant drag_start_value_;
|
||||
QVariant drag_start_value_;
|
||||
|
||||
QVariant offset_;
|
||||
QVariant offset_;
|
||||
|
||||
double drag_multiplier_;
|
||||
double drag_multiplier_;
|
||||
|
||||
bool setting_drag_value_;
|
||||
bool setting_drag_value_;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief An effects slider somewhere is being dragged
|
||||
*/
|
||||
static bool effects_slider_is_being_dragged_;
|
||||
static bool effects_slider_is_being_dragged_;
|
||||
|
||||
private slots:
|
||||
void LabelPressed();
|
||||
void LabelPressed();
|
||||
|
||||
void RepositionLadder();
|
||||
void RepositionLadder();
|
||||
|
||||
void LadderDragged(int value, double multiplier);
|
||||
|
||||
void LadderReleased();
|
||||
void LadderDragged(int value, double multiplier);
|
||||
|
||||
void LadderReleased();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -28,226 +28,230 @@
|
||||
#include "core.h"
|
||||
#include "window/mainwindow/mainwindow.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super QStackedWidget
|
||||
|
||||
SliderBase::SliderBase(QWidget *parent) :
|
||||
super(parent),
|
||||
tristate_(false),
|
||||
format_plural_(false)
|
||||
SliderBase::SliderBase(QWidget *parent)
|
||||
: super(parent)
|
||||
, tristate_(false)
|
||||
, format_plural_(false)
|
||||
{
|
||||
// Standard (non-numeric) sliders are not draggable, so we indicate as such
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
// Standard (non-numeric) sliders are not draggable, so we indicate as such
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
|
||||
label_ = new SliderLabel(this);
|
||||
addWidget(label_);
|
||||
label_ = new SliderLabel(this);
|
||||
addWidget(label_);
|
||||
|
||||
editor_ = new FocusableLineEdit(this);
|
||||
addWidget(editor_);
|
||||
editor_ = new FocusableLineEdit(this);
|
||||
addWidget(editor_);
|
||||
|
||||
connect(label_, &SliderLabel::focused, this, &SliderBase::ShowEditor);
|
||||
connect(label_, &SliderLabel::RequestReset, this, &SliderBase::ResetValue);
|
||||
connect(editor_, &FocusableLineEdit::Confirmed, this, &SliderBase::LineEditConfirmed);
|
||||
connect(editor_, &FocusableLineEdit::Cancelled, this, &SliderBase::LineEditCancelled);
|
||||
connect(label_, &SliderLabel::focused, this, &SliderBase::ShowEditor);
|
||||
connect(label_, &SliderLabel::RequestReset, this, &SliderBase::ResetValue);
|
||||
connect(editor_, &FocusableLineEdit::Confirmed, this,
|
||||
&SliderBase::LineEditConfirmed);
|
||||
connect(editor_, &FocusableLineEdit::Cancelled, this,
|
||||
&SliderBase::LineEditCancelled);
|
||||
}
|
||||
|
||||
void SliderBase::SetAlignment(Qt::Alignment alignment)
|
||||
{
|
||||
label_->setAlignment(alignment);
|
||||
editor_->setAlignment(alignment);
|
||||
label_->setAlignment(alignment);
|
||||
editor_->setAlignment(alignment);
|
||||
}
|
||||
|
||||
bool SliderBase::IsTristate() const
|
||||
{
|
||||
return tristate_;
|
||||
return tristate_;
|
||||
}
|
||||
|
||||
void SliderBase::SetTristate()
|
||||
{
|
||||
tristate_ = true;
|
||||
UpdateLabel();
|
||||
tristate_ = true;
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
const QVariant &SliderBase::GetValueInternal() const
|
||||
{
|
||||
return value_;
|
||||
return value_;
|
||||
}
|
||||
|
||||
void SliderBase::SetValueInternal(const QVariant &v)
|
||||
{
|
||||
if (!CanSetValue()) {
|
||||
return;
|
||||
}
|
||||
if (!CanSetValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
value_ = AdjustValue(v);
|
||||
value_ = AdjustValue(v);
|
||||
|
||||
// Disable tristate
|
||||
tristate_ = false;
|
||||
// Disable tristate
|
||||
tristate_ = false;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SliderBase::SetDefaultValue(const QVariant &v)
|
||||
{
|
||||
default_value_ = v;
|
||||
default_value_ = v;
|
||||
}
|
||||
|
||||
void SliderBase::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
UpdateLabel();
|
||||
}
|
||||
super::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
UpdateLabel();
|
||||
}
|
||||
super::changeEvent(e);
|
||||
}
|
||||
|
||||
bool SliderBase::GetLabelSubstitution(const QVariant &v, QString *out) const
|
||||
{
|
||||
for (auto it=label_substitutions_.constBegin(); it!=label_substitutions_.constEnd(); it++) {
|
||||
if (it->first == v) {
|
||||
*out = it->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (auto it = label_substitutions_.constBegin();
|
||||
it != label_substitutions_.constEnd(); it++) {
|
||||
if (it->first == v) {
|
||||
*out = it->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void SliderBase::UpdateLabel()
|
||||
{
|
||||
QString s;
|
||||
QString s;
|
||||
|
||||
if (tristate_) {
|
||||
s = tr("---");
|
||||
} else if (GetLabelSubstitution(GetValueInternal(), &s)) {
|
||||
// String will already be set, just pass through
|
||||
} else {
|
||||
s = GetFormattedValueToString();
|
||||
}
|
||||
if (tristate_) {
|
||||
s = tr("---");
|
||||
} else if (GetLabelSubstitution(GetValueInternal(), &s)) {
|
||||
// String will already be set, just pass through
|
||||
} else {
|
||||
s = GetFormattedValueToString();
|
||||
}
|
||||
|
||||
label_->setText(s);
|
||||
label_->setText(s);
|
||||
}
|
||||
|
||||
QVariant SliderBase::AdjustValue(const QVariant &value) const
|
||||
{
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
bool SliderBase::CanSetValue() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SliderBase::ValueSignalEvent(const QVariant &value)
|
||||
{
|
||||
Q_UNUSED(value)
|
||||
Q_UNUSED(value)
|
||||
}
|
||||
|
||||
void SliderBase::ShowEditor()
|
||||
{
|
||||
// This was a simple click
|
||||
// Load label's text into editor
|
||||
editor_->setText(ValueToString(value_));
|
||||
// This was a simple click
|
||||
// Load label's text into editor
|
||||
editor_->setText(ValueToString(value_));
|
||||
|
||||
// Show editor
|
||||
setCurrentWidget(editor_);
|
||||
// Show editor
|
||||
setCurrentWidget(editor_);
|
||||
|
||||
// Select all text in the editor
|
||||
editor_->setFocus();
|
||||
editor_->selectAll();
|
||||
// Select all text in the editor
|
||||
editor_->setFocus();
|
||||
editor_->selectAll();
|
||||
}
|
||||
|
||||
void SliderBase::LineEditConfirmed()
|
||||
{
|
||||
bool is_valid = true;
|
||||
QVariant test_val = StringToValue(editor_->text(), &is_valid);
|
||||
bool is_valid = true;
|
||||
QVariant test_val = StringToValue(editor_->text(), &is_valid);
|
||||
|
||||
// Ensure editor doesn't signal that the focus is lost
|
||||
editor_->blockSignals(true);
|
||||
label_->blockSignals(true);
|
||||
// Ensure editor doesn't signal that the focus is lost
|
||||
editor_->blockSignals(true);
|
||||
label_->blockSignals(true);
|
||||
|
||||
if (is_valid) {
|
||||
SetValueInternal(test_val);
|
||||
if (is_valid) {
|
||||
SetValueInternal(test_val);
|
||||
|
||||
setCurrentWidget(label_);
|
||||
setCurrentWidget(label_);
|
||||
|
||||
ValueSignalEvent(value_);
|
||||
} else {
|
||||
QMessageBox::critical(this,
|
||||
tr("Invalid Value"),
|
||||
tr("The entered value is not valid for this field."),
|
||||
QMessageBox::Ok);
|
||||
ValueSignalEvent(value_);
|
||||
} else {
|
||||
QMessageBox::critical(
|
||||
this, tr("Invalid Value"),
|
||||
tr("The entered value is not valid for this field."),
|
||||
QMessageBox::Ok);
|
||||
|
||||
// Refocus editor
|
||||
editor_->setFocus();
|
||||
}
|
||||
// Refocus editor
|
||||
editor_->setFocus();
|
||||
}
|
||||
|
||||
editor_->blockSignals(false);
|
||||
label_->blockSignals(false);
|
||||
editor_->blockSignals(false);
|
||||
label_->blockSignals(false);
|
||||
}
|
||||
|
||||
void SliderBase::LineEditCancelled()
|
||||
{
|
||||
// Ensure editor doesn't signal that the focus is lost
|
||||
editor_->blockSignals(true);
|
||||
label_->blockSignals(true);
|
||||
// Ensure editor doesn't signal that the focus is lost
|
||||
editor_->blockSignals(true);
|
||||
label_->blockSignals(true);
|
||||
|
||||
// Set widget back to label
|
||||
setCurrentWidget(label_);
|
||||
// Set widget back to label
|
||||
setCurrentWidget(label_);
|
||||
|
||||
editor_->blockSignals(false);
|
||||
label_->blockSignals(false);
|
||||
editor_->blockSignals(false);
|
||||
label_->blockSignals(false);
|
||||
}
|
||||
|
||||
void SliderBase::ResetValue()
|
||||
{
|
||||
if (default_value_.isValid()) {
|
||||
SetValueInternal(default_value_);
|
||||
ValueSignalEvent(value_);
|
||||
}
|
||||
if (default_value_.isValid()) {
|
||||
SetValueInternal(default_value_);
|
||||
ValueSignalEvent(value_);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderBase::SetFormat(const QString &s, const bool plural)
|
||||
{
|
||||
custom_format_ = s;
|
||||
format_plural_ = plural;
|
||||
UpdateLabel();
|
||||
custom_format_ = s;
|
||||
format_plural_ = plural;
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SliderBase::ClearFormat()
|
||||
{
|
||||
custom_format_.clear();
|
||||
UpdateLabel();
|
||||
custom_format_.clear();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
bool SliderBase::IsFormatPlural() const
|
||||
{
|
||||
return format_plural_;
|
||||
return format_plural_;
|
||||
}
|
||||
|
||||
QString SliderBase::GetFormat() const
|
||||
{
|
||||
if (custom_format_.isEmpty()) {
|
||||
return QStringLiteral("%1");
|
||||
} else {
|
||||
return custom_format_;
|
||||
}
|
||||
if (custom_format_.isEmpty()) {
|
||||
return QStringLiteral("%1");
|
||||
} else {
|
||||
return custom_format_;
|
||||
}
|
||||
}
|
||||
|
||||
QString SliderBase::GetFormattedValueToString() const
|
||||
{
|
||||
return GetFormattedValueToString(GetValueInternal());
|
||||
return GetFormattedValueToString(GetValueInternal());
|
||||
}
|
||||
|
||||
QString SliderBase::GetFormattedValueToString(const QVariant &v) const
|
||||
{
|
||||
if (format_plural_) {
|
||||
return tr(GetFormat().toUtf8().constData(), nullptr, v.toInt());
|
||||
} else {
|
||||
return GetFormat().arg(ValueToString(v));
|
||||
}
|
||||
if (format_plural_) {
|
||||
return tr(GetFormat().toUtf8().constData(), nullptr, v.toInt());
|
||||
} else {
|
||||
return GetFormat().arg(ValueToString(v));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,93 +27,95 @@
|
||||
#include "sliderladder.h"
|
||||
#include "widget/focusablelineedit/focusablelineedit.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SliderBase : public QStackedWidget
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class SliderBase : public QStackedWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SliderBase(QWidget* parent = nullptr);
|
||||
SliderBase(QWidget *parent = nullptr);
|
||||
|
||||
void SetAlignment(Qt::Alignment alignment);
|
||||
void SetAlignment(Qt::Alignment alignment);
|
||||
|
||||
bool IsTristate() const;
|
||||
void SetTristate();
|
||||
bool IsTristate() const;
|
||||
void SetTristate();
|
||||
|
||||
void SetFormat(const QString& s, const bool plural = false);
|
||||
void ClearFormat();
|
||||
void SetFormat(const QString &s, const bool plural = false);
|
||||
void ClearFormat();
|
||||
|
||||
bool IsFormatPlural() const;
|
||||
bool IsFormatPlural() const;
|
||||
|
||||
void SetDefaultValue(const QVariant& v);
|
||||
void SetDefaultValue(const QVariant &v);
|
||||
|
||||
QString GetFormattedValueToString(const QVariant& v) const;
|
||||
QString GetFormattedValueToString(const QVariant &v) const;
|
||||
|
||||
void InsertLabelSubstitution(const QVariant &value, const QString &label)
|
||||
{
|
||||
label_substitutions_.append({value, label});
|
||||
UpdateLabel();
|
||||
}
|
||||
void InsertLabelSubstitution(const QVariant &value, const QString &label)
|
||||
{
|
||||
label_substitutions_.append({ value, label });
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SetColor(const QColor &c)
|
||||
{
|
||||
label_->SetColor(c);
|
||||
}
|
||||
void SetColor(const QColor &c)
|
||||
{
|
||||
label_->SetColor(c);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void ShowEditor();
|
||||
void ShowEditor();
|
||||
|
||||
protected slots:
|
||||
void UpdateLabel();
|
||||
void UpdateLabel();
|
||||
|
||||
protected:
|
||||
const QVariant& GetValueInternal() const;
|
||||
const QVariant &GetValueInternal() const;
|
||||
|
||||
void SetValueInternal(const QVariant& v);
|
||||
void SetValueInternal(const QVariant &v);
|
||||
|
||||
QString GetFormat() const;
|
||||
QString GetFormat() const;
|
||||
|
||||
QString GetFormattedValueToString() const;
|
||||
QString GetFormattedValueToString() const;
|
||||
|
||||
SliderLabel* label() { return label_; }
|
||||
SliderLabel *label()
|
||||
{
|
||||
return label_;
|
||||
}
|
||||
|
||||
virtual QString ValueToString(const QVariant &v) const = 0;
|
||||
virtual QString ValueToString(const QVariant &v) const = 0;
|
||||
|
||||
virtual QVariant StringToValue(const QString& s, bool* ok) const = 0;
|
||||
virtual QVariant StringToValue(const QString &s, bool *ok) const = 0;
|
||||
|
||||
virtual QVariant AdjustValue(const QVariant& value) const;
|
||||
virtual QVariant AdjustValue(const QVariant &value) const;
|
||||
|
||||
virtual bool CanSetValue() const;
|
||||
virtual bool CanSetValue() const;
|
||||
|
||||
virtual void ValueSignalEvent(const QVariant& value) = 0;
|
||||
virtual void ValueSignalEvent(const QVariant &value) = 0;
|
||||
|
||||
virtual void changeEvent(QEvent* e) override;
|
||||
virtual void changeEvent(QEvent *e) override;
|
||||
|
||||
private:
|
||||
bool GetLabelSubstitution(const QVariant &v, QString *out) const;
|
||||
bool GetLabelSubstitution(const QVariant &v, QString *out) const;
|
||||
|
||||
SliderLabel* label_;
|
||||
SliderLabel *label_;
|
||||
|
||||
FocusableLineEdit* editor_;
|
||||
FocusableLineEdit *editor_;
|
||||
|
||||
QVariant value_;
|
||||
QVariant default_value_;
|
||||
QVariant value_;
|
||||
QVariant default_value_;
|
||||
|
||||
bool tristate_;
|
||||
bool tristate_;
|
||||
|
||||
QString custom_format_;
|
||||
QString custom_format_;
|
||||
|
||||
bool format_plural_;
|
||||
bool format_plural_;
|
||||
|
||||
QVector<QPair<QVariant, QString> > label_substitutions_;
|
||||
QVector<QPair<QVariant, QString>> label_substitutions_;
|
||||
|
||||
private slots:
|
||||
void LineEditConfirmed();
|
||||
void LineEditConfirmed();
|
||||
|
||||
void LineEditCancelled();
|
||||
|
||||
void ResetValue();
|
||||
void LineEditCancelled();
|
||||
|
||||
void ResetValue();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,91 +24,91 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
namespace olive {
|
||||
|
||||
SliderLabel::SliderLabel(QWidget *parent) :
|
||||
QLabel(parent),
|
||||
override_color_enabled_(false)
|
||||
namespace olive
|
||||
{
|
||||
QPalette p = palette();
|
||||
|
||||
p.setColor(QPalette::Disabled,
|
||||
QPalette::Highlight,
|
||||
p.color(QPalette::Disabled, QPalette::ButtonText));
|
||||
SliderLabel::SliderLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
, override_color_enabled_(false)
|
||||
{
|
||||
QPalette p = palette();
|
||||
|
||||
setPalette(p);
|
||||
p.setColor(QPalette::Disabled, QPalette::Highlight,
|
||||
p.color(QPalette::Disabled, QPalette::ButtonText));
|
||||
|
||||
// Use highlight color as font color
|
||||
setForegroundRole(QPalette::Link);
|
||||
setPalette(p);
|
||||
|
||||
// Set underlined
|
||||
QFont f = font();
|
||||
f.setUnderline(true);
|
||||
setFont(f);
|
||||
// Use highlight color as font color
|
||||
setForegroundRole(QPalette::Link);
|
||||
|
||||
// Allow users to tab to this widget
|
||||
setFocusPolicy(Qt::TabFocus);
|
||||
// Set underlined
|
||||
QFont f = font();
|
||||
f.setUnderline(true);
|
||||
setFont(f);
|
||||
|
||||
// Add custom context menu
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
// Allow users to tab to this widget
|
||||
setFocusPolicy(Qt::TabFocus);
|
||||
|
||||
// Add custom context menu
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
void SliderLabel::SetColor(const QColor &c)
|
||||
{
|
||||
// Prevent infinite loop in changeEvent when we set the stylesheet
|
||||
override_color_enabled_ = false;
|
||||
override_color_ = c;
|
||||
// Prevent infinite loop in changeEvent when we set the stylesheet
|
||||
override_color_enabled_ = false;
|
||||
override_color_ = c;
|
||||
|
||||
// Different colors will look different depending on the theme (light/dark mode). We abstract
|
||||
// that away here so that other classes can simply choose a color and we will handle making it
|
||||
// more legible based on the background
|
||||
QColor adjusted;
|
||||
if (palette().window().color().lightness() < 128) {
|
||||
adjusted = override_color_.lighter(150);
|
||||
} else {
|
||||
adjusted = override_color_.darker(150);
|
||||
}
|
||||
// Different colors will look different depending on the theme (light/dark mode). We abstract
|
||||
// that away here so that other classes can simply choose a color and we will handle making it
|
||||
// more legible based on the background
|
||||
QColor adjusted;
|
||||
if (palette().window().color().lightness() < 128) {
|
||||
adjusted = override_color_.lighter(150);
|
||||
} else {
|
||||
adjusted = override_color_.darker(150);
|
||||
}
|
||||
|
||||
setStyleSheet(QStringLiteral("color: %1").arg(adjusted.name()));
|
||||
override_color_enabled_ = true;
|
||||
setStyleSheet(QStringLiteral("color: %1").arg(adjusted.name()));
|
||||
override_color_enabled_ = true;
|
||||
}
|
||||
|
||||
void SliderLabel::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
if (e->modifiers() & Qt::AltModifier) {
|
||||
emit RequestReset();
|
||||
} else {
|
||||
emit LabelPressed();
|
||||
}
|
||||
}
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
if (e->modifiers() & Qt::AltModifier) {
|
||||
emit RequestReset();
|
||||
} else {
|
||||
emit LabelPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SliderLabel::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
if (!(e->modifiers() & Qt::AltModifier)) {
|
||||
emit LabelReleased();
|
||||
}
|
||||
}
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
if (!(e->modifiers() & Qt::AltModifier)) {
|
||||
emit LabelReleased();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SliderLabel::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
QWidget::focusInEvent(event);
|
||||
QWidget::focusInEvent(event);
|
||||
|
||||
if (event->reason() == Qt::TabFocusReason) {
|
||||
emit focused();
|
||||
}
|
||||
if (event->reason() == Qt::TabFocusReason) {
|
||||
emit focused();
|
||||
}
|
||||
}
|
||||
|
||||
void SliderLabel::changeEvent(QEvent *event)
|
||||
{
|
||||
QWidget::changeEvent(event);
|
||||
QWidget::changeEvent(event);
|
||||
|
||||
if (override_color_enabled_ && event->type() == QEvent::StyleChange) {
|
||||
SetColor(override_color_);
|
||||
}
|
||||
if (override_color_enabled_ && event->type() == QEvent::StyleChange) {
|
||||
SetColor(override_color_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,40 +25,39 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SliderLabel : public QLabel
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SliderLabel(QWidget* parent);
|
||||
|
||||
void SetColor(const QColor &c);
|
||||
class SliderLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SliderLabel(QWidget *parent);
|
||||
|
||||
void SetColor(const QColor &c);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent *e) override;
|
||||
virtual void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
||||
virtual void focusInEvent(QFocusEvent *event) override;
|
||||
virtual void focusInEvent(QFocusEvent *event) override;
|
||||
|
||||
virtual void changeEvent(QEvent *event) override;
|
||||
virtual void changeEvent(QEvent *event) override;
|
||||
|
||||
signals:
|
||||
void LabelPressed();
|
||||
void LabelPressed();
|
||||
|
||||
void LabelReleased();
|
||||
void LabelReleased();
|
||||
|
||||
void focused();
|
||||
void focused();
|
||||
|
||||
void RequestReset();
|
||||
void RequestReset();
|
||||
|
||||
void ChangeSliderType();
|
||||
void ChangeSliderType();
|
||||
|
||||
private:
|
||||
bool override_color_enabled_;
|
||||
QColor override_color_;
|
||||
|
||||
bool override_color_enabled_;
|
||||
QColor override_color_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -35,306 +35,315 @@
|
||||
#include "common/qtutils.h"
|
||||
#include "config/config.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QString width_hint, QWidget* parent) :
|
||||
QFrame(parent, Qt::Popup)
|
||||
namespace olive
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
setFrameShape(QFrame::Box);
|
||||
setLineWidth(1);
|
||||
SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values,
|
||||
QString width_hint, QWidget *parent)
|
||||
: QFrame(parent, Qt::Popup)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
if (!OLIVE_CONFIG("UseSliderLadders").toBool()) {
|
||||
nb_outer_values = 0;
|
||||
}
|
||||
setFrameShape(QFrame::Box);
|
||||
setLineWidth(1);
|
||||
|
||||
for (int i=nb_outer_values-1;i>=0;i--) {
|
||||
elements_.append(new SliderLadderElement(qPow(10, i + 1) * drag_multiplier, width_hint));
|
||||
}
|
||||
if (!OLIVE_CONFIG("UseSliderLadders").toBool()) {
|
||||
nb_outer_values = 0;
|
||||
}
|
||||
|
||||
// Create center entry
|
||||
SliderLadderElement* start_element = new SliderLadderElement(drag_multiplier, width_hint);
|
||||
active_element_ = elements_.size();
|
||||
start_element->SetHighlighted(true);
|
||||
elements_.append(start_element);
|
||||
for (int i = nb_outer_values - 1; i >= 0; i--) {
|
||||
elements_.append(new SliderLadderElement(
|
||||
qPow(10, i + 1) * drag_multiplier, width_hint));
|
||||
}
|
||||
|
||||
for (int i=0;i<nb_outer_values;i++) {
|
||||
elements_.append(new SliderLadderElement(qPow(10, -i - 1) * drag_multiplier, width_hint));
|
||||
}
|
||||
// Create center entry
|
||||
SliderLadderElement *start_element =
|
||||
new SliderLadderElement(drag_multiplier, width_hint);
|
||||
active_element_ = elements_.size();
|
||||
start_element->SetHighlighted(true);
|
||||
elements_.append(start_element);
|
||||
|
||||
foreach (SliderLadderElement* e, elements_) {
|
||||
layout->addWidget(e);
|
||||
}
|
||||
for (int i = 0; i < nb_outer_values; i++) {
|
||||
elements_.append(new SliderLadderElement(
|
||||
qPow(10, -i - 1) * drag_multiplier, width_hint));
|
||||
}
|
||||
|
||||
if (elements_.size() == 1) {
|
||||
elements_.first()->SetMultiplierVisible(false);
|
||||
}
|
||||
foreach (SliderLadderElement *e, elements_) {
|
||||
layout->addWidget(e);
|
||||
}
|
||||
|
||||
drag_timer_.setInterval(10);
|
||||
connect(&drag_timer_, &QTimer::timeout, this, &SliderLadder::TimerUpdate);
|
||||
if (elements_.size() == 1) {
|
||||
elements_.first()->SetMultiplierVisible(false);
|
||||
}
|
||||
|
||||
screen_ = nullptr;
|
||||
foreach (QScreen *screen, qApp->screens()) {
|
||||
if (screen->geometry().contains(QCursor::pos())) {
|
||||
screen_ = screen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
drag_timer_.setInterval(10);
|
||||
connect(&drag_timer_, &QTimer::timeout, this, &SliderLadder::TimerUpdate);
|
||||
|
||||
if (UsingLadders()) {
|
||||
drag_start_x_ = -1;
|
||||
wrap_count_ = 0;
|
||||
} else {
|
||||
screen_ = nullptr;
|
||||
foreach (QScreen *screen, qApp->screens()) {
|
||||
if (screen->geometry().contains(QCursor::pos())) {
|
||||
screen_ = screen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (UsingLadders()) {
|
||||
drag_start_x_ = -1;
|
||||
wrap_count_ = 0;
|
||||
} else {
|
||||
#if defined(Q_OS_MAC)
|
||||
CGAssociateMouseAndMouseCursorPosition(false);
|
||||
CGDisplayHideCursor(kCGDirectMainDisplay);
|
||||
CGGetLastMouseDelta(nullptr, nullptr);
|
||||
CGAssociateMouseAndMouseCursorPosition(false);
|
||||
CGDisplayHideCursor(kCGDirectMainDisplay);
|
||||
CGGetLastMouseDelta(nullptr, nullptr);
|
||||
#else
|
||||
drag_start_x_ = QCursor::pos().x();
|
||||
drag_start_y_ = QCursor::pos().y();
|
||||
drag_start_x_ = QCursor::pos().x();
|
||||
drag_start_y_ = QCursor::pos().y();
|
||||
|
||||
static_cast<QGuiApplication*>(QApplication::instance())->setOverrideCursor(Qt::BlankCursor);
|
||||
static_cast<QGuiApplication *>(QApplication::instance())
|
||||
->setOverrideCursor(Qt::BlankCursor);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SliderLadder::~SliderLadder()
|
||||
{
|
||||
if (UsingLadders()) {
|
||||
if (wrap_count_ != 0) {
|
||||
// If wrapped, restore cursor to ladder
|
||||
QCursor::setPos(pos() + rect().center());
|
||||
}
|
||||
} else {
|
||||
if (UsingLadders()) {
|
||||
if (wrap_count_ != 0) {
|
||||
// If wrapped, restore cursor to ladder
|
||||
QCursor::setPos(pos() + rect().center());
|
||||
}
|
||||
} else {
|
||||
#if defined(Q_OS_MAC)
|
||||
CGAssociateMouseAndMouseCursorPosition(true);
|
||||
CGDisplayShowCursor(kCGDirectMainDisplay);
|
||||
CGAssociateMouseAndMouseCursorPosition(true);
|
||||
CGDisplayShowCursor(kCGDirectMainDisplay);
|
||||
#else
|
||||
static_cast<QGuiApplication*>(QApplication::instance())->restoreOverrideCursor();
|
||||
static_cast<QGuiApplication *>(QApplication::instance())
|
||||
->restoreOverrideCursor();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SliderLadder::SetValue(const QString &s)
|
||||
{
|
||||
foreach (SliderLadderElement* e, elements_) {
|
||||
e->SetValue(s);
|
||||
}
|
||||
foreach (SliderLadderElement *e, elements_) {
|
||||
e->SetValue(s);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderLadder::StartListeningToMouseInput()
|
||||
{
|
||||
QMetaObject::invokeMethod(&drag_timer_, "start", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(&drag_timer_, "start", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void SliderLadder::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(event)
|
||||
|
||||
this->close();
|
||||
this->close();
|
||||
}
|
||||
|
||||
void SliderLadder::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
Q_UNUSED(event)
|
||||
|
||||
drag_timer_.stop();
|
||||
drag_timer_.stop();
|
||||
|
||||
emit Released();
|
||||
emit Released();
|
||||
|
||||
QFrame::closeEvent(event);
|
||||
QFrame::closeEvent(event);
|
||||
}
|
||||
|
||||
void SliderLadder::TimerUpdate()
|
||||
{
|
||||
int ladder_left = this->x();
|
||||
int ladder_right = this->x() + this->width() - 1;
|
||||
int now_pos = QCursor::pos().x();
|
||||
int ladder_left = this->x();
|
||||
int ladder_right = this->x() + this->width() - 1;
|
||||
int now_pos = QCursor::pos().x();
|
||||
|
||||
if (UsingLadders()) {
|
||||
if (UsingLadders()) {
|
||||
bool is_under_mouse = (now_pos >= ladder_left &&
|
||||
now_pos <= ladder_right && wrap_count_ == 0);
|
||||
|
||||
bool is_under_mouse = (now_pos >= ladder_left && now_pos <= ladder_right && wrap_count_ == 0);
|
||||
if (drag_start_x_ != -1 &&
|
||||
(is_under_mouse ||
|
||||
(drag_start_x_ < ladder_left && now_pos > ladder_right) ||
|
||||
(drag_start_x_ > ladder_right && now_pos < ladder_left))) {
|
||||
// We're ending a drag, try to return the value back to its beginning
|
||||
int anchor;
|
||||
|
||||
if (drag_start_x_ != -1 && (is_under_mouse
|
||||
|| (drag_start_x_ < ladder_left && now_pos > ladder_right)
|
||||
|| (drag_start_x_ > ladder_right && now_pos < ladder_left))) {
|
||||
// We're ending a drag, try to return the value back to its beginning
|
||||
int anchor;
|
||||
if (drag_start_x_ < ladder_left) {
|
||||
anchor = ladder_left;
|
||||
} else {
|
||||
anchor = ladder_right;
|
||||
}
|
||||
|
||||
if (drag_start_x_ < ladder_left) {
|
||||
anchor = ladder_left;
|
||||
} else {
|
||||
anchor = ladder_right;
|
||||
}
|
||||
int makeup_value = anchor - drag_start_x_;
|
||||
emit DraggedByValue(makeup_value,
|
||||
elements_.at(active_element_)->GetMultiplier());
|
||||
|
||||
int makeup_value = anchor - drag_start_x_;
|
||||
emit DraggedByValue(makeup_value, elements_.at(active_element_)->GetMultiplier());
|
||||
drag_start_x_ = -1;
|
||||
}
|
||||
|
||||
drag_start_x_ = -1;
|
||||
}
|
||||
if (is_under_mouse) {
|
||||
// Determine which element is currently active
|
||||
for (int i = 0; i < elements_.size(); i++) {
|
||||
if (elements_.at(i)->underMouse()) {
|
||||
if (i != active_element_) {
|
||||
elements_.at(active_element_)->SetHighlighted(false);
|
||||
active_element_ = i;
|
||||
elements_.at(active_element_)->SetHighlighted(true);
|
||||
}
|
||||
|
||||
if (is_under_mouse) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which element is currently active
|
||||
for (int i=0; i<elements_.size(); i++) {
|
||||
if (elements_.at(i)->underMouse()) {
|
||||
if (i != active_element_) {
|
||||
elements_.at(active_element_)->SetHighlighted(false);
|
||||
active_element_ = i;
|
||||
elements_.at(active_element_)->SetHighlighted(true);
|
||||
}
|
||||
} else {
|
||||
if (drag_start_x_ == -1) {
|
||||
// Drag is a new leave from the ladder, calculate origin
|
||||
if (now_pos < ladder_left) {
|
||||
drag_start_x_ = ladder_left;
|
||||
} else {
|
||||
drag_start_x_ = ladder_right;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit DraggedByValue(now_pos - drag_start_x_,
|
||||
elements_.at(active_element_)->GetMultiplier());
|
||||
|
||||
} else {
|
||||
// Determine if cursor is at desktop edge, if so wrap around to other side
|
||||
if (screen_) {
|
||||
int left = screen_->geometry().left();
|
||||
int right = screen_->geometry().right();
|
||||
int width = right - left;
|
||||
if (now_pos <= left || now_pos >= right) {
|
||||
int orig_now_pos = now_pos;
|
||||
int orig_wrap = wrap_count_;
|
||||
|
||||
if (drag_start_x_ == -1) {
|
||||
// Drag is a new leave from the ladder, calculate origin
|
||||
if (now_pos < ladder_left) {
|
||||
drag_start_x_ = ladder_left;
|
||||
} else {
|
||||
drag_start_x_ = ladder_right;
|
||||
}
|
||||
}
|
||||
if (now_pos <= left) {
|
||||
wrap_count_--;
|
||||
now_pos += width;
|
||||
} else {
|
||||
wrap_count_++;
|
||||
now_pos -= width;
|
||||
}
|
||||
|
||||
emit DraggedByValue(now_pos - drag_start_x_, elements_.at(active_element_)->GetMultiplier());
|
||||
QPoint p(now_pos, QCursor::pos().y());
|
||||
QCursor::setPos(p);
|
||||
if (QCursor::pos() != p) {
|
||||
wrap_count_ = orig_wrap;
|
||||
now_pos = orig_now_pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if cursor is at desktop edge, if so wrap around to other side
|
||||
if (screen_) {
|
||||
int left = screen_->geometry().left();
|
||||
int right = screen_->geometry().right();
|
||||
int width = right - left;
|
||||
if (now_pos <= left || now_pos >= right) {
|
||||
int orig_now_pos = now_pos;
|
||||
int orig_wrap = wrap_count_;
|
||||
drag_start_x_ = now_pos;
|
||||
}
|
||||
|
||||
if (now_pos <= left) {
|
||||
wrap_count_--;
|
||||
now_pos += width;
|
||||
} else {
|
||||
wrap_count_++;
|
||||
now_pos -= width;
|
||||
}
|
||||
} else {
|
||||
int32_t x_mvmt, y_mvmt;
|
||||
|
||||
QPoint p(now_pos, QCursor::pos().y());
|
||||
QCursor::setPos(p);
|
||||
if (QCursor::pos() != p) {
|
||||
wrap_count_ = orig_wrap;
|
||||
now_pos = orig_now_pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drag_start_x_ = now_pos;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
int32_t x_mvmt, y_mvmt;
|
||||
|
||||
// Keep cursor in the same position
|
||||
// Keep cursor in the same position
|
||||
#if defined(Q_OS_MAC)
|
||||
CGGetLastMouseDelta(&x_mvmt, &y_mvmt);
|
||||
CGGetLastMouseDelta(&x_mvmt, &y_mvmt);
|
||||
#else
|
||||
QPoint current_pos = QCursor::pos();
|
||||
QPoint current_pos = QCursor::pos();
|
||||
|
||||
x_mvmt = current_pos.x() - drag_start_x_;
|
||||
y_mvmt = current_pos.y() - drag_start_y_;
|
||||
x_mvmt = current_pos.x() - drag_start_x_;
|
||||
y_mvmt = current_pos.y() - drag_start_y_;
|
||||
|
||||
QCursor::setPos(QPoint(drag_start_x_, drag_start_y_));
|
||||
QCursor::setPos(QPoint(drag_start_x_, drag_start_y_));
|
||||
#endif
|
||||
|
||||
if (x_mvmt || y_mvmt) {
|
||||
double multiplier = 1.0;
|
||||
if (x_mvmt || y_mvmt) {
|
||||
double multiplier = 1.0;
|
||||
|
||||
if (qApp->keyboardModifiers() & Qt::ControlModifier) {
|
||||
multiplier *= 0.01;
|
||||
}
|
||||
if (qApp->keyboardModifiers() & Qt::ControlModifier) {
|
||||
multiplier *= 0.01;
|
||||
}
|
||||
|
||||
if (qApp->keyboardModifiers() & Qt::ShiftModifier) {
|
||||
multiplier *= 100.0;
|
||||
}
|
||||
if (qApp->keyboardModifiers() & Qt::ShiftModifier) {
|
||||
multiplier *= 100.0;
|
||||
}
|
||||
|
||||
emit DraggedByValue(x_mvmt + y_mvmt, multiplier);
|
||||
}
|
||||
}
|
||||
emit DraggedByValue(x_mvmt + y_mvmt, multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SliderLadder::UsingLadders() const
|
||||
{
|
||||
return elements_.size() > 1;
|
||||
return elements_.size() > 1;
|
||||
}
|
||||
|
||||
SliderLadderElement::SliderLadderElement(const double &multiplier, QString width_hint, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
multiplier_(multiplier),
|
||||
highlighted_(false),
|
||||
multiplier_visible_(true)
|
||||
SliderLadderElement::SliderLadderElement(const double &multiplier,
|
||||
QString width_hint, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, multiplier_(multiplier)
|
||||
, highlighted_(false)
|
||||
, multiplier_visible_(true)
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
label_ = new QLabel();
|
||||
label_->setAlignment(Qt::AlignCenter);
|
||||
label_->setFixedWidth(QtUtils::QFontMetricsWidth(label_->fontMetrics(), width_hint));
|
||||
layout->addWidget(label_);
|
||||
label_ = new QLabel();
|
||||
label_->setAlignment(Qt::AlignCenter);
|
||||
label_->setFixedWidth(
|
||||
QtUtils::QFontMetricsWidth(label_->fontMetrics(), width_hint));
|
||||
layout->addWidget(label_);
|
||||
|
||||
QPalette p = palette();
|
||||
QColor highlight_color = palette().text().color();
|
||||
highlight_color.setAlpha(64);
|
||||
p.setColor(QPalette::Highlight, highlight_color);
|
||||
setPalette(p);
|
||||
QPalette p = palette();
|
||||
QColor highlight_color = palette().text().color();
|
||||
highlight_color.setAlpha(64);
|
||||
p.setColor(QPalette::Highlight, highlight_color);
|
||||
setPalette(p);
|
||||
|
||||
setAutoFillBackground(true);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SliderLadderElement::SetHighlighted(bool e)
|
||||
{
|
||||
highlighted_ = e;
|
||||
highlighted_ = e;
|
||||
|
||||
if (highlighted_) {
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
} else {
|
||||
setBackgroundRole(QPalette::Window);
|
||||
}
|
||||
if (highlighted_) {
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
} else {
|
||||
setBackgroundRole(QPalette::Window);
|
||||
}
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SliderLadderElement::SetValue(const QString &value)
|
||||
{
|
||||
value_ = value;
|
||||
value_ = value;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SliderLadderElement::SetMultiplierVisible(bool e)
|
||||
{
|
||||
multiplier_visible_ = e;
|
||||
multiplier_visible_ = e;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void SliderLadderElement::UpdateLabel()
|
||||
{
|
||||
if (multiplier_visible_) {
|
||||
QString val_text;
|
||||
if (multiplier_visible_) {
|
||||
QString val_text;
|
||||
|
||||
if (highlighted_) {
|
||||
val_text = value_;
|
||||
}
|
||||
if (highlighted_) {
|
||||
val_text = value_;
|
||||
}
|
||||
|
||||
label_->setText(QStringLiteral("%1\n%2").arg(QString::number(multiplier_),
|
||||
val_text));
|
||||
} else {
|
||||
label_->setText(value_);
|
||||
}
|
||||
label_->setText(QStringLiteral("%1\n%2").arg(
|
||||
QString::number(multiplier_), val_text));
|
||||
} else {
|
||||
label_->setText(value_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,79 +27,78 @@
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SliderLadderElement : public QWidget
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class SliderLadderElement : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SliderLadderElement(const double& multiplier, QString width_hint, QWidget* parent = nullptr);
|
||||
SliderLadderElement(const double &multiplier, QString width_hint,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
void SetHighlighted(bool e);
|
||||
void SetHighlighted(bool e);
|
||||
|
||||
void SetValue(const QString& value);
|
||||
void SetValue(const QString &value);
|
||||
|
||||
void SetMultiplierVisible(bool e);
|
||||
void SetMultiplierVisible(bool e);
|
||||
|
||||
double GetMultiplier() const
|
||||
{
|
||||
return multiplier_;
|
||||
}
|
||||
double GetMultiplier() const
|
||||
{
|
||||
return multiplier_;
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateLabel();
|
||||
void UpdateLabel();
|
||||
|
||||
QLabel* label_;
|
||||
QLabel *label_;
|
||||
|
||||
double multiplier_;
|
||||
QString value_;
|
||||
double multiplier_;
|
||||
QString value_;
|
||||
|
||||
bool highlighted_;
|
||||
|
||||
bool multiplier_visible_;
|
||||
bool highlighted_;
|
||||
|
||||
bool multiplier_visible_;
|
||||
};
|
||||
|
||||
class SliderLadder : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
class SliderLadder : public QFrame {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SliderLadder(double drag_multiplier, int nb_outer_values, QString width_hint, QWidget* parent = nullptr);
|
||||
SliderLadder(double drag_multiplier, int nb_outer_values,
|
||||
QString width_hint, QWidget *parent = nullptr);
|
||||
|
||||
virtual ~SliderLadder() override;
|
||||
virtual ~SliderLadder() override;
|
||||
|
||||
void SetValue(const QString& s);
|
||||
void SetValue(const QString &s);
|
||||
|
||||
void StartListeningToMouseInput();
|
||||
void StartListeningToMouseInput();
|
||||
|
||||
protected:
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
virtual void closeEvent(QCloseEvent* event) override;
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
signals:
|
||||
void DraggedByValue(int value, double multiplier);
|
||||
void DraggedByValue(int value, double multiplier);
|
||||
|
||||
void Released();
|
||||
void Released();
|
||||
|
||||
private:
|
||||
bool UsingLadders() const;
|
||||
bool UsingLadders() const;
|
||||
|
||||
int drag_start_x_;
|
||||
int drag_start_y_;
|
||||
int wrap_count_;
|
||||
int drag_start_x_;
|
||||
int drag_start_y_;
|
||||
int wrap_count_;
|
||||
|
||||
QList<SliderLadderElement*> elements_;
|
||||
QList<SliderLadderElement *> elements_;
|
||||
|
||||
int active_element_;
|
||||
int active_element_;
|
||||
|
||||
QTimer drag_timer_;
|
||||
QTimer drag_timer_;
|
||||
|
||||
QScreen *screen_;
|
||||
QScreen *screen_;
|
||||
|
||||
private slots:
|
||||
void TimerUpdate();
|
||||
|
||||
void TimerUpdate();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -25,149 +25,154 @@
|
||||
|
||||
#include "common/decibel.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super DecimalSliderBase
|
||||
|
||||
FloatSlider::FloatSlider(QWidget *parent) :
|
||||
super(parent),
|
||||
display_type_(kNormal)
|
||||
FloatSlider::FloatSlider(QWidget *parent)
|
||||
: super(parent)
|
||||
, display_type_(kNormal)
|
||||
{
|
||||
SetValue(0.0);
|
||||
SetValue(0.0);
|
||||
}
|
||||
|
||||
double FloatSlider::GetValue() const
|
||||
{
|
||||
return GetValueInternal().toDouble();
|
||||
return GetValueInternal().toDouble();
|
||||
}
|
||||
|
||||
void FloatSlider::SetValue(const double &d)
|
||||
{
|
||||
SetValueInternal(d);
|
||||
SetValueInternal(d);
|
||||
}
|
||||
|
||||
void FloatSlider::SetDefaultValue(const double &d)
|
||||
{
|
||||
super::SetDefaultValue(d);
|
||||
super::SetDefaultValue(d);
|
||||
}
|
||||
|
||||
void FloatSlider::SetMinimum(const double &d)
|
||||
{
|
||||
SetMinimumInternal(d);
|
||||
SetMinimumInternal(d);
|
||||
}
|
||||
|
||||
void FloatSlider::SetMaximum(const double &d)
|
||||
{
|
||||
SetMaximumInternal(d);
|
||||
SetMaximumInternal(d);
|
||||
}
|
||||
|
||||
void FloatSlider::SetDisplayType(const FloatSlider::DisplayType &type)
|
||||
{
|
||||
display_type_ = type;
|
||||
display_type_ = type;
|
||||
|
||||
switch (display_type_) {
|
||||
case kNormal:
|
||||
ClearFormat();
|
||||
break;
|
||||
case kDecibel:
|
||||
SetFormat(tr("%1 dB"));
|
||||
break;
|
||||
case kPercentage:
|
||||
SetFormat(tr("%1%"));
|
||||
break;
|
||||
}
|
||||
switch (display_type_) {
|
||||
case kNormal:
|
||||
ClearFormat();
|
||||
break;
|
||||
case kDecibel:
|
||||
SetFormat(tr("%1 dB"));
|
||||
break;
|
||||
case kPercentage:
|
||||
SetFormat(tr("%1%"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double FloatSlider::TransformValueToDisplay(double val, DisplayType display)
|
||||
{
|
||||
switch (display) {
|
||||
case kNormal:
|
||||
break;
|
||||
case kDecibel:
|
||||
val = Decibel::fromLinear(val);
|
||||
break;
|
||||
case kPercentage:
|
||||
val *= 100.0;
|
||||
break;
|
||||
}
|
||||
switch (display) {
|
||||
case kNormal:
|
||||
break;
|
||||
case kDecibel:
|
||||
val = Decibel::fromLinear(val);
|
||||
break;
|
||||
case kPercentage:
|
||||
val *= 100.0;
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
double FloatSlider::TransformDisplayToValue(double val, DisplayType display)
|
||||
{
|
||||
switch (display) {
|
||||
case kNormal:
|
||||
break;
|
||||
case kDecibel:
|
||||
val = Decibel::toLinear(val);
|
||||
break;
|
||||
case kPercentage:
|
||||
val *= 0.01;
|
||||
break;
|
||||
}
|
||||
switch (display) {
|
||||
case kNormal:
|
||||
break;
|
||||
case kDecibel:
|
||||
val = Decibel::toLinear(val);
|
||||
break;
|
||||
case kPercentage:
|
||||
val *= 0.01;
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
QString FloatSlider::ValueToString(double val, FloatSlider::DisplayType display, int decimal_places, bool autotrim_decimal_places)
|
||||
QString FloatSlider::ValueToString(double val, FloatSlider::DisplayType display,
|
||||
int decimal_places,
|
||||
bool autotrim_decimal_places)
|
||||
{
|
||||
// Return negative infinity for zero volume
|
||||
if (display == kDecibel && qIsNull(val)) {
|
||||
return tr("\xE2\x88\x9E");
|
||||
}
|
||||
// Return negative infinity for zero volume
|
||||
if (display == kDecibel && qIsNull(val)) {
|
||||
return tr("\xE2\x88\x9E");
|
||||
}
|
||||
|
||||
return FloatToString(TransformValueToDisplay(val, display), decimal_places, autotrim_decimal_places);
|
||||
return FloatToString(TransformValueToDisplay(val, display), decimal_places,
|
||||
autotrim_decimal_places);
|
||||
}
|
||||
|
||||
QString FloatSlider::ValueToString(const QVariant &v) const
|
||||
{
|
||||
return ValueToString(v.toDouble() + GetOffset().toDouble(), display_type_, GetDecimalPlaces(), GetAutoTrimDecimalPlaces());
|
||||
return ValueToString(v.toDouble() + GetOffset().toDouble(), display_type_,
|
||||
GetDecimalPlaces(), GetAutoTrimDecimalPlaces());
|
||||
}
|
||||
|
||||
QVariant FloatSlider::StringToValue(const QString &s, bool *ok) const
|
||||
{
|
||||
bool valid;
|
||||
double val = s.toDouble(&valid);
|
||||
bool valid;
|
||||
double val = s.toDouble(&valid);
|
||||
|
||||
// If we were given an `ok` pointer, set it to `valid`
|
||||
if (ok) {
|
||||
*ok = valid;
|
||||
}
|
||||
// If we were given an `ok` pointer, set it to `valid`
|
||||
if (ok) {
|
||||
*ok = valid;
|
||||
}
|
||||
|
||||
// If valid, transform it from display
|
||||
if (valid) {
|
||||
val = TransformDisplayToValue(val, display_type_);
|
||||
}
|
||||
// If valid, transform it from display
|
||||
if (valid) {
|
||||
val = TransformDisplayToValue(val, display_type_);
|
||||
}
|
||||
|
||||
// Return un-offset value
|
||||
return val - GetOffset().toDouble();
|
||||
// Return un-offset value
|
||||
return val - GetOffset().toDouble();
|
||||
}
|
||||
|
||||
QVariant FloatSlider::AdjustDragDistanceInternal(const QVariant &start, const double &drag) const
|
||||
QVariant FloatSlider::AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const
|
||||
{
|
||||
switch (display_type_) {
|
||||
case kNormal:
|
||||
// No change here
|
||||
break;
|
||||
case kDecibel:
|
||||
{
|
||||
double current_db = Decibel::fromLinear(start.toDouble());
|
||||
current_db += drag;
|
||||
double adjusted_linear = Decibel::toLinear(current_db);
|
||||
switch (display_type_) {
|
||||
case kNormal:
|
||||
// No change here
|
||||
break;
|
||||
case kDecibel: {
|
||||
double current_db = Decibel::fromLinear(start.toDouble());
|
||||
current_db += drag;
|
||||
double adjusted_linear = Decibel::toLinear(current_db);
|
||||
|
||||
return adjusted_linear;
|
||||
}
|
||||
case kPercentage:
|
||||
return super::AdjustDragDistanceInternal(start, drag * 0.01);
|
||||
}
|
||||
return adjusted_linear;
|
||||
}
|
||||
case kPercentage:
|
||||
return super::AdjustDragDistanceInternal(start, drag * 0.01);
|
||||
}
|
||||
|
||||
return super::AdjustDragDistanceInternal(start, drag);
|
||||
return super::AdjustDragDistanceInternal(start, drag);
|
||||
}
|
||||
|
||||
void FloatSlider::ValueSignalEvent(const QVariant &value)
|
||||
{
|
||||
emit ValueChanged(value.toDouble());
|
||||
emit ValueChanged(value.toDouble());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,53 +23,52 @@
|
||||
|
||||
#include "base/decimalsliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class FloatSlider : public DecimalSliderBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class FloatSlider : public DecimalSliderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FloatSlider(QWidget* parent = nullptr);
|
||||
FloatSlider(QWidget *parent = nullptr);
|
||||
|
||||
enum DisplayType {
|
||||
kNormal,
|
||||
kDecibel,
|
||||
kPercentage
|
||||
};
|
||||
enum DisplayType { kNormal, kDecibel, kPercentage };
|
||||
|
||||
double GetValue() const;
|
||||
double GetValue() const;
|
||||
|
||||
void SetValue(const double& d);
|
||||
void SetValue(const double &d);
|
||||
|
||||
void SetDefaultValue(const double& d);
|
||||
void SetDefaultValue(const double &d);
|
||||
|
||||
void SetMinimum(const double& d);
|
||||
void SetMinimum(const double &d);
|
||||
|
||||
void SetMaximum(const double& d);
|
||||
void SetMaximum(const double &d);
|
||||
|
||||
void SetDisplayType(const DisplayType& type);
|
||||
void SetDisplayType(const DisplayType &type);
|
||||
|
||||
static double TransformValueToDisplay(double val, DisplayType display);
|
||||
static double TransformValueToDisplay(double val, DisplayType display);
|
||||
|
||||
static double TransformDisplayToValue(double val, DisplayType display);
|
||||
static double TransformDisplayToValue(double val, DisplayType display);
|
||||
|
||||
static QString ValueToString(double val, DisplayType display, int decimal_places, bool autotrim_decimal_places);
|
||||
static QString ValueToString(double val, DisplayType display,
|
||||
int decimal_places,
|
||||
bool autotrim_decimal_places);
|
||||
|
||||
protected:
|
||||
virtual QString ValueToString(const QVariant& v) const override;
|
||||
virtual QString ValueToString(const QVariant &v) const override;
|
||||
|
||||
virtual QVariant StringToValue(const QString& s, bool* ok) const override;
|
||||
virtual QVariant StringToValue(const QString &s, bool *ok) const override;
|
||||
|
||||
virtual QVariant AdjustDragDistanceInternal(const QVariant &start, const double &drag) const override;
|
||||
virtual QVariant
|
||||
AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const override;
|
||||
|
||||
virtual void ValueSignalEvent(const QVariant &value) override;
|
||||
virtual void ValueSignalEvent(const QVariant &value) override;
|
||||
|
||||
signals:
|
||||
void ValueChanged(double);
|
||||
void ValueChanged(double);
|
||||
|
||||
private:
|
||||
DisplayType display_type_;
|
||||
|
||||
DisplayType display_type_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,75 +20,77 @@
|
||||
|
||||
#include "integerslider.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super NumericSliderBase
|
||||
|
||||
IntegerSlider::IntegerSlider(QWidget* parent) :
|
||||
super(parent)
|
||||
IntegerSlider::IntegerSlider(QWidget *parent)
|
||||
: super(parent)
|
||||
{
|
||||
SetValue(0);
|
||||
SetValue(0);
|
||||
}
|
||||
|
||||
int64_t IntegerSlider::GetValue()
|
||||
{
|
||||
return GetValueInternal().toLongLong();
|
||||
return GetValueInternal().toLongLong();
|
||||
}
|
||||
|
||||
void IntegerSlider::SetValue(const int64_t &v)
|
||||
{
|
||||
SetValueInternal(QVariant::fromValue(v));
|
||||
SetValueInternal(QVariant::fromValue(v));
|
||||
}
|
||||
|
||||
void IntegerSlider::SetMinimum(const int64_t &d)
|
||||
{
|
||||
SetMinimumInternal(QVariant::fromValue(d));
|
||||
SetMinimumInternal(QVariant::fromValue(d));
|
||||
}
|
||||
|
||||
void IntegerSlider::SetMaximum(const int64_t &d)
|
||||
{
|
||||
SetMaximumInternal(QVariant::fromValue(d));
|
||||
SetMaximumInternal(QVariant::fromValue(d));
|
||||
}
|
||||
|
||||
void IntegerSlider::SetDefaultValue(const int64_t &d)
|
||||
{
|
||||
super::SetDefaultValue(QVariant::fromValue(d));
|
||||
super::SetDefaultValue(QVariant::fromValue(d));
|
||||
}
|
||||
|
||||
QString IntegerSlider::ValueToString(const QVariant &v) const
|
||||
{
|
||||
return QString::number(v.toLongLong() + GetOffset().toLongLong());
|
||||
return QString::number(v.toLongLong() + GetOffset().toLongLong());
|
||||
}
|
||||
|
||||
QVariant IntegerSlider::StringToValue(const QString &s, bool *ok) const
|
||||
{
|
||||
bool valid;
|
||||
bool valid;
|
||||
|
||||
// Allow both floats and integers for either modes
|
||||
double decimal_val = s.toDouble(&valid);
|
||||
// Allow both floats and integers for either modes
|
||||
double decimal_val = s.toDouble(&valid);
|
||||
|
||||
if (ok) {
|
||||
*ok = valid;
|
||||
}
|
||||
if (ok) {
|
||||
*ok = valid;
|
||||
}
|
||||
|
||||
decimal_val -= GetOffset().toLongLong();
|
||||
decimal_val -= GetOffset().toLongLong();
|
||||
|
||||
if (valid) {
|
||||
// But for an integer, we round it
|
||||
return qRound(decimal_val);
|
||||
}
|
||||
if (valid) {
|
||||
// But for an integer, we round it
|
||||
return qRound(decimal_val);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void IntegerSlider::ValueSignalEvent(const QVariant &value)
|
||||
{
|
||||
emit ValueChanged(value.toInt());
|
||||
emit ValueChanged(value.toInt());
|
||||
}
|
||||
|
||||
QVariant IntegerSlider::AdjustDragDistanceInternal(const QVariant &start, const double &drag) const
|
||||
QVariant IntegerSlider::AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const
|
||||
{
|
||||
return qRound64(super::AdjustDragDistanceInternal(start, drag).toDouble());
|
||||
return qRound64(super::AdjustDragDistanceInternal(start, drag).toDouble());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,36 +23,37 @@
|
||||
|
||||
#include "base/numericsliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class IntegerSlider : public NumericSliderBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class IntegerSlider : public NumericSliderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
IntegerSlider(QWidget* parent = nullptr);
|
||||
IntegerSlider(QWidget *parent = nullptr);
|
||||
|
||||
int64_t GetValue();
|
||||
int64_t GetValue();
|
||||
|
||||
void SetValue(const int64_t& v);
|
||||
void SetValue(const int64_t &v);
|
||||
|
||||
void SetMinimum(const int64_t& d);
|
||||
void SetMinimum(const int64_t &d);
|
||||
|
||||
void SetMaximum(const int64_t& d);
|
||||
void SetMaximum(const int64_t &d);
|
||||
|
||||
void SetDefaultValue(const int64_t& d);
|
||||
void SetDefaultValue(const int64_t &d);
|
||||
|
||||
protected:
|
||||
virtual QString ValueToString(const QVariant& v) const override;
|
||||
virtual QString ValueToString(const QVariant &v) const override;
|
||||
|
||||
virtual QVariant StringToValue(const QString& s, bool* ok) const override;
|
||||
virtual QVariant StringToValue(const QString &s, bool *ok) const override;
|
||||
|
||||
virtual void ValueSignalEvent(const QVariant &value) override;
|
||||
virtual void ValueSignalEvent(const QVariant &value) override;
|
||||
|
||||
virtual QVariant AdjustDragDistanceInternal(const QVariant &start, const double &drag) const override;
|
||||
virtual QVariant
|
||||
AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const override;
|
||||
|
||||
signals:
|
||||
void ValueChanged(int64_t);
|
||||
|
||||
void ValueChanged(int64_t);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,197 +24,209 @@
|
||||
#include "widget/menu/menu.h"
|
||||
#include "widget/menu/menushared.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super DecimalSliderBase
|
||||
|
||||
RationalSlider::RationalSlider(QWidget *parent) :
|
||||
super(parent),
|
||||
lock_display_type_(false)
|
||||
RationalSlider::RationalSlider(QWidget *parent)
|
||||
: super(parent)
|
||||
, lock_display_type_(false)
|
||||
{
|
||||
connect(Core::instance(), &Core::TimecodeDisplayChanged, this, &RationalSlider::UpdateLabel);
|
||||
connect(SliderBase::label(), &SliderLabel::customContextMenuRequested, this, &RationalSlider::ShowDisplayTypeMenu);
|
||||
connect(Core::instance(), &Core::TimecodeDisplayChanged, this,
|
||||
&RationalSlider::UpdateLabel);
|
||||
connect(SliderBase::label(), &SliderLabel::customContextMenuRequested, this,
|
||||
&RationalSlider::ShowDisplayTypeMenu);
|
||||
|
||||
SetDisplayType(kFloat);
|
||||
SetDisplayType(kFloat);
|
||||
|
||||
SetValue(rational(0, 0));
|
||||
SetValue(rational(0, 0));
|
||||
}
|
||||
|
||||
rational RationalSlider::GetValue()
|
||||
{
|
||||
return GetValueInternal().value<rational>();
|
||||
return GetValueInternal().value<rational>();
|
||||
}
|
||||
|
||||
void RationalSlider::SetValue(const rational &d)
|
||||
{
|
||||
SetValueInternal(QVariant::fromValue(d));
|
||||
SetValueInternal(QVariant::fromValue(d));
|
||||
}
|
||||
|
||||
void RationalSlider::SetDefaultValue(const rational &r)
|
||||
{
|
||||
super::SetDefaultValue(QVariant::fromValue(r));
|
||||
super::SetDefaultValue(QVariant::fromValue(r));
|
||||
}
|
||||
|
||||
void RationalSlider::SetMinimum(const rational &d)
|
||||
{
|
||||
SetMinimumInternal(QVariant::fromValue(d));
|
||||
SetMinimumInternal(QVariant::fromValue(d));
|
||||
}
|
||||
|
||||
void RationalSlider::SetMaximum(const rational &d)
|
||||
{
|
||||
SetMaximumInternal(QVariant::fromValue(d));
|
||||
SetMaximumInternal(QVariant::fromValue(d));
|
||||
}
|
||||
|
||||
void RationalSlider::SetTimebase(const rational &timebase)
|
||||
{
|
||||
timebase_ = timebase;
|
||||
timebase_ = timebase;
|
||||
|
||||
// Refresh label since we have a new timebase to generate a timecode with
|
||||
UpdateLabel();
|
||||
// Refresh label since we have a new timebase to generate a timecode with
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void RationalSlider::SetDisplayType(const RationalSlider::DisplayType &type)
|
||||
{
|
||||
display_type_ = type;
|
||||
display_type_ = type;
|
||||
|
||||
UpdateLabel();
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
void RationalSlider::SetLockDisplayType(bool e)
|
||||
{
|
||||
lock_display_type_ = e;
|
||||
lock_display_type_ = e;
|
||||
}
|
||||
|
||||
bool RationalSlider::GetLockDisplayType()
|
||||
{
|
||||
return lock_display_type_;
|
||||
return lock_display_type_;
|
||||
}
|
||||
|
||||
void RationalSlider::DisableDisplayType(RationalSlider::DisplayType type)
|
||||
{
|
||||
disabled_.append(type);
|
||||
disabled_.append(type);
|
||||
}
|
||||
|
||||
QString RationalSlider::ValueToString(const QVariant &v) const
|
||||
{
|
||||
rational r = v.value<rational>();
|
||||
rational r = v.value<rational>();
|
||||
|
||||
if (r.isNaN()) {
|
||||
return tr("NaN");
|
||||
} else {
|
||||
double val = r.toDouble() + GetOffset().value<rational>().toDouble();
|
||||
if (r.isNaN()) {
|
||||
return tr("NaN");
|
||||
} else {
|
||||
double val = r.toDouble() + GetOffset().value<rational>().toDouble();
|
||||
|
||||
switch (display_type_) {
|
||||
case kTime:
|
||||
return QString::fromStdString(Timecode::time_to_timecode(r, timebase_, Core::instance()->GetTimecodeDisplay()));
|
||||
case kFloat:
|
||||
return FloatToString(val, GetDecimalPlaces(), GetAutoTrimDecimalPlaces());
|
||||
case kRational:
|
||||
return QString::fromStdString(v.value<rational>().toString());
|
||||
}
|
||||
switch (display_type_) {
|
||||
case kTime:
|
||||
return QString::fromStdString(Timecode::time_to_timecode(
|
||||
r, timebase_, Core::instance()->GetTimecodeDisplay()));
|
||||
case kFloat:
|
||||
return FloatToString(val, GetDecimalPlaces(),
|
||||
GetAutoTrimDecimalPlaces());
|
||||
case kRational:
|
||||
return QString::fromStdString(v.value<rational>().toString());
|
||||
}
|
||||
|
||||
return v.toString();
|
||||
}
|
||||
return v.toString();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant RationalSlider::StringToValue(const QString &s, bool *ok) const
|
||||
{
|
||||
rational r;
|
||||
*ok = false;
|
||||
rational r;
|
||||
*ok = false;
|
||||
|
||||
switch (display_type_) {
|
||||
case kTime:
|
||||
{
|
||||
r = Timecode::timecode_to_time(s.toStdString(), timebase_, Core::instance()->GetTimecodeDisplay(), ok);
|
||||
break;
|
||||
}
|
||||
case kFloat:
|
||||
{
|
||||
// First, convert to a double
|
||||
double d = s.toDouble(ok);
|
||||
if (!(*ok)) {
|
||||
break;
|
||||
}
|
||||
switch (display_type_) {
|
||||
case kTime: {
|
||||
r = Timecode::timecode_to_time(s.toStdString(), timebase_,
|
||||
Core::instance()->GetTimecodeDisplay(),
|
||||
ok);
|
||||
break;
|
||||
}
|
||||
case kFloat: {
|
||||
// First, convert to a double
|
||||
double d = s.toDouble(ok);
|
||||
if (!(*ok)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// If double conversion succeeded, convert to a rational
|
||||
r = rational::fromDouble(d, ok);
|
||||
break;
|
||||
}
|
||||
case kRational:
|
||||
r = rational::fromString(s.toStdString(), ok);
|
||||
break;
|
||||
}
|
||||
// If double conversion succeeded, convert to a rational
|
||||
r = rational::fromDouble(d, ok);
|
||||
break;
|
||||
}
|
||||
case kRational:
|
||||
r = rational::fromString(s.toStdString(), ok);
|
||||
break;
|
||||
}
|
||||
|
||||
//return QVariant::fromValue(r - GetOffset().value<rational>());
|
||||
return QVariant::fromValue(r);
|
||||
//return QVariant::fromValue(r - GetOffset().value<rational>());
|
||||
return QVariant::fromValue(r);
|
||||
}
|
||||
|
||||
QVariant RationalSlider::AdjustDragDistanceInternal(const QVariant &start, const double &drag) const
|
||||
QVariant RationalSlider::AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const
|
||||
{
|
||||
// Assume we want smallest increment to be timebase or 1 frame
|
||||
return QVariant::fromValue(start.value<rational>() + rational::fromDouble(drag)*timebase_);
|
||||
// Assume we want smallest increment to be timebase or 1 frame
|
||||
return QVariant::fromValue(start.value<rational>() +
|
||||
rational::fromDouble(drag) * timebase_);
|
||||
}
|
||||
|
||||
void RationalSlider::ValueSignalEvent(const QVariant &v)
|
||||
{
|
||||
emit ValueChanged(v.value<rational>());
|
||||
emit ValueChanged(v.value<rational>());
|
||||
}
|
||||
|
||||
bool RationalSlider::ValueGreaterThan(const QVariant &lhs, const QVariant &rhs) const
|
||||
bool RationalSlider::ValueGreaterThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const
|
||||
{
|
||||
return lhs.value<rational>() > rhs.value<rational>();
|
||||
return lhs.value<rational>() > rhs.value<rational>();
|
||||
}
|
||||
|
||||
bool RationalSlider::ValueLessThan(const QVariant &lhs, const QVariant &rhs) const
|
||||
bool RationalSlider::ValueLessThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const
|
||||
{
|
||||
return lhs.value<rational>() < rhs.value<rational>();
|
||||
return lhs.value<rational>() < rhs.value<rational>();
|
||||
}
|
||||
|
||||
void RationalSlider::ShowDisplayTypeMenu()
|
||||
{
|
||||
Menu m(this);
|
||||
Menu m(this);
|
||||
|
||||
if (!GetLockDisplayType()) {
|
||||
if (!disabled_.contains(kFloat)) {
|
||||
QAction* float_action = m.addAction(tr("Float"));
|
||||
float_action->setData(kFloat);
|
||||
connect(float_action, &QAction::triggered, this, &RationalSlider::SetDisplayTypeFromMenu);
|
||||
}
|
||||
if (!GetLockDisplayType()) {
|
||||
if (!disabled_.contains(kFloat)) {
|
||||
QAction *float_action = m.addAction(tr("Float"));
|
||||
float_action->setData(kFloat);
|
||||
connect(float_action, &QAction::triggered, this,
|
||||
&RationalSlider::SetDisplayTypeFromMenu);
|
||||
}
|
||||
|
||||
if (!disabled_.contains(kRational)) {
|
||||
QAction* rational_action = m.addAction(tr("Rational"));
|
||||
rational_action->setData(kRational);
|
||||
connect(rational_action, &QAction::triggered, this, &RationalSlider::SetDisplayTypeFromMenu);
|
||||
}
|
||||
if (!disabled_.contains(kRational)) {
|
||||
QAction *rational_action = m.addAction(tr("Rational"));
|
||||
rational_action->setData(kRational);
|
||||
connect(rational_action, &QAction::triggered, this,
|
||||
&RationalSlider::SetDisplayTypeFromMenu);
|
||||
}
|
||||
|
||||
if (!disabled_.contains(kTime)) {
|
||||
QAction* time_action = m.addAction(tr("Time"));
|
||||
time_action->setData(kTime);
|
||||
connect(time_action, &QAction::triggered, this, &RationalSlider::SetDisplayTypeFromMenu);
|
||||
}
|
||||
}
|
||||
if (!disabled_.contains(kTime)) {
|
||||
QAction *time_action = m.addAction(tr("Time"));
|
||||
time_action->setData(kTime);
|
||||
connect(time_action, &QAction::triggered, this,
|
||||
&RationalSlider::SetDisplayTypeFromMenu);
|
||||
}
|
||||
}
|
||||
|
||||
if (display_type_ == kTime) {
|
||||
if (!m.actions().isEmpty()) {
|
||||
m.addSeparator();
|
||||
}
|
||||
MenuShared::instance()->AddItemsForTimeRulerMenu(&m);
|
||||
MenuShared::instance()->AboutToShowTimeRulerActions(timebase_);
|
||||
}
|
||||
if (display_type_ == kTime) {
|
||||
if (!m.actions().isEmpty()) {
|
||||
m.addSeparator();
|
||||
}
|
||||
MenuShared::instance()->AddItemsForTimeRulerMenu(&m);
|
||||
MenuShared::instance()->AboutToShowTimeRulerActions(timebase_);
|
||||
}
|
||||
|
||||
if (!m.actions().isEmpty()) {
|
||||
m.exec(QCursor::pos());
|
||||
UpdateLabel();
|
||||
}
|
||||
if (!m.actions().isEmpty()) {
|
||||
m.exec(QCursor::pos());
|
||||
UpdateLabel();
|
||||
}
|
||||
}
|
||||
|
||||
void RationalSlider::SetDisplayTypeFromMenu()
|
||||
{
|
||||
QAction* action = static_cast<QAction*>(sender());
|
||||
QAction *action = static_cast<QAction *>(sender());
|
||||
|
||||
DisplayType type = static_cast<DisplayType>(action->data().toInt());
|
||||
DisplayType type = static_cast<DisplayType>(action->data().toInt());
|
||||
|
||||
SetDisplayType(type);
|
||||
SetDisplayType(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,112 +26,111 @@
|
||||
|
||||
#include "base/decimalsliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
using namespace core;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief A olive::rational based slider
|
||||
*
|
||||
* A slider that can display rationals as either timecode (drop or non-drop), a timestamp (frames),
|
||||
* or a float (seconds).
|
||||
*/
|
||||
class RationalSlider : public DecimalSliderBase
|
||||
{
|
||||
Q_OBJECT
|
||||
class RationalSlider : public DecimalSliderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
/**
|
||||
* @brief enum containing the possibly display types
|
||||
*/
|
||||
enum DisplayType {
|
||||
kTime,
|
||||
kFloat,
|
||||
kRational
|
||||
};
|
||||
enum DisplayType { kTime, kFloat, kRational };
|
||||
|
||||
RationalSlider(QWidget* parent = nullptr);
|
||||
RationalSlider(QWidget *parent = nullptr);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Returns the sliders value as a rational
|
||||
*/
|
||||
rational GetValue();
|
||||
rational GetValue();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the sliders default value
|
||||
*/
|
||||
void SetDefaultValue(const rational& r);
|
||||
void SetDefaultValue(const rational &r);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the sliders minimum value
|
||||
*/
|
||||
void SetMinimum(const rational& d);
|
||||
void SetMinimum(const rational &d);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the sliders maximum value
|
||||
*/
|
||||
void SetMaximum(const rational& d);
|
||||
void SetMaximum(const rational &d);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the display type of the slider
|
||||
*/
|
||||
void SetDisplayType(const DisplayType& type);
|
||||
void SetDisplayType(const DisplayType &type);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Set whether the user can change the display type or not
|
||||
*/
|
||||
void SetLockDisplayType(bool e);
|
||||
void SetLockDisplayType(bool e);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get whether the user can change the display type or not
|
||||
*/
|
||||
bool GetLockDisplayType();
|
||||
bool GetLockDisplayType();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Hide display type in menu
|
||||
*/
|
||||
void DisableDisplayType(DisplayType type);
|
||||
void DisableDisplayType(DisplayType type);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the sliders timebase which is also the minimum increment of the slider
|
||||
*/
|
||||
void SetTimebase(const rational& timebase);
|
||||
void SetTimebase(const rational &timebase);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Sets the sliders value
|
||||
*/
|
||||
void SetValue(const rational& d);
|
||||
void SetValue(const rational &d);
|
||||
|
||||
protected:
|
||||
virtual QString ValueToString(const QVariant& v) const override;
|
||||
virtual QString ValueToString(const QVariant &v) const override;
|
||||
|
||||
virtual QVariant StringToValue(const QString& s, bool* ok) const override;
|
||||
virtual QVariant StringToValue(const QString &s, bool *ok) const override;
|
||||
|
||||
virtual QVariant AdjustDragDistanceInternal(const QVariant &start, const double &drag) const override;
|
||||
virtual QVariant
|
||||
AdjustDragDistanceInternal(const QVariant &start,
|
||||
const double &drag) const override;
|
||||
|
||||
virtual void ValueSignalEvent(const QVariant& v) override;
|
||||
virtual void ValueSignalEvent(const QVariant &v) override;
|
||||
|
||||
virtual bool ValueGreaterThan(const QVariant& lhs, const QVariant& rhs) const override;
|
||||
virtual bool ValueGreaterThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const override;
|
||||
|
||||
virtual bool ValueLessThan(const QVariant& lhs, const QVariant& rhs) const override;
|
||||
virtual bool ValueLessThan(const QVariant &lhs,
|
||||
const QVariant &rhs) const override;
|
||||
|
||||
signals:
|
||||
void ValueChanged(rational);
|
||||
void ValueChanged(rational);
|
||||
|
||||
private slots:
|
||||
void ShowDisplayTypeMenu();
|
||||
void ShowDisplayTypeMenu();
|
||||
|
||||
void SetDisplayTypeFromMenu();
|
||||
void SetDisplayTypeFromMenu();
|
||||
|
||||
private:
|
||||
DisplayType display_type_;
|
||||
DisplayType display_type_;
|
||||
|
||||
rational timebase_;
|
||||
rational timebase_;
|
||||
|
||||
bool lock_display_type_;
|
||||
|
||||
QVector<DisplayType> disabled_;
|
||||
bool lock_display_type_;
|
||||
|
||||
QVector<DisplayType> disabled_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,48 +20,50 @@
|
||||
|
||||
#include "stringslider.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super SliderBase
|
||||
|
||||
StringSlider::StringSlider(QWidget* parent) :
|
||||
super(parent)
|
||||
StringSlider::StringSlider(QWidget *parent)
|
||||
: super(parent)
|
||||
{
|
||||
SetValue(QString());
|
||||
SetValue(QString());
|
||||
|
||||
connect(label(), &SliderLabel::LabelReleased, this, &SliderBase::ShowEditor);
|
||||
connect(label(), &SliderLabel::LabelReleased, this,
|
||||
&SliderBase::ShowEditor);
|
||||
}
|
||||
|
||||
QString StringSlider::GetValue() const
|
||||
{
|
||||
return GetValueInternal().toString();
|
||||
return GetValueInternal().toString();
|
||||
}
|
||||
|
||||
void StringSlider::SetValue(const QString &v)
|
||||
{
|
||||
SetValueInternal(v);
|
||||
SetValueInternal(v);
|
||||
}
|
||||
|
||||
void StringSlider::SetDefaultValue(const QString &v)
|
||||
{
|
||||
super::SetDefaultValue(v);
|
||||
super::SetDefaultValue(v);
|
||||
}
|
||||
|
||||
QString StringSlider::ValueToString(const QVariant &v) const
|
||||
{
|
||||
QString vstr = v.toString();
|
||||
return (vstr.isEmpty()) ? tr("(none)") : vstr;
|
||||
QString vstr = v.toString();
|
||||
return (vstr.isEmpty()) ? tr("(none)") : vstr;
|
||||
}
|
||||
|
||||
QVariant StringSlider::StringToValue(const QString &s, bool *ok) const
|
||||
{
|
||||
*ok = true;
|
||||
return s;
|
||||
*ok = true;
|
||||
return s;
|
||||
}
|
||||
|
||||
void StringSlider::ValueSignalEvent(const QVariant &value)
|
||||
{
|
||||
emit ValueChanged(value.toString());
|
||||
emit ValueChanged(value.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,32 +23,31 @@
|
||||
|
||||
#include "base/sliderbase.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class StringSlider : public SliderBase
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class StringSlider : public SliderBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
StringSlider(QWidget* parent = nullptr);
|
||||
StringSlider(QWidget *parent = nullptr);
|
||||
|
||||
void SetDragMultiplier(const double& d) = delete;
|
||||
void SetDragMultiplier(const double &d) = delete;
|
||||
|
||||
QString GetValue() const;
|
||||
QString GetValue() const;
|
||||
|
||||
void SetValue(const QString& v);
|
||||
void SetValue(const QString &v);
|
||||
|
||||
void SetDefaultValue(const QString& v);
|
||||
void SetDefaultValue(const QString &v);
|
||||
|
||||
signals:
|
||||
void ValueChanged(const QString& str);
|
||||
void ValueChanged(const QString &str);
|
||||
|
||||
protected:
|
||||
virtual QString ValueToString(const QVariant& value) const override;
|
||||
virtual QString ValueToString(const QVariant &value) const override;
|
||||
|
||||
virtual QVariant StringToValue(const QString &s, bool *ok) const override;
|
||||
|
||||
virtual void ValueSignalEvent(const QVariant &value) override;
|
||||
virtual QVariant StringToValue(const QString &s, bool *ok) const override;
|
||||
|
||||
virtual void ValueSignalEvent(const QVariant &value) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user