source: trunk/src/qt3support/text/q3richtext_p.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 16.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt3Support module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3richtext_p.h"
43
44#ifndef QT_NO_RICHTEXT
45
46QT_BEGIN_NAMESPACE
47
48Q3TextCommand::~Q3TextCommand() {}
49Q3TextCommand::Commands Q3TextCommand::type() const { return Invalid; }
50
51
52#ifndef QT_NO_TEXTCUSTOMITEM
53Q3TextCustomItem::~Q3TextCustomItem() {}
54void Q3TextCustomItem::adjustToPainter(QPainter* p){ if (p) width = 0; }
55Q3TextCustomItem::Placement Q3TextCustomItem::placement() const { return PlaceInline; }
56
57bool Q3TextCustomItem::ownLine() const { return false; }
58void Q3TextCustomItem::resize(int nwidth){ width = nwidth; }
59void Q3TextCustomItem::invalidate() {}
60
61bool Q3TextCustomItem::isNested() const { return false; }
62int Q3TextCustomItem::minimumWidth() const { return 0; }
63
64QString Q3TextCustomItem::richText() const { return QString(); }
65
66bool Q3TextCustomItem::enter(Q3TextCursor *, Q3TextDocument*&, Q3TextParagraph *&, int &, int &, int &, bool)
67{
68 return true;
69}
70bool Q3TextCustomItem::enterAt(Q3TextCursor *, Q3TextDocument *&, Q3TextParagraph *&, int &, int &, int &, const QPoint &)
71{
72 return true;
73}
74bool Q3TextCustomItem::next(Q3TextCursor *, Q3TextDocument *&, Q3TextParagraph *&, int &, int &, int &)
75{
76 return true;
77}
78bool Q3TextCustomItem::prev(Q3TextCursor *, Q3TextDocument *&, Q3TextParagraph *&, int &, int &, int &)
79{
80 return true;
81}
82bool Q3TextCustomItem::down(Q3TextCursor *, Q3TextDocument *&, Q3TextParagraph *&, int &, int &, int &)
83{
84 return true;
85}
86bool Q3TextCustomItem::up(Q3TextCursor *, Q3TextDocument *&, Q3TextParagraph *&, int &, int &, int &)
87{
88 return true;
89}
90#endif // QT_NO_TEXTCUSTOMITEM
91
92void Q3TextFlow::setPageSize(int ps) { pagesize = ps; }
93#ifndef QT_NO_TEXTCUSTOMITEM
94bool Q3TextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); }
95#else
96bool Q3TextFlow::isEmpty() { return true; }
97#endif
98
99#ifndef QT_NO_TEXTCUSTOMITEM
100void Q3TextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; }
101
102void Q3TextTable::invalidate() { cachewidth = -1; }
103#endif
104
105Q3TextParagraphData::~Q3TextParagraphData() {}
106void Q3TextParagraphData::join(Q3TextParagraphData *) {}
107
108Q3TextFormatter::~Q3TextFormatter() {}
109void Q3TextFormatter::setWrapEnabled(bool b) { wrapEnabled = b; }
110void Q3TextFormatter::setWrapAtColumn(int c) { wrapColumn = c; }
111
112
113
114int Q3TextCursor::x() const
115{
116 if (idx >= para->length())
117 return 0;
118 Q3TextStringChar *c = para->at(idx);
119 int curx = c->x;
120 if (!c->rightToLeft &&
121 c->c.isSpace() &&
122 idx > 0 &&
123 para->at(idx - 1)->c != QLatin1Char('\t') &&
124 !c->lineStart &&
125 (para->alignment() & Qt::AlignJustify) == Qt::AlignJustify)
126 curx = para->at(idx - 1)->x + para->string()->width(idx - 1);
127 if (c->rightToLeft)
128 curx += para->string()->width(idx);
129 return curx;
130}
131
132int Q3TextCursor::y() const
133{
134 int dummy, line;
135 para->lineStartOfChar(idx, &dummy, &line);
136 return para->lineY(line);
137}
138
139int Q3TextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); }
140int Q3TextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); }
141
142Q3TextDocument *Q3TextCursor::document() const
143{
144 return para ? para->document() : 0;
145}
146
147void Q3TextCursor::gotoPosition(Q3TextParagraph* p, int index)
148{
149 if (para && p != para) {
150 while (!indices.isEmpty() && para->document() != p->document())
151 pop();
152 Q_ASSERT(indices.isEmpty() || para->document() == p->document());
153 }
154 para = p;
155 if (index < 0 || index >= para->length()) {
156 qWarning("Q3TextCursor::gotoParagraph Index: %d out of range", index);
157 if (index < 0 || para->length() == 0)
158 index = 0;
159 else
160 index = para->length() - 1;
161 }
162
163 tmpX = -1;
164 idx = index;
165 fixCursorPosition();
166}
167
168bool Q3TextDocument::hasSelection(int id, bool visible) const
169{