1 | /* $Id: QIRichTextLabel.h 98312 2023-01-26 12:52:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIRichTextLabel class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-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_QIRichTextLabel_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QIRichTextLabel_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QTextBrowser>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QIWithRetranslateUI.h"
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 |
|
---|
41 | /* Forward declarations: */
|
---|
42 | class QAction;
|
---|
43 |
|
---|
44 | /** QLabel analog to reflect rich-text,
|
---|
45 | ** based on private QTextBrowser functionality. */
|
---|
46 | class SHARED_LIBRARY_STUFF QIRichTextLabel : public QIWithRetranslateUI<QWidget>
|
---|
47 | {
|
---|
48 | Q_OBJECT;
|
---|
49 | Q_PROPERTY(QString text READ text WRITE setText);
|
---|
50 |
|
---|
51 | signals:
|
---|
52 |
|
---|
53 | /** Notifies listeners about @a link clicked. */
|
---|
54 | void sigLinkClicked(const QUrl &link);
|
---|
55 |
|
---|
56 | public:
|
---|
57 |
|
---|
58 | /** Constructs rich text-label passing @a pParent to the base-class. */
|
---|
59 | QIRichTextLabel(QWidget *pParent = 0);
|
---|
60 |
|
---|
61 | /** Returns text. */
|
---|
62 | QString text() const;
|
---|
63 | /** Returns plain text. */
|
---|
64 | QString plainText() const;
|
---|
65 |
|
---|
66 | /** Registers @a image under a passed @a strName. */
|
---|
67 | void registerImage(const QImage &image, const QString &strName);
|
---|
68 | /** Registers @a pixmap under a passed @a strName. */
|
---|
69 | void registerPixmap(const QPixmap &pixmap, const QString &strName);
|
---|
70 |
|
---|
71 | /** Returns word wrapping policy. */
|
---|
72 | QTextOption::WrapMode wordWrapMode() const;
|
---|
73 | /** Defines word wrapping @a policy. */
|
---|
74 | void setWordWrapMode(QTextOption::WrapMode policy);
|
---|
75 |
|
---|
76 | /** Installs event filter for a passed @ pFilterObj. */
|
---|
77 | void installEventFilter(QObject *pFilterObj);
|
---|
78 |
|
---|
79 | /** Returns browser font. */
|
---|
80 | QFont browserFont() const;
|
---|
81 | /** Defines @a newFont for browser. */
|
---|
82 | void setBrowserFont(const QFont &newFont);
|
---|
83 |
|
---|
84 | public slots:
|
---|
85 |
|
---|
86 | /** Returns minimum text width. */
|
---|
87 | int minimumTextWidth() const;
|
---|
88 | /** Defines @a iMinimumTextWidth. */
|
---|
89 | void setMinimumTextWidth(int iMinimumTextWidth);
|
---|
90 |
|
---|
91 | /** Defines @a strText. */
|
---|
92 | void setText(const QString &strText);
|
---|
93 |
|
---|
94 | /** Copies text-browser text into clipboard. */
|
---|
95 | void copy();
|
---|
96 |
|
---|
97 | protected:
|
---|
98 |
|
---|
99 | /** Handles translation event. */
|
---|
100 | virtual void retranslateUi() RT_OVERRIDE;
|
---|
101 |
|
---|
102 | private slots:
|
---|
103 |
|
---|
104 | /** Handles the fact of text-browser text copy available.
|
---|
105 | * @param fYes Brings whether some text is selected and can
|
---|
106 | * be copied directly by QTextBrowser::copy() call. */
|
---|
107 | void sltHandleCopyAvailable(bool fYes) { m_fCopyAvailable = fYes; }
|
---|
108 |
|
---|
109 | private:
|
---|
110 |
|
---|
111 | /** Holds the text-browser instance. */
|
---|
112 | QTextBrowser *m_pTextBrowser;
|
---|
113 |
|
---|
114 | /** Holds the context-menu Copy action instance. */
|
---|
115 | QAction *m_pActionCopy;
|
---|
116 | /** Holds whether text-browser text copy is available. */
|
---|
117 | bool m_fCopyAvailable;
|
---|
118 |
|
---|
119 | /** Holds the minimum text-width. */
|
---|
120 | int m_iMinimumTextWidth;
|
---|
121 | };
|
---|
122 |
|
---|
123 | #endif /* !FEQT_INCLUDED_SRC_extensions_QIRichTextLabel_h */
|
---|