Make editor and console windows dockable and make MDI mode a runtime option.

master
Torsten Paul 2014-05-12 22:47:42 +02:00
parent 71f8e62a15
commit 4fbbc09895
8 changed files with 447 additions and 311 deletions

View File

@ -349,7 +349,7 @@ void GLView::gimbalCamPaintGL()
glColor3d(1.0, 0.0, 0.0);
if (this->renderer) {
#if defined(ENABLE_MDI) && defined(ENABLE_OPENCSG)
#if defined(ENABLE_OPENCSG)
// FIXME: This belongs in the OpenCSG renderer, but it doesn't know about this ID yet
OpenCSG::setContext(this->opencsg_id);
#endif

View File

@ -64,6 +64,7 @@ public:
static const int maxRecentFiles = 10;
QAction *actionRecentFile[maxRecentFiles];
QMap<QString, QString> knownFileExtensions;
MainWindow(const QString &filename);
~MainWindow();
@ -74,6 +75,8 @@ protected:
private slots:
void updatedFps();
void updateTVal();
void updateMdiMode(bool mdi);
void updateUndockMode(bool undockMode);
void setFileName(const QString &filename);
void setFont(const QString &family, uint size);
void showProgress();
@ -81,6 +84,7 @@ private slots:
private:
void openFile(const QString &filename);
void handleFileDrop(const QString &filename);
void refreshDocument();
void updateTemporalVariables();
bool fileChangedOnDisk();
@ -96,6 +100,7 @@ private:
void saveBackup();
void writeBackup(class QFile *file);
QString get2dExportFilename(QString format, QString extension);
void setDockWidgetTitle(QDockWidget *dockWidget, QString prefix, bool topLevel);
class QMessageBox *openglbox;
@ -168,6 +173,10 @@ public:
public slots:
void actionReloadRenderPreview();
void on_editorDock_visibilityChanged(bool);
void on_consoleDock_visibilityChanged(bool);
void editorTopLevelChanged(bool);
void consoleTopLevelChanged(bool);
#ifdef ENABLE_OPENCSG
void viewModePreview();
#endif
@ -207,6 +216,8 @@ public slots:
private:
static void report_func(const class AbstractNode*, void *vp, int mark);
static bool mdiMode;
static bool undockMode;
char const * afterCompileSlot;
bool procevents;

View File

@ -6,208 +6,96 @@
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>647</height>
<width>936</width>
<height>693</height>
</rect>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QWidget" name="mainWidget" native="true">
<property name="styleSheet">
<string notr="true"/>
</property>
<widget class="QWidget" name="editorPane" native="true">
<property name="enabled">
<bool>true</bool>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="find_panel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<item>
<widget class="QGLView" name="qglview" native="true">
<property name="minimumSize">
<size>
<width>200</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignBottom">
<widget class="QFrame" name="animate_panel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayoutAnimate">
<property name="margin">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QComboBox" name="findTypeComboBox">
<item>
<property name="text">
<string>Find</string>
</property>
</item>
<item>
<property name="text">
<string>Replace</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="findInputField">
<property name="placeholderText">
<string>Search string</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="prevButton">
<property name="text">
<string>&lt;</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>&gt;</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="hideFindButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="replaceInputField">
<property name="placeholderText">
<string>Replacement string</string>
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QPushButton" name="replaceButton">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="replaceAllButton">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Editor" name="editor" native="true">
<property name="font">
<font>
<family>Monaco</family>
<pointsize>8</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QGLView" name="qglview" native="true"/>
<widget class="QTextEdit" name="console">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QFrame" name="animate_panel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayoutAnimate">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_tval"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>FPS:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_fps"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Steps:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_fsteps"/>
</item>
<item>
<widget class="QCheckBox" name="e_dump">
<property name="text">
<string>Dump Pictures</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_tval"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>FPS:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_fps"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Steps:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_fsteps"/>
</item>
<item>
<widget class="QCheckBox" name="e_dump">
<property name="text">
<string>Dump Pictures</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
@ -217,8 +105,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>22</height>
<width>936</width>
<height>34</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@ -361,6 +249,146 @@
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QDockWidget" name="editorDock">
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="editorDockContents">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item alignment="Qt::AlignTop">
<widget class="QFrame" name="find_panel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QComboBox" name="findTypeComboBox">
<item>
<property name="text">
<string>Find</string>
</property>
</item>
<item>
<property name="text">
<string>Replace</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="findInputField">
<property name="placeholderText">
<string>Search string</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="prevButton">
<property name="text">
<string>&lt;</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>&gt;</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="hideFindButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="replaceInputField">
<property name="placeholderText">
<string>Replacement string</string>
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QPushButton" name="replaceButton">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="replaceAllButton">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Editor" name="editor" native="true">
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="font">
<font>
<family>Monaco</family>
<pointsize>8</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="consoleDock">
<attribute name="dockWidgetArea">
<number>8</number>
</attribute>
<widget class="QWidget" name="consoleDockContents">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="console">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<action name="fileActionNew">
<property name="text">
<string>&amp;New</string>

View File

@ -96,6 +96,8 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
#endif
this->defaultmap["advanced/openCSGLimit"] = RenderSettings::inst()->openCSGTermLimit;
this->defaultmap["advanced/forceGoldfeather"] = false;
this->defaultmap["advanced/mdi"] = true;
this->defaultmap["advanced/undockableWindows"] = false;
// Toolbar
QActionGroup *group = new QActionGroup(this);
@ -335,6 +337,22 @@ void Preferences::on_checkNowButton_clicked()
}
}
void
Preferences::on_mdiCheckBox_toggled(bool state)
{
QSettings settings;
settings.setValue("advanced/mdi", state);
emit updateMdiMode(state);
}
void
Preferences::on_undockCheckBox_toggled(bool state)
{
QSettings settings;
settings.setValue("advanced/undockableWindows", state);
emit updateUndockMode(state);
}
void
Preferences::on_openCSGWarningBox_toggled(bool state)
{
@ -461,6 +479,8 @@ void Preferences::updateGUI()
this->polysetCacheSizeEdit->setText(getValue("advanced/polysetCacheSize").toString());
this->opencsgLimitEdit->setText(getValue("advanced/openCSGLimit").toString());
this->forceGoldfeatherBox->setChecked(getValue("advanced/forceGoldfeather").toBool());
this->mdiCheckBox->setChecked(getValue("advanced/mdi").toBool());
this->undockCheckBox->setChecked(getValue("advanced/undockableWindows").toBool());
}
void Preferences::apply() const

View File

@ -34,10 +34,14 @@ public slots:
void on_mouseWheelZoomBox_toggled(bool);
void on_updateCheckBox_toggled(bool);
void on_snapshotCheckBox_toggled(bool);
void on_mdiCheckBox_toggled(bool);
void on_undockCheckBox_toggled(bool);
void on_checkNowButton_clicked();
signals:
void requestRedraw() const;
void updateMdiMode(bool mdi) const;
void updateUndockMode(bool mdi) const;
void fontChanged(const QString &family, uint size) const;
void openCSGSettingsChanged() const;
void syntaxHighlightChanged(const QString &s);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>823</width>
<height>433</height>
<height>440</height>
</rect>
</property>
<property name="sizePolicy">
@ -27,7 +27,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
<number>4</number>
</property>
<widget class="QWidget" name="page3DView">
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -607,6 +607,20 @@
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="mdiCheckBox">
<property name="text">
<string>Allow to open multiple documents</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="undockCheckBox">
<property name="text">
<string>Enable undocking of Editor and Console</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -76,6 +76,7 @@
#include <QProgressDialog>
#include <QMutexLocker>
#include <QTemporaryFile>
#include <QDockWidget>
#include <fstream>
@ -157,10 +158,17 @@ settings_valueList(const QString &key, const QList<int> &defaultList = QList<int
}
bool MainWindow::mdiMode = false;
bool MainWindow::undockMode = false;
MainWindow::MainWindow(const QString &filename)
: root_inst("group"), tempFile(NULL), progresswidget(NULL)
{
setupUi(this);
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
this->setAttribute(Qt::WA_DeleteOnClose);
@ -195,7 +203,16 @@ MainWindow::MainWindow(const QString &filename)
fps = 0;
fsteps = 1;
editActionZoomIn->setShortcuts(QList<QKeySequence>() << editActionZoomIn->shortcuts() << QKeySequence("CTRL+="));
const QString importStatement = "import(\"%1\");\n";
const QString surfaceStatement = "surface(\"%1\");\n";
knownFileExtensions["stl"] = importStatement;
knownFileExtensions["off"] = importStatement;
knownFileExtensions["dxf"] = importStatement;
knownFileExtensions["dat"] = surfaceStatement;
knownFileExtensions["png"] = surfaceStatement;
knownFileExtensions["scad"] = "";
editActionZoomIn->setShortcuts(QList<QKeySequence>() << editActionZoomIn->shortcuts() << QKeySequence("CTRL+="));
connect(this, SIGNAL(highlightError(int)), editor, SLOT(highlightError(int)));
connect(this, SIGNAL(unhighlightLastError()), editor, SLOT(unhighlightLastError()));
@ -358,8 +375,8 @@ MainWindow::MainWindow(const QString &filename)
connect(this->viewActionPerspective, SIGNAL(triggered()), this, SLOT(viewPerspective()));
connect(this->viewActionOrthogonal, SIGNAL(triggered()), this, SLOT(viewOrthogonal()));
connect(this->viewActionHide, SIGNAL(triggered()), this, SLOT(hideConsole()));
connect(this->viewActionZoomIn, SIGNAL(triggered()), qglview, SLOT(ZoomIn()));
connect(this->viewActionZoomOut, SIGNAL(triggered()), qglview, SLOT(ZoomOut()));
connect(this->viewActionZoomIn, SIGNAL(triggered()), qglview, SLOT(ZoomIn()));
connect(this->viewActionZoomOut, SIGNAL(triggered()), qglview, SLOT(ZoomOut()));
// Help menu
connect(this->helpActionAbout, SIGNAL(triggered()), this, SLOT(helpAbout()));
@ -367,7 +384,6 @@ MainWindow::MainWindow(const QString &filename)
connect(this->helpActionManual, SIGNAL(triggered()), this, SLOT(helpManual()));
connect(this->helpActionLibraryInfo, SIGNAL(triggered()), this, SLOT(helpLibrary()));
setCurrentOutput();
PRINT(helptitle);
@ -387,7 +403,9 @@ MainWindow::MainWindow(const QString &filename)
connect(this->qglview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
connect(Preferences::inst(), SIGNAL(requestRedraw()), this->qglview, SLOT(updateGL()));
connect(Preferences::inst(), SIGNAL(fontChanged(const QString&,uint)),
connect(Preferences::inst(), SIGNAL(updateMdiMode(bool)), this, SLOT(updateMdiMode(bool)));
connect(Preferences::inst(), SIGNAL(updateUndockMode(bool)), this, SLOT(updateUndockMode(bool)));
connect(Preferences::inst(), SIGNAL(fontChanged(const QString&,uint)),
this, SLOT(setFont(const QString&,uint)));
connect(Preferences::inst(), SIGNAL(openCSGSettingsChanged()),
this, SLOT(openCSGSettingsChanged()));
@ -408,13 +426,13 @@ MainWindow::MainWindow(const QString &filename)
// make sure it looks nice..
QSettings settings;
restoreState(settings.value("window/state", QByteArray()).toByteArray());
resize(settings.value("window/size", QSize(800, 600)).toSize());
move(settings.value("window/position", QPoint(0, 0)).toPoint());
QList<int> s1sizes = settings_valueList("window/splitter1sizes",QList<int>()<<400<<400);
QList<int> s2sizes = settings_valueList("window/splitter2sizes",QList<int>()<<400<<200);
splitter1->setSizes(s1sizes);
splitter2->setSizes(s2sizes);
connect(this->editorDock, SIGNAL(topLevelChanged(bool)), this, SLOT(editorTopLevelChanged(bool)));
connect(this->consoleDock, SIGNAL(topLevelChanged(bool)), this, SLOT(consoleTopLevelChanged(bool)));
// display this window and check for OpenGL 2.0 (OpenCSG) support
viewModeThrownTogether();
show();
@ -459,6 +477,8 @@ MainWindow::loadViewSettings(){
editActionHide->setChecked(true);
hideEditor();
}
updateMdiMode(settings.value("advanced/mdi").toBool());
updateUndockMode(settings.value("advanced/undockableWindows").toBool());
}
void
@ -476,6 +496,23 @@ MainWindow::loadDesignSettings()
#endif
}
void MainWindow::updateMdiMode(bool mdi)
{
MainWindow::mdiMode = mdi;
}
void MainWindow::updateUndockMode(bool undockMode)
{
MainWindow::undockMode = undockMode;
if (undockMode) {
editorDock->setFeatures(editorDock->features() | QDockWidget::DockWidgetFloatable);
consoleDock->setFeatures(consoleDock->features() | QDockWidget::DockWidgetFloatable);
} else {
editorDock->setFeatures(editorDock->features() & ~QDockWidget::DockWidgetFloatable);
consoleDock->setFeatures(consoleDock->features() & ~QDockWidget::DockWidgetFloatable);
}
}
MainWindow::~MainWindow()
{
if (root_module) delete root_module;
@ -515,7 +552,6 @@ void MainWindow::report_func(const class AbstractNode*, void *vp, int mark)
/*!
Requests to open a file from an external event, e.g. by double-clicking a filename.
*/
#ifdef ENABLE_MDI
void MainWindow::requestOpenFile(const QString &filename)
{
// if we have an empty open window, use that one
@ -532,37 +568,41 @@ void MainWindow::requestOpenFile(const QString &filename)
// otherwise, create a new one
new MainWindow(filename);
}
#else
void MainWindow::requestOpenFile(const QString &)
{
}
#endif
/*!
Open the given file. In MDI mode a new window is created if the current
one is not empty. Otherwise the current window content is overwritten.
Any check whether to replace the content have to be made before.
*/
void
MainWindow::openFile(const QString &new_filename)
{
QString actual_filename = new_filename;
QFileInfo fi(new_filename);
if (fi.suffix().toLower().contains(QRegExp("^(stl|off|dxf)$"))) {
actual_filename = QString();
if (MainWindow::mdiMode) {
if (!editor->toPlainText().isEmpty()) {
new MainWindow(new_filename);
return;
}
}
#ifdef ENABLE_MDI
if (!editor->toPlainText().isEmpty()) {
new MainWindow(actual_filename);
clearCurrentOutput();
return;
}
#endif
setFileName(actual_filename);
setCurrentOutput();
editor->setPlainText("");
this->last_compiled_doc = "";
const QFileInfo fileInfo(new_filename);
const QString suffix = fileInfo.suffix().toLower();
const bool knownFileType = knownFileExtensions.contains(suffix);
const QString cmd = knownFileExtensions[suffix];
if (knownFileType && cmd.isEmpty()) {
setFileName(new_filename);
updateRecentFiles();
} else {
setFileName("");
editor->setPlainText(cmd.arg(new_filename));
}
fileChangedOnDisk(); // force cached autoReloadId to update
refreshDocument();
updateRecentFiles();
if (actual_filename.isEmpty()) {
this->editor->setPlainText(QString("import(\"%1\");\n").arg(new_filename));
}
clearCurrentOutput();
}
void
@ -570,38 +610,17 @@ MainWindow::setFileName(const QString &filename)
{
if (filename.isEmpty()) {
this->fileName.clear();
this->top_ctx.setDocumentPath(currentdir);
#if QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)
setWindowTitle("");
setWindowFilePath("untitled.scad");
#else
setWindowTitle("OpenSCAD - New Document[*]");
#endif
}
else {
this->top_ctx.setDocumentPath(currentdir);
} else {
QFileInfo fileinfo(filename);
this->fileName = fileinfo.exists() ? fileinfo.absoluteFilePath() : fileinfo.fileName();
setWindowFilePath(this->fileName);
// Check that the canonical file path exists - only update recent files
// if it does. Should prevent empty list items on initial open etc.
QString infoFileName = fileinfo.absoluteFilePath();
if (!infoFileName.isEmpty()) {
this->fileName = infoFileName;
#if QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)
setWindowTitle("");
this->setWindowFilePath(infoFileName);
#else
setWindowTitle("OpenSCAD - " + fileinfo.fileName() + "[*]");
#endif
} else {
this->fileName = fileinfo.fileName();
setWindowTitle("OpenSCAD - " + fileinfo.fileName() + "[*]");
}
this->top_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
QDir::setCurrent(fileinfo.dir().absolutePath());
this->top_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
}
}
void MainWindow::updateRecentFiles()
@ -963,15 +982,15 @@ void MainWindow::actionUpdateCheck()
void MainWindow::actionNew()
{
#ifdef ENABLE_MDI
new MainWindow(QString());
#else
if (!maybeSave())
return;
if (MainWindow::mdiMode) {
new MainWindow(QString());
} else {
if (!maybeSave())
return;
setFileName("");
editor->setPlainText("");
#endif
setFileName("");
editor->setPlainText("");
}
}
void MainWindow::actionOpen()
@ -979,42 +998,30 @@ void MainWindow::actionOpen()
QSettings settings;
QString last_dirname = settings.value("lastOpenDirName").toString();
QString new_filename = QFileDialog::getOpenFileName(this, "Open File",
last_dirname, "OpenSCAD Designs (*.scad *.csg)");
if (new_filename!="") {
QDir last_dir = QFileInfo( new_filename ).dir();
last_dirname = last_dir.path();
settings.setValue("lastOpenDirName", last_dirname);
}
#ifdef ENABLE_MDI
if (!new_filename.isEmpty()) {
openFile(new_filename);
}
#else
if (!new_filename.isEmpty()) {
if (!maybeSave())
return;
last_dirname, "OpenSCAD Designs (*.scad *.csg)");
setCurrentOutput();
openFile(new_filename);
clearCurrentOutput();
if (new_filename.isEmpty()) {
return;
}
#endif
QDir last_dir = QFileInfo(new_filename).dir();
last_dirname = last_dir.path();
settings.setValue("lastOpenDirName", last_dirname);
if (!MainWindow::mdiMode && !maybeSave()) {
return;
}
openFile(new_filename);
}
void MainWindow::actionOpenRecent()
{
QAction *action = qobject_cast<QAction *>(sender());
#ifdef ENABLE_MDI
openFile(action->data().toString());
#else
if (!maybeSave())
if (!MainWindow::mdiMode && !maybeSave()) {
return;
if (action) {
openFile(action->data().toString());
}
#endif
QAction *action = qobject_cast<QAction *>(sender());
openFile(action->data().toString());
}
void MainWindow::clearRecentFiles()
@ -1063,6 +1070,10 @@ void MainWindow::updateRecentFileActions()
void MainWindow::actionOpenExample()
{
if (!MainWindow::mdiMode && !maybeSave()) {
return;
}
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
openFile(qexamplesdir + QDir::separator() + action->text());
@ -1180,18 +1191,6 @@ void MainWindow::actionReload()
}
}
void MainWindow::hideEditor()
{
QSettings settings;
if (editActionHide->isChecked()) {
editorPane->hide();
settings.setValue("view/hideEditor",true);
} else {
editorPane->show();
settings.setValue("view/hideEditor",false);
}
}
void MainWindow::pasteViewportTranslation()
{
QTextCursor cursor = editor->textCursor();
@ -2058,15 +2057,57 @@ void MainWindow::viewResetView()
this->qglview->updateGL();
}
void MainWindow::hideConsole()
void MainWindow::on_editorDock_visibilityChanged(bool visible)
{
QSettings settings;
if (viewActionHide->isChecked()) {
console->hide();
settings.setValue("view/hideConsole",true);
settings.setValue("view/hideEditor", !visible);
editActionHide->setChecked(!visible);
editorTopLevelChanged(editorDock->isFloating());
}
void MainWindow::on_consoleDock_visibilityChanged(bool visible)
{
QSettings settings;
settings.setValue("view/hideConsole", !visible);
viewActionHide->setChecked(!visible);
consoleTopLevelChanged(consoleDock->isFloating());
}
void MainWindow::editorTopLevelChanged(bool topLevel)
{
setDockWidgetTitle(editorDock, QString("Editor"), topLevel);
}
void MainWindow::consoleTopLevelChanged(bool topLevel)
{
setDockWidgetTitle(consoleDock, QString("Console"), topLevel);
}
void MainWindow::setDockWidgetTitle(QDockWidget *dockWidget, QString prefix, bool topLevel)
{
QString title(prefix);
if (topLevel) {
const QFileInfo fileInfo(windowFilePath());
title += " (" + fileInfo.fileName() + ")";
}
dockWidget->setWindowTitle(title);
}
void MainWindow::hideEditor()
{
if (editActionHide->isChecked()) {
editorDock->close();
} else {
console->show();
settings.setValue("view/hideConsole",false);
editorDock->show();
}
}
void MainWindow::hideConsole()
{
if (viewActionHide->isChecked()) {
consoleDock->hide();
} else {
consoleDock->show();
}
}
@ -2083,11 +2124,27 @@ void MainWindow::dropEvent(QDropEvent *event)
for (int i = 0; i < urls.size(); i++) {
if (urls[i].scheme() != "file")
continue;
openFile(urls[i].toLocalFile());
handleFileDrop(urls[i].toLocalFile());
}
clearCurrentOutput();
}
void MainWindow::handleFileDrop(const QString &filename)
{
const QFileInfo fileInfo(filename);
const QString suffix = fileInfo.suffix().toLower();
const QString cmd = knownFileExtensions[suffix];
if (cmd.isEmpty()) {
if (!MainWindow::mdiMode && !maybeSave()) {
return;
}
openFile(filename);
} else {
editor->insertPlainText(cmd.arg(filename));
}
}
void
MainWindow::helpAbout()
{
@ -2162,8 +2219,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
QSettings settings;
settings.setValue("window/size", size());
settings.setValue("window/position", pos());
settings_setValueList("window/splitter1sizes",splitter1->sizes());
settings_setValueList("window/splitter2sizes",splitter2->sizes());
settings.setValue("window/state", saveState());
if (this->tempFile) {
delete this->tempFile;
this->tempFile = NULL;

View File

@ -540,7 +540,10 @@ int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, cha
QCoreApplication::setOrganizationDomain("openscad.org");
QCoreApplication::setApplicationName("OpenSCAD");
QCoreApplication::setApplicationVersion(TOSTRING(OPENSCAD_VERSION));
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QGuiApplication::setApplicationDisplayName("OpenSCAD");
#endif
// Other global settings
qRegisterMetaType<shared_ptr<const Geometry> >();