Skip to content

Commit

Permalink
Track widgets: set show_track_menu only for main decks ...
Browse files Browse the repository at this point in the history
only for those BaseTrackPlayer created the ControlPushButtons
  • Loading branch information
ronso0 committed Mar 19, 2024
1 parent 2d7768e commit 238ff87
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 37 deletions.
12 changes: 8 additions & 4 deletions src/skin/legacy/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,17 +1081,20 @@ QWidget* LegacySkinParser::parseTrackProperty(const QDomElement& node) {
return nullptr;
}

bool isMainDeck = PlayerManager::isDeckGroup(group);
WTrackProperty* pTrackProperty = new WTrackProperty(
m_pParent,
m_pConfig,
m_pLibrary,
group);
group,
isMainDeck);
setupLabelWidget(node, pTrackProperty);

// Ensure 'show_track_menu' control is created for each main deck and
// valueChangeRequest hook is set up.
// Only the first WTrackProperty that is created connects the signals.
if (PlayerManager::isDeckGroup(group)) {
if (isMainDeck) {
// Only the first WTrackProperty that is created connects the signals,
// for later attempts this returns false.
if (pPlayer->isTrackMenuControlAvailable()) {
connect(pPlayer,
&BaseTrackPlayer::trackMenuChangeRequest,
Expand Down Expand Up @@ -1143,7 +1146,8 @@ QWidget* LegacySkinParser::parseTrackWidgetGroup(const QDomElement& node) {
m_pParent,
m_pConfig,
m_pLibrary,
group);
group,
PlayerManager::isDeckGroup(group));
commonWidgetSetup(node, pGroup);
pGroup->setup(node, *m_pContext);
pGroup->Init();
Expand Down
42 changes: 25 additions & 17 deletions src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ WTrackProperty::WTrackProperty(
QWidget* pParent,
UserSettingsPointer pConfig,
Library* pLibrary,
const QString& group)
const QString& group,
bool isMainDeck)
: WLabel(pParent),
m_group(group),
m_pConfig(pConfig),
m_pLibrary(pLibrary) {
m_pLibrary(pLibrary),
m_isMainDeck(isMainDeck) {
setAcceptDrops(true);
}

Expand Down Expand Up @@ -120,22 +122,28 @@ void WTrackProperty::contextMenuEvent(QContextMenuEvent* event) {
}

void WTrackProperty::ensureTrackMenuIsCreated() {
if (m_pTrackMenu.get() == nullptr) {
m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, WTrackMenu::kDeckTrackMenuFeatures);

// When a track menu for this deck is shown/hidden via contextMenuEvent
// or pushbutton, it emits trackMenuVisible(bool).
// The pushbutton is created in BaseTrackPlayer which, on value change requests,
// also emits a signal which is connected to our slotShowTrackMenuChangeRequest().
connect(m_pTrackMenu,
&WTrackMenu::trackMenuVisible,
this,
[this](bool visible) {
ControlObject::set(ConfigKey(m_group, kShowTrackMenuKey),
visible ? 1.0 : 0.0);
});
if (m_pTrackMenu.get() != nullptr) {
return;
}

m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, WTrackMenu::kDeckTrackMenuFeatures);

// The show control exists only for main decks.
if (!m_isMainDeck) {
return;
}
// When a track menu for this deck is shown/hidden via contextMenuEvent
// or pushbutton, it emits trackMenuVisible(bool).
// The pushbutton is created in BaseTrackPlayer which, on value change requests,
// also emits a signal which is connected to our slotShowTrackMenuChangeRequest().
connect(m_pTrackMenu,
&WTrackMenu::trackMenuVisible,
this,
[this](bool visible) {
ControlObject::set(ConfigKey(m_group, kShowTrackMenuKey),
visible ? 1.0 : 0.0);
});
}

/// This slot handles show/hide requests originating from both pushbutton changes
Expand Down
4 changes: 3 additions & 1 deletion src/widget/wtrackproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class WTrackProperty : public WLabel, public TrackDropTarget {
QWidget* pParent,
UserSettingsPointer pConfig,
Library* pLibrary,
const QString& group);
const QString& group,
bool isMainDeck);
~WTrackProperty() override;

void setup(const QDomNode& node, const SkinContext& context) override;
Expand Down Expand Up @@ -48,6 +49,7 @@ class WTrackProperty : public WLabel, public TrackDropTarget {
const QString m_group;
const UserSettingsPointer m_pConfig;
Library* m_pLibrary;
const bool m_isMainDeck;
TrackPointer m_pCurrentTrack;
QString m_property;

Expand Down
35 changes: 21 additions & 14 deletions src/widget/wtrackwidgetgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ constexpr int kDefaultTrackColorAlpha = 255;
WTrackWidgetGroup::WTrackWidgetGroup(QWidget* pParent,
UserSettingsPointer pConfig,
Library* pLibrary,
const QString& group)
const QString& group,
bool isMainDeck)
: WWidgetGroup(pParent),
m_group(group),
m_pConfig(pConfig),
m_pLibrary(pLibrary),
m_trackColorAlpha(kDefaultTrackColorAlpha) {
m_trackColorAlpha(kDefaultTrackColorAlpha),
m_isMainDeck(isMainDeck) {
setAcceptDrops(true);
}

Expand Down Expand Up @@ -116,17 +118,22 @@ void WTrackWidgetGroup::contextMenuEvent(QContextMenuEvent* event) {
}

void WTrackWidgetGroup::ensureTrackMenuIsCreated() {
if (m_pTrackMenu.get() == nullptr) {
m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, WTrackMenu::kDeckTrackMenuFeatures);

// See WTrackProperty for info
connect(m_pTrackMenu,
&WTrackMenu::trackMenuVisible,
this,
[this](bool visible) {
ControlObject::set(ConfigKey(m_group, kShowTrackMenuKey),
visible ? 1.0 : 0.0);
});
if (m_pTrackMenu.get() != nullptr) {
return;
}
m_pTrackMenu = make_parented<WTrackMenu>(
this, m_pConfig, m_pLibrary, WTrackMenu::kDeckTrackMenuFeatures);

// The show control exists onlyfor main decks.
// See WTrackProperty for info
if (!m_isMainDeck) {
return;
}
connect(m_pTrackMenu,
&WTrackMenu::trackMenuVisible,
this,
[this](bool visible) {
ControlObject::set(ConfigKey(m_group, kShowTrackMenuKey),
visible ? 1.0 : 0.0);
});
}
4 changes: 3 additions & 1 deletion src/widget/wtrackwidgetgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class WTrackWidgetGroup : public WWidgetGroup, public TrackDropTarget {
WTrackWidgetGroup(QWidget* pParent,
UserSettingsPointer pConfig,
Library* pLibrary,
const QString& group);
const QString& group,
bool isMainDeck);
~WTrackWidgetGroup() override;
void setup(const QDomNode& node, const SkinContext& context) override;

Expand Down Expand Up @@ -49,6 +50,7 @@ class WTrackWidgetGroup : public WWidgetGroup, public TrackDropTarget {
TrackPointer m_pCurrentTrack;
QColor m_trackColor;
int m_trackColorAlpha;
const bool m_isMainDeck;

parented_ptr<WTrackMenu> m_pTrackMenu;
};

0 comments on commit 238ff87

Please sign in to comment.