From 1d7ed16dc93630ec12f55a992b71181b7e45a0a5 Mon Sep 17 00:00:00 2001 From: saker Date: Thu, 19 Sep 2024 12:53:40 -0400 Subject: [PATCH] Make the send button and receive arrow occupy the same space in mixer channels (#7503) --- include/MixerChannelView.h | 18 ++++----- src/gui/MixerChannelView.cpp | 72 ++++++++++++------------------------ src/gui/MixerView.cpp | 31 ++++++++++------ 3 files changed, 51 insertions(+), 70 deletions(-) diff --git a/include/MixerChannelView.h b/include/MixerChannelView.h index 7ccb8a24f23..13d149e8740 100644 --- a/include/MixerChannelView.h +++ b/include/MixerChannelView.h @@ -37,6 +37,7 @@ #include #include #include +#include namespace lmms { @@ -59,11 +60,6 @@ namespace lmms::gui Q_PROPERTY(QColor strokeInnerActive READ strokeInnerActive WRITE setStrokeInnerActive) Q_PROPERTY(QColor strokeInnerInactive READ strokeInnerInactive WRITE setStrokeInnerInactive) public: - enum class SendReceiveState - { - None, SendToThis, ReceiveFromThis - }; - MixerChannelView(QWidget* parent, MixerView* mixerView, int channelIndex); void paintEvent(QPaintEvent* event) override; void contextMenuEvent(QContextMenuEvent*) override; @@ -74,9 +70,6 @@ namespace lmms::gui int channelIndex() const; void setChannelIndex(int index); - SendReceiveState sendReceiveState() const; - void setSendReceiveState(const SendReceiveState& state); - QBrush backgroundActive() const; void setBackgroundActive(const QBrush& c); @@ -115,19 +108,22 @@ namespace lmms::gui private: SendButtonIndicator* m_sendButton; + QLabel* m_receiveArrow; + QStackedWidget* m_receiveArrowOrSendButton; + int m_receiveArrowStackedIndex = -1; + int m_sendButtonStackedIndex = -1; + Knob* m_sendKnob; LcdWidget* m_channelNumberLcd; QLineEdit* m_renameLineEdit; QGraphicsView* m_renameLineEditView; QLabel* m_sendArrow; - QLabel* m_receiveArrow; PixmapButton* m_muteButton; PixmapButton* m_soloButton; PeakIndicator* m_peakIndicator = nullptr; Fader* m_fader; EffectRackView* m_effectRackView; MixerView* m_mixerView; - SendReceiveState m_sendReceiveState = SendReceiveState::None; int m_channelIndex = 0; bool m_inRename = false; @@ -141,4 +137,4 @@ namespace lmms::gui }; } // namespace lmms::gui -#endif \ No newline at end of file +#endif // MIXER_CHANNEL_VIEW_H diff --git a/src/gui/MixerChannelView.cpp b/src/gui/MixerChannelView.cpp index 91705e5d04b..b347a04a0e9 100644 --- a/src/gui/MixerChannelView.cpp +++ b/src/gui/MixerChannelView.cpp @@ -58,12 +58,33 @@ namespace lmms::gui widget->setSizePolicy(sizePolicy); }; + auto receiveArrowContainer = new QWidget{}; + auto receiveArrowLayout = new QVBoxLayout{receiveArrowContainer}; + m_receiveArrow = new QLabel{}; + m_receiveArrow->setPixmap(embed::getIconPixmap("receive_bg_arrow")); + receiveArrowLayout->setContentsMargins(0, 0, 0, 0); + receiveArrowLayout->setSpacing(0); + receiveArrowLayout->addWidget(m_receiveArrow, 0, Qt::AlignHCenter); + + auto sendButtonContainer = new QWidget{}; + auto sendButtonLayout = new QVBoxLayout{sendButtonContainer}; m_sendButton = new SendButtonIndicator{this, this, mixerView}; - retainSizeWhenHidden(m_sendButton); + sendButtonLayout->setContentsMargins(0, 0, 0, 0); + sendButtonLayout->setSpacing(0); + sendButtonLayout->addWidget(m_sendButton, 0, Qt::AlignHCenter); + + m_receiveArrowOrSendButton = new QStackedWidget{this}; + m_receiveArrowStackedIndex = m_receiveArrowOrSendButton->addWidget(receiveArrowContainer); + m_sendButtonStackedIndex = m_receiveArrowOrSendButton->addWidget(sendButtonContainer); + retainSizeWhenHidden(m_receiveArrowOrSendButton); m_sendKnob = new Knob{KnobType::Bright26, this, tr("Channel send amount")}; retainSizeWhenHidden(m_sendKnob); + m_sendArrow = new QLabel{}; + m_sendArrow->setPixmap(embed::getIconPixmap("send_bg_arrow")); + retainSizeWhenHidden(m_sendArrow); + m_channelNumberLcd = new LcdWidget{2, this}; m_channelNumberLcd->setValue(channelIndex); retainSizeWhenHidden(m_channelNumberLcd); @@ -89,16 +110,6 @@ namespace lmms::gui renameLineEditProxy->setRotation(-90); m_renameLineEditView->setFixedSize(m_renameLineEdit->height() + 5, m_renameLineEdit->width() + 5); - m_sendArrow = new QLabel{}; - m_sendArrow->setPixmap(embed::getIconPixmap("send_bg_arrow")); - retainSizeWhenHidden(m_sendArrow); - m_sendArrow->setVisible(m_sendReceiveState == SendReceiveState::SendToThis); - - m_receiveArrow = new QLabel{}; - m_receiveArrow->setPixmap(embed::getIconPixmap("receive_bg_arrow")); - retainSizeWhenHidden(m_receiveArrow); - m_receiveArrow->setVisible(m_sendReceiveState == SendReceiveState::ReceiveFromThis); - m_muteButton = new PixmapButton(this, tr("Mute")); m_muteButton->setModel(&mixerChannel->m_muteModel); m_muteButton->setActiveGraphic(embed::getIconPixmap("led_off")); @@ -131,8 +142,7 @@ namespace lmms::gui mainLayout->setContentsMargins(4, 4, 4, 4); mainLayout->setSpacing(2); - mainLayout->addWidget(m_receiveArrow, 0, Qt::AlignHCenter); - mainLayout->addWidget(m_sendButton, 0, Qt::AlignHCenter); + mainLayout->addWidget(m_receiveArrowOrSendButton, 0, Qt::AlignHCenter); mainLayout->addWidget(m_sendKnob, 0, Qt::AlignHCenter); mainLayout->addWidget(m_sendArrow, 0, Qt::AlignHCenter); mainLayout->addWidget(m_channelNumberLcd, 0, Qt::AlignHCenter); @@ -179,13 +189,11 @@ namespace lmms::gui void MixerChannelView::paintEvent(QPaintEvent* event) { - auto * mixer = Engine::mixer(); const auto channel = mixerChannel(); const bool muted = channel->m_muteModel.value(); const auto name = channel->m_name; const auto elidedName = elideName(name); - const auto * mixerChannelView = m_mixerView->currentMixerChannel(); - const auto isActive = mixerChannelView == this; + const auto isActive = m_mixerView->currentMixerChannel() == this; if (!m_inRename && m_renameLineEdit->text() != elidedName) { @@ -213,26 +221,6 @@ namespace lmms::gui painter.setPen(isActive ? strokeOuterActive() : strokeOuterInactive()); painter.drawRect(0, 0, width - MIXER_CHANNEL_OUTER_BORDER_SIZE, height - MIXER_CHANNEL_OUTER_BORDER_SIZE); - const auto & currentMixerChannelIndex = mixerChannelView->m_channelIndex; - const auto sendToThis = mixer->channelSendModel(currentMixerChannelIndex, m_channelIndex) != nullptr; - const auto receiveFromThis = mixer->channelSendModel(m_channelIndex, currentMixerChannelIndex) != nullptr; - const auto sendReceiveStateNone = !sendToThis && !receiveFromThis; - - // Only one or none of them can be on - assert(sendToThis ^ receiveFromThis || sendReceiveStateNone); - - m_sendArrow->setVisible(sendToThis); - m_receiveArrow->setVisible(receiveFromThis); - - if (sendReceiveStateNone) - { - setSendReceiveState(SendReceiveState::None); - } - else - { - setSendReceiveState(sendToThis ? SendReceiveState::SendToThis : SendReceiveState::ReceiveFromThis); - } - QWidget::paintEvent(event); } @@ -284,18 +272,6 @@ namespace lmms::gui m_channelIndex = index; } - MixerChannelView::SendReceiveState MixerChannelView::sendReceiveState() const - { - return m_sendReceiveState; - } - - void MixerChannelView::setSendReceiveState(const SendReceiveState& state) - { - m_sendReceiveState = state; - m_sendArrow->setVisible(state == SendReceiveState::SendToThis); - m_receiveArrow->setVisible(state == SendReceiveState::ReceiveFromThis); - } - QBrush MixerChannelView::backgroundActive() const { return m_backgroundActive; diff --git a/src/gui/MixerView.cpp b/src/gui/MixerView.cpp index 8152509f86a..0388c0c7d13 100644 --- a/src/gui/MixerView.cpp +++ b/src/gui/MixerView.cpp @@ -343,28 +343,37 @@ void MixerView::setCurrentMixerChannel(MixerChannelView* channel) void MixerView::updateMixerChannel(int index) { - Mixer * mix = getMixer(); + const auto mixer = getMixer(); - // does current channel send to this channel? - int selIndex = m_currentMixerChannel->channelIndex(); - auto thisLine = m_mixerChannelViews[index]; + const auto currentIndex = m_currentMixerChannel->channelIndex(); + const auto thisLine = m_mixerChannelViews[index]; thisLine->setToolTip(getMixer()->mixerChannel(index)->m_name); - FloatModel * sendModel = mix->channelSendModel(selIndex, index); - if (sendModel == nullptr) + const auto sendModelCurrentToThis = mixer->channelSendModel(currentIndex, index); + if (sendModelCurrentToThis == nullptr) { - // does not send, hide send knob thisLine->m_sendKnob->setVisible(false); + thisLine->m_sendArrow->setVisible(false); } else { - // it does send, show knob and connect thisLine->m_sendKnob->setVisible(true); - thisLine->m_sendKnob->setModel(sendModel); + thisLine->m_sendKnob->setModel(sendModelCurrentToThis); + thisLine->m_sendArrow->setVisible(true); + } + + const auto sendModelThisToCurrent = mixer->channelSendModel(index, currentIndex); + if (sendModelThisToCurrent) + { + thisLine->m_receiveArrowOrSendButton->setVisible(true); + thisLine->m_receiveArrowOrSendButton->setCurrentIndex(thisLine->m_receiveArrowStackedIndex); + } + else + { + thisLine->m_receiveArrowOrSendButton->setVisible(!mixer->isInfiniteLoop(currentIndex, index)); + thisLine->m_receiveArrowOrSendButton->setCurrentIndex(thisLine->m_sendButtonStackedIndex); } - // disable the send button if it would cause an infinite loop - thisLine->m_sendButton->setVisible(!mix->isInfiniteLoop(selIndex, index)); thisLine->m_sendButton->updateLightStatus(); thisLine->update(); }