Move SliderSlider and PrettySlider into own files
This commit is contained in:
parent
25323b4a3a
commit
04f010aa7b
15
debian/copyright
vendored
15
debian/copyright
vendored
@ -5,10 +5,10 @@ Source: https://github.com/strawberrymusicplayer/strawberry
|
||||
|
||||
Files: *
|
||||
Copyright: 2010-2015, David Sansome <me@davidsansome.com>
|
||||
2012-2014, 2017-2022 Jonas Kvinge <jonas@jkvinge.net>
|
||||
2012-2014, 2017-2023 Jonas Kvinge <jonas@jkvinge.net>
|
||||
License: GPL-3+
|
||||
|
||||
Files: src/core/timeconstants.h
|
||||
Files: src/utilities/timeconstants.h
|
||||
ext/libstrawberry-common/core/logging.cpp
|
||||
ext/libstrawberry-common/core/logging.h
|
||||
ext/libstrawberry-common/core/messagehandler.cpp
|
||||
@ -98,7 +98,7 @@ Files: src/core/main.h
|
||||
ext/macdeploycheck/*
|
||||
src/widgets/resizabletextedit.cpp
|
||||
src/widgets/resizabletextedit.h
|
||||
Copyright: 2012-2014, 2017-2022, Jonas Kvinge <jonas@jkvinge.net>
|
||||
Copyright: 2012-2014, 2017-2023, Jonas Kvinge <jonas@jkvinge.net>
|
||||
License: GPL-3+
|
||||
|
||||
Files: src/engine/enginebase.cpp
|
||||
@ -227,9 +227,14 @@ Files: src/widgets/clickablelabel.cpp
|
||||
Copyright: 2010, 2011, Andrea Decorte <adecorte@gmail.com>
|
||||
License: GPL-3+
|
||||
|
||||
Files: src/widgets/volumeslider.cpp
|
||||
Files: src/widgets/sliderslider.cpp
|
||||
src/widgets/sliderslider.h
|
||||
src/widgets/prettyslider.cpp
|
||||
src/widgets/prettyslider.h
|
||||
src/widgets/volumeslider.cpp
|
||||
src/widgets/volumeslider.h
|
||||
Copyright: 2005, Gábor Lehel
|
||||
Copyright: 2018-2023, Jonas Kvinge <jonas@jkvinge.net>
|
||||
2005, Gábor Lehel
|
||||
2003, Mark Kretschmann <markey@web.de>
|
||||
License: GPL-2+
|
||||
|
||||
|
@ -218,6 +218,8 @@ set(SOURCES
|
||||
widgets/multiloadingindicator.cpp
|
||||
widgets/playingwidget.cpp
|
||||
widgets/renametablineedit.cpp
|
||||
widgets/sliderslider.cpp
|
||||
widgets/prettyslider.cpp
|
||||
widgets/volumeslider.cpp
|
||||
widgets/stickyslider.cpp
|
||||
widgets/stretchheaderview.cpp
|
||||
@ -448,6 +450,8 @@ set(HEADERS
|
||||
widgets/multiloadingindicator.h
|
||||
widgets/playingwidget.h
|
||||
widgets/renametablineedit.h
|
||||
widgets/sliderslider.h
|
||||
widgets/prettyslider.h
|
||||
widgets/volumeslider.h
|
||||
widgets/stickyslider.h
|
||||
widgets/stretchheaderview.h
|
||||
|
54
src/widgets/prettyslider.cpp
Normal file
54
src/widgets/prettyslider.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
prettyslider.cpp
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
copyright : (C) 2018-2023 by Jonas Kvinge
|
||||
email : jonas@jkvinge.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QSlider>
|
||||
#include <QStyle>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "prettyslider.h"
|
||||
|
||||
PrettySlider::PrettySlider(const Qt::Orientation orientation, const SliderMode mode, QWidget *parent, const uint max)
|
||||
: SliderSlider(orientation, parent, static_cast<int>(max)), m_mode(mode) {
|
||||
|
||||
if (m_mode == SliderMode_Pretty) {
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettySlider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
SliderSlider::mousePressEvent(e);
|
||||
|
||||
slideEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void PrettySlider::slideEvent(QMouseEvent *e) {
|
||||
|
||||
if (m_mode == SliderMode_Pretty) {
|
||||
QSlider::setValue(orientation() == Qt::Horizontal ? QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().x(), width() - 2) : QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().y(), height() - 2)); // clazy:exclude=skipped-base-method
|
||||
}
|
||||
else {
|
||||
SliderSlider::slideEvent(e);
|
||||
}
|
||||
|
||||
}
|
53
src/widgets/prettyslider.h
Normal file
53
src/widgets/prettyslider.h
Normal file
@ -0,0 +1,53 @@
|
||||
/***************************************************************************
|
||||
prettyslider.h
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
copyright : (C) 2018-2023 by Jonas Kvinge
|
||||
email : jonas@jkvinge.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef PRETTYSLIDER_H
|
||||
#define PRETTYSLIDER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "sliderslider.h"
|
||||
|
||||
class QMouseEvent;
|
||||
|
||||
class PrettySlider : public SliderSlider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum SliderMode {
|
||||
SliderMode_Normal, // Same behavior as Slider *unless* there's a moodbar
|
||||
SliderMode_Pretty
|
||||
};
|
||||
|
||||
explicit PrettySlider(const Qt::Orientation orientation, const SliderMode mode, QWidget *parent, const uint max = 0);
|
||||
|
||||
protected:
|
||||
void slideEvent(QMouseEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
|
||||
private:
|
||||
PrettySlider(const PrettySlider&); // undefined
|
||||
PrettySlider &operator=(const PrettySlider&); // undefined
|
||||
|
||||
SliderMode m_mode;
|
||||
};
|
||||
|
||||
#endif // PRETTYSLIDER_H
|
155
src/widgets/sliderslider.cpp
Normal file
155
src/widgets/sliderslider.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
/***************************************************************************
|
||||
sliderslider.cpp
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
copyright : (C) 2018-2023 by Jonas Kvinge
|
||||
email : jonas@jkvinge.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSlider>
|
||||
#include <QStyle>
|
||||
#include <QStyleOptionSlider>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include "sliderslider.h"
|
||||
|
||||
SliderSlider::SliderSlider(const Qt::Orientation orientation, QWidget *parent, const int max)
|
||||
: QSlider(orientation, parent),
|
||||
sliding_(false),
|
||||
wheeling_(false),
|
||||
outside_(false),
|
||||
prev_value_(0) {
|
||||
|
||||
setRange(0, max);
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::SetValue(const uint value) {
|
||||
|
||||
setValue(static_cast<int>(value));
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::setValue(int value) {
|
||||
|
||||
// Don't adjust the slider while the user is dragging it!
|
||||
|
||||
if ((!sliding_ || outside_) && !wheeling_) {
|
||||
QSlider::setValue(adjustValue(value));
|
||||
}
|
||||
else {
|
||||
prev_value_ = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int SliderSlider::adjustValue(int v) const {
|
||||
int mp = (minimum() + maximum()) / 2;
|
||||
return orientation() == Qt::Vertical ? mp - (v - mp) : v;
|
||||
}
|
||||
|
||||
void SliderSlider::slideEvent(QMouseEvent *e) {
|
||||
|
||||
QStyleOptionSlider option;
|
||||
initStyleOption(&option);
|
||||
QRect sliderRect(style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this));
|
||||
|
||||
QSlider::setValue(
|
||||
orientation() == Qt::Horizontal
|
||||
? ((QApplication::layoutDirection() == Qt::RightToLeft)
|
||||
? QStyle::sliderValueFromPosition(
|
||||
minimum(), maximum(),
|
||||
width() - (e->pos().x() - sliderRect.width() / 2),
|
||||
width() + sliderRect.width(), true)
|
||||
: QStyle::sliderValueFromPosition(
|
||||
minimum(), maximum(),
|
||||
e->pos().x() - sliderRect.width() / 2,
|
||||
width() - sliderRect.width()))
|
||||
: QStyle::sliderValueFromPosition(
|
||||
minimum(), maximum(), e->pos().y() - sliderRect.height() / 2,
|
||||
height() - sliderRect.height()));
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::mouseMoveEvent(QMouseEvent *e) {
|
||||
|
||||
if (sliding_) {
|
||||
// feels better, but using set value of 20 is bad of course
|
||||
QRect rect(-20, -20, width() + 40, height() + 40);
|
||||
|
||||
if (orientation() == Qt::Horizontal && !rect.contains(e->pos())) {
|
||||
if (!outside_) QSlider::setValue(prev_value_);
|
||||
outside_ = true;
|
||||
}
|
||||
else {
|
||||
outside_ = false;
|
||||
slideEvent(e);
|
||||
emit sliderMoved(value());
|
||||
}
|
||||
}
|
||||
else {
|
||||
QSlider::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
QStyleOptionSlider option;
|
||||
initStyleOption(&option);
|
||||
QRect sliderRect(style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this));
|
||||
|
||||
sliding_ = true;
|
||||
prev_value_ = QSlider::value();
|
||||
|
||||
if (!sliderRect.contains(e->pos())) mouseMoveEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::mouseReleaseEvent(QMouseEvent*) {
|
||||
|
||||
if (!outside_ && QSlider::value() != prev_value_) {
|
||||
emit SliderReleased(value());
|
||||
}
|
||||
|
||||
sliding_ = false;
|
||||
outside_ = false;
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::wheelEvent(QWheelEvent *e) {
|
||||
|
||||
if (orientation() == Qt::Vertical) {
|
||||
// Will be handled by the parent widget
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
wheeling_ = true;
|
||||
|
||||
// Position Slider (horizontal)
|
||||
int step = e->angleDelta().y() * 1500 / 18;
|
||||
int nval = qBound(minimum(), QSlider::value() + step, maximum());
|
||||
|
||||
QSlider::setValue(nval);
|
||||
|
||||
emit SliderReleased(value());
|
||||
|
||||
wheeling_ = false;
|
||||
|
||||
}
|
68
src/widgets/sliderslider.h
Normal file
68
src/widgets/sliderslider.h
Normal file
@ -0,0 +1,68 @@
|
||||
/***************************************************************************
|
||||
sliderslider.h
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
copyright : (C) 2018-2023 by Jonas Kvinge
|
||||
email : jonas@jkvinge.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SLIDERSLIDER_H
|
||||
#define SLIDERSLIDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSlider>
|
||||
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
class SliderSlider : public QSlider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SliderSlider(const Qt::Orientation, QWidget*, const int max = 0);
|
||||
|
||||
// WARNING non-virtual - and thus only really intended for internal use this is a major flaw in the class presently, however it suits our current needs fine
|
||||
int value() const { return adjustValue(QSlider::value()); }
|
||||
|
||||
virtual void SetValue(const uint value);
|
||||
virtual void setValue(int value);
|
||||
|
||||
signals:
|
||||
// We emit this when the user has specifically changed the slider so connect to it if valueChanged() is too generic Qt also emits valueChanged(int)
|
||||
void SliderReleased(int);
|
||||
|
||||
protected:
|
||||
virtual void slideEvent(QMouseEvent*);
|
||||
void mouseMoveEvent(QMouseEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
void wheelEvent(QWheelEvent*) override;
|
||||
|
||||
bool sliding_;
|
||||
bool wheeling_;
|
||||
|
||||
/// we flip the value for vertical sliders
|
||||
int adjustValue(int v) const;
|
||||
|
||||
private:
|
||||
bool outside_;
|
||||
int prev_value_;
|
||||
|
||||
SliderSlider(const SliderSlider&);
|
||||
SliderSlider &operator=(const SliderSlider&);
|
||||
};
|
||||
|
||||
#endif // SLIDERSLIDER_H
|
@ -1,11 +1,13 @@
|
||||
/***************************************************************************
|
||||
amarokslider.cpp - description
|
||||
-------------------
|
||||
volumeslider.cpp
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
copyright : (C) 2018-2023 by Jonas Kvinge
|
||||
email : jonas@jkvinge.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
@ -17,16 +19,14 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "volumeslider.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QSlider>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QPalette>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QPalette>
|
||||
#include <QFont>
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
@ -38,184 +38,19 @@
|
||||
#include <QStyleOption>
|
||||
#include <QTimer>
|
||||
#include <QAction>
|
||||
#include <QSlider>
|
||||
#include <QLinearGradient>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QFlags>
|
||||
#include <QtEvents>
|
||||
|
||||
SliderSlider::SliderSlider(const Qt::Orientation orientation, QWidget *parent, const int max)
|
||||
: QSlider(orientation, parent),
|
||||
sliding_(false),
|
||||
wheeling_(false),
|
||||
outside_(false),
|
||||
prev_value_(0) {
|
||||
|
||||
setRange(0, max);
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::wheelEvent(QWheelEvent *e) {
|
||||
|
||||
if (orientation() == Qt::Vertical) {
|
||||
// Will be handled by the parent widget
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
wheeling_ = true;
|
||||
|
||||
// Position Slider (horizontal)
|
||||
int step = e->angleDelta().y() * 1500 / 18;
|
||||
int nval = qBound(minimum(), QSlider::value() + step, maximum());
|
||||
|
||||
QSlider::setValue(nval);
|
||||
|
||||
emit SliderReleased(value());
|
||||
|
||||
wheeling_ = false;
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::mouseMoveEvent(QMouseEvent *e) {
|
||||
|
||||
if (sliding_) {
|
||||
// feels better, but using set value of 20 is bad of course
|
||||
QRect rect(-20, -20, width() + 40, height() + 40);
|
||||
|
||||
if (orientation() == Qt::Horizontal && !rect.contains(e->pos())) {
|
||||
if (!outside_) QSlider::setValue(prev_value_);
|
||||
outside_ = true;
|
||||
}
|
||||
else {
|
||||
outside_ = false;
|
||||
slideEvent(e);
|
||||
emit sliderMoved(value());
|
||||
}
|
||||
}
|
||||
else {
|
||||
QSlider::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::slideEvent(QMouseEvent *e) {
|
||||
|
||||
QStyleOptionSlider option;
|
||||
initStyleOption(&option);
|
||||
QRect sliderRect(style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this));
|
||||
|
||||
QSlider::setValue(
|
||||
orientation() == Qt::Horizontal
|
||||
? ((QApplication::layoutDirection() == Qt::RightToLeft)
|
||||
? QStyle::sliderValueFromPosition(
|
||||
minimum(), maximum(),
|
||||
width() - (e->pos().x() - sliderRect.width() / 2),
|
||||
width() + sliderRect.width(), true)
|
||||
: QStyle::sliderValueFromPosition(
|
||||
minimum(), maximum(),
|
||||
e->pos().x() - sliderRect.width() / 2,
|
||||
width() - sliderRect.width()))
|
||||
: QStyle::sliderValueFromPosition(
|
||||
minimum(), maximum(), e->pos().y() - sliderRect.height() / 2,
|
||||
height() - sliderRect.height()));
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
QStyleOptionSlider option;
|
||||
initStyleOption(&option);
|
||||
QRect sliderRect(style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this));
|
||||
|
||||
sliding_ = true;
|
||||
prev_value_ = QSlider::value();
|
||||
|
||||
if (!sliderRect.contains(e->pos())) mouseMoveEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::mouseReleaseEvent(QMouseEvent*) {
|
||||
|
||||
if (!outside_ && QSlider::value() != prev_value_) {
|
||||
emit SliderReleased(value());
|
||||
}
|
||||
|
||||
sliding_ = false;
|
||||
outside_ = false;
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::SetValue(const uint value) {
|
||||
|
||||
setValue(static_cast<int>(value));
|
||||
|
||||
}
|
||||
|
||||
void SliderSlider::setValue(int value) {
|
||||
|
||||
// Don't adjust the slider while the user is dragging it!
|
||||
|
||||
if ((!sliding_ || outside_) && !wheeling_) {
|
||||
QSlider::setValue(adjustValue(value));
|
||||
}
|
||||
else {
|
||||
prev_value_ = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// CLASS PrettySlider
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PrettySlider::PrettySlider(const Qt::Orientation orientation, const SliderMode mode, QWidget *parent, const uint max)
|
||||
: SliderSlider(orientation, parent, static_cast<int>(max)), m_mode(mode) {
|
||||
|
||||
if (m_mode == Pretty) {
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettySlider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
SliderSlider::mousePressEvent(e);
|
||||
|
||||
slideEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void PrettySlider::slideEvent(QMouseEvent *e) {
|
||||
|
||||
if (m_mode == Pretty) {
|
||||
QSlider::setValue(orientation() == Qt::Horizontal ? QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().x(), width() - 2) : QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().y(), height() - 2)); // clazy:exclude=skipped-base-method
|
||||
}
|
||||
else {
|
||||
SliderSlider::slideEvent(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
/** these functions aren't required in our fixed size world, but they may become useful one day **/
|
||||
|
||||
QSize PrettySlider::minimumSizeHint() const {
|
||||
return sizeHint();
|
||||
}
|
||||
|
||||
QSize PrettySlider::sizeHint() const {
|
||||
constPolish();
|
||||
|
||||
return (orientation() == Horizontal
|
||||
? QSize( maxValue(), THICKNESS + MARGIN )
|
||||
: QSize( THICKNESS + MARGIN, maxValue() )).expandedTo( QApplit ication::globalStrut() );
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
# include <QEnterEvent>
|
||||
#else
|
||||
# include <QEvent>
|
||||
#endif
|
||||
#include <QPaintEvent>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// CLASS VolumeSlider
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "volumeslider.h"
|
||||
|
||||
VolumeSlider::VolumeSlider(QWidget *parent, const uint max)
|
||||
: SliderSlider(Qt::Horizontal, parent, static_cast<int>(max)),
|
||||
@ -245,86 +80,6 @@ void VolumeSlider::SetEnabled(const bool enabled) {
|
||||
QSlider::setVisible(enabled);
|
||||
}
|
||||
|
||||
void VolumeSlider::generateGradient() {
|
||||
|
||||
const QImage mask(":/pictures/volumeslider-gradient.png");
|
||||
|
||||
QImage gradient_image(mask.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
QPainter p(&gradient_image);
|
||||
|
||||
QLinearGradient gradient(gradient_image.rect().topLeft(), gradient_image.rect().topRight());
|
||||
gradient.setColorAt(0, palette().color(QPalette::Window));
|
||||
gradient.setColorAt(1, palette().color(QPalette::Highlight));
|
||||
p.fillRect(gradient_image.rect(), QBrush(gradient));
|
||||
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
p.drawImage(0, 0, mask);
|
||||
p.end();
|
||||
|
||||
pixmap_gradient_ = QPixmap::fromImage(gradient_image);
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::slotAnimTimer() {
|
||||
|
||||
if (anim_enter_) {
|
||||
++anim_count_;
|
||||
update();
|
||||
if (anim_count_ == ANIM_MAX - 1) timer_anim_->stop();
|
||||
}
|
||||
else {
|
||||
--anim_count_;
|
||||
update();
|
||||
if (anim_count_ == 0) timer_anim_->stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
if (e->button() != Qt::RightButton) {
|
||||
SliderSlider::mousePressEvent(e);
|
||||
slideEvent(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
QHash<QAction*, int> values;
|
||||
QMenu menu;
|
||||
menu.setTitle("Volume");
|
||||
values[menu.addAction("100%")] = 100;
|
||||
values[menu.addAction("80%")] = 80;
|
||||
values[menu.addAction("60%")] = 60;
|
||||
values[menu.addAction("40%")] = 40;
|
||||
values[menu.addAction("20%")] = 20;
|
||||
values[menu.addAction("0%")] = 0;
|
||||
|
||||
QAction *ret = menu.exec(mapToGlobal(e->pos()));
|
||||
if (ret) {
|
||||
QSlider::setValue(values[ret]);
|
||||
emit SliderReleased(values[ret]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::slideEvent(QMouseEvent *e) {
|
||||
QSlider::setValue(QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().x(), width() - 2));
|
||||
}
|
||||
|
||||
void VolumeSlider::wheelEvent(QWheelEvent *e) {
|
||||
|
||||
wheeling_ = true;
|
||||
|
||||
const int step = e->angleDelta().y() / (e->angleDelta().x() == 0 ? 30 : -30);
|
||||
QSlider::setValue(SliderSlider::value() + step);
|
||||
emit SliderReleased(value());
|
||||
|
||||
wheeling_ = false;
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::paintEvent(QPaintEvent*) {
|
||||
|
||||
QPainter p(this);
|
||||
@ -358,26 +113,38 @@ void VolumeSlider::paintEvent(QPaintEvent*) {
|
||||
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void VolumeSlider::enterEvent(QEnterEvent*) {
|
||||
#else
|
||||
void VolumeSlider::enterEvent(QEvent*) {
|
||||
#endif
|
||||
void VolumeSlider::generateGradient() {
|
||||
|
||||
anim_enter_ = true;
|
||||
anim_count_ = 0;
|
||||
const QImage mask(":/pictures/volumeslider-gradient.png");
|
||||
|
||||
timer_anim_->start(ANIM_INTERVAL);
|
||||
QImage gradient_image(mask.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
QPainter p(&gradient_image);
|
||||
|
||||
QLinearGradient gradient(gradient_image.rect().topLeft(), gradient_image.rect().topRight());
|
||||
gradient.setColorAt(0, palette().color(QPalette::Window));
|
||||
gradient.setColorAt(1, palette().color(QPalette::Highlight));
|
||||
p.fillRect(gradient_image.rect(), QBrush(gradient));
|
||||
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
p.drawImage(0, 0, mask);
|
||||
p.end();
|
||||
|
||||
pixmap_gradient_ = QPixmap::fromImage(gradient_image);
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::leaveEvent(QEvent*) {
|
||||
void VolumeSlider::slotAnimTimer() {
|
||||
|
||||
// This can happen if you enter and leave the widget quickly
|
||||
if (anim_count_ == 0) anim_count_ = 1;
|
||||
|
||||
anim_enter_ = false;
|
||||
timer_anim_->start(ANIM_INTERVAL);
|
||||
if (anim_enter_) {
|
||||
++anim_count_;
|
||||
update();
|
||||
if (anim_count_ == ANIM_MAX - 1) timer_anim_->stop();
|
||||
}
|
||||
else {
|
||||
--anim_count_;
|
||||
update();
|
||||
if (anim_count_ == 0) timer_anim_->stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -447,3 +214,71 @@ void VolumeSlider::drawVolumeSliderHandle() {
|
||||
// END
|
||||
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void VolumeSlider::enterEvent(QEnterEvent*) {
|
||||
#else
|
||||
void VolumeSlider::enterEvent(QEvent*) {
|
||||
#endif
|
||||
|
||||
anim_enter_ = true;
|
||||
anim_count_ = 0;
|
||||
|
||||
timer_anim_->start(ANIM_INTERVAL);
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::leaveEvent(QEvent*) {
|
||||
|
||||
// This can happen if you enter and leave the widget quickly
|
||||
if (anim_count_ == 0) anim_count_ = 1;
|
||||
|
||||
anim_enter_ = false;
|
||||
timer_anim_->start(ANIM_INTERVAL);
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
QHash<QAction*, int> values;
|
||||
QMenu menu;
|
||||
menu.setTitle("Volume");
|
||||
values[menu.addAction("100%")] = 100;
|
||||
values[menu.addAction("80%")] = 80;
|
||||
values[menu.addAction("60%")] = 60;
|
||||
values[menu.addAction("40%")] = 40;
|
||||
values[menu.addAction("20%")] = 20;
|
||||
values[menu.addAction("0%")] = 0;
|
||||
|
||||
QAction *ret = menu.exec(mapToGlobal(e->pos()));
|
||||
if (ret) {
|
||||
QSlider::setValue(values[ret]);
|
||||
emit SliderReleased(values[ret]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::slideEvent(QMouseEvent *e) {
|
||||
QSlider::setValue(QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().x(), width() - 2));
|
||||
}
|
||||
|
||||
void VolumeSlider::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
if (e->button() != Qt::RightButton) {
|
||||
SliderSlider::mousePressEvent(e);
|
||||
slideEvent(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VolumeSlider::wheelEvent(QWheelEvent *e) {
|
||||
|
||||
wheeling_ = true;
|
||||
|
||||
const int step = e->angleDelta().y() / (e->angleDelta().x() == 0 ? 30 : -30);
|
||||
QSlider::setValue(SliderSlider::value() + step);
|
||||
emit SliderReleased(value());
|
||||
|
||||
wheeling_ = false;
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
/***************************************************************************
|
||||
amarokslider.h - description
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
***************************************************************************/
|
||||
volumeslider.h
|
||||
-------------------
|
||||
begin : Dec 15 2003
|
||||
copyright : (C) 2003 by Mark Kretschmann
|
||||
email : markey@web.de
|
||||
copyright : (C) 2005 by Gábor Lehel
|
||||
email : illissius@gmail.com
|
||||
copyright : (C) 2018-2023 by Jonas Kvinge
|
||||
email : jonas@jkvinge.net
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
@ -22,83 +24,23 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QPixmap>
|
||||
#include <QColor>
|
||||
#include <QPalette>
|
||||
#include <QSlider>
|
||||
#include <QColor>
|
||||
|
||||
#include "sliderslider.h"
|
||||
|
||||
class QTimer;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
class QEnterEvent;
|
||||
#else
|
||||
class QEvent;
|
||||
class QMouseEvent;
|
||||
#endif
|
||||
class QPaintEvent;
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
class QContextMenuEvent;
|
||||
class QEnterEvent;
|
||||
|
||||
class SliderSlider : public QSlider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SliderSlider(const Qt::Orientation, QWidget*, const int max = 0);
|
||||
|
||||
virtual void SetValue(const uint value);
|
||||
virtual void setValue(int value);
|
||||
|
||||
// WARNING non-virtual - and thus only really intended for internal use this is a major flaw in the class presently, however it suits our current needs fine
|
||||
int value() const { return adjustValue(QSlider::value()); }
|
||||
|
||||
signals:
|
||||
// We emit this when the user has specifically changed the slider so connect to it if valueChanged() is too generic Qt also emits valueChanged(int)
|
||||
void SliderReleased(int);
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent*) override;
|
||||
void mouseMoveEvent(QMouseEvent*) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
virtual void slideEvent(QMouseEvent*);
|
||||
|
||||
bool sliding_;
|
||||
bool wheeling_;
|
||||
|
||||
/// we flip the value for vertical sliders
|
||||
int adjustValue(int v) const {
|
||||
int mp = (minimum() + maximum()) / 2;
|
||||
return orientation() == Qt::Vertical ? mp - (v - mp) : v;
|
||||
}
|
||||
|
||||
private:
|
||||
bool outside_;
|
||||
int prev_value_;
|
||||
|
||||
SliderSlider(const SliderSlider&); // undefined
|
||||
SliderSlider &operator=(const SliderSlider&); // undefined
|
||||
};
|
||||
|
||||
class PrettySlider : public SliderSlider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using SliderMode = enum {
|
||||
Normal, // Same behavior as Slider *unless* there's a moodbar
|
||||
Pretty
|
||||
};
|
||||
|
||||
explicit PrettySlider(const Qt::Orientation orientation, const SliderMode mode, QWidget *parent, const uint max = 0);
|
||||
|
||||
protected:
|
||||
void slideEvent(QMouseEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
|
||||
private:
|
||||
PrettySlider(const PrettySlider&); // undefined
|
||||
PrettySlider &operator=(const PrettySlider&); // undefined
|
||||
|
||||
SliderMode m_mode;
|
||||
};
|
||||
|
||||
class VolumeSlider : public SliderSlider {
|
||||
Q_OBJECT
|
||||
@ -108,34 +50,33 @@ class VolumeSlider : public SliderSlider {
|
||||
void SetEnabled(const bool enabled);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void enterEvent(QEnterEvent*) override;
|
||||
#else
|
||||
void enterEvent(QEvent*) override;
|
||||
#endif
|
||||
void leaveEvent(QEvent*) override;
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
virtual void paletteChange(const QPalette&);
|
||||
void slideEvent(QMouseEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void contextMenuEvent(QContextMenuEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
|
||||
private slots:
|
||||
virtual void slotAnimTimer();
|
||||
|
||||
private:
|
||||
static const int ANIM_INTERVAL = 18;
|
||||
static const int ANIM_MAX = 18;
|
||||
|
||||
VolumeSlider(const VolumeSlider&);
|
||||
VolumeSlider &operator=(const VolumeSlider&);
|
||||
|
||||
void generateGradient();
|
||||
QPixmap drawVolumePixmap() const;
|
||||
void drawVolumeSliderHandle();
|
||||
|
||||
VolumeSlider(const VolumeSlider&); // undefined
|
||||
VolumeSlider &operator=(const VolumeSlider&); // undefined
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
static const int ANIM_INTERVAL = 18;
|
||||
static const int ANIM_MAX = 18;
|
||||
|
||||
bool anim_enter_;
|
||||
int anim_count_;
|
||||
QTimer *timer_anim_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user