Skip to content

Commit

Permalink
damc_gui: set sliders to 0 on double click
Browse files Browse the repository at this point in the history
  • Loading branch information
amurzeau committed Jul 16, 2023
1 parent 6c97ef7 commit d0317f4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
19 changes: 19 additions & 0 deletions damc_gui/DoubleClickSlider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// From https://stackoverflow.com/questions/52550633/how-to-emit-a-signal-if-double-clicking-on-slider-handle

#include "DoubleClickSlider.h"
#include <QStyleOption>

DoubleClickSlider::DoubleClickSlider(QWidget* parent) : QSlider(parent) {}

void DoubleClickSlider::mouseDoubleClickEvent(QMouseEvent* event) {
QStyleOptionSlider opt;
this->initStyleOption(&opt);
QRect sr = this->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);

if(sr.contains(event->pos())) {
printf("Set slider to 0\n");
setValue(0);
} else {
QSlider::mouseDoubleClickEvent(event);
}
}
13 changes: 13 additions & 0 deletions damc_gui/DoubleClickSlider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <QMouseEvent>
#include <QSlider>

class DoubleClickSlider : public QSlider {
Q_OBJECT
public:
DoubleClickSlider(QWidget* parent = nullptr);

protected:
void mouseDoubleClickEvent(QMouseEvent* event) override;
};
35 changes: 20 additions & 15 deletions damc_gui/OutputController.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>62</width>
<width>70</width>
<height>391</height>
</rect>
</property>
Expand Down Expand Up @@ -94,6 +94,19 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>77</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="levelContainer" native="true">
<layout class="QHBoxLayout" name="levelContainerLayout">
Expand All @@ -116,20 +129,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>77</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSlider" name="volumeSlider">
<widget class="DoubleClickSlider" name="volumeSlider">
<property name="minimum">
<number>-80</number>
</property>
Expand Down Expand Up @@ -365,6 +365,11 @@
<header>FastLabelWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>DoubleClickSlider</class>
<extends>QSlider</extends>
<header>DoubleClickSlider.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>muteButton</tabstop>
Expand Down

0 comments on commit d0317f4

Please sign in to comment.