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 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | struct QTextOptionPrivate; |
52 | |
53 | class Q_GUI_EXPORT QTextOption |
54 | { |
55 | public: |
56 | enum TabType { |
57 | LeftTab, |
58 | RightTab, |
59 | CenterTab, |
60 | DelimiterTab |
61 | }; |
62 | |
63 | struct Q_GUI_EXPORT Tab { |
64 | inline Tab() : position(80), type(QTextOption::LeftTab) { } |
65 | inline Tab(qreal pos, TabType tabType, QChar delim = QChar()) |
66 | : position(pos), type(tabType), delimiter(delim) {} |
67 | |
68 | inline bool operator==(const Tab &other) const { |
69 | return type == other.type |
70 | && qFuzzyCompare(position, other.position) |
71 | && delimiter == other.delimiter; |
72 | } |
73 | |
74 | inline bool operator!=(const Tab &other) const { |
75 | return !operator==(other); |
76 | } |
77 | |
78 | qreal position; |
79 | TabType type; |
80 | QChar delimiter; |
81 | }; |
82 | |
83 | QTextOption(); |
84 | Q_IMPLICIT QTextOption(Qt::Alignment alignment); |
85 | ~QTextOption(); |
86 | |
87 | QTextOption(const QTextOption &o); |
88 | QTextOption &operator=(const QTextOption &o); |
89 | |
90 | inline void setAlignment(Qt::Alignment alignment); |
91 | inline Qt::Alignment alignment() const { return Qt::Alignment(align); } |
92 | |
93 | inline void setTextDirection(Qt::LayoutDirection aDirection) { this->direction = aDirection; } |
94 | inline Qt::LayoutDirection textDirection() const { return Qt::LayoutDirection(direction); } |
95 | |
96 | enum WrapMode { |
97 | NoWrap, |
98 | WordWrap, |
99 | ManualWrap, |
100 | WrapAnywhere, |
101 | WrapAtWordBoundaryOrAnywhere |
102 | }; |
103 | inline void setWrapMode(WrapMode wrap) { wordWrap = wrap; } |
104 | inline WrapMode wrapMode() const { return static_cast<WrapMode>(wordWrap); } |
105 | |
106 | enum Flag { |
107 | ShowTabsAndSpaces = 0x1, |
108 | ShowLineAndParagraphSeparators = 0x2, |
109 | AddSpaceForLineAndParagraphSeparators = 0x4, |
110 | SuppressColors = 0x8, |
111 | ShowDocumentTerminator = 0x10, |
112 | IncludeTrailingSpaces = 0x80000000 |
113 | }; |
114 | Q_DECLARE_FLAGS(Flags, Flag) |
115 | inline void setFlags(Flags flags); |
116 | inline Flags flags() const { return Flags(f); } |
117 | |
118 | inline void setTabStopDistance(qreal tabStopDistance); |
119 | inline qreal tabStopDistance() const { return tab; } |
120 | |
121 | void setTabArray(const QList<qreal> &tabStops); |
122 | QList<qreal> tabArray() const; |
123 | |
124 | void setTabs(const QList<Tab> &tabStops); |
125 | QList<Tab> tabs() const; |
126 | |
127 | void setUseDesignMetrics(bool b) { design = b; } |
128 | bool useDesignMetrics() const { return design; } |
129 | |
130 | private: |
131 | uint align : 9; |
132 | uint wordWrap : 4; |
133 | uint design : 1; |
134 | uint direction : 2; |
135 | uint unused : 16; |
136 | uint f; |
137 | qreal tab; |
138 | QTextOptionPrivate *d; |
139 | }; |
140 | |
141 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTextOption::Flags) |
142 | |
143 | inline void QTextOption::setAlignment(Qt::Alignment aalignment) |
144 | { align = aalignment; } |
145 | |
146 | inline void QTextOption::setFlags(Flags aflags) |
147 | { f = aflags; } |
148 | |
149 | inline void QTextOption::setTabStopDistance(qreal atabStop) |
150 | { tab = atabStop; } |
151 | |
152 | QT_END_NAMESPACE |
153 | |
154 | Q_DECLARE_METATYPE( QTextOption::Tab ) |
155 | |
156 | #endif // QTEXTOPTION_H |
157 | |