Skip to content

Commit

Permalink
add right click menu on WOverview to edit hotcue label & color
Browse files Browse the repository at this point in the history
This is much easier to use and discover than finding the track in the
library, right clicking it, opening the track Properties window, and
going to the Cuepoints tab.
  • Loading branch information
Be-ing committed Aug 15, 2019
1 parent 65d2790 commit f9a540f
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ def sources(self, build):
"src/sources/soundsourceproxy.cpp",

"src/widget/controlwidgetconnection.cpp",
"src/widget/cuemenu.cpp",
"src/widget/wbasewidget.cpp",
"src/widget/wwidget.cpp",
"src/widget/wwidgetgroup.cpp",
Expand Down
78 changes: 78 additions & 0 deletions src/widget/cuemenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <QInputDialog>

#include "widget/cuemenu.h"
#include "util/color/color.h"

CueMenu::CueMenu(QWidget *parent)
: QMenu(parent) {
m_pEditLabel = new QAction(tr("Edit label"));
addAction(m_pEditLabel);
connect(m_pEditLabel, &QAction::triggered, this, &CueMenu::slotEditLabel);

m_pColorMenu = new QMenu(this);
m_pColorMenu->setTitle(tr("Set color"));
addMenu(m_pColorMenu);

for (const auto& pColor : Color::kPredefinedColorsSet.allColors) {
if (*pColor == *Color::kPredefinedColorsSet.noColor) {
continue;
}

QAction* pColorAction = new QAction(pColor->m_sDisplayName);
QPixmap pixmap(80, 80);
pixmap.fill(pColor->m_defaultRgba);
pColorAction->setIcon(QIcon(pixmap));

m_pColorMenuActions.append(pColorAction);
m_pColorMenu->addAction(pColorAction);
connect(pColorAction, &QAction::triggered, this, [pColor, this]() {
changeCueColor(pColor);
});
}

m_pRemoveCue = new QAction(tr("Remove"));
addAction(m_pRemoveCue);
connect(m_pRemoveCue, &QAction::triggered, this, &CueMenu::slotRemoveCue);
}

CueMenu::~CueMenu() {
delete m_pEditLabel;
for (auto& pAction : m_pColorMenuActions) {
delete pAction;
}
delete m_pColorMenu;
delete m_pRemoveCue;
}

void CueMenu::slotEditLabel() {
VERIFY_OR_DEBUG_ASSERT(m_pCue != nullptr) {
return;
}
bool okay = false;
QString newLabel = QInputDialog::getText(this, tr("Edit cue label"),
tr("Cue label"), QLineEdit::Normal,
m_pCue->getLabel(), &okay);
if (okay) {
m_pCue->setLabel(newLabel);
}
}

void CueMenu::changeCueColor(PredefinedColorPointer pColor) {
VERIFY_OR_DEBUG_ASSERT(m_pCue != nullptr) {
return;
}
VERIFY_OR_DEBUG_ASSERT(pColor != nullptr) {
return;
}
m_pCue->setColor(pColor);
}

void CueMenu::slotRemoveCue() {
VERIFY_OR_DEBUG_ASSERT(m_pCue != nullptr) {
return;
}
VERIFY_OR_DEBUG_ASSERT(m_pTrack != nullptr) {
return;
}
m_pTrack->removeCue(m_pCue);
}
37 changes: 37 additions & 0 deletions src/widget/cuemenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <QMenu>

#include "track/track.h"
#include "track/cue.h"

class CueMenu : public QMenu {
Q_OBJECT
public:
CueMenu(QWidget *parent = nullptr);
~CueMenu() override;

void setCue(CuePointer pCue) {
m_pCue = pCue;
}

void setTrack(TrackPointer pTrack) {
m_pTrack = pTrack;
}

private slots:
void slotEditLabel();
void slotRemoveCue();

private:
// This is not a Qt slot because it is connected via a lambda.
void changeCueColor(PredefinedColorPointer pColor);

CuePointer m_pCue;
TrackPointer m_pTrack;

QAction* m_pEditLabel;
QMenu* m_pColorMenu;
QList<QAction*> m_pColorMenuActions;
QAction* m_pRemoveCue;
};
39 changes: 36 additions & 3 deletions src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ WOverview::WOverview(
m_group(group),
m_pConfig(pConfig),
m_endOfTrack(false),
m_pCueMenu(std::make_unique<CueMenu>(this)),
m_bDrag(false),
m_iPos(0),
m_orientation(Qt::Horizontal),
Expand Down Expand Up @@ -362,14 +363,46 @@ void WOverview::mouseReleaseEvent(QMouseEvent* e) {
double dValue = positionToValue(m_iPos);
//qDebug() << "WOverview::mouseReleaseEvent" << e->pos() << m_iPos << ">>" << dValue;

setControlParameterUp(dValue);
m_bDrag = false;
if (e->button() == Qt::LeftButton) {
setControlParameterUp(dValue);
m_bDrag = false;
// Do not seek when releasing a right click. This is important to
// prevent accidental seeking when trying to right click a hotcue.
}
}

void WOverview::mousePressEvent(QMouseEvent* e) {
//qDebug() << "WOverview::mousePressEvent" << e->pos();
mouseMoveEvent(e);
m_bDrag = true;
if (e->button() == Qt::LeftButton) {
m_bDrag = true;
} else {
if (m_pCurrentTrack != nullptr) {
QList<CuePointer> cueList = m_pCurrentTrack->getCuePoints();
for (const auto& pMark : m_marksToRender) {
if (pMark->m_bMouseHovering) {
// Currently the only way WaveformMarks can be associated
// with their respective Cue objects is by using the hotcue
// number. If cues without assigned hotcue are drawn on
// WOverview in the future, another way to associate
// WaveformMarks with Cues will need to be implemented.
CuePointer pHoveredCue;
for (const auto& pCue : cueList) {
if (pCue->getHotCue() == pMark->getHotCue()) {
pHoveredCue = pCue;
break;
}
}
VERIFY_OR_DEBUG_ASSERT(pHoveredCue != nullptr) {
continue;
}
m_pCueMenu->setCue(pHoveredCue);
m_pCueMenu->setTrack(m_pCurrentTrack);
m_pCueMenu->popup(e->globalPos());
}
}
}
}
}

void WOverview::leaveEvent(QEvent* e) {
Expand Down
3 changes: 3 additions & 0 deletions src/widget/woverview.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QList>

#include "track/track.h"
#include "widget/cuemenu.h"
#include "widget/trackdroptarget.h"
#include "widget/wwidget.h"
#include "analyzer/analyzerprogress.h"
Expand Down Expand Up @@ -138,6 +139,8 @@ class WOverview : public WWidget, public TrackDropTarget {
TrackPointer m_pCurrentTrack;
ConstWaveformPointer m_pWaveform;

std::unique_ptr<CueMenu> m_pCueMenu;

// True if slider is dragged. Only used when m_bEventWhileDrag is false
bool m_bDrag;
// Internal storage of slider position in pixels
Expand Down

0 comments on commit f9a540f

Please sign in to comment.