1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * RTNet GUI
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: t_mainWin
|
---|
7 | *
|
---|
8 | * Purpose: Re-Implements QMainWindow
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 05-Jan-2013
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include "mainwin.h"
|
---|
19 | #include "settings.h"
|
---|
20 | #include "mdiarea.h"
|
---|
21 | #include "svgmap.h"
|
---|
22 | #include "inpedit/inpfile.h"
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 | using namespace RTGUI;
|
---|
26 |
|
---|
27 | // Constructor
|
---|
28 | ////////////////////////////////////////////////////////////////////////////
|
---|
29 | t_mainWin::t_mainWin(QWidget* parent, Qt::WindowFlags flags) :
|
---|
30 | QMainWindow(parent, flags) {
|
---|
31 |
|
---|
32 | _mdi = new t_mdiArea(0);
|
---|
33 | setCentralWidget(_mdi);
|
---|
34 |
|
---|
35 | createMenu();
|
---|
36 | createToolBar();
|
---|
37 | createStatusBar();
|
---|
38 | }
|
---|
39 |
|
---|
40 | // Destructor
|
---|
41 | ////////////////////////////////////////////////////////////////////////////
|
---|
42 | t_mainWin::~t_mainWin() {
|
---|
43 | }
|
---|
44 |
|
---|
45 | //
|
---|
46 | ////////////////////////////////////////////////////////////////////////////
|
---|
47 | void t_mainWin::createToolBar() {
|
---|
48 | _fileToolBar = addToolBar(tr("File"));
|
---|
49 | _editToolBar = addToolBar(tr("Edit"));
|
---|
50 | }
|
---|
51 |
|
---|
52 | //
|
---|
53 | ////////////////////////////////////////////////////////////////////////////
|
---|
54 | void t_mainWin::createStatusBar() {
|
---|
55 | statusBar()->showMessage(tr("Ready"));
|
---|
56 | }
|
---|
57 |
|
---|
58 | //
|
---|
59 | ////////////////////////////////////////////////////////////////////////////
|
---|
60 | void t_mainWin::createMenu() {
|
---|
61 |
|
---|
62 | // Create Actions
|
---|
63 | // --------------
|
---|
64 | _actFontSel = new QAction(tr("Select &Font"),this);
|
---|
65 | connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
|
---|
66 |
|
---|
67 | _actSaveOpt = new QAction(tr("&Save && Reread Configuration"),this);
|
---|
68 | connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
|
---|
69 |
|
---|
70 | _actQuit = new QAction(tr("&Quit"),this);
|
---|
71 | connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
|
---|
72 |
|
---|
73 | _actEditInput = new QAction(tr("&Edit Input File"),this);
|
---|
74 | connect(_actEditInput, SIGNAL(triggered()), SLOT(slotEditInput()));
|
---|
75 |
|
---|
76 | _actMap = new QAction(tr("Show &Map"),this);
|
---|
77 | connect(_actMap, SIGNAL(triggered()), SLOT(slotMap()));
|
---|
78 |
|
---|
79 | _actHelp = new QAction(tr("&Help Contents"),this);
|
---|
80 | connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
|
---|
81 |
|
---|
82 | _actAbout = new QAction(tr("&About"),this);
|
---|
83 | connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
|
---|
84 |
|
---|
85 | // Create Menu
|
---|
86 | // -----------
|
---|
87 | _menuFile = menuBar()->addMenu(tr("&File"));
|
---|
88 | _menuFile->addAction(_actFontSel);
|
---|
89 | _menuFile->addSeparator();
|
---|
90 | _menuFile->addAction(_actSaveOpt);
|
---|
91 | _menuFile->addSeparator();
|
---|
92 | _menuFile->addAction(_actQuit);
|
---|
93 |
|
---|
94 | _menuNew = menuBar()->addMenu(tr("&New"));
|
---|
95 | _menuNew->addAction(_actEditInput);
|
---|
96 | _menuNew->addAction(_actMap);
|
---|
97 |
|
---|
98 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
---|
99 | _menuHlp->addAction(_actHelp);
|
---|
100 | _menuHlp->addAction(_actAbout);
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Select Fonts
|
---|
104 | ////////////////////////////////////////////////////////////////////////////
|
---|
105 | void t_mainWin::slotFontSel() {
|
---|
106 | bool ok;
|
---|
107 | QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
|
---|
108 | if (ok) {
|
---|
109 | t_settings settings;
|
---|
110 | settings.setValue("font", newFont.toString());
|
---|
111 | QApplication::setFont(newFont);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | // Save Options (serialize)
|
---|
116 | ////////////////////////////////////////////////////////////////////////////
|
---|
117 | void t_mainWin::slotSaveOptions() {
|
---|
118 | t_settings settings;
|
---|
119 | settings.sync();
|
---|
120 | }
|
---|
121 |
|
---|
122 | // Edit RTNet Input File
|
---|
123 | ////////////////////////////////////////////////////////////////////////////
|
---|
124 | void t_mainWin::slotEditInput() {
|
---|
125 | QString fileName = QFileDialog::getOpenFileName(this);
|
---|
126 | if (!fileName.isEmpty()) {
|
---|
127 | t_inpFile* inpFile = new t_inpFile(fileName);
|
---|
128 | QMdiSubWindow* win = _mdi->addSubWindow(inpFile);
|
---|
129 | win->show();
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | // Edit RTNet Input File
|
---|
134 | ////////////////////////////////////////////////////////////////////////////
|
---|
135 | void t_mainWin::slotMap() {
|
---|
136 | t_svgMap* svgMap = new t_svgMap();
|
---|
137 | svgMap->setMinimumSize(600, 400);
|
---|
138 | QMdiSubWindow* win = _mdi->addSubWindow(svgMap);
|
---|
139 | win->show();
|
---|
140 | }
|
---|
141 |
|
---|
142 | // Help Window
|
---|
143 | ////////////////////////////////////////////////////////////////////////////
|
---|
144 | void t_mainWin::slotHelp() {
|
---|
145 | }
|
---|
146 |
|
---|
147 | // About Message
|
---|
148 | ////////////////////////////////////////////////////////////////////////////
|
---|
149 | void t_mainWin::slotAbout() {
|
---|
150 | }
|
---|
151 |
|
---|
152 | // Close Application gracefully
|
---|
153 | ////////////////////////////////////////////////////////////////////////////
|
---|
154 | void t_mainWin::closeEvent(QCloseEvent* event) {
|
---|
155 | int iRet = QMessageBox::question(this, "Close", "Save Options?",
|
---|
156 | QMessageBox::Yes, QMessageBox::No,
|
---|
157 | QMessageBox::Cancel);
|
---|
158 | if (iRet == QMessageBox::Cancel) {
|
---|
159 | event->ignore();
|
---|
160 | return;
|
---|
161 | }
|
---|
162 | else if (iRet == QMessageBox::Yes) {
|
---|
163 | slotSaveOptions();
|
---|
164 | }
|
---|
165 | QMainWindow::closeEvent(event);
|
---|
166 | }
|
---|