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
|
// Copyright 2007 Nanorex, Inc. See LICENSE file for details.
#include <QApplication>
#include "main.h"
static NXEntityManager* createEntityManager(QSettings *const settings);
static NXGraphicsManager* createGraphicsManager(QSettings *const settings);
/* FUNCTION: main */
int main(int argc, char *argv[]) {
#ifdef WIN32
// Create a console window to see stdout
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
#endif
Q_INIT_RESOURCE(application);
QApplication* app = new QApplication(argc, argv);
// Show splashscreen
//QPixmap pixmap(":/Icons/splashscreen.png");
//SplashScreen* splash = new SplashScreen(pixmap);
//splash->show();
// Get user settings
UserSettings* settings = UserSettings::Instance();
// Start logger
//
//splash->showMessage("Starting logger...");
//splash->repaint();
int logLevel = 0;
NXLogger* logger = new NXLogger();
// Console logging
if (settings->value("Logging/EnableConsoleLogging", true).toBool()) {
logLevel =
settings->value("Logging/ConsoleLoggingLevel",
NXLogLevel_Debug).toInt();
logger->addHandler(new NXConsoleLogHandler((NXLogLevel)logLevel));
}
// File logging
if (settings->value("Logging/EnableFileLogging", true).toBool()) {
logLevel =
settings->value("Logging/FileLoggingLevel",
NXLogLevel_Config).toInt();
QString logFilename = settings->fileName();
logFilename.chop(3);
logFilename.append("log");
logFilename =
settings->value("Logging/FileLoggingFilename", logFilename)
.toString();
NXFileLogHandler* logHandler =
new NXFileLogHandler(qPrintable(logFilename), (NXLogLevel)logLevel);
logger->addHandler(logHandler);
}
// TODO: Emit verbose config level log messages
NXLOG_CONFIG("main", "spew QSysInfo and OpenGL config information here");
// Dock widget logging
LogHandlerWidget* logHandlerWidget =
new LogHandlerWidget(NXLogLevel_Config);
logger->addHandler(logHandlerWidget);
// Initialize entity manager and load import/export plugins
//splash->showMessage("Loading entity manager...");
//splash->repaint();
NXEntityManager *entityManager = createEntityManager(settings);
NXGraphicsManager *graphicsManager = createGraphicsManager(settings);
// Create main window
nv1* mainWindow = new nv1(entityManager, graphicsManager, logHandlerWidget);
mainWindow->show();
//splash->repaint();
mainWindow->processCommandLine(argc, argv);
//sleep(1);
//splash->finish(mainWindow);
//delete splash;
int appReturn = app->exec();
NXLOG_DEBUG("main", "QApplication::exec() returned.");
delete app;
return appReturn;
}
NXEntityManager* createEntityManager(QSettings *const settings)
{
NXProperties* properties = new NXProperties();
QString pluginsSearchPath =
settings->value("Miscellaneous/PluginsSearchPath").toString();
properties->setProperty("PluginsSearchPath", qPrintable(pluginsSearchPath));
settings->beginGroup("NXEntityManager");
QStringList keys = settings->allKeys();
QStringList::const_iterator iter;
for (iter = keys.constBegin(); iter != keys.constEnd(); iter++)
properties->setProperty(qPrintable(*iter),
qPrintable(settings->value(*iter).toString()));
settings->endGroup();
NXEntityManager* entityManager = new NXEntityManager();
entityManager->loadDataImportExportPlugins(properties);
delete properties;
return entityManager;
}
NXGraphicsManager* createGraphicsManager(QSettings *const settings)
{
NXProperties *properties = new NXProperties();
QString pluginsSearchPath =
settings->value("Miscellaneous/PluginsSearchPath").toString();
properties->setProperty("PluginsSearchPath", qPrintable(pluginsSearchPath));
settings->beginGroup("NXGraphicsManager");
QStringList keys = settings->allKeys();
QStringList::const_iterator iter;
for (iter = keys.constBegin(); iter != keys.constEnd(); iter++)
properties->setProperty(qPrintable(*iter),
qPrintable(settings->value(*iter).toString()));
settings->endGroup();
NXGraphicsManager *graphicsManager = new NXGraphicsManager();
graphicsManager->loadPlugins(properties);
delete properties;
return graphicsManager;
}
SplashScreen::SplashScreen(const QPixmap &img) : QSplashScreen(img) {
setMask(
QRegion(
QPixmap::fromImage(
pixmap().toImage().createAlphaMask(
Qt::AutoColor | Qt::DiffuseDither | Qt::DiffuseAlphaDither),
Qt::AutoColor | Qt::DiffuseDither | Qt::DiffuseAlphaDither)));
}
void SplashScreen::showMessage(const QString &message, int alignment,
const QColor &color) {
QSplashScreen::showMessage(message, alignment, color);
m_message = message;
}
void SplashScreen::drawContents(QPainter* painter) {
painter->setBackground(QColor(0, 0, 0, 0));
painter->setRenderHint(QPainter::Antialiasing);
painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter->drawPixmap(0, 0, pixmap());
painter->drawText(4, height() - 66, m_message);
}
|