Changeset 10082 in ntrip


Ignore:
Timestamp:
Jun 1, 2023, 8:00:11 AM (18 months ago)
Author:
stuerze
Message:

find function added in internal help contents

Location:
trunk/BNC/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/bnchlpdlg.cpp

    r8238 r10082  
    5252  const int ww = QFontMetrics(font()).width('w');
    5353
    54   bncHtml* _tb = new bncHtml;
     54  _tb = new bncHtml;
    5555  setWindowTitle("Help Contents");
    5656  _tb->setSource(url);
    5757  _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)));
    6260
    6361  QVBoxLayout* dlgLayout = new QVBoxLayout;
     
    8078  _closeButton = new QPushButton("Close");
    8179  _closeButton->setMaximumWidth(10*ww);
     80  connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
    8281  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());
    84107
    85108  dlgLayout->addLayout(butLayout);
     
    97120  delete _forwButton;
    98121  delete _closeButton;
     122  delete _findButton;
     123  delete _label;
     124  delete _what;
     125  delete _cbCase;
     126  delete _cbBack;
    99127}
    100128
     
    108136  _forwButton->setEnabled(avail);
    109137}
     138
     139void 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
     152void bncHlpDlg::enableBtnFind(const QString& text) {
     153  _findButton->setEnabled(!text.isEmpty());
     154}
     155
     156void 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
     182void 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  
    2929
    3030#include <QDialog>
     31#include <QLabel>
     32#include <QCheckBox>
     33#include <QLineEdit>
    3134#include <QPushButton>
    3235
     
    4144
    4245  signals:
    43  
     46  void findNext(const QString& str, Qt::CaseSensitivity cs);
     47  void findPrev(const QString& str, Qt::CaseSensitivity cs);
     48
    4449  public slots:
    4550    void backwardAvailable(bool);
    4651    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);
    4756
    4857  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;
    5368};
    5469
Note: See TracChangeset for help on using the changeset viewer.