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

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