forked from mumble-voip/mumble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX(client): Fix using the keyboad to change local volume adjustment
Previously, when using keyboard arrows, the new slider widget action applied the new local volume but did not save it. That was because it used the sliderReleased event to save the value, which is not triggered by keyboard updates. We could simply save the local volume on every sliderChange instead of on sliderRelease, but that would cause many writes to the disk in a short period of time and possibly lag the client. This commit introduces an event filter in addition to the sliderChanged event, which is observing key releases. If the slider has focus and left/right is released, it is then calling the save slot of the slider. Fixes mumble-voip#6211
- Loading branch information
Showing
10 changed files
with
161 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#include "EventFilters.h" | ||
|
||
#include <algorithm> | ||
|
||
#include <QKeyEvent> | ||
#include <QWidget> | ||
|
||
KeyEventObserver::KeyEventObserver(QObject *parent, QEvent::Type eventType, bool consume, | ||
std::initializer_list< Qt::Key > keys) | ||
: QObject(parent), m_eventType(eventType), m_consume(consume), m_keys(keys) { | ||
} | ||
|
||
bool KeyEventObserver::eventFilter(QObject *obj, QEvent *event) { | ||
QWidget *widget = static_cast< QWidget * >(obj); | ||
|
||
if (!widget || !widget->hasFocus()) { | ||
return false; | ||
} | ||
|
||
QKeyEvent *keyEvent = static_cast< QKeyEvent * >(event); | ||
|
||
if (!keyEvent || keyEvent->type() != m_eventType) { | ||
return false; | ||
} | ||
|
||
Qt::Key key = static_cast< Qt::Key >(keyEvent->key()); | ||
|
||
if (std::find(m_keys.begin(), m_keys.end(), key) == m_keys.end()) { | ||
return false; | ||
} | ||
|
||
emit keyEventObserved(); | ||
|
||
return m_consume; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#ifndef MUMBLE_MUMBLE_WIDGETS_EVENTFILTERS_H_ | ||
#define MUMBLE_MUMBLE_WIDGETS_EVENTFILTERS_H_ | ||
|
||
#include <initializer_list> | ||
#include <vector> | ||
|
||
#include <QEvent> | ||
#include <QObject> | ||
|
||
class KeyEventObserver : public QObject { | ||
Q_OBJECT | ||
|
||
private: | ||
QEvent::Type m_eventType; | ||
bool m_consume; | ||
std::vector< Qt::Key > m_keys; | ||
|
||
public: | ||
KeyEventObserver(QObject *parent, QEvent::Type eventType, bool consume, std::initializer_list< Qt::Key > keys); | ||
|
||
protected: | ||
bool eventFilter(QObject *obj, QEvent *event) override; | ||
|
||
signals: | ||
void keyEventObserved(); | ||
}; | ||
|
||
#endif |