source: trunk/src/gui/text/qtextformat.h@ 455

Last change on this file since 455 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 28.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QTEXTFORMAT_H
43#define QTEXTFORMAT_H
44
45#include <QtGui/qcolor.h>
46#include <QtGui/qfont.h>
47#include <QtCore/qshareddata.h>
48#include <QtCore/qvector.h>
49#include <QtCore/qvariant.h>
50#include <QtGui/qpen.h>
51#include <QtGui/qbrush.h>
52#include <QtGui/qtextoption.h>
53
54QT_BEGIN_HEADER
55
56QT_BEGIN_NAMESPACE
57
58QT_MODULE(Gui)
59
60class QString;
61class QVariant;
62class QFont;
63
64class QTextFormatCollection;
65class QTextFormatPrivate;
66class QTextBlockFormat;
67class QTextCharFormat;
68class QTextListFormat;
69class QTextTableFormat;
70class QTextFrameFormat;
71class QTextImageFormat;
72class QTextTableCellFormat;
73class QTextFormat;
74class QTextObject;
75class QTextCursor;
76class QTextDocument;
77class QTextLength;
78
79Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
80Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
81
82class Q_GUI_EXPORT QTextLength
83{
84public:
85 enum Type { VariableLength = 0, FixedLength, PercentageLength };
86
87 inline QTextLength() : lengthType(VariableLength), fixedValueOrPercentage(0) {}
88
89 inline explicit QTextLength(Type type, qreal value);
90
91 inline Type type() const { return lengthType; }
92 inline qreal value(qreal maximumLength) const
93 {
94 switch (lengthType) {
95 case FixedLength: return fixedValueOrPercentage;
96 case VariableLength: return maximumLength;
97 case PercentageLength: return fixedValueOrPercentage * maximumLength / qreal(100);
98 }
99 return -1;
100 }
101
102 inline qreal rawValue() const { return fixedValueOrPercentage; }
103
104 inline bool operator==(const QTextLength &other) const
105 { return lengthType == other.lengthType
106 && qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
107 inline bool operator!=(const QTextLength &other) const
108 { return lengthType != other.lengthType
109 || !qFuzzyCompare(fixedValueOrPercentage, other.fixedValueOrPercentage); }
110 operator QVariant() const;
111
112private:
113 Type lengthType;
114 qreal fixedValueOrPercentage;
115 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextLength &);
116 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextLength &);
117};
118
119inline QTextLength::QTextLength(Type atype, qreal avalue)
120 : lengthType(atype), fixedValueOrPercentage(avalue) {}
121
122Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTextFormat &);
123Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTextFormat &);
124
125class Q_GUI_EXPORT QTextFormat
126{
127 Q_GADGET
128 Q_ENUMS(FormatType Property ObjectTypes)
129public:
130 enum FormatType {
131 InvalidFormat = -1,
132 BlockFormat = 1,
133 CharFormat = 2,
134 ListFormat = 3,
135 TableFormat = 4,
136 FrameFormat = 5,
137
138 UserFormat = 100
139 };
140
141 enum Property {
142 ObjectIndex = 0x0,
143
144 // paragraph and char
145 CssFloat = 0x0800,
146 LayoutDirection = 0x0801,
147
148 OutlinePen = 0x810,
149 BackgroundBrush = 0x820,
150 ForegroundBrush = 0x821,
151 // Internal to qtextlayout.cpp: ObjectSelectionBrush = 0x822
152 BackgroundImageUrl = 0x823,
153
154 // paragraph
155 BlockAlignment = 0x1010,
156 BlockTopMargin = 0x1030,
157 BlockBottomMargin = 0x1031,
158 BlockLeftMargin = 0x1032,
159 BlockRightMargin = 0x1033,
160 TextIndent = 0x1034,
161 TabPositions = 0x1035,
162 BlockIndent = 0x1040,
163 BlockNonBreakableLines = 0x1050,
164 BlockTrailingHorizontalRulerWidth = 0x1060,
165
166 // character properties
167 FirstFontProperty = 0x1FE0,
168 FontCapitalization = FirstFontProperty,
169 FontLetterSpacing = 0x1FE1,
170 FontWordSpacing = 0x1FE2,
171 FontStyleHint = 0x1FE3,
172 FontStyleStrategy = 0x1FE4,
173 FontKerning = 0x1FE5,
174 FontFamily = 0x2000,
175 FontPointSize = 0x2001,
176 FontSizeAdjustment = 0x2002,
177 FontSizeIncrement = FontSizeAdjustment, // old name, compat
178 FontWeight = 0x2003,
179 FontItalic = 0x2004,