New "find" dialog for web browser.
This commit is contained in:
parent
cf72e2c6e1
commit
67db4ede25
7 changed files with 172 additions and 35 deletions
|
@ -2,6 +2,55 @@
|
|||
|
||||
#include "gui/searchtextwidget.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
SearchTextWidget::SearchTextWidget(QWidget* parent) : QWidget(parent) {
|
||||
m_ui.setupUi(this);
|
||||
setFocusProxy(m_ui.m_txtSearch);
|
||||
|
||||
m_ui.m_btnClear->setIcon(qApp->icons()->fromTheme(QSL("edit-clear")));
|
||||
m_ui.m_btnSearchBackward->setIcon(qApp->icons()->fromTheme(QSL("back")));
|
||||
m_ui.m_btnSearchForward->setIcon(qApp->icons()->fromTheme(QSL("forward")));
|
||||
|
||||
connect(m_ui.m_btnClear, &QToolButton::clicked, m_ui.m_txtSearch, &QLineEdit::clear);
|
||||
connect(m_ui.m_txtSearch, &BaseLineEdit::textChanged, this, &SearchTextWidget::onTextChanged);
|
||||
connect(m_ui.m_txtSearch, &BaseLineEdit::submitted, [this]() {
|
||||
emit searchForText(m_ui.m_txtSearch->text(), false);
|
||||
});
|
||||
connect(m_ui.m_btnSearchForward, &QToolButton::clicked, [this]() {
|
||||
emit searchForText(m_ui.m_txtSearch->text(), false);
|
||||
});
|
||||
connect(m_ui.m_btnSearchBackward, &QToolButton::clicked, [this]() {
|
||||
emit searchForText(m_ui.m_txtSearch->text(), true);
|
||||
});
|
||||
}
|
||||
|
||||
void SearchTextWidget::clear() {
|
||||
m_ui.m_txtSearch->clear();
|
||||
}
|
||||
|
||||
void SearchTextWidget::onTextChanged(const QString& text) {
|
||||
m_ui.m_btnSearchBackward->setDisabled(text.isEmpty());
|
||||
m_ui.m_btnSearchForward->setDisabled(text.isEmpty());
|
||||
m_ui.m_btnClear->setDisabled(text.isEmpty());
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
emit searchForText(text, false);
|
||||
}
|
||||
else {
|
||||
emit cancelSearch();
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTextWidget::keyPressEvent(QKeyEvent* event) {
|
||||
if (event->key() == Qt::Key::Key_Escape) {
|
||||
emit cancelSearch();
|
||||
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTextWidget::focusInEvent(QFocusEvent* event) {
|
||||
QWidget::focusInEvent(event);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,20 @@ class SearchTextWidget : public QWidget {
|
|||
public:
|
||||
explicit SearchTextWidget(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void onTextChanged(const QString& text);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void focusInEvent(QFocusEvent* event);
|
||||
|
||||
signals:
|
||||
void searchForText(QString text, bool search_backwards);
|
||||
void cancelSearch();
|
||||
|
||||
private:
|
||||
Ui::SearchTextWidget m_ui;
|
||||
};
|
||||
|
|
|
@ -6,32 +6,58 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>370</width>
|
||||
<height>27</height>
|
||||
<width>461</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="m_txtSearch">
|
||||
<widget class="QToolButton" name="m_btnClear">
|
||||
<property name="toolTip">
|
||||
<string>Clear searched phrase</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BaseLineEdit" name="m_txtSearch">
|
||||
<property name="placeholderText">
|
||||
<string>Seach text</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="m_btnClear">
|
||||
<widget class="QToolButton" name="m_btnSearchBackward">
|
||||
<property name="toolTip">
|
||||
<string>Find previous occurence</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="m_btnSearchForward">
|
||||
<property name="toolTip">
|
||||
<string>Find next occurence</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -52,9 +78,18 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BaseLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>baselineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>m_txtSearch</tabstop>
|
||||
<tabstop>m_btnClear</tabstop>
|
||||
<tabstop>m_txtSearch</tabstop>
|
||||
<tabstop>m_btnSearchBackward</tabstop>
|
||||
<tabstop>m_btnSearchForward</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "gui/discoverfeedsbutton.h"
|
||||
#include "gui/locationlineedit.h"
|
||||
#include "gui/messagebox.h"
|
||||
#include "gui/searchtextwidget.h"
|
||||
#include "gui/webviewer.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
|
@ -18,7 +19,43 @@
|
|||
#include <QWebEngineSettings>
|
||||
#include <QWidgetAction>
|
||||
|
||||
WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
|
||||
m_layout(new QVBoxLayout(this)),
|
||||
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
||||
m_webView(new WebViewer(this)),
|
||||
m_searchWidget(new SearchTextWidget(this)),
|
||||
m_txtLocation(new LocationLineEdit(this)),
|
||||
m_btnDiscoverFeeds(new DiscoverFeedsButton(this)),
|
||||
m_actionBack(m_webView->pageAction(QWebEnginePage::Back)),
|
||||
m_actionForward(m_webView->pageAction(QWebEnginePage::Forward)),
|
||||
m_actionReload(m_webView->pageAction(QWebEnginePage::Reload)),
|
||||
m_actionStop(m_webView->pageAction(QWebEnginePage::Stop)) {
|
||||
// Initialize the components and layout.
|
||||
initializeLayout();
|
||||
setFocusProxy(m_txtLocation);
|
||||
setTabOrder(m_txtLocation, m_toolBar);
|
||||
setTabOrder(m_toolBar, m_webView);
|
||||
createConnections();
|
||||
reloadFontSettings();
|
||||
}
|
||||
|
||||
void WebBrowser::createConnections() {
|
||||
installEventFilter(this);
|
||||
|
||||
connect(m_searchWidget, &SearchTextWidget::cancelSearch, this, [this]() {
|
||||
m_webView->findText(QString());
|
||||
});
|
||||
connect(m_searchWidget, &SearchTextWidget::searchForText, this, [this](const QString& text, bool backwards) {
|
||||
if (backwards) {
|
||||
m_webView->findText(text, QWebEnginePage::FindBackward);
|
||||
}
|
||||
else {
|
||||
m_webView->findText(text);
|
||||
}
|
||||
|
||||
m_searchWidget->setFocus();
|
||||
});
|
||||
|
||||
connect(m_webView, &WebViewer::messageStatusChangeRequested, this, &WebBrowser::receiveMessageStatusChangeRequest);
|
||||
connect(m_txtLocation, &LocationLineEdit::submitted,
|
||||
this, static_cast<void (WebBrowser::*)(const QString&)>(&WebBrowser::loadUrl));
|
||||
|
@ -37,9 +74,7 @@ void WebBrowser::createConnections() {
|
|||
}
|
||||
|
||||
void WebBrowser::updateUrl(const QUrl& url) {
|
||||
QString url_string = url.toString();
|
||||
|
||||
m_txtLocation->setText(url_string);
|
||||
m_txtLocation->setText(url.toString());
|
||||
|
||||
//setNavigationBarVisible(url_string != INTERNAL_URL_EMPTY && url_string != INTERNAL_URL_NEWSPAPER);
|
||||
}
|
||||
|
@ -50,25 +85,6 @@ void WebBrowser::loadUrl(const QUrl& url) {
|
|||
}
|
||||
}
|
||||
|
||||
WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
|
||||
m_layout(new QVBoxLayout(this)),
|
||||
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
||||
m_webView(new WebViewer(this)),
|
||||
m_txtLocation(new LocationLineEdit(this)),
|
||||
m_btnDiscoverFeeds(new DiscoverFeedsButton(this)),
|
||||
m_actionBack(m_webView->pageAction(QWebEnginePage::Back)),
|
||||
m_actionForward(m_webView->pageAction(QWebEnginePage::Forward)),
|
||||
m_actionReload(m_webView->pageAction(QWebEnginePage::Reload)),
|
||||
m_actionStop(m_webView->pageAction(QWebEnginePage::Stop)) {
|
||||
// Initialize the components and layout.
|
||||
initializeLayout();
|
||||
setFocusProxy(m_txtLocation);
|
||||
setTabOrder(m_txtLocation, m_toolBar);
|
||||
setTabOrder(m_toolBar, m_webView);
|
||||
createConnections();
|
||||
reloadFontSettings();
|
||||
}
|
||||
|
||||
WebBrowser::~WebBrowser() {
|
||||
// Delete members. Do not use scoped pointers here.
|
||||
delete m_layout;
|
||||
|
@ -119,6 +135,21 @@ void WebBrowser::loadMessage(const Message& message, RootItem* root) {
|
|||
loadMessages(QList<Message>() << message, root);
|
||||
}
|
||||
|
||||
bool WebBrowser::eventFilter(QObject* watched, QEvent* event) {
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
|
||||
|
||||
if (key_event->matches(QKeySequence::StandardKey::Find)) {
|
||||
m_searchWidget->clear();
|
||||
m_searchWidget->show();
|
||||
m_searchWidget->setFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebBrowser::receiveMessageStatusChangeRequest(int message_id, WebPage::MessageStatusChange change) {
|
||||
switch (change) {
|
||||
case WebPage::MarkRead:
|
||||
|
@ -192,8 +223,11 @@ void WebBrowser::initializeLayout() {
|
|||
m_layout->addWidget(m_toolBar);
|
||||
m_layout->addWidget(m_webView);
|
||||
m_layout->addWidget(m_loadingProgress);
|
||||
m_layout->addWidget(m_searchWidget);
|
||||
m_layout->setMargin(0);
|
||||
m_layout->setSpacing(0);
|
||||
|
||||
m_searchWidget->hide();
|
||||
}
|
||||
|
||||
void WebBrowser::onLoadingStarted() {
|
||||
|
|
|
@ -22,12 +22,13 @@ class TabWidget;
|
|||
class WebViewer;
|
||||
class LocationLineEdit;
|
||||
class DiscoverFeedsButton;
|
||||
class SearchTextWidget;
|
||||
|
||||
class WebBrowser : public TabContent {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WebBrowser(QWidget* parent = 0);
|
||||
explicit WebBrowser(QWidget* parent = nullptr);
|
||||
virtual ~WebBrowser();
|
||||
|
||||
WebBrowser* webBrowser() const {
|
||||
|
@ -56,6 +57,9 @@ class WebBrowser : public TabContent {
|
|||
m_toolBar->setVisible(visible);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* watched, QEvent* event);
|
||||
|
||||
private slots:
|
||||
void updateUrl(const QUrl& url);
|
||||
|
||||
|
@ -88,6 +92,7 @@ class WebBrowser : public TabContent {
|
|||
QVBoxLayout* m_layout;
|
||||
QToolBar* m_toolBar;
|
||||
WebViewer* m_webView;
|
||||
SearchTextWidget* m_searchWidget;
|
||||
LocationLineEdit* m_txtLocation;
|
||||
DiscoverFeedsButton* m_btnDiscoverFeeds;
|
||||
QProgressBar* m_loadingProgress;
|
||||
|
|
|
@ -149,7 +149,7 @@ bool GmailServiceRoot::editViaGui() {
|
|||
}
|
||||
|
||||
bool GmailServiceRoot::supportsFeedAdding() const {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GmailServiceRoot::supportsCategoryAdding() const {
|
||||
|
|
|
@ -109,7 +109,7 @@ bool InoreaderServiceRoot::editViaGui() {
|
|||
}
|
||||
|
||||
bool InoreaderServiceRoot::supportsFeedAdding() const {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InoreaderServiceRoot::supportsCategoryAdding() const {
|
||||
|
|
Loading…
Add table
Reference in a new issue