From 5b63fc3be4733b4f6994cba2ffa0c51517c29063 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Tue, 11 May 2021 11:05:29 +0200 Subject: [PATCH 1/5] Data type double for Volume Smaller step size for volume needed Signed-off-by: Thomas Ruschival --- include/appconstants.hpp | 19 +++++++----- include/configuration_manager.hpp | 10 +++---- include/mediaplayer.hpp | 16 +++++----- include/mediaplayerproxy.hpp | 8 ++--- include/util.hpp | 7 ----- include/volume_button.hpp | 2 +- include/weather.hpp | 2 +- libsrc/configuration_manager.cpp | 26 +++++----------- libsrc/mediaplayer.cpp | 12 +++----- libsrc/mediaplayerproxy.cpp | 7 ++--- libsrc/util.cpp | 5 ---- libsrc/volume_button.cpp | 5 ++-- test/cm_mock.hpp | 2 +- test/player_mock.hpp | 49 ++++++++++++++++--------------- test/test_alarmmonitor.cpp | 2 +- test/test_mediaplayerproxy.cpp | 18 ++++++++---- test/test_volume_button.cpp | 9 +++--- 17 files changed, 93 insertions(+), 106 deletions(-) diff --git a/include/appconstants.hpp b/include/appconstants.hpp index 000f3e9..0a8870e 100644 --- a/include/appconstants.hpp +++ b/include/appconstants.hpp @@ -217,11 +217,6 @@ const QString KEY_WIFI_DEV_NAME("net_dev"); */ const QString RSS_FILE_DIR(QDir::tempPath()); -/** - * Default alarm volume - */ -const int DEFAULT_ALARM_VOLUME = 30; - /** * Minimum percentage of Podcast episode played to be considered 'listened' */ @@ -247,12 +242,17 @@ const std::chrono::milliseconds ALS_SAMPLING_PERIOD(300); /** * Default output volume */ -const int DEFAULT_VOLUME = 30; +const double DEFAULT_VOLUME = 25; + +/** + * Default alarm volume + */ +const double DEFAULT_ALARM_VOLUME = 30; /** * Default volume for fallback alarm sound */ -const int DEFAULT_FALLBACK_VOLUME = 50; +const double DEFAULT_FALLBACK_VOLUME = 35; /** * Default display brightness @@ -271,6 +271,11 @@ const int DEFAULT_ICON_WIDTH = 88; */ const int WEATHER_FORECAST_COUNT = 8; +/** + * Step size of volume increment per rotary event + */ +const double VOLUME_INCREMENT = 0.2; + /** * Where to find icons for weather condition */ diff --git a/include/configuration_manager.hpp b/include/configuration_manager.hpp index b432338..a7a3f23 100644 --- a/include/configuration_manager.hpp +++ b/include/configuration_manager.hpp @@ -54,7 +54,7 @@ class ConfigurationManager : public QObject, set_standby_brightness) Q_PROPERTY(int activebrightness READ get_active_brightness WRITE set_active_brightness) - Q_PROPERTY(int defaultvolume READ get_volume WRITE set_volume) + Q_PROPERTY(double defaultvolume READ get_volume WRITE set_volume) public: /** @@ -87,7 +87,7 @@ class ConfigurationManager : public QObject, * current linear volume * @return volume 0..100 */ - int get_volume() const { + double get_volume() const { return do_get_volume(); } @@ -177,7 +177,7 @@ public slots: * volume settings changed -> store * @param vol new volume settings (0..100) */ - void set_volume(int vol); + void set_volume(double vol); /** * user changed standby brightness @@ -263,7 +263,7 @@ public slots: /** * Linear Volume in percent (stored in config file) */ - int volume; + double volume; /** * display brightness (0..100%) in standby mode @@ -395,7 +395,7 @@ public slots: /** * Private virtual interface for volume settings */ - virtual int do_get_volume() const { + virtual double do_get_volume() const { return volume; }; diff --git a/include/mediaplayer.hpp b/include/mediaplayer.hpp index 073a9b5..1f53ef1 100644 --- a/include/mediaplayer.hpp +++ b/include/mediaplayer.hpp @@ -29,7 +29,7 @@ class MediaPlayer : public QObject { Q_PROPERTY(qint64 position READ get_position NOTIFY position_changed) Q_PROPERTY(qint64 duration READ get_duration NOTIFY duration_changed) Q_PROPERTY( - int volume READ get_volume WRITE set_volume NOTIFY volume_changed) + double volume READ get_volume WRITE set_volume NOTIFY volume_changed) Q_PROPERTY(bool muted READ muted WRITE set_muted NOTIFY muted_changed) Q_PROPERTY(bool seekable READ seekable NOTIFY seekable_changed) Q_PROPERTY(QMediaPlayer::MediaStatus mediaStatus READ media_status NOTIFY @@ -42,7 +42,7 @@ class MediaPlayer : public QObject { virtual ~MediaPlayer() = default; bool muted() const; - int get_volume() const; + double get_volume() const; void set_muted(bool muted); bool seekable() const; @@ -68,12 +68,12 @@ public slots: * Set linear volume value to * @param volume 0..100% */ - void set_volume(int volume); + void set_volume(double volume); /** * increment/decrement linear volume by increment percent * @param increment percentage to change volume */ - void increment_volume(int increment); + void increment_volume(double increment); void pause(); void play(); @@ -86,7 +86,7 @@ public slots: * volume has changed * @param volume linear volume value 0..100 % */ - void volume_changed(int volume); + void volume_changed(double volume); void muted_changed(bool muted); void seekable_changed(bool seekable); @@ -103,7 +103,7 @@ public slots: */ virtual bool is_seekable() const = 0; virtual bool is_muted() const = 0; - virtual int do_get_volume() const = 0; + virtual double do_get_volume() const = 0; virtual qint64 do_get_duration() const = 0; virtual qint64 do_get_position() const = 0; virtual QMediaPlayer::MediaStatus do_media_status() const = 0; @@ -114,8 +114,8 @@ public slots: virtual void do_set_playlist(QMediaPlaylist* playlist) = 0; virtual void do_set_position(qint64 position) = 0; virtual void do_set_muted(bool muted) = 0; - virtual void do_set_volume(int volume) = 0; - virtual void do_increment_volume(int increment) = 0; + virtual void do_set_volume(double volume) = 0; + virtual void do_increment_volume(double increment) = 0; virtual void do_seek(qint64 incr) = 0; virtual void do_pause() = 0; virtual void do_play() = 0; diff --git a/include/mediaplayerproxy.hpp b/include/mediaplayerproxy.hpp index 75cbd2f..062d29e 100644 --- a/include/mediaplayerproxy.hpp +++ b/include/mediaplayerproxy.hpp @@ -49,7 +49,7 @@ class MediaPlayerProxy : public MediaPlayer { private: virtual bool is_seekable() const override; virtual bool is_muted() const override; - virtual int do_get_volume() const override; + virtual double do_get_volume() const override; virtual qint64 do_get_duration() const override; virtual qint64 do_get_position() const override; virtual QMediaPlayer::MediaStatus do_media_status() const override; @@ -60,8 +60,8 @@ class MediaPlayerProxy : public MediaPlayer { virtual void do_set_playlist(QMediaPlaylist* playlist) override; virtual void do_set_position(qint64 position) override; virtual void do_set_muted(bool muted) override; - virtual void do_set_volume(int volume) override; - virtual void do_increment_volume(int increment) override; + virtual void do_set_volume(double volume) override; + virtual void do_increment_volume(double increment) override; virtual void do_seek(qint64 incr) override; virtual void do_pause() override; virtual void do_play() override; @@ -77,7 +77,7 @@ class MediaPlayerProxy : public MediaPlayer { * Linear volume 0..100% * Initialized because increment/decrement has to work with some value */ - int linear_volume = 0; + double linear_volume = 0; /** * The actual player implementation diff --git a/include/util.hpp b/include/util.hpp index 56992d6..79df937 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -51,13 +51,6 @@ QUrl valid_url_from_string(const QString& urlstr); */ QUuid valid_uuid_from_String(const QString& uuidstr); -/** - * Simple check if value is in range 0-100 used for positive - * Integer range like volume percentage, brightness percentage.... - * @param value to check - * @return value>=0 && value <=100 - */ -bool value_in_0_100(int value); } // namespace DigitalRooster #endif /* INCLUDE_UTIL_HPP_ */ diff --git a/include/volume_button.hpp b/include/volume_button.hpp index 50c6d90..dd8ad83 100644 --- a/include/volume_button.hpp +++ b/include/volume_button.hpp @@ -77,7 +77,7 @@ public slots: /** * volume was incremented/decremented by increment */ - void volume_incremented(int increment); + void volume_incremented(double increment); /** * Push button was/is pressed */ diff --git a/include/weather.hpp b/include/weather.hpp index 0673eaf..31f8c0c 100644 --- a/include/weather.hpp +++ b/include/weather.hpp @@ -150,7 +150,7 @@ class WeatherStatus : public QObject { class Weather : public QObject { Q_OBJECT Q_PROPERTY(QString city READ get_city NOTIFY city_updated) - Q_PROPERTY(float temp READ get_temperature NOTIFY temperature_changed) + Q_PROPERTY(double temp READ get_temperature NOTIFY temperature_changed) Q_PROPERTY(QUrl weatherIcon READ get_weather_icon_url NOTIFY icon_changed) public: /** diff --git a/libsrc/configuration_manager.cpp b/libsrc/configuration_manager.cpp index b373967..ebcca42 100644 --- a/libsrc/configuration_manager.cpp +++ b/libsrc/configuration_manager.cpp @@ -181,7 +181,7 @@ void ConfigurationManager::parse_json(const QByteArray& json) { enable_backlight_control(appconfig[KEY_BACKLIGHT_CONTROL].toBool(true)); - set_volume(appconfig[KEY_VOLUME].toInt(DEFAULT_VOLUME)); + set_volume(appconfig[KEY_VOLUME].toDouble(DEFAULT_VOLUME)); set_sleep_timeout(std::chrono::minutes( appconfig[KEY_SLEEP_TIMEOUT].toInt(DEFAULT_SLEEP_TIMEOUT.count()))); @@ -298,35 +298,23 @@ void ConfigurationManager::fileChanged(const QString& path) { } /*****************************************************************************/ -void ConfigurationManager::set_volume(int vol) { +void ConfigurationManager::set_volume(double vol) { qCDebug(CLASS_LC) << Q_FUNC_INFO << vol; - if (value_in_0_100(vol)) { - this->volume = vol; - dirty = true; - } else { - qCWarning(CLASS_LC) << "invalid volume value: " << vol; - } + this->volume = std::clamp(vol, 0.0, 100.0); + dirty = true; } /*****************************************************************************/ void ConfigurationManager::set_standby_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness; - if (value_in_0_100(brightness)) { - this->brightness_sb = brightness; - dirty = true; - } else { - qCWarning(CLASS_LC) << "invalid brightness value: " << brightness; - } + this->brightness_sb = std::clamp(brightness, 0, 100); + dirty = true; } /*****************************************************************************/ void ConfigurationManager::set_active_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO << brightness; - if (value_in_0_100(brightness)) { - do_set_brightness_act(brightness); - } else { - qCWarning(CLASS_LC) << "invalid brightness value: " << brightness; - } + do_set_brightness_act(std::clamp(brightness, 0, 100)); } /*****************************************************************************/ diff --git a/libsrc/mediaplayer.cpp b/libsrc/mediaplayer.cpp index c0e8d29..9486b59 100644 --- a/libsrc/mediaplayer.cpp +++ b/libsrc/mediaplayer.cpp @@ -20,7 +20,7 @@ bool MediaPlayer::muted() const { } /*****************************************************************************/ -int MediaPlayer::get_volume() const { +double MediaPlayer::get_volume() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return do_get_volume(); } @@ -32,17 +32,13 @@ void MediaPlayer::set_muted(bool muted) { } /*****************************************************************************/ -void MediaPlayer::set_volume(int volume) { +void MediaPlayer::set_volume(double volume) { qCDebug(CLASS_LC) << Q_FUNC_INFO << volume; - if (!value_in_0_100(volume)) { - qCWarning(CLASS_LC) << "invalid volume (must be 0..100%)"; - return; - } - return do_set_volume(volume); + return do_set_volume(std::clamp(volume, 0.0, 100.0)); } /*****************************************************************************/ -void MediaPlayer::increment_volume(int increment) { +void MediaPlayer::increment_volume(double increment) { qCDebug(CLASS_LC) << Q_FUNC_INFO; return do_increment_volume(increment); } diff --git a/libsrc/mediaplayerproxy.cpp b/libsrc/mediaplayerproxy.cpp index 04dabfb..bf08b0f 100644 --- a/libsrc/mediaplayerproxy.cpp +++ b/libsrc/mediaplayerproxy.cpp @@ -175,7 +175,7 @@ bool MediaPlayerProxy::is_muted() const { } /*****************************************************************************/ -int MediaPlayerProxy::do_get_volume() const { +double MediaPlayerProxy::do_get_volume() const { qCDebug(CLASS_LC) << Q_FUNC_INFO; return linear_volume; } @@ -211,7 +211,7 @@ QMediaPlayer::State MediaPlayerProxy::do_playback_state() const { } /*****************************************************************************/ -void MediaPlayerProxy::do_set_volume(int volume) { +void MediaPlayerProxy::do_set_volume(double volume) { qCDebug(CLASS_LC) << Q_FUNC_INFO; linear_volume = volume; emit volume_changed(volume); @@ -223,9 +223,8 @@ void MediaPlayerProxy::do_set_volume(int volume) { } /*****************************************************************************/ -void MediaPlayerProxy::do_increment_volume(int increment) { +void MediaPlayerProxy::do_increment_volume(double increment) { qCDebug(CLASS_LC) << Q_FUNC_INFO << increment; - qCDebug(CLASS_LC) << " current volume" << linear_volume; set_volume(linear_volume + increment); } diff --git a/libsrc/util.cpp b/libsrc/util.cpp index 782b55f..3e78356 100644 --- a/libsrc/util.cpp +++ b/libsrc/util.cpp @@ -102,10 +102,5 @@ QUuid valid_uuid_from_String(const QString& uuidstr) { return id; } -/*****************************************************************************/ -bool value_in_0_100(int value) { - return (value >= 0 && value <= 100); -} - /*****************************************************************************/ } // namespace DigitalRooster diff --git a/libsrc/volume_button.cpp b/libsrc/volume_button.cpp index 167278f..5d23a58 100644 --- a/libsrc/volume_button.cpp +++ b/libsrc/volume_button.cpp @@ -6,6 +6,7 @@ #include +#include "appconstants.hpp" #include "volume_button.hpp" using namespace DigitalRooster; @@ -36,10 +37,10 @@ void DigitalRooster::VolumeButton::process_rotary_event( } // only react on -1 or 1 events if (evt.value < 0) { - emit volume_incremented(-1); + emit volume_incremented(-DigitalRooster::VOLUME_INCREMENT); } if (evt.value > 0) { - emit volume_incremented(1); + emit volume_incremented(DigitalRooster::VOLUME_INCREMENT); } } diff --git a/test/cm_mock.hpp b/test/cm_mock.hpp index 82e9e4f..87030ab 100644 --- a/test/cm_mock.hpp +++ b/test/cm_mock.hpp @@ -34,7 +34,7 @@ class CmMock : public DigitalRooster::ConfigurationManager { MOCK_CONST_METHOD0(get_active_brightness, int()); MOCK_CONST_METHOD0(get_standby_brightness, int()); MOCK_CONST_METHOD0(backlight_control_enabled, bool()); - MOCK_CONST_METHOD0(do_get_volume, int()); + MOCK_CONST_METHOD0(do_get_volume, double()); MOCK_METHOD1(set_active_brightness, void(int ab)); MOCK_METHOD1(set_standby_brightness, void(int sb)); MOCK_CONST_METHOD0(get_wpa_socket_name, QString()); diff --git a/test/player_mock.hpp b/test/player_mock.hpp index 2719f1c..b8e095a 100644 --- a/test/player_mock.hpp +++ b/test/player_mock.hpp @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-oiIdentifier: GPL-3.0-or-later /* * copyright (c) 2020 Thomas Ruschival * Licensed under GNU PUBLIC LICENSE Version 3 or later @@ -13,28 +13,31 @@ class PlayerMock : public DigitalRooster::MediaPlayer { PlayerMock(){ }; - MOCK_METHOD0(do_play, void()); - MOCK_METHOD0(do_stop, void()); - MOCK_METHOD0(do_pause, void()); - - MOCK_CONST_METHOD0(is_seekable, bool()); - MOCK_CONST_METHOD0(is_muted, bool()); - MOCK_CONST_METHOD0(do_get_volume, int()); - MOCK_CONST_METHOD0(do_get_duration, qint64()); - MOCK_CONST_METHOD0(do_get_position, qint64()); - MOCK_CONST_METHOD0(do_media_status, QMediaPlayer::MediaStatus()); - MOCK_CONST_METHOD0(do_playback_state, QMediaPlayer::State()); - MOCK_CONST_METHOD0(do_error, QMediaPlayer::Error()); - - MOCK_METHOD1(do_set_media, - void(std::shared_ptr media)); - MOCK_METHOD1(do_set_playlist, void(QMediaPlaylist* playlist)); - - MOCK_METHOD1(do_set_position, void(qint64 position)); - MOCK_METHOD1(do_set_muted, void(bool muted)); - MOCK_METHOD1(do_set_volume, void(int volume)); - MOCK_METHOD1(do_seek, void(qint64 position)); - MOCK_METHOD1(do_increment_volume, void(int increment)); + MOCK_METHOD(void, do_play, ()); + MOCK_METHOD(void, do_stop, ()); + MOCK_METHOD(void, do_pause, ()); + + MOCK_METHOD(bool, is_seekable, (), (const)); + MOCK_METHOD(bool, is_muted, (), (const)); + MOCK_METHOD(double, do_get_volume, (), (const)); + MOCK_METHOD(qint64, do_get_duration, (), (const)); + MOCK_METHOD(qint64, do_get_position, (), (const)); + + MOCK_METHOD(QMediaPlayer::MediaStatus, do_media_status, (), (const)); + MOCK_METHOD(QMediaPlayer::State, do_playback_state, (), (const)); + MOCK_METHOD(QMediaPlayer::Error, do_error, (), (const)); + + MOCK_METHOD(void, do_set_media, + (std::shared_ptr), (override)); + + MOCK_METHOD(void, do_set_playlist, (QMediaPlaylist*), (override)); + + MOCK_METHOD(void, do_set_position, (qint64), (override)); + MOCK_METHOD(void, do_seek, (qint64), (override)); + + MOCK_METHOD(void, do_set_muted, (bool), (override)); + MOCK_METHOD(void, do_set_volume, (double), (override)); + MOCK_METHOD(void, do_increment_volume, (double), (override)); void emitError(QMediaPlayer::Error err) { emit error(err); diff --git a/test/test_alarmmonitor.cpp b/test/test_alarmmonitor.cpp index 1db45f9..2694a35 100644 --- a/test/test_alarmmonitor.cpp +++ b/test/test_alarmmonitor.cpp @@ -65,7 +65,7 @@ TEST(AlarmMonitor, triggersFallbackForError) { EXPECT_CALL(player, do_set_volume(DEFAULT_ALARM_VOLUME)).Times(1); // Fallback behavior - EXPECT_CALL(player, do_set_volume(50)).Times(1); + EXPECT_CALL(player, do_set_volume(DEFAULT_FALLBACK_VOLUME)).Times(1); EXPECT_CALL(player, do_set_playlist(_)).Times(1); mon.alarm_triggered(alm.get()); diff --git a/test/test_mediaplayerproxy.cpp b/test/test_mediaplayerproxy.cpp index c5303f8..930aee9 100644 --- a/test/test_mediaplayerproxy.cpp +++ b/test/test_mediaplayerproxy.cpp @@ -88,28 +88,34 @@ TEST_F(PlayerFixture, setMuted) { /*****************************************************************************/ TEST_F(PlayerFixture, setVolume) { - QSignalSpy spy(&dut, SIGNAL(volume_changed(int))); + QSignalSpy spy(&dut, SIGNAL(volume_changed(double))); ASSERT_TRUE(spy.isValid()); - dut.set_volume(23); + dut.set_volume(23.0); ASSERT_EQ(spy.count(), 1); - ASSERT_EQ(dut.get_volume(), 23); + ASSERT_FLOAT_EQ(dut.get_volume(), 23.0); } /*****************************************************************************/ TEST_F(PlayerFixture, setVolumeInvalid) { - QSignalSpy spy(&dut, SIGNAL(volume_changed(int))); + QSignalSpy spy(&dut, SIGNAL(volume_changed(double))); ASSERT_TRUE(spy.isValid()); dut.set_volume(-1); // invalid dut.set_volume(100); - ASSERT_EQ(spy.count(), 1); // only 1 set calls is valid and should emit + ASSERT_EQ(spy.count(), 2); + // lower bound clamp + auto arguments = spy.takeFirst(); + EXPECT_DOUBLE_EQ(arguments.at(0).toDouble(), 0.0); + arguments = spy.takeFirst(); + EXPECT_DOUBLE_EQ(arguments.at(0).toDouble(), 100.0); + ASSERT_EQ(dut.get_volume(), 100); } /*****************************************************************************/ TEST_F(PlayerFixture, incrementVolume) { - QSignalSpy spy(&dut, SIGNAL(volume_changed(int))); + QSignalSpy spy(&dut, SIGNAL(volume_changed(double))); ASSERT_TRUE(spy.isValid()); dut.set_volume(23); dut.increment_volume(1); diff --git a/test/test_volume_button.cpp b/test/test_volume_button.cpp index dac04d5..7209faa 100644 --- a/test/test_volume_button.cpp +++ b/test/test_volume_button.cpp @@ -8,6 +8,7 @@ #include #include +#include "appconstants.hpp" #include "volume_button.hpp" using namespace DigitalRooster; @@ -18,7 +19,7 @@ using namespace ::testing; TEST(VolumeButton, VolumeIncreasedDecreased) { VolumeButton vbtn; QSignalSpy spy( - &vbtn, SIGNAL(volume_incremented(int))); + &vbtn, SIGNAL(volume_incremented(double))); ASSERT_TRUE(spy.isValid()); Hal::InputEvent evt; evt.value = 1; @@ -28,16 +29,16 @@ TEST(VolumeButton, VolumeIncreasedDecreased) { ASSERT_EQ(spy.count(), 2); auto arguments = spy.takeFirst(); - EXPECT_EQ(arguments.at(0).toInt(), 1); + EXPECT_DOUBLE_EQ(arguments.at(0).toDouble(), VOLUME_INCREMENT); arguments = spy.takeFirst(); - EXPECT_EQ(arguments.at(0).toInt(), -1); + EXPECT_DOUBLE_EQ(arguments.at(0).toDouble(), -VOLUME_INCREMENT); } /*****************************************************************************/ TEST(VolumeButton, FilterRotaryEvents) { VolumeButton vbtn; QSignalSpy spy( - &vbtn, SIGNAL(volume_incremented(int))); + &vbtn, SIGNAL(volume_incremented(double))); ASSERT_TRUE(spy.isValid()); vbtn.monitor_rotary_button(false); From 8e6d8551ab08682e33f8c40b0781a870d4922589 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sat, 22 May 2021 14:04:18 +0200 Subject: [PATCH 2/5] truncate volume decimals for display Signed-off-by: Thomas Ruschival --- qtgui/qml/VolumePopup.qml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qtgui/qml/VolumePopup.qml b/qtgui/qml/VolumePopup.qml index 5d0c06d..a542623 100644 --- a/qtgui/qml/VolumePopup.qml +++ b/qtgui/qml/VolumePopup.qml @@ -46,9 +46,8 @@ Menu { Layout.fillWidth: true; from: 0 to: 100 - stepSize: 1 wheelEnabled: true - value: playerProxy.volume + value: playerProxy.volume.toFixed(2) onMoved: { volumeShowTimer.restart(); playerProxy.volume = value; From 911df633e18795d84737dab4c23a2b252480b911 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sat, 22 May 2021 16:35:57 +0200 Subject: [PATCH 3/5] Add Wheel Handler to ApplicationWindow Signed-off-by: Thomas Ruschival --- qtgui/qml/VolumePopup.qml | 6 +++--- qtgui/qml/main.qml | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/qtgui/qml/VolumePopup.qml b/qtgui/qml/VolumePopup.qml index a542623..14bc234 100644 --- a/qtgui/qml/VolumePopup.qml +++ b/qtgui/qml/VolumePopup.qml @@ -30,7 +30,7 @@ Menu { // Row 1 Label{ font: Style.font.sliderValue - text: volumeSlider.value + text: playerProxy.volume.toFixed(2) Layout.alignment: Qt.AlignVCenter| Qt.AlignHCenter Layout.columnSpan: 3; } @@ -38,7 +38,7 @@ Menu { IconLabel{ // volume low text: "\uf57f"; - } + } Slider { id: volumeSlider @@ -47,7 +47,7 @@ Menu { from: 0 to: 100 wheelEnabled: true - value: playerProxy.volume.toFixed(2) + value: playerProxy.volume onMoved: { volumeShowTimer.restart(); playerProxy.volume = value; diff --git a/qtgui/qml/main.qml b/qtgui/qml/main.qml index 632ca40..279a30e 100644 --- a/qtgui/qml/main.qml +++ b/qtgui/qml/main.qml @@ -3,7 +3,7 @@ * copyright (c) 2021 Thomas Ruschival * Licensed under GNU PUBLIC LICENSE Version 3 or later */ -import QtQuick 2.11 +import QtQuick 2.14 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.11 import QtQuick.Controls.Material 2.4 @@ -48,6 +48,10 @@ ApplicationWindow { onTriggered: stackView.reset(); } + WheelHandler { + onWheel: volumePopUp.show() + } + menuBar: ToolBar { height: Style.toolbarHeight; @@ -100,7 +104,6 @@ ApplicationWindow { } // click resets timer onPressed: sleeptimer.reset_timer(); - } } From 81a0a410a578af4e036c6791fdc61a21b01ba43d Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Sat, 22 May 2021 16:50:17 +0200 Subject: [PATCH 4/5] Add signals to brightness changes Signed-off-by: Thomas Ruschival --- include/brightnesscontrol.hpp | 16 ++++++++++++++-- libsrc/brightnesscontrol.cpp | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/brightnesscontrol.hpp b/include/brightnesscontrol.hpp index 7d2c0a2..1928d6c 100644 --- a/include/brightnesscontrol.hpp +++ b/include/brightnesscontrol.hpp @@ -39,9 +39,9 @@ class BrightnessControl : public QObject { Q_OBJECT Q_PROPERTY(int brightness READ get_brightness NOTIFY brightness_changed) Q_PROPERTY(int active_brightness READ get_active_brightness WRITE - set_active_brightness) + set_active_brightness NOTIFY active_brightness_changed) Q_PROPERTY(int standby_brightness READ get_standby_brightness WRITE - set_standby_brightness) + set_standby_brightness NOTIFY standby_brightness_changed) Q_PROPERTY(bool has_sensor READ has_als_sensor) Q_PROPERTY(bool feedback READ adaptive_mode WRITE set_adaptive_mode NOTIFY adaptive_mode_changed) @@ -140,6 +140,18 @@ public slots: */ void brightness_changed(int perc); + /** + * Change of active brightness setpoint + * @param perc value for dutycycle (0-100%) + */ + void standby_brightness_changed(int perc); + + /** + * Change of standby brightness setpoint + * @param perc value for dutycycle (0-100%) + */ + void active_brightness_changed(int perc); + private: /** * configuration and data handler diff --git a/libsrc/brightnesscontrol.cpp b/libsrc/brightnesscontrol.cpp index 946bfed..a80a2b4 100644 --- a/libsrc/brightnesscontrol.cpp +++ b/libsrc/brightnesscontrol.cpp @@ -125,7 +125,9 @@ void BrightnessControl::als_value_changed(Hal::AlsValue brightness) { /*****************************************************************************/ void BrightnessControl::set_active_brightness(int brightness) { + qCDebug(CLASS_LC) << Q_FUNC_INFO; cm.set_active_brightness(brightness); + emit active_brightness_changed(brightness); if (!adaptive_mode()) { update_backlight(); } @@ -135,6 +137,7 @@ void BrightnessControl::set_active_brightness(int brightness) { void BrightnessControl::set_standby_brightness(int brightness) { qCDebug(CLASS_LC) << Q_FUNC_INFO; cm.set_standby_brightness(brightness); + emit standby_brightness_changed(brightness); if (!adaptive_mode()) { update_backlight(); } From 9963664ae221fb1bad99e122f2bb9856d9b82373 Mon Sep 17 00:00:00 2001 From: Thomas Ruschival Date: Mon, 24 May 2021 10:19:13 +0200 Subject: [PATCH 5/5] Bump version to v1.1 Signed-off-by: Thomas Ruschival --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d7be28..2359740 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/) # Project Name MESSAGE( STATUS "Running ${CMAKE_COMMAND} v${CMAKE_VERSION}" ) PROJECT(DigitalRooster - VERSION 1.0.0 + VERSION 1.1.0 DESCRIPTION "A digital alarm clock and podcast player" LANGUAGES CXX C )