-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathwhotcuebutton.cpp
178 lines (154 loc) · 5.83 KB
/
whotcuebutton.cpp
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
#include "widget/whotcuebutton.h"
#include <QStyleOption>
#include <QStylePainter>
#include <QtDebug>
#include "mixer/playerinfo.h"
#include "moc_whotcuebutton.cpp"
#include "track/track.h"
namespace {
constexpr int kDefaultDimBrightThreshold = 127;
} // namespace
WHotcueButton::WHotcueButton(const QString& group, QWidget* pParent)
: WPushButton(pParent),
m_group(group),
m_hotcue(Cue::kNoHotCue),
m_hoverCueColor(false),
m_pCoColor(nullptr),
m_cueColorDimThreshold(kDefaultDimBrightThreshold),
m_bCueColorDimmed(false),
m_bCueColorIsLight(false),
m_bCueColorIsDark(false) {
}
void WHotcueButton::setup(const QDomNode& node, const SkinContext& context) {
// Setup parent class.
WPushButton::setup(node, context);
bool ok;
int hotcue = context.selectInt(node, QStringLiteral("Hotcue"), &ok);
if (ok && hotcue > 0) {
m_hotcue = hotcue - 1;
} else {
SKIN_WARNING(node, context) << "Hotcue value invalid";
}
bool okay;
m_cueColorDimThreshold = context.selectInt(node, QStringLiteral("DimBrightThreshold"), &okay);
if (!okay) {
m_cueColorDimThreshold = kDefaultDimBrightThreshold;
}
m_hoverCueColor = context.selectBool(node, QStringLiteral("Hover"), false);
m_pCueMenuPopup = make_parented<WCueMenuPopup>(context.getConfig(), this);
ColorPaletteSettings colorPaletteSettings(context.getConfig());
auto colorPalette = colorPaletteSettings.getHotcueColorPalette();
m_pCueMenuPopup->setColorPalette(colorPalette);
setFocusPolicy(Qt::NoFocus);
m_pCoColor = make_parented<ControlProxy>(
createConfigKey(QStringLiteral("color")),
this,
ControlFlag::NoAssertIfMissing);
m_pCoColor->connectValueChanged(this, &WHotcueButton::slotColorChanged);
slotColorChanged(m_pCoColor->get());
auto* pLeftConnection = new ControlParameterWidgetConnection(
this,
createConfigKey(QStringLiteral("activate")),
nullptr,
ControlParameterWidgetConnection::DIR_FROM_WIDGET,
ControlParameterWidgetConnection::EMIT_ON_PRESS_AND_RELEASE);
addLeftConnection(pLeftConnection);
auto* pDisplayConnection = new ControlParameterWidgetConnection(
this,
createConfigKey(QStringLiteral("enabled")),
nullptr,
ControlParameterWidgetConnection::DIR_TO_WIDGET,
ControlParameterWidgetConnection::EMIT_NEVER);
addConnection(pDisplayConnection);
setDisplayConnection(pDisplayConnection);
QDomNode con = context.selectNode(node, QStringLiteral("Connection"));
if (!con.isNull()) {
SKIN_WARNING(node, context) << "Additional Connections are not allowed";
}
}
void WHotcueButton::mousePressEvent(QMouseEvent* e) {
const bool rightClick = e->button() == Qt::RightButton;
if (rightClick) {
if (isPressed()) {
// Discard right clicks when already left clicked.
// Otherwise the pop up menu receives the release event and the
// button stucks in the pressed stage.
return;
}
if (readDisplayValue() == 1) {
// hot cue is set
TrackPointer pTrack = PlayerInfo::instance().getTrackInfo(m_group);
if (!pTrack) {
return;
}
CuePointer pHotCue;
QList<CuePointer> cueList = pTrack->getCuePoints();
for (const auto& pCue : cueList) {
if (pCue->getHotCue() == m_hotcue) {
pHotCue = pCue;
break;
}
}
if (!pHotCue) {
return;
}
if (e->modifiers().testFlag(Qt::ShiftModifier)) {
pTrack->removeCue(pHotCue);
return;
}
m_pCueMenuPopup->setTrackAndCue(pTrack, pHotCue);
// use the bottom left corner as starting point for popup
m_pCueMenuPopup->popup(mapToGlobal(QPoint(0, height())));
}
return;
}
// Pass all other press events to the base class.
WPushButton::mousePressEvent(e);
}
void WHotcueButton::mouseReleaseEvent(QMouseEvent* e) {
const bool rightClick = e->button() == Qt::RightButton;
if (rightClick) {
// Don't handle stray release events
return;
}
WPushButton::mouseReleaseEvent(e);
}
ConfigKey WHotcueButton::createConfigKey(const QString& name) {
ConfigKey key;
key.group = m_group;
// Add one to hotcue so that we don't have a hotcue_0
key.item = QStringLiteral("hotcue_") + QString::number(m_hotcue + 1) + QChar('_') + name;
return key;
}
void WHotcueButton::slotColorChanged(double color) {
VERIFY_OR_DEBUG_ASSERT(color >= 0 && color <= 0xFFFFFF) {
return;
}
QColor cueColor = QColor::fromRgb(static_cast<QRgb>(color));
m_bCueColorDimmed = Color::isDimColorCustom(cueColor, m_cueColorDimThreshold);
QString style =
QStringLiteral("WWidget[displayValue=\"1\"] { background-color: ") +
cueColor.name() +
QStringLiteral("; }");
if (m_hoverCueColor) {
style +=
QStringLiteral("WWidget[displayValue=\"1\"]:hover { background-color: ") +
cueColor.lighter(m_bCueColorDimmed ? 120 : 80).name() +
QStringLiteral("; }");
}
setStyleSheet(style);
restyleAndRepaint();
}
void WHotcueButton::restyleAndRepaint() {
if (readDisplayValue()) {
// Adjust properties for Qss file
m_bCueColorIsLight = !m_bCueColorDimmed;
m_bCueColorIsDark = m_bCueColorDimmed;
} else {
// We are now at the background set by qss.
// Since we don't know the color reset both
m_bCueColorIsLight = false;
m_bCueColorIsDark = false;
}
WPushButton::restyleAndRepaint();
}