VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILabel.h

Last change on this file was 103988, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10624. Adding missing override keywords gcc has found.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: QILabel.h 103988 2024-03-21 13:49:47Z 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
42/* GUI includes: */
43#include "UILibraryDefs.h"
44
45/** QLabel subclass extending it with advanced functionality. */
46class SHARED_LIBRARY_STUFF QILabel : public QLabel
47{
48 Q_OBJECT;
49
50public:
51
52 /** Constructs label passing @a pParent and @a enmFlags to the base-class. */
53 QILabel(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
54 /** Constructs label passing @a strText, @a pParent and @a enmFlags to the base-class. */
55 QILabel(const QString &strText, QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
56
57 /** Returns whether label full-size focusing selection is enabled. */
58 bool fullSizeSelection() const { return m_fFullSizeSelection; }
59 /** Defines whether label full-size focusing selection is @a fEnabled. */
60 void setFullSizeSelection(bool fEnabled);
61
62 /** Defines whether label should use size-hint based on passed @a iWidthHint. */
63 void useSizeHintForWidth(int iWidthHint) const;
64 /** Returns size-hint. */
65 QSize sizeHint() const RT_OVERRIDE RT_FINAL;
66 /** Returns minimum size-hint. */
67 QSize minimumSizeHint() const RT_OVERRIDE RT_FINAL;
68
69 /** Returns text. */
70 QString text() const { return m_strText; }
71
72public slots:
73
74 /** Clears text. */
75 void clear();
76 /** Defines text. */
77 void setText(const QString &strText);
78 /** Copies text into clipboard. */
79 void copy();
80
81protected:
82
83 /** Handles resize @a pEvent. */
84 void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE RT_FINAL;
85
86 /** Handles mouse-press @a pEvent. */
87 void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE RT_FINAL;
88 /** Handles mouse-release @a pEvent. */
89 void mouseReleaseEvent(QMouseEvent *pEvent) RT_OVERRIDE RT_FINAL;
90 /** Handles mouse-move @a pEvent. */
91 void mouseMoveEvent(QMouseEvent *pEvent) RT_OVERRIDE RT_FINAL;
92
93 /** Handles context-menu @a pEvent. */
94 void contextMenuEvent(QContextMenuEvent *pEvent) RT_OVERRIDE RT_FINAL;
95
96 /** Handles focus-in @a pEvent. */
97 void focusInEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
98 /** Handles focus-out @a pEvent. */
99 void focusOutEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
100
101 /** Handles paint @a pEvent. */
102 void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE RT_FINAL;
103
104private:
105
106 /** Performs initialization. */
107 void init();
108
109 /** Updates size-hint. */
110 void updateSizeHint() const;
111 /** Defines full-text. */
112 void setFullText(const QString &strText);
113 /** Updates text. */
114 void updateText();
115 /** Compresses passed @a strText. */
116 QString compressText(const QString &strText) const;
117 /** Returns text without HTML tags. */
118 static QString removeHtmlTags(const QString &strText);
119 /** Converts passed @a strType to text-elide mode flag. */
120 static Qt::TextElideMode toTextElideMode(const QString& strType);
121
122 /** Holds the text. */
123 QString m_strText;
124
125 /** Holds whether label full-size focusing selection is enabled. */
126 bool m_fFullSizeSelection;
127 /** Holds whether we started D&D. */
128 bool m_fStartDragging;
129
130 /** Holds whether the size-hint is valid. */
131 mutable bool m_fHintValid;
132 /** Holds the width-hint. */
133 mutable int m_iWidthHint;
134 /** Holds the size-hint. */
135 mutable QSize m_ownSizeHint;
136
137 /** Holds the Copy action instance. */
138 QAction *m_pCopyAction;
139
140 /** Holds text-copy reg-exp. */
141 static const QRegularExpression s_regExpCopy;
142 /** Holds text-elide reg-exp. */
143 static const QRegularExpression s_regExpElide;
144};
145
146#endif /* !FEQT_INCLUDED_SRC_extensions_QILabel_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use