summaryrefslogtreecommitdiffstats
path: root/src/widget
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2020-03-15 17:20:01 +0100
committerDaniel Schürmann <daschuer@mixxx.org>2020-03-17 23:51:27 +0100
commitd13f3ab486125b3ddbce8926f2330cf83e795468 (patch)
tree2698b225b533b009e0cf4609f5670628d5604b12 /src/widget
parent7ece3ef9525a0957178d04b3923964d41c0051f6 (diff)
Added WHotcueButton featuring a right click context menu
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/whotcuebutton.cpp59
-rw-r--r--src/widget/whotcuebutton.h26
-rw-r--r--src/widget/woverview.cpp2
-rw-r--r--src/widget/woverview.h3
4 files changed, 88 insertions, 2 deletions
diff --git a/src/widget/whotcuebutton.cpp b/src/widget/whotcuebutton.cpp
new file mode 100644
index 0000000000..de177abfe3
--- /dev/null
+++ b/src/widget/whotcuebutton.cpp
@@ -0,0 +1,59 @@
+#include "widget/whotcuebutton.h"
+
+#include <QtDebug>
+#include "mixer/playerinfo.h"
+
+WHotcueButton::WHotcueButton(QWidget* pParent)
+ : WPushButton(pParent),
+ m_hotcue(Cue::kNoHotCue) {
+}
+
+void WHotcueButton::setup(const QDomNode& node, const SkinContext& context) {
+ // Setup parent class.
+ WPushButton::setup(node, context);
+
+ m_group = context.selectString(node, "Group");
+ bool ok;
+ int hotcue = context.selectString(node, "Hotcue").toInt(&ok);
+ if (ok && hotcue > 0) {
+ m_hotcue = hotcue - 1;
+ }
+
+ m_pCueMenuPopup = make_parented<WCueMenuPopup>(context.getConfig(), this);
+ ColorPaletteSettings colorPaletteSettings(context.getConfig());
+ auto colorPalette = colorPaletteSettings.getHotcueColorPalette();
+ m_pCueMenuPopup->setColorPalette(colorPalette);
+
+ setFocusPolicy(Qt::NoFocus);
+}
+
+void WHotcueButton::mousePressEvent(QMouseEvent* e) {
+ const bool rightClick = e->button() == Qt::RightButton;
+ if (rightClick) {
+ 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;
+ }
+ m_pCueMenuPopup->setTrackAndCue(pTrack, pHotCue);
+ m_pCueMenuPopup->popup(e->globalPos());
+ }
+ return;
+ }
+
+ // Pass all other press events to the base class.
+ WPushButton::mousePressEvent(e);
+}
diff --git a/src/widget/whotcuebutton.h b/src/widget/whotcuebutton.h
new file mode 100644
index 0000000000..0f2d81b176
--- /dev/null
+++ b/src/widget/whotcuebutton.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <QDomNode>
+#include <QMouseEvent>
+#include <QWidget>
+
+#include "skin/skincontext.h"
+#include "util/parented_ptr.h"
+#include "widget/wcuemenupopup.h"
+#include "widget/wpushbutton.h"
+
+class WHotcueButton : public WPushButton {
+ Q_OBJECT
+ public:
+ WHotcueButton(QWidget* pParent);
+
+ void setup(const QDomNode& node, const SkinContext& context) override;
+
+ protected:
+ void mousePressEvent(QMouseEvent* e) override;
+
+ private:
+ QString m_group;
+ int m_hotcue;
+ parented_ptr<WCueMenuPopup> m_pCueMenuPopup;
+};
diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp
index 4fb65c6fbf..a6475491f7 100644
--- a/src/widget/woverview.cpp
+++ b/src/widget/woverview.cpp
@@ -54,7 +54,7 @@ WOverview::WOverview(
m_group(group),
m_pConfig(pConfig),
m_endOfTrack(false),
- m_pCueMenuPopup(std::make_unique<WCueMenuPopup>(pConfig, this)),
+ m_pCueMenuPopup(make_parented<WCueMenuPopup>(pConfig, this)),
m_bShowCueTimes(true),
m_iPosSeconds(0),
m_bLeftClickDragging(false),
diff --git a/src/widget/woverview.h b/src/widget/woverview.h
index 25ce680bd1..a3e6a93d44 100644
--- a/src/widget/woverview.h
+++ b/src/widget/woverview.h
@@ -25,6 +25,7 @@
#include "widget/wwidget.h"
#include "util/color/color.h"
+#include "util/parented_ptr.h"
#include "waveform/renderers/waveformsignalcolors.h"
#include "waveform/renderers/waveformmarkset.h"
@@ -141,7 +142,7 @@ class WOverview : public WWidget, public TrackDropTarget {
TrackPointer m_pCurrentTrack;
ConstWaveformPointer m_pWaveform;
- std::unique_ptr<WCueMenuPopup> m_pCueMenuPopup;
+ parented_ptr<WCueMenuPopup> m_pCueMenuPopup;
bool m_bShowCueTimes;
int m_iPosSeconds;