1 /************************************************************************
2 *
3 * Copyright 2011-2012 Jakob Leben (jakob.leben@gmail.com)
4 *
5 * This file is part of SuperCollider Qt GUI.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ************************************************************************/
21
22 #include "QtCollider.h"
23 #include "QcApplication.h"
24 #include "Common.h"
25 #include "style/ProxyStyle.hpp"
26 #include "style/style.hpp"
27 #include "metatype.hpp"
28
29 #include <QTimer>
30 #include <QEventLoop>
31 #include <QDir>
32
33 #ifdef SC_USE_QTWEBENGINE
34 # include <QWebEngineSettings>
35 #endif
36
37 #ifdef Q_WS_X11
38 # include <X11/Xlib.h>
39 #endif
40
41 #include <clocale>
42
43 namespace QtCollider {
44 void loadFactories();
45 }
46
initResources()47 inline void initResources() { Q_INIT_RESOURCE(resources); }
48
49 static QPalette gSystemPalette;
systemPalette()50 QPalette QtCollider::systemPalette() { return gSystemPalette; }
51
init()52 void QtCollider::init() {
53 if (!QApplication::instance()) {
54 qcDebugMsg(1, "Initializing QtCollider");
55
56 initResources();
57
58 QtCollider::loadFactories();
59
60 QtCollider::MetaType::initAll();
61
62 QLocale::setDefault(QLocale::c());
63
64 #ifdef Q_WS_X11
65 XInitThreads();
66 #endif
67
68 #ifdef Q_OS_MAC
69 // TODO: this should not be necessary
70 QApplication::setAttribute(Qt::AA_PluginApplication, true);
71 #endif
72
73 static int qcArgc = 1;
74 static char qcArg0[] = "SuperCollider";
75 static char* qcArgv[1] = { qcArg0 };
76
77 QcApplication* qcApp = new QcApplication(qcArgc, qcArgv);
78
79 qcApp->setQuitOnLastWindowClosed(false);
80
81 // qcApp->setStyle( new QtCollider::Style::StyleImpl( new QPlastiqueStyle ) );
82
83 gSystemPalette = qcApp->palette();
84
85 #ifdef SC_USE_QTWEBENGINE
86 // Enable javascript localStorage for WebViews
87 QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
88 #endif
89
90 // NOTE: Qt may tamper with the C language locale, affecting POSIX number-string conversions.
91 // Revert the locale to default:
92 setlocale(LC_NUMERIC, "C");
93 }
94 }
95
exec(int argc,char ** argv)96 int QtCollider::exec(int argc, char** argv) {
97 QtCollider::init();
98 Q_ASSERT(qApp);
99 return qApp->exec();
100 }
101