Skip to content

Commit cde9a37

Browse files
committed
#3498 updatedialog: allow to search changelog
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent f97e706 commit cde9a37

File tree

5 files changed

+80
-17
lines changed

5 files changed

+80
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# QOwnNotes Changelog
22

3+
## 26.3.12
4+
5+
- Added a search panel to the update dialog changelog so release note changes can
6+
be searched directly with the standard find workflow (for
7+
[#3498](https://github.com/pbek/QOwnNotes/issues/3498))
8+
39
## 26.3.11
410

511
- Changed Markdown formatting syntax hiding so named links keep their URL part

src/dialogs/updatedialog.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#include <services/metricsservice.h>
55
#include <utils/gui.h>
66
#include <utils/misc.h>
7+
#include <widgets/qtexteditsearchwidget.h>
78

89
#include <QDebug>
910
#include <QDesktopServices>
1011
#include <QDir>
12+
#include <QKeyEvent>
13+
#include <QLayout>
1114
#include <QMessageBox>
1215
#include <QNetworkReply>
1316
#include <QNetworkRequest>
@@ -21,7 +24,11 @@
2124

2225
UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml, const QString &releaseUrl,
2326
const QString &releaseVersionString)
24-
: MasterDialog(parent), ui(new Ui::UpdateDialog) {
27+
: MasterDialog(parent),
28+
ui(new Ui::UpdateDialog),
29+
_networkManager(nullptr),
30+
_updateButton(nullptr),
31+
_changeLogSearchWidget(nullptr) {
2532
ui->setupUi(this);
2633
afterSetupUI();
2734
ui->downloadProgressBar->hide();
@@ -38,6 +45,20 @@ UpdateDialog::UpdateDialog(QWidget *parent, const QString &changesHtml, const QS
3845
// ui->label_4->setText("<style>" + Utils::Misc::genericCSS() +
3946
// "</style>" + ui->label_4->text());
4047

48+
_changeLogSearchWidget = new QTextEditSearchWidget(ui->changeLogEdit);
49+
_changeLogSearchWidget->setReplaceEnabled(false);
50+
_changeLogSearchWidget->setDarkMode(
51+
SettingsService().value(QStringLiteral("darkMode")).toBool());
52+
53+
auto *searchLayout = new QVBoxLayout(ui->searchFrame);
54+
searchLayout->setSpacing(0);
55+
searchLayout->setContentsMargins(0, 0, 0, 0);
56+
searchLayout->addWidget(_changeLogSearchWidget);
57+
ui->searchFrame->setLayout(searchLayout);
58+
59+
ui->changeLogEdit->installEventFilter(this);
60+
ui->changeLogEdit->viewport()->installEventFilter(this);
61+
4162
ui->changeLogEdit->setHtml(changesHtml);
4263
ui->versionLabel->setText("Version " + releaseVersionString);
4364
this->releaseVersionString = releaseVersionString;
@@ -121,6 +142,30 @@ void UpdateDialog::show() {
121142
MasterDialog::show();
122143
}
123144

145+
bool UpdateDialog::eventFilter(QObject *obj, QEvent *event) {
146+
if (((obj == ui->changeLogEdit) || (obj == ui->changeLogEdit->viewport())) &&
147+
(event->type() == QEvent::KeyPress)) {
148+
auto *keyEvent = static_cast<QKeyEvent *>(event);
149+
150+
if ((keyEvent->key() == Qt::Key_Escape) && _changeLogSearchWidget->isVisible()) {
151+
_changeLogSearchWidget->deactivate();
152+
return true;
153+
}
154+
155+
if ((keyEvent->key() == Qt::Key_F) && keyEvent->modifiers().testFlag(Qt::ControlModifier)) {
156+
_changeLogSearchWidget->activate();
157+
return true;
158+
}
159+
160+
if (keyEvent->key() == Qt::Key_F3) {
161+
_changeLogSearchWidget->doSearch(!keyEvent->modifiers().testFlag(Qt::ShiftModifier));
162+
return true;
163+
}
164+
}
165+
166+
return MasterDialog::eventFilter(obj, event);
167+
}
168+
124169
void UpdateDialog::dialogButtonClicked(QAbstractButton *button) {
125170
int actionRole = button->property("ActionRole").toInt();
126171

src/dialogs/updatedialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ class UpdateDialog;
88
}
99

1010
class QAbstractButton;
11+
class QPushButton;
1112
class QNetworkReply;
1213
class QNetworkAccessManager;
14+
class QTextEditSearchWidget;
1315

1416
class UpdateDialog : public MasterDialog {
1517
Q_OBJECT
@@ -37,6 +39,7 @@ class UpdateDialog : public MasterDialog {
3739
QString releaseVersionString;
3840
QNetworkAccessManager *_networkManager;
3941
QPushButton *_updateButton;
42+
QTextEditSearchWidget *_changeLogSearchWidget;
4043

4144
enum ButtonRole {
4245
Unset, // nothing was selected
@@ -48,6 +51,7 @@ class UpdateDialog : public MasterDialog {
4851
};
4952

5053
void closeEvent(QCloseEvent *event) override;
54+
bool eventFilter(QObject *obj, QEvent *event) override;
5155

5256
bool initializeUpdateProcess(const QString &filePath);
5357

src/dialogs/updatedialog.ui

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
</property>
4141
</widget>
4242
</item>
43-
<item>
44-
<widget class="QTextBrowser" name="changeLogEdit">
43+
<item>
44+
<widget class="QTextBrowser" name="changeLogEdit">
4545
<property name="readOnly">
4646
<bool>true</bool>
4747
</property>
@@ -61,10 +61,17 @@ p, li { white-space: pre-wrap; }
6161
<property name="openLinks">
6262
<bool>true</bool>
6363
</property>
64-
</widget>
65-
</item>
66-
<item>
67-
<widget class="QLabel" name="label_2">
64+
</widget>
65+
</item>
66+
<item>
67+
<widget class="QFrame" name="searchFrame">
68+
<property name="frameShape">
69+
<enum>QFrame::NoFrame</enum>
70+
</property>
71+
</widget>
72+
</item>
73+
<item>
74+
<widget class="QLabel" name="label_2">
6875
<property name="text">
6976
<string>Do you want to download the new version?</string>
7077
</property>

src/widgets/qtexteditsearchwidget.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
#include "ui_qtexteditsearchwidget.h"
2222

2323
QTextEditSearchWidget::QTextEditSearchWidget(QTextEdit *parent)
24-
: QWidget(parent), ui(new Ui::QTextEditSearchWidget) {
24+
: QWidget(parent), ui(new Ui::QTextEditSearchWidget), _textEdit(parent), _darkMode(false) {
2525
ui->setupUi(this);
26-
_textEdit = parent;
2726
hide();
2827

2928
QObject::connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(deactivate()));
@@ -231,15 +230,17 @@ bool QTextEditSearchWidget::doSearch(bool searchDown, bool allowRestartAtTop) {
231230
found = _textEdit->find(text, options);
232231
}
233232

234-
QRect rect = _textEdit->cursorRect();
235-
QMargins margins = _textEdit->layout()->contentsMargins();
236-
int searchWidgetHotArea = _textEdit->height() - this->height();
237-
int marginBottom = (rect.y() > searchWidgetHotArea) ? (this->height() + 10) : 0;
233+
if (_textEdit->layout() != nullptr) {
234+
QRect rect = _textEdit->cursorRect();
235+
QMargins margins = _textEdit->layout()->contentsMargins();
236+
int searchWidgetHotArea = _textEdit->height() - this->height();
237+
int marginBottom = (rect.y() > searchWidgetHotArea) ? (this->height() + 10) : 0;
238238

239-
// move the search box a bit up if we would block the search result
240-
if (margins.bottom() != marginBottom) {
241-
margins.setBottom(marginBottom);
242-
_textEdit->layout()->setContentsMargins(margins);
239+
// move the search box a bit up if we would block the search result
240+
if (margins.bottom() != marginBottom) {
241+
margins.setBottom(marginBottom);
242+
_textEdit->layout()->setContentsMargins(margins);
243+
}
243244
}
244245

245246
// add a background color according if we found the text or not

0 commit comments

Comments
 (0)