Skip to content

Commit

Permalink
Changes that were supposed to be commited in last commit
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.clifford.at/openscad/trunk@501 b57f626f-c46c-0410-a088-ec61d464b74c
  • Loading branch information
kintel committed Apr 3, 2010
1 parent 1fb93c2 commit 9f58225
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 90 deletions.
7 changes: 5 additions & 2 deletions openscad.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
8 changes: 1 addition & 7 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
23 changes: 20 additions & 3 deletions src/editor.h
Original file line number Diff line number Diff line change
@@ -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
};
5 changes: 4 additions & 1 deletion src/highlighter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
4 changes: 4 additions & 0 deletions src/highlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
97 changes: 20 additions & 77 deletions src/mainwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -979,15 +914,23 @@ 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);
}

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));
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 9f58225

Please sign in to comment.