1 | /* $Id: QILineEdit.h 99177 2023-03-24 15:46:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QILineEdit 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_extensions_QILineEdit_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QILineEdit_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes */
|
---|
35 | #include <QIcon>
|
---|
36 | #include <QLineEdit>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 |
|
---|
41 | class QLabel;
|
---|
42 |
|
---|
43 | /** QLineEdit extension with advanced functionality. */
|
---|
44 | class SHARED_LIBRARY_STUFF QILineEdit : public QLineEdit
|
---|
45 | {
|
---|
46 | Q_OBJECT;
|
---|
47 |
|
---|
48 | public:
|
---|
49 |
|
---|
50 | /** Constructs line-edit passing @a pParent to the base-class. */
|
---|
51 | QILineEdit(QWidget *pParent = 0);
|
---|
52 | /** Constructs line-edit passing @a pParent to the base-class.
|
---|
53 | * @param strText Brings the line-edit text. */
|
---|
54 | QILineEdit(const QString &strText, QWidget *pParent = 0);
|
---|
55 |
|
---|
56 | /** Defines whether this is @a fAllowed to copy contents when disabled. */
|
---|
57 | void setAllowToCopyContentsWhenDisabled(bool fAllowed);
|
---|
58 |
|
---|
59 | /** Forces line-edit to adjust minimum width acording to passed @a strText. */
|
---|
60 | void setMinimumWidthByText(const QString &strText);
|
---|
61 | /** Forces line-edit to adjust fixed width acording to passed @a strText. */
|
---|
62 | void setFixedWidthByText(const QString &strText);
|
---|
63 |
|
---|
64 | /** Puts an icon to mark some error on the right hand side of the line edit. @p is used as tooltip of the icon. */
|
---|
65 | void mark(bool fError, const QString &strErrorMessage = QString());
|
---|
66 |
|
---|
67 | protected:
|
---|
68 |
|
---|
69 | /** Handles any Qt @a pEvent. */
|
---|
70 | virtual bool event(QEvent *pEvent) RT_OVERRIDE;
|
---|
71 |
|
---|
72 | /** Handles resize @a pEvent. */
|
---|
73 | virtual void resizeEvent(QResizeEvent *pResizeEvent) RT_OVERRIDE;
|
---|
74 |
|
---|
75 | private slots:
|
---|
76 |
|
---|
77 | /** Copies text into clipboard. */
|
---|
78 | void copy();
|
---|
79 |
|
---|
80 | private:
|
---|
81 |
|
---|
82 | /** Prepares all. */
|
---|
83 | void prepare();
|
---|
84 |
|
---|
85 | /** Calculates suitable @a strText size. */
|
---|
86 | QSize fitTextWidth(const QString &strText) const;
|
---|
87 |
|
---|
88 | /** Holds whether this is allowed to copy contents when disabled. */
|
---|
89 | bool m_fAllowToCopyContentsWhenDisabled;
|
---|
90 | /** Holds the copy to clipboard action. */
|
---|
91 | QAction *m_pCopyAction;
|
---|
92 |
|
---|
93 | QLabel *m_pIconLabel;
|
---|
94 | QIcon m_markIcon;
|
---|
95 | bool m_fMarkForError;
|
---|
96 | QString m_strErrorMessage;
|
---|
97 | };
|
---|
98 |
|
---|
99 | class SHARED_LIBRARY_STUFF UIMarkableLineEdit : public QWidget
|
---|
100 | {
|
---|
101 | Q_OBJECT;
|
---|
102 |
|
---|
103 | signals:
|
---|
104 |
|
---|
105 | void textChanged(const QString &strText);
|
---|
106 |
|
---|
107 | public:
|
---|
108 |
|
---|
109 | UIMarkableLineEdit(QWidget *pParent = 0);
|
---|
110 | void mark(bool fError, const QString &strErrorMessage = QString());
|
---|
111 |
|
---|
112 | /** @name Pass through functions for QILineEdit.
|
---|
113 | * @{ */
|
---|
114 | void setText(const QString &strText);
|
---|
115 | QString text() const;
|
---|
116 | void setValidator(const QValidator *pValidator);
|
---|
117 | bool hasAcceptableInput() const;
|
---|
118 | void setPlaceholderText(const QString &strText);
|
---|
119 | /** @} */
|
---|
120 |
|
---|
121 | private:
|
---|
122 |
|
---|
123 | void prepare();
|
---|
124 |
|
---|
125 | QILineEdit *m_pLineEdit;
|
---|
126 | QLabel *m_pIconLabel;
|
---|
127 | };
|
---|
128 |
|
---|
129 | #endif /* !FEQT_INCLUDED_SRC_extensions_QILineEdit_h */
|
---|