Undo/redo
This commit is contained in:
parent
adab645c86
commit
f681b69467
5 changed files with 43 additions and 46 deletions
|
|
@ -157,14 +157,40 @@ QWidget *PipeWireGraphModel::nodeWidget(QtNodes::NodeId nodeId) const
|
|||
return;
|
||||
}
|
||||
const float volume = static_cast<float>(slider->value()) / 100.0f;
|
||||
const NodeVolumeState state{volume, muteButton->isChecked()};
|
||||
m_controller->setNodeVolume(pipewireId, volume, state.mute);
|
||||
const NodeVolumeState next{volume, muteButton->isChecked()};
|
||||
const NodeVolumeState previous = m_nodeVolumeState.value(pipewireId, next);
|
||||
m_controller->setNodeVolume(pipewireId, volume, next.mute);
|
||||
auto *self = const_cast<PipeWireGraphModel*>(this);
|
||||
self->setNodeVolumeState(pipewireId, state, true);
|
||||
self->setNodeVolumeState(pipewireId, next, false);
|
||||
if (!slider->isSliderDown() && !m_inlineStartState.contains(pipewireId)) {
|
||||
self->emitNodeVolumeChanged(pipewireId, previous, next);
|
||||
}
|
||||
};
|
||||
|
||||
QObject::connect(slider, &QSlider::valueChanged, widget, [applyVolume](int) { applyVolume(); });
|
||||
QObject::connect(muteButton, &QToolButton::toggled, widget, [applyVolume](bool) { applyVolume(); });
|
||||
QObject::connect(slider, &QSlider::sliderPressed, widget, [this, pipewireId, slider, muteButton]() {
|
||||
if (pipewireId == 0) {
|
||||
return;
|
||||
}
|
||||
bool ok = false;
|
||||
const int pressValue = slider->property("pressValue").toInt(&ok);
|
||||
const float volume = ok ? (static_cast<float>(pressValue) / 100.0f)
|
||||
: static_cast<float>(slider->value()) / 100.0f;
|
||||
const bool mute = muteButton->isChecked();
|
||||
m_inlineStartState.insert(pipewireId, NodeVolumeState{volume, mute});
|
||||
});
|
||||
QObject::connect(slider, &QSlider::sliderReleased, widget, [this, pipewireId, slider, muteButton]() {
|
||||
if (pipewireId == 0) {
|
||||
return;
|
||||
}
|
||||
const NodeVolumeState previous = m_inlineStartState.value(pipewireId, m_nodeVolumeState.value(pipewireId));
|
||||
m_inlineStartState.remove(pipewireId);
|
||||
const float volume = static_cast<float>(slider->value()) / 100.0f;
|
||||
const NodeVolumeState next{volume, muteButton->isChecked()};
|
||||
auto *self = const_cast<PipeWireGraphModel*>(this);
|
||||
self->emitNodeVolumeChanged(pipewireId, previous, next);
|
||||
});
|
||||
|
||||
layout->addWidget(muteButton);
|
||||
layout->addWidget(slider);
|
||||
|
|
@ -811,6 +837,15 @@ void PipeWireGraphModel::applyVolumeStates(const QHash<QString, NodeVolumeState>
|
|||
}
|
||||
}
|
||||
|
||||
void PipeWireGraphModel::emitNodeVolumeChanged(uint32_t nodeId, const NodeVolumeState &previous, const NodeVolumeState ¤t)
|
||||
{
|
||||
const bool changedVolume = qAbs(previous.volume - current.volume) > 0.0001f;
|
||||
if (!changedVolume && previous.mute == current.mute) {
|
||||
return;
|
||||
}
|
||||
Q_EMIT nodeVolumeChanged(nodeId, previous, current);
|
||||
}
|
||||
|
||||
void PipeWireGraphModel::setNodeVolumeState(uint32_t nodeId, const NodeVolumeState &state, bool notify)
|
||||
{
|
||||
const NodeVolumeState previous = m_nodeVolumeState.value(nodeId, NodeVolumeState{});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue