~ubuntu-branches/ubuntu/vivid/regina-normal/vivid

« back to all changes in this revision

Viewing changes to qtui/src/packettypes/ntextui.cpp

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2014-08-29 17:37:46 UTC
  • mfrom: (19.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140829173746-igmqc9b67y366a7u
Tags: 4.96-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *  Regina - A Normal Surface Theory Calculator                           *
5
5
 *  KDE User Interface                                                    *
6
6
 *                                                                        *
7
 
 *  Copyright (c) 1999-2013, Ben Burton                                   *
 
7
 *  Copyright (c) 1999-2014, Ben Burton                                   *
8
8
 *  For further details contact Ben Burton (bab@debian.org).              *
9
9
 *                                                                        *
10
10
 *  This program is free software; you can redistribute it and/or         *
37
37
 
38
38
// UI includes:
39
39
#include "bigwidget.h"
 
40
#include "docwidget.h"
40
41
#include "packeteditiface.h"
41
42
#include "ntextui.h"
42
43
 
54
55
    QBoxLayout* layout = new QVBoxLayout(ui);
55
56
    layout->setContentsMargins(0, 0, 0, 0);
56
57
 
57
 
    document = new QPlainTextEdit(enclosingPane);
58
 
    document->setReadOnly(!enclosingPane->isReadWrite());
59
 
    document->setLineWrapMode(QPlainTextEdit::WidgetWidth);
60
 
    editIface = new PacketEditTextEditor(document);
61
 
    layout->addWidget(document, 1);
 
58
    editWidget = new DocWidget<NText>(text, enclosingPane);
 
59
    editWidget->setReadOnly(!enclosingPane->isReadWrite());
 
60
    editWidget->setLineWrapMode(QPlainTextEdit::WidgetWidth);
 
61
    editIface = new PacketEditTextEditor(editWidget);
 
62
    layout->addWidget(editWidget, 1);
62
63
 
63
64
    refresh();
64
 
 
65
 
    connect(document, SIGNAL(textChanged()),
66
 
        this, SLOT(notifyTextChanged()));
67
65
}
68
66
 
69
67
NTextUI::~NTextUI() {
83
81
    return tr("Te&xt");
84
82
}
85
83
 
86
 
void NTextUI::commit() {
87
 
    text->setText(document->toPlainText().toAscii().constData());
88
 
    setDirty(false);
89
 
}
90
 
 
91
84
void NTextUI::refresh() {
92
 
    // A kate part needs to be in read-write mode before we can alter its
93
 
    // contents.
94
 
//    bool wasReadWrite = document->isReadWrite();
95
 
//    if (! wasReadWrite)
96
 
//        document->setReadWrite(true);
97
 
 
98
 
    document->clear();
99
 
 
100
 
    // Back to all-at-once insertion instead of line-by-line insertion.
101
 
    // Grrr vimpart.
102
 
    if (! text->getText().empty()) {
103
 
        QString data = text->getText().c_str();
104
 
 
105
 
        // We are guaranteed that data.length() >= 1.
106
 
        if (data[data.length() - 1] == '\n')
107
 
            data.truncate(data.length() - 1);
108
 
 
109
 
        document->setPlainText(data);
110
 
        document->moveCursor(QTextCursor::Start);
111
 
    }
112
 
 
113
 
//    if (! wasReadWrite)
114
 
//        document->setReadWrite(false);
115
 
 
116
 
    setDirty(false);
 
85
    editWidget->refresh();
117
86
}
118
87
 
119
88
void NTextUI::setReadWrite(bool readWrite) {
120
 
    document->setReadOnly(!readWrite);
121
 
}
122
 
 
123
 
void NTextUI::notifyTextChanged() {
124
 
    setDirty(true);
 
89
    editWidget->setReadOnly(!readWrite);
125
90
}
126
91