1
/**********************************************************************
2
** Copyright (C) 2001 Trolltech AS. All rights reserved.
4
** This file is part of Qt Designer.
6
** This file may be distributed and/or modified under the terms of the
7
** GNU General Public License version 2 as published by the Free Software
8
** Foundation and appearing in the file LICENSE.GPL included in the
9
** packaging of this file.
11
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12
** licenses may use this file in accordance with the Qt Commercial License
13
** Agreement provided with the Software.
15
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18
** See http://www.trolltech.com/gpl/ for GPL licensing information.
19
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20
** information about Qt Commercial License Agreements.
22
** Contact info@trolltech.com if any conditions of this licensing are
25
**********************************************************************/
27
#include "filechooser.h"
28
#include <qlineedit.h>
29
#include <qpushbutton.h>
30
#include <qfiledialog.h>
33
#include <kfiledialog.h>
35
FileChooser::FileChooser( QWidget *parent, const char *name )
36
: QWidget( parent, name ), md( File )
38
QHBoxLayout *layout = new QHBoxLayout( this );
39
layout->setMargin( 0 );
41
lineEdit = new QLineEdit( this, "filechooser_lineedit" );
42
layout->addWidget( lineEdit );
44
connect( lineEdit, SIGNAL( textChanged( const QString & ) ),
45
this, SIGNAL( fileNameChanged( const QString & ) ) );
47
button = new QPushButton( "...", this, "filechooser_button" );
48
button->setFixedWidth( button->fontMetrics().width( " ... " ) );
49
layout->addWidget( button );
51
connect( button, SIGNAL( clicked() ),
52
this, SLOT( chooseFile() ) );
54
setFocusProxy( lineEdit );
57
void FileChooser::setMode( Mode m )
62
FileChooser::Mode FileChooser::mode() const
67
void FileChooser::setFileName( const QString &fn )
69
lineEdit->setText( fn );
72
QString FileChooser::fileName() const
74
return lineEdit->text();
77
void FileChooser::chooseFile()
81
fn = KFileDialog::getOpenFileName( lineEdit->text(), QString::null, this );
83
fn = KFileDialog::getExistingDirectory( lineEdit->text(),this );
85
if ( !fn.isEmpty() ) {
86
lineEdit->setText( fn );
87
emit fileNameChanged( fn );