Skip to content

Commit

Permalink
Align the rename line edit for tracks (#7414)
Browse files Browse the repository at this point in the history
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 <michael.gregorius.git@arcor.de>
  • Loading branch information
BaraMGB and michaelgregorius authored Oct 7, 2024
1 parent 79eac41 commit 066f6b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
11 changes: 0 additions & 11 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -601,35 +601,24 @@ 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 {
border: 1px solid #485059;
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;
}

Expand Down
20 changes: 15 additions & 5 deletions src/gui/tracks/TrackLabelButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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()));
}

Expand Down Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 066f6b5

Please sign in to comment.