#include "slxoutput.h" #include "main.h" 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), _id(id), _type(type), _cardId(card), _profileId(profile), _deviceId(sink), _portId(port), QWidget(nullptr) { setupUi(this); // Make heading 20% larger than system default QFont f = headingLabel->font(); f.setPointSize(f.pointSize() * 6 / 5); 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); volumeSlider->setVisible(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 (_type == CardProfileItem) { enableCard(_cardId, _profileId, _portId); } else if (_type == SinkPortItem) { enableSink(_deviceId, _portId); } else { enableSource(_deviceId, _portId); } }); } SlxOutput::~SlxOutput() { } void SlxOutput::volumeSliderChanged(int value) { if (g_IgnoreGui) return; // Update slider every 100ms if (_volumeTimer.isActive()) return; _volumeTimer.start(); } /** * Update this entry, which has to represent a sink/source plus one of its ports. */ void SlxOutput::updateDeviceAndPort(bool isDefault, bool isMuted, int volume) { 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(true); muteToggleButton->setEnabled(true); } 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 }