Skip to content

Commit

Permalink
slider: use cursor-less drag when no multipliers are active
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Apr 13, 2021
1 parent afed4f4 commit 51064f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions app/widget/slider/sliderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ QString SliderBase::GetFormat() const
}
}

bool SliderBase::UsingLadders() const
{
return ladder_element_count_ > 0 && Config::Current()[QStringLiteral("UseSliderLadders")].toBool();
}

void SliderBase::UpdateLabel(const QVariant &v)
{
if (tristate_) {
Expand Down Expand Up @@ -303,7 +308,7 @@ void SliderBase::LadderDragged(int value, double multiplier)

drag_ladder_->SetValue(ValueToString(clamped_temp_dragged_value_));

if (!Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
if (!UsingLadders()) {
RepositionLadder();
}

Expand Down Expand Up @@ -394,7 +399,7 @@ void SliderBase::ResetValue()
void SliderBase::RepositionLadder()
{
if (drag_ladder_) {
if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
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());
Expand Down
2 changes: 2 additions & 0 deletions app/widget/slider/sliderbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class SliderBase : public QStackedWidget

QString GetFormat() const;

bool UsingLadders() const;

SliderLabel* label_;

FocusableLineEdit* editor_;
Expand Down
11 changes: 8 additions & 3 deletions app/widget/slider/sliderladder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QWidget*
drag_timer_.setInterval(10);
connect(&drag_timer_, &QTimer::timeout, this, &SliderLadder::TimerUpdate);

if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
if (UsingLadders()) {
drag_start_x_ = -1;
} else {
#if defined(Q_OS_MAC)
Expand All @@ -94,7 +94,7 @@ SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QWidget*

SliderLadder::~SliderLadder()
{
if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
if (UsingLadders()) {

} else {
#if defined(Q_OS_MAC)
Expand Down Expand Up @@ -142,7 +142,7 @@ void SliderLadder::TimerUpdate()
int ladder_right = this->x() + this->width() - 1;
int now_pos = QCursor::pos().x();

if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
if (UsingLadders()) {

bool is_under_mouse = (now_pos >= ladder_left && now_pos <= ladder_right);

Expand Down Expand Up @@ -226,6 +226,11 @@ void SliderLadder::TimerUpdate()
}
}

bool SliderLadder::UsingLadders() const
{
return elements_.size() > 1;
}

SliderLadderElement::SliderLadderElement(const double &multiplier, QWidget *parent) :
QWidget(parent),
multiplier_(multiplier),
Expand Down
2 changes: 2 additions & 0 deletions app/widget/slider/sliderladder.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SliderLadder : public QFrame
void Released();

private:
bool UsingLadders() const;

int drag_start_x_;
int drag_start_y_;

Expand Down

0 comments on commit 51064f4

Please sign in to comment.