Something went wrong. Try again.
Mixxx DJ software with MCP, Subsonic/Navidrome streaming library support — browse and load tracks from your self-hosted music server mixxx.org
subsonic navidrome streaming audio dj mac linux midi
Something went wrong. Try again.
C++
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207#include "widget/weffectchainpresetselector.h"
#include <QAbstractItemView>#include <QStyleOption>#include <QStylePainter>
#include "effects/chains/quickeffectchain.h"#include "effects/effectsmanager.h"#include "effects/presets/effectchainpreset.h"#include "effects/presets/effectpreset.h"#include "moc_weffectchainpresetselector.cpp"#include "widget/effectwidgetutils.h"
class QPaintEvent;
WEffectChainPresetSelector::WEffectChainPresetSelector( QWidget* pParent, EffectsManager* pEffectsManager) : QComboBox(pParent), WBaseWidget(this), m_bQuickEffectChain(false), m_pChainPresetManager(pEffectsManager->getChainPresetManager()), m_pEffectsManager(pEffectsManager) { // Prevent this widget from getting focused by Tab/Shift+Tab // to avoid interfering with using the library via keyboard. // Allow click focus though so the list can always be opened by mouse, // see https://github.com/mixxxdj/mixxx/issues/10184 setFocusPolicy(Qt::ClickFocus);}
void WEffectChainPresetSelector::setup(const QDomNode& node, const SkinContext& context) { m_pChain = EffectWidgetUtils::getEffectChainFromNode( node, context, m_pEffectsManager);
#ifdef __STEM__ VERIFY_OR_DEBUG_ASSERT(m_pChain != nullptr) { SKIN_WARNING(node, context, QStringLiteral("EffectChainPresetSelector node could not " "attach to EffectChain")); return; }#else if (m_pChain == nullptr) { // This happens if the skin has stem nodes but Mixxx has no stem support. return; }#endif
auto* pQuickEffectChain = qobject_cast<QuickEffectChain*>(m_pChain.data()); if (pQuickEffectChain) { connect(m_pChainPresetManager.data(), &EffectChainPresetManager::quickEffectChainPresetListUpdated, this, &WEffectChainPresetSelector::populate); m_bQuickEffectChain = true; } else { connect(m_pChainPresetManager.data(), &EffectChainPresetManager::effectChainPresetListUpdated, this, &WEffectChainPresetSelector::populate); } connect(m_pChain.data(), &EffectChain::chainPresetChanged, this, &WEffectChainPresetSelector::slotChainPresetChanged); connect(this, QOverload<int>::of(&QComboBox::activated), this, &WEffectChainPresetSelector::slotEffectChainPresetSelected); // Show/hide the chains list connect(m_pChain.data(), &EffectChain::presetListShowRequest, this, &WEffectChainPresetSelector::slotPresetListShowRequest); // Callback when list is shown/hidden connect(this, &WEffectChainPresetSelector::presetListVisibleChanged, m_pChain.data(), &EffectChain::slotPresetListVisibleChanged);
populate();}
void WEffectChainPresetSelector::populate() { blockSignals(true); clear();
QFontMetrics metrics(font());
QList<EffectChainPresetPointer> presetList; if (m_bQuickEffectChain) { presetList = m_pEffectsManager->getChainPresetManager()->getQuickEffectPresetsSorted(); } else { presetList = m_pEffectsManager->getChainPresetManager()->getPresetsSorted(); }
const EffectsBackendManagerPointer pBackendManager = m_pEffectsManager->getBackendManager(); QStringList effectNames; for (int i = 0; i < presetList.size(); i++) { auto pChainPreset = presetList.at(i); QString elidedDisplayName = metrics.elidedText(pChainPreset->name(), Qt::ElideMiddle, view()->width() - 2); addItem(elidedDisplayName, QVariant(pChainPreset->name())); QString tooltip = QStringLiteral("<b>") + pChainPreset->name() + QStringLiteral("</b>"); for (const auto& pEffectPreset : pChainPreset->effectPresets()) { if (!pEffectPreset->isEmpty()) { EffectManifestPointer pManifest = pBackendManager->getManifest(pEffectPreset); if (pManifest) { effectNames.append(pManifest->name()); } } } if (effectNames.size() > 1) { tooltip.append("<br/>"); tooltip.append(effectNames.join("<br/>")); } effectNames.clear(); setItemData(i, tooltip, Qt::ToolTipRole); }
slotChainPresetChanged(m_pChain->presetName()); blockSignals(false);}
void WEffectChainPresetSelector::slotEffectChainPresetSelected(int index) { Q_UNUSED(index); m_pChain->loadChainPreset( m_pChainPresetManager->getPreset(currentData().toString())); // Clicking a chain item moves keyboard focus to the list view. // Move focus back to the previously focused library widget. ControlObject::set(ConfigKey("[Library]", "refocus_prev_widget"), 1);}
void WEffectChainPresetSelector::slotChainPresetChanged(const QString& name) { setCurrentIndex(findData(name)); setBaseTooltip(itemData(currentIndex(), Qt::ToolTipRole).toString());}
void WEffectChainPresetSelector::slotPresetListShowRequest(bool show) { if (!isVisible()) { return; } if (show) { showPopup(); } else { hidePopup(); }}
/// This opens the popup. Overrides showPopup() so we can set the visibility control,/// both when clicking the down arrow and when triggering the control.void WEffectChainPresetSelector::showPopup() { if (count() > 0) { QComboBox::showPopup(); emit presetListVisibleChanged(true); }}
/// Same as showPopup(), override to set the visibility control for both GUI and/// control changesvoid WEffectChainPresetSelector::hidePopup() { QComboBox::hidePopup(); emit presetListVisibleChanged(false);}
bool WEffectChainPresetSelector::event(QEvent* pEvent) { if (pEvent->type() == QEvent::ToolTip) { updateTooltip(); } else if (pEvent->type() == QEvent::Wheel && !hasFocus()) { // don't change preset by scrolling hovered preset selector return true; }
return QComboBox::event(pEvent);}
void WEffectChainPresetSelector::paintEvent(QPaintEvent* e) { Q_UNUSED(e); // The default paint implementation aligns the text based on the layout direction. // Override to allow qss to align the text of the closed combobox with the // Quick effect controls in the mixer. QStylePainter painter(this); QStyleOptionComboBox comboStyle; // Initialize the style and draw the frame, down-arrow etc. // Note: using 'comboStyle.initFrom(this)' and 'painter.drawComplexControl(...) // here would not paint the hover style of the down arrow. initStyleOption(&comboStyle); style()->drawComplexControl(QStyle::CC_ComboBox, &comboStyle, &painter, this);
QStyleOptionButton buttonStyle; buttonStyle.initFrom(this); QRect buttonRect = style()->subControlRect( QStyle::CC_ComboBox, &comboStyle, QStyle::SC_ComboBoxEditField, this); buttonStyle.rect = buttonRect; QFontMetrics metrics(font()); // Since the chain selector and the popup can differ in width, // elide the button text independently from the popup display name. buttonStyle.text = metrics.elidedText( currentData().toString(), Qt::ElideRight, buttonRect.width()); // Draw the text for the selector button. Alternative: painter.drawControl(...) style()->drawControl(QStyle::CE_PushButtonLabel, &buttonStyle, &painter, this);}