Skip to content

Commit

Permalink
Merge pull request #12212 from ronso0/trackmenu-on-demand
Browse files Browse the repository at this point in the history
WTrackMenu: create only on demand for deck widgets
  • Loading branch information
daschuer authored Oct 24, 2023
2 parents d3915e6 + f6caf67 commit 8c92561
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ WTrackProperty::WTrackProperty(
: WLabel(pParent),
m_group(group),
m_pConfig(pConfig),
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
m_pLibrary(pLibrary) {
setAcceptDrops(true);
}

Expand Down Expand Up @@ -102,6 +101,7 @@ void WTrackProperty::mouseMoveEvent(QMouseEvent* event) {
void WTrackProperty::mouseDoubleClickEvent(QMouseEvent* event) {
Q_UNUSED(event);
if (m_pCurrentTrack) {
ensureTrackMenuIsCreated();
m_pTrackMenu->loadTrack(m_pCurrentTrack, m_group);
m_pTrackMenu->showDlgTrackInfo(m_property);
}
Expand All @@ -118,8 +118,16 @@ void WTrackProperty::dropEvent(QDropEvent* event) {
void WTrackProperty::contextMenuEvent(QContextMenuEvent* event) {
event->accept();
if (m_pCurrentTrack) {
ensureTrackMenuIsCreated();
m_pTrackMenu->loadTrack(m_pCurrentTrack, m_group);
// Create the right-click menu
m_pTrackMenu->popup(event->globalPos());
}
}

void WTrackProperty::ensureTrackMenuIsCreated() {
if (m_pTrackMenu.get() == nullptr) {
m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, kTrackMenuFeatures);
}
}
5 changes: 4 additions & 1 deletion src/widget/wtrackproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ private slots:

void updateLabel();

void ensureTrackMenuIsCreated();

const QString m_group;
const UserSettingsPointer m_pConfig;
Library* m_pLibrary;
TrackPointer m_pCurrentTrack;
QString m_property;

const parented_ptr<WTrackMenu> m_pTrackMenu;
parented_ptr<WTrackMenu> m_pTrackMenu;
};
13 changes: 10 additions & 3 deletions src/widget/wtracktext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ WTrackText::WTrackText(QWidget* pParent,
: WLabel(pParent),
m_group(group),
m_pConfig(pConfig),
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
m_pLibrary(pLibrary) {
setAcceptDrops(true);
}

Expand Down Expand Up @@ -86,6 +85,7 @@ void WTrackText::mouseMoveEvent(QMouseEvent *event) {
void WTrackText::mouseDoubleClickEvent(QMouseEvent* event) {
Q_UNUSED(event);
if (m_pCurrentTrack) {
ensureTrackMenuIsCreated();
m_pTrackMenu->loadTrack(m_pCurrentTrack, m_group);
m_pTrackMenu->slotShowDlgTrackInfo();
}
Expand All @@ -102,8 +102,15 @@ void WTrackText::dropEvent(QDropEvent *event) {
void WTrackText::contextMenuEvent(QContextMenuEvent* event) {
event->accept();
if (m_pCurrentTrack) {
ensureTrackMenuIsCreated();
m_pTrackMenu->loadTrack(m_pCurrentTrack, m_group);
// Create the right-click menu
m_pTrackMenu->popup(event->globalPos());
}
}

void WTrackText::ensureTrackMenuIsCreated() {
if (m_pTrackMenu.get() == nullptr) {
m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, kTrackMenuFeatures);
}
}
5 changes: 4 additions & 1 deletion src/widget/wtracktext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ class WTrackText : public WLabel, public TrackDropTarget {

void updateLabel();

void ensureTrackMenuIsCreated();

const QString m_group;
UserSettingsPointer m_pConfig;
Library* m_pLibrary;
TrackPointer m_pCurrentTrack;
const parented_ptr<WTrackMenu> m_pTrackMenu;
parented_ptr<WTrackMenu> m_pTrackMenu;
};
13 changes: 10 additions & 3 deletions src/widget/wtrackwidgetgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ WTrackWidgetGroup::WTrackWidgetGroup(QWidget* pParent,
: WWidgetGroup(pParent),
m_group(group),
m_pConfig(pConfig),
m_trackColorAlpha(kDefaultTrackColorAlpha),
m_pTrackMenu(make_parented<WTrackMenu>(
this, pConfig, pLibrary, kTrackMenuFeatures)) {
m_pLibrary(pLibrary),
m_trackColorAlpha(kDefaultTrackColorAlpha) {
setAcceptDrops(true);
}

Expand Down Expand Up @@ -125,8 +124,16 @@ void WTrackWidgetGroup::dropEvent(QDropEvent* event) {
void WTrackWidgetGroup::contextMenuEvent(QContextMenuEvent* event) {
event->accept();
if (m_pCurrentTrack) {
ensureTrackMenuIsCreated();
m_pTrackMenu->loadTrack(m_pCurrentTrack, m_group);
// Create the right-click menu
m_pTrackMenu->popup(event->globalPos());
}
}

void WTrackWidgetGroup::ensureTrackMenuIsCreated() {
if (m_pTrackMenu.get() == nullptr) {
m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, kTrackMenuFeatures);
}
}
5 changes: 4 additions & 1 deletion src/widget/wtrackwidgetgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ class WTrackWidgetGroup : public WWidgetGroup, public TrackDropTarget {

void updateColor();

void ensureTrackMenuIsCreated();

const QString m_group;
const UserSettingsPointer m_pConfig;
Library* m_pLibrary;
TrackPointer m_pCurrentTrack;
QColor m_trackColor;
int m_trackColorAlpha;

const parented_ptr<WTrackMenu> m_pTrackMenu;
parented_ptr<WTrackMenu> m_pTrackMenu;
};

0 comments on commit 8c92561

Please sign in to comment.