Simplify TrackLabelButton

Remove the dependency to `Instrument` and `InstrumentTrack` from `TrackLabelButton`. The icon of an `InstrumentTrackView` is now determined in the class `InstrumentTrackView` itself using the new method `determinePixmap`. This enables the removal of the overridden `paintEvent` method from `TrackLabelButton`.
This commit is contained in:
Michael Gregorius
2023-12-24 22:49:39 +01:00
parent 3aefe7b3d3
commit 88e0e94dcd
4 changed files with 27 additions and 33 deletions

View File

@@ -93,6 +93,8 @@ private slots:
void handleConfigChange(QString cls, QString attr, QString value);
private:
QPixmap determinePixmap(InstrumentTrack * instrumentTrack);
private:
InstrumentTrackWindow * m_window;

View File

@@ -55,7 +55,6 @@ protected:
void mousePressEvent( QMouseEvent * _me ) override;
void mouseDoubleClickEvent( QMouseEvent * _me ) override;
void mouseReleaseEvent( QMouseEvent * _me ) override;
void paintEvent( QPaintEvent * _pe ) override;
void resizeEvent( QResizeEvent * _re ) override;

View File

@@ -40,6 +40,7 @@
#include "Mixer.h"
#include "MixerView.h"
#include "GuiApplication.h"
#include "Instrument.h"
#include "InstrumentTrack.h"
#include "InstrumentTrackWindow.h"
#include "MainWindow.h"
@@ -62,7 +63,7 @@ InstrumentTrackView::InstrumentTrackView( InstrumentTrack * _it, TrackContainerV
m_tlb = new TrackLabelButton( this, getTrackSettingsWidget() );
m_tlb->setCheckable( true );
m_tlb->setIcon( embed::getIconPixmap( "instrument_track" ) );
m_tlb->setIcon(determinePixmap(_it));
m_tlb->show();
connect( m_tlb, SIGNAL(toggled(bool)),
@@ -393,4 +394,27 @@ QMenu * InstrumentTrackView::createMixerMenu(QString title, QString newMixerLabe
}
QPixmap InstrumentTrackView::determinePixmap(InstrumentTrack * instrumentTrack)
{
if (instrumentTrack)
{
Instrument * instrument = instrumentTrack->instrument();
if (instrument && instrument->descriptor())
{
const PixmapLoader * pl = instrument->key().isValid() ?
instrument->key().logo() :
instrument->descriptor()->logo;
if(pl)
{
return pl->pixmap();
}
}
}
return embed::getIconPixmap("instrument_track");
}
} // namespace lmms::gui

View File

@@ -31,8 +31,6 @@
#include "ConfigManager.h"
#include "embed.h"
#include "Engine.h"
#include "Instrument.h"
#include "InstrumentTrack.h"
#include "RenameDialog.h"
#include "Song.h"
#include "TrackRenameLineEdit.h"
@@ -185,35 +183,6 @@ void TrackLabelButton::mouseReleaseEvent( QMouseEvent *_me )
void TrackLabelButton::paintEvent( QPaintEvent * _pe )
{
if( m_trackView->getTrack()->type() == Track::Type::Instrument )
{
auto it = dynamic_cast<InstrumentTrack*>(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 );
}
void TrackLabelButton::resizeEvent(QResizeEvent *_re)
{
setText( elideName( m_trackView->getTrack()->displayName() ) );