1 /**********************************************************************************************
2 Copyright (C) 2017 Oliver Eichler <oliver.eichler@gmx.de>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 **********************************************************************************************/
18
19 #include "CAbout.h"
20 #include "CMainWindow.h"
21 #include "help/CHelp.h"
22 #include "helpers/CSettings.h"
23 #include "setup/CSetupExtTools.h"
24 #include "setup/IAppSetup.h"
25 #include "tool/CToolAddOverview.h"
26 #include "tool/CToolBox.h"
27 #include "tool/CToolCutMap.h"
28 #include "tool/CToolExport.h"
29 #include "tool/CToolGrid.h"
30 #include "tool/CToolPalettize.h"
31 #include "tool/CToolRefMap.h"
32 #include "units/CCoordFormatSetup.h"
33 #include "units/CUnitsSetup.h"
34 #include "units/IUnit.h"
35 #include "version.h"
36
37 CMainWindow* CMainWindow::pSelf = nullptr;
38
CMainWindow()39 CMainWindow::CMainWindow()
40 {
41 SETTINGS;
42 IUnit::setUnitType((IUnit::type_e)cfg.value("Units/units", IUnit::eTypeMetric).toInt(), this);
43 IUnit::setCoordFormat((IUnit::coord_format_e)cfg.value("Units/coordFormat", IUnit::eCoordFormat1).toInt());
44
45 pSelf = this;
46 setupUi(this);
47 setWindowTitle(WHAT_STR);
48
49 canvas->setToolInterface(toolStack);
50
51 connect(actionAbout, &QAction::triggered, this, &CMainWindow::slotAbout);
52 connect(actionSetupExtTools, &QAction::triggered, this, &CMainWindow::slotSetupExtTools);
53 connect(actionSetupUnits, &QAction::triggered, this, &CMainWindow::slotSetupUnits);
54 connect(actionSetupCoordFormat, &QAction::triggered, this, &CMainWindow::slotSetupCoordFormat);
55 connect(actionHelp, &QAction::triggered, this, &CMainWindow::slotHelp);
56 connect(&IAppSetup::self(), &IAppSetup::sigSetupChanged, this, &CMainWindow::slotSetupChanged);
57
58 menuWindow->addAction(dockTools->toggleViewAction());
59 menuWindow->addAction(dockShell->toggleViewAction());
60 prepareMenuForMac();
61
62 toolBox = new CToolBox(this);
63 toolStack->addWidget(toolBox);
64
65 toolAddOverview = new CToolAddOverview(toolBox);
66 toolBox->addItem(toolAddOverview, QIcon("://icons/32x32/AddOverview.png"), toolAddOverview->objectName());
67
68 toolCutMap = new CToolCutMap(toolBox);
69 toolBox->addItem(toolCutMap, QIcon("://icons/32x32/CutMap.png"), toolCutMap->objectName());
70
71 toolRefMap = new CToolRefMap(toolBox);
72 toolBox->addItem(toolRefMap, QIcon("://icons/32x32/ReferenceMap.png"), toolRefMap->objectName());
73
74 toolPalettize = new CToolPalettize(toolBox);
75 toolBox->addItem(toolPalettize, QIcon("://icons/32x32/Rasterize.png"), toolPalettize->objectName());
76
77 toolExport = new CToolExport(toolBox);
78 toolBox->addItem(toolExport, QIcon("://icons/32x32/Export.png"), toolExport->objectName());
79
80 toolGrid = new CToolGrid(this);
81 toolStack->addWidget(toolGrid);
82
83 // start ---- restore window geometry -----
84 if ( cfg.contains("MainWindow/geometry"))
85 {
86 restoreGeometry(cfg.value("MainWindow/geometry").toByteArray());
87 }
88 else
89 {
90 QTimer::singleShot(500, this, SLOT(showMaximized()));
91 }
92
93 if ( cfg.contains("MainWindow/state"))
94 {
95 restoreState(cfg.value("MainWindow/state").toByteArray());
96 }
97 // end ---- restore window geometry -----
98 //toolStack->setCurrentIndex(cfg.value("Tool/Stack/current",0).toInt());
99 toolBox->setCurrentIndex(cfg.value("Tool/Box/current", 0).toInt());
100 actionShowToolHelp->setChecked(cfg.value("Tool/showHelp", true).toBool());
101 mapFont = cfg.value("Canvas/mapFont", font()).value<QFont>();
102 actionFlipMouseWheel->setChecked(cfg.value("Canvas/flipMouseWheel", false).toBool());
103 }
104
~CMainWindow()105 CMainWindow::~CMainWindow()
106 {
107 SETTINGS;
108 cfg.setValue("MainWindow/state", saveState());
109 cfg.setValue("MainWindow/geometry", saveGeometry());
110
111 cfg.setValue("Canvas/mapFont", mapFont);
112 cfg.setValue("Canvas/flipMouseWheel", actionFlipMouseWheel->isChecked());
113
114 cfg.setValue("Units/units", IUnit::self().type);
115 cfg.setValue("Units/coordFormat", IUnit::getCoordFormat());
116
117 cfg.setValue("Tool/Box/current", toolBox->currentIndex());
118 cfg.setValue("Tool/showHelp", actionShowToolHelp->isChecked());
119 }
120
getUser()121 QString CMainWindow::getUser()
122 {
123 QString user = getenv("USER");
124 if(user.isEmpty())
125 {
126 user = getenv("USERNAME"); //for windows
127
128 if(user.isEmpty())
129 {
130 user = "QMapTool";
131 }
132 }
133
134 return user;
135 }
136
prepareMenuForMac()137 void CMainWindow::prepareMenuForMac()
138 {
139 dockTools->toggleViewAction()->setMenuRole(QAction::NoRole);
140 }
141
makeShellVisible()142 void CMainWindow::makeShellVisible()
143 {
144 dockShell->show();
145 }
146
startGridTool(CItemRefMap * item)147 void CMainWindow::startGridTool(CItemRefMap* item)
148 {
149 toolGrid->registerItem(item);
150 toolStack->setCurrentWidget(toolGrid);
151 }
152
showToolBox()153 void CMainWindow::showToolBox()
154 {
155 toolStack->setCurrentWidget(toolBox);
156 }
157
slotAbout()158 void CMainWindow::slotAbout()
159 {
160 CAbout dlg(this);
161 dlg.exec();
162 }
163
slotSetupExtTools()164 void CMainWindow::slotSetupExtTools()
165 {
166 CSetupExtTools dlg(this);
167 dlg.exec();
168 }
169
slotSetupUnits()170 void CMainWindow::slotSetupUnits()
171 {
172 CUnitsSetup dlg(this);
173 dlg.exec();
174 }
175
slotSetupCoordFormat()176 void CMainWindow::slotSetupCoordFormat()
177 {
178 CCoordFormatSetup dlg(this);
179 dlg.exec();
180 }
181
slotSetupChanged()182 void CMainWindow::slotSetupChanged()
183 {
184 toolStack->setupChanged();
185 }
186
slotHelp()187 void CMainWindow::slotHelp()
188 {
189 if(help.isNull())
190 {
191 help = new CHelp(
192 IAppSetup::self().helpFile(),
193 "qthelp://qmt/doc/doc/html/QMapTool/QMTDocMain.html",
194 this
195 );
196 addDockWidget(Qt::AllDockWidgetAreas, help);
197 }
198
199 help->setVisible(true);
200 }
201