git-svn-id: svn://db.shs.com.ru/libs@469 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
#include "qad_types.h"
|
||||
#include "ui_qcodeedit.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QTextCursor)
|
||||
|
||||
QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent) {
|
||||
qRegisterMetaType<QTextCursor>();
|
||||
ui = new Ui::QCodeEdit();
|
||||
ui->setupUi(this);
|
||||
ui->widgetSearch->hide();
|
||||
@@ -150,6 +152,31 @@ QTextDocument * QCodeEdit::document() const {
|
||||
}
|
||||
|
||||
|
||||
void QCodeEdit::setDocument(QTextDocument * doc) {
|
||||
if (document()) {
|
||||
document()->setProperty("_cursor", QVariant::fromValue(textCursor()));
|
||||
document()->setProperty("_vpos", textEdit()->verticalScrollBar()->value());
|
||||
}
|
||||
documentUnset();
|
||||
if (!doc) {
|
||||
ui->textCode->setDocument(0);
|
||||
documentChanged(0);
|
||||
return;
|
||||
}
|
||||
if (!qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()))
|
||||
doc->setDocumentLayout(new QPlainTextDocumentLayout(doc));
|
||||
ui->textCode->setDocument(doc);
|
||||
ui->textCode->setCursorWidth(qMax<int>(qRound(fontHeight() / 10.), 1));
|
||||
if (doc->property("_cursor").isValid()) {
|
||||
setTextCursor(doc->property("_cursor").value<QTextCursor>());
|
||||
textEdit()->verticalScrollBar()->setValue(doc->property("_vpos").toInt());
|
||||
}
|
||||
documentChanged(doc);
|
||||
doc->setDefaultFont(editorFont());
|
||||
updateLines();
|
||||
}
|
||||
|
||||
|
||||
void QCodeEdit::setTextCursor(const QTextCursor & c) {
|
||||
ui->textCode->setTextCursor(c);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user