Changeset View
Changeset View
Standalone View
Standalone View
src/lib/webtab/searchtoolbar.cpp
Show All 32 Lines | |||||
33 | { | 33 | { | ||
34 | setAttribute(Qt::WA_DeleteOnClose); | 34 | setAttribute(Qt::WA_DeleteOnClose); | ||
35 | ui->setupUi(this); | 35 | ui->setupUi(this); | ||
36 | 36 | | |||
37 | ui->closeButton->setIcon(IconProvider::instance()->standardIcon(QStyle::SP_DialogCloseButton)); | 37 | ui->closeButton->setIcon(IconProvider::instance()->standardIcon(QStyle::SP_DialogCloseButton)); | ||
38 | ui->next->setShortcut(QKeySequence("Ctrl+G")); | 38 | ui->next->setShortcut(QKeySequence("Ctrl+G")); | ||
39 | ui->previous->setShortcut(QKeySequence("Ctrl+Shift+G")); | 39 | ui->previous->setShortcut(QKeySequence("Ctrl+Shift+G")); | ||
40 | 40 | | |||
41 | ui->resultsInfo->hide(); | ||||
drosca: Should be hidden in the UI file. | |||||
That would make it very hard to edit in QtDesigner. SGOrava: That would make it very hard to edit in QtDesigner.
The visibility option is not even there and… | |||||
drosca: Yes, you are right. | |||||
42 | #if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0) | ||||
43 | connect(view->page(), &QWebEnginePage::findTextFinished, this, &SearchToolBar::showSearchResults); | ||||
44 | #endif | ||||
45 | | ||||
41 | connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); | 46 | connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); | ||
42 | connect(ui->lineEdit, &QLineEdit::textEdited, this, &SearchToolBar::findNext); | 47 | connect(ui->lineEdit, &QLineEdit::textEdited, this, &SearchToolBar::findNext); | ||
43 | connect(ui->next, &QAbstractButton::clicked, this, &SearchToolBar::findNext); | 48 | connect(ui->next, &QAbstractButton::clicked, this, &SearchToolBar::findNext); | ||
44 | connect(ui->previous, &QAbstractButton::clicked, this, &SearchToolBar::findPrevious); | 49 | connect(ui->previous, &QAbstractButton::clicked, this, &SearchToolBar::findPrevious); | ||
45 | connect(ui->caseSensitive, &QAbstractButton::clicked, this, &SearchToolBar::caseSensitivityChanged); | 50 | connect(ui->caseSensitive, &QAbstractButton::clicked, this, &SearchToolBar::caseSensitivityChanged); | ||
46 | 51 | | |||
47 | QShortcut* findNextAction = new QShortcut(QKeySequence("F3"), this); | 52 | QShortcut* findNextAction = new QShortcut(QKeySequence("F3"), this); | ||
48 | connect(findNextAction, &QShortcut::activated, this, &SearchToolBar::findNext); | 53 | connect(findNextAction, &QShortcut::activated, this, &SearchToolBar::findNext); | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 126 | m_view->findText(text, m_findFlags, [=](bool found) { | |||
132 | ui->lineEdit->style()->unpolish(ui->lineEdit); | 137 | ui->lineEdit->style()->unpolish(ui->lineEdit); | ||
133 | ui->lineEdit->style()->polish(ui->lineEdit); | 138 | ui->lineEdit->style()->polish(ui->lineEdit); | ||
134 | 139 | | |||
135 | // Clear selection | 140 | // Clear selection | ||
136 | m_view->page()->runJavaScript(QSL("window.getSelection().empty();"), WebPage::SafeJsWorld); | 141 | m_view->page()->runJavaScript(QSL("window.getSelection().empty();"), WebPage::SafeJsWorld); | ||
137 | }); | 142 | }); | ||
138 | } | 143 | } | ||
139 | 144 | | |||
145 | #if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0) | ||||
146 | void SearchToolBar::showSearchResults(const QWebEngineFindTextResult &result) | ||||
drosca: coding style `const QWebEngineFindTextResult &result` | |||||
147 | { | ||||
148 | if (result.numberOfMatches() == 0) { | ||||
drosca: No need, `this` will always be valid here. | |||||
I thought it can be truigerred even when this object is being killed... SGOrava: I thought it can be truigerred even when this object is being killed... | |||||
drosca: It can't, because you are using `connect(.., ..., THIS, ...)` | |||||
drosca: And even if it were possible, this check wouldn't solve anything :D | |||||
Yes, now I actually see it. SGOrava: Yes, now I actually see it.
I will not copy someone elses code this whole month! | |||||
149 | ui->resultsInfo->hide(); | ||||
150 | return; | ||||
151 | } | ||||
152 | | ||||
153 | ui->resultsInfo->setText(tr("%1 of %2").arg( | ||||
154 | QString::number(result.activeMatch()), QString::number(result.numberOfMatches()))); | ||||
155 | ui->resultsInfo->show(); | ||||
156 | } | ||||
157 | #endif | ||||
158 | | ||||
140 | bool SearchToolBar::eventFilter(QObject* obj, QEvent* event) | 159 | bool SearchToolBar::eventFilter(QObject* obj, QEvent* event) | ||
141 | { | 160 | { | ||
142 | Q_UNUSED(obj); | 161 | Q_UNUSED(obj); | ||
143 | 162 | | |||
144 | if (event->type() == QEvent::KeyPress) { | 163 | if (event->type() == QEvent::KeyPress) { | ||
145 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | 164 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | ||
146 | switch (ke->key()) { | 165 | switch (ke->key()) { | ||
147 | case Qt::Key_Escape: | 166 | case Qt::Key_Escape: | ||
Show All 22 Lines |
Should be hidden in the UI file.