Skip to content

Commit

Permalink
Experiemental slider improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jan 4, 2024
1 parent 8dc98c9 commit 85c3c3e
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 24 deletions.
12 changes: 11 additions & 1 deletion src/mumble/ListenerVolumeSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ void ListenerVolumeSlider::setListenedChannel(const Channel &channel) {

void ListenerVolumeSlider::on_VolumeSlider_valueChanged(int value) {
updateTooltip(value);
displayTooltip(value);
}

void ListenerVolumeSlider::on_VolumeSlider_sliderReleased() {
VolumeAdjustment adjustment = VolumeAdjustment::fromDBAdjustment(m_volumeSlider->value());

updateLabelValue(adjustment.dbAdjustment);

emit on_VolumeSlider_changeCompleted();
}

void ListenerVolumeSlider::on_VolumeSlider_changeCompleted() {
Expand Down Expand Up @@ -61,6 +68,7 @@ void ListenerVolumeSlider::on_VolumeSlider_changeCompleted() {
// Before the new audio protocol, volume adjustments for listeners are handled locally
Global::get().channelListenerManager->setListenerVolumeAdjustment(Global::get().uiSession, m_channel->iId,
adjustment);
updateLabelValue(adjustment.dbAdjustment);
}
}

Expand All @@ -81,4 +89,6 @@ void ListenerVolumeSlider::sendToServer() {
adjustmentMsg->set_volume_adjustment(m_cachedAdjustment.factor);

handler->sendMessage(mpus);

updateLabelValue(m_cachedAdjustment.dbAdjustment);
}
1 change: 1 addition & 0 deletions src/mumble/ListenerVolumeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ListenerVolumeSlider : public VolumeSliderWidgetAction {
void sendToServer();

private slots:
void on_VolumeSlider_sliderReleased() override;
void on_VolumeSlider_valueChanged(int value) override;
void on_VolumeSlider_changeCompleted() override;
};
Expand Down
1 change: 1 addition & 0 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#endif

#include <QAccessible>
#include <QResizeEvent>
#include <QtCore/QStandardPaths>
#include <QtCore/QUrlQuery>
#include <QtGui/QClipboard>
Expand Down
41 changes: 39 additions & 2 deletions src/mumble/MenuLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,50 @@

#include <QLabel>

MenuLabel::MenuLabel(const QString &text, QObject *parent) : QWidgetAction(parent), m_text(text) {
MenuLabel::MenuLabel(const QString &text, QObject *parent)
: QWidgetAction(parent), m_text(text), m_accessibleName(""), m_accessibleDescription("") {
setMenuRole(QAction::NoRole);
}

QWidget *MenuLabel::createWidget(QWidget *parent) {
QLabel *label = new QLabel(m_text, parent);
label->setFocusPolicy(Qt::TabFocus);

label->setAccessibleName(m_accessibleName);
label->setAccessibleDescription(m_accessibleDescription);

return label;
}

QString MenuLabel::text() {
return m_text;
}

void MenuLabel::setText(const QString &text) {
m_text = text;

QLabel *label = qobject_cast< QLabel * >(defaultWidget());
if (label) {
label->setText(text);
label->update();
}
}

void MenuLabel::setAccessibleName(const QString &name) {
m_accessibleName = name;

QLabel *label = qobject_cast< QLabel * >(defaultWidget());
if (label) {
label->setAccessibleName(m_accessibleName);
label->update();
}
}

void MenuLabel::setAccessibleDescription(const QString &description) {
m_accessibleDescription = description;

QLabel *label = qobject_cast< QLabel * >(defaultWidget());
if (label) {
label->setAccessibleDescription(m_accessibleDescription);
label->update();
}
}
9 changes: 8 additions & 1 deletion src/mumble/MenuLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ class MenuLabel : public QWidgetAction {
public:
MenuLabel(const QString &text, QObject *parent = nullptr);

QString text();
void setText(const QString &name);
void setAccessibleName(const QString &name);
void setAccessibleDescription(const QString &description);

protected:
QWidget *createWidget(QWidget *parent) override;

private:
const QString m_text;
QString m_text;
QString m_accessibleName;
QString m_accessibleDescription;
};

#endif
11 changes: 10 additions & 1 deletion src/mumble/UserLocalVolumeSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ void UserLocalVolumeSlider::on_VolumeSlider_valueChanged(int value) {
ClientUser *user = ClientUser::get(m_clientSession);

updateTooltip(value);
displayTooltip(value);

if (user) {
float factor = VolumeAdjustment::toFactor(value);
user->setLocalVolumeAdjustment(factor);
}
}

void UserLocalVolumeSlider::on_VolumeSlider_sliderReleased() {
ClientUser *user = ClientUser::get(sessionId);

if (user) {
updateLabelValue(VolumeAdjustment::toDBAdjustment(user->getLocalVolumeAdjustments()));
}

emit on_VolumeSlider_changeCompleted();
}

void UserLocalVolumeSlider::on_VolumeSlider_changeCompleted() {
ClientUser *user = ClientUser::get(m_clientSession);
if (user) {
Expand Down
5 changes: 3 additions & 2 deletions src/mumble/UserLocalVolumeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class UserLocalVolumeSlider : public VolumeSliderWidgetAction {
void setUser(unsigned int sessionId);

private slots:
void on_VolumeSlider_valueChanged(int value);
void on_VolumeSlider_changeCompleted();
void on_VolumeSlider_sliderReleased() override;
void on_VolumeSlider_valueChanged(int value) override;
void on_VolumeSlider_changeCompleted() override;
};

#endif
47 changes: 32 additions & 15 deletions src/mumble/VolumeSliderWidgetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@

#include <QSlider>
#include <QToolTip>
#include <QHBoxLayout>
#include <QLabel>

VolumeSliderWidgetAction::VolumeSliderWidgetAction(QWidget *parent)
: QWidgetAction(parent), m_volumeSlider(make_qt_unique< QSlider >(Qt::Horizontal, parent)) {
: QWidgetAction(parent),
m_widget(make_qt_unique< QWidget >(parent)),
m_volumeSlider(new QSlider(Qt::Horizontal, parent)),
m_label(new QLabel("0 db", parent)) {

m_volumeSlider->setMinimum(-30);
m_volumeSlider->setMaximum(30);
m_volumeSlider->setAccessibleName(tr("Slider for volume adjustment"));
m_volumeSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_volumeSlider->setAccessibleName(tr("Local volume adjustment"));

m_label->setStyleSheet("QLabel { margin-left: 0px; padding: 0px; }");
m_volumeSlider->setStyleSheet("QSlider { margin-right: 0px; }");

KeyEventObserver *keyEventFilter = new KeyEventObserver(this, QEvent::KeyRelease, false,
{ Qt::Key_Left, Qt::Key_Right, Qt::Key_Up, Qt::Key_Down });
{ Qt::Key_Left, Qt::Key_Right });
m_volumeSlider->installEventFilter(keyEventFilter);

// The list of wheel events observed seems odd at first. We have to check for multiple
Expand All @@ -33,27 +41,42 @@ VolumeSliderWidgetAction::VolumeSliderWidgetAction(QWidget *parent)
new MouseWheelEventObserver(this, { Qt::ScrollMomentum, Qt::ScrollUpdate, Qt::ScrollEnd }, false);
m_volumeSlider->installEventFilter(wheelEventFilter);

connect(m_volumeSlider.get(), &QSlider::valueChanged, this,
connect(m_volumeSlider, &QSlider::valueChanged, this,
&VolumeSliderWidgetAction::on_VolumeSlider_valueChanged);
connect(m_volumeSlider.get(), &QSlider::sliderReleased, this,
&VolumeSliderWidgetAction::on_VolumeSlider_changeCompleted);
connect(m_volumeSlider, &QSlider::sliderReleased, this,
&VolumeSliderWidgetAction::on_VolumeSlider_sliderReleased);
connect(keyEventFilter, &KeyEventObserver::keyEventObserved, this,
&VolumeSliderWidgetAction::on_VolumeSlider_changeCompleted);
connect(wheelEventFilter, &MouseWheelEventObserver::wheelEventObserved, this,
&VolumeSliderWidgetAction::on_VolumeSlider_changeCompleted);

setDefaultWidget(m_volumeSlider.get());

UpDownKeyEventFilter *eventFilter = new UpDownKeyEventFilter(this);
m_volumeSlider->installEventFilter(eventFilter);

m_volumeSlider->setProperty("mouseTracking", true);

QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(m_volumeSlider);
layout->addWidget(m_label);
layout->setContentsMargins(0, 0, -1, 0);
layout->setSpacing(3);
m_widget->setLayout(layout);

m_widget->setFocusProxy(m_volumeSlider);
m_widget->setFocusPolicy(Qt::TabFocus);

setDefaultWidget(m_widget.get());
}

void VolumeSliderWidgetAction::updateLabelValue(int value) {
m_label->setText(QString("%01dB").arg(value));
}

void VolumeSliderWidgetAction::updateSliderValue(float value) {
int dbShift = VolumeAdjustment::toIntegerDBAdjustment(value);
m_volumeSlider->setValue(dbShift);
updateTooltip(dbShift);
updateLabelValue(dbShift);
}

void VolumeSliderWidgetAction::updateTooltip(int value) {
Expand All @@ -62,9 +85,3 @@ void VolumeSliderWidgetAction::updateTooltip(int value) {
m_volumeSlider->setToolTip(
tooltipText.arg(tr("Volume Adjustment")).arg(value > 0 ? QString("+") : QString("")).arg(value));
}

void VolumeSliderWidgetAction::displayTooltip(int value) {
// ToolTip on drag
QString tooltipText = QString("%1%2 dB");
QToolTip::showText(QCursor::pos(), tooltipText.arg(value > 0 ? QString("+") : QString("")).arg(value), nullptr);
}
9 changes: 7 additions & 2 deletions src/mumble/VolumeSliderWidgetAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "QtUtils.h"

class QSlider;
class QHBoxLayout;
class QLabel;

class VolumeSliderWidgetAction : public QWidgetAction {
Q_OBJECT
Expand All @@ -19,13 +21,16 @@ class VolumeSliderWidgetAction : public QWidgetAction {
VolumeSliderWidgetAction(QWidget *parent = nullptr);

protected:
qt_unique_ptr< QSlider > m_volumeSlider;
qt_unique_ptr< QWidget > m_widget;
QSlider* m_volumeSlider;
QLabel* m_label;

void updateLabelValue(int value);
void updateSliderValue(float value);
void displayTooltip(int value);
void updateTooltip(int value);

protected slots:
virtual void on_VolumeSlider_sliderReleased(){};
virtual void on_VolumeSlider_valueChanged(int){};
virtual void on_VolumeSlider_changeCompleted(){};
};
Expand Down

0 comments on commit 85c3c3e

Please sign in to comment.