1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTEXTOPTION_H
5#define QTEXTOPTION_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qnamespace.h>
9#include <QtCore/qchar.h>
10#include <QtCore/qmetatype.h>
11
12
13QT_BEGIN_NAMESPACE
14
15struct QTextOptionPrivate;
16
17class Q_GUI_EXPORT QTextOption
18{
19public:
20 enum TabType {
21 LeftTab,
22 RightTab,
23 CenterTab,
24 DelimiterTab
25 };
26
27 struct Q_GUI_EXPORT Tab {
28 inline Tab() : position(80), type(QTextOption::LeftTab) { }
29 inline Tab(qreal pos, TabType tabType, QChar delim = QChar())
30 : position(pos), type(tabType), delimiter(delim) {}
31
32 inline bool operator==(const Tab &other) const {
33 return type == other.type
34 && qFuzzyCompare(p1: position, p2: other.position)
35 && delimiter == other.delimiter;
36 }
37
38 inline bool operator!=(const Tab &other) const {
39 return !operator==(other);
40 }
41
42 qreal position;
43 TabType type;
44 QChar delimiter;
45 };
46
47 QTextOption();
48 Q_IMPLICIT QTextOption(Qt::Alignment alignment);
49 ~QTextOption();
50
51 QTextOption(const QTextOption &o);
52 QTextOption &operator=(const QTextOption &o);
53
54 inline void setAlignment(Qt::Alignment alignment);
55 inline Qt::Alignment alignment() const { return Qt::Alignment(align); }
56
57 inline void setTextDirection(Qt::LayoutDirection aDirection) { this->direction = aDirection; }
58 inline Qt::LayoutDirection textDirection() const { return Qt::LayoutDirection(direction); }
59
60 enum WrapMode {
61 NoWrap,
62 WordWrap,
63 ManualWrap,
64 WrapAnywhere,
65 WrapAtWordBoundaryOrAnywhere
66 };
67 inline void setWrapMode(WrapMode wrap) { wordWrap = wrap; }
68 inline WrapMode wrapMode() const { return static_cast<WrapMode>(wordWrap); }
69
70 enum Flag {
71 ShowTabsAndSpaces = 0x1,
72 ShowLineAndParagraphSeparators = 0x2,
73 AddSpaceForLineAndParagraphSeparators = 0x4,
74 SuppressColors = 0x8,
75 ShowDocumentTerminator = 0x10,
76 IncludeTrailingSpaces = 0x80000000
77 };
78 Q_DECLARE_FLAGS(Flags, Flag)
79 inline void setFlags(Flags flags);
80 inline Flags flags() const { return Flags(f); }
81
82 inline void setTabStopDistance(qreal tabStopDistance);
83 inline qreal tabStopDistance() const { return tab; }
84
85 void setTabArray(const QList<qreal> &tabStops);
86 QList<qreal> tabArray() const;
87
88 void setTabs(const QList<Tab> &tabStops);
89 QList<Tab> tabs() const;
90
91 void setUseDesignMetrics(bool b) { design = b; }
92 bool useDesignMetrics() const { return design; }
93
94private:
95 uint align : 9;
96 uint wordWrap : 4;
97 uint design : 1;
98 uint direction : 2;
99 uint unused : 16;
100 uint f;
101 qreal tab;
102 QTextOptionPrivate *d;
103};
104
105Q_DECLARE_OPERATORS_FOR_FLAGS(QTextOption::Flags)
106
107inline void QTextOption::setAlignment(Qt::Alignment aalignment)
108{ align = uint(aalignment.toInt()); }
109
110inline void QTextOption::setFlags(Flags aflags)
111{ f = uint(aflags.toInt()); }
112
113inline void QTextOption::setTabStopDistance(qreal atabStop)
114{ tab = atabStop; }
115
116QT_END_NAMESPACE
117
118QT_DECL_METATYPE_EXTERN_TAGGED(QTextOption::Tab, QTextOption_Tab, Q_GUI_EXPORT)
119
120#endif // QTEXTOPTION_H
121

source code of qtbase/src/gui/text/qtextoption.h