VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.h@ 104158

Last change on this file since 104158 was 103987, checked in by vboxsync, 9 months ago

FE/Qt: bugref:10624. Adding RT_FINAL to virtual functions whereever appropriate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: UIFilePathSelector.h 103987 2024-03-21 12:33:33Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIFilePathSelector class declaration.
4 */
5
6/*
7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef FEQT_INCLUDED_SRC_widgets_UIFilePathSelector_h
29#define FEQT_INCLUDED_SRC_widgets_UIFilePathSelector_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* GUI includes: */
35#include "QIComboBox.h"
36#include "QIWithRetranslateUI.h"
37#include "UILibraryDefs.h"
38#include "UIMediumDefs.h"
39
40/* Forward declarations: */
41class QAction;
42class QFocusEvent;
43class QHBoxLayout;
44class QObject;
45class QResizeEvent;
46class QWidget;
47class QString;
48class QILabel;
49class QILineEdit;
50class QIToolButton;
51
52/** QIComboBox subclass providing GUI with the
53 * possibility to choose/reflect file/folder path. */
54class SHARED_LIBRARY_STUFF UIFilePathSelector : public QIWithRetranslateUI<QIComboBox>
55{
56 Q_OBJECT;
57
58signals:
59
60 /** Notify listeners about @a strPath changed. */
61 void pathChanged(const QString &strPath);
62
63public:
64
65 /** Modes file-path selector operates in. */
66 enum Mode
67 {
68 Mode_Folder = 0,
69 Mode_File_Open,
70 Mode_File_Save
71 };
72
73 /** Combo-box field IDs file-path selector uses. */
74 enum
75 {
76 PathId = 0,
77 SelectId,
78 ResetId
79 };
80
81 /** Constructs file-path selector passing @a pParent to QIComboBox base-class. */
82 UIFilePathSelector(QWidget *pParent = 0);
83
84 /** Defines the @a enmMode to operate in. */
85 void setMode(Mode enmMode);
86 /** Returns the mode to operate in. */
87 Mode mode() const { return m_enmMode; }
88
89 /** Defines whether the path is @a fEditable. */
90 void setEditable(bool fEditable);
91 /** Returns whether the path is editable. */
92 bool isEditable() const { return m_fEditable; }
93
94 /** Defines whether the reseting to defauilt path is @a fEnabled. */
95 void setResetEnabled(bool fEnabled);
96 /** Returns whether the reseting to defauilt path is enabled. */
97 bool isResetEnabled() const { return count() - 1 == ResetId; }
98
99 /** Defines the file-dialog @a strTitle. */
100 void setFileDialogTitle(const QString &strTitle) { m_strFileDialogTitle = strTitle; }
101 /** Returns the file-dialog title. */
102 QString fileDialogTitle() const { return m_strFileDialogTitle; }
103
104 /** Defines the file-dialog @a strFilters. */
105 void setFileDialogFilters(const QString &strFilters) { m_strFileDialogFilters = strFilters; }
106 /** Returns the file-dialog filters. */
107 QString fileDialogFilters() const { return m_strFileDialogFilters; }
108
109 /** Defines the file-dialog @a strDefaultSaveExtension. */
110 void setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension) { m_strFileDialogDefaultSaveExtension = strDefaultSaveExtension; }
111 /** Returns the file-dialog default save extension. */
112 QString fileDialogDefaultSaveExtension() const { return m_strFileDialogDefaultSaveExtension; }
113
114 /** Resets path modified state to false. */
115 void resetModified() { m_fModified = false; }
116 /** Returns whether the path is modified. */
117 bool isModified() const { return m_fModified; }
118 /** Returns whether the path is selected. */
119 bool isPathSelected() const { return currentIndex() == PathId; }
120
121 /** Returns the path. */
122 QString path() const { return m_strPath; }
123 /** Returns the path which we pass to QFileDialog as initial path. */
124 QString initialPath() const { return m_strInitialPath; }
125
126 /** Returns true if the selected path points to an existing/readable file. */
127 bool isValid() const;
128
129 /** Sets overriden widget's @a strToolTip.
130 * @note If nothing set it's generated automatically. */
131 void setToolTip(const QString &strToolTip);
132
133 void setDefaultPath(const QString &strDefaultPath);
134 const QString& defaultPath() const;
135
136 void setRecentMediaListType(UIMediumDeviceType enmMediumType);
137 UIMediumDeviceType recentMediaListType() const;
138
139public slots:
140
141 /** Defines the @a strPath and @a fRefreshText after that. */
142 void setPath(const QString &strPath, bool fRefreshText = true);
143
144 /** Defines the @a strInitialPath. */
145 void setInitialPath(const QString &strInitialPath) { m_strInitialPath = strInitialPath; }
146
147protected:
148
149 /** Preprocesses every @a pEvent sent to @a pObject. */
150 bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE RT_FINAL;
151
152 /** Handles resize @a pEvent. */
153 void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE RT_FINAL;
154
155 /** Handles focus-in @a pEvent. */
156 void focusInEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
157 /** Handles focus-out @a pEvent. */
158 void focusOutEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
159
160 /** Handles translation event. */
161 virtual void retranslateUi() RT_OVERRIDE RT_FINAL;
162
163private slots:
164
165 /** Handles combo-box @a iIndex activation. */
166 void onActivated(int iIndex);
167
168 /** Handles combo-box @a strText editing. */
169 void onTextEdited(const QString &strText);
170
171 /** Handles combo-box text copying. */
172 void copyToClipboard();
173
174 /** Refreshes combo-box text according to chosen path. */
175 void refreshText();
176
177 void sltRecentMediaListUpdated(UIMediumDeviceType enmMediumType);
178
179private:
180
181 /** Provokes change to @a strPath and @a fRefreshText after that. */
182 void changePath(const QString &strPath, bool fRefreshText = true);
183
184 /** Call for file-dialog to choose path. */
185 void selectPath();
186
187 /** Returns default icon. */
188 QIcon defaultIcon() const;
189
190 /** Returns full path @a fAbsolute if necessary. */
191 QString fullPath(bool fAbsolute = true) const;
192
193 /** Shrinks the reflected text to @a iWidth pixels. */
194 QString shrinkText(int iWidth) const;
195
196 /** Holds the mode to operate in. */
197 Mode m_enmMode;
198
199 /** Holds the path. */
200 QString m_strPath;
201 /** Holds the path which we pass to QFileDialog as initial path. */
202 QString m_strInitialPath;
203
204 /** Holds the file-dialog title. */
205 QString m_strFileDialogTitle;
206 /** Holds the file-dialog filters. */
207 QString m_strFileDialogFilters;
208 /** Holds the file-dialog default save extension. */
209 QString m_strFileDialogDefaultSaveExtension;
210
211 /** Holds the cached text for empty path. */
212 QString m_strNoneText;
213 /** Holds the cached tool-tip for empty path. */
214 QString m_strNoneToolTip;
215
216 /** Holds whether editor has Reset action. */
217 bool m_fResetEnabled;
218
219 /** Holds whether the path is editable. */
220 bool m_fEditable;
221 /** Holds whether the path is modified. */
222 bool m_fModified;
223
224 /** Holds whether we are in editable mode. */
225 bool m_fEditableMode;
226 /** Holds whether we are expecting mouse events. */
227 bool m_fMouseAwaited;
228
229 /** Holds whether the tool-tip overriden. */
230 bool m_fToolTipOverriden;
231
232 /** Holds the copy action instance. */
233 QAction *m_pCopyAction;
234
235 /** Path is set to m_strDefaultPath when it is reset. */
236 QString m_strDefaultPath;
237
238 /** Holds the recent list separator position. */
239 int m_iRecentListSeparatorPosition;
240 /** Holds whether medium type for recent media list. If it is UIMediumDeviceType_Invalid the recent list is not shown. */
241 UIMediumDeviceType m_enmRecentMediaListType;
242};
243
244#endif /* !FEQT_INCLUDED_SRC_widgets_UIFilePathSelector_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette