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

Last change on this file since 5409 was 5118, checked in by mervart, 11 years ago
File size: 5.1 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 _toolBar = new QToolBar("Tool Bar", this);
68 _toolBar->addWidget(new QLabel("Tool Bar"));
69 addToolBar(Qt::BottomToolBarArea, _toolBar);
70}
71
72//
73////////////////////////////////////////////////////////////////////////////
74void t_mainWin::createStatusBar() {
75 statusBar()->addPermanentWidget(new QLabel("Status Bar"));
76}
77
78//
79////////////////////////////////////////////////////////////////////////////
80void t_mainWin::createMenu() {
81
82 // Create Actions
83 // --------------
84 QAction* actFontSel = new QAction(tr("Select &Font"),this);
85 connect(actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
86
87 QAction* actSaveOpt = new QAction(tr("&Save && Reread Configuration"),this);
88 connect(actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
89
90 QAction* actQuit = new QAction(tr("&Quit"),this);
91 connect(actQuit, SIGNAL(triggered()), SLOT(close()));
92
93 QAction* actHelp = new QAction(tr("&Help Contents"),this);
94 connect(actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
95
96 QAction* actAbout = new QAction(tr("&About"),this);
97 connect(actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
98
99 // Create Menu
100 // -----------
101 _menuFile = menuBar()->addMenu(tr("&File"));
102 _menuFile->addAction(actFontSel);
103 _menuFile->addSeparator();
104 _menuFile->addAction(actSaveOpt);
105 _menuFile->addSeparator();
106 _menuFile->addAction(actQuit);
107
108 _menuPlugins = menuBar()->addMenu(tr("&Plugins"));
109
110 _menuHlp = menuBar()->addMenu(tr("&Help"));
111 _menuHlp->addAction(actHelp);
112 _menuHlp->addAction(actAbout);
113}
114
115// Select Fonts
116////////////////////////////////////////////////////////////////////////////
117void t_mainWin::slotFontSel() {
118 bool ok;
119 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
120 if (ok) {
121 t_settings settings;
122 settings.setValue("font", newFont.toString());
123 QApplication::setFont(newFont);
124 }
125}
126
127// Save Options (serialize)
128////////////////////////////////////////////////////////////////////////////
129void t_mainWin::slotSaveOptions() {
130 t_settings settings;
131 settings.sync();
132}
133
134//
135////////////////////////////////////////////////////////////////////////////
136void t_mainWin::slotStartPlugin() {
137 t_pluginAction* action = dynamic_cast<t_pluginAction*>(sender());
138 QWidget* widget = action->_factIface->create();
139 t_app* app = dynamic_cast<t_app*>(qApp);
140 if (app) {
141 const QMetaObject* metaObj = widget->metaObject();
142 QByteArray bncMessageName = QMetaObject::normalizedSignature("bncMessage(QByteArray)");
143 if (metaObj->indexOfSignal(bncMessageName) != -1) {
144 connect(widget, SIGNAL(bncMessage(QByteArray)), app, SLOT(slotMessage(QByteArray)));
145 }
146 }
147 widget->setMinimumSize(500, 300);
148 QMdiSubWindow* subWindow = _mdi->addSubWindow((QWidget*) widget);
149 subWindow->show();
150}
151
152// Help Window
153////////////////////////////////////////////////////////////////////////////
154void t_mainWin::slotHelp() {
155}
156
157// About Message
158////////////////////////////////////////////////////////////////////////////
159void t_mainWin::slotAbout() {
160}
161
162// Close Application gracefully
163////////////////////////////////////////////////////////////////////////////
164void t_mainWin::closeEvent(QCloseEvent* event) {
165 int iRet = QMessageBox::question(this, "Close", "Save Options?",
166 QMessageBox::Yes, QMessageBox::No,
167 QMessageBox::Cancel);
168 if (iRet == QMessageBox::Cancel) {
169 event->ignore();
170 return;
171 }
172 else if (iRet == QMessageBox::Yes) {
173 slotSaveOptions();
174 }
175 QMainWindow::closeEvent(event);
176}
Note: See TracBrowser for help on using the repository browser.