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 = nullptr;
40 
41 Application::Application(int &argc, char **argv)
42  : QApplication(argc, argv)
43 {
44  d->mainWindow = nullptr;
45  d->running = true;
46  setApplicationName(NAME);
47 
48  // http://blog.qt.io/blog/2013/04/25/retina-display-support-for-mac-os-ios-and-x11/
49  setAttribute(Qt::AA_UseHighDpiPixmaps);
50 }
51 
52 
53 Application::~Application()
54 {
55 }
56 
58 {
59  if (staticInstance != nullptr)
60  {
61  staticInstance->destroy();
62  delete staticInstance;
63  staticInstance = nullptr;
64  }
65 }
66 
67 void Application::destroy()
68 {
69  d->running = false;
70 }
71 
72 QIcon Application::icon()
73 {
74  return QIcon(":/icon.png");
75 }
76 
77 bool Application::isInit()
78 {
79  return staticInstance != nullptr;
80 }
81 
82 void Application::init(int &argc, char **argv)
83 {
84  assert(staticInstance == nullptr && "Cannot initialize Application twice!");
85  staticInstance = new Application(argc, argv);
86 }
87 
88 Application *Application::instance()
89 {
90  assert(staticInstance != nullptr);
91  return staticInstance;
92 }
93 
95 {
96  return d->running;
97 }
98 
100 {
101  return d->mainWindow;
102 }
103 
105 {
106  return d->mainWindow;
107 }
108 
109 void Application::setMainWindow(MainWindow *mainWindow)
110 {
111  d->mainWindow = mainWindow;
112 }
113 
115 {
116  d->running = false;
117 }