1 | /* $Id: UIFilePathSelector.h 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIFilePathSelector class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___UIFilePathSelector_h___
|
---|
19 | #define ___UIFilePathSelector_h___
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* GUI includes: */
|
---|
25 | #include "QIComboBox.h"
|
---|
26 | #include "QIWithRetranslateUI.h"
|
---|
27 | #include "UILibraryDefs.h"
|
---|
28 |
|
---|
29 | /* Forward declarations: */
|
---|
30 | class QAction;
|
---|
31 | class QFocusEvent;
|
---|
32 | class QHBoxLayout;
|
---|
33 | class QObject;
|
---|
34 | class QResizeEvent;
|
---|
35 | class QWidget;
|
---|
36 | class QString;
|
---|
37 | class QILabel;
|
---|
38 | class QILineEdit;
|
---|
39 | class QIToolButton;
|
---|
40 |
|
---|
41 | /** QIComboBox subclass providing GUI with the
|
---|
42 | * possibility to choose/reflect file/folder path. */
|
---|
43 | class SHARED_LIBRARY_STUFF UIFilePathSelector : public QIWithRetranslateUI<QIComboBox>
|
---|
44 | {
|
---|
45 | Q_OBJECT;
|
---|
46 |
|
---|
47 | signals:
|
---|
48 |
|
---|
49 | /** Notify listeners about @a strPath changed. */
|
---|
50 | void pathChanged(const QString &strPath);
|
---|
51 |
|
---|
52 | public:
|
---|
53 |
|
---|
54 | /** Modes file-path selector operates in. */
|
---|
55 | enum Mode
|
---|
56 | {
|
---|
57 | Mode_Folder = 0,
|
---|
58 | Mode_File_Open,
|
---|
59 | Mode_File_Save
|
---|
60 | };
|
---|
61 |
|
---|
62 | /** Combo-box field IDs file-path selector uses. */
|
---|
63 | enum
|
---|
64 | {
|
---|
65 | PathId = 0,
|
---|
66 | SelectId,
|
---|
67 | ResetId
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** Constructs file-path selector passing @a pParent to QIComboBox base-class. */
|
---|
71 | UIFilePathSelector(QWidget *pParent = 0);
|
---|
72 |
|
---|
73 | /** Defines the @a enmMode to operate in. */
|
---|
74 | void setMode(Mode enmMode);
|
---|
75 | /** Returns the mode to operate in. */
|
---|
76 | Mode mode() const { return m_enmMode; }
|
---|
77 |
|
---|
78 | /** Defines whether the path is @a fEditable. */
|
---|
79 | void setEditable(bool fEditable);
|
---|
80 | /** Returns whether the path is editable. */
|
---|
81 | bool isEditable() const { return m_fEditable; }
|
---|
82 |
|
---|
83 | /** Defines whether the reseting to defauilt path is @a fEnabled. */
|
---|
84 | void setResetEnabled(bool fEnabled);
|
---|
85 | /** Returns whether the reseting to defauilt path is enabled. */
|
---|
86 | bool isResetEnabled() const { return count() - 1 == ResetId; }
|
---|
87 |
|
---|
88 | /** Defines the file-dialog @a strTitle. */
|
---|
89 | void setFileDialogTitle(const QString &strTitle) { m_strFileDialogTitle = strTitle; }
|
---|
90 | /** Returns the file-dialog title. */
|
---|
91 | QString fileDialogTitle() const { return m_strFileDialogTitle; }
|
---|
92 |
|
---|
93 | /** Defines the file-dialog @a strFilters. */
|
---|
94 | void setFileDialogFilters(const QString &strFilters) { m_strFileDialogFilters = strFilters; }
|
---|
95 | /** Returns the file-dialog filters. */
|
---|
96 | QString fileDialogFilters() const { return m_strFileDialogFilters; }
|
---|
97 |
|
---|
98 | /** Defines the file-dialog @a strDefaultSaveExtension. */
|
---|
99 | void setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension) { m_strFileDialogDefaultSaveExtension = strDefaultSaveExtension; }
|
---|
100 | /** Returns the file-dialog default save extension. */
|
---|
101 | QString fileDialogDefaultSaveExtension() const { return m_strFileDialogDefaultSaveExtension; }
|
---|
102 |
|
---|
103 | /** Resets path modified state to false. */
|
---|
104 | void resetModified() { m_fModified = false; }
|
---|
105 | /** Returns whether the path is modified. */
|
---|
106 | bool isModified() const { return m_fModified; }
|
---|
107 | /** Returns whether the path is selected. */
|
---|
108 | bool isPathSelected() const { return currentIndex() == PathId; }
|
---|
109 |
|
---|
110 | /** Returns the path. */
|
---|
111 | QString path() const { return m_strPath; }
|
---|
112 |
|
---|
113 | /** Sets overriden widget's @a strToolTip.
|
---|
114 | * @note If nothing set it's generated automatically. */
|
---|
115 | void setToolTip(const QString &strToolTip);
|
---|
116 |
|
---|
117 | void setDefaultPath(const QString &strDefaultPath);
|
---|
118 | const QString& defaultPath() const;
|
---|
119 |
|
---|
120 | public slots:
|
---|
121 |
|
---|
122 | /** Defines the @a strPath and @a fRefreshText after that. */
|
---|
123 | void setPath(const QString &strPath, bool fRefreshText = true);
|
---|
124 |
|
---|
125 | /** Defines the @a strHomeDir. */
|
---|
126 | void setHomeDir(const QString &strHomeDir) { m_strHomeDir = strHomeDir; }
|
---|
127 |
|
---|
128 | protected:
|
---|
129 |
|
---|
130 | /** Preprocesses every @a pEvent sent to @a pObject. */
|
---|
131 | bool eventFilter(QObject *pObject, QEvent *pEvent);
|
---|
132 |
|
---|
133 | /** Handles resize @a pEvent. */
|
---|
134 | void resizeEvent(QResizeEvent *pEvent);
|
---|
135 |
|
---|
136 | /** Handles focus-in @a pEvent. */
|
---|
137 | void focusInEvent(QFocusEvent *pEvent);
|
---|
138 | /** Handles focus-out @a pEvent. */
|
---|
139 | void focusOutEvent(QFocusEvent *pEvent);
|
---|
140 |
|
---|
141 | /** Handles translation event. */
|
---|
142 | void retranslateUi();
|
---|
143 |
|
---|
144 | private slots:
|
---|
145 |
|
---|
146 | /** Handles combo-box @a iIndex activation. */
|
---|
147 | void onActivated(int iIndex);
|
---|
148 |
|
---|
149 | /** Handles combo-box @a strText editing. */
|
---|
150 | void onTextEdited(const QString &strText);
|
---|
151 |
|
---|
152 | /** Handles combo-box text copying. */
|
---|
153 | void copyToClipboard();
|
---|
154 |
|
---|
155 | /** Refreshes combo-box text according to chosen path. */
|
---|
156 | void refreshText();
|
---|
157 |
|
---|
158 | private:
|
---|
159 |
|
---|
160 | /** Provokes change to @a strPath and @a fRefreshText after that. */
|
---|
161 | void changePath(const QString &strPath, bool fRefreshText = true);
|
---|
162 |
|
---|
163 | /** Call for file-dialog to choose path. */
|
---|
164 | void selectPath();
|
---|
165 |
|
---|
166 | /** Returns default icon. */
|
---|
167 | QIcon defaultIcon() const;
|
---|
168 |
|
---|
169 | /** Returns full path @a fAbsolute if necessary. */
|
---|
170 | QString fullPath(bool fAbsolute = true) const;
|
---|
171 |
|
---|
172 | /** Shrinks the reflected text to @a iWidth pixels. */
|
---|
173 | QString shrinkText(int iWidth) const;
|
---|
174 |
|
---|
175 | /** Holds the mode to operate in. */
|
---|
176 | Mode m_enmMode;
|
---|
177 |
|
---|
178 | /** Holds the path. */
|
---|
179 | QString m_strPath;
|
---|
180 | /** Holds the home dir. */
|
---|
181 | QString m_strHomeDir;
|
---|
182 |
|
---|
183 | /** Holds the file-dialog title. */
|
---|
184 | QString m_strFileDialogTitle;
|
---|
185 | /** Holds the file-dialog filters. */
|
---|
186 | QString m_strFileDialogFilters;
|
---|
187 | /** Holds the file-dialog default save extension. */
|
---|
188 | QString m_strFileDialogDefaultSaveExtension;
|
---|
189 |
|
---|
190 | /** Holds the cached text for empty path. */
|
---|
191 | QString m_strNoneText;
|
---|
192 | /** Holds the cached tool-tip for empty path. */
|
---|
193 | QString m_strNoneToolTip;
|
---|
194 | /** Holds the cached tool-tip for empty path in focused case. */
|
---|
195 | QString m_strNoneToolTipFocused;
|
---|
196 |
|
---|
197 | /** Holds whether the path is editable. */
|
---|
198 | bool m_fEditable;
|
---|
199 | /** Holds whether the path is modified. */
|
---|
200 | bool m_fModified;
|
---|
201 |
|
---|
202 | /** Holds whether we are in editable mode. */
|
---|
203 | bool m_fEditableMode;
|
---|
204 | /** Holds whether we are expecting mouse events. */
|
---|
205 | bool m_fMouseAwaited;
|
---|
206 |
|
---|
207 | /** Holds whether the tool-tip overriden. */
|
---|
208 | bool m_fToolTipOverriden;
|
---|
209 |
|
---|
210 | /** Holds the copy action instance. */
|
---|
211 | QAction *m_pCopyAction;
|
---|
212 |
|
---|
213 | /** Path is set to m_strDefaultPath when it is reset. */
|
---|
214 | QString m_strDefaultPath;
|
---|
215 | };
|
---|
216 |
|
---|
217 | #endif /* !___UIFilePathSelector_h___ */
|
---|