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
stl_dim
kintel 2010-04-03 03:05:14 +00:00
parent 1fb93c2985
commit 9f58225754
6 changed files with 54 additions and 90 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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