A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQTextFrame</id>
		<title>C++/Qt/QTextFrame - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQTextFrame"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextFrame&amp;action=history"/>
		<updated>2026-04-17T11:59:39Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextFrame&amp;diff=1226&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextFrame&amp;diff=1226&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextFrame&amp;diff=1227&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextFrame&amp;diff=1227&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:13Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==QTextFrame based calendar==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef MAINWINDOW_H&lt;br /&gt;
#define MAINWINDOW_H&lt;br /&gt;
#include &amp;lt;QDate&amp;gt;&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QTextBrowser;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void setFontSize(int size);&lt;br /&gt;
    void setMonth(int month);&lt;br /&gt;
    void setYear(QDate date);&lt;br /&gt;
private:&lt;br /&gt;
    void insertCalendar();&lt;br /&gt;
    int fontSize;&lt;br /&gt;
    QDate selectedDate;&lt;br /&gt;
    QTextBrowser *editor;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    selectedDate = QDate::currentDate();&lt;br /&gt;
    fontSize = 10;&lt;br /&gt;
    QWidget *centralWidget = new QWidget;&lt;br /&gt;
&lt;br /&gt;
    QLabel *dateLabel = new QLabel(tr(&amp;quot;Date:&amp;quot;));&lt;br /&gt;
    QComboBox *monthCombo = new QComboBox;&lt;br /&gt;
    for (int month = 1; month &amp;lt;= 12; ++month)&lt;br /&gt;
        monthCombo-&amp;gt;addItem(QDate::longMonthName(month));&lt;br /&gt;
    QDateTimeEdit *yearEdit = new QDateTimeEdit;&lt;br /&gt;
    yearEdit-&amp;gt;setDisplayFormat(&amp;quot;yyyy&amp;quot;);&lt;br /&gt;
    yearEdit-&amp;gt;setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));&lt;br /&gt;
&lt;br /&gt;
    monthCombo-&amp;gt;setCurrentIndex(selectedDate.month() - 1);&lt;br /&gt;
    yearEdit-&amp;gt;setDate(selectedDate);&lt;br /&gt;
&lt;br /&gt;
    QLabel *fontSizeLabel = new QLabel(tr(&amp;quot;Font size:&amp;quot;));&lt;br /&gt;
    QSpinBox *fontSizeSpinBox = new QSpinBox;&lt;br /&gt;
    fontSizeSpinBox-&amp;gt;setRange(1, 64);&lt;br /&gt;
    fontSizeSpinBox-&amp;gt;setValue(10);&lt;br /&gt;
    editor = new QTextBrowser;&lt;br /&gt;
    insertCalendar();&lt;br /&gt;
&lt;br /&gt;
    connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));&lt;br /&gt;
    connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate)));&lt;br /&gt;
    connect(fontSizeSpinBox, SIGNAL(valueChanged(int)),&lt;br /&gt;
            this, SLOT(setFontSize(int)));&lt;br /&gt;
&lt;br /&gt;
    QHBoxLayout *controlsLayout = new QHBoxLayout;&lt;br /&gt;
    controlsLayout-&amp;gt;addWidget(dateLabel);&lt;br /&gt;
    controlsLayout-&amp;gt;addWidget(monthCombo);&lt;br /&gt;
    controlsLayout-&amp;gt;addWidget(yearEdit);&lt;br /&gt;
    controlsLayout-&amp;gt;addSpacing(24);&lt;br /&gt;
    controlsLayout-&amp;gt;addWidget(fontSizeLabel);&lt;br /&gt;
    controlsLayout-&amp;gt;addWidget(fontSizeSpinBox);&lt;br /&gt;
    controlsLayout-&amp;gt;addStretch(1);&lt;br /&gt;
    QVBoxLayout *centralLayout = new QVBoxLayout;&lt;br /&gt;
    centralLayout-&amp;gt;addLayout(controlsLayout);&lt;br /&gt;
    centralLayout-&amp;gt;addWidget(editor, 1);&lt;br /&gt;
    centralWidget-&amp;gt;setLayout(centralLayout);&lt;br /&gt;
    setCentralWidget(centralWidget);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MainWindow::insertCalendar()&lt;br /&gt;
{&lt;br /&gt;
    editor-&amp;gt;clear();&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    cursor.beginEditBlock();&lt;br /&gt;
    QDate date(selectedDate.year(), selectedDate.month(), 1);&lt;br /&gt;
&lt;br /&gt;
    QTextTableFormat tableFormat;&lt;br /&gt;
    tableFormat.setAlignment(Qt::AlignHCenter);&lt;br /&gt;
    tableFormat.setBackground(QColor(&amp;quot;#e0e0e0&amp;quot;));&lt;br /&gt;
    tableFormat.setCellPadding(2);&lt;br /&gt;
    tableFormat.setCellSpacing(4);&lt;br /&gt;
 &lt;br /&gt;
    QVector&amp;lt;QTextLength&amp;gt; constraints;&lt;br /&gt;
    constraints &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14)&lt;br /&gt;
                &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14)&lt;br /&gt;
                &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14)&lt;br /&gt;
                &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14)&lt;br /&gt;
                &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14)&lt;br /&gt;
                &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14)&lt;br /&gt;
                &amp;lt;&amp;lt; QTextLength(QTextLength::PercentageLength, 14);&lt;br /&gt;
    tableFormat.setColumnWidthConstraints(constraints);&lt;br /&gt;
&lt;br /&gt;
    QTextTable *table = cursor.insertTable(1, 7, tableFormat);&lt;br /&gt;
&lt;br /&gt;
    QTextFrame *frame = cursor.currentFrame();&lt;br /&gt;
    QTextFrameFormat frameFormat = frame-&amp;gt;frameFormat();&lt;br /&gt;
    frameFormat.setBorder(1);&lt;br /&gt;
    frame-&amp;gt;setFrameFormat(frameFormat);&lt;br /&gt;
&lt;br /&gt;
    QTextCharFormat format = cursor.charFormat();&lt;br /&gt;
    format.setFontPointSize(fontSize);&lt;br /&gt;
    QTextCharFormat boldFormat = format;&lt;br /&gt;
    boldFormat.setFontWeight(QFont::Bold);&lt;br /&gt;
    QTextCharFormat highlightedFormat = boldFormat;&lt;br /&gt;
    highlightedFormat.setBackground(Qt::yellow);&lt;br /&gt;
&lt;br /&gt;
    for (int weekDay = 1; weekDay &amp;lt;= 7; ++weekDay) {&lt;br /&gt;
        QTextTableCell cell = table-&amp;gt;cellAt(0, weekDay-1);&lt;br /&gt;
 &lt;br /&gt;
        QTextCursor cellCursor = cell.firstCursorPosition();&lt;br /&gt;
        cellCursor.insertText(QString(&amp;quot;%1&amp;quot;).arg(QDate::longDayName(weekDay)),&lt;br /&gt;
                              boldFormat);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    table-&amp;gt;insertRows(table-&amp;gt;rows(), 1);&lt;br /&gt;
&lt;br /&gt;
    while (date.month() == selectedDate.month()) {&lt;br /&gt;
        int weekDay = date.dayOfWeek();&lt;br /&gt;
        QTextTableCell cell = table-&amp;gt;cellAt(table-&amp;gt;rows()-1, weekDay-1);&lt;br /&gt;
        QTextCursor cellCursor = cell.firstCursorPosition();&lt;br /&gt;
        if (date == QDate::currentDate())&lt;br /&gt;
            cellCursor.insertText(QString(&amp;quot;%1&amp;quot;).arg(date.day()), highlightedFormat);&lt;br /&gt;
        else&lt;br /&gt;
            cellCursor.insertText(QString(&amp;quot;%1&amp;quot;).arg(date.day()), format);&lt;br /&gt;
        date = date.addDays(1);&lt;br /&gt;
        if (weekDay == 7 &amp;amp;&amp;amp; date.month() == selectedDate.month())&lt;br /&gt;
            table-&amp;gt;insertRows(table-&amp;gt;rows(), 1);&lt;br /&gt;
    }&lt;br /&gt;
    cursor.endEditBlock();&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Calendar for %1 %2&amp;quot;&lt;br /&gt;
        ).arg(QDate::longMonthName(selectedDate.month())&lt;br /&gt;
        ).arg(selectedDate.year()));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MainWindow::setFontSize(int size)&lt;br /&gt;
{&lt;br /&gt;
    fontSize = size;&lt;br /&gt;
    insertCalendar();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MainWindow::setMonth(int month)&lt;br /&gt;
{&lt;br /&gt;
    selectedDate = QDate(selectedDate.year(), month + 1, selectedDate.day());&lt;br /&gt;
    insertCalendar();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MainWindow::setYear(QDate date)&lt;br /&gt;
{&lt;br /&gt;
    selectedDate = QDate(date.year(), selectedDate.month(), selectedDate.day());&lt;br /&gt;
    insertCalendar();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow window;&lt;br /&gt;
    window.resize(640, 256);&lt;br /&gt;
    window.show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using QTextFrame==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef XMLWRITER_H&lt;br /&gt;
#define XMLWRITER_H&lt;br /&gt;
#include &amp;lt;QDomDocument&amp;gt;&lt;br /&gt;
class QTextDocument;&lt;br /&gt;
class XmlWriter&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    XmlWriter(QTextDocument *document) : textDocument(document) {}&lt;br /&gt;
    QDomDocument *toXml();&lt;br /&gt;
private:&lt;br /&gt;
    void processBlock(QDomElement &amp;amp;parent, const QTextBlock &amp;amp;block);&lt;br /&gt;
    void processFrame(QDomElement &amp;amp;parent, QTextFrame *frame);&lt;br /&gt;
    QDomDocument *document;&lt;br /&gt;
    QTextDocument *textDocument;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;xmlwriter.h&amp;quot;&lt;br /&gt;
QDomDocument *XmlWriter::toXml()&lt;br /&gt;
{&lt;br /&gt;
    QDomImplementation implementation;&lt;br /&gt;
    QDomDocumentType docType = implementation.createDocumentType(&lt;br /&gt;
        &amp;quot;scribe-document&amp;quot;, &amp;quot;scribe&amp;quot;, &amp;quot;qt,nokia.com/scribe&amp;quot;);&lt;br /&gt;
    document = new QDomDocument(docType);&lt;br /&gt;
    // ### This processing instruction is required to ensure that any kind&lt;br /&gt;
    // of encoding is given when the document is written.&lt;br /&gt;
    QDomProcessingInstruction process = document-&amp;gt;createProcessingInstruction(&lt;br /&gt;
        &amp;quot;xml&amp;quot;, &amp;quot;version=\&amp;quot;1.0\&amp;quot; encoding=\&amp;quot;utf-8\&amp;quot;&amp;quot;);&lt;br /&gt;
    document-&amp;gt;appendChild(process);&lt;br /&gt;
    QDomElement documentElement = document-&amp;gt;createElement(&amp;quot;document&amp;quot;);&lt;br /&gt;
    document-&amp;gt;appendChild(documentElement);&lt;br /&gt;
&lt;br /&gt;
    QTextFrame *root = textDocument-&amp;gt;rootFrame();&lt;br /&gt;
    &lt;br /&gt;
    if (root)&lt;br /&gt;
        processFrame(documentElement, root);&lt;br /&gt;
    return document;&lt;br /&gt;
}&lt;br /&gt;
void XmlWriter::processBlock(QDomElement &amp;amp;parent, const QTextBlock &amp;amp;block)&lt;br /&gt;
{&lt;br /&gt;
    QDomElement blockElement = document-&amp;gt;createElement(&amp;quot;block&amp;quot;);&lt;br /&gt;
    blockElement.setAttribute(&amp;quot;position&amp;quot;, block.position());&lt;br /&gt;
    blockElement.setAttribute(&amp;quot;length&amp;quot;, block.length());&lt;br /&gt;
    parent.appendChild(blockElement);&lt;br /&gt;
    QTextBlock::iterator it;&lt;br /&gt;
    for (it = block.begin(); !(it.atEnd()); ++it) {&lt;br /&gt;
        QTextFragment fragment = it.fragment();&lt;br /&gt;
        if (fragment.isValid()) {&lt;br /&gt;
            QDomElement fragmentElement = document-&amp;gt;createElement(&amp;quot;fragment&amp;quot;);&lt;br /&gt;
            blockElement.appendChild(fragmentElement);&lt;br /&gt;
            fragmentElement.setAttribute(&amp;quot;length&amp;quot;, fragment.length());&lt;br /&gt;
            QDomText fragmentText = document-&amp;gt;createTextNode(fragment.text());&lt;br /&gt;
            fragmentElement.appendChild(fragmentText);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void XmlWriter::processFrame(QDomElement &amp;amp;parent, QTextFrame *frame)&lt;br /&gt;
{&lt;br /&gt;
    QDomElement frameElement = document-&amp;gt;createElement(&amp;quot;frame&amp;quot;);&lt;br /&gt;
    frameElement.setAttribute(&amp;quot;begin&amp;quot;, frame-&amp;gt;firstPosition());&lt;br /&gt;
    frameElement.setAttribute(&amp;quot;end&amp;quot;, frame-&amp;gt;lastPosition());&lt;br /&gt;
    parent.appendChild(frameElement);&lt;br /&gt;
&lt;br /&gt;
    QTextFrame::iterator it;&lt;br /&gt;
    for (it = frame-&amp;gt;begin(); !(it.atEnd()); ++it) {&lt;br /&gt;
        QTextFrame *childFrame = it.currentFrame();&lt;br /&gt;
        QTextBlock childBlock = it.currentBlock();&lt;br /&gt;
        if (childFrame)&lt;br /&gt;
 &lt;br /&gt;
            processFrame(frameElement, childFrame);&lt;br /&gt;
        else if (childBlock.isValid())&lt;br /&gt;
            processBlock(frameElement, childBlock);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
class QTextEdit;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void saveFile();&lt;br /&gt;
private:&lt;br /&gt;
    bool writeXml(const QString &amp;amp;fileName);&lt;br /&gt;
    QTextEdit *editor;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
#include &amp;quot;xmlwriter.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    QAction *saveAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Save...&amp;quot;));&lt;br /&gt;
    saveAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+S&amp;quot;));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    editor = new QTextEdit();&lt;br /&gt;
    QTextCursor cursor(editor-&amp;gt;textCursor());&lt;br /&gt;
    cursor.movePosition(QTextCursor::Start); &lt;br /&gt;
    QTextFrame *mainFrame = cursor.currentFrame();&lt;br /&gt;
    &lt;br /&gt;
    QTextCharFormat plainCharFormat;&lt;br /&gt;
    QTextCharFormat boldCharFormat;&lt;br /&gt;
    boldCharFormat.setFontWeight(QFont::Bold);&lt;br /&gt;
/*  main frame&lt;br /&gt;
    QTextFrame *mainFrame = cursor.currentFrame();&lt;br /&gt;
    cursor.insertText(...);&lt;br /&gt;
*/&lt;br /&gt;
    cursor.insertText(&amp;quot;Text documents are represented by the &amp;quot;&lt;br /&gt;
                      &amp;quot;QTextDocument class, rather than by QString objects. &amp;quot;&lt;br /&gt;
                      &amp;quot;Each QTextDocument object contains information about &amp;quot;&lt;br /&gt;
                      &amp;quot;the document&amp;quot;s internal representation, its structure, &amp;quot;&lt;br /&gt;
                      &amp;quot;and keeps track of modifications to provide undo/redo &amp;quot;&lt;br /&gt;
                      &amp;quot;facilities. This approach allows features such as the &amp;quot;&lt;br /&gt;
                      &amp;quot;layout management to be delegated to specialized &amp;quot;&lt;br /&gt;
                      &amp;quot;classes, but also provides a focus for the framework.&amp;quot;,&lt;br /&gt;
                      plainCharFormat);&lt;br /&gt;
&lt;br /&gt;
    QTextFrameFormat frameFormat;&lt;br /&gt;
    frameFormat.setMargin(32);&lt;br /&gt;
    frameFormat.setPadding(8);&lt;br /&gt;
    frameFormat.setBorder(4);&lt;br /&gt;
    cursor.insertFrame(frameFormat);&lt;br /&gt;
/*  insert frame&lt;br /&gt;
    cursor.insertFrame(frameFormat);&lt;br /&gt;
    cursor.insertText(...);&lt;br /&gt;
*/&lt;br /&gt;
    cursor.insertText(&amp;quot;Documents are either converted from external sources &amp;quot;&lt;br /&gt;
                      &amp;quot;or created from scratch using Qt. The creation process &amp;quot;&lt;br /&gt;
                      &amp;quot;can done by an editor widget, such as QTextEdit, or by &amp;quot;&lt;br /&gt;
                      &amp;quot;explicit calls to the Scribe API.&amp;quot;, boldCharFormat);&lt;br /&gt;
    cursor = mainFrame-&amp;gt;lastCursorPosition();&lt;br /&gt;
/*  last cursor&lt;br /&gt;
    cursor = mainFrame-&amp;gt;lastCursorPosition();&lt;br /&gt;
    cursor.insertText(...);&lt;br /&gt;
*/&lt;br /&gt;
    cursor.insertText(&amp;quot;There are two complementary ways to visualize the &amp;quot;&lt;br /&gt;
                      &amp;quot;contents of a document: as a linear buffer that is &amp;quot;&lt;br /&gt;
                      &amp;quot;used by editors to modify the contents, and as an &amp;quot;&lt;br /&gt;
                      &amp;quot;object hierarchy containing structural information &amp;quot;&lt;br /&gt;
                      &amp;quot;that is useful to layout engines. In the hierarchical &amp;quot;&lt;br /&gt;
                      &amp;quot;model, the objects generally correspond to visual &amp;quot;&lt;br /&gt;
                      &amp;quot;elements such as frames, tables, and lists. At a lower &amp;quot;&lt;br /&gt;
                      &amp;quot;level, these elements describe properties such as the &amp;quot;&lt;br /&gt;
                      &amp;quot;style of text used and its alignment. The linear &amp;quot;&lt;br /&gt;
                      &amp;quot;representation of the document is used for editing and &amp;quot;&lt;br /&gt;
                      &amp;quot;manipulation of the document&amp;quot;s contents.&amp;quot;,&lt;br /&gt;
                      plainCharFormat);&lt;br /&gt;
&lt;br /&gt;
    connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));&lt;br /&gt;
    setCentralWidget(editor);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Text Document Frames&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::saveFile()&lt;br /&gt;
{&lt;br /&gt;
    QString fileName = QFileDialog::getSaveFileName(this,&lt;br /&gt;
        tr(&amp;quot;Save document as:&amp;quot;), &amp;quot;&amp;quot;, tr(&amp;quot;XML (*.xml)&amp;quot;));&lt;br /&gt;
    if (!fileName.isEmpty()) {&lt;br /&gt;
        if (writeXml(fileName))&lt;br /&gt;
            setWindowTitle(fileName);&lt;br /&gt;
        else&lt;br /&gt;
            QMessageBox::warning(this, tr(&amp;quot;Warning&amp;quot;),&lt;br /&gt;
                tr(&amp;quot;Failed to save the document.&amp;quot;), QMessageBox::Cancel,&lt;br /&gt;
                QMessageBox::NoButton);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
bool MainWindow::writeXml(const QString &amp;amp;fileName)&lt;br /&gt;
{&lt;br /&gt;
    XmlWriter documentWriter(editor-&amp;gt;document());&lt;br /&gt;
    QDomDocument *domDocument = documentWriter.toXml();&lt;br /&gt;
    QFile file(fileName);&lt;br /&gt;
    if (file.open(QFile::WriteOnly)) {&lt;br /&gt;
        QTextStream textStream(&amp;amp;file);&lt;br /&gt;
        textStream.setCodec(QTextCodec::codecForName(&amp;quot;UTF-8&amp;quot;));&lt;br /&gt;
        &lt;br /&gt;
        textStream &amp;lt;&amp;lt; domDocument-&amp;gt;toString(1).toUtf8();&lt;br /&gt;
        file.close();&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
        return false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;resize(480, 480);&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>