source: ntrip/trunk/GnssCenter/main/mainwin.cpp@ 5056

Last change on this file since 5056 was 5056, checked in by mervart, 9 years ago
File size: 4.6 KB
Line 
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
22using namespace std;
23using namespace GnssCenter;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27t_mainWin::t_mainWin(QWidget* parent, Qt::WindowFlags flags) :
28 QMainWindow(parent, flags) {
29
30 _mdi = new t_mdiArea(0);
31 setCentralWidget(_mdi);
32
33 createMenu();
34 createToolBar();
35 createStatusBar();
36
37 // Handle Plugins
38 // --------------
39 QDir pluginsDir = QDir(qApp->applicationDirPath());
40
41 pluginsDir.cd("plugins");
42
43 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
44 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
45 QObject* object = loader.instance();
46 if (object) {
47 t_pluginFactoryInterface* plugin = qobject_cast<t_pluginFactoryInterface*>(object);
48 if (plugin) {
49 t_pluginAction* action = new t_pluginAction(this, plugin);
50 _menuPlugins->addAction(action);
51 connect(action, SIGNAL(triggered()), SLOT(slotStartPlugin()));
52 }
53 }
54 }
55
56}
57
58// Destructor
59////////////////////////////////////////////////////////////////////////////
60t_mainWin::~t_mainWin() {
61}
62
63//
64////////////////////////////////////////////////////////////////////////////
65void t_mainWin::createToolBar() {
66 _fileToolBar = addToolBar(tr("File"));
67 _editToolBar = addToolBar(tr("Edit"));
68}
69
70//
71////////////////////////////////////////////////////////////////////////////
72void t_mainWin::createStatusBar() {
73 statusBar()->showMessage(tr("Ready"));
74}
75
76//
77////////////////////////////////////////////////////////////////////////////
78void t_mainWin::createMenu() {
79
80 // Create Actions
81 // --------------
82 QAction* actFontSel = new QAction(tr("Select &Font"),this);
83 connect(actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
84
85 QAction* actSaveOpt = new QAction(tr("&Save && Reread Configuration"),this);
86 connect(actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
87
88 QAction* actQuit = new QAction(tr("&Quit"),this);
89 connect(actQuit, SIGNAL(triggered()), SLOT(close()));
90
91 QAction* actHelp = new QAction(tr("&Help Contents"),this);
92 connect(actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
93
94 QAction* actAbout = new QAction(tr("&About"),this);
95 connect(actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
96
97 // Create Menu
98 // -----------
99 _menuFile = menuBar()->addMenu(tr("&File"));
100 _menuFile->addAction(actFontSel);
101 _menuFile->addSeparator();
102 _menuFile->addAction(actSaveOpt);
103 _menuFile->addSeparator();
104 _menuFile->addAction(actQuit);
105
106 _menuPlugins = menuBar()->addMenu(tr("&Plugins"));
107
108 _menuHlp = menuBar()->addMenu(tr("&Help"));
109 _menuHlp->addAction(actHelp);
110 _menuHlp->addAction(actAbout);
111}
112
113// Select Fonts
114////////////////////////////////////////////////////////////////////////////
115void t_mainWin::slotFontSel() {
116 bool ok;
117 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
118 if (ok) {
119 t_settings settings;
120 settings.setValue("font", newFont.toString());
121 QApplication::setFont(newFont);
122 }
123}
124
125// Save Options (serialize)
126////////////////////////////////////////////////////////////////////////////
127void t_mainWin::slotSaveOptions() {
128 t_settings settings;
129 settings.sync();
130}
131
132//
133////////////////////////////////////////////////////////////////////////////
134void t_mainWin::slotStartPlugin() {
135 qDebug() << "slotStartPlugin" << sender();
136// t_svgMap* svgMap = new t_svgMap();
137// QMdiSubWindow* win = _mdi->addSubWindow(svgMap);
138// win->show();
139}
140
141// Help Window
142////////////////////////////////////////////////////////////////////////////
143void t_mainWin::slotHelp() {
144}
145
146// About Message
147////////////////////////////////////////////////////////////////////////////
148void t_mainWin::slotAbout() {
149}
150
151// Close Application gracefully
152////////////////////////////////////////////////////////////////////////////
153void t_mainWin::closeEvent(QCloseEvent* event) {
154 int iRet = QMessageBox::question(this, "Close", "Save Options?",
155 QMessageBox::Yes, QMessageBox::No,
156 QMessageBox::Cancel);
157 if (iRet == QMessageBox::Cancel) {
158 event->ignore();
159 return;
160 }
161 else if (iRet == QMessageBox::Yes) {
162 slotSaveOptions();
163 }
164 QMainWindow::closeEvent(event);
165}
Note: See TracBrowser for help on using the repository browser.