diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-27 01:38:16 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-27 01:38:16 +0200 |
| commit | 4ad32f09d68dd7b589e1f44ccc77766a133a6761 (patch) | |
| tree | 950c3587118ce94a4b02ab4c05ce6738ef76316f /src | |
| parent | 8a1961707348c85b6564a18a4c0c3e1d8e34b65c (diff) | |
| download | kristall-4ad32f09d68dd7b589e1f44ccc77766a133a6761.tar.gz | |
Implements Ctrl-F search, fully featured (F3, Shift-F3, Ctrl-F, Escape)
Diffstat (limited to 'src')
| -rw-r--r-- | src/browsertab.cpp | 64 | ||||
| -rw-r--r-- | src/browsertab.hpp | 18 | ||||
| -rw-r--r-- | src/browsertab.ui | 57 | ||||
| -rw-r--r-- | src/builtins.qrc | 58 | ||||
| -rw-r--r-- | src/icons.qrc | 4 | ||||
| -rw-r--r-- | src/icons/dark/actions/search-next.svg | 1 | ||||
| -rw-r--r-- | src/icons/dark/actions/search-previous.svg | 1 | ||||
| -rw-r--r-- | src/icons/light/actions/search-next.svg | 1 | ||||
| -rw-r--r-- | src/icons/light/actions/search-previous.svg | 1 | ||||
| -rwxr-xr-x | src/icons/update-themes.sh | 3 |
10 files changed, 206 insertions, 2 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 0f0d8b2..c47858f 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -36,6 +36,8 @@ #include <QImageReader> #include <QClipboard> #include <QDesktopServices> +#include <QShortcut> +#include <QKeySequence> #include <QGraphicsPixmapItem> #include <QGraphicsTextItem> @@ -60,6 +62,8 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr), this->updateUI(); + this->ui->search_bar->setVisible(false); + this->ui->media_browser->setVisible(false); this->ui->graphics_browser->setVisible(false); this->ui->text_browser->setVisible(true); @@ -78,6 +82,25 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr), this->network_timeout_timer.setTimerType(Qt::PreciseTimer); connect(&this->network_timeout_timer, &QTimer::timeout, this, &BrowserTab::on_networkTimeout); + + + + { + QShortcut * sc = new QShortcut(QKeySequence("Ctrl+F"), this); + connect(sc, &QShortcut::activated, this, &BrowserTab::on_focusSearchbar); + } + { + QShortcut * sc = new QShortcut(QKeySequence("F3"), this); + connect(sc, &QShortcut::activated, this, &BrowserTab::on_search_next_clicked); + } + { + QShortcut * sc = new QShortcut(QKeySequence("Shift+F3"), this); + connect(sc, &QShortcut::activated, this, &BrowserTab::on_search_previous_clicked); + } + { + QShortcut * sc = new QShortcut(QKeySequence("Escape"), this->ui->search_bar); + connect(sc, &QShortcut::activated, this, &BrowserTab::on_close_search_clicked); + } } BrowserTab::~BrowserTab() @@ -173,6 +196,16 @@ void BrowserTab::focusUrlBar() this->ui->url_bar->selectAll(); } +void BrowserTab::focusSearchBar() +{ + if(not this->ui->search_bar->isVisible()) { + this->ui->search_box->setText(""); + } + this->ui->search_bar->setVisible(true); + this->ui->search_box->setFocus(); + this->ui->search_box->selectAll(); +} + void BrowserTab::on_url_bar_returnPressed() { QUrl url { this->ui->url_bar->text().trimmed() }; @@ -244,6 +277,11 @@ void BrowserTab::on_networkTimeout() on_networkError(ProtocolHandler::Timeout, "The server didn't respond in time."); } +void BrowserTab::on_focusSearchbar() +{ + this->focusSearchBar(); +} + void BrowserTab::on_certificateRequired(const QString &reason) { this->network_timeout_timer.stop(); @@ -1010,3 +1048,29 @@ void BrowserTab::on_enable_client_cert_button_clicked(bool checked) resetClientCertificate(); } } + +void BrowserTab::on_search_box_textChanged(const QString &arg1) +{ + this->ui->text_browser->setTextCursor(QTextCursor { this->ui->text_browser->document() }); + this->ui->text_browser->find(arg1); +} + +void BrowserTab::on_search_box_returnPressed() +{ + this->ui->text_browser->find(this->ui->search_box->text()); +} + +void BrowserTab::on_search_next_clicked() +{ + this->ui->text_browser->find(this->ui->search_box->text()); +} + +void BrowserTab::on_search_previous_clicked() +{ + this->ui->text_browser->find(this->ui->search_box->text(), QTextDocument::FindBackward); +} + +void BrowserTab::on_close_search_clicked() +{ + this->ui->search_bar->setVisible(false); +} diff --git a/src/browsertab.hpp b/src/browsertab.hpp index 12cbc77..3d247d8 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -9,6 +9,7 @@ #include <QNetworkAccessManager> #include <QElapsedTimer> #include <QTimer> +#include <QTextCursor> #include "documentoutlinemodel.hpp" #include "tabbrowsinghistory.hpp" @@ -68,6 +69,8 @@ public: void focusUrlBar(); + void focusSearchBar(); + signals: void titleChanged(QString const & title); void locationChanged(QUrl const & url); @@ -96,6 +99,16 @@ private slots: void on_enable_client_cert_button_clicked(bool checked); + void on_search_box_textChanged(const QString &arg1); + + void on_search_box_returnPressed(); + + void on_search_next_clicked(); + + void on_search_previous_clicked(); + + void on_close_search_clicked(); + private: // network slots void on_requestProgress(qint64 transferred); @@ -108,6 +121,9 @@ private: // network slots void on_networkTimeout(); +private: // ui slots + void on_focusSearchbar(); + private: void setErrorMessage(QString const & msg); @@ -163,6 +179,8 @@ public: DocumentStats current_stats; QTimer network_timeout_timer; + + QTextCursor current_search_position; }; #endif // BROWSERTAB_HPP diff --git a/src/browsertab.ui b/src/browsertab.ui index 5a3aef5..df1b530 100644 --- a/src/browsertab.ui +++ b/src/browsertab.ui @@ -199,6 +199,63 @@ p, li { white-space: pre-wrap; } </item> </layout> </item> + <item> + <widget class="QWidget" name="search_bar" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QLineEdit" name="search_box"/> + </item> + <item> + <widget class="QToolButton" name="search_previous"> + <property name="text"> + <string>Previous</string> + </property> + <property name="icon"> + <iconset theme="search-previous"/> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="search_next"> + <property name="toolTip"> + <string>Next</string> + </property> + <property name="text"> + <string>Next</string> + </property> + <property name="icon"> + <iconset theme="search-next"/> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="close_search"> + <property name="toolTip"> + <string>Hide search</string> + </property> + <property name="text"> + <string>Hide</string> + </property> + <property name="icon"> + <iconset theme="close"/> + </property> + </widget> + </item> + </layout> + </widget> + </item> </layout> </widget> <customwidgets> diff --git a/src/builtins.qrc b/src/builtins.qrc index 9d51375..566f96b 100644 --- a/src/builtins.qrc +++ b/src/builtins.qrc @@ -18,5 +18,63 @@ <file>error_page/UnknownError.gemini</file> <file>error_page/UntrustedHost.gemini</file> <file>about/style-preview.gemini</file> + <file>icons/dark/actions/close.svg</file> + <file>icons/dark/actions/create-new.svg</file> + <file>icons/dark/actions/delete-alert.svg</file> + <file>icons/dark/actions/navigate-back.svg</file> + <file>icons/dark/actions/navigate-forward.svg</file> + <file>icons/dark/actions/pause.svg</file> + <file>icons/dark/actions/play.svg</file> + <file>icons/dark/actions/refresh.svg</file> + <file>icons/dark/actions/save-export.svg</file> + <file>icons/dark/actions/save-import.svg</file> + <file>icons/dark/actions/save.svg</file> + <file>icons/dark/actions/search-next.svg</file> + <file>icons/dark/actions/search-previous.svg</file> + <file>icons/dark/objects/bookmarks.svg</file> + <file>icons/dark/objects/certificate.svg</file> + <file>icons/dark/objects/changelog.svg</file> + <file>icons/dark/objects/folder.svg</file> + <file>icons/dark/objects/font.svg</file> + <file>icons/dark/objects/help.svg</file> + <file>icons/dark/objects/history.svg</file> + <file>icons/dark/objects/home.svg</file> + <file>icons/dark/objects/info.svg</file> + <file>icons/dark/objects/menu.svg</file> + <file>icons/dark/objects/palette.svg</file> + <file>icons/dark/objects/settings.svg</file> + <file>icons/dark/objects/table-of-contents.svg</file> + <file>icons/dark/objects/volume-off.svg</file> + <file>icons/dark/objects/volume-on.svg</file> + <file>icons/dark/index.theme</file> + <file>icons/light/actions/close.svg</file> + <file>icons/light/actions/create-new.svg</file> + <file>icons/light/actions/delete-alert.svg</file> + <file>icons/light/actions/navigate-back.svg</file> + <file>icons/light/actions/navigate-forward.svg</file> + <file>icons/light/actions/pause.svg</file> + <file>icons/light/actions/play.svg</file> + <file>icons/light/actions/refresh.svg</file> + <file>icons/light/actions/save-export.svg</file> + <file>icons/light/actions/save-import.svg</file> + <file>icons/light/actions/save.svg</file> + <file>icons/light/actions/search-next.svg</file> + <file>icons/light/actions/search-previous.svg</file> + <file>icons/light/objects/bookmarks.svg</file> + <file>icons/light/objects/certificate.svg</file> + <file>icons/light/objects/changelog.svg</file> + <file>icons/light/objects/folder.svg</file> + <file>icons/light/objects/font.svg</file> + <file>icons/light/objects/help.svg</file> + <file>icons/light/objects/history.svg</file> + <file>icons/light/objects/home.svg</file> + <file>icons/light/objects/info.svg</file> + <file>icons/light/objects/menu.svg</file> + <file>icons/light/objects/palette.svg</file> + <file>icons/light/objects/settings.svg</file> + <file>icons/light/objects/table-of-contents.svg</file> + <file>icons/light/objects/volume-off.svg</file> + <file>icons/light/objects/volume-on.svg</file> + <file>icons/light/index.theme</file> </qresource> </RCC> diff --git a/src/icons.qrc b/src/icons.qrc index 58249a7..e550b4c 100644 --- a/src/icons.qrc +++ b/src/icons.qrc @@ -77,5 +77,9 @@ <file>icons/dark/objects/volume-on.svg</file> <file>icons/dark/index.theme</file> <file>icons/update-themes.sh</file> + <file>icons/dark/actions/search-next.svg</file> + <file>icons/dark/actions/search-previous.svg</file> + <file>icons/light/actions/search-next.svg</file> + <file>icons/light/actions/search-previous.svg</file> </qresource> </RCC> diff --git a/src/icons/dark/actions/search-next.svg b/src/icons/dark/actions/search-next.svg new file mode 100644 index 0000000..59356a4 --- /dev/null +++ b/src/icons/dark/actions/search-next.svg @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="#FFFFFF" d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /></svg>
\ No newline at end of file diff --git a/src/icons/dark/actions/search-previous.svg b/src/icons/dark/actions/search-previous.svg new file mode 100644 index 0000000..4da1d2b --- /dev/null +++ b/src/icons/dark/actions/search-previous.svg @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path fill="#FFFFFF" d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" /></svg>
\ No newline at end of file diff --git a/src/icons/light/actions/search-next.svg b/src/icons/light/actions/search-next.svg new file mode 100644 index 0000000..fc32cf8 --- /dev/null +++ b/src/icons/light/actions/search-next.svg @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /></svg>
\ No newline at end of file diff --git a/src/icons/light/actions/search-previous.svg b/src/icons/light/actions/search-previous.svg new file mode 100644 index 0000000..24cd1dd --- /dev/null +++ b/src/icons/light/actions/search-previous.svg @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" /></svg>
\ No newline at end of file diff --git a/src/icons/update-themes.sh b/src/icons/update-themes.sh index 7975fb0..f9bd47b 100755 --- a/src/icons/update-themes.sh +++ b/src/icons/update-themes.sh @@ -6,5 +6,4 @@ rm -rf dark/objects/* cp -r light/actions/*.svg dark/actions cp -r light/objects/*.svg dark/objects - -sed -i 's/d=/fill="#FFFFFF" d=/g' dark/{objects,actions}/*.svg
\ No newline at end of file +sed -i 's/d=/fill="#FFFFFF" d=/g' dark/{objects,actions}/*.svg |
