diff options
Diffstat (limited to 'src/slxoutput.cpp')
-rw-r--r-- | src/slxoutput.cpp | 101 |
1 files changed, 63 insertions, 38 deletions
diff --git a/src/slxoutput.cpp b/src/slxoutput.cpp index 0ac38b1..5bc319b 100644 --- a/src/slxoutput.cpp +++ b/src/slxoutput.cpp @@ -1,44 +1,66 @@ #include "slxoutput.h" #include "main.h" -SlxOutput::SlxOutput(QWidget *parent, const QString &id) +SlxOutput::SlxOutput(ItemType type, const QString &id, + const QString &card, const QString &profile, + const QString &sink, const QString &port, + const QString &heading, const QString &title) : unused(false), - QWidget(parent), - _id(id) + _id(id), + _type(type), + _cardId(card), + _profileId(profile), + _deviceId(sink), + _portId(port), + QWidget(nullptr) { 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()); - }); + // Make heading 25% larger than system default + QFont f = headingLabel->font(); + f.setPointSize(f.pointSize() * 5 / 4); + f.setBold(_type == SinkPortItem || _type == SourcePortItem); + headingLabel->setFont(f); + // + if (_type == SinkPortItem || _type == SourcePortItem) { + 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 (_deviceId.isEmpty()) + return; + setMuted(_deviceId, muteToggleButton->isChecked()); + }); + connect(volumeSlider, &QSlider::sliderMoved, this, &SlxOutput::volumeSliderChanged); + connect(volumeSlider, &QSlider::valueChanged, this, &SlxOutput::volumeSliderChanged); + connect(&_volumeTimer, &QTimer::timeout, [this]() { + if (g_IgnoreGui || !isDevice()) + return; + setSinkVolume(_deviceId, volumeSlider->value()); + }); + } else { + volumeSlider->setEnabled(false); + muteToggleButton->setEnabled(false); + } + nameLabel->setText(title); + headingLabel->setText(heading); + // Default Toggle connect(defaultToggleButton, &QToolButton::toggled, [this]() { if (g_IgnoreGui) return; if (!defaultToggleButton->isChecked()) { defaultToggleButton->setChecked(true); } - if (_sink.isEmpty()) { - enableCard(_card, _port); + if (_type == CardProfileItem) { + enableCard(_cardId, _profileId); } else { - enableSink(_sink, _port); + enableSink(_deviceId, _portId); } }); - 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() @@ -56,28 +78,31 @@ void SlxOutput::volumeSliderChanged(int value) _volumeTimer.start(); } -void SlxOutput::updateOutput(const QString &name, bool isDefault, bool isMuted, int volume, const QString &card, const QString &sink, const QString &port) +/** + * Update this entry, which has to represent a sink/source plus one of its ports. + */ +void SlxOutput::updateDeviceAndPort(bool isDefault, bool isMuted, int volume) { - 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); + muteToggleButton->setEnabled(false); } else { if (volume > volumeSlider->maximum()) { volumeSlider->setMaximum(volume); } volumeSlider->setValue(volume); - volumeSlider->setEnabled(isSink()); + volumeSlider->setEnabled(true); + muteToggleButton->setEnabled(true); } - muteToggleButton->setEnabled(isSink()); + unused = false; // Entry was updated, so it's being used +} + +/** + * Update this entry, which has to represent a card plus one of its profiles. + */ +void SlxOutput::updateCardAndProfile() +{ unused = false; // Entry was updated, so it's being used } |