From 066f6b5e958955db3d7c0c6e6ae179b22ca7728a Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Mon, 7 Oct 2024 13:25:11 +0200 Subject: [PATCH] Align the rename line edit for tracks (#7414) Align the rename line edit for tracks. Make sure that the rename line edit of the `TrackLabelButton` has the same font size as the widget itself. Because the font size is defined via style sheets the font size of the line edit has to be set when the actual renaming starts and not in the constructor. The reason is that style sheets are set after the constructor has run. Rename the local variable `txt` to the more speaking name `trackName`. Ensure that the line edit is moved to the correct place for different icon sizes by taking the icon size into account. To make this work this also has to be done in the `rename` method. ## Other changes Streamline the default style sheet of `TrackLabelButton` by removing repeated properties that are inherited from the "main" style sheet, i.e. that are already part of `lmms--gui--TrackLabelButton`. Interestingly, the `background-color` property had to be repeated for `lmms--gui--TrackLabelButton:hover`. --------- Co-authored-by: Michael Gregorius --- data/themes/default/style.css | 11 ----------- src/gui/tracks/TrackLabelButton.cpp | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index ef98c060999..e2dd369f952 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -601,17 +601,11 @@ lmms--gui--TrackLabelButton:hover { background: #3B424A; border: 1px solid #515B66; border-radius: none; - font-size: 11px; - font-weight: normal; - padding: 2px 1px; } lmms--gui--TrackLabelButton:pressed { background: #262B30; border-radius: none; - font-size: 11px; - font-weight: normal; - padding: 2px 1px; } lmms--gui--TrackLabelButton:checked { @@ -619,17 +613,12 @@ lmms--gui--TrackLabelButton:checked { background: #1C1F24; background-image: url("resources:track_shadow_p.png"); border-radius: none; - font-size: 11px; - font-weight: normal; - padding: 2px 1px; } lmms--gui--TrackLabelButton:checked:pressed { border: 1px solid #2f353b; background: #0e1012; background-image: url("resources:track_shadow_p.png"); - font-size: 11px; - padding: 2px 1px; font-weight: solid; } diff --git a/src/gui/tracks/TrackLabelButton.cpp b/src/gui/tracks/TrackLabelButton.cpp index 871d42316e5..dd19f3d19fc 100644 --- a/src/gui/tracks/TrackLabelButton.cpp +++ b/src/gui/tracks/TrackLabelButton.cpp @@ -50,6 +50,7 @@ TrackLabelButton::TrackLabelButton( TrackView * _tv, QWidget * _parent ) : setAcceptDrops( true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); + m_renameLineEdit = new TrackRenameLineEdit( this ); m_renameLineEdit->hide(); @@ -60,8 +61,6 @@ TrackLabelButton::TrackLabelButton( TrackView * _tv, QWidget * _parent ) : else { setFixedSize( 160, 29 ); - m_renameLineEdit->move( 30, ( height() / 2 ) - ( m_renameLineEdit->sizeHint().height() / 2 ) ); - m_renameLineEdit->setFixedWidth( width() - 33 ); connect( m_renameLineEdit, SIGNAL(editingFinished()), this, SLOT(renameFinished())); } @@ -89,11 +88,22 @@ void TrackLabelButton::rename() } else { - QString txt = m_trackView->getTrack()->name(); - m_renameLineEdit->show(); - m_renameLineEdit->setText( txt ); + const auto & trackName = m_trackView->getTrack()->name(); + m_renameLineEdit->setText(trackName); m_renameLineEdit->selectAll(); m_renameLineEdit->setFocus(); + + // Make sure that the rename line edit uses the same font as the widget + // which is set via style sheets + m_renameLineEdit->setFont(font()); + + // Move the line edit to the correct position by taking the size of the + // icon into account. + const auto iconWidth = iconSize().width(); + m_renameLineEdit->move(iconWidth + 1, (height() / 2 - m_renameLineEdit->sizeHint().height() / 2) + 1); + m_renameLineEdit->setFixedWidth(width() - (iconWidth + 6)); + + m_renameLineEdit->show(); } }