Skip to content

Commit

Permalink
rename tracks directly on TrackLableButton in a QLineEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
BaraMGB committed Jul 14, 2016
1 parent 46c2aa3 commit 3fce5fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/TrackLabelButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define TRACK_LABEL_BUTTON_H

#include <QToolButton>
#include <QLineEdit>


class TrackView;
Expand All @@ -42,6 +43,7 @@ class TrackLabelButton : public QToolButton

public slots:
void rename();
void renameFinished();


protected:
Expand All @@ -55,6 +57,7 @@ public slots:
private:
TrackView * m_trackView;
QString m_iconName;
QLineEdit * m_rename;

} ;

Expand Down
40 changes: 35 additions & 5 deletions src/gui/widgets/TrackLabelButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


#include <QApplication>
#include <QLineEdit>
#include <QMouseEvent>


Expand Down Expand Up @@ -61,6 +62,13 @@ TrackLabelButton::TrackLabelButton( TrackView * _tv, QWidget * _parent ) :
setIconSize( QSize( 24, 24 ) );
setText( " " );

m_rename = new QLineEdit(this);
m_rename->move( 30, (height() / 2) - ( m_rename->sizeHint().height() / 2 ) );
m_rename->setFixedWidth( this->width() - 33 );
m_rename->hide();

connect( m_rename, SIGNAL( editingFinished() ), this, SLOT( renameFinished() ) );

connect( m_trackView->getTrack(), SIGNAL( dataChanged() ),
this, SLOT( update() ) );
}
Expand All @@ -77,18 +85,40 @@ TrackLabelButton::~TrackLabelButton()

void TrackLabelButton::rename()
{
QString txt = m_trackView->getTrack()->name();
RenameDialog rename_dlg( txt );
rename_dlg.exec();
if( txt != text() )
if( ConfigManager::inst()->value( "ui",
"compacttrackbuttons" ).toInt() )
{
QString txt = m_trackView->getTrack()->name();
RenameDialog rename_dlg( txt );
rename_dlg.exec();
if( txt != text() )
{
m_trackView->getTrack()->setName( txt );
}
}
else
{
m_trackView->getTrack()->setName( txt );
QString txt = m_trackView->getTrack()->name();
m_rename->show();
m_rename->setText( txt );
m_rename->selectAll();
m_rename->setFocus();
}
}




void TrackLabelButton::renameFinished()
{
m_rename->hide();
setText( m_rename->text() );
m_trackView->getTrack()->setName( m_rename->text() );
}




void TrackLabelButton::dragEnterEvent( QDragEnterEvent * _dee )
{
m_trackView->dragEnterEvent( _dee );
Expand Down

0 comments on commit 3fce5fa

Please sign in to comment.