Repository navigation
Expand file tree
/
Copy pathquicksettingscontroller.cpp
More file actions
75 lines (64 loc) · 2.18 KB
/
Copy pathquicksettingscontroller.cpp
File metadata and controls
75 lines (64 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "quicksettingscontroller.h"
#include <algorithm>
QuickSettingsController::QuickSettingsController(QObject *parent)
: QObject(parent)
{
}
bool QuickSettingsController::cellularOn() const { return m_cellularOn; }
bool QuickSettingsController::bluetoothOn() const { return m_bluetoothOn; }
bool QuickSettingsController::notificationsMuted() const { return m_notificationsMuted; }
bool QuickSettingsController::hotspotOn() const { return m_hotspotOn; }
qreal QuickSettingsController::volume() const { return m_volume; }
qreal QuickSettingsController::brightness() const { return m_brightness; }
void QuickSettingsController::setCellularOn(bool enabled)
{
if (m_cellularOn == enabled)
return;
m_cellularOn = enabled;
emit quickSettingsChanged();
}
void QuickSettingsController::setBluetoothOn(bool enabled)
{
if (m_bluetoothOn == enabled)
return;
m_bluetoothOn = enabled;
emit quickSettingsChanged();
}
void QuickSettingsController::setNotificationsMuted(bool muted)
{
if (m_notificationsMuted == muted)
return;
m_notificationsMuted = muted;
emit quickSettingsChanged();
}
void QuickSettingsController::setHotspotOn(bool enabled)
{
if (m_hotspotOn == enabled)
return;
m_hotspotOn = enabled;
emit quickSettingsChanged();
}
void QuickSettingsController::setVolume(qreal volume)
{
const qreal normalized = clamp01(volume);
if (qFuzzyCompare(m_volume, normalized))
return;
m_volume = normalized;
emit quickSettingsChanged();
}
void QuickSettingsController::setBrightness(qreal brightness)
{
const qreal normalized = clamp01(brightness);
if (qFuzzyCompare(m_brightness, normalized))
return;
m_brightness = normalized;
emit quickSettingsChanged();
}
void QuickSettingsController::toggleCellular() { setCellularOn(!m_cellularOn); }
void QuickSettingsController::toggleBluetooth() { setBluetoothOn(!m_bluetoothOn); }
void QuickSettingsController::toggleNotifications() { setNotificationsMuted(!m_notificationsMuted); }
void QuickSettingsController::toggleHotspot() { setHotspotOn(!m_hotspotOn); }
qreal QuickSettingsController::clamp01(qreal value)
{
return std::clamp(value, 0.0, 1.0);
}