summaryrefslogtreecommitdiffhomepage
path: root/gui/main.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-30 08:34:40 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-10-30 08:39:33 +0100
commit2160e39a4f3d5198eafbb483671583a5a0b51eaa (patch)
tree2370dd4e9a7b43c204d175af3ab2a0ff5b33c41d /gui/main.cpp
parentaa066bdd4622d4f6824fee864f6be6806813f04d (diff)
rename gui directory
Diffstat (limited to 'gui/main.cpp')
-rw-r--r--gui/main.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/gui/main.cpp b/gui/main.cpp
new file mode 100644
index 00000000..a63fe54a
--- /dev/null
+++ b/gui/main.cpp
@@ -0,0 +1,71 @@
+#ifdef _WIN32
+# include <stdlib.h>
+#endif
+
+#include "ui.h"
+#include "opentrack/options.hpp"
+using namespace options;
+#include <QApplication>
+#include <QCommandLineParser>
+#include <QStyleFactory>
+#include <QStringList>
+#include <QMessageBox>
+#include <memory>
+#include <cstring>
+
+#ifdef _WIN32
+// workaround QTBUG-38598, allow for launching from another directory
+static void add_program_library_path()
+{
+ char* p = _pgmptr;
+ char path[MAX_PATH+1];
+ strcpy(path, p);
+ char* ptr = strrchr(path, '\\');
+ if (ptr)
+ {
+ *ptr = '\0';
+ QCoreApplication::addLibraryPath(path);
+ }
+}
+#endif
+
+int main(int argc, char** argv)
+{
+#ifdef _WIN32
+ add_program_library_path();
+#elif !defined(__linux)
+ // workaround QTBUG-38598
+ QCoreApplication::addLibraryPath(".");
+#endif
+
+#if defined(_WIN32) || defined(__APPLE__)
+ // qt5 designer-made controls look like shit on 'doze -sh 20140921
+ // also our OSX look leaves a lot to be desired -sh 20150726
+ {
+ const QStringList preferred { "fusion", "windowsvista", "macintosh", "windowsxp" };
+ for (const auto& style_name : preferred)
+ {
+ QStyle* s = QStyleFactory::create(style_name);
+ if (s)
+ {
+ QApplication::setStyle(s);
+ break;
+ }
+ }
+ }
+#endif
+
+ QApplication::setAttribute(Qt::AA_X11InitThreads, true);
+ QApplication app(argc, argv);
+
+ auto w = std::make_shared<MainWindow>();
+
+ w->show();
+ app.exec();
+
+ // on MSVC crashes in atexit
+#ifdef _MSC_VER
+ TerminateProcess(GetCurrentProcess(), 0);
+#endif
+ return 0;
+}