[748] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
[749] | 3 | * BKG NTRIP Server
|
---|
[748] | 4 | * -------------------------------------------------------------------------
|
---|
| 5 | *
|
---|
| 6 | * Class: bnsWindow
|
---|
| 7 | *
|
---|
| 8 | * Purpose: This class implements the main application window.
|
---|
| 9 | *
|
---|
| 10 | * Author: L. Mervart
|
---|
| 11 | *
|
---|
| 12 | * Created: 29-Mar-2008
|
---|
| 13 | *
|
---|
| 14 | * Changes:
|
---|
| 15 | *
|
---|
| 16 | * -----------------------------------------------------------------------*/
|
---|
| 17 |
|
---|
[749] | 18 | #include <iostream>
|
---|
| 19 |
|
---|
[748] | 20 | #include "bnswindow.h"
|
---|
[749] | 21 | #include "bnshlpdlg.h"
|
---|
[748] | 22 |
|
---|
| 23 | using namespace std;
|
---|
| 24 |
|
---|
| 25 | // Constructor
|
---|
| 26 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 27 | bnsWindow::bnsWindow() {
|
---|
[749] | 28 |
|
---|
| 29 | int ww = QFontMetrics(this->font()).width('w');
|
---|
| 30 |
|
---|
| 31 | setMinimumSize(77*ww, 65*ww);
|
---|
| 32 |
|
---|
| 33 | setWindowTitle(tr("BKG Ntrip Server (BNS) Version 1.0"));
|
---|
| 34 |
|
---|
| 35 | // Create Actions
|
---|
| 36 | // --------------
|
---|
| 37 | _actHelp = new QAction(tr("&Help Contents"),this);
|
---|
| 38 | connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
|
---|
| 39 |
|
---|
| 40 | _actAbout = new QAction(tr("&About BNS"),this);
|
---|
| 41 | connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
|
---|
| 42 |
|
---|
| 43 | _actFontSel = new QAction(tr("Select &Font"),this);
|
---|
| 44 | connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
|
---|
| 45 |
|
---|
| 46 | _actSaveOpt = new QAction(tr("&Save Options"),this);
|
---|
| 47 | connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
|
---|
| 48 |
|
---|
| 49 | _actQuit = new QAction(tr("&Quit"),this);
|
---|
| 50 | connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
|
---|
| 51 |
|
---|
| 52 | _actwhatsthis= new QAction(tr("Help=Shift+F1"),this);
|
---|
| 53 | connect(_actwhatsthis, SIGNAL(triggered()), SLOT(slotWhatsThis()));
|
---|
| 54 |
|
---|
| 55 | CreateMenu();
|
---|
| 56 | AddToolbar();
|
---|
| 57 |
|
---|
| 58 | // Canvas with Editable Fields
|
---|
| 59 | // ---------------------------
|
---|
| 60 | _canvas = new QWidget;
|
---|
| 61 | setCentralWidget(_canvas);
|
---|
| 62 |
|
---|
[748] | 63 | }
|
---|
| 64 |
|
---|
| 65 | // Destructor
|
---|
| 66 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 67 | bnsWindow::~bnsWindow() {
|
---|
[749] | 68 | cout << "destructor" << endl;
|
---|
[748] | 69 | }
|
---|
| 70 |
|
---|
| 71 | // Close Application gracefully
|
---|
| 72 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 73 | void bnsWindow::closeEvent(QCloseEvent* event) {
|
---|
[749] | 74 |
|
---|
| 75 | int iRet = QMessageBox::question(this, "Close", "Save Options?",
|
---|
| 76 | QMessageBox::Yes, QMessageBox::No,
|
---|
| 77 | QMessageBox::Cancel);
|
---|
| 78 |
|
---|
| 79 | if (iRet == QMessageBox::Cancel) {
|
---|
| 80 | event->ignore();
|
---|
| 81 | return;
|
---|
| 82 | }
|
---|
| 83 | else if (iRet == QMessageBox::Yes) {
|
---|
| 84 | slotSaveOptions();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[748] | 87 | QMainWindow::closeEvent(event);
|
---|
[749] | 88 |
|
---|
[748] | 89 | delete this;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[749] | 92 | // About Message
|
---|
| 93 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 94 | void bnsWindow::slotAbout() {
|
---|
| 95 | new bnsAboutDlg(0);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | // Help Window
|
---|
| 99 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 100 | void bnsWindow::slotHelp() {
|
---|
| 101 | QUrl url;
|
---|
| 102 | url.setPath(":bnshelp.html");
|
---|
| 103 | new bnsHlpDlg(0, url);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | // Select Fonts
|
---|
| 107 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 108 | void bnsWindow::slotFontSel() {
|
---|
| 109 | bool ok;
|
---|
| 110 | QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
|
---|
| 111 | if (ok) {
|
---|
| 112 | QSettings settings;
|
---|
| 113 | settings.setValue("font", newFont.toString());
|
---|
| 114 | QApplication::setFont(newFont);
|
---|
| 115 | int ww = QFontMetrics(newFont).width('w');
|
---|
| 116 | setMinimumSize(60*ww, 80*ww);
|
---|
| 117 | resize(60*ww, 80*ww);
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | // Whats This Help
|
---|
| 122 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 123 | void bnsWindow::slotWhatsThis() {
|
---|
| 124 | QWhatsThis::enterWhatsThisMode();
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | // Create Menus
|
---|
| 128 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 129 | void bnsWindow::CreateMenu() {
|
---|
| 130 | _menuFile = menuBar()->addMenu(tr("&File"));
|
---|
| 131 | _menuFile->addAction(_actFontSel);
|
---|
| 132 | _menuFile->addSeparator();
|
---|
| 133 | _menuFile->addAction(_actSaveOpt);
|
---|
| 134 | _menuFile->addSeparator();
|
---|
| 135 | _menuFile->addAction(_actQuit);
|
---|
| 136 |
|
---|
| 137 | _menuHlp = menuBar()->addMenu(tr("&Help"));
|
---|
| 138 | _menuHlp->addAction(_actHelp);
|
---|
| 139 | _menuHlp->addAction(_actAbout);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | // Tool (Command) Bar
|
---|
| 143 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 144 | void bnsWindow::AddToolbar() {
|
---|
| 145 | QToolBar* toolBar = new QToolBar;
|
---|
| 146 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
| 147 | toolBar->setMovable(false);
|
---|
| 148 | toolBar->addWidget(new QLabel(" "));
|
---|
| 149 | toolBar->addAction(_actwhatsthis);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | // Save Options
|
---|
| 153 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 154 | void bnsWindow::slotSaveOptions() {
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | // About Dialog - Constructor
|
---|
| 158 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 159 | bnsAboutDlg::bnsAboutDlg(QWidget* parent) :
|
---|
| 160 | QDialog(parent) {
|
---|
| 161 |
|
---|
| 162 | QTextBrowser* tb = new QTextBrowser;
|
---|
| 163 | QUrl url; url.setPath(":bnsabout.html");
|
---|
| 164 | tb->setSource(url);
|
---|
| 165 | tb->setReadOnly(true);
|
---|
| 166 |
|
---|
| 167 | int ww = QFontMetrics(font()).width('w');
|
---|
| 168 | QPushButton* _closeButton = new QPushButton("Close");
|
---|
| 169 | _closeButton->setMaximumWidth(10*ww);
|
---|
| 170 | connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
---|
| 171 |
|
---|
| 172 | QGridLayout* dlgLayout = new QGridLayout();
|
---|
| 173 | QLabel* img = new QLabel();
|
---|
| 174 | img->setPixmap(QPixmap(":ntrip-logo.png"));
|
---|
| 175 | dlgLayout->addWidget(img, 0,0);
|
---|
| 176 | dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1);
|
---|
| 177 | dlgLayout->addWidget(tb,1,0,1,2);
|
---|
| 178 | dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight);
|
---|
| 179 |
|
---|
| 180 | setLayout(dlgLayout);
|
---|
| 181 | resize(60*ww, 60*ww);
|
---|
| 182 | show();
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | // About Dialog - Constructor
|
---|
| 186 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 187 | bnsAboutDlg::~bnsAboutDlg() {
|
---|
| 188 | };
|
---|
| 189 |
|
---|