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

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