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 5238868
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ MainWindow::MainWindow(QWidget *p)
QObject::connect(this, &MainWindow::serverSynchronized, Global::get().pluginManager,
&PluginManager::on_serverSynchronized);

// Sadly, QWidgetActions have a poor accessibility as of Qt 5.15.10
// The slider value will not be read under any circumstances, so we use the label
// above it to communicate that to the user.
// This is not pretty, but it seems to be the only option, if we want to keep
// the inline slider...
connect(m_userLocalVolumeSlider.get(), &VolumeSliderWidgetAction::dbAdjustmentChanged, this,
&MainWindow::on_volumeSlider_dbAdjustmentChanged);
connect(m_listenerVolumeSlider.get(), &VolumeSliderWidgetAction::dbAdjustmentChanged, this,
&MainWindow::on_volumeSlider_dbAdjustmentChanged);
on_volumeSlider_dbAdjustmentChanged(0);
m_localVolumeLabel->setAccessibleDescription(
tr("The next element in this menu is a slider to adjust the volume of the selected client. "
"Focus this label to get the updated adjustment value."));

QAccessible::installFactory(AccessibleSlider::semanticSliderFactory);
}

Expand Down Expand Up @@ -3858,6 +3872,12 @@ void MainWindow::on_qteLog_highlighted(const QUrl &url) {
}
}

void MainWindow::on_volumeSlider_dbAdjustmentChanged(int value) {
QString newName = QString("%1 %2%3 %4");
newName.arg(tr("Local Volume Adjustment")).arg(value > 0 ? QString("+") : QString("")).arg(value).arg(tr("decibels"));
m_localVolumeLabel->setAccessibleName(newName);
}

void MainWindow::context_triggered() {
QAction *a = qobject_cast< QAction * >(sender());

Expand Down
1 change: 1 addition & 0 deletions src/mumble/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public slots:
void on_qteLog_customContextMenuRequested(const QPoint &pos);
void on_qteLog_anchorClicked(const QUrl &);
void on_qteLog_highlighted(const QUrl &link);
void on_volumeSlider_dbAdjustmentChanged(int value);
void on_PushToTalk_triggered(bool, QVariant);
void on_PushToMute_triggered(bool, QVariant);
void on_VolumeUp_triggered(bool, QVariant);
Expand Down
24 changes: 23 additions & 1 deletion src/mumble/MenuLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,35 @@

#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;
}

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

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

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

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

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

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

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

#endif
4 changes: 3 additions & 1 deletion src/mumble/VolumeSliderWidgetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ VolumeSliderWidgetAction::VolumeSliderWidgetAction(QWidget *parent)
m_volumeSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

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 Down Expand Up @@ -54,6 +54,8 @@ void VolumeSliderWidgetAction::updateSliderValue(float value) {
int dbShift = VolumeAdjustment::toIntegerDBAdjustment(value);
m_volumeSlider->setValue(dbShift);
updateTooltip(dbShift);

emit dbAdjustmentChanged(dbShift);
}

void VolumeSliderWidgetAction::updateTooltip(int value) {
Expand Down
3 changes: 3 additions & 0 deletions src/mumble/VolumeSliderWidgetAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class VolumeSliderWidgetAction : public QWidgetAction {
void displayTooltip(int value);
void updateTooltip(int value);

signals:
void dbAdjustmentChanged(int value);

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

0 comments on commit 5238868

Please sign in to comment.