1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTEXTOPTION_H
41#define QTEXTOPTION_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qnamespace.h>
45#include <QtCore/qchar.h>
46#include <QtCore/qmetatype.h>
47
48
49QT_BEGIN_NAMESPACE
50
51
52template <typename T> class QList;
53struct QTextOptionPrivate;
54
55class Q_GUI_EXPORT QTextOption
56{
57public:
58 enum TabType {
59 LeftTab,
60 RightTab,
61 CenterTab,
62 DelimiterTab
63 };
64
65 struct Q_GUI_EXPORT Tab {
66 inline Tab() : position(80), type(QTextOption::LeftTab) { }
67 inline Tab(qreal pos, TabType tabType, QChar delim = QChar())
68 : position(pos), type(tabType), delimiter(delim) {}
69
70 inline bool operator==(const Tab &other) const {
71 return type == other.type
72 && qFuzzyCompare(p1: position, p2: other.position)
73 && delimiter == other.delimiter;
74 }
75
76 inline bool operator!=(const Tab &other) const {
77 return !operator==(other);
78 }
79
80 qreal position;
81 TabType type;
82 QChar delimiter;
83 };
84
85 QTextOption();
86 /*implicit*/ QTextOption(Qt::Alignment alignment);
87 ~QTextOption();
88
89 QTextOption(const QTextOption &o);
90 QTextOption &operator=(const QTextOption &o);
91
92 inline void setAlignment(Qt::Alignment alignment);
93 inline Qt::Alignment alignment() const { return Qt::Alignment(align); }
94
95 inline void setTextDirection(Qt::LayoutDirection aDirection) { this->direction = aDirection; }
96 inline Qt::LayoutDirection textDirection() const { return Qt::LayoutDirection(direction); }
97
98 enum WrapMode {
99 NoWrap,
100 WordWrap,
101 ManualWrap,
102 WrapAnywhere,
103 WrapAtWordBoundaryOrAnywhere
104 };
105 inline void setWrapMode(WrapMode wrap) { wordWrap = wrap; }
106 inline WrapMode wrapMode() const { return static_cast<WrapMode>(wordWrap); }
107
108 enum Flag {
109 ShowTabsAndSpaces = 0x1,
110 ShowLineAndParagraphSeparators = 0x2,
111 AddSpaceForLineAndParagraphSeparators = 0x4,
112 SuppressColors = 0x8,
113 ShowDocumentTerminator = 0x10,
114 IncludeTrailingSpaces = 0x80000000
115 };
116 Q_DECLARE_FLAGS(Flags, Flag)
117 inline void setFlags(Flags flags);
118 inline Flags flags() const { return Flags(f); }
119
120#if QT_DEPRECATED_SINCE(5, 10)
121 QT_DEPRECATED inline void setTabStop(qreal tabStop);
122 QT_DEPRECATED inline qreal tabStop() const { return tabStopDistance(); }
123#endif
124
125 inline void setTabStopDistance(qreal tabStopDistance);
126 inline qreal tabStopDistance() const { return tab; }
127
128 void setTabArray(const QList<qreal> &tabStops);
129 QList<qreal> tabArray() const;
130
131 void setTabs(const QList<Tab> &tabStops);
132 QList<Tab> tabs() const;
133
134 void setUseDesignMetrics(bool b) { design = b; }
135 bool useDesignMetrics() const { return design; }
136
137private:
138 uint align : 8;
139 uint wordWrap : 4;
140 uint design : 1;
141 uint direction : 2;
142 uint unused : 17;
143 uint unused2; // ### Qt 6: remove unnecessary, extra 32 bits
144 uint f;
145 qreal tab;
146 QTextOptionPrivate *d;
147};
148
149Q_DECLARE_OPERATORS_FOR_FLAGS(QTextOption::Flags)
150
151inline void QTextOption::setAlignment(Qt::Alignment aalignment)
152{ align = aalignment; }
153
154inline void QTextOption::setFlags(Flags aflags)
155{ f = aflags; }
156
157#if QT_DEPRECATED_SINCE(5, 10)
158inline void QTextOption::setTabStop(qreal atabStop)
159{ setTabStopDistance(atabStop); }
160#endif
161
162inline void QTextOption::setTabStopDistance(qreal atabStop)
163{ tab = atabStop; }
164
165QT_END_NAMESPACE
166
167Q_DECLARE_METATYPE( QTextOption::Tab )
168
169#endif // QTEXTOPTION_H
170

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