Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Track widgets: set show_track_menu only for main decks #12978

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};