| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include "finddialog.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include <QtWidgets/QTextBrowser> |
| 35 |
#include <QTextCursor> |
| 36 |
#include <QtWidgets/QStatusBar> |
| 37 |
#include <QtWidgets/QLineEdit> |
| 38 |
#include <QDateTime> |
| 39 |
#include <QtWidgets/QGridLayout> |
| 40 |
//#include <QtWidgets/QDialog> |
| 41 |
CaseSensitiveModel::CaseSensitiveModel(int rows, int columns, QObject *parent) |
| 42 |
: QStandardItemModel(rows, columns, parent) |
| 43 |
{} |
| 44 |
QModelIndexList CaseSensitiveModel::match(const QModelIndex &start, int role, const QVariant &value, |
| 45 |
int hits, Qt::MatchFlags flags) const |
| 46 |
{ |
| 47 |
if (flags == Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) |
| 48 |
flags |= Qt::MatchCaseSensitive; |
| 49 |
|
| 50 |
return QStandardItemModel::match(start, role, value, hits, flags); |
| 51 |
} |
| 52 |
|
| 53 |
FindDialog::FindDialog(QMainWindow *parent) |
| 54 |
: QDialog(parent) |
| 55 |
{ |
| 56 |
auto contentsWidget = new QWidget(this); |
| 57 |
//ui.setupUi(contentsWidget); |
| 58 |
//ui.comboFind->setModel(new CaseSensitiveModel(0, 1, ui.comboFind)); |
| 59 |
|
| 60 |
QVBoxLayout *l = new QVBoxLayout(this); |
| 61 |
l->setContentsMargins(QMargins()); |
| 62 |
l->setSpacing(0); |
| 63 |
l->addWidget(contentsWidget); |
| 64 |
|
| 65 |
auto lastBrowser = 0; |
| 66 |
auto onceFound = false; |
| 67 |
//findExpr.clear(); |
| 68 |
|
| 69 |
auto sb = new QStatusBar(this); |
| 70 |
l->addWidget(sb); |
| 71 |
|
| 72 |
sb->showMessage(tr("Enter the text you want to find.")); |
| 73 |
|
| 74 |
//connect(ui.findButton, SIGNAL(clicked()), this, SLOT(findButtonClicked())); |
| 75 |
//connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(reject())); |
| 76 |
} |
| 77 |
|
| 78 |
//FindDialog::~FindDialog() |
| 79 |
//{ |
| 80 |
//} |
| 81 |
|
| 82 |
//void FindDialog::findButtonClicked() |
| 83 |
//{ |
| 84 |
// doFind(ui.radioForward->isChecked()); |
| 85 |
//} |
| 86 |
|
| 87 |
void FindDialog::doFind(bool forward) |
| 88 |
{ |
| 89 |
QTextBrowser *browser = NULL;// = static_cast<QTextBrowser*>(mainWindow()->browsers()->currentBrowser()); |
| 90 |
//sb->clearMessage(); |
| 91 |
|
| 92 |
//if (ui.comboFind->currentText() != findExpr || lastBrowser != browser) |
| 93 |
// onceFound = false; |
| 94 |
//findExpr = ui.comboFind->currentText(); |
| 95 |
|
| 96 |
QTextDocument::FindFlags flags;// = 0; |
| 97 |
|
| 98 |
//if (ui.checkCase->isChecked()) |
| 99 |
// flags |= QTextDocument::FindCaseSensitively; |
| 100 |
|
| 101 |
//if (ui.checkWords->isChecked()) |
| 102 |
// flags |= QTextDocument::FindWholeWords; |
| 103 |
|
| 104 |
QTextCursor c = browser->textCursor(); |
| 105 |
if (!c.hasSelection()) { |
| 106 |
if (forward) |
| 107 |
c.movePosition(QTextCursor::Start); |
| 108 |
else |
| 109 |
c.movePosition(QTextCursor::End); |
| 110 |
|
| 111 |
browser->setTextCursor(c); |
| 112 |
} |
| 113 |
|
| 114 |
QTextDocument::FindFlags options; |
| 115 |
if (forward == false) |
| 116 |
flags |= QTextDocument::FindBackward; |
| 117 |
bool onceFound = true; |
| 118 |
QTextCursor found;// = browser->document()->find(findExpr, c, flags); |
| 119 |
if (found.isNull()) { |
| 120 |
if (onceFound) { |
| 121 |
if (forward) |
| 122 |
auto a = tr("Search reached end of the document");//statusMessage(tr("Search reached end of the document")); |
| 123 |
else |
| 124 |
auto aa = tr("Search reached start of the document");//statusMessage(tr("Search reached start of the document")); |
| 125 |
} else { |
| 126 |
auto aaa = tr( "Text not found" ); //statusMessage(tr( "Text not found" )); |
| 127 |
} |
| 128 |
} else { |
| 129 |
browser->setTextCursor(found); |
| 130 |
} |
| 131 |
onceFound |= !found.isNull(); |
| 132 |
auto lastBrowser = browser; |
| 133 |
} |
| 134 |
|
| 135 |
void FindDialog::hasFindExpression() const |
| 136 |
{ |
| 137 |
// statusMessage(tr( "Should be obsolete" )); |
| 138 |
|
| 139 |
//% "This is some random text" |
| 140 |
qtTrId("keep_id"); |
| 141 |
} |