-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweffectselector.cpp
More file actions
194 lines (164 loc) · 7.09 KB
/
Copy pathweffectselector.cpp
File metadata and controls
194 lines (164 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "widget/weffectselector.h"
#include <QAbstractItemView>
#include <QGuiApplication>
#include <QScreen>
#include <QStyledItemDelegate>
#include <QtDebug>
#include "effects/effectsmanager.h"
#include "effects/visibleeffectslist.h"
#include "moc_weffectselector.cpp"
#include "widget/effectwidgetutils.h"
namespace {
constexpr int kTouchEffectRowHeight = 56;
constexpr int kTouchEffectPopupWidth = 420;
class TouchEffectItemDelegate final : public QStyledItemDelegate {
public:
explicit TouchEffectItemDelegate(QObject* pParent)
: QStyledItemDelegate(pParent) {
}
QSize sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const override {
QSize size = QStyledItemDelegate::sizeHint(option, index);
size.setHeight(qMax(size.height(), kTouchEffectRowHeight));
size.setWidth(qMax(size.width(), kTouchEffectPopupWidth));
return size;
}
};
} // namespace
WEffectSelector::WEffectSelector(QWidget* pParent, EffectsManager* pEffectsManager)
: QComboBox(pParent),
WBaseWidget(this),
m_pEffectsManager(pEffectsManager),
m_pVisibleEffectsList(pEffectsManager->getVisibleEffectsList()) {
// 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);
// The BiteDJ side panel is intentionally compact, but the selector popup
// must not inherit that tiny geometry. Give every effect a finger-sized
// row. Do not install a QScroller gesture here: on the Pi touchscreen it
// consumes the release event, which lets the list move but prevents the
// tapped effect from being activated.
setItemDelegate(new TouchEffectItemDelegate(this));
setMaxVisibleItems(8);
view()->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
view()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void WEffectSelector::showPopup() {
const QScreen* pScreen = QGuiApplication::screenAt(
mapToGlobal(rect().center()));
const int availableWidth = pScreen != nullptr
? pScreen->availableGeometry().width()
: kTouchEffectPopupWidth;
const int availableHeight = pScreen != nullptr
? pScreen->availableGeometry().height()
: kTouchEffectRowHeight * 8;
const int popupWidth = qMin(
qMax(width(), kTouchEffectPopupWidth),
qMax(width(), availableWidth - 24));
view()->setMinimumWidth(popupWidth);
view()->setMaximumWidth(popupWidth);
// Keep the popup on-screen on smaller Mako-class displays while showing
// up to eight effects at once on the 10-inch Touch Display 2.
setMaxVisibleItems(qBound(4,
(availableHeight - 48) / kTouchEffectRowHeight,
8));
QComboBox::showPopup();
}
void WEffectSelector::setup(const QDomNode& node, const SkinContext& context) {
// EffectWidgetUtils propagates NULLs so this is all safe.
EffectChainPointer pChainSlot = EffectWidgetUtils::getEffectChainFromNode(
node, context, m_pEffectsManager);
m_pEffectSlot = EffectWidgetUtils::getEffectSlotFromNode(
node, context, pChainSlot);
if (m_pEffectSlot != nullptr) {
connect(m_pVisibleEffectsList.data(),
&VisibleEffectsList::visibleEffectsListChanged,
this,
&WEffectSelector::populate);
connect(m_pEffectSlot.data(),
&EffectSlot::effectChanged,
this,
&WEffectSelector::slotEffectUpdated);
connect(this,
QOverload<int>::of(&QComboBox::activated),
this,
&WEffectSelector::slotEffectSelected);
} else {
SKIN_WARNING(node,
context,
QStringLiteral("EffectSelector node could not attach to effect "
"slot."));
}
populate();
}
void WEffectSelector::populate() {
blockSignals(true);
clear();
const QList<EffectManifestPointer> visibleEffectManifests = m_pVisibleEffectsList->getList();
// Add empty item: no effect
addItem(kNoEffectString);
setItemData(0, QVariant(tr("No effect loaded.")), Qt::ToolTipRole);
for (int i = 0; i < visibleEffectManifests.size(); ++i) {
const EffectManifestPointer pManifest = visibleEffectManifests.at(i);
// Keep the complete name in the model. The closed combo clips it to
// the compact side panel, while the widened popup can show it whole.
addItem(pManifest->displayName(), QVariant(pManifest->uniqueId()));
QString name = pManifest->name();
QString description = pManifest->description();
// <b> makes the effect name bold. Also, like <span> it serves as hack
// to get Qt to treat the string as rich text so it automatically wraps long lines.
setItemData(i + 1,
QVariant(QStringLiteral("<b>") + name +
QStringLiteral("</b><br/>") + description),
Qt::ToolTipRole);
}
slotEffectUpdated();
blockSignals(false);
}
void WEffectSelector::slotEffectSelected(int newIndex) {
const EffectManifestPointer pManifest =
m_pEffectsManager->getBackendManager()->getManifestFromUniqueId(
itemData(newIndex).toString());
// Bite DJ fork: route through the per-manifest cache so the BeatFX
// picker preserves user knob/metaknob state across effect switches.
// Standard chains opt in; EQ/QuickEffect/Output fall through to
// loadEffectWithDefaults internally.
m_pEffectSlot->switchEffectRemembering(pManifest);
setBaseTooltip(itemData(newIndex, Qt::ToolTipRole).toString());
// Clicking an effect 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 WEffectSelector::slotEffectUpdated() {
int newIndex;
if (m_pEffectSlot != nullptr) {
if (m_pEffectSlot->getManifest() != nullptr) {
EffectManifestPointer pManifest = m_pEffectSlot->getManifest();
newIndex = findData(QVariant(pManifest->uniqueId()));
} else {
newIndex = findData(QVariant());
}
} else {
newIndex = findData(QVariant());
}
if (kEffectDebugOutput) {
qDebug() << "WEffectSelector::slotEffectUpdated"
<< "old" << itemData(currentIndex())
<< "new" << itemData(newIndex);
}
if (newIndex != -1 && newIndex != currentIndex()) {
setCurrentIndex(newIndex);
setBaseTooltip(itemData(newIndex, Qt::ToolTipRole).toString());
}
}
bool WEffectSelector::event(QEvent* pEvent) {
if (pEvent->type() == QEvent::ToolTip) {
updateTooltip();
} else if (pEvent->type() == QEvent::Wheel && !hasFocus()) {
// don't change effect by scrolling hovered effect selector
return true;
}
return QComboBox::event(pEvent);
}