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

Last change on this file since 5875 was 5411, checked in by mervart, 11 years ago
File size: 5.2 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();
[5411]47 if (!object) {
48 qDebug() << loader.errorString();
49 }
50 else {
[5052]51 t_pluginFactoryInterface* plugin = qobject_cast<t_pluginFactoryInterface*>(object);
[5045]52 if (plugin) {
[5056]53 t_pluginAction* action = new t_pluginAction(this, plugin);
54 _menuPlugins->addAction(action);
55 connect(action, SIGNAL(triggered()), SLOT(slotStartPlugin()));
[5045]56 }
[5042]57 }
[5016]58 }
59
[4815]60}
61
62// Destructor
63////////////////////////////////////////////////////////////////////////////
[4860]64t_mainWin::~t_mainWin() {
[4815]65}
[4817]66
67//
68////////////////////////////////////////////////////////////////////////////
[4860]69void t_mainWin::createToolBar() {
[5118]70 _toolBar = new QToolBar("Tool Bar", this);
71 _toolBar->addWidget(new QLabel("Tool Bar"));
72 addToolBar(Qt::BottomToolBarArea, _toolBar);
[4822]73}
74
75//
76////////////////////////////////////////////////////////////////////////////
[4860]77void t_mainWin::createStatusBar() {
[5118]78 statusBar()->addPermanentWidget(new QLabel("Status Bar"));
[4822]79}
80
81//
82////////////////////////////////////////////////////////////////////////////
[4860]83void t_mainWin::createMenu() {
[4817]84
85 // Create Actions
86 // --------------
[5056]87 QAction* actFontSel = new QAction(tr("Select &Font"),this);
88 connect(actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
[4817]89
[5056]90 QAction* actSaveOpt = new QAction(tr("&Save && Reread Configuration"),this);
91 connect(actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
[4817]92
[5056]93 QAction* actQuit = new QAction(tr("&Quit"),this);
94 connect(actQuit, SIGNAL(triggered()), SLOT(close()));
[4817]95
[5056]96 QAction* actHelp = new QAction(tr("&Help Contents"),this);
97 connect(actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
[4817]98
[5056]99 QAction* actAbout = new QAction(tr("&About"),this);
100 connect(actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
[4817]101
102 // Create Menu
103 // -----------
104 _menuFile = menuBar()->addMenu(tr("&File"));
[5056]105 _menuFile->addAction(actFontSel);
[4817]106 _menuFile->addSeparator();
[5056]107 _menuFile->addAction(actSaveOpt);
[4817]108 _menuFile->addSeparator();
[5056]109 _menuFile->addAction(actQuit);
[4817]110
[5055]111 _menuPlugins = menuBar()->addMenu(tr("&Plugins"));
[4817]112
113 _menuHlp = menuBar()->addMenu(tr("&Help"));
[5056]114 _menuHlp->addAction(actHelp);
115 _menuHlp->addAction(actAbout);
[4817]116}
117
118// Select Fonts
119////////////////////////////////////////////////////////////////////////////
[4860]120void t_mainWin::slotFontSel() {
[4817]121 bool ok;
122 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
123 if (ok) {
[4860]124 t_settings settings;
[4817]125 settings.setValue("font", newFont.toString());
126 QApplication::setFont(newFont);
127 }
128}
129
130// Save Options (serialize)
131////////////////////////////////////////////////////////////////////////////
[4860]132void t_mainWin::slotSaveOptions() {
133 t_settings settings;
[4817]134 settings.sync();
135}
136
[5055]137//
[4817]138////////////////////////////////////////////////////////////////////////////
[5055]139void t_mainWin::slotStartPlugin() {
[5057]140 t_pluginAction* action = dynamic_cast<t_pluginAction*>(sender());
[5059]141 QWidget* widget = action->_factIface->create();
[5086]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 }
[5061]150 widget->setMinimumSize(500, 300);
[5059]151 QMdiSubWindow* subWindow = _mdi->addSubWindow((QWidget*) widget);
152 subWindow->show();
[4846]153}
154
[4817]155// Help Window
156////////////////////////////////////////////////////////////////////////////
[4860]157void t_mainWin::slotHelp() {
[4817]158}
159
160// About Message
161////////////////////////////////////////////////////////////////////////////
[4860]162void t_mainWin::slotAbout() {
[4817]163}
164
165// Close Application gracefully
166////////////////////////////////////////////////////////////////////////////
[4860]167void t_mainWin::closeEvent(QCloseEvent* event) {
[4817]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.