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

Last change on this file since 5060 was 5059, checked in by mervart, 12 years ago
File size: 4.7 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_pluginAction* action = dynamic_cast<t_pluginAction*>(sender());
137 qDebug() << "Action" << action;
138 QWidget* widget = action->_factIface->create();
139 QMdiSubWindow* subWindow = _mdi->addSubWindow((QWidget*) widget);
140 subWindow->show();
141}
142
143// Help Window
144////////////////////////////////////////////////////////////////////////////
145void t_mainWin::slotHelp() {
146}
147
148// About Message
149////////////////////////////////////////////////////////////////////////////
150void t_mainWin::slotAbout() {
151}
152
153// Close Application gracefully
154////////////////////////////////////////////////////////////////////////////
155void t_mainWin::closeEvent(QCloseEvent* event) {
156 int iRet = QMessageBox::question(this, "Close", "Save Options?",
157 QMessageBox::Yes, QMessageBox::No,
158 QMessageBox::Cancel);
159 if (iRet == QMessageBox::Cancel) {
160 event->ignore();
161 return;
162 }
163 else if (iRet == QMessageBox::Yes) {
164 slotSaveOptions();
165 }
166 QMainWindow::closeEvent(event);
167}
Note: See TracBrowser for help on using the repository browser.