VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/objects/UIRichTextString.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h70873
    /branches/VBox-4.1/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h74233
    /branches/VBox-4.2/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h91223
    /branches/VBox-4.3/trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h91223
    /branches/dsen/gui/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h79562-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h79645-79692
    /trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h79225,​79271
File size: 5.4 KB
Line 
1/* $Id: UIRichTextString.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIRichTextString class declaration.
4 */
5
6/*
7 * Copyright (C) 2015-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_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. */
42class SHARED_LIBRARY_STUFF UIRichTextString
43{
44public:
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
78private:
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 */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use