application.cpp
1 //------------------------------------------------------------------------------
2 // application.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 const QString Application::NAME = "doomseeker";
29 
30 DClass<Application>
31 {
32  public:
33  MainWindow *mainWindow;
34  bool running;
35 };
36 
37 DPointered(Application)
38 
39 Application *Application::staticInstance = NULL;
40 
41 Application::Application(int &argc, char **argv)
42 : QApplication(argc, argv)
43 {
44  d->mainWindow = NULL;
45  d->running = true;
46  setApplicationName(NAME);
47 
48 #if QT_VERSION >= 0x050000
49  // http://blog.qt.io/blog/2013/04/25/retina-display-support-for-mac-os-ios-and-x11/
50  setAttribute(Qt::AA_UseHighDpiPixmaps);
51 #endif
52 }
53 
54 
55 Application::~Application()
56 {
57 }
58 
60 {
61  if (staticInstance != NULL)
62  {
63  staticInstance->destroy();
64  delete staticInstance;
65  staticInstance = NULL;
66  }
67 }
68 
69 void Application::destroy()
70 {
71  d->running = false;
72 }
73 
74 QIcon Application::icon()
75 {
76  return QIcon(":/icon.png");
77 }
78 
79 bool Application::isInit()
80 {
81  return staticInstance != NULL;
82 }
83 
84 void Application::init(int &argc, char **argv)
85 {
86  assert(staticInstance == NULL && "Cannot initialize Application twice!");
87  staticInstance = new Application(argc, argv);
88 }
89 
90 Application *Application::instance()
91 {
92  assert(staticInstance != NULL);
93  return staticInstance;
94 }
95 
97 {
98  return d->running;
99 }
100 
102 {
103  return d->mainWindow;
104 }
105 
107 {
108  return d->mainWindow;
109 }
110 
111 void Application::setMainWindow(MainWindow *mainWindow)
112 {
113  d->mainWindow = mainWindow;
114 }
115 
117 {
118  d->running = false;
119 }
void stopRunning()
Makes isRunning() return false.
QWidget * mainWindowAsQWidget() const
Returns MainWindow as a QWidget.
MainWindow * mainWindow() const
MainWindow of the program.
static const QString NAME
Program name - doomseeker.
Definition: application.h:51
Program central hub of information.
Definition: application.h:45
static void deinit()
Deinitializes the program; executed when program is shutting down.
Definition: application.cpp:59
bool isRunning() const
Plugins and other threads can use this to figure out if program is closing.
Definition: application.cpp:96