diff options
| author | 2023-10-29 02:46:25 +0200 | |
|---|---|---|
| committer | 2023-10-29 20:29:17 +0100 | |
| commit | 0bb1c7c804a5dd8825acfe80f05b639c5752baf6 (patch) | |
| tree | 2625bc15c111207c23f6c9350768b2c8676f607c /src | |
| parent | Merge pull request #11880 from abouvier/unbundle-stb (diff) | |
| download | yuzu-0bb1c7c804a5dd8825acfe80f05b639c5752baf6.tar.gz yuzu-0bb1c7c804a5dd8825acfe80f05b639c5752baf6.tar.xz yuzu-0bb1c7c804a5dd8825acfe80f05b639c5752baf6.zip | |
Implemented wheel event for volume control in VolumeButton
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/main.cpp | 30 | ||||
| -rw-r--r-- | src/yuzu/main.h | 25 |
2 files changed, 53 insertions, 2 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 1431cf2fe..5e687891f 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1072,7 +1072,7 @@ void GMainWindow::InitializeWidgets() { | |||
| 1072 | }); | 1072 | }); |
| 1073 | volume_popup->layout()->addWidget(volume_slider); | 1073 | volume_popup->layout()->addWidget(volume_slider); |
| 1074 | 1074 | ||
| 1075 | volume_button = new QPushButton(); | 1075 | volume_button = new VolumeButton(); |
| 1076 | volume_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); | 1076 | volume_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); |
| 1077 | volume_button->setFocusPolicy(Qt::NoFocus); | 1077 | volume_button->setFocusPolicy(Qt::NoFocus); |
| 1078 | volume_button->setCheckable(true); | 1078 | volume_button->setCheckable(true); |
| @@ -1103,6 +1103,8 @@ void GMainWindow::InitializeWidgets() { | |||
| 1103 | context_menu.exec(volume_button->mapToGlobal(menu_location)); | 1103 | context_menu.exec(volume_button->mapToGlobal(menu_location)); |
| 1104 | volume_button->repaint(); | 1104 | volume_button->repaint(); |
| 1105 | }); | 1105 | }); |
| 1106 | connect(volume_button, &VolumeButton::VolumeChanged, this, &GMainWindow::UpdateVolumeUI); | ||
| 1107 | |||
| 1106 | statusBar()->insertPermanentWidget(0, volume_button); | 1108 | statusBar()->insertPermanentWidget(0, volume_button); |
| 1107 | 1109 | ||
| 1108 | // setup AA button | 1110 | // setup AA button |
| @@ -5126,6 +5128,32 @@ void GMainWindow::changeEvent(QEvent* event) { | |||
| 5126 | QWidget::changeEvent(event); | 5128 | QWidget::changeEvent(event); |
| 5127 | } | 5129 | } |
| 5128 | 5130 | ||
| 5131 | void VolumeButton::wheelEvent(QWheelEvent* event) { | ||
| 5132 | |||
| 5133 | int num_degrees = event->angleDelta().y() / 8; | ||
| 5134 | int num_steps = (num_degrees / 15) * scroll_multiplier; | ||
| 5135 | // Stated in QT docs: Most mouse types work in steps of 15 degrees, in which case the delta | ||
| 5136 | // value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees. | ||
| 5137 | |||
| 5138 | if (num_steps > 0) { | ||
| 5139 | Settings::values.volume.SetValue( | ||
| 5140 | std::min(200, Settings::values.volume.GetValue() + num_steps)); | ||
| 5141 | } else { | ||
| 5142 | Settings::values.volume.SetValue( | ||
| 5143 | std::max(0, Settings::values.volume.GetValue() + num_steps)); | ||
| 5144 | } | ||
| 5145 | |||
| 5146 | scroll_multiplier = std::min(MaxMultiplier, scroll_multiplier * 2); | ||
| 5147 | scroll_timer.start(100); // reset the multiplier if no scroll event occurs within 100 ms | ||
| 5148 | |||
| 5149 | emit VolumeChanged(); | ||
| 5150 | event->accept(); | ||
| 5151 | } | ||
| 5152 | |||
| 5153 | void VolumeButton::ResetMultiplier() { | ||
| 5154 | scroll_multiplier = 1; | ||
| 5155 | } | ||
| 5156 | |||
| 5129 | #ifdef main | 5157 | #ifdef main |
| 5130 | #undef main | 5158 | #undef main |
| 5131 | #endif | 5159 | #endif |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 270a40c5f..f9c6efe4f 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | #include <QMainWindow> | 9 | #include <QMainWindow> |
| 10 | #include <QMessageBox> | 10 | #include <QMessageBox> |
| 11 | #include <QPushButton> | ||
| 11 | #include <QTimer> | 12 | #include <QTimer> |
| 12 | #include <QTranslator> | 13 | #include <QTranslator> |
| 13 | 14 | ||
| @@ -137,6 +138,28 @@ namespace VkDeviceInfo { | |||
| 137 | class Record; | 138 | class Record; |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 141 | class VolumeButton : public QPushButton { | ||
| 142 | Q_OBJECT | ||
| 143 | public: | ||
| 144 | explicit VolumeButton(QWidget* parent = nullptr) : QPushButton(parent), scroll_multiplier(1) { | ||
| 145 | connect(&scroll_timer, &QTimer::timeout, this, &VolumeButton::ResetMultiplier); | ||
| 146 | } | ||
| 147 | |||
| 148 | signals: | ||
| 149 | void VolumeChanged(); | ||
| 150 | |||
| 151 | protected: | ||
| 152 | void wheelEvent(QWheelEvent* event) override; | ||
| 153 | |||
| 154 | private slots: | ||
| 155 | void ResetMultiplier(); | ||
| 156 | |||
| 157 | private: | ||
| 158 | int scroll_multiplier; | ||
| 159 | QTimer scroll_timer; | ||
| 160 | constexpr static int MaxMultiplier = 8; | ||
| 161 | }; | ||
| 162 | |||
| 140 | class GMainWindow : public QMainWindow { | 163 | class GMainWindow : public QMainWindow { |
| 141 | Q_OBJECT | 164 | Q_OBJECT |
| 142 | 165 | ||
| @@ -481,7 +504,7 @@ private: | |||
| 481 | QPushButton* dock_status_button = nullptr; | 504 | QPushButton* dock_status_button = nullptr; |
| 482 | QPushButton* filter_status_button = nullptr; | 505 | QPushButton* filter_status_button = nullptr; |
| 483 | QPushButton* aa_status_button = nullptr; | 506 | QPushButton* aa_status_button = nullptr; |
| 484 | QPushButton* volume_button = nullptr; | 507 | VolumeButton* volume_button = nullptr; |
| 485 | QWidget* volume_popup = nullptr; | 508 | QWidget* volume_popup = nullptr; |
| 486 | QSlider* volume_slider = nullptr; | 509 | QSlider* volume_slider = nullptr; |
| 487 | QTimer status_bar_update_timer; | 510 | QTimer status_bar_update_timer; |