New "find" dialog for web browser.

This commit is contained in:
Martin Rotter 2017-10-25 09:39:55 +02:00
parent cf72e2c6e1
commit 67db4ede25
7 changed files with 172 additions and 35 deletions

View file

@ -2,6 +2,55 @@
#include "gui/searchtextwidget.h" #include "gui/searchtextwidget.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
SearchTextWidget::SearchTextWidget(QWidget* parent) : QWidget(parent) { SearchTextWidget::SearchTextWidget(QWidget* parent) : QWidget(parent) {
m_ui.setupUi(this); 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);
} }

View file

@ -17,6 +17,20 @@ class SearchTextWidget : public QWidget {
public: public:
explicit SearchTextWidget(QWidget* parent = nullptr); 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: private:
Ui::SearchTextWidget m_ui; Ui::SearchTextWidget m_ui;
}; };

View file

@ -6,32 +6,58 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>370</width> <width>461</width>
<height>27</height> <height>25</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>3</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>3</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>3</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>3</number>
</property> </property>
<item> <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"> <property name="placeholderText">
<string>Seach text</string> <string>Seach text</string>
</property> </property>
</widget> </widget>
</item> </item>
<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"> <property name="text">
<string/> <string/>
</property> </property>
@ -52,9 +78,18 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>BaseLineEdit</class>
<extends>QLineEdit</extends>
<header>baselineedit.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>m_txtSearch</tabstop>
<tabstop>m_btnClear</tabstop> <tabstop>m_btnClear</tabstop>
<tabstop>m_txtSearch</tabstop>
<tabstop>m_btnSearchBackward</tabstop>
<tabstop>m_btnSearchForward</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View file

@ -5,6 +5,7 @@
#include "gui/discoverfeedsbutton.h" #include "gui/discoverfeedsbutton.h"
#include "gui/locationlineedit.h" #include "gui/locationlineedit.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "gui/searchtextwidget.h"
#include "gui/webviewer.h" #include "gui/webviewer.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h" #include "miscellaneous/databasequeries.h"
@ -18,7 +19,43 @@
#include <QWebEngineSettings> #include <QWebEngineSettings>
#include <QWidgetAction> #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() { 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_webView, &WebViewer::messageStatusChangeRequested, this, &WebBrowser::receiveMessageStatusChangeRequest);
connect(m_txtLocation, &LocationLineEdit::submitted, connect(m_txtLocation, &LocationLineEdit::submitted,
this, static_cast<void (WebBrowser::*)(const QString&)>(&WebBrowser::loadUrl)); this, static_cast<void (WebBrowser::*)(const QString&)>(&WebBrowser::loadUrl));
@ -37,9 +74,7 @@ void WebBrowser::createConnections() {
} }
void WebBrowser::updateUrl(const QUrl& url) { void WebBrowser::updateUrl(const QUrl& url) {
QString url_string = url.toString(); m_txtLocation->setText(url.toString());
m_txtLocation->setText(url_string);
//setNavigationBarVisible(url_string != INTERNAL_URL_EMPTY && url_string != INTERNAL_URL_NEWSPAPER); //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() { WebBrowser::~WebBrowser() {
// Delete members. Do not use scoped pointers here. // Delete members. Do not use scoped pointers here.
delete m_layout; delete m_layout;
@ -119,6 +135,21 @@ void WebBrowser::loadMessage(const Message& message, RootItem* root) {
loadMessages(QList<Message>() << message, 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) { void WebBrowser::receiveMessageStatusChangeRequest(int message_id, WebPage::MessageStatusChange change) {
switch (change) { switch (change) {
case WebPage::MarkRead: case WebPage::MarkRead:
@ -192,8 +223,11 @@ void WebBrowser::initializeLayout() {
m_layout->addWidget(m_toolBar); m_layout->addWidget(m_toolBar);
m_layout->addWidget(m_webView); m_layout->addWidget(m_webView);
m_layout->addWidget(m_loadingProgress); m_layout->addWidget(m_loadingProgress);
m_layout->addWidget(m_searchWidget);
m_layout->setMargin(0); m_layout->setMargin(0);
m_layout->setSpacing(0); m_layout->setSpacing(0);
m_searchWidget->hide();
} }
void WebBrowser::onLoadingStarted() { void WebBrowser::onLoadingStarted() {

View file

@ -22,12 +22,13 @@ class TabWidget;
class WebViewer; class WebViewer;
class LocationLineEdit; class LocationLineEdit;
class DiscoverFeedsButton; class DiscoverFeedsButton;
class SearchTextWidget;
class WebBrowser : public TabContent { class WebBrowser : public TabContent {
Q_OBJECT Q_OBJECT
public: public:
explicit WebBrowser(QWidget* parent = 0); explicit WebBrowser(QWidget* parent = nullptr);
virtual ~WebBrowser(); virtual ~WebBrowser();
WebBrowser* webBrowser() const { WebBrowser* webBrowser() const {
@ -56,6 +57,9 @@ class WebBrowser : public TabContent {
m_toolBar->setVisible(visible); m_toolBar->setVisible(visible);
} }
protected:
bool eventFilter(QObject* watched, QEvent* event);
private slots: private slots:
void updateUrl(const QUrl& url); void updateUrl(const QUrl& url);
@ -88,6 +92,7 @@ class WebBrowser : public TabContent {
QVBoxLayout* m_layout; QVBoxLayout* m_layout;
QToolBar* m_toolBar; QToolBar* m_toolBar;
WebViewer* m_webView; WebViewer* m_webView;
SearchTextWidget* m_searchWidget;
LocationLineEdit* m_txtLocation; LocationLineEdit* m_txtLocation;
DiscoverFeedsButton* m_btnDiscoverFeeds; DiscoverFeedsButton* m_btnDiscoverFeeds;
QProgressBar* m_loadingProgress; QProgressBar* m_loadingProgress;

View file

@ -149,7 +149,7 @@ bool GmailServiceRoot::editViaGui() {
} }
bool GmailServiceRoot::supportsFeedAdding() const { bool GmailServiceRoot::supportsFeedAdding() const {
return true; return false;
} }
bool GmailServiceRoot::supportsCategoryAdding() const { bool GmailServiceRoot::supportsCategoryAdding() const {

View file

@ -109,7 +109,7 @@ bool InoreaderServiceRoot::editViaGui() {
} }
bool InoreaderServiceRoot::supportsFeedAdding() const { bool InoreaderServiceRoot::supportsFeedAdding() const {
return true; return false;
} }
bool InoreaderServiceRoot::supportsCategoryAdding() const { bool InoreaderServiceRoot::supportsCategoryAdding() const {