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

Last change on this file since 5061 was 5061, checked in by mervart, 11 years ago
File size: 4.7 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"
[4815]21
22using namespace std;
[5001]23using namespace GnssCenter;
[4815]24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
[4860]27t_mainWin::t_mainWin(QWidget* parent, Qt::WindowFlags flags) :
[4815]28 QMainWindow(parent, flags) {
[4817]29
[4860]30 _mdi = new t_mdiArea(0);
[4818]31 setCentralWidget(_mdi);
32
[5055]33 createMenu();
34 createToolBar();
35 createStatusBar();
36
[5039]37 // Handle Plugins
38 // --------------
39 QDir pluginsDir = QDir(qApp->applicationDirPath());
[5041]40
41 pluginsDir.cd("plugins");
[5039]42
43 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
44 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
[5042]45 QObject* object = loader.instance();
46 if (object) {
[5052]47 t_pluginFactoryInterface* plugin = qobject_cast<t_pluginFactoryInterface*>(object);
[5045]48 if (plugin) {
[5056]49 t_pluginAction* action = new t_pluginAction(this, plugin);
50 _menuPlugins->addAction(action);
51 connect(action, SIGNAL(triggered()), SLOT(slotStartPlugin()));
[5045]52 }
[5042]53 }
[5016]54 }
55
[4815]56}
57
58// Destructor
59////////////////////////////////////////////////////////////////////////////
[4860]60t_mainWin::~t_mainWin() {
[4815]61}
[4817]62
63//
64////////////////////////////////////////////////////////////////////////////
[4860]65void t_mainWin::createToolBar() {
[4822]66 _fileToolBar = addToolBar(tr("File"));
67 _editToolBar = addToolBar(tr("Edit"));
68}
69
70//
71////////////////////////////////////////////////////////////////////////////
[4860]72void t_mainWin::createStatusBar() {
[4822]73 statusBar()->showMessage(tr("Ready"));
74}
75
76//
77////////////////////////////////////////////////////////////////////////////
[4860]78void t_mainWin::createMenu() {
[4817]79
80 // Create Actions
81 // --------------
[5056]82 QAction* actFontSel = new QAction(tr("Select &Font"),this);
83 connect(actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
[4817]84
[5056]85 QAction* actSaveOpt = new QAction(tr("&Save && Reread Configuration"),this);
86 connect(actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
[4817]87
[5056]88 QAction* actQuit = new QAction(tr("&Quit"),this);
89 connect(actQuit, SIGNAL(triggered()), SLOT(close()));
[4817]90
[5056]91 QAction* actHelp = new QAction(tr("&Help Contents"),this);
92 connect(actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
[4817]93
[5056]94 QAction* actAbout = new QAction(tr("&About"),this);
95 connect(actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
[4817]96
97 // Create Menu
98 // -----------
99 _menuFile = menuBar()->addMenu(tr("&File"));
[5056]100 _menuFile->addAction(actFontSel);
[4817]101 _menuFile->addSeparator();
[5056]102 _menuFile->addAction(actSaveOpt);
[4817]103 _menuFile->addSeparator();
[5056]104 _menuFile->addAction(actQuit);
[4817]105
[5055]106 _menuPlugins = menuBar()->addMenu(tr("&Plugins"));
[4817]107
108 _menuHlp = menuBar()->addMenu(tr("&Help"));
[5056]109 _menuHlp->addAction(actHelp);
110 _menuHlp->addAction(actAbout);
[4817]111}
112
113// Select Fonts
114////////////////////////////////////////////////////////////////////////////
[4860]115void t_mainWin::slotFontSel() {
[4817]116 bool ok;
117 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
118 if (ok) {
[4860]119 t_settings settings;
[4817]120 settings.setValue("font", newFont.toString());
121 QApplication::setFont(newFont);
122 }
123}
124
125// Save Options (serialize)
126////////////////////////////////////////////////////////////////////////////
[4860]127void t_mainWin::slotSaveOptions() {
128 t_settings settings;
[4817]129 settings.sync();
130}
131
[5055]132//
[4817]133////////////////////////////////////////////////////////////////////////////
[5055]134void t_mainWin::slotStartPlugin() {
[5057]135 t_pluginAction* action = dynamic_cast<t_pluginAction*>(sender());
[5059]136 QWidget* widget = action->_factIface->create();
[5061]137 widget->setMinimumSize(500, 300);
[5059]138 QMdiSubWindow* subWindow = _mdi->addSubWindow((QWidget*) widget);
139 subWindow->show();
[4846]140}
141
[4817]142// Help Window
143////////////////////////////////////////////////////////////////////////////
[4860]144void t_mainWin::slotHelp() {
[4817]145}
146
147// About Message
148////////////////////////////////////////////////////////////////////////////
[4860]149void t_mainWin::slotAbout() {
[4817]150}
151
152// Close Application gracefully
153////////////////////////////////////////////////////////////////////////////
[4860]154void t_mainWin::closeEvent(QCloseEvent* event) {
[4817]155 int iRet = QMessageBox::question(this, "Close", "Save Options?",
156 QMessageBox::Yes, QMessageBox::No,
157 QMessageBox::Cancel);
158 if (iRet == QMessageBox::Cancel) {
159 event->ignore();
160 return;
161 }
162 else if (iRet == QMessageBox::Yes) {
163 slotSaveOptions();
164 }
165 QMainWindow::closeEvent(event);
166}
Note: See TracBrowser for help on using the repository browser.