Changeset 10082 in ntrip
- Timestamp:
- Jun 1, 2023, 8:00:11 AM (18 months ago)
- Location:
- trunk/BNC/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/src/bnchlpdlg.cpp
r8238 r10082 52 52 const int ww = QFontMetrics(font()).width('w'); 53 53 54 bncHtml*_tb = new bncHtml;54 _tb = new bncHtml; 55 55 setWindowTitle("Help Contents"); 56 56 _tb->setSource(url); 57 57 _tb->setReadOnly(true); 58 connect(_tb, SIGNAL(backwardAvailable(bool)), 59 this, SLOT(backwardAvailable(bool))); 60 connect(_tb, SIGNAL(forwardAvailable(bool)), 61 this, SLOT(forwardAvailable(bool))); 58 connect(_tb, SIGNAL(backwardAvailable(bool)), this, SLOT(backwardAvailable(bool))); 59 connect(_tb, SIGNAL(forwardAvailable(bool)), this, SLOT(forwardAvailable(bool))); 62 60 63 61 QVBoxLayout* dlgLayout = new QVBoxLayout; … … 80 78 _closeButton = new QPushButton("Close"); 81 79 _closeButton->setMaximumWidth(10*ww); 80 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close())); 82 81 butLayout->addWidget(_closeButton); 83 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close())); 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()); 84 107 85 108 dlgLayout->addLayout(butLayout); … … 97 120 delete _forwButton; 98 121 delete _closeButton; 122 delete _findButton; 123 delete _label; 124 delete _what; 125 delete _cbCase; 126 delete _cbBack; 99 127 } 100 128 … … 108 136 _forwButton->setEnabled(avail); 109 137 } 138 139 void bncHlpDlg::findClicked() { 140 141 QString text = _what->text(); 142 Qt::CaseSensitivity cs = _cbCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; 143 144 if(_cbBack->isChecked()) { 145 emit findPrev(text, cs); 146 } 147 else { 148 emit findNext(text, cs); 149 } 150 } 151 152 void bncHlpDlg::enableBtnFind(const QString& text) { 153 _findButton->setEnabled(!text.isEmpty()); 154 } 155 156 void bncHlpDlg::slotFindNext(const QString& str, Qt::CaseSensitivity cs) { 157 QString searchString = str; 158 bool found = false; 159 QTextDocument::FindFlags flags; 160 flags |= QTextDocument::FindWholeWords; 161 if ( cs == Qt::CaseSensitive) { 162 flags |= QTextDocument::FindCaseSensitively; 163 } 164 165 if (!_hlCursor.atEnd()) { 166 _hlCursor = (_tb->document()->find(searchString, _hlCursor, flags)); 167 if (!_hlCursor.isNull()) { 168 found = true; 169 _hlCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); 170 _tb->setTextCursor(_hlCursor); 171 } 172 } 173 174 if (found == false) { 175 _hlCursor.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor); 176 _tb->setTextCursor(_hlCursor); 177 } 178 179 } 180 181 182 void bncHlpDlg::slotFindPrev(const QString& str, Qt::CaseSensitivity cs) { 183 QString searchString = str; 184 bool found = false; 185 QTextDocument::FindFlags flags; 186 flags |= QTextDocument::FindWholeWords; 187 flags |= QTextDocument::FindBackward; 188 if ( cs == Qt::CaseSensitive) { 189 flags |= QTextDocument::FindCaseSensitively; 190 } 191 192 if (!_hlCursor.atEnd()) { 193 _hlCursor = (_tb->document()->find(searchString, _hlCursor, flags)); 194 if (!_hlCursor.isNull()) { 195 found = true; 196 _hlCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); 197 _tb->setTextCursor(_hlCursor); 198 } 199 } 200 201 if (found == false) { 202 _hlCursor.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor); 203 _tb->setTextCursor(_hlCursor); 204 } 205 } 206 207 208 209 210 -
trunk/BNC/src/bnchlpdlg.h
r8252 r10082 29 29 30 30 #include <QDialog> 31 #include <QLabel> 32 #include <QCheckBox> 33 #include <QLineEdit> 31 34 #include <QPushButton> 32 35 … … 41 44 42 45 signals: 43 46 void findNext(const QString& str, Qt::CaseSensitivity cs); 47 void findPrev(const QString& str, Qt::CaseSensitivity cs); 48 44 49 public slots: 45 50 void backwardAvailable(bool); 46 51 void forwardAvailable(bool); 52 void findClicked(); 53 void enableBtnFind(const QString& text); 54 void slotFindNext(const QString& str, Qt::CaseSensitivity cs); 55 void slotFindPrev(const QString& str, Qt::CaseSensitivity cs); 47 56 48 57 private: 49 bncHtml* _tb; 50 QPushButton* _backButton; 51 QPushButton* _forwButton; 52 QPushButton* _closeButton; 58 bncHtml* _tb; 59 QPushButton* _backButton; 60 QPushButton* _forwButton; 61 QPushButton* _closeButton; 62 QPushButton* _findButton; 63 QTextCursor _hlCursor; 64 QLabel* _label; 65 QLineEdit* _what; 66 QCheckBox* _cbCase; 67 QCheckBox* _cbBack; 53 68 }; 54 69
Note:
See TracChangeset
for help on using the changeset viewer.