Skip to content
Snippets Groups Projects
pathchooser.h 4.03 KiB
Newer Older
/**************************************************************************
con's avatar
con committed
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
**
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
**
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
**
**************************************************************************/
con's avatar
con committed
#ifndef PATHCHOOSER_H
#define PATHCHOOSER_H

#include "utils_global.h"

#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QAbstractButton;
class QLineEdit;
QT_END_NAMESPACE

con's avatar
con committed

namespace Utils {

class Environment;
class PathChooserPrivate;
con's avatar
con committed

/**
 * A control that let's the user choose a path, consisting of a QLineEdit and
 * a "Browse" button. Has some validation logic for embedding into QWizardPage.
 */
class QTCREATOR_UTILS_EXPORT PathChooser : public QWidget
con's avatar
con committed
{
    Q_DISABLE_COPY(PathChooser)
    Q_OBJECT
con's avatar
con committed
    Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
    Q_PROPERTY(QString promptDialogTitle READ promptDialogTitle WRITE setPromptDialogTitle DESIGNABLE true)
    Q_PROPERTY(Kind expectedKind READ expectedKind WRITE setExpectedKind DESIGNABLE true)
dt's avatar
dt committed
    Q_PROPERTY(QString baseDirectory READ baseDirectory WRITE setBaseDirectory DESIGNABLE true)
con's avatar
con committed

public:
    static const char * const browseButtonLabel;

con's avatar
con committed
    explicit PathChooser(QWidget *parent = 0);
    virtual ~PathChooser();

    enum Kind {
        Directory,
        File,
        ExistingCommand, // A command that must exist at the time of selection
        Command, // A command that may or may not exist at the time of selection (e.g. result of a build)
    };

    // Default is <Directory>
    void setExpectedKind(Kind expected);

    void setPromptDialogTitle(const QString &title);
    QString promptDialogTitle() const;

    void setPromptDialogFilter(const QString &filter);
    QString promptDialogFilter() const;
    void setInitialBrowsePathBackup(const QString &path);

con's avatar
con committed
    bool isValid() const;
    QString errorMessage() const;

    QString path() const;
    QString rawPath() const; // The raw unexpanded input.
con's avatar
con committed

dt's avatar
dt committed
    QString baseDirectory() const;
    void setBaseDirectory(const QString &directory);

    void setEnvironment(const Utils::Environment &env);

    /** Returns the suggested label title when used in a form layout. */
con's avatar
con committed
    static QString label();

    virtual bool validatePath(const QString &path, QString *errorMessage = 0);
con's avatar
con committed

    /** Return the home directory, which needs some fixing under Windows. */
con's avatar
con committed
    static QString homePath();

    void addButton(const QString &text, QObject *receiver, const char *slotFunc);
    QAbstractButton *buttonAtIndex(int index) const;
    QLineEdit *lineEdit() const;

private:
    // Returns overridden title or the one from <title>
    QString makeDialogTitle(const QString &title);

con's avatar
con committed
signals:
    void validChanged();
    void validChanged(bool validState);
con's avatar
con committed
    void changed(const QString &text);
    void editingFinished();
    void beforeBrowsing();
    void browsingFinished();
con's avatar
con committed
    void returnPressed();

public slots:
    void setPath(const QString &);

private slots:
    void slotBrowse();

private:
    PathChooserPrivate *m_d;
};

hjk's avatar
hjk committed
} // namespace Utils
con's avatar
con committed

#endif // PATHCHOOSER_H