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

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