1 /*
2 * RenameDialog.cpp - implementation of dialog for renaming something
3 *
4 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26 #include <QKeyEvent>
27 #include <QLineEdit>
28
29 #include "RenameDialog.h"
30
31
32
RenameDialog(QString & _string)33 RenameDialog::RenameDialog( QString & _string ) :
34 QDialog(),
35 m_stringToEdit( _string ),
36 m_originalString( _string )
37 {
38 setWindowTitle( tr("Rename...") );
39 setFixedHeight( 30 );
40 m_stringLE = new QLineEdit( this );
41 m_stringLE->setText( _string );
42 m_stringLE->setGeometry ( 10, 5, 220, 20 );
43 m_stringLE->selectAll();
44 connect( m_stringLE, SIGNAL( textChanged( const QString & ) ), this,
45 SLOT( textChanged( const QString & ) ) );
46 connect( m_stringLE, SIGNAL( returnPressed() ), this,
47 SLOT( accept() ) );
48 }
49
50
51
52
~RenameDialog()53 RenameDialog::~RenameDialog()
54 {
55 }
56
57
58
59
resizeEvent(QResizeEvent * event)60 void RenameDialog::resizeEvent (QResizeEvent * event) {
61 m_stringLE->setGeometry ( 10, 5, width() - 20, 20 );
62 }
63
64
65
66
keyPressEvent(QKeyEvent * _ke)67 void RenameDialog::keyPressEvent( QKeyEvent * _ke )
68 {
69 if( _ke->key() == Qt::Key_Escape )
70 {
71 m_stringLE->setText( m_originalString );
72 accept();
73 }
74 }
75
76
77
78
textChanged(const QString & _new_string)79 void RenameDialog::textChanged( const QString & _new_string )
80 {
81 m_stringToEdit = _new_string;
82 }
83