Make the equalizer sliders stick in the middle around '0' when being dragged. Updates issue #166

This commit is contained in:
David Sansome 2010-04-11 13:29:27 +00:00
parent 8c1bdd1bf6
commit e6da826227
5 changed files with 96 additions and 1 deletions

View File

@ -72,6 +72,7 @@ set(CLEMENTINE-SOURCES
equalizer.cpp
equalizerslider.cpp
tracksliderslider.cpp
stickyslider.cpp
)
# Header files that have Q_OBJECT in
@ -134,6 +135,7 @@ set(CLEMENTINE-MOC-HEADERS
groupbydialog.h
equalizer.h
equalizerslider.h
stickyslider.h
)
# UI files

View File

@ -21,6 +21,7 @@
#include "ui_equalizerslider.h"
// Contains the slider and the label
class EqualizerSlider : public QWidget {
Q_OBJECT

View File

@ -33,7 +33,7 @@
</spacer>
</item>
<item>
<widget class="QSlider" name="slider">
<widget class="StickySlider" name="slider">
<property name="minimum">
<number>-100</number>
</property>
@ -43,6 +43,12 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sticky_center" stdset="0">
<number>0</number>
</property>
<property name="sticky_threshold" stdset="0">
<number>10</number>
</property>
</widget>
</item>
<item>
@ -69,6 +75,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>StickySlider</class>
<extends>QSlider</extends>
<header>stickyslider.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

36
src/stickyslider.cpp Normal file
View File

@ -0,0 +1,36 @@
/* This file is part of Clementine.
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stickyslider.h"
StickySlider::StickySlider(QWidget *parent)
: QSlider(parent),
sticky_center_(-1),
sticky_threshold_(10)
{
}
void StickySlider::mouseMoveEvent(QMouseEvent *e) {
QSlider::mouseMoveEvent(e);
if (sticky_center_ == -1)
return;
const int v = value();
if (v <= sticky_center_ + sticky_threshold_ &&
v >= sticky_center_ - sticky_threshold_)
setValue(sticky_center_);
}

43
src/stickyslider.h Normal file
View File

@ -0,0 +1,43 @@
/* This file is part of Clementine.
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STICKYSLIDER_H
#define STICKYSLIDER_H
#include <QSlider>
class StickySlider : public QSlider {
Q_OBJECT
Q_PROPERTY(int sticky_center READ sticky_center WRITE set_sticky_center);
Q_PROPERTY(int sticky_threshold READ sticky_threshold WRITE set_sticky_threshold);
public:
StickySlider(QWidget* parent = 0);
int sticky_center() const { return sticky_center_; }
int sticky_threshold() const { return sticky_threshold_; }
void set_sticky_center(int center) { sticky_center_ = center; }
void set_sticky_threshold(int threshold) { sticky_threshold_ = threshold; }
protected:
void mouseMoveEvent(QMouseEvent* e);
private:
int sticky_center_;
int sticky_threshold_;
};
#endif // STICKYSLIDER_H