application.cpp
1 //------------------------------------------------------------------------------
2 // application.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "application.h"
24 
25 #include "gui/mainwindow.h"
26 #include <cassert>
27 
28 DClass<Application>
29 {
30  public:
31  MainWindow *mainWindow;
32  bool running;
33 };
34 
35 DPointered(Application)
36 
37 Application *Application::staticInstance = NULL;
38 
39 Application::Application(int &argc, char **argv)
40 : QApplication(argc, argv)
41 {
42  d->mainWindow = NULL;
43  d->running = true;
44  setApplicationName("doomseeker");
45 
46 #if QT_VERSION >= 0x050000
47  // http://blog.qt.io/blog/2013/04/25/retina-display-support-for-mac-os-ios-and-x11/
48  setAttribute(Qt::AA_UseHighDpiPixmaps);
49 #endif
50 }
51 
52 
53 Application::~Application()
54 {
55 }
56 
58 {
59  if (staticInstance != NULL)
60  {
61  staticInstance->destroy();
62  }
63 }
64 
65 void Application::destroy()
66 {
67  d->running = false;
68 }
69 
70 bool Application::isInit()
71 {
72  return staticInstance != NULL;
73 }
74 
75 void Application::init(int &argc, char **argv)
76 {
77  assert(staticInstance == NULL && "Cannot initialize Application twice!");
78  staticInstance = new Application(argc, argv);
79 }
80 
81 Application *Application::instance()
82 {
83  assert(staticInstance != NULL);
84  return staticInstance;
85 }
86 
88 {
89  return d->running;
90 }
91 
93 {
94  return d->mainWindow;
95 }
96 
98 {
99  return d->mainWindow;
100 }
101 
102 void Application::setMainWindow(MainWindow *mainWindow)
103 {
104  d->mainWindow = mainWindow;
105 }
106 
108 {
109  d->running = false;
110 }
void stopRunning()
Makes isRunning() return false.
QWidget * mainWindowAsQWidget() const
Returns MainWindow as a QWidget.
Definition: application.cpp:97
MainWindow * mainWindow() const
MainWindow of the program.
Definition: application.cpp:92
Program central hub of information.
Definition: application.h:44
static void deinit()
Deinitializes the program; executed when program is shutting down.
Definition: application.cpp:57
bool isRunning() const
Plugins and other threads can use this to figure out if program is closing.
Definition: application.cpp:87