summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c>2010-04-03 03:05:14 (GMT)
committerkintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c>2010-04-03 03:05:14 (GMT)
commit9f582257544a6b81097c5aded4ae912faf112475 (patch)
tree9568b7871c741d14c1595c259e83fce94fca0a5f /src
parent1fb93c298546a28c4653007ff4a74ab703f73e46 (diff)
Changes that were supposed to be commited in last commit
git-svn-id: http://svn.clifford.at/openscad/trunk@501 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'src')
-rw-r--r--src/MainWindow.ui8
-rw-r--r--src/editor.h23
-rw-r--r--src/highlighter.cc5
-rw-r--r--src/highlighter.h4
-rw-r--r--src/mainwin.cc97
5 files changed, 49 insertions, 88 deletions
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"
contact: Jan Huwald // Impressum