dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pathchooser.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef PATHCHOOSER_H
29 #define PATHCHOOSER_H
30 
31 #include "utils_global.h"
32 
33 #include <QWidget>
34 #include <QAbstractButton>
35 
36 namespace Utils {
37 
38 struct PathChooserPrivate;
39 
44 class QTCREATOR_UTILS_EXPORT PathChooser : public QWidget
45 {
46  Q_DISABLE_COPY(PathChooser)
47  Q_OBJECT
48  Q_ENUMS(Kind)
49  Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
50  Q_PROPERTY(QString promptDialogTitle READ promptDialogTitle WRITE setPromptDialogTitle DESIGNABLE true)
51  Q_PROPERTY(Kind expectedKind READ expectedKind WRITE setExpectedKind DESIGNABLE true)
52 
53 public:
54  static const char * const browseButtonLabel;
55 
56  explicit PathChooser(QWidget *parent = nullptr);
57  virtual ~PathChooser();
58 
59  enum Kind {
60  Directory,
61  File,
62  Command
63  // ,Any
64  };
65 
66  // Default is <Directory>
67  void setExpectedKind(Kind expected);
68  Kind expectedKind() const;
69 
70  void setPromptDialogTitle(const QString &title);
71  QString promptDialogTitle() const;
72 
73  void setPromptDialogFilter(const QString &filter);
74  QString promptDialogFilter() const;
75 
76  void setInitialBrowsePathBackup(const QString &path);
77 
78  bool isValid() const;
79  QString errorMessage() const;
80 
81  QString path() const;
82 
84  static QString label();
85 
86  virtual bool validatePath(const QString &path, QString *errorMessage = nullptr);
87 
89  static QString homePath();
90 
91  void addButton(const QString &text, QObject *receiver, const char *slotFunc);
92  QAbstractButton *buttonAtIndex(int index) const;
93 
94 private:
95  // Returns overridden title or the one from <title>
96  QString makeDialogTitle(const QString &title);
97 
98 signals:
99  void validChanged();
100  void validChanged(bool validState);
101  void changed(const QString &text);
102  void editingFinished();
103  void beforeBrowsing();
104  void browsingFinished();
105  void returnPressed();
106 
107 public slots:
108  void setPath(const QString &);
109 
110 private slots:
111  void slotBrowse();
112 
113 private:
114  PathChooserPrivate *m_d;
115 };
116 
117 } // namespace Utils
118 
119 
120 #endif // PATHCHOOSER_H