Moved font cache dialog to OpenSCADApp

This commit is contained in:
Marius Kintel 2016-01-25 20:22:42 -05:00
parent a20e327f54
commit 7c104f0630
5 changed files with 31 additions and 29 deletions

View file

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

View file

@ -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));
@ -15,6 +17,7 @@ OpenSCADApp::OpenSCADApp(int &argc ,char **argv)
OpenSCADApp::~OpenSCADApp()
{
delete this->fontCacheDialog;
}
bool OpenSCADApp::notify(QObject *object, QEvent *event)
@ -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();
}

View file

@ -14,7 +14,15 @@ public:
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()))

View file

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

View file

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