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%2FQTextDocument</id>
		<title>C++/Qt/QTextDocument - История изменений</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%2FQTextDocument"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextDocument&amp;action=history"/>
		<updated>2026-04-17T18:37:26Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/Qt/QTextDocument&amp;diff=1144&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/QTextDocument&amp;diff=1144&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/QTextDocument&amp;diff=1145&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/QTextDocument&amp;diff=1145&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:57Z</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;==Adding resource to QTextDocument==&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;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
QString tr(const char *text)&lt;br /&gt;
{&lt;br /&gt;
    return QApplication::translate(text, text);&lt;br /&gt;
}&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    QTextEdit *editor = new QTextEdit;&lt;br /&gt;
    QTextDocument *document = new QTextDocument(editor);&lt;br /&gt;
    QTextCursor cursor(document);&lt;br /&gt;
    QImage image(64, 64, QImage::Format_RGB32);&lt;br /&gt;
    image.fill(qRgb(255, 160, 128));&lt;br /&gt;
//! [Adding a resource]&lt;br /&gt;
    document-&amp;gt;addResource(QTextDocument::ImageResource,&lt;br /&gt;
        QUrl(&amp;quot;mydata://image.png&amp;quot;), QVariant(image));&lt;br /&gt;
//! [Adding a resource]&lt;br /&gt;
//! [Inserting an image with a cursor]&lt;br /&gt;
    QTextImageFormat imageFormat;&lt;br /&gt;
    imageFormat.setName(&amp;quot;mydata://image.png&amp;quot;);&lt;br /&gt;
    cursor.insertImage(imageFormat);&lt;br /&gt;
//! [Inserting an image with a cursor]&lt;br /&gt;
    cursor.insertBlock();&lt;br /&gt;
    cursor.insertText(&amp;quot;Code less. Create more.&amp;quot;);&lt;br /&gt;
    editor-&amp;gt;setDocument(document);&lt;br /&gt;
    editor-&amp;gt;setWindowTitle(tr(&amp;quot;Text Document Images&amp;quot;));&lt;br /&gt;
    editor-&amp;gt;resize(320, 480);&lt;br /&gt;
    editor-&amp;gt;show();&lt;br /&gt;
//! [Inserting an image using HTML]&lt;br /&gt;
    editor-&amp;gt;append(&amp;quot;&amp;lt;img src=\&amp;quot;mydata://image.png\&amp;quot; /&amp;gt;&amp;quot;);&lt;br /&gt;
//! [Inserting an image using HTML]&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;
==Draw QTextDocument with QTextDocument==&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;
Foundations of Qt Development\Chapter07\text\main.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QPixmap&amp;gt;&lt;br /&gt;
#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;
#include &amp;lt;QTextDocument&amp;gt;&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QApplication app( argc, argv );&lt;br /&gt;
  QPixmap pixmap( 200, 330 );&lt;br /&gt;
  pixmap.fill( Qt::white );&lt;br /&gt;
  QPainter painter( &amp;amp;pixmap );&lt;br /&gt;
  painter.setPen( Qt::black );&lt;br /&gt;
    &lt;br /&gt;
  QPoint point = QPoint( 10, 20 );&lt;br /&gt;
  painter.drawText( point, &amp;quot;You can draw text from a point...&amp;quot; );&lt;br /&gt;
  painter.drawLine( point+QPoint(-5, 0), point+QPoint(5, 0) );&lt;br /&gt;
  painter.drawLine( point+QPoint(0, -5), point+QPoint(0, 5) );&lt;br /&gt;
  &lt;br /&gt;
  QRect rect = QRect(10, 30, 180, 20);&lt;br /&gt;
  painter.drawText( rect, Qt::AlignCenter, &lt;br /&gt;
                    &amp;quot;...or you can draw it inside a rectangle.&amp;quot; );&lt;br /&gt;
  painter.drawRect( rect );&lt;br /&gt;
  &lt;br /&gt;
  rect.translate( 0, 30 );&lt;br /&gt;
  &lt;br /&gt;
  QFont font = QApplication::font();&lt;br /&gt;
  font.setPixelSize( rect.height() );&lt;br /&gt;
  painter.setFont( font );&lt;br /&gt;
  &lt;br /&gt;
  painter.drawText( rect, Qt::AlignRight, &amp;quot;Right.&amp;quot; );&lt;br /&gt;
  painter.drawText( rect, Qt::AlignLeft, &amp;quot;Left.&amp;quot; );&lt;br /&gt;
  painter.drawRect( rect );&lt;br /&gt;
  &lt;br /&gt;
  rect.translate( 0, rect.height()+10 );&lt;br /&gt;
  rect.setHeight( QFontMetrics( font ).height() );&lt;br /&gt;
  painter.drawText( rect, Qt::AlignRight, &amp;quot;Right.&amp;quot; );&lt;br /&gt;
  painter.drawText( rect, Qt::AlignLeft, &amp;quot;Left.&amp;quot; );&lt;br /&gt;
  painter.drawRect( rect );&lt;br /&gt;
  &lt;br /&gt;
  QTextDocument doc;&lt;br /&gt;
  doc.setHtml( &amp;quot;&amp;lt;p&amp;gt;A QTextDocument can be used to present formatted text &amp;quot;&lt;br /&gt;
               &amp;quot;in a nice way.&amp;lt;/p&amp;gt;&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;lt;p align=center&amp;gt;It can be &amp;lt;b&amp;gt;formatted&amp;lt;/b&amp;gt; &amp;quot;&lt;br /&gt;
               &amp;quot;&amp;lt;font size=+2&amp;gt;in&amp;lt;/font&amp;gt; &amp;lt;i&amp;gt;different&amp;lt;/i&amp;gt; ways.&amp;lt;/p&amp;gt;&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;lt;p&amp;gt;The text can be really long and contain many &amp;quot;&lt;br /&gt;
               &amp;quot;paragraphs. It is properly wrapped and such...&amp;lt;/p&amp;gt;&amp;quot; );&lt;br /&gt;
  rect.translate( 0, rect.height()+10 );&lt;br /&gt;
  rect.setHeight( 160 );&lt;br /&gt;
  doc.setTextWidth( rect.width() );&lt;br /&gt;
  painter.save();&lt;br /&gt;
  painter.translate( rect.topLeft() );&lt;br /&gt;
  doc.drawContents( &amp;amp;painter, rect.translated( -rect.topLeft() ) );&lt;br /&gt;
  painter.restore();&lt;br /&gt;
  painter.drawRect( rect );&lt;br /&gt;
  rect.translate( 0, 160 );&lt;br /&gt;
  rect.setHeight( doc.size().height()-160 );&lt;br /&gt;
  painter.setBrush( Qt::gray );&lt;br /&gt;
  painter.drawRect( rect );&lt;br /&gt;
  pixmap.save( &amp;quot;text.png&amp;quot; );&lt;br /&gt;
  return 0;&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;
==Text document blocks==&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 createItems(QDomElement &amp;amp;parent, const QTextBlock &amp;amp;block);&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;
    QTextBlock firstBlock = textDocument-&amp;gt;begin();&lt;br /&gt;
    createItems(documentElement, firstBlock);&lt;br /&gt;
    return document;&lt;br /&gt;
}&lt;br /&gt;
void XmlWriter::createItems(QDomElement &amp;amp;parent, const QTextBlock &amp;amp;block)&lt;br /&gt;
{&lt;br /&gt;
    QTextBlock currentBlock = block;&lt;br /&gt;
    while (currentBlock.isValid()) {&lt;br /&gt;
        QDomElement blockElement = document-&amp;gt;createElement(&amp;quot;block&amp;quot;);&lt;br /&gt;
        blockElement.setAttribute(&amp;quot;length&amp;quot;, currentBlock.length());&lt;br /&gt;
        parent.appendChild(blockElement);&lt;br /&gt;
        if (!(currentBlock.text().isNull())) {&lt;br /&gt;
            QDomText textNode = document-&amp;gt;createTextNode(currentBlock.text());&lt;br /&gt;
            blockElement.appendChild(textNode);&lt;br /&gt;
        }&lt;br /&gt;
        currentBlock = currentBlock.next();&lt;br /&gt;
    }&lt;br /&gt;
}&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 insertCalendar();&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;
    QMenu *insertMenu = new QMenu(tr(&amp;quot;&amp;amp;Insert&amp;quot;));&lt;br /&gt;
    QAction *calendarAction = insertMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Calendar&amp;quot;));&lt;br /&gt;
    calendarAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+I&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(insertMenu);&lt;br /&gt;
&lt;br /&gt;
    editor = new QTextEdit(this);&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;
    connect(calendarAction, SIGNAL(triggered()), this, SLOT(insertCalendar()));&lt;br /&gt;
    setCentralWidget(editor);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Text Document Writer&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;
void MainWindow::insertCalendar()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor(editor-&amp;gt;textCursor());&lt;br /&gt;
    cursor.movePosition(QTextCursor::Start); &lt;br /&gt;
    QTextCharFormat format(cursor.charFormat());&lt;br /&gt;
    format.setFontFamily(&amp;quot;Courier&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    QTextCharFormat boldFormat = format;&lt;br /&gt;
    boldFormat.setFontWeight(QFont::Bold);&lt;br /&gt;
    cursor.insertBlock();&lt;br /&gt;
    cursor.insertText(&amp;quot; &amp;quot;, boldFormat);&lt;br /&gt;
    QDate date = QDate::currentDate();&lt;br /&gt;
    int year = date.year(), month = date.month();&lt;br /&gt;
    for (int weekDay = 1; weekDay &amp;lt;= 7; ++weekDay) {&lt;br /&gt;
        cursor.insertText(QString(&amp;quot;%1 &amp;quot;).arg(QDate::shortDayName(weekDay), 3),&lt;br /&gt;
            boldFormat);&lt;br /&gt;
    }&lt;br /&gt;
    cursor.insertBlock();&lt;br /&gt;
    cursor.insertText(&amp;quot; &amp;quot;, format);&lt;br /&gt;
    for (int column = 1; column &amp;lt; QDate(year, month, 1).dayOfWeek(); ++column) {&lt;br /&gt;
        cursor.insertText(&amp;quot;    &amp;quot;, format);&lt;br /&gt;
    }&lt;br /&gt;
    for (int day = 1; day &amp;lt;= date.daysInMonth(); ++day) {&lt;br /&gt;
 &lt;br /&gt;
        int weekDay = QDate(year, month, day).dayOfWeek();&lt;br /&gt;
        if (QDate(year, month, day) == date)&lt;br /&gt;
            cursor.insertText(QString(&amp;quot;%1 &amp;quot;).arg(day, 3), boldFormat);&lt;br /&gt;
        else&lt;br /&gt;
            cursor.insertText(QString(&amp;quot;%1 &amp;quot;).arg(day, 3), format);&lt;br /&gt;
        if (weekDay == 7) {&lt;br /&gt;
            cursor.insertBlock();&lt;br /&gt;
            cursor.insertText(&amp;quot; &amp;quot;, format);&lt;br /&gt;
        }&lt;br /&gt;
 &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(640, 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;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Text document selection==&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 WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
#include &amp;lt;QTextDocumentFragment&amp;gt;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QTextDocument;&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 cutSelection();&lt;br /&gt;
    void copySelection();&lt;br /&gt;
    void openFile();&lt;br /&gt;
    void pasteSelection();&lt;br /&gt;
    void selectWord();&lt;br /&gt;
    void selectLine();&lt;br /&gt;
    void selectBlock();&lt;br /&gt;
    void selectFrame();&lt;br /&gt;
    void updateMenus();&lt;br /&gt;
private:&lt;br /&gt;
    QAction *cutAction;&lt;br /&gt;
    QAction *copyAction;&lt;br /&gt;
    QAction *pasteAction;&lt;br /&gt;
    QString currentFile;&lt;br /&gt;
    QTextEdit *editor;&lt;br /&gt;
    QTextDocument *document;&lt;br /&gt;
    QTextDocumentFragment selection;&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;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    fileMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Open...&amp;quot;), this, SLOT(openFile()),&lt;br /&gt;
                        QKeySequence(tr(&amp;quot;Ctrl+O&amp;quot;, &amp;quot;File|Open&amp;quot;)));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;), this, SLOT(close()));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    QMenu *editMenu = new QMenu(tr(&amp;quot;&amp;amp;Edit&amp;quot;));&lt;br /&gt;
    cutAction = editMenu-&amp;gt;addAction(tr(&amp;quot;Cu&amp;amp;t&amp;quot;), this, SLOT(cutSelection()));&lt;br /&gt;
    cutAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+X&amp;quot;));&lt;br /&gt;
    cutAction-&amp;gt;setEnabled(false);&lt;br /&gt;
    copyAction = editMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Copy&amp;quot;), this, SLOT(copySelection()));&lt;br /&gt;
    copyAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+C&amp;quot;));&lt;br /&gt;
    copyAction-&amp;gt;setEnabled(false);&lt;br /&gt;
    pasteAction = editMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Paste&amp;quot;), this, SLOT(pasteSelection()));&lt;br /&gt;
    pasteAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+V&amp;quot;));&lt;br /&gt;
    pasteAction-&amp;gt;setEnabled(false);&lt;br /&gt;
    QMenu *selectMenu = new QMenu(tr(&amp;quot;&amp;amp;Select&amp;quot;));&lt;br /&gt;
    selectMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Word&amp;quot;), this, SLOT(selectWord()));&lt;br /&gt;
    selectMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Line&amp;quot;), this, SLOT(selectLine()));&lt;br /&gt;
    selectMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Block&amp;quot;), this, SLOT(selectBlock()));&lt;br /&gt;
    selectMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Frame&amp;quot;), this, SLOT(selectFrame()));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(editMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(selectMenu);&lt;br /&gt;
    editor = new QTextEdit(this);&lt;br /&gt;
    document = new QTextDocument(this);&lt;br /&gt;
    editor-&amp;gt;setDocument(document);&lt;br /&gt;
    connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus()));&lt;br /&gt;
    setCentralWidget(editor);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Text Document Writer&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::openFile()&lt;br /&gt;
{&lt;br /&gt;
    QString fileName = QFileDialog::getOpenFileName(this,&lt;br /&gt;
        tr(&amp;quot;Open file&amp;quot;), currentFile, &amp;quot;HTML files (*.html);;Text files (*.txt)&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    if (!fileName.isEmpty()) {&lt;br /&gt;
        QFileInfo info(fileName);&lt;br /&gt;
        if (info.completeSuffix() == &amp;quot;html&amp;quot;) {&lt;br /&gt;
            QFile file(fileName);&lt;br /&gt;
            &lt;br /&gt;
            if (file.open(QFile::ReadOnly)) {&lt;br /&gt;
                editor-&amp;gt;setHtml(QString(file.readAll()));&lt;br /&gt;
                file.close();&lt;br /&gt;
                currentFile = fileName;&lt;br /&gt;
            }&lt;br /&gt;
        } else if (info.completeSuffix() == &amp;quot;txt&amp;quot;) {&lt;br /&gt;
            QFile file(fileName);&lt;br /&gt;
            &lt;br /&gt;
            if (file.open(QFile::ReadOnly)) {&lt;br /&gt;
                editor-&amp;gt;setPlainText(file.readAll());&lt;br /&gt;
                file.close();&lt;br /&gt;
                currentFile = fileName;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::cutSelection()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    if (cursor.hasSelection()) {&lt;br /&gt;
        selection = cursor.selection();&lt;br /&gt;
        cursor.removeSelectedText();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::copySelection()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    if (cursor.hasSelection()) {&lt;br /&gt;
        selection = cursor.selection();&lt;br /&gt;
        cursor.clearSelection();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::pasteSelection()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    cursor.insertFragment(selection);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::selectWord()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    QTextBlock block = cursor.block();&lt;br /&gt;
&lt;br /&gt;
    cursor.beginEditBlock();&lt;br /&gt;
    cursor.movePosition(QTextCursor::StartOfWord);&lt;br /&gt;
    cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);&lt;br /&gt;
    cursor.endEditBlock();&lt;br /&gt;
&lt;br /&gt;
    editor-&amp;gt;setTextCursor(cursor);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::selectLine()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    QTextBlock block = cursor.block();&lt;br /&gt;
    cursor.beginEditBlock();&lt;br /&gt;
    cursor.movePosition(QTextCursor::StartOfLine);&lt;br /&gt;
    cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);&lt;br /&gt;
    cursor.endEditBlock();&lt;br /&gt;
    editor-&amp;gt;setTextCursor(cursor);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::selectBlock()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    QTextBlock block = cursor.block();&lt;br /&gt;
    cursor.beginEditBlock();&lt;br /&gt;
    cursor.movePosition(QTextCursor::StartOfBlock);&lt;br /&gt;
    cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);&lt;br /&gt;
    cursor.endEditBlock();&lt;br /&gt;
    editor-&amp;gt;setTextCursor(cursor);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::selectFrame()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    QTextFrame *frame = cursor.currentFrame();&lt;br /&gt;
    cursor.beginEditBlock();&lt;br /&gt;
    cursor.setPosition(frame-&amp;gt;firstPosition());&lt;br /&gt;
    cursor.setPosition(frame-&amp;gt;lastPosition(), QTextCursor::KeepAnchor);&lt;br /&gt;
    cursor.endEditBlock();&lt;br /&gt;
    editor-&amp;gt;setTextCursor(cursor);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::updateMenus()&lt;br /&gt;
{&lt;br /&gt;
    QTextCursor cursor = editor-&amp;gt;textCursor();&lt;br /&gt;
    cutAction-&amp;gt;setEnabled(cursor.hasSelection());&lt;br /&gt;
    copyAction-&amp;gt;setEnabled(cursor.hasSelection());&lt;br /&gt;
    pasteAction-&amp;gt;setEnabled(!selection.isEmpty());&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(640, 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>