#879 Handle document modification signals, make editor interface more abstract

master
Marius Kintel 2014-08-22 18:39:12 -04:00
parent f6b74eb6e0
commit 10f4a52985
6 changed files with 61 additions and 26 deletions

View File

@ -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;

View File

@ -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()

View File

@ -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();

View File

@ -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()));

View File

@ -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
}

View File

@ -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();