source: ntrip/trunk/BNC/src/bnchlpdlg.cpp@ 10149

Last change on this file since 10149 was 10087, checked in by stuerze, 18 months ago

minor changes

File size: 5.8 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncHlpDlg
30 *
31 * Purpose: Displays the help
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Sep-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <QHBoxLayout>
42#include <QVBoxLayout>
43#include <iostream>
44#include "bnchlpdlg.h"
45#include "bnchtml.h"
46
47// Constructor
48////////////////////////////////////////////////////////////////////////////
49bncHlpDlg::bncHlpDlg(QWidget* parent, const QUrl& url) :
50 QDialog(parent) {
51
52 const int ww = QFontMetrics(font()).width('w');
53
54 _tb = new bncHtml;
55 setWindowTitle("Help Contents");
56 _tb->setSource(url);
57 _tb->setReadOnly(true);
58 connect(_tb, SIGNAL(backwardAvailable(bool)), this, SLOT(backwardAvailable(bool)));
59 connect(_tb, SIGNAL(forwardAvailable(bool)), this, SLOT(forwardAvailable(bool)));
60
61 QVBoxLayout* dlgLayout = new QVBoxLayout;
62 dlgLayout->addWidget(_tb);
63
64 QHBoxLayout* butLayout = new QHBoxLayout;
65
66 _backButton = new QPushButton("Backward");
67 _backButton->setMaximumWidth(10*ww);
68 _backButton->setEnabled(false);
69 connect(_backButton, SIGNAL(clicked()), _tb, SLOT(backward()));
70 butLayout->addWidget(_backButton);
71
72 _forwButton = new QPushButton("Forward");
73 _forwButton->setMaximumWidth(10*ww);
74 _forwButton->setEnabled(false);
75 connect(_forwButton, SIGNAL(clicked()), _tb, SLOT(forward()));
76 butLayout->addWidget(_forwButton);
77
78 _closeButton = new QPushButton("Close");
79 _closeButton->setMaximumWidth(10*ww);
80 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
81 butLayout->addWidget(_closeButton);
82
83 _label = new QLabel("Find &what:"); // 2.
84 _what = new QLineEdit();
85 _label->setBuddy(_what); // 3.
86 _cbCase = new QCheckBox("Match &case");
87 _cbBack = new QCheckBox("Search &backward");
88 _findButton = new QPushButton("&Find"); // 4.
89 _findButton->setDefault(true);
90 _findButton->setEnabled(false);
91 connect(_what, SIGNAL(textChanged(const QString&)), this, SLOT(enableBtnFind(const QString&)));
92 connect(_findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
93
94 butLayout->addWidget(_label);
95 butLayout->addWidget(_what);
96 butLayout->addWidget(_findButton);
97 butLayout->addWidget(_cbCase);
98 butLayout->addWidget(_cbBack);
99
100 connect(this, SIGNAL(findNext(const QString &, Qt::CaseSensitivity)),
101 this, SLOT(slotFindNext(const QString &, Qt::CaseSensitivity)));
102
103 connect(this, SIGNAL(findPrev(const QString &, Qt::CaseSensitivity)),
104 this, SLOT(slotFindPrev(const QString &, Qt::CaseSensitivity)));
105
106 _hlCursor = QTextCursor(_tb->document());
107
108 dlgLayout->addLayout(butLayout);
109
110 setLayout(dlgLayout);
111 resize(110*ww, 100*ww);
112 show();
113}
114
115// Destructor
116////////////////////////////////////////////////////////////////////////////
117bncHlpDlg::~bncHlpDlg() {
118 delete _tb;
119 delete _backButton;
120 delete _forwButton;
121 delete _closeButton;
122 delete _findButton;
123 delete _label;
124 delete _what;
125 delete _cbCase;
126 delete _cbBack;
127}
128
129// Slots
130////////////////////////////////////////////////////////////////////////////
131void bncHlpDlg::backwardAvailable(bool avail) {
132 _backButton->setEnabled(avail);
133}
134
135void bncHlpDlg::forwardAvailable(bool avail) {
136 _forwButton->setEnabled(avail);
137}
138
139void bncHlpDlg::findClicked() {
140
141 QString text = _what->text();
142
143 Qt::CaseSensitivity cs = _cbCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
144
145 if(_cbBack->isChecked()) {
146 emit findPrev(text, cs);
147 }
148 else {
149 emit findNext(text, cs);
150 }
151}
152
153void bncHlpDlg::enableBtnFind(const QString& text) {
154 _findButton->setEnabled(!text.isEmpty());
155}
156
157void bncHlpDlg::slotFindNext(const QString& str, Qt::CaseSensitivity cs) {
158 QString searchString = str;
159 QTextDocument::FindFlags flags;
160 flags |= QTextDocument::FindWholeWords;
161 if ( cs == Qt::CaseSensitive) {
162 flags |= QTextDocument::FindCaseSensitively;
163 }
164
165 _hlCursor = (_tb->document()->find(searchString, _hlCursor, flags));
166 if (!_hlCursor.isNull()) {
167 _hlCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);
168 _tb->setTextCursor(_hlCursor);
169 }
170 else {
171 _hlCursor.movePosition(QTextCursor::Start);
172 _tb->setTextCursor(_hlCursor);
173 }
174
175}
176
177
178void bncHlpDlg::slotFindPrev(const QString& str, Qt::CaseSensitivity cs) {
179 QString searchString = str;
180 QTextDocument::FindFlags flags;
181 flags |= QTextDocument::FindWholeWords;
182 flags |= QTextDocument::FindBackward;
183 if ( cs == Qt::CaseSensitive) {
184 flags |= QTextDocument::FindCaseSensitively;
185 }
186
187 _hlCursor = (_tb->document()->find(searchString, _hlCursor, flags));
188 if (!_hlCursor.isNull()) {
189 _hlCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);
190 _tb->setTextCursor(_hlCursor);
191 }
192 else {
193 _hlCursor.movePosition(QTextCursor::End);
194 _tb->setTextCursor(_hlCursor);
195 }
196
197}
198
199
200
201
202
Note: See TracBrowser for help on using the repository browser.