source: ntrip/trunk/BNS/bnswindow.cpp@ 750

Last change on this file since 750 was 750, checked in by mervart, 16 years ago

* empty log message *

File size: 8.7 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
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
18#include <iostream>
19
20#include "bnswindow.h"
21#include "bnshlpdlg.h"
22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27bnsWindow::bnsWindow() {
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
63 QSettings settings;
64 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
65 _proxyHostLineEdit->setWhatsThis(tr("<p>If you are running BNS within a protected Local Area Network (LAN), you might need to use a proxy server to access the Internet. Enter your proxy server IP and port number in case one is operated in front of BNC. If you do not know the IP and port of your proxy server, check the proxy server settings in your Internet browser or ask your network administrator.</p><p>Note that IP streaming is sometimes not allowed in a LAN. In this case you need to ask your network administrator for an appropriate modification of the local security policy or for the installation of a TCP relay to the NTRIP broadcasters. If these are not possible, you might need to run BNC outside your LAN on a network that has unobstructed connection to the Internet.</p>"));
66 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
67 _proxyPortLineEdit->setWhatsThis(tr("<p>If you are running BNS within a protected Local Area Network (LAN), you might need to use a proxy server to access the Internet. Enter your proxy server IP and port number in case one is operated in front of BNC. If you do not know the IP and port of your proxy server, check the proxy server settings in your Internet browser or ask your network administrator.</p><p>Note that IP streaming is sometimes not allowed in a LAN. In this case you need to ask your network administrator for an appropriate modification of the local security policy or for the installation of a TCP relay to the NTRIP broadcasters. If these are not possible, you might need to run BNC outside your LAN on a network that has unobstructed connection to the Internet.</p>"));
68 _proxyPortLineEdit->setMaximumWidth(9*ww);
69
70 // TabWidget
71 // ---------
72 QTabWidget* tabs = new QTabWidget();
73 QWidget* tab_proxy = new QWidget();
74 QWidget* tab_opt = new QWidget();
75 QWidget* tab_res = new QWidget();
76 tabs->addTab(tab_proxy,tr("Proxy"));
77 tabs->addTab(tab_opt, tr("Options"));
78 tabs->addTab(tab_res, tr("Results"));
79
80 // Proxy-Tab
81 // ---------
82 QGridLayout* pLayout = new QGridLayout;
83 pLayout->setColumnMinimumWidth(0,12*ww);
84 pLayout->addWidget(new QLabel("Proxy host"),0,0, Qt::AlignLeft);
85 pLayout->addWidget(_proxyHostLineEdit,0, 1);
86 pLayout->addWidget(new QLabel("Proxy port"),1,0, Qt::AlignLeft);
87 pLayout->addWidget(_proxyPortLineEdit,1,1);
88 pLayout->addWidget(new QLabel("Settings for the proxy in protected networks, leave the boxes blank if none."),2, 0, 1, 2, Qt::AlignLeft);
89 pLayout->addWidget(new QLabel(" "),3,0);
90 pLayout->addWidget(new QLabel(" "),4,0);
91 pLayout->addWidget(new QLabel(" "),5,0);
92 tab_proxy->setLayout(pLayout);
93
94 // Log
95 // ---
96 _log = new QTextBrowser();
97 _log->setReadOnly(true);
98 _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
99
100 // Main Layout
101 // -----------
102 QVBoxLayout* mainLayout = new QVBoxLayout;
103 mainLayout->addWidget(tabs);
104 mainLayout->addWidget(_log);
105
106 _canvas->setLayout(mainLayout);
107}
108
109// Destructor
110////////////////////////////////////////////////////////////////////////////
111bnsWindow::~bnsWindow() {
112}
113
114// Close Application gracefully
115////////////////////////////////////////////////////////////////////////////
116void bnsWindow::closeEvent(QCloseEvent* event) {
117
118int iRet = QMessageBox::question(this, "Close", "Save Options?",
119 QMessageBox::Yes, QMessageBox::No,
120 QMessageBox::Cancel);
121
122 if (iRet == QMessageBox::Cancel) {
123 event->ignore();
124 return;
125 }
126 else if (iRet == QMessageBox::Yes) {
127 slotSaveOptions();
128 }
129
130 QMainWindow::closeEvent(event);
131
132 delete this;
133}
134
135// About Message
136////////////////////////////////////////////////////////////////////////////
137void bnsWindow::slotAbout() {
138 new bnsAboutDlg(0);
139}
140
141// Help Window
142////////////////////////////////////////////////////////////////////////////
143void bnsWindow::slotHelp() {
144 QUrl url;
145 url.setPath(":bnshelp.html");
146 new bnsHlpDlg(0, url);
147}
148
149// Select Fonts
150////////////////////////////////////////////////////////////////////////////
151void bnsWindow::slotFontSel() {
152 bool ok;
153 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
154 if (ok) {
155 QSettings settings;
156 settings.setValue("font", newFont.toString());
157 QApplication::setFont(newFont);
158 int ww = QFontMetrics(newFont).width('w');
159 setMinimumSize(60*ww, 80*ww);
160 resize(60*ww, 80*ww);
161 }
162}
163
164// Whats This Help
165////////////////////////////////////////////////////////////////////////////
166void bnsWindow::slotWhatsThis() {
167QWhatsThis::enterWhatsThisMode();
168}
169
170// Create Menus
171////////////////////////////////////////////////////////////////////////////
172void bnsWindow::CreateMenu() {
173 _menuFile = menuBar()->addMenu(tr("&File"));
174 _menuFile->addAction(_actFontSel);
175 _menuFile->addSeparator();
176 _menuFile->addAction(_actSaveOpt);
177 _menuFile->addSeparator();
178 _menuFile->addAction(_actQuit);
179
180 _menuHlp = menuBar()->addMenu(tr("&Help"));
181 _menuHlp->addAction(_actHelp);
182 _menuHlp->addAction(_actAbout);
183}
184
185// Tool (Command) Bar
186////////////////////////////////////////////////////////////////////////////
187void bnsWindow::AddToolbar() {
188 QToolBar* toolBar = new QToolBar;
189 addToolBar(Qt::BottomToolBarArea, toolBar);
190 toolBar->setMovable(false);
191 toolBar->addWidget(new QLabel(" "));
192 toolBar->addAction(_actwhatsthis);
193}
194
195// Save Options
196////////////////////////////////////////////////////////////////////////////
197void bnsWindow::slotSaveOptions() {
198 QSettings settings;
199 settings.setValue("proxyHost", _proxyHostLineEdit->text());
200 settings.setValue("proxyPort", _proxyPortLineEdit->text());
201}
202
203// About Dialog - Constructor
204////////////////////////////////////////////////////////////////////////////
205bnsAboutDlg::bnsAboutDlg(QWidget* parent) :
206 QDialog(parent) {
207
208 QTextBrowser* tb = new QTextBrowser;
209 QUrl url; url.setPath(":bnsabout.html");
210 tb->setSource(url);
211 tb->setReadOnly(true);
212
213 int ww = QFontMetrics(font()).width('w');
214 QPushButton* _closeButton = new QPushButton("Close");
215 _closeButton->setMaximumWidth(10*ww);
216 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
217
218 QGridLayout* dlgLayout = new QGridLayout();
219 QLabel* img = new QLabel();
220 img->setPixmap(QPixmap(":ntrip-logo.png"));
221 dlgLayout->addWidget(img, 0,0);
222 dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1);
223 dlgLayout->addWidget(tb,1,0,1,2);
224 dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight);
225
226 setLayout(dlgLayout);
227 resize(60*ww, 60*ww);
228 show();
229}
230
231// About Dialog - Constructor
232////////////////////////////////////////////////////////////////////////////
233bnsAboutDlg::~bnsAboutDlg() {
234};
235
236// Display Program Messages
237////////////////////////////////////////////////////////////////////////////
238void bnsWindow::slotMessage(const QByteArray msg) {
239
240 const int maxBufferSize = 10000;
241
242 QString txt = _log->toPlainText() + "\n" +
243 QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
244 _log->clear();
245 _log->append(txt.right(maxBufferSize));
246}
Note: See TracBrowser for help on using the repository browser.