forked from mapmapteam/mapmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
182 lines (146 loc) · 4.7 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// NOTE: To run, it is recommended not to be in Compiz or Beryl, they have shown some instability.
#define USING_QT_5 (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <iostream>
#include <QTranslator>
#include <QtGui>
#include <QDebug>
#if USING_QT_5
#include <QCommandLineParser>
#include <QCommandLineOption>
#endif
#include "MM.h"
#include "MainWindow.h"
#include "MainApplication.h"
#include <stdlib.h>
#include <iostream>
static void set_env_vars_if_needed()
{
#ifdef __MACOSX_CORE__
std::cout << "OS X detected. Set environment for GStreamer-SDK support." << std::endl;
if (0 == setenv("GST_PLUGIN_PATH", "/Library/Frameworks/GStreamer.framework/Libraries", 1))
std::cout << " * GST_PLUGIN_PATH=Library/Frameworks/GStreamer.framework/Libraries" << std::endl;
if (0 == setenv("GST_DEBUG", "2", 1))
std::cout << " * GST_DEBUG=2" << std::endl;
//setenv("LANG", "C", 1);
#endif // __MACOSX_CORE__
}
// This class is just used to provide sleep functionalities in the main() method.
class I : public QThread
{
public:
static void sleep(unsigned long secs) {
QThread::sleep(secs);
}
static void msleep(unsigned long msecs) {
QThread::msleep(msecs);
}
static void usleep(unsigned long usecs) {
QThread::usleep(usecs);
}
};
int main(int argc, char *argv[])
{
set_env_vars_if_needed();
MainApplication app(argc, argv);
#if USING_QT_5
QCommandLineParser parser;
parser.setApplicationDescription("Video mapping editor");
// --help option
const QCommandLineOption helpOption = parser.addHelpOption();
// --version option
const QCommandLineOption versionOption = parser.addVersionOption();
// --fullscreen option
QCommandLineOption fullscreenOption(QStringList() << "F" << "fullscreen",
"Display the output window and make it fullscreen.");
parser.addOption(fullscreenOption);
// --file option
QCommandLineOption fileOption(QStringList() << "f" << "file", "Load project from <file>.", "file", "");
parser.addOption(fileOption);
// --reset-settings option
QCommandLineOption resetSettingsOption(QStringList() << "R" << "reset-settings",
"Reset MapMap settings, such as GUI properties.");
parser.addOption(resetSettingsOption);
// --osc-port option
QCommandLineOption oscPortOption(QStringList() << "p" << "osc-port", "Use OSC port number <osc-port>.", "osc-port", "");
parser.addOption(oscPortOption);
// Positional argument: file
parser.addPositionalArgument("file", "Load project from that file.");
parser.process(app);
if (parser.isSet(versionOption) || parser.isSet(helpOption))
{
return 0;
}
if (parser.isSet(resetSettingsOption))
{
Util::eraseSettings();
}
#endif // USING_QT_5
if (! QGLFormat::hasOpenGL())
qFatal("This system has no OpenGL support.");
// Create splash screen.
QPixmap pixmap("splash.png");
QSplashScreen splash(pixmap);
// Show splash.
splash.show();
splash.showMessage(" " + QObject::tr("Initiating program..."),
Qt::AlignLeft | Qt::AlignTop, MM::WHITE);
bool FORCE_FRENCH_LANG = false;
// set_language_to_french(app);
if (FORCE_FRENCH_LANG) // XXX FIXME this if seems wrong
{
std::cerr << "This system has no OpenGL support" << std::endl;
return 1;
}
// Let splash for at least one second.
I::sleep(1);
// Create window.
MainWindow win;
QFontDatabase db;
Q_ASSERT( QFontDatabase::addApplicationFont(":/base-font") != -1);
app.setFont(QFont(":/base-font", 10, QFont::Bold));
// Load stylesheet.
QFile stylesheet("mapmap.qss");
stylesheet.open(QFile::ReadOnly);
app.setStyleSheet(QLatin1String(stylesheet.readAll()));
//win.setLocale(QLocale("fr"));
#if USING_QT_5
// read positional argument:
const QStringList args = parser.positionalArguments();
QString projectFileValue = QString();
// there are two ways to specify the project file name.
// The 2nd overrides the first:
// read the file option value: (overrides the positional argument)
projectFileValue = parser.value("file");
// read the first positional argument:
if (! args.isEmpty())
{
projectFileValue = args.first();
}
// finally, load the project file.
if (projectFileValue != "")
{
win.loadFile(projectFileValue);
}
QString oscPortNumberValue = parser.value("osc-port");
if (oscPortNumberValue != "")
{
win.setOscPort(oscPortNumberValue);
}
#endif
// Terminate splash.
splash.showMessage(" " + QObject::tr("Done."),
Qt::AlignLeft | Qt::AlignTop, MM::WHITE);
splash.finish(&win);
splash.raise();
// Launch program.
win.show();
#if USING_QT_5
if (parser.isSet(fullscreenOption))
{
qDebug() << "TODO: Running in fullscreen mode";
win.startFullScreen();
}
#endif
// Start app.
return app.exec();
}