From d5e1d9e853f72468ab24ea04005ca6e63a98dcca Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Wed, 17 Apr 2024 19:21:23 +0200 Subject: [PATCH] Move icon determination into TrackLabelButton again (#7209) Move icon determination into TrackLabelButton again Fully undo the changes made in commit 88e0e94dcdb because the intermediate revert made in commit 04ecf733951 seems to have led to a performance problem due to the icon being set over and over again in `TrackLabelButton::paintEvent`. The original intention of the changes made in pull request #7114 was to remove the painting code that dynamically determines the icon over and over again. Ideally the icon that is used by an instrument should be somewhat of a "static" property that should be known very early on when an instrument view is created. There should not be any need to dynamically resolve the icon over and over, especially not in a button class very far down in the widget hierarchy. However, due to technical reasons this is not the case in the current code. See pull request #7132 for more details. --- include/InstrumentTrackView.h | 2 -- src/gui/tracks/InstrumentTrackView.cpp | 7 ------- src/gui/tracks/TrackLabelButton.cpp | 25 +++++++++++++++++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/InstrumentTrackView.h b/include/InstrumentTrackView.h index cfde89bde..c7d524b36 100644 --- a/include/InstrumentTrackView.h +++ b/include/InstrumentTrackView.h @@ -71,8 +71,6 @@ public: // Create a menu for assigning/creating channels for this track QMenu * createMixerMenu( QString title, QString newMixerLabel ) override; - QPixmap determinePixmap(); - protected: void modelChanged() override; diff --git a/src/gui/tracks/InstrumentTrackView.cpp b/src/gui/tracks/InstrumentTrackView.cpp index c812999fd..1d9991c31 100644 --- a/src/gui/tracks/InstrumentTrackView.cpp +++ b/src/gui/tracks/InstrumentTrackView.cpp @@ -41,7 +41,6 @@ #include "MixerView.h" #include "GuiApplication.h" #include "Instrument.h" -#include "InstrumentTrack.h" #include "InstrumentTrackWindow.h" #include "MainWindow.h" #include "MidiClient.h" @@ -397,12 +396,6 @@ QMenu * InstrumentTrackView::createMixerMenu(QString title, QString newMixerLabe return mixerMenu; } -QPixmap InstrumentTrackView::determinePixmap() -{ - return determinePixmap(dynamic_cast(getTrack())); -} - - QPixmap InstrumentTrackView::determinePixmap(InstrumentTrack* instrumentTrack) { if (instrumentTrack) diff --git a/src/gui/tracks/TrackLabelButton.cpp b/src/gui/tracks/TrackLabelButton.cpp index c164b780e..871d42316 100644 --- a/src/gui/tracks/TrackLabelButton.cpp +++ b/src/gui/tracks/TrackLabelButton.cpp @@ -31,6 +31,8 @@ #include "ConfigManager.h" #include "embed.h" #include "InstrumentTrackView.h" +#include "Instrument.h" +#include "InstrumentTrack.h" #include "RenameDialog.h" #include "TrackRenameLineEdit.h" #include "TrackView.h" @@ -181,12 +183,27 @@ void TrackLabelButton::mouseReleaseEvent( QMouseEvent *_me ) void TrackLabelButton::paintEvent(QPaintEvent* pe) { - InstrumentTrackView* instrumentTrackView = dynamic_cast(m_trackView); - if (instrumentTrackView) + if (m_trackView->getTrack()->type() == Track::Type::Instrument) { - setIcon(instrumentTrackView->determinePixmap()); + auto it = dynamic_cast(m_trackView->getTrack()); + const PixmapLoader* pl; + auto get_logo = [](InstrumentTrack* it) -> const PixmapLoader* + { + return it->instrument()->key().isValid() + ? it->instrument()->key().logo() + : it->instrument()->descriptor()->logo; + }; + if (it && it->instrument() && + it->instrument()->descriptor() && + (pl = get_logo(it))) + { + if (pl->pixmapName() != m_iconName) + { + m_iconName = pl->pixmapName(); + setIcon(pl->pixmap()); + } + } } - QToolButton::paintEvent(pe); }