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

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPlainTextEdit&amp;diff=1190&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPlainTextEdit&amp;diff=1190&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://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPlainTextEdit&amp;diff=1191&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QPlainTextEdit&amp;diff=1191&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:05Z</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;==Code editor==&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 CODEEDITOR_H&lt;br /&gt;
#define CODEEDITOR_H&lt;br /&gt;
#include &amp;lt;QPlainTextEdit&amp;gt;&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
QT_BEGIN_NAMESPACE&lt;br /&gt;
class QPaintEvent;&lt;br /&gt;
class QResizeEvent;&lt;br /&gt;
class QSize;&lt;br /&gt;
class QWidget;&lt;br /&gt;
QT_END_NAMESPACE&lt;br /&gt;
class LineNumberArea;&lt;br /&gt;
//![codeeditordefinition]&lt;br /&gt;
class CodeEditor : public QPlainTextEdit&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    CodeEditor(QWidget *parent = 0);&lt;br /&gt;
    void lineNumberAreaPaintEvent(QPaintEvent *event);&lt;br /&gt;
    int lineNumberAreaWidth();&lt;br /&gt;
protected:&lt;br /&gt;
    void resizeEvent(QResizeEvent *event);&lt;br /&gt;
private slots:&lt;br /&gt;
    void updateLineNumberAreaWidth(int newBlockCount);&lt;br /&gt;
    void highlightCurrentLine();&lt;br /&gt;
    void updateLineNumberArea(const QRect &amp;amp;, int);&lt;br /&gt;
private:&lt;br /&gt;
    QWidget *lineNumberArea;&lt;br /&gt;
};&lt;br /&gt;
//![codeeditordefinition]&lt;br /&gt;
//![extraarea]&lt;br /&gt;
class LineNumberArea : public QWidget&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    LineNumberArea(CodeEditor *editor) : QWidget(editor) {&lt;br /&gt;
        codeEditor = editor;&lt;br /&gt;
    }&lt;br /&gt;
    QSize sizeHint() const {&lt;br /&gt;
        return QSize(codeEditor-&amp;gt;lineNumberAreaWidth(), 0);&lt;br /&gt;
    }&lt;br /&gt;
protected:&lt;br /&gt;
    void paintEvent(QPaintEvent *event) {&lt;br /&gt;
        codeEditor-&amp;gt;lineNumberAreaPaintEvent(event);&lt;br /&gt;
    }&lt;br /&gt;
private:&lt;br /&gt;
    CodeEditor *codeEditor;&lt;br /&gt;
};&lt;br /&gt;
//![extraarea]&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;codeeditor.h&amp;quot;&lt;br /&gt;
//![constructor]&lt;br /&gt;
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)&lt;br /&gt;
{&lt;br /&gt;
    lineNumberArea = new LineNumberArea(this);&lt;br /&gt;
    connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));&lt;br /&gt;
    connect(this, SIGNAL(updateRequest(const QRect &amp;amp;, int)), this, SLOT(updateLineNumberArea(const QRect &amp;amp;, int)));&lt;br /&gt;
    connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));&lt;br /&gt;
    updateLineNumberAreaWidth(0);&lt;br /&gt;
    highlightCurrentLine();&lt;br /&gt;
}&lt;br /&gt;
//![constructor]&lt;br /&gt;
//![extraAreaWidth]&lt;br /&gt;
int CodeEditor::lineNumberAreaWidth()&lt;br /&gt;
{&lt;br /&gt;
    int digits = 1;&lt;br /&gt;
    int max = qMax(1, blockCount());&lt;br /&gt;
    while (max &amp;gt;= 10) {&lt;br /&gt;
        max /= 10;&lt;br /&gt;
        ++digits;&lt;br /&gt;
    }&lt;br /&gt;
    int space = 3 + fontMetrics().width(QLatin1Char(&amp;quot;9&amp;quot;)) * digits;&lt;br /&gt;
    return space;&lt;br /&gt;
}&lt;br /&gt;
//![extraAreaWidth]&lt;br /&gt;
//![slotUpdateExtraAreaWidth]&lt;br /&gt;
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)&lt;br /&gt;
{ &lt;br /&gt;
    setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);&lt;br /&gt;
}&lt;br /&gt;
//![slotUpdateExtraAreaWidth]&lt;br /&gt;
//![slotUpdateRequest]&lt;br /&gt;
void CodeEditor::updateLineNumberArea(const QRect &amp;amp;rect, int dy)&lt;br /&gt;
{&lt;br /&gt;
    if (dy)&lt;br /&gt;
        lineNumberArea-&amp;gt;scroll(0, dy);&lt;br /&gt;
    else&lt;br /&gt;
        lineNumberArea-&amp;gt;update(0, rect.y(), lineNumberArea-&amp;gt;width(), rect.height());&lt;br /&gt;
    if (rect.contains(viewport()-&amp;gt;rect()))&lt;br /&gt;
        updateLineNumberAreaWidth(0);&lt;br /&gt;
}&lt;br /&gt;
//![slotUpdateRequest]&lt;br /&gt;
//![resizeEvent]&lt;br /&gt;
void CodeEditor::resizeEvent(QResizeEvent *e)&lt;br /&gt;
{&lt;br /&gt;
    QPlainTextEdit::resizeEvent(e);&lt;br /&gt;
    QRect cr = contentsRect();&lt;br /&gt;
    lineNumberArea-&amp;gt;setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));&lt;br /&gt;
}&lt;br /&gt;
//![resizeEvent]&lt;br /&gt;
//![cursorPositionChanged]&lt;br /&gt;
void CodeEditor::highlightCurrentLine()&lt;br /&gt;
{&lt;br /&gt;
    QList&amp;lt;QTextEdit::ExtraSelection&amp;gt; extraSelections;&lt;br /&gt;
    if (!isReadOnly()) {&lt;br /&gt;
        QTextEdit::ExtraSelection selection;&lt;br /&gt;
        &lt;br /&gt;
        QColor lineColor = QColor(Qt::yellow).lighter(160);&lt;br /&gt;
        selection.format.setBackground(lineColor);&lt;br /&gt;
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);&lt;br /&gt;
        selection.cursor = textCursor();&lt;br /&gt;
        selection.cursor.clearSelection();&lt;br /&gt;
        extraSelections.append(selection);&lt;br /&gt;
    }&lt;br /&gt;
    setExtraSelections(extraSelections);&lt;br /&gt;
}&lt;br /&gt;
//![cursorPositionChanged]&lt;br /&gt;
//![extraAreaPaintEvent_0]&lt;br /&gt;
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)&lt;br /&gt;
{&lt;br /&gt;
    QPainter painter(lineNumberArea);&lt;br /&gt;
    painter.fillRect(event-&amp;gt;rect(), Qt::lightGray);&lt;br /&gt;
//![extraAreaPaintEvent_0]&lt;br /&gt;
//![extraAreaPaintEvent_1]&lt;br /&gt;
    QTextBlock block = firstVisibleBlock();&lt;br /&gt;
    int blockNumber = block.blockNumber();&lt;br /&gt;
    int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();&lt;br /&gt;
    int bottom = top + (int) blockBoundingRect(block).height();&lt;br /&gt;
//![extraAreaPaintEvent_1]&lt;br /&gt;
//![extraAreaPaintEvent_2]&lt;br /&gt;
    while (block.isValid() &amp;amp;&amp;amp; top &amp;lt;= event-&amp;gt;rect().bottom()) {&lt;br /&gt;
        if (block.isVisible() &amp;amp;&amp;amp; bottom &amp;gt;= event-&amp;gt;rect().top()) {&lt;br /&gt;
            QString number = QString::number(blockNumber + 1);&lt;br /&gt;
            painter.setPen(Qt::black);&lt;br /&gt;
            painter.drawText(0, top, lineNumberArea-&amp;gt;width(), fontMetrics().height(),&lt;br /&gt;
                             Qt::AlignRight, number);&lt;br /&gt;
        }&lt;br /&gt;
        block = block.next();&lt;br /&gt;
        top = bottom;&lt;br /&gt;
        bottom = top + (int) blockBoundingRect(block).height();&lt;br /&gt;
        ++blockNumber;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
//![extraAreaPaintEvent_2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;codeeditor.h&amp;quot;&lt;br /&gt;
int main(int argv, char **args)&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argv, args);&lt;br /&gt;
    CodeEditor editor;&lt;br /&gt;
    editor.setWindowTitle(QObject::tr(&amp;quot;Code Editor Example&amp;quot;));&lt;br /&gt;
    editor.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>