author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
||
46 |
#include <qtextdocument.h> |
|
47 |
#include <qdebug.h> |
|
48 |
||
49 |
#include <qtextcursor.h> |
|
50 |
#include <qtextdocumentfragment.h> |
|
51 |
#include <qtextformat.h> |
|
52 |
#include <qtextobject.h> |
|
53 |
#include <qtexttable.h> |
|
54 |
#include <qabstracttextdocumentlayout.h> |
|
55 |
#include <qtextlist.h> |
|
56 |
#include <qtextcodec.h> |
|
57 |
#include <qurl.h> |
|
58 |
#include <qpainter.h> |
|
59 |
#include <qfontmetrics.h> |
|
60 |
#include <qimage.h> |
|
61 |
#include <qtextlayout.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
#include <QDomDocument> |
0 | 63 |
#include "common.h" |
64 |
||
65 |
||
66 |
QT_FORWARD_DECLARE_CLASS(QTextDocument) |
|
67 |
||
68 |
//TESTED_CLASS= |
|
69 |
//TESTED_FILES= |
|
70 |
||
71 |
class tst_QTextDocument : public QObject |
|
72 |
{ |
|
73 |
Q_OBJECT |
|
74 |
||
75 |
public: |
|
76 |
tst_QTextDocument(); |
|
77 |
virtual ~tst_QTextDocument(); |
|
78 |
||
79 |
public slots: |
|
80 |
void init(); |
|
81 |
void cleanup(); |
|
82 |
private slots: |
|
83 |
void getSetCheck(); |
|
84 |
void isEmpty(); |
|
85 |
void find_data(); |
|
86 |
void find(); |
|
87 |
void find2(); |
|
88 |
void findWithRegExp_data(); |
|
89 |
void findWithRegExp(); |
|
90 |
void findMultiple(); |
|
91 |
void basicIsModifiedChecks(); |
|
92 |
void moreIsModified(); |
|
93 |
void isModified2(); |
|
94 |
void isModified3(); |
|
95 |
void isModified4(); |
|
96 |
void noundo_basicIsModifiedChecks(); |
|
97 |
void noundo_moreIsModified(); |
|
98 |
void noundo_isModified2(); |
|
99 |
void noundo_isModified3(); |
|
100 |
void mightBeRichText(); |
|
101 |
||
102 |
void task240325(); |
|
103 |
||
104 |
void stylesheetFont_data(); |
|
105 |
void stylesheetFont(); |
|
106 |
||
107 |
void toHtml_data(); |
|
108 |
void toHtml(); |
|
109 |
void toHtml2(); |
|
110 |
||
111 |
void setFragmentMarkersInHtmlExport(); |
|
112 |
||
113 |
void toHtmlBodyBgColor(); |
|
114 |
void toHtmlRootFrameProperties(); |
|
115 |
void capitalizationHtmlInExport(); |
|
116 |
void wordspacingHtmlExport(); |
|
117 |
||
118 |
void cursorPositionChanged(); |
|
119 |
void cursorPositionChangedOnSetText(); |
|
120 |
||
121 |
void textFrameIterator(); |
|
122 |
||
123 |
void codecForHtml(); |
|
124 |
||
125 |
void markContentsDirty(); |
|
126 |
||
127 |
void clonePreservesMetaInformation(); |
|
128 |
void clonePreservesPageSize(); |
|
129 |
void clonePreservesPageBreakPolicies(); |
|
130 |
void clonePreservesDefaultFont(); |
|
131 |
void clonePreservesRootFrameFormat(); |
|
132 |
void clonePreservesResources(); |
|
133 |
void clonePreservesUserStates(); |
|
134 |
void clonePreservesIndentWidth(); |
|
135 |
void blockCount(); |
|
136 |
void defaultStyleSheet(); |
|
137 |
||
138 |
void resolvedFontInEmptyFormat(); |
|
139 |
||
140 |
void defaultRootFrameMargin(); |
|
141 |
||
142 |
void clearResources(); |
|
143 |
||
144 |
void setPlainText(); |
|
145 |
void toPlainText(); |
|
146 |
||
147 |
void deleteTextObjectsOnClear(); |
|
148 |
||
149 |
void maximumBlockCount(); |
|
150 |
void adjustSize(); |
|
151 |
void initialUserData(); |
|
152 |
||
153 |
void html_defaultFont(); |
|
154 |
||
155 |
void blockCountChanged(); |
|
156 |
||
157 |
void nonZeroDocumentLengthOnClear(); |
|
158 |
||
159 |
void setTextPreservesUndoRedoEnabled(); |
|
160 |
||
161 |
void firstLast(); |
|
162 |
||
163 |
void backgroundImage_toHtml(); |
|
164 |
void backgroundImage_toHtml2(); |
|
165 |
void backgroundImage_clone(); |
|
166 |
void backgroundImage_copy(); |
|
167 |
||
168 |
void documentCleanup(); |
|
169 |
||
170 |
void characterAt(); |
|
171 |
void revisions(); |
|
172 |
void revisionWithUndoCompressionAndUndo(); |
|
173 |
||
174 |
void testUndoCommandAdded(); |
|
175 |
||
176 |
void testUndoBlocks(); |
|
177 |
||
178 |
void receiveCursorPositionChangedAfterContentsChange(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
void escape_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
void escape(); |
0 | 181 |
|
182 |
private: |
|
183 |
void backgroundImage_checkExpectedHtml(const QTextDocument &doc); |
|
184 |
||
185 |
QTextDocument *doc; |
|
186 |
QTextCursor cursor; |
|
187 |
QFont defaultFont; |
|
188 |
QString htmlHead; |
|
189 |
QString htmlTail; |
|
190 |
}; |
|
191 |
||
192 |
class MyAbstractTextDocumentLayout : public QAbstractTextDocumentLayout |
|
193 |
{ |
|
194 |
public: |
|
195 |
MyAbstractTextDocumentLayout(QTextDocument *doc) : QAbstractTextDocumentLayout(doc) {} |
|
196 |
void draw(QPainter *, const PaintContext &) {} |
|
197 |
int hitTest(const QPointF &, Qt::HitTestAccuracy) const { return 0; } |
|
198 |
int pageCount() const { return 0; } |
|
199 |
QSizeF documentSize() const { return QSizeF(); } |
|
200 |
QRectF frameBoundingRect(QTextFrame *) const { return QRectF(); } |
|
201 |
QRectF blockBoundingRect(const QTextBlock &) const { return QRectF(); } |
|
202 |
void documentChanged(int, int, int) {} |
|
203 |
}; |
|
204 |
||
205 |
// Testing get/set functions |
|
206 |
void tst_QTextDocument::getSetCheck() |
|
207 |
{ |
|
208 |
QTextDocument obj1; |
|
209 |
// QAbstractTextDocumentLayout * QTextDocument::documentLayout() |
|
210 |
// void QTextDocument::setDocumentLayout(QAbstractTextDocumentLayout *) |
|
211 |
QPointer<MyAbstractTextDocumentLayout> var1 = new MyAbstractTextDocumentLayout(0); |
|
212 |
obj1.setDocumentLayout(var1); |
|
213 |
QCOMPARE(static_cast<QAbstractTextDocumentLayout *>(var1), obj1.documentLayout()); |
|
214 |
obj1.setDocumentLayout((QAbstractTextDocumentLayout *)0); |
|
215 |
QVERIFY(var1.isNull()); |
|
216 |
QVERIFY(obj1.documentLayout()); |
|
217 |
||
218 |
// bool QTextDocument::useDesignMetrics() |
|
219 |
// void QTextDocument::setUseDesignMetrics(bool) |
|
220 |
obj1.setUseDesignMetrics(false); |
|
221 |
QCOMPARE(false, obj1.useDesignMetrics()); |
|
222 |
obj1.setUseDesignMetrics(true); |
|
223 |
QCOMPARE(true, obj1.useDesignMetrics()); |
|
224 |
} |
|
225 |
||
226 |
tst_QTextDocument::tst_QTextDocument() |
|
227 |
{ |
|
228 |
QImage img(16, 16, QImage::Format_ARGB32_Premultiplied); |
|
229 |
img.save("foo.png"); |
|
230 |
} |
|
231 |
||
232 |
tst_QTextDocument::~tst_QTextDocument() |
|
233 |
{ |
|
234 |
QFile::remove(QLatin1String("foo.png")); |
|
235 |
} |
|
236 |
||
237 |
void tst_QTextDocument::init() |
|
238 |
{ |
|
239 |
doc = new QTextDocument; |
|
240 |
cursor = QTextCursor(doc); |
|
241 |
defaultFont = QFont(); |
|
242 |
||
243 |
htmlHead = QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" " |
|
244 |
"\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" |
|
245 |
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" |
|
246 |
"p, li { white-space: pre-wrap; }\n" |
|
247 |
"</style></head>" |
|
248 |
"<body style=\" font-family:'%1'; font-size:%2pt; font-weight:%3; font-style:%4;\">\n"); |
|
249 |
htmlHead = htmlHead.arg(defaultFont.family()).arg(defaultFont.pointSizeF()).arg(defaultFont.weight() * 8).arg((defaultFont.italic() ? "italic" : "normal")); |
|
250 |
||
251 |
htmlTail = QString("</body></html>"); |
|
252 |
} |
|
253 |
||
254 |
void tst_QTextDocument::cleanup() |
|
255 |
{ |
|
256 |
cursor = QTextCursor(); |
|
257 |
delete doc; |
|
258 |
doc = 0; |
|
259 |
} |
|
260 |
||
261 |
void tst_QTextDocument::isEmpty() |
|
262 |
{ |
|
263 |
QVERIFY(doc->isEmpty()); |
|
264 |
} |
|
265 |
||
266 |
void tst_QTextDocument::find_data() |
|
267 |
{ |
|
268 |
QTest::addColumn<QString>("haystack"); |
|
269 |
QTest::addColumn<QString>("needle"); |
|
270 |
QTest::addColumn<int>("flags"); |
|
271 |
QTest::addColumn<int>("from"); |
|
272 |
QTest::addColumn<int>("anchor"); |
|
273 |
QTest::addColumn<int>("position"); |
|
274 |
||
275 |
QTest::newRow("1") << "Hello World" << "World" << int(QTextDocument::FindCaseSensitively) << 0 << 6 << 11; |
|
276 |
||
277 |
QTest::newRow("2") << QString::fromAscii("Hello") + QString(QChar::ParagraphSeparator) + QString::fromAscii("World") |
|
278 |
<< "World" << int(QTextDocument::FindCaseSensitively) << 1 << 6 << 11; |
|
279 |
||
280 |
QTest::newRow("3") << QString::fromAscii("Hello") + QString(QChar::ParagraphSeparator) + QString::fromAscii("World") |
|
281 |
<< "Hello" << int(QTextDocument::FindCaseSensitively | QTextDocument::FindBackward) << 10 << 0 << 5; |
|
282 |
QTest::newRow("4wholewords") << QString::fromAscii("Hello Blah World") |
|
283 |
<< "Blah" << int(QTextDocument::FindWholeWords) << 0 << 6 << 10; |
|
284 |
QTest::newRow("5wholewords") << QString::fromAscii("HelloBlahWorld") |
|
285 |
<< "Blah" << int(QTextDocument::FindWholeWords) << 0 << -1 << -1; |
|
286 |
QTest::newRow("6wholewords") << QString::fromAscii("HelloBlahWorld Blah Hah") |
|
287 |
<< "Blah" << int(QTextDocument::FindWholeWords) << 0 << 15 << 19; |
|
288 |
QTest::newRow("7wholewords") << QString::fromAscii("HelloBlahWorld Blah Hah") |
|
289 |
<< "Blah" << int(QTextDocument::FindWholeWords | QTextDocument::FindBackward) << 23 << 15 << 19; |
|
290 |
QTest::newRow("8wholewords") << QString::fromAscii("Hello: World\n") |
|
291 |
<< "orld" << int(QTextDocument::FindWholeWords) << 0 << -1 << -1; |
|
292 |
||
293 |
QTest::newRow("across-paragraphs") << QString::fromAscii("First Parag\nSecond Parag with a lot more text") |
|
294 |
<< "Parag" << int(QTextDocument::FindBackward) |
|
295 |
<< 15 << 6 << 11; |
|
296 |
||
297 |
QTest::newRow("nbsp") << "Hello" + QString(QChar(QChar::Nbsp)) +"World" << " " << int(QTextDocument::FindCaseSensitively) << 0 << 5 << 6; |
|
298 |
} |
|
299 |
||
300 |
void tst_QTextDocument::find() |
|
301 |
{ |
|
302 |
QFETCH(QString, haystack); |
|
303 |
QFETCH(QString, needle); |
|
304 |
QFETCH(int, flags); |
|
305 |
QFETCH(int, from); |
|
306 |
QFETCH(int, anchor); |
|
307 |
QFETCH(int, position); |
|
308 |
||
309 |
cursor.insertText(haystack); |
|
310 |
cursor = doc->find(needle, from, QTextDocument::FindFlags(flags)); |
|
311 |
||
312 |
if (anchor != -1) { |
|
313 |
QCOMPARE(cursor.anchor(), anchor); |
|
314 |
QCOMPARE(cursor.position(), position); |
|
315 |
} else { |
|
316 |
QVERIFY(cursor.isNull()); |
|
317 |
} |
|
318 |
||
319 |
//search using a regular expression |
|
320 |
QRegExp expr(needle); |
|
321 |
expr.setPatternSyntax(QRegExp::FixedString); |
|
322 |
QTextDocument::FindFlags flg(flags); |
|
323 |
expr.setCaseSensitivity((flg & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); |
|
324 |
cursor = doc->find(expr, from, flg); |
|
325 |
||
326 |
if (anchor != -1) { |
|
327 |
QCOMPARE(cursor.anchor(), anchor); |
|
328 |
QCOMPARE(cursor.position(), position); |
|
329 |
} else { |
|
330 |
QVERIFY(cursor.isNull()); |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
void tst_QTextDocument::findWithRegExp_data() |
|
335 |
{ |
|
336 |
QTest::addColumn<QString>("haystack"); |
|
337 |
QTest::addColumn<QString>("needle"); |
|
338 |
QTest::addColumn<int>("flags"); |
|
339 |
QTest::addColumn<int>("from"); |
|
340 |
QTest::addColumn<int>("anchor"); |
|
341 |
QTest::addColumn<int>("position"); |
|
342 |
||
343 |
// match integers 0 to 99 |
|
344 |
QTest::newRow("1") << "23" << "^\\d\\d?$" << int(QTextDocument::FindCaseSensitively) << 0 << 0 << 2; |
|
345 |
// match ampersands but not & |
|
346 |
QTest::newRow("2") << "His & hers & theirs" << "&(?!amp;)"<< int(QTextDocument::FindCaseSensitively) << 0 << 15 << 16; |
|
347 |
//backward search |
|
348 |
QTest::newRow("3") << QString::fromAscii("HelloBlahWorld Blah Hah") |
|
349 |
<< "h" << int(QTextDocument::FindBackward) << 18 << 8 << 9; |
|
350 |
||
351 |
} |
|
352 |
||
353 |
void tst_QTextDocument::findWithRegExp() |
|
354 |
{ |
|
355 |
QFETCH(QString, haystack); |
|
356 |
QFETCH(QString, needle); |
|
357 |
QFETCH(int, flags); |
|
358 |
QFETCH(int, from); |
|
359 |
QFETCH(int, anchor); |
|
360 |
QFETCH(int, position); |
|
361 |
||
362 |
cursor.insertText(haystack); |
|
363 |
//search using a regular expression |
|
364 |
QRegExp expr(needle); |
|
365 |
QTextDocument::FindFlags flg(flags); |
|
366 |
expr.setCaseSensitivity((flg & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); |
|
367 |
cursor = doc->find(expr, from, flg); |
|
368 |
||
369 |
if (anchor != -1) { |
|
370 |
QCOMPARE(cursor.anchor(), anchor); |
|
371 |
QCOMPARE(cursor.position(), position); |
|
372 |
} else { |
|
373 |
QVERIFY(cursor.isNull()); |
|
374 |
} |
|
375 |
} |
|
376 |
||
377 |
void tst_QTextDocument::find2() |
|
378 |
{ |
|
379 |
doc->setPlainText("aaa"); |
|
380 |
cursor.movePosition(QTextCursor::Start); |
|
381 |
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); |
|
382 |
QTextCursor hit = doc->find("a", cursor); |
|
383 |
QCOMPARE(hit.position(), 2); |
|
384 |
QCOMPARE(hit.anchor(), 1); |
|
385 |
} |
|
386 |
||
387 |
void tst_QTextDocument::findMultiple() |
|
388 |
{ |
|
389 |
const QString text("foo bar baz foo bar baz"); |
|
390 |
doc->setPlainText(text); |
|
391 |
||
392 |
cursor.movePosition(QTextCursor::Start); |
|
393 |
cursor = doc->find("bar", cursor); |
|
394 |
QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); |
|
395 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
396 |
cursor = doc->find("bar", cursor); |
|
397 |
QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar")); |
|
398 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
399 |
||
400 |
cursor.movePosition(QTextCursor::End); |
|
401 |
cursor = doc->find("bar", cursor, QTextDocument::FindBackward); |
|
402 |
QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar")); |
|
403 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
404 |
cursor = doc->find("bar", cursor, QTextDocument::FindBackward); |
|
405 |
QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); |
|
406 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
407 |
||
408 |
||
409 |
QRegExp expr("bar"); |
|
410 |
expr.setPatternSyntax(QRegExp::FixedString); |
|
411 |
||
412 |
cursor.movePosition(QTextCursor::End); |
|
413 |
cursor = doc->find(expr, cursor, QTextDocument::FindBackward); |
|
414 |
QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar")); |
|
415 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
416 |
cursor = doc->find(expr, cursor, QTextDocument::FindBackward); |
|
417 |
QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); |
|
418 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
419 |
||
420 |
cursor.movePosition(QTextCursor::Start); |
|
421 |
cursor = doc->find(expr, cursor); |
|
422 |
QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); |
|
423 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
424 |
cursor = doc->find(expr, cursor); |
|
425 |
QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar")); |
|
426 |
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); |
|
427 |
} |
|
428 |
||
429 |
void tst_QTextDocument::basicIsModifiedChecks() |
|
430 |
{ |
|
431 |
QSignalSpy spy(doc, SIGNAL(modificationChanged(bool))); |
|
432 |
||
433 |
QVERIFY(!doc->isModified()); |
|
434 |
cursor.insertText("Hello World"); |
|
435 |
QVERIFY(doc->isModified()); |
|
436 |
QCOMPARE(spy.count(), 1); |
|
437 |
QVERIFY(spy.takeFirst().at(0).toBool()); |
|
438 |
||
439 |
doc->undo(); |
|
440 |
QVERIFY(!doc->isModified()); |
|
441 |
QCOMPARE(spy.count(), 1); |
|
442 |
QVERIFY(!spy.takeFirst().at(0).toBool()); |
|
443 |
||
444 |
doc->redo(); |
|
445 |
QVERIFY(doc->isModified()); |
|
446 |
QCOMPARE(spy.count(), 1); |
|
447 |
QVERIFY(spy.takeFirst().at(0).toBool()); |
|
448 |
} |
|
449 |
||
450 |
void tst_QTextDocument::moreIsModified() |
|
451 |
{ |
|
452 |
QVERIFY(!doc->isModified()); |
|
453 |
||
454 |
cursor.insertText("Hello"); |
|
455 |
QVERIFY(doc->isModified()); |
|
456 |
||
457 |
doc->undo(); |
|
458 |
QVERIFY(!doc->isModified()); |
|
459 |
||
460 |
cursor.insertText("Hello"); |
|
461 |
||
462 |
doc->undo(); |
|
463 |
QVERIFY(!doc->isModified()); |
|
464 |
} |
|
465 |
||
466 |
void tst_QTextDocument::isModified2() |
|
467 |
{ |
|
468 |
// reported on qt4-preview-feedback |
|
469 |
QVERIFY(!doc->isModified()); |
|
470 |
||
471 |
cursor.insertText("Hello"); |
|
472 |
QVERIFY(doc->isModified()); |
|
473 |
||
474 |
doc->setModified(false); |
|
475 |
QVERIFY(!doc->isModified()); |
|
476 |
||
477 |
cursor.insertText("Hello"); |
|
478 |
QVERIFY(doc->isModified()); |
|
479 |
} |
|
480 |
||
481 |
void tst_QTextDocument::isModified3() |
|
482 |
{ |
|
483 |
QVERIFY(!doc->isModified()); |
|
484 |
||
485 |
doc->setUndoRedoEnabled(false); |
|
486 |
doc->setUndoRedoEnabled(true); |
|
487 |
||
488 |
cursor.insertText("Hello"); |
|
489 |
||
490 |
QVERIFY(doc->isModified()); |
|
491 |
doc->undo(); |
|
492 |
QVERIFY(!doc->isModified()); |
|
493 |
} |
|
494 |
||
495 |
void tst_QTextDocument::isModified4() |
|
496 |
{ |
|
497 |
QVERIFY(!doc->isModified()); |
|
498 |
||
499 |
cursor.insertText("Hello"); |
|
500 |
cursor.insertText("World"); |
|
501 |
||
502 |
doc->setModified(false); |
|
503 |
||
504 |
QVERIFY(!doc->isModified()); |
|
505 |
||
506 |
cursor.insertText("Again"); |
|
507 |
QVERIFY(doc->isModified()); |
|
508 |
||
509 |
doc->undo(); |
|
510 |
QVERIFY(!doc->isModified()); |
|
511 |
doc->undo(); |
|
512 |
QVERIFY(doc->isModified()); |
|
513 |
||
514 |
doc->redo(); |
|
515 |
QVERIFY(!doc->isModified()); |
|
516 |
doc->redo(); |
|
517 |
QVERIFY(doc->isModified()); |
|
518 |
||
519 |
doc->undo(); |
|
520 |
QVERIFY(!doc->isModified()); |
|
521 |
doc->undo(); |
|
522 |
QVERIFY(doc->isModified()); |
|
523 |
||
524 |
//task 197769 |
|
525 |
cursor.insertText("Hello"); |
|
526 |
QVERIFY(doc->isModified()); |
|
527 |
} |
|
528 |
||
529 |
void tst_QTextDocument::noundo_basicIsModifiedChecks() |
|
530 |
{ |
|
531 |
doc->setUndoRedoEnabled(false); |
|
532 |
QSignalSpy spy(doc, SIGNAL(modificationChanged(bool))); |
|
533 |
||
534 |
QVERIFY(!doc->isModified()); |
|
535 |
cursor.insertText("Hello World"); |
|
536 |
QVERIFY(doc->isModified()); |
|
537 |
QCOMPARE(spy.count(), 1); |
|
538 |
QVERIFY(spy.takeFirst().at(0).toBool()); |
|
539 |
||
540 |
doc->undo(); |
|
541 |
QVERIFY(doc->isModified()); |
|
542 |
QCOMPARE(spy.count(), 0); |
|
543 |
||
544 |
doc->redo(); |
|
545 |
QVERIFY(doc->isModified()); |
|
546 |
QCOMPARE(spy.count(), 0); |
|
547 |
} |
|
548 |
||
549 |
void tst_QTextDocument::task240325() |
|
550 |
{ |
|
551 |
doc->setHtml("<html><img width=\"100\" height=\"100\" align=\"right\"/>Foobar Foobar Foobar Foobar</html>"); |
|
552 |
||
553 |
QImage img(1000, 7000, QImage::Format_ARGB32_Premultiplied); |
|
554 |
QPainter p(&img); |
|
555 |
QFontMetrics fm(p.font()); |
|
556 |
||
557 |
// Set page size to contain image and one "Foobar" |
|
558 |
doc->setPageSize(QSize(100 + fm.width("Foobar")*2, 1000)); |
|
559 |
||
560 |
// Force layout |
|
561 |
doc->drawContents(&p); |
|
562 |
||
563 |
QCOMPARE(doc->blockCount(), 1); |
|
564 |
for (QTextBlock block = doc->begin() ; block!=doc->end() ; block = block.next()) { |
|
565 |
QTextLayout *layout = block.layout(); |
|
566 |
QCOMPARE(layout->lineCount(), 4); |
|
567 |
for (int lineIdx=0;lineIdx<layout->lineCount();++lineIdx) { |
|
568 |
QTextLine line = layout->lineAt(lineIdx); |
|
569 |
||
570 |
QString text = block.text().mid(line.textStart(), line.textLength()).trimmed(); |
|
571 |
||
572 |
// Remove start token |
|
573 |
if (lineIdx == 0) |
|
574 |
text = text.mid(1); |
|
575 |
||
576 |
QCOMPARE(text, QString::fromLatin1("Foobar")); |
|
577 |
} |
|
578 |
} |
|
579 |
} |
|
580 |
||
581 |
void tst_QTextDocument::stylesheetFont_data() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
582 |
{ |
0 | 583 |
QTest::addColumn<QString>("stylesheet"); |
584 |
QTest::addColumn<QFont>("font"); |
|
585 |
||
586 |
{ |
|
587 |
QFont font; |
|
588 |
font.setBold(true); |
|
589 |
font.setPixelSize(64); |
|
590 |
||
591 |
QTest::newRow("Regular font specification") |
|
592 |
<< "font-size: 64px; font-weight: bold;" |
|
593 |
<< font; |
|
594 |
} |
|
595 |
||
596 |
||
597 |
{ |
|
598 |
QFont font; |
|
599 |
font.setBold(true); |
|
600 |
font.setPixelSize(64); |
|
601 |
||
602 |
QTest::newRow("Shorthand font specification") |
|
603 |
<< "font: normal bold 64px Arial;" |
|
604 |
<< font; |
|
605 |
} |
|
606 |
||
607 |
} |
|
608 |
||
609 |
void tst_QTextDocument::stylesheetFont() |
|
610 |
{ |
|
611 |
QFETCH(QString, stylesheet); |
|
612 |
QFETCH(QFont, font); |
|
613 |
||
614 |
QString html = QString::fromLatin1("<html>" |
|
615 |
"<body>" |
|
616 |
"<div style=\"%1\" >" |
|
617 |
"Foobar" |
|
618 |
"</div>" |
|
619 |
"</body>" |
|
620 |
"</html>").arg(stylesheet); |
|
621 |
||
622 |
qDebug() << html; |
|
623 |
doc->setHtml(html); |
|
624 |
QCOMPARE(doc->blockCount(), 1); |
|
625 |
||
626 |
// First and only block |
|
627 |
QTextBlock block = doc->firstBlock(); |
|
628 |
||
629 |
QString text = block.text(); |
|
630 |
QCOMPARE(text, QString::fromLatin1("Foobar")); |
|
631 |
||
632 |
QFont actualFont = block.charFormat().font(); |
|
633 |
||
634 |
QCOMPARE(actualFont.bold(), font.bold()); |
|
635 |
QCOMPARE(actualFont.pixelSize(), font.pixelSize()); |
|
636 |
} |
|
637 |
||
638 |
void tst_QTextDocument::noundo_moreIsModified() |
|
639 |
{ |
|
640 |
doc->setUndoRedoEnabled(false); |
|
641 |
QVERIFY(!doc->isModified()); |
|
642 |
||
643 |
cursor.insertText("Hello"); |
|
644 |
QVERIFY(doc->isModified()); |
|
645 |
||
646 |
doc->undo(); |
|
647 |
QVERIFY(doc->isModified()); |
|
648 |
||
649 |
cursor.insertText("Hello"); |
|
650 |
||
651 |
doc->undo(); |
|
652 |
QVERIFY(doc->isModified()); |
|
653 |
} |
|
654 |
||
655 |
void tst_QTextDocument::noundo_isModified2() |
|
656 |
{ |
|
657 |
// reported on qt4-preview-feedback |
|
658 |
QVERIFY(!doc->isModified()); |
|
659 |
||
660 |
cursor.insertText("Hello"); |
|
661 |
QVERIFY(doc->isModified()); |
|
662 |
||
663 |
doc->setModified(false); |
|
664 |
QVERIFY(!doc->isModified()); |
|
665 |
||
666 |
cursor.insertText("Hello"); |
|
667 |
QVERIFY(doc->isModified()); |
|
668 |
} |
|
669 |
||
670 |
void tst_QTextDocument::noundo_isModified3() |
|
671 |
{ |
|
672 |
doc->setUndoRedoEnabled(false); |
|
673 |
QVERIFY(!doc->isModified()); |
|
674 |
||
675 |
cursor.insertText("Hello"); |
|
676 |
||
677 |
QVERIFY(doc->isModified()); |
|
678 |
doc->undo(); |
|
679 |
QVERIFY(doc->isModified()); |
|
680 |
} |
|
681 |
||
682 |
void tst_QTextDocument::mightBeRichText() |
|
683 |
{ |
|
684 |
const char qtDocuHeader[] = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" |
|
685 |
"<!DOCTYPE html\n" |
|
686 |
" PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n" |
|
687 |
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"; |
|
688 |
QVERIFY(Qt::mightBeRichText(QString::fromLatin1(qtDocuHeader))); |
|
689 |
} |
|
690 |
||
691 |
Q_DECLARE_METATYPE(QTextDocumentFragment) |
|
692 |
||
693 |
#define CREATE_DOC_AND_CURSOR() \ |
|
694 |
QTextDocument doc; \ |
|
695 |
doc.setDefaultFont(defaultFont); \ |
|
696 |
QTextCursor cursor(&doc); |
|
697 |
||
698 |
void tst_QTextDocument::toHtml_data() |
|
699 |
{ |
|
700 |
QTest::addColumn<QTextDocumentFragment>("input"); |
|
701 |
QTest::addColumn<QString>("expectedOutput"); |
|
702 |
||
703 |
{ |
|
704 |
CREATE_DOC_AND_CURSOR(); |
|
705 |
||
706 |
cursor.insertText("Blah"); |
|
707 |
||
708 |
QTest::newRow("simple") << QTextDocumentFragment(&doc) << QString("<p DEFAULTBLOCKSTYLE>Blah</p>"); |
|
709 |
} |
|
710 |
||
711 |
{ |
|
712 |
CREATE_DOC_AND_CURSOR(); |
|
713 |
||
714 |
cursor.insertText("&<>"); |
|
715 |
||
716 |
QTest::newRow("entities") << QTextDocumentFragment(&doc) << QString("<p DEFAULTBLOCKSTYLE>&<></p>"); |
|
717 |
} |
|
718 |
||
719 |
{ |
|
720 |
CREATE_DOC_AND_CURSOR(); |
|
721 |
||
722 |
QTextCharFormat fmt; |
|
723 |
fmt.setFontFamily("Times"); |
|
724 |
cursor.insertText("Blah", fmt); |
|
725 |
||
726 |
QTest::newRow("font-family") << QTextDocumentFragment(&doc) |
|
727 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Times';\">Blah</span></p>"); |
|
728 |
} |
|
729 |
||
730 |
{ |
|
731 |
CREATE_DOC_AND_CURSOR(); |
|
732 |
||
733 |
QTextCharFormat fmt; |
|
734 |
fmt.setFontFamily("Foo's Family"); |
|
735 |
cursor.insertText("Blah", fmt); |
|
736 |
||
737 |
QTest::newRow("font-family-with-quotes1") << QTextDocumentFragment(&doc) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:"Foo's Family";\">Blah</span></p>"); |
0 | 739 |
} |
740 |
||
741 |
{ |
|
742 |
CREATE_DOC_AND_CURSOR(); |
|
743 |
||
744 |
QTextCharFormat fmt; |
|
745 |
fmt.setFontFamily("Foo\"s Family"); |
|
746 |
cursor.insertText("Blah", fmt); |
|
747 |
||
748 |
QTest::newRow("font-family-with-quotes2") << QTextDocumentFragment(&doc) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
749 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Foo"s Family';\">Blah</span></p>"); |
0 | 750 |
} |
751 |
||
752 |
{ |
|
753 |
CREATE_DOC_AND_CURSOR(); |
|
754 |
||
755 |
QTextBlockFormat fmt; |
|
756 |
fmt.setNonBreakableLines(true); |
|
757 |
cursor.insertBlock(fmt); |
|
758 |
cursor.insertText("Blah"); |
|
759 |
||
760 |
QTest::newRow("pre") << QTextDocumentFragment(&doc) |
|
761 |
<< |
|
762 |
QString("EMPTYBLOCK") + |
|
763 |
QString("<pre DEFAULTBLOCKSTYLE>Blah</pre>"); |
|
764 |
} |
|
765 |
||
766 |
{ |
|
767 |
CREATE_DOC_AND_CURSOR(); |
|
768 |
||
769 |
QTextCharFormat fmt; |
|
770 |
fmt.setFontPointSize(40); |
|
771 |
cursor.insertText("Blah", fmt); |
|
772 |
||
773 |
QTest::newRow("font-size") << QTextDocumentFragment(&doc) |
|
774 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-size:40pt;\">Blah</span></p>"); |
|
775 |
} |
|
776 |
||
777 |
{ |
|
778 |
CREATE_DOC_AND_CURSOR(); |
|
779 |
||
780 |
QTextCharFormat fmt; |
|
781 |
fmt.setProperty(QTextFormat::FontSizeIncrement, 2); |
|
782 |
cursor.insertText("Blah", fmt); |
|
783 |
||
784 |
QTest::newRow("logical-font-size") << QTextDocumentFragment(&doc) |
|
785 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-size:x-large;\">Blah</span></p>"); |
|
786 |
} |
|
787 |
||
788 |
{ |
|
789 |
CREATE_DOC_AND_CURSOR(); |
|
790 |
||
791 |
cursor.insertText("Foo"); |
|
792 |
||
793 |
QTextCharFormat fmt; |
|
794 |
fmt.setFontPointSize(40); |
|
795 |
cursor.insertBlock(QTextBlockFormat(), fmt); |
|
796 |
||
797 |
fmt.clearProperty(QTextFormat::FontPointSize); |
|
798 |
cursor.insertText("Blub", fmt); |
|
799 |
||
800 |
QTest::newRow("no-font-size") << QTextDocumentFragment(&doc) |
|
801 |
<< QString("<p DEFAULTBLOCKSTYLE>Foo</p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blub</p>"); |
|
802 |
} |
|
803 |
||
804 |
{ |
|
805 |
CREATE_DOC_AND_CURSOR(); |
|
806 |
||
807 |
QTextBlockFormat fmt; |
|
808 |
fmt.setLayoutDirection(Qt::RightToLeft); |
|
809 |
cursor.insertBlock(fmt); |
|
810 |
cursor.insertText("Blah"); |
|
811 |
||
812 |
QTest::newRow("rtl") << QTextDocumentFragment(&doc) |
|
813 |
<< |
|
814 |
QString("EMPTYBLOCK") + |
|
815 |
QString("<p dir='rtl' DEFAULTBLOCKSTYLE>Blah</p>"); |
|
816 |
} |
|
817 |
||
818 |
{ |
|
819 |
CREATE_DOC_AND_CURSOR(); |
|
820 |
||
821 |
QTextBlockFormat fmt; |
|
822 |
fmt.setAlignment(Qt::AlignJustify); |
|
823 |
cursor.insertBlock(fmt); |
|
824 |
cursor.insertText("Blah"); |
|
825 |
||
826 |
QTest::newRow("blockalign") << QTextDocumentFragment(&doc) |
|
827 |
<< |
|
828 |
QString("EMPTYBLOCK") + |
|
829 |
QString("<p align=\"justify\" DEFAULTBLOCKSTYLE>Blah</p>"); |
|
830 |
} |
|
831 |
||
832 |
{ |
|
833 |
CREATE_DOC_AND_CURSOR(); |
|
834 |
||
835 |
QTextBlockFormat fmt; |
|
836 |
fmt.setAlignment(Qt::AlignCenter); |
|
837 |
cursor.insertBlock(fmt); |
|
838 |
cursor.insertText("Blah"); |
|
839 |
||
840 |
QTest::newRow("blockalign2") << QTextDocumentFragment(&doc) |
|
841 |
<< |
|
842 |
QString("EMPTYBLOCK") + |
|
843 |
QString("<p align=\"center\" DEFAULTBLOCKSTYLE>Blah</p>"); |
|
844 |
} |
|
845 |
||
846 |
{ |
|
847 |
CREATE_DOC_AND_CURSOR(); |
|
848 |
||
849 |
QTextBlockFormat fmt; |
|
850 |
fmt.setAlignment(Qt::AlignRight | Qt::AlignAbsolute); |
|
851 |
cursor.insertBlock(fmt); |
|
852 |
cursor.insertText("Blah"); |
|
853 |
||
854 |
QTest::newRow("blockalign3") << QTextDocumentFragment(&doc) |
|
855 |
<< |
|
856 |
QString("EMPTYBLOCK") + |
|
857 |
QString("<p align=\"right\" DEFAULTBLOCKSTYLE>Blah</p>"); |
|
858 |
} |
|
859 |
||
860 |
{ |
|
861 |
CREATE_DOC_AND_CURSOR(); |
|
862 |
||
863 |
QTextBlockFormat fmt; |
|
864 |
fmt.setBackground(QColor("#0000ff")); |
|
865 |
cursor.insertBlock(fmt); |
|
866 |
cursor.insertText("Blah"); |
|
867 |
||
868 |
QTest::newRow("bgcolor") << QTextDocumentFragment(&doc) |
|
869 |
<< QString("EMPTYBLOCK") + |
|
870 |
QString("<p OPENDEFAULTBLOCKSTYLE background-color:#0000ff;\">Blah</p>"); |
|
871 |
} |
|
872 |
||
873 |
{ |
|
874 |
CREATE_DOC_AND_CURSOR(); |
|
875 |
||
876 |
QTextCharFormat fmt; |
|
877 |
fmt.setFontWeight(40); |
|
878 |
cursor.insertText("Blah", fmt); |
|
879 |
||
880 |
QTest::newRow("font-weight") << QTextDocumentFragment(&doc) |
|
881 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-weight:320;\">Blah</span></p>"); |
|
882 |
} |
|
883 |
||
884 |
{ |
|
885 |
CREATE_DOC_AND_CURSOR(); |
|
886 |
||
887 |
QTextCharFormat fmt; |
|
888 |
fmt.setFontItalic(true); |
|
889 |
cursor.insertText("Blah", fmt); |
|
890 |
||
891 |
QTest::newRow("font-italic") << QTextDocumentFragment(&doc) |
|
892 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" font-style:italic;\">Blah</span></p>"); |
|
893 |
} |
|
894 |
||
895 |
{ |
|
896 |
CREATE_DOC_AND_CURSOR(); |
|
897 |
||
898 |
QTextCharFormat fmt; |
|
899 |
fmt.setFontUnderline(true); |
|
900 |
fmt.setFontOverline(false); |
|
901 |
cursor.insertText("Blah", fmt); |
|
902 |
||
903 |
QTest::newRow("text-decoration-1") << QTextDocumentFragment(&doc) |
|
904 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" text-decoration: underline;\">Blah</span></p>"); |
|
905 |
} |
|
906 |
||
907 |
{ |
|
908 |
CREATE_DOC_AND_CURSOR(); |
|
909 |
||
910 |
QTextCharFormat fmt; |
|
911 |
fmt.setForeground(QColor("#00ff00")); |
|
912 |
cursor.insertText("Blah", fmt); |
|
913 |
||
914 |
QTest::newRow("color") << QTextDocumentFragment(&doc) |
|
915 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" color:#00ff00;\">Blah</span></p>"); |
|
916 |
} |
|
917 |
||
918 |
{ |
|
919 |
CREATE_DOC_AND_CURSOR(); |
|
920 |
||
921 |
QTextCharFormat fmt; |
|
922 |
fmt.setBackground(QColor("#00ff00")); |
|
923 |
cursor.insertText("Blah", fmt); |
|
924 |
||
925 |
QTest::newRow("span-bgcolor") << QTextDocumentFragment(&doc) |
|
926 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" background-color:#00ff00;\">Blah</span></p>"); |
|
927 |
} |
|
928 |
||
929 |
{ |
|
930 |
CREATE_DOC_AND_CURSOR(); |
|
931 |
||
932 |
QTextCharFormat fmt; |
|
933 |
fmt.setVerticalAlignment(QTextCharFormat::AlignSubScript); |
|
934 |
cursor.insertText("Blah", fmt); |
|
935 |
||
936 |
QTest::newRow("valign-sub") << QTextDocumentFragment(&doc) |
|
937 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" vertical-align:sub;\">Blah</span></p>"); |
|
938 |
||
939 |
} |
|
940 |
||
941 |
{ |
|
942 |
CREATE_DOC_AND_CURSOR(); |
|
943 |
||
944 |
QTextCharFormat fmt; |
|
945 |
fmt.setVerticalAlignment(QTextCharFormat::AlignSuperScript); |
|
946 |
cursor.insertText("Blah", fmt); |
|
947 |
||
948 |
QTest::newRow("valign-super") << QTextDocumentFragment(&doc) |
|
949 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" vertical-align:super;\">Blah</span></p>"); |
|
950 |
||
951 |
} |
|
952 |
||
953 |
{ |
|
954 |
CREATE_DOC_AND_CURSOR(); |
|
955 |
||
956 |
QTextCharFormat fmt; |
|
957 |
fmt.setAnchor(true); |
|
958 |
fmt.setAnchorName("blub"); |
|
959 |
cursor.insertText("Blah", fmt); |
|
960 |
||
961 |
QTest::newRow("named anchor") << QTextDocumentFragment(&doc) |
|
962 |
<< QString("<p DEFAULTBLOCKSTYLE><a name=\"blub\"></a>Blah</p>"); |
|
963 |
} |
|
964 |
||
965 |
{ |
|
966 |
CREATE_DOC_AND_CURSOR(); |
|
967 |
||
968 |
QTextCharFormat fmt; |
|
969 |
fmt.setAnchor(true); |
|
970 |
fmt.setAnchorHref("http://www.kde.org/"); |
|
971 |
cursor.insertText("Blah", fmt); |
|
972 |
||
973 |
QTest::newRow("href anchor") << QTextDocumentFragment(&doc) |
|
974 |
<< QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/\">Blah</a></p>"); |
|
975 |
} |
|
976 |
||
977 |
{ |
|
978 |
CREATE_DOC_AND_CURSOR(); |
|
979 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
980 |
QTextCharFormat fmt; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
fmt.setAnchor(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
982 |
fmt.setAnchorHref("http://www.kde.org/?a=1&b=2"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
cursor.insertText("Blah", fmt); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
984 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
QTest::newRow("href anchor with &") << QTextDocumentFragment(&doc) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
986 |
<< QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/?a=1&b=2\">Blah</a></p>"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
987 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
988 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
989 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
990 |
CREATE_DOC_AND_CURSOR(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
991 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
992 |
QTextCharFormat fmt; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
993 |
fmt.setAnchor(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
994 |
fmt.setAnchorHref("http://www.kde.org/?a='&b=\""); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
995 |
cursor.insertText("Blah", fmt); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
996 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
997 |
QTest::newRow("href anchor with ' and \"") << QTextDocumentFragment(&doc) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
998 |
<< QString("<p DEFAULTBLOCKSTYLE><a href=\"http://www.kde.org/?a='&b="\">Blah</a></p>"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
999 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1000 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1001 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1002 |
CREATE_DOC_AND_CURSOR(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1003 |
|
0 | 1004 |
cursor.insertTable(2, 2); |
1005 |
||
1006 |
QTest::newRow("simpletable") << QTextDocumentFragment(&doc) |
|
1007 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1008 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1009 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1010 |
"</table>"); |
|
1011 |
} |
|
1012 |
||
1013 |
{ |
|
1014 |
CREATE_DOC_AND_CURSOR(); |
|
1015 |
||
1016 |
QTextTable *table = cursor.insertTable(1, 4); |
|
1017 |
table->mergeCells(0, 0, 1, 2); |
|
1018 |
table->mergeCells(0, 2, 1, 2); |
|
1019 |
||
1020 |
QTest::newRow("tablespans") << QTextDocumentFragment(&doc) |
|
1021 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1022 |
"\n<tr>\n<td colspan=\"2\"></td>\n<td colspan=\"2\"></td></tr>" |
|
1023 |
"</table>"); |
|
1024 |
} |
|
1025 |
||
1026 |
{ |
|
1027 |
CREATE_DOC_AND_CURSOR(); |
|
1028 |
||
1029 |
QTextTableFormat fmt; |
|
1030 |
fmt.setBorder(1); |
|
1031 |
fmt.setCellSpacing(3); |
|
1032 |
fmt.setCellPadding(3); |
|
1033 |
fmt.setBackground(QColor("#ff00ff")); |
|
1034 |
fmt.setWidth(QTextLength(QTextLength::PercentageLength, 50)); |
|
1035 |
fmt.setAlignment(Qt::AlignHCenter); |
|
1036 |
fmt.setPosition(QTextFrameFormat::FloatRight); |
|
1037 |
cursor.insertTable(2, 2, fmt); |
|
1038 |
||
1039 |
QTest::newRow("tableattrs") << QTextDocumentFragment(&doc) |
|
1040 |
<< QString("<table border=\"1\" style=\" float: right;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">" |
|
1041 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1042 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1043 |
"</table>"); |
|
1044 |
} |
|
1045 |
||
1046 |
{ |
|
1047 |
CREATE_DOC_AND_CURSOR(); |
|
1048 |
||
1049 |
QTextTableFormat fmt; |
|
1050 |
fmt.setBorder(1); |
|
1051 |
fmt.setCellSpacing(3); |
|
1052 |
fmt.setCellPadding(3); |
|
1053 |
fmt.setBackground(QColor("#ff00ff")); |
|
1054 |
fmt.setWidth(QTextLength(QTextLength::PercentageLength, 50)); |
|
1055 |
fmt.setAlignment(Qt::AlignHCenter); |
|
1056 |
fmt.setPosition(QTextFrameFormat::FloatRight); |
|
1057 |
fmt.setLeftMargin(25); |
|
1058 |
fmt.setBottomMargin(35); |
|
1059 |
cursor.insertTable(2, 2, fmt); |
|
1060 |
||
1061 |
QTest::newRow("tableattrs2") << QTextDocumentFragment(&doc) |
|
1062 |
<< QString("<table border=\"1\" style=\" float: right; margin-top:0px; margin-bottom:35px; margin-left:25px; margin-right:0px;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">" |
|
1063 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1064 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1065 |
"</table>"); |
|
1066 |
} |
|
1067 |
||
1068 |
{ |
|
1069 |
CREATE_DOC_AND_CURSOR(); |
|
1070 |
||
1071 |
QTextTableFormat fmt; |
|
1072 |
fmt.setHeaderRowCount(2); |
|
1073 |
cursor.insertTable(4, 2, fmt); |
|
1074 |
||
1075 |
QTest::newRow("tableheader") << QTextDocumentFragment(&doc) |
|
1076 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1077 |
"<thead>\n<tr>\n<td></td>\n<td></td></tr>" |
|
1078 |
"\n<tr>\n<td></td>\n<td></td></tr></thead>" |
|
1079 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1080 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1081 |
"</table>"); |
|
1082 |
} |
|
1083 |
||
1084 |
{ |
|
1085 |
CREATE_DOC_AND_CURSOR(); |
|
1086 |
||
1087 |
QTextTable *table = cursor.insertTable(2, 2); |
|
1088 |
QTextTable *subTable = table->cellAt(0, 1).firstCursorPosition().insertTable(1, 1); |
|
1089 |
subTable->cellAt(0, 0).firstCursorPosition().insertText("Hey"); |
|
1090 |
||
1091 |
QTest::newRow("nestedtable") << QTextDocumentFragment(&doc) |
|
1092 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1093 |
"\n<tr>\n<td></td>\n<td>\n<table border=\"1\" cellspacing=\"2\">\n<tr>\n<td>\n<p DEFAULTBLOCKSTYLE>Hey</p></td></tr></table></td></tr>" |
|
1094 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1095 |
"</table>"); |
|
1096 |
} |
|
1097 |
||
1098 |
{ |
|
1099 |
CREATE_DOC_AND_CURSOR(); |
|
1100 |
||
1101 |
QTextTableFormat fmt; |
|
1102 |
QVector<QTextLength> widths; |
|
1103 |
widths.append(QTextLength()); |
|
1104 |
widths.append(QTextLength(QTextLength::PercentageLength, 30)); |
|
1105 |
widths.append(QTextLength(QTextLength::FixedLength, 40)); |
|
1106 |
fmt.setColumnWidthConstraints(widths); |
|
1107 |
cursor.insertTable(1, 3, fmt); |
|
1108 |
||
1109 |
QTest::newRow("colwidths") << QTextDocumentFragment(&doc) |
|
1110 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1111 |
"\n<tr>\n<td></td>\n<td width=\"30%\"></td>\n<td width=\"40\"></td></tr>" |
|
1112 |
"</table>"); |
|
1113 |
} |
|
1114 |
||
1115 |
// ### rowspan/colspan tests, once texttable api for that is back again |
|
1116 |
// |
|
1117 |
{ |
|
1118 |
CREATE_DOC_AND_CURSOR(); |
|
1119 |
||
1120 |
QTextTable *table = cursor.insertTable(1, 1); |
|
1121 |
QTextCursor cellCurs = table->cellAt(0, 0).firstCursorPosition(); |
|
1122 |
QTextCharFormat fmt; |
|
1123 |
fmt.setBackground(QColor("#ffffff")); |
|
1124 |
cellCurs.mergeBlockCharFormat(fmt); |
|
1125 |
||
1126 |
QTest::newRow("cellproperties") << QTextDocumentFragment(&doc) |
|
1127 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1128 |
"\n<tr>\n<td bgcolor=\"#ffffff\"></td></tr>" |
|
1129 |
"</table>"); |
|
1130 |
} |
|
1131 |
||
1132 |
{ |
|
1133 |
CREATE_DOC_AND_CURSOR(); |
|
1134 |
||
1135 |
// ### fixme: use programmatic api as soon as we can create floats through it |
|
1136 |
const char html[] = "<html><body>Blah<img src=\"image.png\" width=\"10\" height=\"20\" style=\"float: right;\" />Blubb</body></html>"; |
|
1137 |
||
1138 |
QTest::newRow("image") << QTextDocumentFragment::fromHtml(QString::fromLatin1(html)) |
|
1139 |
<< QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah<img src=\"image.png\" width=\"10\" height=\"20\" style=\"float: right;\" />Blubb</p>"); |
|
1140 |
} |
|
1141 |
||
1142 |
{ |
|
1143 |
CREATE_DOC_AND_CURSOR(); |
|
1144 |
||
1145 |
QTextImageFormat fmt; |
|
1146 |
fmt.setName("foo"); |
|
1147 |
fmt.setVerticalAlignment(QTextCharFormat::AlignMiddle); |
|
1148 |
cursor.insertImage(fmt); |
|
1149 |
||
1150 |
QTest::newRow("image-malign") << QTextDocumentFragment(&doc) |
|
1151 |
<< QString("<p DEFAULTBLOCKSTYLE><img src=\"foo\" style=\"vertical-align: middle;\" /></p>"); |
|
1152 |
} |
|
1153 |
||
1154 |
{ |
|
1155 |
CREATE_DOC_AND_CURSOR(); |
|
1156 |
||
1157 |
QTextImageFormat fmt; |
|
1158 |
fmt.setName("foo"); |
|
1159 |
fmt.setVerticalAlignment(QTextCharFormat::AlignTop); |
|
1160 |
cursor.insertImage(fmt); |
|
1161 |
||
1162 |
QTest::newRow("image-malign") << QTextDocumentFragment(&doc) |
|
1163 |
<< QString("<p DEFAULTBLOCKSTYLE><img src=\"foo\" style=\"vertical-align: top;\" /></p>"); |
|
1164 |
} |
|
1165 |
||
1166 |
{ |
|
1167 |
CREATE_DOC_AND_CURSOR(); |
|
1168 |
||
1169 |
QTextImageFormat fmt; |
|
1170 |
fmt.setName("foo"); |
|
1171 |
cursor.insertImage(fmt); |
|
1172 |
cursor.insertImage(fmt); |
|
1173 |
||
1174 |
QTest::newRow("2images") << QTextDocumentFragment(&doc) |
|
1175 |
<< QString("<p DEFAULTBLOCKSTYLE><img src=\"foo\" /><img src=\"foo\" /></p>"); |
|
1176 |
} |
|
1177 |
||
1178 |
{ |
|
1179 |
CREATE_DOC_AND_CURSOR(); |
|
1180 |
||
1181 |
QString txt = QLatin1String("Blah"); |
|
1182 |
txt += QChar::LineSeparator; |
|
1183 |
txt += QLatin1String("Bar"); |
|
1184 |
cursor.insertText(txt); |
|
1185 |
||
1186 |
QTest::newRow("linebreaks") << QTextDocumentFragment(&doc) |
|
1187 |
<< QString("<p DEFAULTBLOCKSTYLE>Blah<br />Bar</p>"); |
|
1188 |
} |
|
1189 |
||
1190 |
{ |
|
1191 |
CREATE_DOC_AND_CURSOR(); |
|
1192 |
||
1193 |
QTextBlockFormat fmt; |
|
1194 |
fmt.setTopMargin(10); |
|
1195 |
fmt.setBottomMargin(20); |
|
1196 |
fmt.setLeftMargin(30); |
|
1197 |
fmt.setRightMargin(40); |
|
1198 |
cursor.insertBlock(fmt); |
|
1199 |
cursor.insertText("Blah"); |
|
1200 |
||
1201 |
QTest::newRow("blockmargins") << QTextDocumentFragment(&doc) |
|
1202 |
<< |
|
1203 |
QString("EMPTYBLOCK") + |
|
1204 |
QString("<p style=\" margin-top:10px; margin-bottom:20px; margin-left:30px; margin-right:40px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"); |
|
1205 |
} |
|
1206 |
||
1207 |
{ |
|
1208 |
CREATE_DOC_AND_CURSOR(); |
|
1209 |
||
1210 |
QTextList *list = cursor.insertList(QTextListFormat::ListDisc); |
|
1211 |
cursor.insertText("Blubb"); |
|
1212 |
cursor.insertBlock(); |
|
1213 |
cursor.insertText("Blah"); |
|
1214 |
QCOMPARE(list->count(), 2); |
|
1215 |
||
1216 |
QTest::newRow("lists") << QTextDocumentFragment(&doc) |
|
1217 |
<< |
|
1218 |
QString("EMPTYBLOCK") + |
|
1219 |
QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blubb</li>\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>"); |
|
1220 |
} |
|
1221 |
||
1222 |
{ |
|
1223 |
CREATE_DOC_AND_CURSOR(); |
|
1224 |
||
1225 |
QTextList *list = cursor.insertList(QTextListFormat::ListDisc); |
|
1226 |
cursor.insertText("Blubb"); |
|
1227 |
||
1228 |
cursor.insertBlock(); |
|
1229 |
||
1230 |
QTextCharFormat blockCharFmt; |
|
1231 |
blockCharFmt.setForeground(QColor("#0000ff")); |
|
1232 |
cursor.mergeBlockCharFormat(blockCharFmt); |
|
1233 |
||
1234 |
QTextCharFormat fmt; |
|
1235 |
fmt.setForeground(QColor("#ff0000")); |
|
1236 |
cursor.insertText("Blah", fmt); |
|
1237 |
QCOMPARE(list->count(), 2); |
|
1238 |
||
1239 |
QTest::newRow("charfmt-for-list-item") << QTextDocumentFragment(&doc) |
|
1240 |
<< |
|
1241 |
QString("EMPTYBLOCK") + |
|
1242 |
QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blubb</li>\n<li style=\" color:#0000ff;\" DEFAULTBLOCKSTYLE><span style=\" color:#ff0000;\">Blah</span></li></ul>"); |
|
1243 |
} |
|
1244 |
||
1245 |
{ |
|
1246 |
CREATE_DOC_AND_CURSOR(); |
|
1247 |
||
1248 |
QTextBlockFormat fmt; |
|
1249 |
fmt.setIndent(3); |
|
1250 |
fmt.setTextIndent(30); |
|
1251 |
cursor.insertBlock(fmt); |
|
1252 |
cursor.insertText("Test"); |
|
1253 |
||
1254 |
QTest::newRow("block-indent") << QTextDocumentFragment(&doc) |
|
1255 |
<< |
|
1256 |
QString("EMPTYBLOCK") + |
|
1257 |
QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:3; text-indent:30px;\">Test</p>"); |
|
1258 |
} |
|
1259 |
||
1260 |
{ |
|
1261 |
CREATE_DOC_AND_CURSOR(); |
|
1262 |
||
1263 |
QTextListFormat fmt; |
|
1264 |
fmt.setStyle(QTextListFormat::ListDisc); |
|
1265 |
fmt.setIndent(4); |
|
1266 |
cursor.insertList(fmt); |
|
1267 |
cursor.insertText("Blah"); |
|
1268 |
||
1269 |
QTest::newRow("list-indent") << QTextDocumentFragment(&doc) |
|
1270 |
<< |
|
1271 |
QString("EMPTYBLOCK") + |
|
1272 |
QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 4;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>"); |
|
1273 |
} |
|
1274 |
||
1275 |
{ |
|
1276 |
CREATE_DOC_AND_CURSOR(); |
|
1277 |
||
1278 |
cursor.insertBlock(); |
|
1279 |
||
1280 |
||
1281 |
QTest::newRow("emptyblock") << QTextDocumentFragment(&doc) |
|
1282 |
// after insertBlock() we /do/ have two blocks in the document, so also expect |
|
1283 |
// these in the html output |
|
1284 |
<< QString("EMPTYBLOCK") + QString("EMPTYBLOCK"); |
|
1285 |
} |
|
1286 |
||
1287 |
{ |
|
1288 |
CREATE_DOC_AND_CURSOR(); |
|
1289 |
||
1290 |
// if you press enter twice in an empty textedit and then insert 'Test' |
|
1291 |
// you actually get three visible paragraphs, two empty leading ones and |
|
1292 |
// a third with the actual text. the corresponding html representation |
|
1293 |
// therefore should also contain three paragraphs. |
|
1294 |
||
1295 |
cursor.insertBlock(); |
|
1296 |
QTextCharFormat fmt; |
|
1297 |
fmt.setForeground(QColor("#00ff00")); |
|
1298 |
fmt.setProperty(QTextFormat::FontSizeIncrement, 1); |
|
1299 |
cursor.mergeBlockCharFormat(fmt); |
|
1300 |
||
1301 |
fmt.setProperty(QTextFormat::FontSizeIncrement, 2); |
|
1302 |
cursor.insertText("Test", fmt); |
|
1303 |
||
1304 |
QTest::newRow("blockcharfmt") << QTextDocumentFragment(&doc) |
|
1305 |
<< QString("EMPTYBLOCK<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:x-large; color:#00ff00;\">Test</span></p>"); |
|
1306 |
} |
|
1307 |
||
1308 |
{ |
|
1309 |
CREATE_DOC_AND_CURSOR(); |
|
1310 |
||
1311 |
QTextCharFormat fmt; |
|
1312 |
fmt.setForeground(QColor("#00ff00")); |
|
1313 |
cursor.setBlockCharFormat(fmt); |
|
1314 |
fmt.setForeground(QColor("#0000ff")); |
|
1315 |
cursor.insertText("Test", fmt); |
|
1316 |
||
1317 |
QTest::newRow("blockcharfmt2") << QTextDocumentFragment(&doc) |
|
1318 |
<< QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" color:#0000ff;\">Test</span></p>"); |
|
1319 |
} |
|
1320 |
||
1321 |
{ |
|
1322 |
QTest::newRow("horizontal-ruler") << QTextDocumentFragment::fromHtml("<hr />") |
|
1323 |
<< |
|
1324 |
QString("EMPTYBLOCK") + |
|
1325 |
QString("<hr />"); |
|
1326 |
} |
|
1327 |
{ |
|
1328 |
QTest::newRow("horizontal-ruler-with-width") << QTextDocumentFragment::fromHtml("<hr width=\"50%\"/>") |
|
1329 |
<< |
|
1330 |
QString("EMPTYBLOCK") + |
|
1331 |
QString("<hr width=\"50%\"/>"); |
|
1332 |
} |
|
1333 |
{ |
|
1334 |
CREATE_DOC_AND_CURSOR(); |
|
1335 |
||
1336 |
QTextFrame *mainFrame = cursor.currentFrame(); |
|
1337 |
||
1338 |
QTextFrameFormat ffmt; |
|
1339 |
ffmt.setBorder(1); |
|
1340 |
ffmt.setPosition(QTextFrameFormat::FloatRight); |
|
1341 |
ffmt.setMargin(2); |
|
1342 |
ffmt.setWidth(100); |
|
1343 |
ffmt.setHeight(50); |
|
1344 |
ffmt.setBackground(QColor("#00ff00")); |
|
1345 |
cursor.insertFrame(ffmt); |
|
1346 |
cursor.insertText("Hello World"); |
|
1347 |
cursor = mainFrame->lastCursorPosition(); |
|
1348 |
||
1349 |
QTest::newRow("frame") << QTextDocumentFragment(&doc) |
|
1350 |
<< QString("<table border=\"1\" style=\"-qt-table-type: frame; float: right; margin-top:2px; margin-bottom:2px; margin-left:2px; margin-right:2px;\" width=\"100\" height=\"50\" bgcolor=\"#00ff00\">\n<tr>\n<td style=\"border: none;\">\n<p DEFAULTBLOCKSTYLE>Hello World</p></td></tr></table>"); |
|
1351 |
} |
|
1352 |
||
1353 |
{ |
|
1354 |
CREATE_DOC_AND_CURSOR(); |
|
1355 |
||
1356 |
QTextCharFormat fmt; |
|
1357 |
fmt.setForeground(QColor("#00ff00")); |
|
1358 |
// fmt.setBackground(QColor("#0000ff")); |
|
1359 |
cursor.setBlockCharFormat(fmt); |
|
1360 |
||
1361 |
fmt.setForeground(QBrush()); |
|
1362 |
// fmt.setBackground(QBrush()); |
|
1363 |
cursor.insertText("Test", fmt); |
|
1364 |
||
1365 |
// QTest::newRow("nostylebrush") << QTextDocumentFragment(&doc) << QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; color:#00ff00; -qt-blockcharfmt-background-color:#0000ff;\">Test</p>"); |
|
1366 |
QTest::newRow("nostylebrush") << QTextDocumentFragment(&doc) << QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Test</p>"); |
|
1367 |
} |
|
1368 |
||
1369 |
{ |
|
1370 |
CREATE_DOC_AND_CURSOR(); |
|
1371 |
||
1372 |
QTextTable *table = cursor.insertTable(2, 2); |
|
1373 |
table->mergeCells(0, 0, 1, 2); |
|
1374 |
QTextTableFormat fmt = table->format(); |
|
1375 |
QVector<QTextLength> widths; |
|
1376 |
widths.append(QTextLength(QTextLength::FixedLength, 20)); |
|
1377 |
widths.append(QTextLength(QTextLength::FixedLength, 40)); |
|
1378 |
fmt.setColumnWidthConstraints(widths); |
|
1379 |
table->setFormat(fmt); |
|
1380 |
||
1381 |
QTest::newRow("mergedtablecolwidths") << QTextDocumentFragment(&doc) |
|
1382 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1383 |
"\n<tr>\n<td colspan=\"2\"></td></tr>" |
|
1384 |
"\n<tr>\n<td width=\"20\"></td>\n<td width=\"40\"></td></tr>" |
|
1385 |
"</table>"); |
|
1386 |
} |
|
1387 |
||
1388 |
{ |
|
1389 |
CREATE_DOC_AND_CURSOR(); |
|
1390 |
||
1391 |
QTextCharFormat fmt; |
|
1392 |
||
1393 |
cursor.insertText("Blah\nGreen yellow green"); |
|
1394 |
cursor.setPosition(0); |
|
1395 |
cursor.setPosition(23, QTextCursor::KeepAnchor); |
|
1396 |
fmt.setBackground(Qt::green); |
|
1397 |
cursor.mergeCharFormat(fmt); |
|
1398 |
cursor.clearSelection(); |
|
1399 |
cursor.setPosition(11); |
|
1400 |
cursor.setPosition(17, QTextCursor::KeepAnchor); |
|
1401 |
fmt.setBackground(Qt::yellow); |
|
1402 |
cursor.mergeCharFormat(fmt); |
|
1403 |
cursor.clearSelection(); |
|
1404 |
||
1405 |
QTest::newRow("multiparagraph-bgcolor") << QTextDocumentFragment(&doc) |
|
1406 |
<< QString("<p DEFAULTBLOCKSTYLE><span style=\" background-color:#00ff00;\">Blah</span></p>\n" |
|
1407 |
"<p DEFAULTBLOCKSTYLE><span style=\" background-color:#00ff00;\">Green </span>" |
|
1408 |
"<span style=\" background-color:#ffff00;\">yellow</span>" |
|
1409 |
"<span style=\" background-color:#00ff00;\"> green</span></p>"); |
|
1410 |
} |
|
1411 |
||
1412 |
{ |
|
1413 |
CREATE_DOC_AND_CURSOR(); |
|
1414 |
||
1415 |
QTextBlockFormat fmt; |
|
1416 |
fmt.setBackground(QColor("#0000ff")); |
|
1417 |
cursor.insertBlock(fmt); |
|
1418 |
||
1419 |
QTextCharFormat charfmt; |
|
1420 |
charfmt.setBackground(QColor("#0000ff")); |
|
1421 |
cursor.insertText("Blah", charfmt); |
|
1422 |
||
1423 |
QTest::newRow("nospan-bgcolor") << QTextDocumentFragment(&doc) |
|
1424 |
<< QString("EMPTYBLOCK") + |
|
1425 |
QString("<p OPENDEFAULTBLOCKSTYLE background-color:#0000ff;\"><span style=\" background-color:#0000ff;\">Blah</span></p>"); |
|
1426 |
} |
|
1427 |
||
1428 |
{ |
|
1429 |
CREATE_DOC_AND_CURSOR(); |
|
1430 |
||
1431 |
QTextTable *table = cursor.insertTable(2, 2); |
|
1432 |
QTextCharFormat fmt = table->cellAt(0, 0).format(); |
|
1433 |
fmt.setVerticalAlignment(QTextCharFormat::AlignMiddle); |
|
1434 |
table->cellAt(0, 0).setFormat(fmt); |
|
1435 |
fmt = table->cellAt(0, 1).format(); |
|
1436 |
fmt.setVerticalAlignment(QTextCharFormat::AlignTop); |
|
1437 |
table->cellAt(0, 1).setFormat(fmt); |
|
1438 |
fmt = table->cellAt(1, 0).format(); |
|
1439 |
fmt.setVerticalAlignment(QTextCharFormat::AlignBottom); |
|
1440 |
table->cellAt(1, 0).setFormat(fmt); |
|
1441 |
||
1442 |
table->cellAt(0, 0).firstCursorPosition().insertText("Blah"); |
|
1443 |
||
1444 |
QTest::newRow("table-vertical-alignment") << QTextDocumentFragment(&doc) |
|
1445 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1446 |
"\n<tr>\n<td style=\" vertical-align:middle;\">\n" |
|
1447 |
"<p DEFAULTBLOCKSTYLE>Blah</p></td>" |
|
1448 |
"\n<td style=\" vertical-align:top;\"></td></tr>" |
|
1449 |
"\n<tr>\n<td style=\" vertical-align:bottom;\"></td>" |
|
1450 |
"\n<td></td></tr>" |
|
1451 |
"</table>"); |
|
1452 |
} |
|
1453 |
||
1454 |
{ |
|
1455 |
CREATE_DOC_AND_CURSOR(); |
|
1456 |
||
1457 |
QTextTable *table = cursor.insertTable(2, 2); |
|
1458 |
QTextTableCellFormat fmt = table->cellAt(0, 0).format().toTableCellFormat(); |
|
1459 |
fmt.setLeftPadding(1); |
|
1460 |
table->cellAt(0, 0).setFormat(fmt); |
|
1461 |
fmt = table->cellAt(0, 1).format().toTableCellFormat(); |
|
1462 |
fmt.setRightPadding(1); |
|
1463 |
table->cellAt(0, 1).setFormat(fmt); |
|
1464 |
fmt = table->cellAt(1, 0).format().toTableCellFormat(); |
|
1465 |
fmt.setTopPadding(1); |
|
1466 |
table->cellAt(1, 0).setFormat(fmt); |
|
1467 |
fmt = table->cellAt(1, 1).format().toTableCellFormat(); |
|
1468 |
fmt.setBottomPadding(1); |
|
1469 |
table->cellAt(1, 1).setFormat(fmt); |
|
1470 |
||
1471 |
table->cellAt(0, 0).firstCursorPosition().insertText("Blah"); |
|
1472 |
||
1473 |
QTest::newRow("table-cell-paddings") << QTextDocumentFragment(&doc) |
|
1474 |
<< QString("<table border=\"1\" cellspacing=\"2\">" |
|
1475 |
"\n<tr>\n<td style=\" padding-left:1;\">\n" |
|
1476 |
"<p DEFAULTBLOCKSTYLE>Blah</p></td>" |
|
1477 |
"\n<td style=\" padding-right:1;\"></td></tr>" |
|
1478 |
"\n<tr>\n<td style=\" padding-top:1;\"></td>" |
|
1479 |
"\n<td style=\" padding-bottom:1;\"></td></tr>" |
|
1480 |
"</table>"); |
|
1481 |
} |
|
1482 |
||
1483 |
{ |
|
1484 |
CREATE_DOC_AND_CURSOR(); |
|
1485 |
||
1486 |
QTextTableFormat fmt; |
|
1487 |
fmt.setBorderBrush(QColor("#0000ff")); |
|
1488 |
fmt.setBorderStyle(QTextFrameFormat::BorderStyle_Solid); |
|
1489 |
cursor.insertTable(2, 2, fmt); |
|
1490 |
||
1491 |
QTest::newRow("tableborder") << QTextDocumentFragment(&doc) |
|
1492 |
<< QString("<table border=\"1\" style=\" border-color:#0000ff; border-style:solid;\" cellspacing=\"2\">" |
|
1493 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1494 |
"\n<tr>\n<td></td>\n<td></td></tr>" |
|
1495 |
"</table>"); |
|
1496 |
} |
|
1497 |
||
1498 |
{ |
|
1499 |
CREATE_DOC_AND_CURSOR(); |
|
1500 |
||
1501 |
cursor.insertBlock(); |
|
1502 |
cursor.insertText("Foo"); |
|
1503 |
||
1504 |
cursor.block().setUserState(42); |
|
1505 |
||
1506 |
QTest::newRow("userstate") << QTextDocumentFragment(&doc) |
|
1507 |
<< QString("EMPTYBLOCK") + |
|
1508 |
QString("<p OPENDEFAULTBLOCKSTYLE -qt-user-state:42;\">Foo</p>"); |
|
1509 |
} |
|
1510 |
||
1511 |
{ |
|
1512 |
CREATE_DOC_AND_CURSOR(); |
|
1513 |
||
1514 |
QTextBlockFormat blockFmt; |
|
1515 |
blockFmt.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
|
1516 |
||
1517 |
cursor.insertBlock(blockFmt); |
|
1518 |
cursor.insertText("Foo"); |
|
1519 |
||
1520 |
blockFmt.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore | QTextFormat::PageBreak_AlwaysAfter); |
|
1521 |
||
1522 |
cursor.insertBlock(blockFmt); |
|
1523 |
cursor.insertText("Bar"); |
|
1524 |
||
1525 |
QTextTableFormat tableFmt; |
|
1526 |
tableFmt.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter); |
|
1527 |
||
1528 |
cursor.insertTable(1, 1, tableFmt); |
|
1529 |
||
1530 |
QTest::newRow("pagebreak") << QTextDocumentFragment(&doc) |
|
1531 |
<< QString("EMPTYBLOCK") + |
|
1532 |
QString("<p OPENDEFAULTBLOCKSTYLE page-break-before:always;\">Foo</p>" |
|
1533 |
"\n<p OPENDEFAULTBLOCKSTYLE page-break-before:always; page-break-after:always;\">Bar</p>" |
|
1534 |
"\n<table border=\"1\" style=\" page-break-after:always;\" cellspacing=\"2\">\n<tr>\n<td></td></tr></table>"); |
|
1535 |
} |
|
1536 |
||
1537 |
{ |
|
1538 |
CREATE_DOC_AND_CURSOR(); |
|
1539 |
||
1540 |
QTextListFormat listFmt; |
|
1541 |
listFmt.setStyle(QTextListFormat::ListDisc); |
|
1542 |
||
1543 |
cursor.insertList(listFmt); |
|
1544 |
cursor.insertText("Blah"); |
|
1545 |
||
1546 |
QTest::newRow("list-ul-margin") << QTextDocumentFragment(&doc) |
|
1547 |
<< QString("EMPTYBLOCK") + |
|
1548 |
QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>"); |
|
1549 |
} |
|
1550 |
} |
|
1551 |
||
1552 |
void tst_QTextDocument::toHtml() |
|
1553 |
{ |
|
1554 |
QFETCH(QTextDocumentFragment, input); |
|
1555 |
QFETCH(QString, expectedOutput); |
|
1556 |
||
1557 |
cursor.insertFragment(input); |
|
1558 |
||
1559 |
expectedOutput.prepend(htmlHead); |
|
1560 |
||
1561 |
expectedOutput.replace("OPENDEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"); |
|
1562 |
expectedOutput.replace("DEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\""); |
|
1563 |
expectedOutput.replace("EMPTYBLOCK", "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\n"); |
|
1564 |
if (expectedOutput.endsWith(QLatin1Char('\n'))) |
|
1565 |
expectedOutput.chop(1); |
|
1566 |
expectedOutput.append(htmlTail); |
|
1567 |
||
1568 |
QString output = doc->toHtml(); |
|
1569 |
||
1570 |
QCOMPARE(output, expectedOutput); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1571 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1572 |
QDomDocument document; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1573 |
QVERIFY2(document.setContent(output), "Output was not valid XML"); |
0 | 1574 |
} |
1575 |
||
1576 |
void tst_QTextDocument::toHtml2() |
|
1577 |
{ |
|
1578 |
QTextDocument doc; |
|
1579 |
doc.setHtml("<p>text <img src=\"\"> text</p>"); // 4 spaces before the second 'text' |
|
1580 |
QTextBlock block = doc.firstBlock(); |
|
1581 |
QTextBlock::Iterator iter = block.begin(); |
|
1582 |
QTextFragment f = iter.fragment(); |
|
1583 |
QVERIFY(f.isValid()); |
|
1584 |
QCOMPARE(f.position(), 0); |
|
1585 |
QCOMPARE(f.length(), 5); |
|
1586 |
//qDebug() << block.text().mid(f.position(), f.length()); |
|
1587 |
||
1588 |
iter++; |
|
1589 |
f = iter.fragment(); |
|
1590 |
QVERIFY(f.isValid()); |
|
1591 |
QCOMPARE(f.position(), 5); |
|
1592 |
QCOMPARE(f.length(), 1); |
|
1593 |
//qDebug() << block.text().mid(f.position(), f.length()); |
|
1594 |
||
1595 |
iter++; |
|
1596 |
f = iter.fragment(); |
|
1597 |
//qDebug() << block.text().mid(f.position(), f.length()); |
|
1598 |
QVERIFY(f.isValid()); |
|
1599 |
QCOMPARE(f.position(), 6); |
|
1600 |
QCOMPARE(f.length(), 5); // 1 space should be preserved. |
|
1601 |
QCOMPARE(block.text().mid(f.position(), f.length()), QString(" text")); |
|
1602 |
||
1603 |
doc.setHtml("<table><tr><td> foo</td></tr></table> text"); // 4 spaces before the second 'text' |
|
1604 |
block = doc.firstBlock().next(); |
|
1605 |
//qDebug() << block.text(); |
|
1606 |
QCOMPARE(block.text(), QString("foo")); |
|
1607 |
||
1608 |
block = block.next(); |
|
1609 |
//qDebug() << block.text(); |
|
1610 |
QCOMPARE(block.text(), QString("text")); |
|
1611 |
} |
|
1612 |
||
1613 |
void tst_QTextDocument::setFragmentMarkersInHtmlExport() |
|
1614 |
{ |
|
1615 |
{ |
|
1616 |
CREATE_DOC_AND_CURSOR(); |
|
1617 |
||
1618 |
cursor.insertText("Leadin"); |
|
1619 |
const int startPos = cursor.position(); |
|
1620 |
||
1621 |
cursor.insertText("Test"); |
|
1622 |
QTextCharFormat fmt; |
|
1623 |
fmt.setForeground(QColor("#00ff00")); |
|
1624 |
cursor.insertText("Blah", fmt); |
|
1625 |
||
1626 |
const int endPos = cursor.position(); |
|
1627 |
cursor.insertText("Leadout", QTextCharFormat()); |
|
1628 |
||
1629 |
cursor.setPosition(startPos); |
|
1630 |
cursor.setPosition(endPos, QTextCursor::KeepAnchor); |
|
1631 |
QTextDocumentFragment fragment(cursor); |
|
1632 |
||
1633 |
QString expected = htmlHead; |
|
1634 |
expected.replace(QRegExp("<body.*>"), QString("<body>")); |
|
1635 |
expected += QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><!--StartFragment-->Test<span style=\" color:#00ff00;\">Blah</span><!--EndFragment--></p>") + htmlTail; |
|
1636 |
QCOMPARE(fragment.toHtml(), expected); |
|
1637 |
} |
|
1638 |
{ |
|
1639 |
CREATE_DOC_AND_CURSOR(); |
|
1640 |
||
1641 |
cursor.insertText("Leadin"); |
|
1642 |
const int startPos = cursor.position(); |
|
1643 |
||
1644 |
cursor.insertText("Test"); |
|
1645 |
||
1646 |
const int endPos = cursor.position(); |
|
1647 |
cursor.insertText("Leadout", QTextCharFormat()); |
|
1648 |
||
1649 |
cursor.setPosition(startPos); |
|
1650 |
cursor.setPosition(endPos, QTextCursor::KeepAnchor); |
|
1651 |
QTextDocumentFragment fragment(cursor); |
|
1652 |
||
1653 |
QString expected = htmlHead; |
|
1654 |
expected.replace(QRegExp("<body.*>"), QString("<body>")); |
|
1655 |
expected += QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><!--StartFragment-->Test<!--EndFragment--></p>") + htmlTail; |
|
1656 |
QCOMPARE(fragment.toHtml(), expected); |
|
1657 |
} |
|
1658 |
} |
|
1659 |
||
1660 |
void tst_QTextDocument::toHtmlBodyBgColor() |
|
1661 |
{ |
|
1662 |
CREATE_DOC_AND_CURSOR(); |
|
1663 |
||
1664 |
cursor.insertText("Blah"); |
|
1665 |
||
1666 |
QTextFrameFormat fmt = doc.rootFrame()->frameFormat(); |
|
1667 |
fmt.setBackground(QColor("#0000ff")); |
|
1668 |
doc.rootFrame()->setFrameFormat(fmt); |
|
1669 |
||
1670 |
QString expectedHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" " |
|
1671 |
"\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" |
|
1672 |
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" |
|
1673 |
"p, li { white-space: pre-wrap; }\n" |
|
1674 |
"</style></head>" |
|
1675 |
"<body style=\" font-family:'%1'; font-size:%2pt; font-weight:%3; font-style:%4;\"" |
|
1676 |
" bgcolor=\"#0000ff\">\n" |
|
1677 |
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>" |
|
1678 |
"</body></html>"); |
|
1679 |
||
1680 |
expectedHtml = expectedHtml.arg(defaultFont.family()).arg(defaultFont.pointSizeF()).arg(defaultFont.weight() * 8).arg((defaultFont.italic() ? "italic" : "normal")); |
|
1681 |
||
1682 |
QCOMPARE(doc.toHtml(), expectedHtml); |
|
1683 |
} |
|
1684 |
||
1685 |
void tst_QTextDocument::toHtmlRootFrameProperties() |
|
1686 |
{ |
|
1687 |
CREATE_DOC_AND_CURSOR(); |
|
1688 |
||
1689 |
QTextFrameFormat fmt = doc.rootFrame()->frameFormat(); |
|
1690 |
fmt.setTopMargin(10); |
|
1691 |
fmt.setLeftMargin(10); |
|
1692 |
fmt.setBorder(2); |
|
1693 |
doc.rootFrame()->setFrameFormat(fmt); |
|
1694 |
||
1695 |
cursor.insertText("Blah"); |
|
1696 |
||
1697 |
QString expectedOutput("<table border=\"2\" style=\"-qt-table-type: root; margin-top:10px; " |
|
1698 |
"margin-bottom:4px; margin-left:10px; margin-right:4px;\">\n" |
|
1699 |
"<tr>\n<td style=\"border: none;\">\n" |
|
1700 |
"<p DEFAULTBLOCKSTYLE>Blah</p></td></tr></table>"); |
|
1701 |
||
1702 |
expectedOutput.prepend(htmlHead); |
|
1703 |
expectedOutput.replace("DEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\""); |
|
1704 |
expectedOutput.append(htmlTail); |
|
1705 |
||
1706 |
QCOMPARE(doc.toHtml(), expectedOutput); |
|
1707 |
} |
|
1708 |
||
1709 |
void tst_QTextDocument::capitalizationHtmlInExport() |
|
1710 |
{ |
|
1711 |
doc->setPlainText("Test"); |
|
1712 |
||
1713 |
QRegExp re(".*span style=\"(.*)\">Test.*"); |
|
1714 |
QVERIFY(re.exactMatch(doc->toHtml()) == false); // no span |
|
1715 |
||
1716 |
QTextCursor cursor(doc); |
|
1717 |
cursor.setPosition(4, QTextCursor::KeepAnchor); |
|
1718 |
QTextCharFormat cf; |
|
1719 |
cf.setFontCapitalization(QFont::SmallCaps); |
|
1720 |
cursor.mergeCharFormat(cf); |
|
1721 |
||
1722 |
const QString smallcaps = doc->toHtml(); |
|
1723 |
QVERIFY(re.exactMatch(doc->toHtml())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1724 |
QCOMPARE(re.captureCount(), 1); |
0 | 1725 |
QCOMPARE(re.cap(1).trimmed(), QString("font-variant:small-caps;")); |
1726 |
||
1727 |
cf.setFontCapitalization(QFont::AllUppercase); |
|
1728 |
cursor.mergeCharFormat(cf); |
|
1729 |
const QString uppercase = doc->toHtml(); |
|
1730 |
QVERIFY(re.exactMatch(doc->toHtml())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1731 |
QCOMPARE(re.captureCount(), 1); |
0 | 1732 |
QCOMPARE(re.cap(1).trimmed(), QString("text-transform:uppercase;")); |
1733 |
||
1734 |
cf.setFontCapitalization(QFont::AllLowercase); |
|
1735 |
cursor.mergeCharFormat(cf); |
|
1736 |
const QString lowercase = doc->toHtml(); |
|
1737 |
QVERIFY(re.exactMatch(doc->toHtml())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1738 |
QCOMPARE(re.captureCount(), 1); |
0 | 1739 |
QCOMPARE(re.cap(1).trimmed(), QString("text-transform:lowercase;")); |
1740 |
||
1741 |
doc->setHtml(smallcaps); |
|
1742 |
cursor.setPosition(1); |
|
1743 |
QCOMPARE(cursor.charFormat().fontCapitalization(), QFont::SmallCaps); |
|
1744 |
doc->setHtml(uppercase); |
|
1745 |
QCOMPARE(cursor.charFormat().fontCapitalization(), QFont::AllUppercase); |
|
1746 |
doc->setHtml(lowercase); |
|
1747 |
QCOMPARE(cursor.charFormat().fontCapitalization(), QFont::AllLowercase); |
|
1748 |
} |
|
1749 |
||
1750 |
void tst_QTextDocument::wordspacingHtmlExport() |
|
1751 |
{ |
|
1752 |
doc->setPlainText("Test"); |
|
1753 |
||
1754 |
QRegExp re(".*span style=\"(.*)\">Test.*"); |
|
1755 |
QVERIFY(re.exactMatch(doc->toHtml()) == false); // no span |
|
1756 |
||
1757 |
QTextCursor cursor(doc); |
|
1758 |
cursor.setPosition(4, QTextCursor::KeepAnchor); |
|
1759 |
QTextCharFormat cf; |
|
1760 |
cf.setFontWordSpacing(4); |
|
1761 |
cursor.mergeCharFormat(cf); |
|
1762 |
||
1763 |
QVERIFY(re.exactMatch(doc->toHtml())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1764 |
QCOMPARE(re.captureCount(), 1); |
0 | 1765 |
QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:4px;")); |
1766 |
||
1767 |
cf.setFontWordSpacing(-8.5); |
|
1768 |
cursor.mergeCharFormat(cf); |
|
1769 |
||
1770 |
QVERIFY(re.exactMatch(doc->toHtml())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1771 |
QCOMPARE(re.captureCount(), 1); |
0 | 1772 |
QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:-8.5px;")); |
1773 |
} |
|
1774 |
||
1775 |
class CursorPosSignalSpy : public QObject |
|
1776 |
{ |
|
1777 |
Q_OBJECT |
|
1778 |
public: |
|
1779 |
CursorPosSignalSpy(QTextDocument *doc) |
|
1780 |
{ |
|
1781 |
calls = 0; |
|
1782 |
connect(doc, SIGNAL(cursorPositionChanged(const QTextCursor &)), |
|
1783 |
this, SLOT(cursorPositionChanged(const QTextCursor &))); |
|
1784 |
} |
|
1785 |
||
1786 |
int calls; |
|
1787 |
||
1788 |
private slots: |
|
1789 |
void cursorPositionChanged(const QTextCursor &) |
|
1790 |
{ |
|
1791 |
++calls; |
|
1792 |
} |
|
1793 |
}; |
|
1794 |
||
1795 |
void tst_QTextDocument::cursorPositionChanged() |
|
1796 |
{ |
|
1797 |
CursorPosSignalSpy spy(doc); |
|
1798 |
||
1799 |
cursor.insertText("Test"); |
|
1800 |
QCOMPARE(spy.calls, 1); |
|
1801 |
||
1802 |
spy.calls = 0; |
|
1803 |
QTextCursor unrelatedCursor(doc); |
|
1804 |
unrelatedCursor.insertText("Blah"); |
|
1805 |
QCOMPARE(spy.calls, 2); |
|
1806 |
||
1807 |
spy.calls = 0; |
|
1808 |
cursor.insertText("Blah"); |
|
1809 |
QCOMPARE(spy.calls, 1); |
|
1810 |
||
1811 |
spy.calls = 0; |
|
1812 |
cursor.movePosition(QTextCursor::PreviousCharacter); |
|
1813 |
QCOMPARE(spy.calls, 0); |
|
1814 |
} |
|
1815 |
||
1816 |
void tst_QTextDocument::cursorPositionChangedOnSetText() |
|
1817 |
{ |
|
1818 |
CursorPosSignalSpy spy(doc); |
|
1819 |
||
1820 |
// doc has one QTextCursor stored in the |
|
1821 |
// cursor member variable, thus the signal |
|
1822 |
// gets emitted once. |
|
1823 |
||
1824 |
doc->setPlainText("Foo\nBar\nBaz\nBlub\nBlah"); |
|
1825 |
||
1826 |
QCOMPARE(spy.calls, 1); |
|
1827 |
||
1828 |
spy.calls = 0; |
|
1829 |
doc->setHtml("<p>Foo<p>Bar<p>Baz<p>Blah"); |
|
1830 |
||
1831 |
QCOMPARE(spy.calls, 1); |
|
1832 |
} |
|
1833 |
||
1834 |
void tst_QTextDocument::textFrameIterator() |
|
1835 |
{ |
|
1836 |
cursor.insertTable(1, 1); |
|
1837 |
||
1838 |
int blockCount = 0; |
|
1839 |
int frameCount = 0; |
|
1840 |
||
1841 |
for (QTextFrame::Iterator frameIt = doc->rootFrame()->begin(); |
|
1842 |
!frameIt.atEnd(); ++frameIt) { |
|
1843 |
if (frameIt.currentFrame()) |
|
1844 |
++frameCount; |
|
1845 |
else if (frameIt.currentBlock().isValid()) |
|
1846 |
++blockCount; |
|
1847 |
||
1848 |
} |
|
1849 |
||
1850 |
QEXPECT_FAIL("", "This is currently worked around in the html export but needs fixing!", Continue); |
|
1851 |
QCOMPARE(blockCount, 0); |
|
1852 |
QCOMPARE(frameCount, 1); |
|
1853 |
} |
|
1854 |
||
1855 |
void tst_QTextDocument::codecForHtml() |
|
1856 |
{ |
|
1857 |
const QByteArray header("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=utf-16\">"); |
|
1858 |
QTextCodec *c = Qt::codecForHtml(header); |
|
1859 |
QVERIFY(c); |
|
1860 |
QCOMPARE(c->name(), QByteArray("UTF-16")); |
|
1861 |
} |
|
1862 |
||
1863 |
class TestSyntaxHighlighter : public QObject |
|
1864 |
{ |
|
1865 |
Q_OBJECT |
|
1866 |
public: |
|
1867 |
inline TestSyntaxHighlighter(QTextDocument *doc) : QObject(doc), ok(false) {} |
|
1868 |
||
1869 |
bool ok; |
|
1870 |
||
1871 |
private slots: |
|
1872 |
inline void markBlockDirty(int from, int charsRemoved, int charsAdded) |
|
1873 |
{ |
|
1874 |
Q_UNUSED(charsRemoved); |
|
1875 |
Q_UNUSED(charsAdded); |
|
1876 |
QTextDocument *doc = static_cast<QTextDocument *>(parent()); |
|
1877 |
QTextBlock block = doc->findBlock(from); |
|
1878 |
||
1879 |
QTestDocumentLayout *lout = qobject_cast<QTestDocumentLayout *>(doc->documentLayout()); |
|
1880 |
lout->called = false; |
|
1881 |
||
1882 |
doc->markContentsDirty(block.position(), block.length()); |
|
1883 |
||
1884 |
ok = (lout->called == false); |
|
1885 |
} |
|
1886 |
||
1887 |
inline void modifyBlockAgain(int from, int charsRemoved, int charsAdded) |
|
1888 |
{ |
|
1889 |
Q_UNUSED(charsRemoved); |
|
1890 |
Q_UNUSED(charsAdded); |
|
1891 |
QTextDocument *doc = static_cast<QTextDocument *>(parent()); |
|
1892 |
QTextBlock block = doc->findBlock(from); |
|
1893 |
QTextCursor cursor(block); |
|
1894 |
||
1895 |
QTestDocumentLayout *lout = qobject_cast<QTestDocumentLayout *>(doc->documentLayout()); |
|
1896 |
lout->called = false; |
|
1897 |
||
1898 |
cursor.insertText("Foo"); |
|
1899 |
||
1900 |
ok = (lout->called == true); |
|
1901 |
} |
|
1902 |
}; |
|
1903 |
||
1904 |
void tst_QTextDocument::markContentsDirty() |
|
1905 |
{ |
|
1906 |
QTestDocumentLayout *lout = new QTestDocumentLayout(doc); |
|
1907 |
doc->setDocumentLayout(lout); |
|
1908 |
TestSyntaxHighlighter *highlighter = new TestSyntaxHighlighter(doc); |
|
1909 |
connect(doc, SIGNAL(contentsChange(int, int, int)), |
|
1910 |
highlighter, SLOT(markBlockDirty(int, int, int))); |
|
1911 |
||
1912 |
highlighter->ok = false; |
|
1913 |
cursor.insertText("Some dummy text blah blah"); |
|
1914 |
QVERIFY(highlighter->ok); |
|
1915 |
||
1916 |
disconnect(doc, SIGNAL(contentsChange(int, int, int)), |
|
1917 |
highlighter, SLOT(markBlockDirty(int, int, int))); |
|
1918 |
connect(doc, SIGNAL(contentsChange(int, int, int)), |
|
1919 |
highlighter, SLOT(modifyBlockAgain(int, int, int))); |
|
1920 |
highlighter->ok = false; |
|
1921 |
cursor.insertText("FooBar"); |
|
1922 |
QVERIFY(highlighter->ok); |
|
1923 |
||
1924 |
lout->called = false; |
|
1925 |
||
1926 |
doc->markContentsDirty(1, 4); |
|
1927 |
||
1928 |
QVERIFY(lout->called); |
|
1929 |
} |
|
1930 |
||
1931 |
void tst_QTextDocument::clonePreservesMetaInformation() |
|
1932 |
{ |
|
1933 |
const QString title("Foobar"); |
|
1934 |
const QString url("about:blank"); |
|
1935 |
doc->setHtml("<html><head><title>" + title + "</title></head><body>Hrm</body></html>"); |
|
1936 |
doc->setMetaInformation(QTextDocument::DocumentUrl, url); |
|
1937 |
QCOMPARE(doc->metaInformation(QTextDocument::DocumentTitle), title); |
|
1938 |
QCOMPARE(doc->metaInformation(QTextDocument::DocumentUrl), url); |
|
1939 |
||
1940 |
QTextDocument *clone = doc->clone(); |
|
1941 |
QCOMPARE(clone->metaInformation(QTextDocument::DocumentTitle), title); |
|
1942 |
QCOMPARE(clone->metaInformation(QTextDocument::DocumentUrl), url); |
|
1943 |
delete clone; |
|
1944 |
} |
|
1945 |
||
1946 |
void tst_QTextDocument::clonePreservesPageSize() |
|
1947 |
{ |
|
1948 |
QSizeF sz(100., 100.); |
|
1949 |
doc->setPageSize(sz); |
|
1950 |
QTextDocument *clone = doc->clone(); |
|
1951 |
QCOMPARE(clone->pageSize(), sz); |
|
1952 |
delete clone; |
|
1953 |
} |
|
1954 |
||
1955 |
void tst_QTextDocument::clonePreservesPageBreakPolicies() |
|
1956 |
{ |
|
1957 |
QTextTableFormat tableFmt; |
|
1958 |
tableFmt.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter); |
|
1959 |
||
1960 |
QTextBlockFormat blockFmt; |
|
1961 |
blockFmt.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
|
1962 |
||
1963 |
QTextCursor cursor(doc); |
|
1964 |
||
1965 |
cursor.setBlockFormat(blockFmt); |
|
1966 |
cursor.insertText("foo"); |
|
1967 |
cursor.insertTable(2, 2, tableFmt); |
|
1968 |
||
1969 |
QTextDocument *clone = doc->clone(); |
|
1970 |
QCOMPARE(clone->begin().blockFormat().pageBreakPolicy(), QTextFormat::PageBreak_AlwaysBefore); |
|
1971 |
QVERIFY(!clone->rootFrame()->childFrames().isEmpty()); |
|
1972 |
QCOMPARE(clone->rootFrame()->childFrames().first()->frameFormat().pageBreakPolicy(), QTextFormat::PageBreak_AlwaysAfter); |
|
1973 |
delete clone; |
|
1974 |
} |
|
1975 |
||
1976 |
void tst_QTextDocument::clonePreservesDefaultFont() |
|
1977 |
{ |
|
1978 |
QFont f = doc->defaultFont(); |
|
1979 |
QVERIFY(f.pointSize() != 100); |
|
1980 |
f.setPointSize(100); |
|
1981 |
doc->setDefaultFont(f); |
|
1982 |
QTextDocument *clone = doc->clone(); |
|
1983 |
QCOMPARE(clone->defaultFont(), f); |
|
1984 |
delete clone; |
|
1985 |
} |
|
1986 |
||
1987 |
void tst_QTextDocument::clonePreservesResources() |
|
1988 |
{ |
|
1989 |
QUrl testUrl(":/foobar"); |
|
1990 |
QVariant testResource("hello world"); |
|
1991 |
||
1992 |
doc->addResource(QTextDocument::ImageResource, testUrl, testResource); |
|
1993 |
QTextDocument *clone = doc->clone(); |
|
1994 |
QVERIFY(clone->resource(QTextDocument::ImageResource, testUrl) == testResource); |
|
1995 |
delete clone; |
|
1996 |
} |
|
1997 |
||
1998 |
void tst_QTextDocument::clonePreservesUserStates() |
|
1999 |
{ |
|
2000 |
QTextCursor cursor(doc); |
|
2001 |
cursor.insertText("bla bla bla"); |
|
2002 |
cursor.block().setUserState(1); |
|
2003 |
cursor.insertBlock(); |
|
2004 |
cursor.insertText("foo bar"); |
|
2005 |
cursor.block().setUserState(2); |
|
2006 |
cursor.insertBlock(); |
|
2007 |
cursor.insertText("no user state"); |
|
2008 |
||
2009 |
QTextDocument *clone = doc->clone(); |
|
2010 |
QTextBlock b1 = doc->begin(), b2 = clone->begin(); |
|
2011 |
while (b1 != doc->end()) { |
|
2012 |
b1 = b1.next(); |
|
2013 |
b2 = b2.next(); |
|
2014 |
QCOMPARE(b1.userState(), b2.userState()); |
|
2015 |
} |
|
2016 |
QVERIFY(b2 == clone->end()); |
|
2017 |
delete clone; |
|
2018 |
} |
|
2019 |
||
2020 |
void tst_QTextDocument::clonePreservesRootFrameFormat() |
|
2021 |
{ |
|
2022 |
doc->setPlainText("Hello"); |
|
2023 |
QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); |
|
2024 |
fmt.setMargin(200); |
|
2025 |
doc->rootFrame()->setFrameFormat(fmt); |
|
2026 |
QCOMPARE(doc->rootFrame()->frameFormat().margin(), qreal(200)); |
|
2027 |
QTextDocument *copy = doc->clone(); |
|
2028 |
QCOMPARE(copy->rootFrame()->frameFormat().margin(), qreal(200)); |
|
2029 |
delete copy; |
|
2030 |
} |
|
2031 |
||
2032 |
void tst_QTextDocument::clonePreservesIndentWidth() |
|
2033 |
{ |
|
2034 |
doc->setIndentWidth(42); |
|
2035 |
QTextDocument *clone = doc->clone(); |
|
2036 |
QCOMPARE(clone->indentWidth(), qreal(42)); |
|
2037 |
} |
|
2038 |
||
2039 |
void tst_QTextDocument::blockCount() |
|
2040 |
{ |
|
2041 |
QCOMPARE(doc->blockCount(), 1); |
|
2042 |
cursor.insertBlock(); |
|
2043 |
QCOMPARE(doc->blockCount(), 2); |
|
2044 |
cursor.insertBlock(); |
|
2045 |
QCOMPARE(doc->blockCount(), 3); |
|
2046 |
cursor.insertText("blah blah"); |
|
2047 |
QCOMPARE(doc->blockCount(), 3); |
|
2048 |
doc->undo(); |
|
2049 |
doc->undo(); |
|
2050 |
QCOMPARE(doc->blockCount(), 2); |
|
2051 |
doc->undo(); |
|
2052 |
QCOMPARE(doc->blockCount(), 1); |
|
2053 |
} |
|
2054 |
||
2055 |
void tst_QTextDocument::resolvedFontInEmptyFormat() |
|
2056 |
{ |
|
2057 |
QFont font; |
|
2058 |
font.setPointSize(42); |
|
2059 |
doc->setDefaultFont(font); |
|
2060 |
QTextCharFormat fmt = doc->begin().charFormat(); |
|
2061 |
QVERIFY(fmt.properties().isEmpty()); |
|
2062 |
QVERIFY(fmt.font() == font); |
|
2063 |
} |
|
2064 |
||
2065 |
void tst_QTextDocument::defaultRootFrameMargin() |
|
2066 |
{ |
|
2067 |
QCOMPARE(doc->rootFrame()->frameFormat().margin(), 4.0); |
|
2068 |
} |
|
2069 |
||
2070 |
class TestDocument : public QTextDocument |
|
2071 |
{ |
|
2072 |
public: |
|
2073 |
inline TestDocument(const QUrl &testUrl, const QString &testString) |
|
2074 |
: url(testUrl), string(testString), resourceLoaded(false) {} |
|
2075 |
||
2076 |
bool hasResourceCached(); |
|
2077 |
||
2078 |
protected: |
|
2079 |
virtual QVariant loadResource(int type, const QUrl &name); |
|
2080 |
||
2081 |
private: |
|
2082 |
QUrl url; |
|
2083 |
QString string; |
|
2084 |
bool resourceLoaded; |
|
2085 |
}; |
|
2086 |
||
2087 |
bool TestDocument::hasResourceCached() |
|
2088 |
{ |
|
2089 |
resourceLoaded = false; |
|
2090 |
resource(QTextDocument::ImageResource, url); |
|
2091 |
return !resourceLoaded; |
|
2092 |
} |
|
2093 |
||
2094 |
QVariant TestDocument::loadResource(int type, const QUrl &name) |
|
2095 |
{ |
|
2096 |
if (type == QTextDocument::ImageResource |
|
2097 |
&& name == url) { |
|
2098 |
resourceLoaded = true; |
|
2099 |
return string; |
|
2100 |
} |
|
2101 |
return QTextDocument::loadResource(type, name); |
|
2102 |
} |
|
2103 |
||
2104 |
void tst_QTextDocument::clearResources() |
|
2105 |
{ |
|
2106 |
// regular resource for QTextDocument |
|
2107 |
QUrl testUrl(":/foobar"); |
|
2108 |
QVariant testResource("hello world"); |
|
2109 |
||
2110 |
// implicitly cached resource, initially loaded through TestDocument::loadResource() |
|
2111 |
QUrl cacheUrl(":/blub"); |
|
2112 |
QString cacheResource("mah"); |
|
2113 |
||
2114 |
TestDocument doc(cacheUrl, cacheResource); |
|
2115 |
doc.addResource(QTextDocument::ImageResource, testUrl, testResource); |
|
2116 |
||
2117 |
QVERIFY(doc.resource(QTextDocument::ImageResource, testUrl) == testResource); |
|
2118 |
||
2119 |
doc.setPlainText("Hah"); |
|
2120 |
QVERIFY(doc.resource(QTextDocument::ImageResource, testUrl) == testResource); |
|
2121 |
||
2122 |
doc.setHtml("<b>Mooo</b><img src=\":/blub\"/>"); |
|
2123 |
QVERIFY(doc.resource(QTextDocument::ImageResource, testUrl) == testResource); |
|
2124 |
QVERIFY(doc.resource(QTextDocument::ImageResource, cacheUrl) == cacheResource); |
|
2125 |
||
2126 |
doc.clear(); |
|
2127 |
QVERIFY(!doc.resource(QTextDocument::ImageResource, testUrl).isValid()); |
|
2128 |
QVERIFY(!doc.hasResourceCached()); |
|
2129 |
doc.clear(); |
|
2130 |
||
2131 |
doc.setHtml("<b>Mooo</b><img src=\":/blub\"/>"); |
|
2132 |
QVERIFY(doc.resource(QTextDocument::ImageResource, cacheUrl) == cacheResource); |
|
2133 |
||
2134 |
doc.setPlainText("Foob"); |
|
2135 |
QVERIFY(!doc.hasResourceCached()); |
|
2136 |
} |
|
2137 |
||
2138 |
void tst_QTextDocument::setPlainText() |
|
2139 |
{ |
|
2140 |
doc->setPlainText("Hello World"); |
|
2141 |
QString s(""); |
|
2142 |
doc->setPlainText(s); |
|
2143 |
QCOMPARE(doc->toPlainText(), s); |
|
2144 |
} |
|
2145 |
||
2146 |
void tst_QTextDocument::toPlainText() |
|
2147 |
{ |
|
2148 |
doc->setHtml("Hello World"); |
|
2149 |
QCOMPARE(doc->toPlainText(), QLatin1String("Hello World")); |
|
2150 |
} |
|
2151 |
||
2152 |
void tst_QTextDocument::deleteTextObjectsOnClear() |
|
2153 |
{ |
|
2154 |
QPointer<QTextTable> table = cursor.insertTable(2, 2); |
|
2155 |
QVERIFY(!table.isNull()); |
|
2156 |
doc->clear(); |
|
2157 |
QVERIFY(table.isNull()); |
|
2158 |
} |
|
2159 |
||
2160 |
void tst_QTextDocument::defaultStyleSheet() |
|
2161 |
{ |
|
2162 |
const QString sheet("p { background-color: green; }"); |
|
2163 |
QVERIFY(doc->defaultStyleSheet().isEmpty()); |
|
2164 |
doc->setDefaultStyleSheet(sheet); |
|
2165 |
QCOMPARE(doc->defaultStyleSheet(), sheet); |
|
2166 |
||
2167 |
cursor.insertHtml("<p>test"); |
|
2168 |
QTextBlockFormat fmt = doc->begin().blockFormat(); |
|
2169 |
QVERIFY(fmt.background().color() == QColor("green")); |
|
2170 |
||
2171 |
doc->clear(); |
|
2172 |
cursor.insertHtml("<p>test"); |
|
2173 |
fmt = doc->begin().blockFormat(); |
|
2174 |
QVERIFY(fmt.background().color() == QColor("green")); |
|
2175 |
||
2176 |
QTextDocument *clone = doc->clone(); |
|
2177 |
QCOMPARE(clone->defaultStyleSheet(), sheet); |
|
2178 |
cursor = QTextCursor(clone); |
|
2179 |
cursor.insertHtml("<p>test"); |
|
2180 |
fmt = clone->begin().blockFormat(); |
|
2181 |
QVERIFY(fmt.background().color() == QColor("green")); |
|
2182 |
delete clone; |
|
2183 |
||
2184 |
cursor = QTextCursor(doc); |
|
2185 |
cursor.insertHtml("<p>test"); |
|
2186 |
fmt = doc->begin().blockFormat(); |
|
2187 |
QVERIFY(fmt.background().color() == QColor("green")); |
|
2188 |
||
2189 |
doc->clear(); |
|
2190 |
cursor.insertHtml("<style>p { background-color: red; }</style><p>test"); |
|
2191 |
fmt = doc->begin().blockFormat(); |
|
2192 |
QVERIFY(fmt.background().color() == QColor("red")); |
|
2193 |
||
2194 |
doc->clear(); |
|
2195 |
doc->setDefaultStyleSheet("invalid style sheet...."); |
|
2196 |
cursor.insertHtml("<p>test"); |
|
2197 |
fmt = doc->begin().blockFormat(); |
|
2198 |
QVERIFY(fmt.background().color() != QColor("green")); |
|
2199 |
} |
|
2200 |
||
2201 |
void tst_QTextDocument::maximumBlockCount() |
|
2202 |
{ |
|
2203 |
QCOMPARE(doc->maximumBlockCount(), 0); |
|
2204 |
QVERIFY(doc->isUndoRedoEnabled()); |
|
2205 |
||
2206 |
cursor.insertBlock(); |
|
2207 |
cursor.insertText("Blah"); |
|
2208 |
cursor.insertBlock(); |
|
2209 |
cursor.insertText("Foo"); |
|
2210 |
QCOMPARE(doc->blockCount(), 3); |
|
2211 |
QCOMPARE(doc->toPlainText(), QString("\nBlah\nFoo")); |
|
2212 |
||
2213 |
doc->setMaximumBlockCount(1); |
|
2214 |
QVERIFY(!doc->isUndoRedoEnabled()); |
|
2215 |
||
2216 |
QCOMPARE(doc->blockCount(), 1); |
|
2217 |
QCOMPARE(doc->toPlainText(), QString("Foo")); |
|
2218 |
||
2219 |
cursor.insertBlock(); |
|
2220 |
cursor.insertText("Hello"); |
|
2221 |
doc->setMaximumBlockCount(1); |
|
2222 |
QCOMPARE(doc->blockCount(), 1); |
|
2223 |
QCOMPARE(doc->toPlainText(), QString("Hello")); |
|
2224 |
||
2225 |
doc->setMaximumBlockCount(100); |
|
2226 |
for (int i = 0; i < 1000; ++i) { |
|
2227 |
cursor.insertBlock(); |
|
2228 |
cursor.insertText("Blah)"); |
|
2229 |
QVERIFY(doc->blockCount() <= 100); |
|
2230 |
} |
|
2231 |
||
2232 |
cursor.movePosition(QTextCursor::End); |
|
2233 |
QCOMPARE(cursor.blockNumber(), 99); |
|
2234 |
QTextCharFormat fmt; |
|
2235 |
fmt.setFontItalic(true); |
|
2236 |
cursor.setBlockCharFormat(fmt); |
|
2237 |
cursor.movePosition(QTextCursor::Start); |
|
2238 |
QVERIFY(!cursor.blockCharFormat().fontItalic()); |
|
2239 |
||
2240 |
doc->setMaximumBlockCount(1); |
|
2241 |
QVERIFY(cursor.blockCharFormat().fontItalic()); |
|
2242 |
||
2243 |
cursor.insertTable(2, 2); |
|
2244 |
QCOMPARE(doc->blockCount(), 6); |
|
2245 |
cursor.insertBlock(); |
|
2246 |
QCOMPARE(doc->blockCount(), 1); |
|
2247 |
} |
|
2248 |
||
2249 |
void tst_QTextDocument::adjustSize() |
|
2250 |
{ |
|
2251 |
// avoid ugly tooltips like in task 125583 |
|
2252 |
QString text("Test Text"); |
|
2253 |
doc->setPlainText(text); |
|
2254 |
doc->rootFrame()->setFrameFormat(QTextFrameFormat()); |
|
2255 |
doc->adjustSize(); |
|
2256 |
QCOMPARE(doc->size().width(), doc->idealWidth()); |
|
2257 |
} |
|
2258 |
||
2259 |
void tst_QTextDocument::initialUserData() |
|
2260 |
{ |
|
2261 |
doc->setPlainText("Hello"); |
|
2262 |
QTextBlock block = doc->begin(); |
|
2263 |
block.setUserData(new QTextBlockUserData); |
|
2264 |
QVERIFY(block.userData()); |
|
2265 |
doc->documentLayout(); |
|
2266 |
QVERIFY(block.userData()); |
|
2267 |
doc->setDocumentLayout(new QTestDocumentLayout(doc)); |
|
2268 |
QVERIFY(!block.userData()); |
|
2269 |
} |
|
2270 |
||
2271 |
void tst_QTextDocument::html_defaultFont() |
|
2272 |
{ |
|
2273 |
QFont f; |
|
2274 |
f.setItalic(true); |
|
2275 |
f.setWeight(QFont::Bold); |
|
2276 |
doc->setDefaultFont(f); |
|
2277 |
doc->setPlainText("Test"); |
|
2278 |
||
2279 |
QString bodyPart = QString::fromLatin1("<body style=\" font-family:'%1'; font-size:%2pt; font-weight:%3; font-style:italic;\">") |
|
2280 |
.arg(f.family()).arg(f.pointSizeF()).arg(f.weight() * 8); |
|
2281 |
||
2282 |
QString html = doc->toHtml(); |
|
2283 |
if (!html.contains(bodyPart)) { |
|
2284 |
qDebug() << "html:" << html; |
|
2285 |
qDebug() << "expected body:" << bodyPart; |
|
2286 |
QVERIFY(html.contains(bodyPart)); |
|
2287 |
} |
|
2288 |
||
2289 |
if (html.contains("span")) |
|
2290 |
qDebug() << "html:" << html; |
|
2291 |
QVERIFY(!html.contains("<span style")); |
|
2292 |
} |
|
2293 |
||
2294 |
void tst_QTextDocument::blockCountChanged() |
|
2295 |
{ |
|
2296 |
QSignalSpy spy(doc, SIGNAL(blockCountChanged(int))); |
|
2297 |
||
2298 |
doc->setPlainText("Foo"); |
|
2299 |
||
2300 |
QCOMPARE(doc->blockCount(), 1); |
|
2301 |
QCOMPARE(spy.count(), 0); |
|
2302 |
||
2303 |
spy.clear(); |
|
2304 |
||
2305 |
doc->setPlainText("Foo\nBar"); |
|
2306 |
QCOMPARE(doc->blockCount(), 2); |
|
2307 |
QCOMPARE(spy.count(), 1); |
|
2308 |
QCOMPARE(spy.at(0).value(0).toInt(), 2); |
|
2309 |
||
2310 |
spy.clear(); |
|
2311 |
||
2312 |
cursor.movePosition(QTextCursor::End); |
|
2313 |
cursor.insertText("Blahblah"); |
|
2314 |
||
2315 |
QCOMPARE(spy.count(), 0); |
|
2316 |
||
2317 |
cursor.insertBlock(); |
|
2318 |
QCOMPARE(spy.count(), 1); |
|
2319 |
QCOMPARE(spy.at(0).value(0).toInt(), 3); |
|
2320 |
||
2321 |
spy.clear(); |
|
2322 |
doc->undo(); |
|
2323 |
||
2324 |
QCOMPARE(spy.count(), 1); |
|
2325 |
QCOMPARE(spy.at(0).value(0).toInt(), 2); |
|
2326 |
} |
|
2327 |
||
2328 |
void tst_QTextDocument::nonZeroDocumentLengthOnClear() |
|
2329 |
{ |
|
2330 |
QTestDocumentLayout *lout = new QTestDocumentLayout(doc); |
|
2331 |
doc->setDocumentLayout(lout); |
|
2332 |
||
2333 |
doc->clear(); |
|
2334 |
QVERIFY(lout->called); |
|
2335 |
QVERIFY(!lout->lastDocumentLengths.contains(0)); |
|
2336 |
} |
|
2337 |
||
2338 |
void tst_QTextDocument::setTextPreservesUndoRedoEnabled() |
|
2339 |
{ |
|
2340 |
QVERIFY(doc->isUndoRedoEnabled()); |
|
2341 |
||
2342 |
doc->setPlainText("Test"); |
|
2343 |
||
2344 |
QVERIFY(doc->isUndoRedoEnabled()); |
|
2345 |
||
2346 |
doc->setUndoRedoEnabled(false); |
|
2347 |
QVERIFY(!doc->isUndoRedoEnabled()); |
|
2348 |
doc->setPlainText("Test2"); |
|
2349 |
QVERIFY(!doc->isUndoRedoEnabled()); |
|
2350 |
||
2351 |
doc->setHtml("<p>hello"); |
|
2352 |
QVERIFY(!doc->isUndoRedoEnabled()); |
|
2353 |
} |
|
2354 |
||
2355 |
void tst_QTextDocument::firstLast() |
|
2356 |
{ |
|
2357 |
QCOMPARE(doc->blockCount(), 1); |
|
2358 |
QVERIFY(doc->firstBlock() == doc->lastBlock()); |
|
2359 |
||
2360 |
doc->setPlainText("Hello\nTest\nWorld"); |
|
2361 |
||
2362 |
QCOMPARE(doc->blockCount(), 3); |
|
2363 |
QVERIFY(doc->firstBlock() != doc->lastBlock()); |
|
2364 |
||
2365 |
QCOMPARE(doc->firstBlock().text(), QString("Hello")); |
|
2366 |
QCOMPARE(doc->lastBlock().text(), QString("World")); |
|
2367 |
||
2368 |
// manual forward loop |
|
2369 |
QTextBlock block = doc->firstBlock(); |
|
2370 |
||
2371 |
QVERIFY(block.isValid()); |
|
2372 |
QCOMPARE(block.text(), QString("Hello")); |
|
2373 |
||
2374 |
block = block.next(); |
|
2375 |
||
2376 |
QVERIFY(block.isValid()); |
|
2377 |
QCOMPARE(block.text(), QString("Test")); |
|
2378 |
||
2379 |
block = block.next(); |
|
2380 |
||
2381 |
QVERIFY(block.isValid()); |
|
2382 |
QCOMPARE(block.text(), QString("World")); |
|
2383 |
||
2384 |
block = block.next(); |
|
2385 |
QVERIFY(!block.isValid()); |
|
2386 |
||
2387 |
// manual backward loop |
|
2388 |
block = doc->lastBlock(); |
|
2389 |
||
2390 |
QVERIFY(block.isValid()); |
|
2391 |
QCOMPARE(block.text(), QString("World")); |
|
2392 |
||
2393 |
block = block.previous(); |
|
2394 |
||
2395 |
QVERIFY(block.isValid()); |
|
2396 |
QCOMPARE(block.text(), QString("Test")); |
|
2397 |
||
2398 |
block = block.previous(); |
|
2399 |
||
2400 |
QVERIFY(block.isValid()); |
|
2401 |
QCOMPARE(block.text(), QString("Hello")); |
|
2402 |
||
2403 |
block = block.previous(); |
|
2404 |
QVERIFY(!block.isValid()); |
|
2405 |
} |
|
2406 |
||
2407 |
const QString backgroundImage_html("<body><table><tr><td background=\"foo.png\">Blah</td></tr></table></body>"); |
|
2408 |
||
2409 |
void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &doc) |
|
2410 |
{ |
|
2411 |
QString expectedHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" " |
|
2412 |
"\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" |
|
2413 |
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" |
|
2414 |
"p, li { white-space: pre-wrap; }\n" |
|
2415 |
"</style></head>" |
|
2416 |
"<body style=\" font-family:'%1'; font-size:%2pt; font-weight:%3; font-style:%4;\">\n" |
|
2417 |
"<table border=\"0\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\">" |
|
2418 |
"\n<tr>\n<td background=\"foo.png\">" |
|
2419 |
"\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>" |
|
2420 |
"</td></tr></table></body></html>"); |
|
2421 |
||
2422 |
expectedHtml = expectedHtml.arg(defaultFont.family()).arg(defaultFont.pointSizeF()).arg(defaultFont.weight() * 8).arg((defaultFont.italic() ? "italic" : "normal")); |
|
2423 |
||
2424 |
QCOMPARE(doc.toHtml(), expectedHtml); |
|
2425 |
} |
|
2426 |
||
2427 |
void tst_QTextDocument::backgroundImage_toHtml() |
|
2428 |
{ |
|
2429 |
CREATE_DOC_AND_CURSOR(); |
|
2430 |
||
2431 |
doc.setHtml(backgroundImage_html); |
|
2432 |
backgroundImage_checkExpectedHtml(doc); |
|
2433 |
} |
|
2434 |
||
2435 |
void tst_QTextDocument::backgroundImage_toHtml2() |
|
2436 |
{ |
|
2437 |
CREATE_DOC_AND_CURSOR(); |
|
2438 |
||
2439 |
cursor.insertHtml(backgroundImage_html); |
|
2440 |
backgroundImage_checkExpectedHtml(doc); |
|
2441 |
} |
|
2442 |
||
2443 |
void tst_QTextDocument::backgroundImage_clone() |
|
2444 |
{ |
|
2445 |
CREATE_DOC_AND_CURSOR(); |
|
2446 |
||
2447 |
doc.setHtml(backgroundImage_html); |
|
2448 |
QTextDocument *clone = doc.clone(); |
|
2449 |
backgroundImage_checkExpectedHtml(*clone); |
|
2450 |
delete clone; |
|
2451 |
} |
|
2452 |
||
2453 |
void tst_QTextDocument::backgroundImage_copy() |
|
2454 |
{ |
|
2455 |
CREATE_DOC_AND_CURSOR(); |
|
2456 |
||
2457 |
doc.setHtml(backgroundImage_html); |
|
2458 |
QTextDocumentFragment fragment(&doc); |
|
2459 |
||
2460 |
{ |
|
2461 |
CREATE_DOC_AND_CURSOR(); |
|
2462 |
||
2463 |
cursor.insertFragment(fragment); |
|
2464 |
backgroundImage_checkExpectedHtml(doc); |
|
2465 |
} |
|
2466 |
} |
|
2467 |
||
2468 |
void tst_QTextDocument::documentCleanup() |
|
2469 |
{ |
|
2470 |
QTextDocument doc; |
|
2471 |
QTextCursor cursor(&doc); |
|
2472 |
cursor.insertText("d\nfoo\nbar\n"); |
|
2473 |
doc.documentLayout(); // forces relayout |
|
2474 |
||
2475 |
// remove char 1 |
|
2476 |
cursor.setPosition(0); |
|
2477 |
QSizeF size = doc.documentLayout()->documentSize(); |
|
2478 |
cursor.deleteChar(); |
|
2479 |
// the size should be unchanged. |
|
2480 |
QCOMPARE(doc.documentLayout()->documentSize(), size); |
|
2481 |
} |
|
2482 |
||
2483 |
void tst_QTextDocument::characterAt() |
|
2484 |
{ |
|
2485 |
QTextDocument doc; |
|
2486 |
QTextCursor cursor(&doc); |
|
2487 |
QString text("12345\n67890"); |
|
2488 |
cursor.insertText(text); |
|
2489 |
int length = doc.characterCount(); |
|
2490 |
QCOMPARE(length, text.length() + 1); |
|
2491 |
QCOMPARE(doc.characterAt(length-1), QChar(QChar::ParagraphSeparator)); |
|
2492 |
QCOMPARE(doc.characterAt(-1), QChar()); |
|
2493 |
QCOMPARE(doc.characterAt(length), QChar()); |
|
2494 |
QCOMPARE(doc.characterAt(length + 1), QChar()); |
|
2495 |
for (int i = 0; i < text.length(); ++i) { |
|
2496 |
QChar c = text.at(i); |
|
2497 |
if (c == QLatin1Char('\n')) |
|
2498 |
c = QChar(QChar::ParagraphSeparator); |
|
2499 |
QCOMPARE(doc.characterAt(i), c); |
|
2500 |
} |
|
2501 |
} |
|
2502 |
||
2503 |
void tst_QTextDocument::revisions() |
|
2504 |
{ |
|
2505 |
QTextDocument doc; |
|
2506 |
QTextCursor cursor(&doc); |
|
2507 |
QString text("Hello World"); |
|
2508 |
QCOMPARE(doc.firstBlock().revision(), 0); |
|
2509 |
cursor.insertText(text); |
|
2510 |
QCOMPARE(doc.firstBlock().revision(), 1); |
|
2511 |
cursor.setPosition(6); |
|
2512 |
cursor.insertBlock(); |
|
2513 |
QCOMPARE(cursor.block().previous().revision(), 2); |
|
2514 |
QCOMPARE(cursor.block().revision(), 2); |
|
2515 |
cursor.insertText("candle"); |
|
2516 |
QCOMPARE(cursor.block().revision(), 3); |
|
2517 |
cursor.movePosition(QTextCursor::EndOfBlock); |
|
2518 |
cursor.insertBlock(); // we are at the block end |
|
2519 |
QCOMPARE(cursor.block().previous().revision(), 3); |
|
2520 |
QCOMPARE(cursor.block().revision(), 4); |
|
2521 |
cursor.insertText("lightbulb"); |
|
2522 |
QCOMPARE(cursor.block().revision(), 5); |
|
2523 |
cursor.movePosition(QTextCursor::StartOfBlock); |
|
2524 |
cursor.insertBlock(); // we are the block start |
|
2525 |
QCOMPARE(cursor.block().previous().revision(), 6); |
|
2526 |
QCOMPARE(cursor.block().revision(), 5); |
|
2527 |
} |
|
2528 |
||
2529 |
void tst_QTextDocument::revisionWithUndoCompressionAndUndo() |
|
2530 |
{ |
|
2531 |
QTextDocument doc; |
|
2532 |
QTextCursor cursor(&doc); |
|
2533 |
cursor.insertText("This is the beginning of it all."); |
|
2534 |
QCOMPARE(doc.firstBlock().revision(), 1); |
|
2535 |
QCOMPARE(doc.revision(), 1); |
|
2536 |
cursor.insertBlock(); |
|
2537 |
QCOMPARE(doc.revision(), 2); |
|
2538 |
cursor.insertText("this"); |
|
2539 |
QCOMPARE(doc.revision(), 3); |
|
2540 |
cursor.insertText("is"); |
|
2541 |
QCOMPARE(doc.revision(), 4); |
|
2542 |
cursor.insertText("compressed"); |
|
2543 |
QCOMPARE(doc.revision(), 5); |
|
2544 |
doc.undo(); |
|
2545 |
QCOMPARE(doc.revision(), 6); |
|
2546 |
QCOMPARE(doc.toPlainText(), QString("This is the beginning of it all.\n")) ; |
|
2547 |
cursor.setPosition(0); |
|
2548 |
QCOMPARE(doc.firstBlock().revision(), 1); |
|
2549 |
cursor.insertText("Very beginnig"); |
|
2550 |
QCOMPARE(doc.firstBlock().revision(), 7); |
|
2551 |
doc.undo(); |
|
2552 |
QCOMPARE(doc.revision(), 8); |
|
2553 |
QCOMPARE(doc.firstBlock().revision(), 1); |
|
2554 |
||
2555 |
cursor.beginEditBlock(); |
|
2556 |
cursor.insertText("Hello"); |
|
2557 |
cursor.insertBlock(); |
|
2558 |
cursor.insertText("world"); |
|
2559 |
cursor.endEditBlock(); |
|
2560 |
QCOMPARE(doc.revision(), 9); |
|
2561 |
doc.undo(); |
|
2562 |
QCOMPARE(doc.revision(), 10); |
|
2563 |
||
2564 |
||
2565 |
} |
|
2566 |
||
2567 |
void tst_QTextDocument::testUndoCommandAdded() |
|
2568 |
{ |
|
2569 |
QVERIFY(doc); |
|
2570 |
QSignalSpy spy(doc, SIGNAL(undoCommandAdded())); |
|
2571 |
QVERIFY(spy.isValid()); |
|
2572 |
QVERIFY(spy.isEmpty()); |
|
2573 |
||
2574 |
cursor.insertText("a"); |
|
2575 |
QCOMPARE(spy.count(), 1); |
|
2576 |
cursor.insertText("b"); // should be merged |
|
2577 |
QCOMPARE(spy.count(), 1); |
|
2578 |
cursor.insertText("c"); // should be merged |
|
2579 |
QCOMPARE(spy.count(), 1); |
|
2580 |
QCOMPARE(doc->toPlainText(), QString("abc")); |
|
2581 |
doc->undo(); |
|
2582 |
QCOMPARE(doc->toPlainText(), QString("")); |
|
2583 |
||
2584 |
doc->clear(); |
|
2585 |
spy.clear(); |
|
2586 |
cursor.insertText("aaa"); |
|
2587 |
QCOMPARE(spy.count(), 1); |
|
2588 |
||
2589 |
spy.clear(); |
|
2590 |
cursor.insertText("aaaa\nbcd"); |
|
2591 |
QCOMPARE(spy.count(), 1); |
|
2592 |
||
2593 |
spy.clear(); |
|
2594 |
cursor.beginEditBlock(); |
|
2595 |
cursor.insertText("aa"); |
|
2596 |
cursor.insertText("bbb\n"); |
|
2597 |
cursor.setCharFormat(QTextCharFormat()); |
|
2598 |
cursor.insertText("\nccc"); |
|
2599 |
QVERIFY(spy.isEmpty()); |
|
2600 |
cursor.endEditBlock(); |
|
2601 |
QCOMPARE(spy.count(), 1); |
|
2602 |
||
2603 |
spy.clear(); |
|
2604 |
cursor.insertBlock(); |
|
2605 |
QCOMPARE(spy.count(), 1); |
|
2606 |
||
2607 |
spy.clear(); |
|
2608 |
cursor.setPosition(5); |
|
2609 |
QVERIFY(spy.isEmpty()); |
|
2610 |
cursor.setCharFormat(QTextCharFormat()); |
|
2611 |
QVERIFY(spy.isEmpty()); |
|
2612 |
cursor.setPosition(10, QTextCursor::KeepAnchor); |
|
2613 |
QVERIFY(spy.isEmpty()); |
|
2614 |
QTextCharFormat cf; |
|
2615 |
cf.setFontItalic(true); |
|
2616 |
cursor.mergeCharFormat(cf); |
|
2617 |
QCOMPARE(spy.count(), 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2618 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2619 |
spy.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2620 |
doc->undo(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2621 |
QCOMPARE(spy.count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2622 |
doc->undo(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2623 |
QCOMPARE(spy.count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2624 |
spy.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2625 |
doc->redo(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2626 |
QCOMPARE(spy.count(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2627 |
doc->redo(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2628 |
QCOMPARE(spy.count(), 0); |
0 | 2629 |
} |
2630 |
||
2631 |
void tst_QTextDocument::testUndoBlocks() |
|
2632 |
{ |
|
2633 |
QVERIFY(doc); |
|
2634 |
cursor.insertText("Hello World"); |
|
2635 |
cursor.insertText("period"); |
|
2636 |
doc->undo(); |
|
2637 |
QCOMPARE(doc->toPlainText(), QString("")); |
|
2638 |
cursor.insertText("Hello World"); |
|
2639 |
cursor.insertText("One\nTwo\nThree"); |
|
2640 |
QCOMPARE(doc->toPlainText(), QString("Hello WorldOne\nTwo\nThree")); |
|
2641 |
doc->undo(); |
|
2642 |
QCOMPARE(doc->toPlainText(), QString("Hello World")); |
|
2643 |
cursor.insertText("One\nTwo\nThree"); |
|
2644 |
cursor.insertText("Trailing text"); |
|
2645 |
doc->undo(); |
|
2646 |
QCOMPARE(doc->toPlainText(), QString("Hello WorldOne\nTwo\nThree")); |
|
2647 |
doc->undo(); |
|
2648 |
QCOMPARE(doc->toPlainText(), QString("Hello World")); |
|
2649 |
doc->undo(); |
|
2650 |
QCOMPARE(doc->toPlainText(), QString("")); |
|
2651 |
||
2652 |
cursor.insertText("quod"); |
|
2653 |
cursor.beginEditBlock(); |
|
2654 |
cursor.insertText(" erat"); |
|
2655 |
cursor.endEditBlock(); |
|
2656 |
cursor.insertText(" demonstrandum"); |
|
2657 |
QCOMPARE(doc->toPlainText(), QString("quod erat demonstrandum")); |
|
2658 |
doc->undo(); |
|
2659 |
QCOMPARE(doc->toPlainText(), QString("quod erat")); |
|
2660 |
doc->undo(); |
|
2661 |
QCOMPARE(doc->toPlainText(), QString("quod")); |
|
2662 |
doc->undo(); |
|
2663 |
QCOMPARE(doc->toPlainText(), QString("")); |
|
2664 |
} |
|
2665 |
||
2666 |
class Receiver : public QObject |
|
2667 |
{ |
|
2668 |
Q_OBJECT |
|
2669 |
public: |
|
2670 |
QString first; |
|
2671 |
public slots: |
|
2672 |
void cursorPositionChanged() { |
|
2673 |
if (first.isEmpty()) |
|
2674 |
first = QLatin1String("cursorPositionChanged"); |
|
2675 |
} |
|
2676 |
||
2677 |
void contentsChange() { |
|
2678 |
if (first.isEmpty()) |
|
2679 |
first = QLatin1String("contentsChanged"); |
|
2680 |
} |
|
2681 |
}; |
|
2682 |
||
2683 |
void tst_QTextDocument::receiveCursorPositionChangedAfterContentsChange() |
|
2684 |
{ |
|
2685 |
QVERIFY(doc); |
|
2686 |
doc->setDocumentLayout(new MyAbstractTextDocumentLayout(doc)); |
|
2687 |
Receiver rec; |
|
2688 |
connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), |
|
2689 |
&rec, SLOT(cursorPositionChanged())); |
|
2690 |
connect(doc, SIGNAL(contentsChange(int,int,int)), |
|
2691 |
&rec, SLOT(contentsChange())); |
|
2692 |
cursor.insertText("Hello World"); |
|
2693 |
QCOMPARE(rec.first, QString("contentsChanged")); |
|
2694 |
} |
|
2695 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2696 |
void tst_QTextDocument::escape_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2697 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2698 |
QTest::addColumn<QString>("original"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2699 |
QTest::addColumn<QString>("expected"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2700 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2701 |
QTest::newRow("1") << "Hello World\n" << "Hello World\n"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2702 |
QTest::newRow("2") << "#include <QtCore>" << "#include <QtCore>"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2703 |
QTest::newRow("3") << "<p class=\"cool\"><a href=\"http://example.com/?foo=bar&bar=foo\">plop --> </a></p>" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2704 |
<< "<p class="cool"><a href="http://example.com/?foo=bar&amp;bar=foo">plop --&gt; </a></p>"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2705 |
QTest::newRow("4") << QString::fromUtf8("<\320\222\321\201>") << QString::fromUtf8("<\320\222\321\201>"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2706 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2707 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2708 |
void tst_QTextDocument::escape() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2709 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2710 |
QFETCH(QString, original); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2711 |
QFETCH(QString, expected); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2712 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2713 |
QCOMPARE(Qt::escape(original), expected); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2714 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2715 |
|
0 | 2716 |
QTEST_MAIN(tst_QTextDocument) |
2717 |
#include "tst_qtextdocument.moc" |