diff options
-rw-r--r-- | openscad.pro | 7 | ||||
-rw-r--r-- | src/MainWindow.ui | 8 | ||||
-rw-r--r-- | src/editor.h | 23 | ||||
-rw-r--r-- | src/highlighter.cc | 5 | ||||
-rw-r--r-- | src/highlighter.h | 4 | ||||
-rw-r--r-- | src/mainwin.cc | 97 |
6 files changed, 54 insertions, 90 deletions
diff --git a/openscad.pro b/openscad.pro index b6d655c..1b89951 100644 --- a/openscad.pro +++ b/openscad.pro @@ -35,6 +35,7 @@ macx:CONFIG += mdi CONFIG += cgal CONFIG += opencsg CONFIG += progresswidget +#CONFIG += qcodeedit mdi { # MDI needs an OpenCSG library that is compiled with OpenCSG-Reset-Hack.patch applied @@ -89,7 +90,8 @@ HEADERS += src/CGAL_renderer.h \ src/polyset.h \ src/printutils.h \ src/value.h \ - src/progress.h + src/progress.h \ + src/editor.h SOURCES += src/openscad.cc \ src/mainwin.cc \ @@ -125,7 +127,8 @@ SOURCES += src/openscad.cc \ src/printutils.cc \ src/nef2dxf.cc \ src/Preferences.cc \ - src/progress.cc + src/progress.cc \ + src/editor.cc macx { HEADERS += src/AppleEvents.h \ diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 37d8579..03f8e2d 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -23,19 +23,13 @@ <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <widget class="QTextEdit" name="editor"> + <widget class="Editor" name="editor"> <property name="font"> <font> <family>Monaco</family> <pointsize>8</pointsize> </font> </property> - <property name="tabStopWidth"> - <number>30</number> - </property> - <property name="textInteractionFlags"> - <set>Qt::LinksAccessibleByMouse|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> - </property> </widget> <widget class="QWidget" name="layoutWidget"> <layout class="QVBoxLayout" name="verticalLayout"> diff --git a/src/editor.h b/src/editor.h index c9450ce..115801d 100644 --- a/src/editor.h +++ b/src/editor.h @@ -1,7 +1,24 @@ #ifdef _QCODE_EDIT_ #include <qeditor.h> -#define EDITOR QEditor +class Editor : public QEditor #else -#include <QTextEditor> -#define EDITOR QTextEditor +#include <QTextEdit> +class Editor : public QTextEdit #endif +{ +public: +#ifdef _QCODE_EDIT_ + Editor(QWidget *parent) : QEditor(parent) {} + QString toPlainText() const { return text(); } + void setPlainText(const QString& text) { setText(text); } +#else + Editor(QWidget *parent) : QTextEdit(parent) {} + void setLineWrapping(bool on) { if(on) setWordWrapMode(QTextOption::WrapAnywhere); } + void setContentModified(bool y) { document()->setModified(y); } + bool isContentModified() { return document()->isModified(); } + void indentSelection(); + void unindentSelection(); + void commentSelection(); + void uncommentSelection(); +#endif +}; diff --git a/src/highlighter.cc b/src/highlighter.cc index d5f729d..1123d1b 100644 --- a/src/highlighter.cc +++ b/src/highlighter.cc @@ -25,8 +25,11 @@ #include "highlighter.h" #include "openscad.h" // extern int parser_error_pos; - +#ifdef _QCODE_EDIT_ +Highlighter::Highlighter(QDocument *parent) +#else Highlighter::Highlighter(QTextDocument *parent) +#endif : QSyntaxHighlighter(parent) { } diff --git a/src/highlighter.h b/src/highlighter.h index 2eead6d..aeb2972 100644 --- a/src/highlighter.h +++ b/src/highlighter.h @@ -6,7 +6,11 @@ class Highlighter : public QSyntaxHighlighter { public: +#ifdef _QCODE_EDIT_ + Highlighter(QDocument *parent); +#else Highlighter(QTextDocument *parent); +#endif void highlightBlock(const QString &text); }; diff --git a/src/mainwin.cc b/src/mainwin.cc index e66b861..b120f44 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -157,7 +157,7 @@ MainWindow::MainWindow(const QString &filename) highlighter = NULL; - editor->setWordWrapMode(QTextOption::WrapAnywhere); // Not designable + editor->setLineWrapping(true); // Not designable setFont("", 0); // Init default font screen->statusLabel = new QLabel(this); @@ -218,10 +218,10 @@ MainWindow::MainWindow(const QString &filename) connect(this->editActionCut, SIGNAL(triggered()), editor, SLOT(cut())); connect(this->editActionCopy, SIGNAL(triggered()), editor, SLOT(copy())); connect(this->editActionPaste, SIGNAL(triggered()), editor, SLOT(paste())); - connect(this->editActionIndent, SIGNAL(triggered()), this, SLOT(editIndent())); - connect(this->editActionUnindent, SIGNAL(triggered()), this, SLOT(editUnindent())); - connect(this->editActionComment, SIGNAL(triggered()), this, SLOT(editComment())); - connect(this->editActionUncomment, SIGNAL(triggered()), this, SLOT(editUncomment())); + connect(this->editActionIndent, SIGNAL(triggered()), editor, SLOT(indentSelection())); + connect(this->editActionUnindent, SIGNAL(triggered()), editor, SLOT(unindentSelection())); + connect(this->editActionComment, SIGNAL(triggered()), editor, SLOT(commentSelection())); + connect(this->editActionUncomment, SIGNAL(triggered()), editor, SLOT(uncommentSelection())); connect(this->editActionPasteVPT, SIGNAL(triggered()), this, SLOT(pasteViewportTranslation())); connect(this->editActionPasteVPR, SIGNAL(triggered()), this, SLOT(pasteViewportRotation())); connect(this->editActionZoomIn, SIGNAL(triggered()), editor, SLOT(zoomIn())); @@ -590,9 +590,14 @@ void MainWindow::compile(bool procevents) if (!root_module) { if (!animate_panel->isVisible()) { +#ifdef _QCODE_EDIT_ + QDocumentCursor cursor = editor->cursor(); + cursor.setPosition(parser_error_pos); +#else QTextCursor cursor = editor->textCursor(); cursor.setPosition(parser_error_pos); editor->setTextCursor(cursor); +#endif } goto fail; } @@ -862,7 +867,7 @@ void MainWindow::actionSave() else { QTextStream(&file) << this->editor->toPlainText(); PRINTA("Saved design `%1'.", this->fileName); - this->editor->document()->setModified(false); + this->editor->setContentModified(false); } clearCurrentOutput(); } @@ -898,76 +903,6 @@ void MainWindow::actionReload() load(); } -void MainWindow::editIndent() -{ - QTextCursor cursor = editor->textCursor(); - int p1 = cursor.selectionStart(); - QString txt = cursor.selectedText(); - - txt.replace(QString(QChar(8233)), QString(QChar(8233)) + QString("\t")); - if (txt.endsWith(QString(QChar(8233)) + QString("\t"))) - txt.chop(1); - txt = QString("\t") + txt; - - cursor.insertText(txt); - int p2 = cursor.position(); - cursor.setPosition(p1, QTextCursor::MoveAnchor); - cursor.setPosition(p2, QTextCursor::KeepAnchor); - editor->setTextCursor(cursor); -} - -void MainWindow::editUnindent() -{ - QTextCursor cursor = editor->textCursor(); - int p1 = cursor.selectionStart(); - QString txt = cursor.selectedText(); - - txt.replace(QString(QChar(8233)) + QString("\t"), QString(QChar(8233))); - if (txt.startsWith(QString("\t"))) - txt.remove(0, 1); - - cursor.insertText(txt); - int p2 = cursor.position(); - cursor.setPosition(p1, QTextCursor::MoveAnchor); - cursor.setPosition(p2, QTextCursor::KeepAnchor); - editor->setTextCursor(cursor); -} - -void MainWindow::editComment() -{ - QTextCursor cursor = editor->textCursor(); - int p1 = cursor.selectionStart(); - QString txt = cursor.selectedText(); - - txt.replace(QString(QChar(8233)), QString(QChar(8233)) + QString("//")); - if (txt.endsWith(QString(QChar(8233)) + QString("//"))) - txt.chop(2); - txt = QString("//") + txt; - - cursor.insertText(txt); - int p2 = cursor.position(); - cursor.setPosition(p1, QTextCursor::MoveAnchor); - cursor.setPosition(p2, QTextCursor::KeepAnchor); - editor->setTextCursor(cursor); -} - -void MainWindow::editUncomment() -{ - QTextCursor cursor = editor->textCursor(); - int p1 = cursor.selectionStart(); - QString txt = cursor.selectedText(); - - txt.replace(QString(QChar(8233)) + QString("//"), QString(QChar(8233))); - if (txt.startsWith(QString("//"))) - txt.remove(0, 2); - - cursor.insertText(txt); - int p2 = cursor.position(); - cursor.setPosition(p1, QTextCursor::MoveAnchor); - cursor.setPosition(p2, QTextCursor::KeepAnchor); - editor->setTextCursor(cursor); -} - void MainWindow::hideEditor() { if (editActionHide->isChecked()) { @@ -979,7 +914,11 @@ void MainWindow::hideEditor() void MainWindow::pasteViewportTranslation() { +#ifdef _QCODE_EDIT_ + QDocumentCursor cursor = editor->cursor(); +#else QTextCursor cursor = editor->textCursor(); +#endif QString txt; txt.sprintf("[ %.2f, %.2f, %.2f ]", -screen->object_trans_x, -screen->object_trans_y, -screen->object_trans_z); cursor.insertText(txt); @@ -987,7 +926,11 @@ void MainWindow::pasteViewportTranslation() void MainWindow::pasteViewportRotation() { +#ifdef _QCODE_EDIT_ + QDocumentCursor cursor = editor->cursor(); +#else QTextCursor cursor = editor->textCursor(); +#endif QString txt; txt.sprintf("[ %.2f, %.2f, %.2f ]", fmodf(360 - screen->object_rot_x + 90, 360), fmodf(360 - screen->object_rot_y, 360), fmodf(360 - screen->object_rot_z, 360)); @@ -1791,7 +1734,7 @@ MainWindow::helpManual() bool MainWindow::maybeSave() { - if (editor->document()->isModified()) { + if (editor->isContentModified()) { QMessageBox::StandardButton ret; ret = QMessageBox::warning(this, "Application", "The document has been modified.\n" |