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

Last change on this file since 5118 was 5118, checked in by mervart, 11 years ago
File size: 5.1 KB
RevLine 
[4815]1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
[4860]6 * Class: t_mainWin
[4815]7 *
8 * Purpose: Re-Implements QMainWindow
9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
[4860]18#include "mainwin.h"
19#include "settings.h"
20#include "mdiarea.h"
[5086]21#include "app.h"
[4815]22
23using namespace std;
[5001]24using namespace GnssCenter;
[4815]25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
[4860]28t_mainWin::t_mainWin(QWidget* parent, Qt::WindowFlags flags) :
[4815]29 QMainWindow(parent, flags) {
[4817]30
[4860]31 _mdi = new t_mdiArea(0);
[4818]32 setCentralWidget(_mdi);
33
[5055]34 createMenu();
35 createToolBar();
36 createStatusBar();
37
[5039]38 // Handle Plugins
39 // --------------
40 QDir pluginsDir = QDir(qApp->applicationDirPath());
[5041]41
42 pluginsDir.cd("plugins");
[5039]43
44 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
45 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
[5042]46 QObject* object = loader.instance();
47 if (object) {
[5052]48 t_pluginFactoryInterface* plugin = qobject_cast<t_pluginFactoryInterface*>(object);
[5045]49 if (plugin) {
[5056]50 t_pluginAction* action = new t_pluginAction(this, plugin);
51 _menuPlugins->addAction(action);
52 connect(action, SIGNAL(triggered()), SLOT(slotStartPlugin()));
[5045]53 }
[5042]54 }
[5016]55 }
56
[4815]57}
58
59// Destructor
60////////////////////////////////////////////////////////////////////////////
[4860]61t_mainWin::~t_mainWin() {
[4815]62}
[4817]63
64//
65////////////////////////////////////////////////////////////////////////////
[4860]66void t_mainWin::createToolBar() {
[5118]67 _toolBar = new QToolBar("Tool Bar", this);
68 _toolBar->addWidget(new QLabel("Tool Bar"));
69 addToolBar(Qt::BottomToolBarArea, _toolBar);
[4822]70}
71
72//
73////////////////////////////////////////////////////////////////////////////
[4860]74void t_mainWin::createStatusBar() {
[5118]75 statusBar()->addPermanentWidget(new QLabel("Status Bar"));
[4822]76}
77
78//
79////////////////////////////////////////////////////////////////////////////
[4860]80void t_mainWin::createMenu() {
[4817]81
82 // Create Actions
83 // --------------
[5056]84 QAction* actFontSel = new QAction(tr("Select &Font"),this);
85 connect(actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
[4817]86
[5056]87 QAction* actSaveOpt = new QAction(tr("&Save && Reread Configuration"),this);
88 connect(actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
[4817]89
[5056]90 QAction* actQuit = new QAction(tr("&Quit"),this);
91 connect(actQuit, SIGNAL(triggered()), SLOT(close()));
[4817]92
[5056]93 QAction* actHelp = new QAction(tr("&Help Contents"),this);
94 connect(actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
[4817]95
[5056]96 QAction* actAbout = new QAction(tr("&About"),this);
97 connect(actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
[4817]98
99 // Create Menu
100 // -----------
101 _menuFile = menuBar()->addMenu(tr("&File"));
[5056]102 _menuFile->addAction(actFontSel);
[4817]103 _menuFile->addSeparator();
[5056]104 _menuFile->addAction(actSaveOpt);
[4817]105 _menuFile->addSeparator();
[5056]106 _menuFile->addAction(actQuit);
[4817]107
[5055]108 _menuPlugins = menuBar()->addMenu(tr("&Plugins"));
[4817]109
110 _menuHlp = menuBar()->addMenu(tr("&Help"));
[5056]111 _menuHlp->addAction(actHelp);
112 _menuHlp->addAction(actAbout);
[4817]113}
114
115// Select Fonts
116////////////////////////////////////////////////////////////////////////////
[4860]117void t_mainWin::slotFontSel() {
[4817]118 bool ok;
119 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
120 if (ok) {
[4860]121 t_settings settings;
[4817]122 settings.setValue("font", newFont.toString());
123 QApplication::setFont(newFont);
124 }
125}
126
127// Save Options (serialize)
128////////////////////////////////////////////////////////////////////////////
[4860]129void t_mainWin::slotSaveOptions() {
130 t_settings settings;
[4817]131 settings.sync();
132}
133
[5055]134//
[4817]135////////////////////////////////////////////////////////////////////////////
[5055]136void t_mainWin::slotStartPlugin() {
[5057]137 t_pluginAction* action = dynamic_cast<t_pluginAction*>(sender());
[5059]138 QWidget* widget = action->_factIface->create();
[5086]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 }
[5061]147 widget->setMinimumSize(500, 300);
[5059]148 QMdiSubWindow* subWindow = _mdi->addSubWindow((QWidget*) widget);
149 subWindow->show();
[4846]150}
151
[4817]152// Help Window
153////////////////////////////////////////////////////////////////////////////
[4860]154void t_mainWin::slotHelp() {
[4817]155}
156
157// About Message
158////////////////////////////////////////////////////////////////////////////
[4860]159void t_mainWin::slotAbout() {
[4817]160}
161
162// Close Application gracefully
163////////////////////////////////////////////////////////////////////////////
[4860]164void t_mainWin::closeEvent(QCloseEvent* event) {
[4817]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.