summaryrefslogtreecommitdiffstats
path: root/src/slxoutput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/slxoutput.cpp')
-rw-r--r--src/slxoutput.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/slxoutput.cpp b/src/slxoutput.cpp
new file mode 100644
index 0000000..d46b0e9
--- /dev/null
+++ b/src/slxoutput.cpp
@@ -0,0 +1,82 @@
+#include "slxoutput.h"
+#include "main.h"
+
+SlxOutput::SlxOutput(QWidget *parent, const QString &id)
+ : unused(false),
+ QWidget(parent),
+ _id(id)
+{
+ setupUi(this);
+ volumeSlider->setMaximum(65535);
+ volumeSlider->setSingleStep(200);
+ volumeSlider->setSingleStep(2000);
+ _volumeTimer.setInterval(100);
+ _volumeTimer.setSingleShot(true);
+ // Events
+ connect(muteToggleButton, &QToolButton::toggled, [this]() {
+ if (g_IgnoreGui)
+ return;
+ if (_sink.isEmpty())
+ return;
+ setMuted(_sink, muteToggleButton->isChecked());
+ });
+ connect(defaultToggleButton, &QToolButton::toggled, [this]() {
+ if (g_IgnoreGui)
+ return;
+ if (!defaultToggleButton->isChecked()) {
+ defaultToggleButton->setChecked(true);
+ }
+ if (_sink.isEmpty()) {
+ enableCard(_card, _port);
+ } else {
+ enableSink(_sink, _port);
+ }
+ });
+ connect(volumeSlider, &QSlider::sliderMoved, this, &SlxOutput::volumeSliderChanged);
+ connect(volumeSlider, &QSlider::valueChanged, this, &SlxOutput::volumeSliderChanged);
+ connect(&_volumeTimer, &QTimer::timeout, [this]() {
+ if (g_IgnoreGui || !isSink())
+ return;
+ setSinkVolume(_sink, volumeSlider->value());
+ });
+}
+
+SlxOutput::~SlxOutput()
+{
+
+}
+
+void SlxOutput::volumeSliderChanged(int value)
+{
+ if (g_IgnoreGui)
+ return;
+ if (_volumeTimer.isActive())
+ return;
+ _volumeTimer.start();
+}
+
+void SlxOutput::updateOutput(const QString &name, bool isDefault, bool isMuted, int volume, const QString &card, const QString &sink, const QString &port)
+{
+ nameLabel->setText(name);
+ if (sink != _sink) {
+ QFont fi = nameLabel->font();
+ fi.setBold(!sink.isEmpty());
+ nameLabel->setFont(fi);
+ }
+ _card = card;
+ _sink = sink;
+ _port = port;
+ defaultToggleButton->setChecked(isDefault);
+ muteToggleButton->setChecked(isMuted);
+ if (volume == -1) {
+ volumeSlider->setEnabled(false);
+ } else {
+ if (volume > volumeSlider->maximum()) {
+ volumeSlider->setMaximum(volume);
+ }
+ volumeSlider->setValue(volume);
+ volumeSlider->setEnabled(isSink());
+ }
+ muteToggleButton->setEnabled(isSink());
+ unused = false;
+}