1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include "utils_global.h"
38 #include <QtGui/QWidget>
41 class QAbstractButton;
49 class PathChooserPrivate;
51 class QTCREATOR_UTILS_EXPORT PathChooser : public QWidget
53 Q_DISABLE_COPY(PathChooser)
56 Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
57 Q_PROPERTY(QString promptDialogTitle READ promptDialogTitle WRITE setPromptDialogTitle DESIGNABLE true)
58 Q_PROPERTY(Kind expectedKind READ expectedKind WRITE setExpectedKind DESIGNABLE true)
59 Q_PROPERTY(QString baseDirectory READ baseDirectory WRITE setBaseDirectory DESIGNABLE true)
60 Q_PROPERTY(QStringList commandVersionArguments READ commandVersionArguments WRITE setCommandVersionArguments)
61 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE true)
64 static const char * const browseButtonLabel;
66 explicit PathChooser(QWidget *parent = 0);
67 virtual ~PathChooser();
71 Directory, // A directory, doesn't need to exist
73 ExistingCommand, // A command that must exist at the time of selection
74 Command, // A command that may or may not exist at the time of selection (e.g. result of a build)
78 // Default is <Directory>
79 void setExpectedKind(Kind expected);
80 Kind expectedKind() const;
82 void setPromptDialogTitle(const QString &title);
83 QString promptDialogTitle() const;
85 void setPromptDialogFilter(const QString &filter);
86 QString promptDialogFilter() const;
88 void setInitialBrowsePathBackup(const QString &path);
91 QString errorMessage() const;
94 QString rawPath() const; // The raw unexpanded input.
96 QString baseDirectory() const;
97 void setBaseDirectory(const QString &directory);
99 void setEnvironment(const Utils::Environment &env);
101 /** Returns the suggested label title when used in a form layout. */
102 static QString label();
104 virtual bool validatePath(const QString &path, QString *errorMessage = 0);
106 /** Return the home directory, which needs some fixing under Windows. */
107 static QString homePath();
109 void addButton(const QString &text, QObject *receiver, const char *slotFunc);
110 QAbstractButton *buttonAtIndex(int index) const;
112 QLineEdit *lineEdit() const;
114 // For PathChoosers of 'Command' type, this property specifies the arguments
115 // required to obtain the tool version (commonly, '--version'). Setting them
116 // causes the version to be displayed as a tooltip.
117 QStringList commandVersionArguments() const;
118 void setCommandVersionArguments(const QStringList &arguments);
120 // Utility to run a tool and return its stdout.
121 static QString toolVersion(const QString &binary, const QStringList &arguments);
122 // Install a tooltip on lineedits used for binaries showing the version.
123 static void installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments);
125 bool isReadOnly() const;
126 void setReadOnly(bool b);
129 // Returns overridden title or the one from <title>
130 QString makeDialogTitle(const QString &title);
134 void validChanged(bool validState);
135 void changed(const QString &text);
136 void editingFinished();
137 void beforeBrowsing();
138 void browsingFinished();
139 void returnPressed();
142 void setPath(const QString &);
148 PathChooserPrivate *m_d;
154 #endif // PATHCHOOSER_H