~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to kdevdesigner/designer/filechooser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
** Copyright (C) 2001 Trolltech AS.  All rights reserved.
3
 
**
4
 
** This file is part of Qt Designer.
5
 
**
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.
10
 
**
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.
14
 
**
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.
17
 
**
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.
21
 
**
22
 
** Contact info@trolltech.com if any conditions of this licensing are
23
 
** not clear to you.
24
 
**
25
 
**********************************************************************/
26
 
 
27
 
#include "filechooser.h"
28
 
#include <qlineedit.h>
29
 
#include <qpushbutton.h>
30
 
#include <qfiledialog.h>
31
 
#include <qlayout.h>
32
 
 
33
 
#include <kfiledialog.h>
34
 
 
35
 
FileChooser::FileChooser( QWidget *parent, const char *name )
36
 
    : QWidget( parent, name ), md( File )
37
 
{
38
 
    QHBoxLayout *layout = new QHBoxLayout( this );
39
 
    layout->setMargin( 0 );
40
 
 
41
 
    lineEdit = new QLineEdit( this, "filechooser_lineedit" );
42
 
    layout->addWidget( lineEdit );
43
 
 
44
 
    connect( lineEdit, SIGNAL( textChanged( const QString & ) ),
45
 
             this, SIGNAL( fileNameChanged( const QString & ) ) );
46
 
 
47
 
    button = new QPushButton( "...", this, "filechooser_button" );
48
 
    button->setFixedWidth( button->fontMetrics().width( " ... " ) );
49
 
    layout->addWidget( button );
50
 
 
51
 
    connect( button, SIGNAL( clicked() ),
52
 
             this, SLOT( chooseFile() ) );
53
 
 
54
 
    setFocusProxy( lineEdit );
55
 
}
56
 
 
57
 
void FileChooser::setMode( Mode m )
58
 
{
59
 
    md = m;
60
 
}
61
 
 
62
 
FileChooser::Mode FileChooser::mode() const
63
 
{
64
 
    return md;
65
 
}
66
 
 
67
 
void FileChooser::setFileName( const QString &fn )
68
 
{
69
 
    lineEdit->setText( fn );
70
 
}
71
 
 
72
 
QString FileChooser::fileName() const
73
 
{
74
 
    return lineEdit->text();
75
 
}
76
 
 
77
 
void FileChooser::chooseFile()
78
 
{
79
 
    QString fn;
80
 
    if ( mode() == File )
81
 
        fn = KFileDialog::getOpenFileName( lineEdit->text(), QString::null, this );
82
 
    else
83
 
        fn = KFileDialog::getExistingDirectory( lineEdit->text(),this );
84
 
 
85
 
    if ( !fn.isEmpty() ) {
86
 
        lineEdit->setText( fn );
87
 
        emit fileNameChanged( fn );
88
 
    }
89
 
}
90