From 49a48495e3537d2f45babae193db4e1d5407cf5e Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Thu, 4 Jan 2024 13:32:35 +0000 Subject: [PATCH] Experiemental slider improvement --- src/mumble/ListenerVolumeSlider.cpp | 3 ++ src/mumble/MainWindow.cpp | 1 + src/mumble/MenuLabel.cpp | 41 +++++++++++++++++++++-- src/mumble/MenuLabel.h | 9 +++++- src/mumble/UserLocalVolumeSlider.cpp | 2 ++ src/mumble/VolumeSliderWidgetAction.cpp | 43 +++++++++++++++++++++---- src/mumble/VolumeSliderWidgetAction.h | 7 +++- 7 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/mumble/ListenerVolumeSlider.cpp b/src/mumble/ListenerVolumeSlider.cpp index 6db5a8fdd3e..dc690f89ce1 100644 --- a/src/mumble/ListenerVolumeSlider.cpp +++ b/src/mumble/ListenerVolumeSlider.cpp @@ -61,6 +61,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); } } @@ -81,4 +82,6 @@ void ListenerVolumeSlider::sendToServer() { adjustmentMsg->set_volume_adjustment(m_cachedAdjustment.factor); handler->sendMessage(mpus); + + updateLabelValue(m_cachedAdjustment.dbAdjustment); } diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index 6d5fa95fca7..988f2655ad2 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -67,6 +67,7 @@ #endif #include +#include #include #include #include diff --git a/src/mumble/MenuLabel.cpp b/src/mumble/MenuLabel.cpp index 1655a5f5156..fc8037c6e05 100644 --- a/src/mumble/MenuLabel.cpp +++ b/src/mumble/MenuLabel.cpp @@ -7,13 +7,50 @@ #include -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(); + } +} diff --git a/src/mumble/MenuLabel.h b/src/mumble/MenuLabel.h index 22aa6225659..a6803ea3d9c 100644 --- a/src/mumble/MenuLabel.h +++ b/src/mumble/MenuLabel.h @@ -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 diff --git a/src/mumble/UserLocalVolumeSlider.cpp b/src/mumble/UserLocalVolumeSlider.cpp index ea3f23fa4a3..3c725899f1c 100644 --- a/src/mumble/UserLocalVolumeSlider.cpp +++ b/src/mumble/UserLocalVolumeSlider.cpp @@ -43,5 +43,7 @@ void UserLocalVolumeSlider::on_VolumeSlider_changeCompleted() { } else { Global::get().mw->logChangeNotPermanent(QObject::tr("Local Volume Adjustment..."), user); } + + updateLabelValue(VolumeAdjustment::toDBAdjustment(user->getLocalVolumeAdjustments())); } } diff --git a/src/mumble/VolumeSliderWidgetAction.cpp b/src/mumble/VolumeSliderWidgetAction.cpp index 7553ae68b9f..fcea8f26668 100644 --- a/src/mumble/VolumeSliderWidgetAction.cpp +++ b/src/mumble/VolumeSliderWidgetAction.cpp @@ -10,16 +10,24 @@ #include #include +#include +#include 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->setAccessibleName(tr("Local volume adjustment")); m_volumeSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + m_label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + m_label->setStyleSheet("QLabel { background-color : red; }"); 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 @@ -33,27 +41,48 @@ 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, + connect(m_volumeSlider, &QSlider::sliderReleased, this, &VolumeSliderWidgetAction::on_VolumeSlider_changeCompleted); 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); + + QGridLayout *layout = new QGridLayout(); + layout->addWidget(m_volumeSlider, 0, 0, 1, 1, Qt::AlignLeft); + layout->addWidget(m_label, 0, 1, 1, 1, Qt::AlignRight); + //layout->setColumnStretch(0, 10); + //layout->setColumnStretch(1, 1); + layout->setColumnMinimumWidth(0, 0); + layout->setColumnMinimumWidth(1, 0); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + m_widget->setLayout(layout); + + m_widget->setFocusProxy(m_volumeSlider); + m_widget->setFocusPolicy(Qt::TabFocus); + + setDefaultWidget(m_widget.get()); +} + +void VolumeSliderWidgetAction::updateLabelValue(int value) { + QString newText = QString("%1%2 dB"); + newText = newText.arg(value > 0 ? QString("+") : QString("")).arg(value); + m_label->setText(newText); } void VolumeSliderWidgetAction::updateSliderValue(float value) { int dbShift = VolumeAdjustment::toIntegerDBAdjustment(value); m_volumeSlider->setValue(dbShift); updateTooltip(dbShift); + updateLabelValue(dbShift); } void VolumeSliderWidgetAction::updateTooltip(int value) { diff --git a/src/mumble/VolumeSliderWidgetAction.h b/src/mumble/VolumeSliderWidgetAction.h index 25bb408670f..84efcb7206a 100644 --- a/src/mumble/VolumeSliderWidgetAction.h +++ b/src/mumble/VolumeSliderWidgetAction.h @@ -11,6 +11,8 @@ #include "QtUtils.h" class QSlider; +class QHBoxLayout; +class QLabel; class VolumeSliderWidgetAction : public QWidgetAction { Q_OBJECT @@ -19,8 +21,11 @@ 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);