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

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

* empty log message *

File size: 9.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 QSettings settings;
30
31 QString fontString = settings.value("font").toString();
32 if ( !fontString.isEmpty() ) {
33 QFont newFont;
34 if (newFont.fromString(fontString)) {
35 this->setFont(newFont);
36 }
37 }
38
39 int ww = QFontMetrics(this->font()).width('w');
40 setMinimumSize(77*ww, 65*ww);
41 setWindowTitle(tr("BKG Ntrip Server (BNS) Version 1.0"));
42 setWindowIcon(QPixmap(":ntrip-logo.png"));
43
44 // Create Actions
45 // --------------
46 _actHelp = new QAction(tr("&Help Contents"),this);
47 connect(_actHelp, SIGNAL(triggered()), SLOT(slotHelp()));
48
49 _actAbout = new QAction(tr("&About BNS"),this);
50 connect(_actAbout, SIGNAL(triggered()), SLOT(slotAbout()));
51
52 _actFontSel = new QAction(tr("Select &Font"),this);
53 connect(_actFontSel, SIGNAL(triggered()), SLOT(slotFontSel()));
54
55 _actSaveOpt = new QAction(tr("&Save Options"),this);
56 connect(_actSaveOpt, SIGNAL(triggered()), SLOT(slotSaveOptions()));
57
58 _actQuit = new QAction(tr("&Quit"),this);
59 connect(_actQuit, SIGNAL(triggered()), SLOT(close()));
60
61 _actwhatsthis= new QAction(tr("Help=Shift+F1"),this);
62 connect(_actwhatsthis, SIGNAL(triggered()), SLOT(slotWhatsThis()));
63
64 CreateMenu();
65 AddToolbar();
66
67 // Canvas with Editable Fields
68 // ---------------------------
69 _canvas = new QWidget;
70 setCentralWidget(_canvas);
71
72 _ephHostLineEdit = new QLineEdit(settings.value("ephHost").toString());
73 _ephHostLineEdit->setWhatsThis(tr("Host for broadcast ephemeris (from BNC)"));
74 _ephPortLineEdit = new QLineEdit(settings.value("ephPort").toString());
75 _ephPortLineEdit->setWhatsThis(tr("Port for broadcast ephemeris (from BNC)"));
76 _ephPortLineEdit->setMaximumWidth(9*ww);
77
78 _proxyHostLineEdit = new QLineEdit(settings.value("proxyHost").toString());
79 _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>"));
80 _proxyPortLineEdit = new QLineEdit(settings.value("proxyPort").toString());
81 _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>"));
82 _proxyPortLineEdit->setMaximumWidth(9*ww);
83
84 // TabWidget
85 // ---------
86 QTabWidget* tabs = new QTabWidget();
87 QWidget* tab_inp = new QWidget();
88 QWidget* tab_out = new QWidget();
89 QWidget* tab_proxy = new QWidget();
90 tabs->addTab(tab_inp, tr("Input"));
91 tabs->addTab(tab_out, tr("Output"));
92 tabs->addTab(tab_proxy,tr("Proxy"));
93
94 // Input-Tab
95 // ---------
96 QGridLayout* iLayout = new QGridLayout;
97 /// iLayout->setColumnMinimumWidth(0,12*ww);
98 iLayout->addWidget(new QLabel("Input Options"),0, 0, 1, 2, Qt::AlignLeft);
99 iLayout->addWidget(new QLabel("Host (Ephemeris)"),1,0, Qt::AlignLeft);
100 iLayout->addWidget(_ephHostLineEdit,1, 1);
101 iLayout->addWidget(new QLabel("Port (Ephemeris)"),2,0, Qt::AlignLeft);
102 iLayout->addWidget(_ephPortLineEdit,2, 1);
103 tab_inp->setLayout(iLayout);
104
105 // Proxy-Tab
106 // ---------
107 QGridLayout* pLayout = new QGridLayout;
108 pLayout->setColumnMinimumWidth(0,12*ww);
109 pLayout->addWidget(new QLabel("Settings for the proxy in protected networks, leave the boxes blank if none."),0, 0, 1, 2, Qt::AlignLeft);
110 pLayout->addWidget(new QLabel("Proxy host"),1,0, Qt::AlignLeft);
111 pLayout->addWidget(_proxyHostLineEdit,1, 1);
112 pLayout->addWidget(new QLabel("Proxy port"),2,0, Qt::AlignLeft);
113 pLayout->addWidget(_proxyPortLineEdit,2,1);
114 tab_proxy->setLayout(pLayout);
115
116 // Log
117 // ---
118 _log = new QTextBrowser();
119 _log->setReadOnly(true);
120 _log->setWhatsThis(tr("Records of BNS's activities are shown in the Log section."));
121
122 // Main Layout
123 // -----------
124 QVBoxLayout* mainLayout = new QVBoxLayout;
125 mainLayout->addWidget(tabs);
126 mainLayout->addWidget(_log);
127
128 _canvas->setLayout(mainLayout);
129}
130
131// Destructor
132////////////////////////////////////////////////////////////////////////////
133bnsWindow::~bnsWindow() {
134}
135
136// Close Application gracefully
137////////////////////////////////////////////////////////////////////////////
138void bnsWindow::closeEvent(QCloseEvent* event) {
139
140int iRet = QMessageBox::question(this, "Close", "Save Options?",
141 QMessageBox::Yes, QMessageBox::No,
142 QMessageBox::Cancel);
143
144 if (iRet == QMessageBox::Cancel) {
145 event->ignore();
146 return;
147 }
148 else if (iRet == QMessageBox::Yes) {
149 slotSaveOptions();
150 }
151
152 QMainWindow::closeEvent(event);
153
154 delete this;
155}
156
157// About Message
158////////////////////////////////////////////////////////////////////////////
159void bnsWindow::slotAbout() {
160 new bnsAboutDlg(0);
161}
162
163// Help Window
164////////////////////////////////////////////////////////////////////////////
165void bnsWindow::slotHelp() {
166 QUrl url;
167 url.setPath(":bnshelp.html");
168 new bnsHlpDlg(0, url);
169}
170
171// Select Fonts
172////////////////////////////////////////////////////////////////////////////
173void bnsWindow::slotFontSel() {
174 bool ok;
175 QFont newFont = QFontDialog::getFont(&ok, this->font(), this);
176 if (ok) {
177 QSettings settings;
178 settings.setValue("font", newFont.toString());
179 QApplication::setFont(newFont);
180 int ww = QFontMetrics(newFont).width('w');
181 setMinimumSize(77*ww, 65*ww);
182 }
183}
184
185// Whats This Help
186////////////////////////////////////////////////////////////////////////////
187void bnsWindow::slotWhatsThis() {
188QWhatsThis::enterWhatsThisMode();
189}
190
191// Create Menus
192////////////////////////////////////////////////////////////////////////////
193void bnsWindow::CreateMenu() {
194 _menuFile = menuBar()->addMenu(tr("&File"));
195 _menuFile->addAction(_actFontSel);
196 _menuFile->addSeparator();
197 _menuFile->addAction(_actSaveOpt);
198 _menuFile->addSeparator();
199 _menuFile->addAction(_actQuit);
200
201 _menuHlp = menuBar()->addMenu(tr("&Help"));
202 _menuHlp->addAction(_actHelp);
203 _menuHlp->addAction(_actAbout);
204}
205
206// Tool (Command) Bar
207////////////////////////////////////////////////////////////////////////////
208void bnsWindow::AddToolbar() {
209 QToolBar* toolBar = new QToolBar;
210 addToolBar(Qt::BottomToolBarArea, toolBar);
211 toolBar->setMovable(false);
212 toolBar->addWidget(new QLabel(" "));
213 toolBar->addAction(_actwhatsthis);
214}
215
216// Save Options
217////////////////////////////////////////////////////////////////////////////
218void bnsWindow::slotSaveOptions() {
219 QSettings settings;
220 settings.setValue("ephHost", _ephHostLineEdit->text());
221 settings.setValue("ephPort", _ephPortLineEdit->text());
222 settings.setValue("proxyHost", _proxyHostLineEdit->text());
223 settings.setValue("proxyPort", _proxyPortLineEdit->text());
224}
225
226// About Dialog - Constructor
227////////////////////////////////////////////////////////////////////////////
228bnsAboutDlg::bnsAboutDlg(QWidget* parent) :
229 QDialog(parent) {
230
231 QTextBrowser* tb = new QTextBrowser;
232 QUrl url; url.setPath(":bnsabout.html");
233 tb->setSource(url);
234 tb->setReadOnly(true);
235
236 int ww = QFontMetrics(font()).width('w');
237 QPushButton* _closeButton = new QPushButton("Close");
238 _closeButton->setMaximumWidth(10*ww);
239 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
240
241 QGridLayout* dlgLayout = new QGridLayout();
242 QLabel* img = new QLabel();
243 img->setPixmap(QPixmap(":ntrip-logo.png"));
244 dlgLayout->addWidget(img, 0,0);
245 dlgLayout->addWidget(new QLabel("BKG NTRIP Server (BNS) Version 1.0"), 0,1);
246 dlgLayout->addWidget(tb,1,0,1,2);
247 dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight);
248
249 setLayout(dlgLayout);
250 resize(60*ww, 60*ww);
251 show();
252}
253
254// About Dialog - Constructor
255////////////////////////////////////////////////////////////////////////////
256bnsAboutDlg::~bnsAboutDlg() {
257};
258
259// Display Program Messages
260////////////////////////////////////////////////////////////////////////////
261void bnsWindow::slotMessage(const QByteArray msg) {
262
263 const int maxBufferSize = 10000;
264
265 QString txt = _log->toPlainText() + "\n" +
266 QDateTime::currentDateTime().toUTC().toString("yy-MM-dd hh:mm:ss ") + msg;
267 _log->clear();
268 _log->append(txt.right(maxBufferSize));
269}
Note: See TracBrowser for help on using the repository browser.