VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 4 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: UIFilePathSelector.h 104358 2024-04-18 05:33:40Z 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 "UILibraryDefs.h"
37#include "UIMediumDefs.h"
38
39/* Forward declarations: */
40class QAction;
41class QFocusEvent;
42class QHBoxLayout;
43class QObject;
44class QResizeEvent;
45class QWidget;
46class QString;
47class QILabel;
48class QILineEdit;
49class QIToolButton;
50
51/** QIComboBox subclass providing GUI with the
52 * possibility to choose/reflect file/folder path. */
53class SHARED_LIBRARY_STUFF UIFilePathSelector : public QIComboBox
54{
55 Q_OBJECT;
56
57signals:
58
59 /** Notify listeners about @a strPath changed. */
60 void pathChanged(const QString &strPath);
61
62public:
63
64 /** Modes file-path selector operates in. */
65 enum Mode
66 {
67 Mode_Folder = 0,
68 Mode_File_Open,
69 Mode_File_Save
70 };
71
72 /** Combo-box field IDs file-path selector uses. */
73 enum
74 {
75 PathId = 0,
76 SelectId,
77 ResetId
78 };
79
80 /** Constructs file-path selector passing @a pParent to QIComboBox base-class. */
81 UIFilePathSelector(QWidget *pParent = 0);
82
83 /** Defines the @a enmMode to operate in. */
84 void setMode(Mode enmMode);
85 /** Returns the mode to operate in. */
86 Mode mode() const { return m_enmMode; }
87
88 /** Defines whether the path is @a fEditable. */
89 void setEditable(bool fEditable);
90 /** Returns whether the path is editable. */
91 bool isEditable() const { return m_fEditable; }
92
93 /** Defines whether the reseting to defauilt path is @a fEnabled. */
94 void setResetEnabled(bool fEnabled);
95 /** Returns whether the reseting to defauilt path is enabled. */
96 bool isResetEnabled() const { return count() - 1 == ResetId; }
97
98 /** Defines the file-dialog @a strTitle. */
99 void setFileDialogTitle(const QString &strTitle) { m_strFileDialogTitle = strTitle; }
100 /** Returns the file-dialog title. */
101 QString fileDialogTitle() const { return m_strFileDialogTitle; }
102
103 /** Defines the file-dialog @a strFilters. */
104 void setFileDialogFilters(const QString &strFilters) { m_strFileDialogFilters = strFilters; }
105 /** Returns the file-dialog filters. */
106 QString fileDialogFilters() const { return m_strFileDialogFilters; }
107
108 /** Defines the file-dialog @a strDefaultSaveExtension. */
109 void setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension) { m_strFileDialogDefaultSaveExtension = strDefaultSaveExtension; }
110 /** Returns the file-dialog default save extension. */
111 QString fileDialogDefaultSaveExtension() const { return m_strFileDialogDefaultSaveExtension; }
112
113 /** Resets path modified state to false. */
114 void resetModified() { m_fModified = false; }
115 /** Returns whether the path is modified. */
116 bool isModified() const { return m_fModified; }
117 /** Returns whether the path is selected. */
118 bool isPathSelected() const { return currentIndex() == PathId; }
119
120 /** Returns the path. */
121 QString path() const { return m_strPath; }
122 /** Returns the path which we pass to QFileDialog as initial path. */
123 QString initialPath() const { return m_strInitialPath; }
124
125 /** Returns true if the selected path points to an existing/readable file. */
126 bool isValid() const;
127
128 /** Sets overriden widget's @a strToolTip.
129 * @note If nothing set it's generated automatically. */
130 void setToolTip(const QString &strToolTip);
131
132 void setDefaultPath(const QString &strDefaultPath);
133 const QString& defaultPath() const;
134
135 void setRecentMediaListType(UIMediumDeviceType enmMediumType);
136 UIMediumDeviceType recentMediaListType() const;
137
138public slots:
139
140 /** Defines the @a strPath and @a fRefreshText after that. */
141 void setPath(const QString &strPath, bool fRefreshText = true);
142
143 /** Defines the @a strInitialPath. */
144 void setInitialPath(const QString &strInitialPath) { m_strInitialPath = strInitialPath; }
145
146protected:
147
148 /** Preprocesses every @a pEvent sent to @a pObject. */
149 bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE RT_FINAL;
150
151 /** Handles resize @a pEvent. */
152 void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE RT_FINAL;
153
154 /** Handles focus-in @a pEvent. */
155 void focusInEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
156 /** Handles focus-out @a pEvent. */
157 void focusOutEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
158
159private slots:
160
161 /** Handles combo-box @a iIndex activation. */
162 void onActivated(int iIndex);
163
164 /** Handles combo-box @a strText editing. */
165 void onTextEdited(const QString &strText);
166
167 /** Handles combo-box text copying. */
168 void copyToClipboard();
169
170 /** Refreshes combo-box text according to chosen path. */
171 void refreshText();
172
173 void sltRecentMediaListUpdated(UIMediumDeviceType enmMediumType);
174
175 /** Handles translation event. */
176 void sltRetranslateUI();
177
178private:
179
180 /** Provokes change to @a strPath and @a fRefreshText after that. */
181 void changePath(const QString &strPath, bool fRefreshText = true);
182
183 /** Call for file-dialog to choose path. */
184 void selectPath();
185
186 /** Returns default icon. */
187 QIcon defaultIcon() const;
188
189 /** Returns full path @a fAbsolute if necessary. */
190 QString fullPath(bool fAbsolute = true) const;
191
192 /** Shrinks the reflected text to @a iWidth pixels. */
193 QString shrinkText(int iWidth) const;
194
195 /** Holds the mode to operate in. */
196 Mode m_enmMode;
197
198 /** Holds the path. */
199 QString m_strPath;
200 /** Holds the path which we pass to QFileDialog as initial path. */
201 QString m_strInitialPath;
202
203 /** Holds the file-dialog title. */
204 QString m_strFileDialogTitle;
205 /** Holds the file-dialog filters. */
206 QString m_strFileDialogFilters;
207 /** Holds the file-dialog default save extension. */
208 QString m_strFileDialogDefaultSaveExtension;
209
210 /** Holds the cached text for empty path. */
211 QString m_strNoneText;
212 /** Holds the cached tool-tip for empty path. */
213 QString m_strNoneToolTip;
214
215 /** Holds whether editor has Reset action. */
216 bool m_fResetEnabled;
217
218 /** Holds whether the path is editable. */
219 bool m_fEditable;
220 /** Holds whether the path is modified. */
221 bool m_fModified;
222
223 /** Holds whether we are in editable mode. */
224 bool m_fEditableMode;
225 /** Holds whether we are expecting mouse events. */
226 bool m_fMouseAwaited;
227
228 /** Holds whether the tool-tip overriden. */
229 bool m_fToolTipOverriden;
230
231 /** Holds the copy action instance. */
232 QAction *m_pCopyAction;
233
234 /** Path is set to m_strDefaultPath when it is reset. */
235 QString m_strDefaultPath;
236
237 /** Holds the recent list separator position. */
238 int m_iRecentListSeparatorPosition;
239 /** Holds whether medium type for recent media list. If it is UIMediumDeviceType_Invalid the recent list is not shown. */
240 UIMediumDeviceType m_enmRecentMediaListType;
241};
242
243#endif /* !FEQT_INCLUDED_SRC_widgets_UIFilePathSelector_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use