From 10f4a52985f5e66f4b49cd81d8e2dbddc5b886f2 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 22 Aug 2014 18:39:12 -0400 Subject: [PATCH] #879 Handle document modification signals, make editor interface more abstract --- src/editor.h | 44 +++++++++++++++++++++-------------------- src/legacyeditor.cc | 4 ++++ src/legacyeditor.h | 1 - src/mainwin.cc | 5 ++--- src/scintillaeditor.cpp | 28 +++++++++++++++++++++++++- src/scintillaeditor.h | 5 +++++ 6 files changed, 61 insertions(+), 26 deletions(-) diff --git a/src/editor.h b/src/editor.h index 36384f43..b229523f 100644 --- a/src/editor.h +++ b/src/editor.h @@ -17,33 +17,35 @@ public: virtual void setInitialSizeHint(const QSize&) { } virtual void wheelEvent (QWheelEvent*) { } virtual void setTabStopWidth(int) { } - virtual QString toPlainText() { QString s; return s;} + virtual QString toPlainText() = 0; virtual QTextDocument *document(){QTextDocument *t = new QTextDocument; return t;} virtual bool find(const QString &, bool findNext = false, bool findBackwards = false) = 0; virtual void replaceSelectedText(const QString &) = 0; +signals: + void contentsChanged(); + void modificationChanged(bool); + public slots: - virtual void zoomIn(){ } - virtual void zoomOut() { } - virtual void setLineWrapping(bool) { } - virtual void setContentModified(bool){ } - virtual bool isContentModified(){ return 0; } - virtual void indentSelection(){ } - virtual void unindentSelection(){ } - virtual void commentSelection() {} - virtual void uncommentSelection(){} - virtual void setPlainText(const QString &){ } - virtual void highlightError(int) {} - virtual void unhighlightLastError() {} - virtual void setHighlightScheme(const QString&){ } + virtual void zoomIn() = 0; + virtual void zoomOut() = 0; + virtual void setContentModified(bool) = 0; + virtual bool isContentModified() = 0; + virtual void indentSelection() = 0; + virtual void unindentSelection() = 0; + virtual void commentSelection() = 0; + virtual void uncommentSelection() = 0; + virtual void setPlainText(const QString &) = 0; + virtual void highlightError(int) = 0; + virtual void unhighlightLastError() = 0; + virtual void setHighlightScheme(const QString&) = 0; virtual void insert(const QString&) = 0; - virtual void undo(){ } - virtual void redo(){ } - virtual void cut(){ } - virtual void copy(){ } - virtual void paste(){ } - virtual void onTextChanged() { } - virtual void initFont(const QString&, uint){ } + virtual void undo() = 0; + virtual void redo() = 0; + virtual void cut() = 0; + virtual void copy() = 0; + virtual void paste() = 0; + virtual void initFont(const QString&, uint) = 0; private: QSize initialSizeHint; diff --git a/src/legacyeditor.cc b/src/legacyeditor.cc index 80b3e39c..b228071a 100644 --- a/src/legacyeditor.cc +++ b/src/legacyeditor.cc @@ -11,8 +11,12 @@ LegacyEditor::LegacyEditor(QWidget *parent) : EditorInterface(parent) // This needed to avoid the editor accepting filename drops as we want // to handle these ourselves in MainWindow this->textedit->setAcceptDrops(false); + this->textedit->setWordWrapMode(QTextOption::WrapAnywhere); this->highlighter = new Highlighter(this->textedit->document()); + + connect(this->textedit, SIGNAL(textChanged()), this, SIGNAL(textChanged())); + connect(this->textedit, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool))); } void LegacyEditor::indentSelection() diff --git a/src/legacyeditor.h b/src/legacyeditor.h index 39e37c2c..b7f04e77 100644 --- a/src/legacyeditor.h +++ b/src/legacyeditor.h @@ -31,7 +31,6 @@ public: public slots: void zoomIn(); void zoomOut(); - void setLineWrapping(bool on) { if(on) textedit->setWordWrapMode(QTextOption::WrapAnywhere); } void setContentModified(bool y) { textedit->document()->setModified(y); } bool isContentModified() {return textedit->document()->isModified();} void indentSelection(); diff --git a/src/mainwin.cc b/src/mainwin.cc index 9eeecf78..aff6baff 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -241,7 +241,6 @@ MainWindow::MainWindow(const QString &filename) connect(this, SIGNAL(highlightError(int)), editor, SLOT(highlightError(int))); connect(this, SIGNAL(unhighlightLastError()), editor, SLOT(unhighlightLastError())); editor->setTabStopWidth(30); - editor->setLineWrapping(true); // Not designable this->qglview->statusLabel = new QLabel(this); statusBar()->addWidget(this->qglview->statusLabel); @@ -417,8 +416,8 @@ MainWindow::MainWindow(const QString &filename) } updateRecentFileActions(); - connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged())); - connect(editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool))); + connect(editor, SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged())); + connect(editor, SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool))); connect(this->qglview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate())); connect(Preferences::inst(), SIGNAL(requestRedraw()), this->qglview, SLOT(updateGL())); diff --git a/src/scintillaeditor.cpp b/src/scintillaeditor.cpp index 8bd60811..71737c24 100644 --- a/src/scintillaeditor.cpp +++ b/src/scintillaeditor.cpp @@ -24,7 +24,9 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent) qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4); qsci->setCaretLineVisible(true); this->setHighlightScheme(preferenceEditorOption); - + + connect(qsci, SIGNAL(textChanged()), this, SIGNAL(textChanged())); + connect(qsci, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool))); } void ScintillaEditor::setPlainText(const QString &text) @@ -37,6 +39,11 @@ QString ScintillaEditor::toPlainText() return qsci->text(); } +void ScintillaEditor::setContentModified(bool modified) +{ + qsci->setModified(modified); +} + bool ScintillaEditor::isContentModified() { return qsci->isModified(); @@ -258,3 +265,22 @@ void ScintillaEditor::replaceSelectedText(const QString &newText) if (qsci->selectedText() != newText) qsci->replaceSelectedText(newText); } +void ScintillaEditor::indentSelection() +{ + // FIXME: Implement +} + +void ScintillaEditor::unindentSelection() +{ + // FIXME: Implement +} + +void ScintillaEditor::commentSelection() +{ + // FIXME: Implement +} + +void ScintillaEditor::uncommentSelection() +{ + // FIXME: Implement +} diff --git a/src/scintillaeditor.h b/src/scintillaeditor.h index 130d023b..ed8b401a 100644 --- a/src/scintillaeditor.h +++ b/src/scintillaeditor.h @@ -30,10 +30,15 @@ public slots: void zoomIn(); void zoomOut(); void setPlainText(const QString&); + void setContentModified(bool); bool isContentModified(); void highlightError(int); void unhighlightLastError(); void setHighlightScheme(const QString&); + void indentSelection(); + void unindentSelection(); + void commentSelection(); + void uncommentSelection(); void insert(const QString&); void undo(); void redo();