1 | /* $Id: QILabel.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QILabel class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | /*
|
---|
29 | * This class is based on the original QLabel implementation.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #ifndef FEQT_INCLUDED_SRC_extensions_QILabel_h
|
---|
33 | #define FEQT_INCLUDED_SRC_extensions_QILabel_h
|
---|
34 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
35 | # pragma once
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /* Qt includes: */
|
---|
39 | #include <QLabel>
|
---|
40 | #include <QRegularExpression>
|
---|
41 | #include <QRegExp>
|
---|
42 |
|
---|
43 | /* GUI includes: */
|
---|
44 | #include "UILibraryDefs.h"
|
---|
45 |
|
---|
46 | /** QLabel subclass extending it with advanced functionality. */
|
---|
47 | class SHARED_LIBRARY_STUFF QILabel : public QLabel
|
---|
48 | {
|
---|
49 | Q_OBJECT;
|
---|
50 |
|
---|
51 | public:
|
---|
52 |
|
---|
53 | /** Constructs label passing @a pParent and @a enmFlags to the base-class. */
|
---|
54 | QILabel(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
|
---|
55 | /** Constructs label passing @a strText, @a pParent and @a enmFlags to the base-class. */
|
---|
56 | QILabel(const QString &strText, QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
|
---|
57 |
|
---|
58 | /** Returns whether label full-size focusing selection is enabled. */
|
---|
59 | bool fullSizeSelection() const { return m_fFullSizeSelection; }
|
---|
60 | /** Defines whether label full-size focusing selection is @a fEnabled. */
|
---|
61 | void setFullSizeSelection(bool fEnabled);
|
---|
62 |
|
---|
63 | /** Defines whether label should use size-hint based on passed @a iWidthHint. */
|
---|
64 | void useSizeHintForWidth(int iWidthHint) const;
|
---|
65 | /** Returns size-hint. */
|
---|
66 | QSize sizeHint() const;
|
---|
67 | /** Returns minimum size-hint. */
|
---|
68 | QSize minimumSizeHint() const;
|
---|
69 |
|
---|
70 | /** Returns text. */
|
---|
71 | QString text() const { return m_strText; }
|
---|
72 |
|
---|
73 | public slots:
|
---|
74 |
|
---|
75 | /** Clears text. */
|
---|
76 | void clear();
|
---|
77 | /** Defines text. */
|
---|
78 | void setText(const QString &strText);
|
---|
79 | /** Copies text into clipboard. */
|
---|
80 | void copy();
|
---|
81 |
|
---|
82 | protected:
|
---|
83 |
|
---|
84 | /** Handles resize @a pEvent. */
|
---|
85 | void resizeEvent(QResizeEvent *pEvent);
|
---|
86 |
|
---|
87 | /** Handles mouse-press @a pEvent. */
|
---|
88 | void mousePressEvent(QMouseEvent *pEvent);
|
---|
89 | /** Handles mouse-release @a pEvent. */
|
---|
90 | void mouseReleaseEvent(QMouseEvent *pEvent);
|
---|
91 | /** Handles mouse-move @a pEvent. */
|
---|
92 | void mouseMoveEvent(QMouseEvent *pEvent);
|
---|
93 |
|
---|
94 | /** Handles context-menu @a pEvent. */
|
---|
95 | void contextMenuEvent(QContextMenuEvent *pEvent);
|
---|
96 |
|
---|
97 | /** Handles focus-in @a pEvent. */
|
---|
98 | void focusInEvent(QFocusEvent *pEvent);
|
---|
99 | /** Handles focus-out @a pEvent. */
|
---|
100 | void focusOutEvent(QFocusEvent *pEvent);
|
---|
101 |
|
---|
102 | /** Handles paint @a pEvent. */
|
---|
103 | void paintEvent(QPaintEvent *pEvent);
|
---|
104 |
|
---|
105 | private:
|
---|
106 |
|
---|
107 | /** Performs initialization. */
|
---|
108 | void init();
|
---|
109 |
|
---|
110 | /** Updates size-hint. */
|
---|
111 | void updateSizeHint() const;
|
---|
112 | /** Defines full-text. */
|
---|
113 | void setFullText(const QString &strText);
|
---|
114 | /** Updates text. */
|
---|
115 | void updateText();
|
---|
116 | /** Compresses passed @a strText. */
|
---|
117 | QString compressText(const QString &strText) const;
|
---|
118 | /** Returns text without HTML tags. */
|
---|
119 | static QString removeHtmlTags(const QString &strText);
|
---|
120 | /** Converts passed @a strType to text-elide mode flag. */
|
---|
121 | static Qt::TextElideMode toTextElideMode(const QString& strType);
|
---|
122 |
|
---|
123 | /** Holds the text. */
|
---|
124 | QString m_strText;
|
---|
125 |
|
---|
126 | /** Holds whether label full-size focusing selection is enabled. */
|
---|
127 | bool m_fFullSizeSelection;
|
---|
128 | /** Holds whether we started D&D. */
|
---|
129 | bool m_fStartDragging;
|
---|
130 |
|
---|
131 | /** Holds whether the size-hint is valid. */
|
---|
132 | mutable bool m_fHintValid;
|
---|
133 | /** Holds the width-hint. */
|
---|
134 | mutable int m_iWidthHint;
|
---|
135 | /** Holds the size-hint. */
|
---|
136 | mutable QSize m_ownSizeHint;
|
---|
137 |
|
---|
138 | /** Holds the Copy action instance. */
|
---|
139 | QAction *m_pCopyAction;
|
---|
140 |
|
---|
141 | /** Holds text-copy reg-exp. */
|
---|
142 | static const QRegularExpression s_regExpCopy;
|
---|
143 | /** Holds text-elide reg-exp. */
|
---|
144 | static QRegExp s_regExpElide;
|
---|
145 | };
|
---|
146 |
|
---|
147 | #endif /* !FEQT_INCLUDED_SRC_extensions_QILabel_h */
|
---|