1 | /* $Id: UIRichTextString.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIRichTextString class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2015-2024 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_objects_UIRichTextString_h
|
---|
29 | #define FEQT_INCLUDED_SRC_objects_UIRichTextString_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QTextLayout>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UILibraryDefs.h"
|
---|
39 |
|
---|
40 | /** Rich text string implementation which parses the passed QString
|
---|
41 | * and holds it as the tree of the formatted rich text blocks. */
|
---|
42 | class SHARED_LIBRARY_STUFF UIRichTextString
|
---|
43 | {
|
---|
44 | public:
|
---|
45 |
|
---|
46 | /** Rich text block types. */
|
---|
47 | enum Type
|
---|
48 | {
|
---|
49 | Type_None,
|
---|
50 | Type_Anchor,
|
---|
51 | Type_Bold,
|
---|
52 | Type_Italic,
|
---|
53 | };
|
---|
54 |
|
---|
55 | /** Constructs empty rich text string.
|
---|
56 | * @param enmType Brings the type of <i>this</i> rich text block. */
|
---|
57 | UIRichTextString(Type enmType = Type_None);
|
---|
58 |
|
---|
59 | /** Constructs rich text string.
|
---|
60 | * @param strString Brings the string being parsed and held as the tree of rich text blocks.
|
---|
61 | * @param enmType Brings the type of <i>this</i> rich text block.
|
---|
62 | * @param strStringMeta Brings the string containing meta data describing <i>this</i> rich text block. */
|
---|
63 | UIRichTextString(const QString &strString, Type enmType = Type_None, const QString &strStringMeta = QString());
|
---|
64 |
|
---|
65 | /** Destructor rich text string. */
|
---|
66 | virtual ~UIRichTextString();
|
---|
67 |
|
---|
68 | /** Returns the QString representation. */
|
---|
69 | QString toString() const;
|
---|
70 |
|
---|
71 | /** Returns the list of existing format ranges appropriate for QTextLayout.
|
---|
72 | * @param iShift Brings the shift of <i>this</i> rich text block accordig to it's root. */
|
---|
73 | QVector<QTextLayout::FormatRange> formatRanges(int iShift = 0) const;
|
---|
74 |
|
---|
75 | /** Defines the anchor to highlight in <i>this</i> rich text block and in it's children. */
|
---|
76 | void setHoveredAnchor(const QString &strHoveredAnchor);
|
---|
77 |
|
---|
78 | private:
|
---|
79 |
|
---|
80 | /** Parses the string. */
|
---|
81 | void parse();
|
---|
82 |
|
---|
83 | /** Used to populate const static map of known patterns.
|
---|
84 | * @note Keep it sync with the method below - #populatePatternHasMeta(). */
|
---|
85 | static QMap<Type, QString> populatePatterns();
|
---|
86 | /** Used to populate const static map of meta flags for the known patterns.
|
---|
87 | * @note Keep it sync with the method above - #populatePatterns(). */
|
---|
88 | static QMap<Type, bool> populatePatternHasMeta();
|
---|
89 |
|
---|
90 | /** Recursively searching for the maximum level of the passed pattern.
|
---|
91 | * @param strString Brings the string to check for the current (recursively advanced) pattern in,
|
---|
92 | * @param strPattern Brings the etalon pattern to recursively advance the current pattern with,
|
---|
93 | * @param strCurrentPattern Brings the current (recursively advanced) pattern to check for the presence of,
|
---|
94 | * @param iCurrentLevel Brings the current level of the recursively advanced pattern. */
|
---|
95 | static int searchForMaxLevel(const QString &strString, const QString &strPattern,
|
---|
96 | const QString &strCurrentPattern, int iCurrentLevel = 0);
|
---|
97 |
|
---|
98 | /** Recursively composing the pattern of the maximum level.
|
---|
99 | * @param strPattern Brings the etalon pattern to recursively update the current pattern with,
|
---|
100 | * @param strCurrentPattern Brings the current (recursively advanced) pattern,
|
---|
101 | * @param iCurrentLevel Brings the amount of the levels left to recursively advance current pattern. */
|
---|
102 | static QString composeFullPattern(const QString &strPattern,
|
---|
103 | const QString &strCurrentPattern, int iCurrentLevel);
|
---|
104 |
|
---|
105 | /** Composes the QTextCharFormat correpoding to passed @a enmType. */
|
---|
106 | static QTextCharFormat textCharFormat(Type enmType);
|
---|
107 |
|
---|
108 | /** Holds the type of <i>this</i> rich text block. */
|
---|
109 | Type m_enmType;
|
---|
110 | /** Holds the string of <i>this</i> rich text block. */
|
---|
111 | QString m_strString;
|
---|
112 | /** Holds the string meta data of <i>this</i> rich text block. */
|
---|
113 | QString m_strStringMeta;
|
---|
114 | /** Holds the children of <i>this</i> rich text block. */
|
---|
115 | QMap<int, UIRichTextString*> m_strings;
|
---|
116 |
|
---|
117 | /** Holds the anchor of <i>this</i> rich text block. */
|
---|
118 | QString m_strAnchor;
|
---|
119 | /** Holds the anchor to highlight in <i>this</i> rich text block and in it's children. */
|
---|
120 | QString m_strHoveredAnchor;
|
---|
121 |
|
---|
122 | /** Holds the <i>any</i> string pattern. */
|
---|
123 | static const QString s_strAny;
|
---|
124 | /** Holds the map of known patterns. */
|
---|
125 | static const QMap<Type, QString> s_patterns;
|
---|
126 | /** Holds the map of meta flags for the known patterns. */
|
---|
127 | static const QMap<Type, bool> s_doPatternHasMeta;
|
---|
128 | };
|
---|
129 |
|
---|
130 | #endif /* !FEQT_INCLUDED_SRC_objects_UIRichTextString_h */
|
---|