Skip to content

Commit

Permalink
Moved font cache dialog to OpenSCADApp
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel committed Jan 26, 2016
1 parent a20e327 commit 7c104f0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
3 changes: 0 additions & 3 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,12 @@ public slots:
void waitAfterReload();
void autoReloadSet(bool);
void setContentsChanged();
void showFontCacheDialog();
void hideFontCacheDialog();

private:
static void report_func(const class AbstractNode*, void *vp, int mark);
static bool mdiMode;
static bool undockMode;
static bool reorderMode;
static class QProgressDialog *fontCacheDialog;

shared_ptr<class CSGNode> csgRoot; // Result of the CSGTreeEvaluator
shared_ptr<CSGNode> normalizedRoot; // Normalized CSG tree
Expand Down
22 changes: 20 additions & 2 deletions src/OpenSCADApp.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "OpenSCADApp.h"
#include "MainWindow.h"
#include <iostream>
#ifdef Q_OS_MAC
#include "EventFilter.h"
#endif

#include <QProgressDialog>
#include <iostream>

OpenSCADApp::OpenSCADApp(int &argc ,char **argv)
: QApplication(argc, argv)
: QApplication(argc, argv), fontCacheDialog(NULL)
{
#ifdef Q_OS_MAC
this->installEventFilter(new EventFilter(this));
Expand All @@ -15,6 +17,7 @@ OpenSCADApp::OpenSCADApp(int &argc ,char **argv)

OpenSCADApp::~OpenSCADApp()
{
delete this->fontCacheDialog;
}

bool OpenSCADApp::notify(QObject *object, QEvent *event)
Expand Down Expand Up @@ -45,3 +48,18 @@ void OpenSCADApp::requestOpenFile(const QString &filename)
new MainWindow(filename);
}

void OpenSCADApp::showFontCacheDialog()
{
if (!this->fontCacheDialog) this->fontCacheDialog = new QProgressDialog();
this->fontCacheDialog->setLabelText(_("Fontconfig needs to update its font cache.\nThis can take up to a couple of minutes."));
this->fontCacheDialog->setMinimum(0);
this->fontCacheDialog->setMaximum(0);
this->fontCacheDialog->setCancelButton(0);
this->fontCacheDialog->exec();
}

void OpenSCADApp::hideFontCacheDialog()
{
assert(this->fontCacheDialog);
this->fontCacheDialog->reset();
}
8 changes: 8 additions & 0 deletions src/OpenSCADApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ class OpenSCADApp : public QApplication
bool notify(QObject *object, QEvent *event);
void requestOpenFile(const QString &filename);

public slots:
void showFontCacheDialog();
void hideFontCacheDialog();

public:
WindowManager windowManager;

private:
class QProgressDialog *fontCacheDialog;
};

#define scadApp (static_cast<OpenSCADApp *>(QCoreApplication::instance()))
19 changes: 0 additions & 19 deletions src/mainwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ bool MainWindow::mdiMode = false;
bool MainWindow::undockMode = false;
bool MainWindow::reorderMode = false;

QProgressDialog *MainWindow::fontCacheDialog = NULL;

MainWindow::MainWindow(const QString &filename)
: root_inst("group"), library_info_dialog(NULL), font_list_dialog(NULL), procevents(false), tempFile(NULL), progresswidget(NULL), contentschanged(false)
{
Expand Down Expand Up @@ -2765,20 +2763,3 @@ void MainWindow::setContentsChanged()
this->contentschanged = true;
}

void MainWindow::showFontCacheDialog()
{
if (!MainWindow::fontCacheDialog) MainWindow::fontCacheDialog = new QProgressDialog;
QProgressDialog *dialog = MainWindow::fontCacheDialog;

dialog->setLabelText(_("Fontconfig needs to update its font cache.\nThis can take up to a couple of minutes."));
dialog->setMinimum(0);
dialog->setMaximum(0);
dialog->setCancelButton(0);
dialog->exec();
}

void MainWindow::hideFontCacheDialog()
{
assert(MainWindow::fontCacheDialog);
MainWindow::fontCacheDialog->reset();
}
8 changes: 3 additions & 5 deletions src/openscad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,23 +616,21 @@ void dialogThreadFunc(FontCacheInitializer *initializer)

void dialogInitHandler(FontCacheInitializer *initializer, void *)
{
MainWindow *mainw = *scadApp->windowManager.getWindows().begin();

QFutureWatcher<void> futureWatcher;
QObject::connect(&futureWatcher, SIGNAL(finished()), mainw, SLOT(hideFontCacheDialog()));
QObject::connect(&futureWatcher, SIGNAL(finished()), scadApp, SLOT(hideFontCacheDialog()));

QFuture<void> future = QtConcurrent::run(boost::bind(dialogThreadFunc, initializer));
futureWatcher.setFuture(future);

// We don't always get the started() signal, so we start manually
QMetaObject::invokeMethod(mainw, "showFontCacheDialog");
QMetaObject::invokeMethod(scadApp, "showFontCacheDialog");

// Block, in case we're in a separate thread, or the dialog was closed by the user
futureWatcher.waitForFinished();

// We don't always receive the finished signal. We still need the signal to break
// out of the exec() though.
QMetaObject::invokeMethod(mainw, "hideFontCacheDialog");
QMetaObject::invokeMethod(scadApp, "hideFontCacheDialog");
}

int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, char ** argv)
Expand Down

0 comments on commit 7c104f0

Please sign in to comment.