]> Shamusworld >> Repos - guemap/blob - src/mainwin.cpp
b12ab24ab8a4891a417735185550a0f232a657a7
[guemap] / src / mainwin.cpp
1 //
2 // GUEmap
3 // Copyright 1997-2007 by Christopher J. Madsen
4 // (C) 2019 James Hammons
5 //
6 // GUEmap is licensed under either version 2 of the GPL, or (at your option)
7 // any later version.  See LICENSE file for details.
8 //
9 // mainwin.cpp: implementation of the MainWin class
10 //
11
12 #include "mainwin.h"
13 #include "about.h"
14 #include "file.h"
15 #include "globals.h"
16 #include "mapdoc.h"
17 #include "mapview.h"
18 #include "roomwidget.h"
19 #include "undo.h"
20
21
22 // CMainWin
23
24 #if 0
25 IMPLEMENT_DYNAMIC(CMainWin, CMDIFrameWnd)
26
27 BEGIN_MESSAGE_MAP(CMainWin, CMDIFrameWnd)
28         //{{AFX_MSG_MAP(CMainWin)
29         ON_WM_ACTIVATEAPP()
30         ON_WM_CREATE()
31         ON_WM_DESTROY()
32         //}}AFX_MSG_MAP
33         // Global help commands
34         ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
35         ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
36         ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
37         ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
38   // Toggle the navigation bar:
39   ON_UPDATE_COMMAND_UI(ID_VIEW_NAVBAR, OnUpdateControlBarMenu)
40   ON_COMMAND_EX(ID_VIEW_NAVBAR, OnBarCheck)
41 END_MESSAGE_MAP();
42
43 static UINT indicators[] =
44 {
45         ID_SEPARATOR,           // status line indicator
46         ID_INDICATOR_CAPS,
47         ID_INDICATOR_NUM,
48         ID_INDICATOR_SCRL,
49 };
50 #endif
51
52
53 MainWin::MainWin(): settings("Underground Software", "GUEmap")
54 {
55         setCentralWidget(&mdiArea);
56         mdiArea.setViewMode(QMdiArea::TabbedView);
57         mdiArea.setTabsClosable(true);
58
59         setWindowIcon(QIcon(":/res/guemap.ico"));
60         setWindowTitle("GUEmap");
61
62         aboutWin = new AboutWindow(this);
63
64         CreateActions();
65         CreateMenus();
66         CreateToolbars();
67
68         undoAct->setEnabled(false);
69         statusBar()->showMessage(tr("Ready"));
70
71         ReadSettings();
72
73         // Create Dock widgets
74         QDockWidget * dock1 = new QDockWidget(tr("Rooms"), this);
75         /*RoomWidget * */rw = new RoomWidget;
76         dock1->setWidget(rw);
77         addDockWidget(Qt::RightDockWidgetArea, dock1);
78 //      QDockWidget * dock2 = new QDockWidget(tr("Blocks"), this);
79 //      BlockWidget * bw = new BlockWidget;
80 //      dock2->setWidget(bw);
81 //      addDockWidget(Qt::RightDockWidgetArea, dock2);
82 //      QDockWidget * dock3 = new QDockWidget(tr("Object"), this);
83 //      ObjectWidget * ow = new ObjectWidget;
84 //      dock3->setWidget(ow);
85 //      addDockWidget(Qt::RightDockWidgetArea, dock3);
86         // Needed for saveState()
87         dock1->setObjectName("Rooms");
88 //      dock2->setObjectName("Blocks");
89 //      dock3->setObjectName("Object");
90
91         // Create status bar
92 //      zoomIndicator = new QLabel("Grid: 12.0\" BU: Inch");
93 //      statusBar()->addPermanentWidget(zoomIndicator);
94 //      statusBar()->showMessage(tr("Ready"));
95
96 //      ReadSettings();
97 //      setUnifiedTitleAndToolBarOnMac(true);
98 //      Global::font =  new QFont("Verdana", 15, QFont::Bold);
99
100 //      connect(lw, SIGNAL(LayerDeleted(int)), drawing, SLOT(DeleteCurrentLayer(int)));
101 //      connect(lw, SIGNAL(LayerToggled()), drawing, SLOT(HandleLayerToggle()));
102 //      connect(lw, SIGNAL(LayersSwapped(int, int)), drawing, SLOT(HandleLayerSwap(int, int)));
103
104 //      connect(drawing, SIGNAL(ObjectHovered(Object *)), ow, SLOT(ShowInfo(Object *)));
105
106 }
107
108
109 void MainWin::closeEvent(QCloseEvent * event)
110 {
111         WriteSettings();
112         event->accept();                // Use ignore() if can't close for some reason
113         //Do we have a memory leak here if we don't delete the font in the Object???
114 }
115
116
117 void MainWin::FileNew(void)
118 {
119         MapView * map = new MapView;
120         map->setWindowTitle("Untitled");
121         map->clearSelection();
122         QMdiSubWindow * sw = mdiArea.addSubWindow(map);
123         mdiArea.setActiveSubWindow(sw);
124         sw->showMaximized();
125         sw->update();
126
127         connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int)));
128
129         statusBar()->showMessage(tr("New map created."), 2000);
130 }
131
132
133 void MainWin::FileOpen(void)
134 {
135         QString filename = QFileDialog::getOpenFileName(this, tr("Open Map"), "",
136                 tr("GUEmap files (*.gmp)"));
137
138         // User cancelled open
139         if (filename.isEmpty())
140                 return;
141
142         MapView * map = new MapView;
143         bool successful = ReadFile(map->doc, filename.toUtf8().data());
144
145         if (!successful)
146         {
147                 // Make sure to delete any hanging objects in the container...
148                 delete map;
149
150                 QMessageBox msg;
151                 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
152                 msg.setIcon(QMessageBox::Critical);
153                 msg.exec();
154                 return;
155         }
156
157         map->doc->filename = filename.toStdString();
158         map->setWindowTitle(map->doc->name.c_str());
159         map->clearSelection();
160         QMdiSubWindow * sw = mdiArea.addSubWindow(map);
161         mdiArea.setActiveSubWindow(sw);
162         sw->showMaximized();
163         sw->update();
164
165         connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int)));
166
167         statusBar()->showMessage(tr("Map loaded."), 2000);
168 }
169
170
171 void MainWin::FileSaveBase(MapView * map, QString filename)
172 {
173         if (filename.endsWith(".gmp") == false)
174                 filename += ".gmp";
175
176         bool successful = WriteFile(map->doc, filename.toUtf8().data());
177
178         if (!successful)
179         {
180                 // In this case, we should unlink the created file, since it's not
181                 // right...
182                 QFile::remove(filename);
183
184                 QMessageBox msg;
185                 msg.setText(QString(tr("Could not save file \"%1\"!")).arg(filename));
186                 msg.setIcon(QMessageBox::Critical);
187                 msg.exec();
188                 return;
189         }
190
191         map->doc->filename = filename.toStdString();
192         map->doc->isDirty = false;
193         statusBar()->showMessage(tr("Map saved."), 2000);
194 }
195
196
197 void MainWin::FileSave(void)
198 {
199         QMdiSubWindow * sw = mdiArea.activeSubWindow();
200         MapView * map = (MapView *)(sw->widget());
201         QString filename = map->doc->filename.c_str();
202
203         if (filename.isEmpty())
204         {
205                 filename = QFileDialog::getSaveFileName(this, tr("Save Map"), "",
206                         tr("GUEmap maps (*.gmp)"));
207
208                 // Bail if the user clicked "Cancel"
209                 if (filename.isEmpty())
210                         return;
211         }
212
213         FileSaveBase(map, filename);
214 }
215
216
217 void MainWin::FileSaveAs(void)
218 {
219         QMdiSubWindow * sw = mdiArea.activeSubWindow();
220         MapView * map = (MapView *)(sw->widget());
221 //      QString filename = map->doc->filename.c_str();
222
223         QString filename = QFileDialog::getSaveFileName(this, tr("Save Map As"),
224                 map->doc->filename.c_str(), tr("GUEmap maps (*.gmp)"));
225
226         // Bail if the user clicked "Cancel"
227         if (filename.isEmpty())
228                 return;
229
230         FileSaveBase(map, filename);
231 }
232
233
234 void MainWin::FileClose(void)
235 {
236         QMdiSubWindow * sw = mdiArea.activeSubWindow();
237         MapView * map = (MapView *)(sw->widget());
238
239         if (map->doc->isDirty)
240         {
241                 QMessageBox msg;
242                 msg.setText(tr("The map has been modified."));
243                 msg.setInformativeText(tr("Do you want to save your changes?"));
244                 msg.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
245                 msg.setDefaultButton(QMessageBox::Save);
246                 msg.setIcon(QMessageBox::Warning);
247
248                 int response = msg.exec();
249
250                 if (response == QMessageBox::Save)
251                         FileSave();
252         }
253
254         sw->close();
255         statusBar()->showMessage(tr("Map closed."), 2000);
256 }
257
258
259 void MainWin::EditUndo(void)
260 {
261         QMdiSubWindow * sw = mdiArea.activeSubWindow();
262
263         if (sw == 0)
264                 return;
265
266         MapView * map = (MapView *)(sw->widget());
267
268         if (map == 0)
269                 return;
270
271         if (map->doc->undoData != 0)
272         {
273                 map->doc->setUndoData(map->doc->undoData->undo(*(map->doc)));
274                 statusBar()->showMessage(tr("Undo successful."));
275                 map->update();
276                 return;
277         }
278
279         statusBar()->showMessage(tr("Ready."));
280 }
281
282
283 void MainWin::MenuFixUndo(void)
284 {
285         QMdiSubWindow * sw = mdiArea.activeSubWindow();
286
287         if (sw == 0)
288                 return;
289
290         MapView * map = (MapView *)(sw->widget());
291         UndoRec * undo = map->doc->undoData;
292
293         if (undo)
294         {
295                 undoAct->setText(QString(tr("&Undo %1")).arg(undo->getName()));
296                 undoAct->setEnabled(true);
297         }
298         else
299         {
300                 undoAct->setText(tr("Can't Undo"));
301                 undoAct->setEnabled(false);
302         }
303 }
304
305
306 void MainWin::EditDelete(void)
307 {
308         QMdiSubWindow * sw = mdiArea.activeSubWindow();
309
310         if (sw == 0)
311                 return;
312
313         MapView * map = (MapView *)(sw->widget());
314
315         if (map == 0)
316                 return;
317
318         map->deleteSelection();
319         map->update();
320 }
321
322
323 void MainWin::EditSelectAll(void)
324 {
325         QMdiSubWindow * sw = mdiArea.activeSubWindow();
326
327         if (sw == 0)
328                 return;
329
330         MapView * map = (MapView *)(sw->widget());
331
332         if (map == 0)
333                 return;
334
335         for(int i=map->doc->room.size()-1; i>=0; i--)
336                 map->selectRoom(i);
337
338         map->update();
339 }
340
341
342 void MainWin::HelpAbout(void)
343 {
344         aboutWin->show();
345 }
346
347
348 void MainWin::CreateActions(void)
349 {
350         fileNewAct = CreateAction(tr("&New Map"), tr("New Map"), tr("Creates a new map."), QIcon(":/res/file-new.png"), QKeySequence(tr("Ctrl+n")));
351         connect(fileNewAct, SIGNAL(triggered()), this, SLOT(FileNew()));
352
353         fileOpenAct = CreateAction(tr("&Open Map"), tr("Open Map"), tr("Opens an existing map from a file."), QIcon(":/res/file-open.png"), QKeySequence(tr("Ctrl+o")));
354         connect(fileOpenAct, SIGNAL(triggered()), this, SLOT(FileOpen()));
355
356         fileSaveAct = CreateAction(tr("&Save Map"), tr("Save Map"), tr("Saves the current map to a file."), QIcon(":/res/file-save.png"), QKeySequence(tr("Ctrl+s")));
357         connect(fileSaveAct, SIGNAL(triggered()), this, SLOT(FileSave()));
358
359         fileSaveAsAct = CreateAction(tr("Save Map &As"), tr("Save As"), tr("Saves the current map to a file with a different name."), QIcon(":/res/file-save-as.png"), QKeySequence(tr("Ctrl+Shift+s")));
360         connect(fileSaveAsAct, SIGNAL(triggered()), this, SLOT(FileSaveAs()));
361
362         fileCloseAct = CreateAction(tr("&Close Map"), tr("Close Map"), tr("Closes the current map."), QIcon(":/res/file-close.png"), QKeySequence(tr("Ctrl+c")));
363         connect(fileCloseAct, SIGNAL(triggered()), this, SLOT(FileClose()));
364
365         exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."), QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
366         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
367
368         undoAct = CreateAction(tr("&Undo"), tr("Undo"), tr("Undoes the last action."), QIcon(), QKeySequence(tr("Ctrl+z")));
369         connect(undoAct, SIGNAL(triggered()), this, SLOT(EditUndo()));
370
371         deleteAct = CreateAction(tr("&Delete"), tr("Delete"), tr("Deletes the selected items."), QIcon(), QKeySequence(tr("Delete")));
372         connect(deleteAct, SIGNAL(triggered()), this, SLOT(EditDelete()));
373
374         selectAllAct = CreateAction(tr("Select &All"), tr("Select All"), tr("Selects all items."), QIcon(), QKeySequence(tr("Ctrl+a")));
375         connect(selectAllAct, SIGNAL(triggered()), this, SLOT(EditSelectAll()));
376
377         aboutAct = CreateAction(tr("About &GUEmap"), tr("About GUEmap"), tr("Gives information about this program."), QIcon(), QKeySequence());
378         connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
379
380 #if 0
381         snapToGridAct = CreateAction(tr("Snap To &Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/snap-to-grid-tool.png"), QKeySequence(tr("S")), true);
382         connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
383
384         fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
385                 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
386         connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
387
388         fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
389                 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
390         connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
391
392         deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true);
393         connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
394
395         addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
396         connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
397
398         addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true);
399         connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
400
401         addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true);
402         connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
403
404         addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true);
405         connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool()));
406
407         addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true);
408         connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool()));
409
410         addSplineAct = CreateAction(tr("Add &Spline"), tr("Add Spline"), tr("Add a NURB spline to the drawing."), QIcon(":/res/add-spline-tool.png"), QKeySequence("A,S"), true);
411         connect(addSplineAct, SIGNAL(triggered()), this, SLOT(AddSplineTool()));
412
413         rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/rotate-tool.png"), QKeySequence(tr("R,O")), true);
414         connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
415
416         zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
417         connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
418
419         zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
420         connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
421
422         settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/settings.png"), QKeySequence());
423         connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
424
425         groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g"));
426         connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping()));
427
428         connectAct = CreateAction(tr("&Connect"), tr("Connect"), tr("Connect objects at point."), QIcon(":/res/connect-tool.png"), QKeySequence("c,c"));
429         connect(connectAct, SIGNAL(triggered()), this, SLOT(HandleConnection()));
430
431         disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d"));
432         connect(disconnectAct, SIGNAL(triggered()), this, SLOT(HandleDisconnection()));
433
434         mirrorAct = CreateAction(tr("&Mirror"), tr("Mirror"), tr("Mirror selected objects around a line."), QIcon(":/res/mirror-tool.png"), QKeySequence("m,i"), true);
435         connect(mirrorAct, SIGNAL(triggered()), this, SLOT(MirrorTool()));
436
437         trimAct = CreateAction(tr("&Trim"), tr("Trim"), tr("Trim extraneous lines from selected objects."), QIcon(":/res/trim-tool.png"), QKeySequence("t,r"), true);
438         connect(trimAct, SIGNAL(triggered()), this, SLOT(TrimTool()));
439
440         triangulateAct = CreateAction(tr("&Triangulate"), tr("Triangulate"), tr("Make triangles from selected lines, preserving their lengths."), QIcon(":/res/triangulate-tool.png"), QKeySequence("t,g"), true);
441         connect(triangulateAct, SIGNAL(triggered()), this, SLOT(TriangulateTool()));
442 #endif
443 }
444
445
446 void MainWin::CreateMenus(void)
447 {
448         QMenu * menu = menuBar()->addMenu(tr("&File"));
449         menu->addAction(fileNewAct);
450         menu->addAction(fileOpenAct);
451         menu->addAction(fileSaveAct);
452         menu->addAction(fileSaveAsAct);
453         menu->addAction(fileCloseAct);
454         menu->addSeparator();
455         menu->addAction(exitAct);
456
457         menu = menuBar()->addMenu(tr("&Edit"));
458         menu->addAction(undoAct);
459         connect(menu, SIGNAL(aboutToShow()), this, SLOT(MenuFixUndo()));
460         menu->addSeparator();
461         menu->addAction(deleteAct);
462         menu->addAction(selectAllAct);
463 #if 0
464         menu = menuBar()->addMenu(tr("&View"));
465         menu->addAction(zoomInAct);
466         menu->addAction(zoomOutAct);
467
468         // EDIT
469         menu->addAction(snapToGridAct);
470         menu->addAction(groupAct);
471         menu->addAction(fixAngleAct);
472         menu->addAction(fixLengthAct);
473         menu->addAction(rotateAct);
474         menu->addAction(mirrorAct);
475         menu->addAction(trimAct);
476         menu->addAction(triangulateAct);
477         menu->addAction(connectAct);
478         menu->addAction(disconnectAct);
479         menu->addSeparator();
480         menu->addAction(addLineAct);
481         menu->addAction(addCircleAct);
482         menu->addAction(addArcAct);
483         menu->addAction(addPolygonAct);
484         menu->addAction(addSplineAct);
485         menu->addAction(addDimensionAct);
486         menu->addSeparator();
487         menu->addAction(settingsAct);
488 #endif
489
490         menu = menuBar()->addMenu(tr("&Help"));
491         menu->addAction(aboutAct);
492 }
493
494
495 void MainWin::CreateToolbars(void)
496 {
497 #if 0
498         QToolBar * toolbar = addToolBar(tr("File"));
499         toolbar->setObjectName("File"); // Needed for saveState()
500         toolbar->addAction(fileNewAct);
501         toolbar->addAction(fileOpenAct);
502         toolbar->addAction(fileSaveAct);
503         toolbar->addAction(fileSaveAsAct);
504         toolbar->addAction(fileCloseAct);
505 //      toolbar->addAction(exitAct);
506
507         toolbar = addToolBar(tr("View"));
508         toolbar->setObjectName("View");
509         toolbar->addAction(zoomInAct);
510         toolbar->addAction(zoomOutAct);
511
512         QSpinBox * spinbox = new QSpinBox;
513         toolbar->addWidget(spinbox);
514 //      QLineEdit * lineedit = new QLineEdit;
515         toolbar->addWidget(baseUnitInput);
516         toolbar->addWidget(dimensionSizeInput);
517
518         toolbar = addToolBar(tr("Edit"));
519         toolbar->setObjectName("Edit");
520         toolbar->addAction(snapToGridAct);
521         toolbar->addAction(groupAct);
522         toolbar->addAction(fixAngleAct);
523         toolbar->addAction(fixLengthAct);
524         toolbar->addAction(rotateAct);
525         toolbar->addAction(mirrorAct);
526         toolbar->addAction(trimAct);
527         toolbar->addAction(triangulateAct);
528         toolbar->addAction(deleteAct);
529         toolbar->addAction(connectAct);
530         toolbar->addAction(disconnectAct);
531         toolbar->addSeparator();
532         toolbar->addAction(addLineAct);
533         toolbar->addAction(addCircleAct);
534         toolbar->addAction(addArcAct);
535         toolbar->addAction(addPolygonAct);
536         toolbar->addAction(addSplineAct);
537         toolbar->addAction(addDimensionAct);
538
539         spinbox->setRange(4, 256);
540         spinbox->setValue(12);
541         baseUnitInput->setText("12");
542         connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int)));
543         connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString)));
544         connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString)));
545
546         PenWidget * pw = new PenWidget();
547         toolbar = addToolBar(tr("Pen"));
548         toolbar->setObjectName(tr("Pen"));
549         toolbar->addWidget(pw);
550         connect(drawing, SIGNAL(ObjectSelected(Object *)), pw, SLOT(SetFields(Object *)));
551         connect(pw, SIGNAL(WidthSelected(float)), drawing, SLOT(HandlePenWidth(float)));
552         connect(pw, SIGNAL(StyleSelected(int)), drawing, SLOT(HandlePenStyle(int)));
553         connect(pw, SIGNAL(ColorSelected(uint32_t)), drawing, SLOT(HandlePenColor(uint32_t)));
554 #endif
555 }
556
557
558 void MainWin::ReadSettings(void)
559 {
560         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
561         QSize size = settings.value("size", QSize(400, 400)).toSize();
562 //      drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
563 //      snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
564         resize(size);
565         move(pos);
566         restoreState(settings.value("windowState").toByteArray());
567 }
568
569
570 void MainWin::WriteSettings(void)
571 {
572         settings.setValue("pos", pos());
573         settings.setValue("size", size());
574         settings.setValue("windowState", saveState());
575 //      settings.setValue("useAntialiasing", drawing->useAntialiasing);
576 //      settings.setValue("snapToGrid", snapToGridAct->isChecked());
577 }
578
579
580 #if 0
581 int MainWin::OnCreate(LPCREATESTRUCT lpCreateStruct)
582 {
583         if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
584                 return -1;
585
586         if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
587         {
588                 TRACE0("Failed to create toolbar\n");
589                 return -1;      // fail to create
590         }
591
592         if (!wndNavBar.Create(this, IDD_NAVBAR, CBRS_TOP, ID_VIEW_NAVBAR))
593         {
594                 TRACE0("Failed to create navigation bar\n");
595                 return -1;      // fail to create
596         }
597
598         if (!m_wndStatusBar.Create(this)
599                 || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)))
600         {
601                 TRACE0("Failed to create status bar\n");
602                 return -1;      // fail to create
603         }
604
605
606         // Add tool tips and resizeable toolbar:
607         m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
608         // Make toolbar dockable:
609         m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
610         EnableDocking(CBRS_ALIGN_ANY);
611         DockControlBar(&m_wndToolBar);
612
613         wndNavBar.SetBarStyle(wndNavBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
614         wndNavBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
615         DockControlBarLeftOf(&wndNavBar, &m_wndToolBar);
616
617         // Restore toolbar state:
618         CDockState state;
619         state.LoadState("Toolbars");
620         SetDockState(state);
621
622         return 0;
623 }
624
625
626 void MainWin::OnDestroy()
627 {
628         CDockState  state;
629
630         GetDockState(state);
631         state.SaveState("Toolbars");
632
633         WINDOWPLACEMENT pos;
634         GetWindowPlacement(&pos);
635         static_cast<CMapApp *>(AfxGetApp())->saveWindowPos(&pos.rcNormalPosition, iniMainWin);
636
637         CMDIFrameWnd::OnDestroy();
638 }
639
640
641 bool MainWin::PreCreateWindow(CREATESTRUCT & cs)
642 {
643         // TODO: Modify the Window class or styles here by modifying
644         //  the CREATESTRUCT cs
645
646         return CMDIFrameWnd::PreCreateWindow(cs);
647 }
648
649
650 /////////////////////////////////////////////////////////////////////////////
651 // CMainWin message handlers
652 //--------------------------------------------------------------------
653 // Keep track of whether we should be eating mouse clicks:
654
655 void MainWin::OnActivateApp(bool bActive, HTASK task)
656 {
657         GUEmapEatClicks = !bActive;
658         CMDIFrameWnd::OnActivateApp(bActive, task);
659 }
660
661
662 /////////////////////////////////////////////////////////////////////////////
663 // Dock control bars on the same line:
664 //
665 // Taken from \MSDev\Samples\MFC\General\DockTool\MainFrm.cpp
666
667 void MainWin::DockControlBarLeftOf(CControlBar * Bar, CControlBar * LeftOf)
668 {
669         CRect rect;
670         DWORD dw;
671         UINT n;
672
673         // get MFC to adjust the dimensions of all docked ToolBars
674         // so that GetWindowRect will be accurate
675         RecalcLayout();
676         LeftOf->GetWindowRect(&rect);
677         rect.OffsetRect(1, 0);
678         dw = LeftOf->GetBarStyle();
679
680         n = 0;
681         n = (dw & CBRS_ALIGN_TOP ? AFX_IDW_DOCKBAR_TOP : n);
682         n = (dw & CBRS_ALIGN_BOTTOM && n == 0 ? AFX_IDW_DOCKBAR_BOTTOM : n);
683         n = (dw & CBRS_ALIGN_LEFT && n == 0 ? AFX_IDW_DOCKBAR_LEFT : n);
684         n = (dw & CBRS_ALIGN_RIGHT && n == 0 ? AFX_IDW_DOCKBAR_RIGHT : n);
685
686         // When we take the default parameters on rect, DockControlBar will dock
687         // each Toolbar on a seperate line.  By calculating a rectangle, we in effect
688         // are simulating a Toolbar being dragged to that location and docked.
689         DockControlBar(Bar, n, &rect);
690 }
691 #endif
692