new Find in page in a bottom bar (#347)

Zimview is now a container for the webview and the find in page bar
Add a F3 shortcut
ESC hides the search bar and the highlighting
This commit is contained in:
jetownfeve21 2020-04-01 19:29:28 +02:00 committed by GitHub
parent 99ac7ab090
commit 135baf48cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 351 additions and 319 deletions

View File

@ -45,6 +45,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
src/findinpagebar.cpp \
src/main.cpp \
src/mainwindow.cpp \
src/kiwixapp.cpp \
@ -60,7 +61,6 @@ SOURCES += \
src/mainmenu.cpp \
src/webpage.cpp \
src/about.cpp \
src/tocsidebar.cpp \
src/contentmanager.cpp \
src/contentmanagerview.cpp \
src/tabbar.cpp \
@ -70,9 +70,11 @@ SOURCES += \
src/opdsrequestmanager.cpp \
src/localkiwixserver.cpp \
src/fullscreenwindow.cpp \
src/fullscreennotification.cpp
src/fullscreennotification.cpp \
src/zimview.cpp
HEADERS += \
src/findinpagebar.h \
src/mainwindow.h \
src/kiwixapp.h \
src/kprofile.h \
@ -88,7 +90,6 @@ HEADERS += \
src/mainmenu.h \
src/webpage.h \
src/about.h \
src/tocsidebar.h \
src/contentmanager.h \
src/contentmanagerview.h \
src/tabbar.h \
@ -99,12 +100,13 @@ HEADERS += \
src/localkiwixserver.h \
src/fullscreenwindow.h \
src/fullscreennotification.h \
src/menuproxystyle.h
src/menuproxystyle.h \
src/zimview.h
FORMS += \
src/findinpagebar.ui \
ui/mainwindow.ui \
ui/about.ui \
src/tocsidebar.ui \
src/contentmanagerside.ui \
src/readinglistbar.ui \
ui/localkiwixserver.ui

View File

@ -174,6 +174,10 @@ QTabBar::tab:last QToolButton::hover {
Find Search page
*/
#FindInPageBar {
border-top: 1px solid #ccc;
}
#findEdit {
background-color: white;
padding: 2px;
@ -182,30 +186,25 @@ QTabBar::tab:last QToolButton::hover {
font-size: 16px;
border: 1px solid #ccc;
border-radius: 0px;
border-bottom-left-radius: 5px;
border-top-left-radius: 5px;
}
#fNextButton,
#fPreviousButton {
#fPreviousButton,
#hideButton {
outline: none;
max-height: 36px;
max-width: 36px;
border: 1px solid #ccc;
border-radius: 0px;
margin-left: -2px;
}
#fNextButton:pressed,
#fPreviousButton:pressed {
#fPreviousButton:pressed,
#hideButton:pressed {
background-color: #D9E9FF;
border: 1px solid #3366CC;
}
#fPreviousButton {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
/* ----------------------------------------
Find Search page
*/

View File

@ -230,7 +230,7 @@ void ContentManager::eraseBook(const QString& id)
auto tabBar = KiwixApp::instance()->getTabWidget();
int i = 1;
while (i < tabBar->count() - 1) {
WebView* webView = tabBar->widget(i);
WebView* webView = tabBar->widget(i)->getWebView();
if (webView->zimId() == id) {
tabBar->closeTab(i);
} else {

View File

@ -1,63 +1,69 @@
#include "tocsidebar.h"
#include "ui_tocsidebar.h"
#include "findinpagebar.h"
#include "ui_findinpagebar.h"
#include "kiwixapp.h"
TocSideBar::TocSideBar(QWidget *parent) :
QWidget(parent),
mp_ui(new Ui::TocSideBar)
FindInPageBar::FindInPageBar(QWidget *parent) :
QFrame(parent),
mp_ui(new Ui::FindInPageBar)
{
mp_ui->setupUi(this);
mp_findLineEdit = mp_ui->findEdit;
connect(mp_ui->hideButton, &QPushButton::released,
this, &TocSideBar::findClose);
this, &FindInPageBar::findClose);
connect(mp_ui->fNextButton, &QPushButton::released,
this, &TocSideBar::findNext);
this, &FindInPageBar::findNext);
connect(mp_ui->fPreviousButton, &QPushButton::released,
this, &TocSideBar::findPrevious);
this, &FindInPageBar::findPrevious);
connect(mp_findLineEdit, &QLineEdit::returnPressed,
this, &TocSideBar::findNext);
this, &FindInPageBar::findNext);
}
TocSideBar::~TocSideBar()
FindInPageBar::~FindInPageBar()
{
delete mp_ui;
}
void TocSideBar::postInit()
{
}
void TocSideBar::findClose()
{
auto current = KiwixApp::instance()->getTabWidget()->currentWidget();
if (!current)
return;
auto page = current->page();
page->findText("");
KiwixApp::instance()->setSideBar(KiwixApp::NONE);
}
void TocSideBar::findNext()
void FindInPageBar::findNext()
{
auto searchText = mp_findLineEdit->text();
if (searchText.isEmpty())
return;
auto current = KiwixApp::instance()->getTabWidget()->currentWidget();
auto current = KiwixApp::instance()->getTabWidget()->currentWebView();
if (!current)
return;
auto page = current->page();
page->findText(searchText);
}
void TocSideBar::findPrevious()
void FindInPageBar::findPrevious()
{
auto searchText = mp_findLineEdit->text();
if (searchText.isEmpty())
return;
auto current = KiwixApp::instance()->getTabWidget()->currentWidget();
auto current = KiwixApp::instance()->getTabWidget()->currentWebView();
if (!current)
return;
auto page = current->page();
page->findText(searchText, QWebEnginePage::FindBackward);
}
void FindInPageBar::findClose()
{
auto current = KiwixApp::instance()->getTabWidget()->currentWebView();
if (!current)
return;
auto page = current->page();
page->findText("");
close();
}
void FindInPageBar::keyPressEvent(QKeyEvent *event)
{
switch(event->key()) {
case Qt::Key_Escape:
findClose();
break;
default:
QWidget::keyPressEvent(event);
}
}

34
src/findinpagebar.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef FINDINPAGEBAR_H
#define FINDINPAGEBAR_H
#include <QFrame>
#include <QLineEdit>
namespace Ui {
class FindInPageBar;
}
class FindInPageBar : public QFrame
{
Q_OBJECT
public:
explicit FindInPageBar(QWidget *parent = nullptr);
~FindInPageBar();
QLineEdit* getFindLineEdit() { return mp_findLineEdit; };
public slots:
void findNext();
void findPrevious();
void findClose();
protected:
void keyPressEvent(QKeyEvent *event);
private:
Ui::FindInPageBar *mp_ui;
QLineEdit *mp_findLineEdit;
};
#endif // FINDINPAGEBAR_H

82
src/findinpagebar.ui Normal file
View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FindInPageBar</class>
<widget class="QFrame" name="FindInPageBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>833</width>
<height>43</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="findEdit">
<property name="placeholderText">
<string>Find in page</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fNextButton">
<property name="icon">
<iconset resource="../resources/kiwix.qrc">
<normaloff>:/icons/search_forward.svg</normaloff>:/icons/search_forward.svg</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fPreviousButton">
<property name="icon">
<iconset resource="../resources/kiwix.qrc">
<normaloff>:/icons/search_backward.svg</normaloff>:/icons/search_backward.svg</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>350</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="hideButton">
<property name="icon">
<iconset resource="../resources/kiwix.qrc">
<normaloff>:/icons/close.svg</normaloff>:/icons/close.svg</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../resources/kiwix.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -160,7 +160,7 @@ void KiwixApp::printPage()
printDialog.setStyle(nullptr);
printDialog.setStyleSheet("");
if (printDialog.exec() == QDialog::Accepted) {
auto webview = mp_tabWidget->currentWidget();
auto webview = mp_tabWidget->currentWebView();
if(!webview)
return;
webview->page()->print(printer, [=](bool success) {
@ -184,8 +184,6 @@ void KiwixApp::setSideBar(KiwixApp::SideBarType type)
{
auto sideDockWidget = mp_mainWindow->getSideDockWidget();
switch(type) {
case SEARCH_BAR:
mp_mainWindow->findChild<TocSideBar*>("tocsidebar")->getFindLineEdit()->setFocus();
case CONTENTMANAGER_BAR:
case READINGLIST_BAR:
sideDockWidget->setCurrentIndex(type);
@ -317,9 +315,9 @@ void KiwixApp::createAction()
HIDE_ACTION(SearchLibraryAction);
CREATE_ACTION(FindInPageAction, tr("Find in page"));
SET_SHORTCUT(FindInPageAction, QKeySequence::Find);
mpa_actions[FindInPageAction]->setShortcuts({QKeySequence::Find, Qt::Key_F3});
connect(mpa_actions[FindInPageAction], &QAction::triggered,
this, [=]() { toggleSideBar(SEARCH_BAR); });
this, [=]() { mp_tabWidget->openFindInPageBar(); });
CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", tr("Set fullScreen"));
SET_SHORTCUT(ToggleFullscreenAction, QKeySequence::FullScreen);

View File

@ -7,8 +7,8 @@
#include "kiwix/downloader.h"
#include <kiwix/kiwixserve.h>
#include "tabbar.h"
#include "tocsidebar.h"
#include "kprofile.h"
#include "urlschemehandler.h"
#include "settingsmanager.h"
#include <QApplication>
@ -54,7 +54,6 @@ public:
MAX_ACTION
};
enum SideBarType {
SEARCH_BAR,
CONTENTMANAGER_BAR,
READINGLIST_BAR,
NONE

View File

@ -6,7 +6,6 @@
#include "webview.h"
#include "tabbar.h"
#include "topwidget.h"
#include "tocsidebar.h"
#include "about.h"
#include "contentmanagerside.h"
#include "localkiwixserver.h"

View File

@ -122,7 +122,7 @@ void SearchBar::updateCompletion(const QString &text)
{
QStringList wordList;
m_urlList.clear();
auto currentWidget = KiwixApp::instance()->getTabWidget()->currentWidget();
auto currentWidget = KiwixApp::instance()->getTabWidget()->currentWebView();
if (!currentWidget) {
m_completionModel.setStringList(wordList);
return;

View File

@ -37,40 +37,9 @@ TabBar::TabBar(QWidget *parent) :
}
this->closeTab(index);
});
connect(app->getAction(KiwixApp::ZoomInAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
QUITIFNULL(current);
auto zoomFactor = current->zoomFactor();
zoomFactor += 0.1;
zoomFactor = max(min(zoomFactor, 5.0), 0.25);
current->setZoomFactor(zoomFactor);
auto key = this->currentZimId() + "/zoomFactor";
KiwixApp::instance()->getSettingsManager()->setSettings(key, zoomFactor);
});
connect(app->getAction(KiwixApp::ZoomOutAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
QUITIFNULL(current);
auto zoomFactor = current->zoomFactor();
zoomFactor -= 0.1;
zoomFactor = max(min(zoomFactor, 5.0), 0.25);
current->setZoomFactor(zoomFactor);
auto key = this->currentZimId() + "/zoomFactor";
KiwixApp::instance()->getSettingsManager()->setSettings(key, zoomFactor);
});
connect(app->getAction(KiwixApp::ZoomResetAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
QUITIFNULL(current);
auto settingsManager = KiwixApp::instance()->getSettingsManager();
current->setZoomFactor(settingsManager->getZoomFactor());
auto key = this->currentZimId() + "/zoomFactor";
settingsManager->deleteSettings(key);
});
connect(app->getAction(KiwixApp::OpenHomePageAction), &QAction::triggered,
this, [=]() {
auto current = this->currentWidget();
auto current = this->currentWebView();
QUITIFNULL(current);
current->setUrl("zim://" + current->zimId() + ".zim/");
});
@ -80,6 +49,7 @@ TabBar::TabBar(QWidget *parent) :
return;
}
auto index = currentIndex() + 1;
m_settingsIndex = index;
auto view = KiwixApp::instance()->getSettingsManager()->getView();
mp_stackedWidget->insertWidget(index, view);
insertTab(index,QIcon(":/icons/settings.svg"), tr("Settings"));
@ -87,7 +57,6 @@ TabBar::TabBar(QWidget *parent) :
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
setTabButton(index, QTabBar::RightSide, tb);
setCurrentIndex(index);
m_settingsIndex = index;
});
}
@ -119,51 +88,11 @@ void TabBar::setNewTabButton()
setTabButton(1, QTabBar::RightSide, 0);
}
WebView* TabBar::createNewTab(bool setCurrent)
ZimView* TabBar::createNewTab(bool setCurrent)
{
WebView* webView = new WebView();
connect(webView->page(), &QWebEnginePage::fullScreenRequested, this, &TabBar::fullScreenRequested);
connect(webView, &WebView::titleChanged, this,
[=](const QString& str) {
setTitleOf(str, webView);
QUITIFNOTCURRENT(webView);
emit currentTitleChanged(str);
});
connect(webView, &WebView::iconChanged, this,
[=](const QIcon& icon) { setIconOf(icon, webView); });
connect(webView, &WebView::zimIdChanged, this,
[=](const QString& zimId) {
QUITIFNOTCURRENT(webView);
emit currentZimIdChanged(zimId);
});
connect(webView->page()->action(QWebEnginePage::Back), &QAction::changed,
[=]() {
QUITIFNOTCURRENT(webView);
emit webActionEnabledChanged(QWebEnginePage::Back, webView->isWebActionEnabled(QWebEnginePage::Back));
});
connect(webView->page()->action(QWebEnginePage::Forward), &QAction::changed,
[=]() {
QUITIFNOTCURRENT(webView);
emit webActionEnabledChanged(QWebEnginePage::Forward, webView->isWebActionEnabled(QWebEnginePage::Forward));
});
connect(webView->page(), &QWebEnginePage::linkHovered, this,
[=](const QString& url) {
auto tabbar = KiwixApp::instance()->getTabWidget();
if (url.isEmpty()) {
QToolTip::hideText();
} else {
auto link = url;
if (url.startsWith("zim://")) {
link = QUrl(url).path();
}
auto height = tabbar->currentWidget()->height() + 1;
auto pos = tabbar->mapToGlobal(QPoint(-3, height));
QToolTip::showText(pos, link);
}
});
// Ownership of webview is passed to the tabWidget
auto tab = new ZimView(this, this);
auto index = count() - 1;
mp_stackedWidget->insertWidget(index, webView);
mp_stackedWidget->insertWidget(index, tab);
insertTab(index, "");
QToolButton *tb = new QToolButton(this);
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
@ -171,55 +100,55 @@ WebView* TabBar::createNewTab(bool setCurrent)
if (setCurrent) {
setCurrentIndex(index);
}
return webView;
return tab;
}
void TabBar::openUrl(const QUrl& url, bool newTab)
{
WebView* webView = currentWidget();
WebView* webView = currentWebView();
if (newTab || !webView) {
webView = createNewTab(true);
webView = createNewTab(true)->getWebView();
}
QUITIFNULL(webView);
webView->setUrl(url);
}
void TabBar::setTitleOf(const QString& title, WebView* webView)
void TabBar::setTitleOf(const QString& title, ZimView* tab)
{
CURRENTIFNULL(webView);
CURRENTIFNULL(tab);
if (title.startsWith("zim://")) {
auto url = QUrl(title);
setTabText(mp_stackedWidget->indexOf(webView), url.path());
setTabText(mp_stackedWidget->indexOf(tab), url.path());
} else {
setTabText(mp_stackedWidget->indexOf(webView), title);
setTabText(mp_stackedWidget->indexOf(tab), title);
}
}
void TabBar::setIconOf(const QIcon &icon, WebView *webView)
void TabBar::setIconOf(const QIcon &icon, ZimView *tab)
{
CURRENTIFNULL(webView);
setTabIcon(mp_stackedWidget->indexOf(webView), icon);
CURRENTIFNULL(tab);
setTabIcon(mp_stackedWidget->indexOf(tab), icon);
}
QString TabBar::currentZimId()
{
if (!currentWidget())
return "";
return currentWidget()->zimId();
return currentWebView()->zimId();
}
QString TabBar::currentArticleUrl()
{
if(!currentWidget())
return "";
return currentWidget()->url().path();
return currentWebView()->url().path();
}
QString TabBar::currentArticleTitle()
{
if(!currentWidget())
return "";
return currentWidget()->title();
return currentWebView()->title();
}
QSize TabBar::tabSizeHint(int index) const {
@ -228,12 +157,17 @@ QSize TabBar::tabSizeHint(int index) const {
return QSize(40, 40);
}
void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, WebView *webView)
void TabBar::openFindInPageBar()
{
CURRENTIFNULL(webView);
QUITIFNULL(webView);
webView->triggerPageAction(action);
webView->setFocus();
currentWidget()->openFindInPageBar();
}
void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, ZimView *widget)
{
CURRENTIFNULL(widget);
QUITIFNULL(widget);
widget->getWebView()->triggerPageAction(action);
widget->getWebView()->setFocus();
}
void TabBar::closeTab(int index)
@ -275,7 +209,7 @@ void TabBar::onCurrentChanged(int index)
KiwixApp::instance()->setSideBar(KiwixApp::NONE);
QTimer::singleShot(0, [=](){emit currentTitleChanged("");});
} else if (index) {
auto view = widget(index);
auto view = widget(index)->getWebView();
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
emit libraryPageDisplayed(false);
@ -298,7 +232,7 @@ void TabBar::fullScreenRequested(QWebEngineFullScreenRequest request)
if (m_fullScreenWindow)
return;
request.accept();
m_fullScreenWindow.reset(new FullScreenWindow(this->currentWidget()));
m_fullScreenWindow.reset(new FullScreenWindow(this->currentWebView()));
} else {
if (!m_fullScreenWindow)
return;

View File

@ -5,6 +5,7 @@
#include <QStackedWidget>
#include <memory>
#include "webview.h"
#include "zimview.h"
#include "contentmanagerview.h"
#include "fullscreenwindow.h"
#include <QMouseEvent>
@ -21,24 +22,29 @@ public:
void setContentManagerView(ContentManagerView* view);
void setNewTabButton();
WebView* createNewTab(bool setCurrent);
WebView* widget(int index) { return (index != 0) ? static_cast<WebView*>(mp_stackedWidget->widget(index)) : nullptr; }
WebView* currentWidget() { auto current = mp_stackedWidget->currentWidget();
if (current == mp_contentManagerView ||
ZimView* createNewTab(bool setCurrent);
ZimView* widget(int index) { return (index != 0) ? static_cast<ZimView*>(mp_stackedWidget->widget(index)) : nullptr; }
WebView* currentWebView() { auto current = mp_stackedWidget->currentWidget();
if (mp_stackedWidget->currentIndex() == 0) return nullptr;
return static_cast<ZimView*>(current)->getWebView();
}
ZimView* currentWidget() { auto current = mp_stackedWidget->currentWidget();
if (mp_stackedWidget->currentIndex() == 0 ||
mp_stackedWidget->currentIndex() == m_settingsIndex) return nullptr;
return static_cast<WebView*>(current);
return static_cast<ZimView*>(current);
}
void openUrl(const QUrl &url, bool newTab);
// Redirect call to sub-webView
void setTitleOf(const QString& title, WebView* webView=nullptr);
void setIconOf(const QIcon& icon, WebView* webView=nullptr);
void setTitleOf(const QString& title, ZimView* tab=nullptr);
void setIconOf(const QIcon& icon, ZimView* tab=nullptr);
QString currentZimId();
void triggerWebPageAction(QWebEnginePage::WebAction action, WebView* webView=nullptr);
void triggerWebPageAction(QWebEnginePage::WebAction action, ZimView* widget=nullptr);
QString currentArticleUrl();
QString currentArticleTitle();
virtual QSize tabSizeHint(int index) const;
void openFindInPageBar();
protected:
void mousePressEvent(QMouseEvent *event);

View File

@ -1,32 +0,0 @@
#ifndef TOCSIDEBAR_H
#define TOCSIDEBAR_H
#include <QWidget>
#include <QLineEdit>
namespace Ui {
class TocSideBar;
}
class TocSideBar : public QWidget
{
Q_OBJECT
public:
explicit TocSideBar(QWidget *parent = 0);
~TocSideBar();
void postInit();
QLineEdit* getFindLineEdit() { return mp_findLineEdit; };
public slots:
void findNext();
void findPrevious();
void findClose();
private:
Ui::TocSideBar *mp_ui;
QLineEdit *mp_findLineEdit;
};
#endif // TOCSIDEBAR_H

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TocSideBar</class>
<widget class="QWidget" name="TocSideBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="hideButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Hide</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QLineEdit" name="findEdit"/>
</item>
<item>
<widget class="QPushButton" name="fNextButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/kiwix.qrc">
<normaloff>:/icons/search_forward.svg</normaloff>:/icons/search_forward.svg</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fPreviousButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/kiwix.qrc">
<normaloff>:/icons/search_backward.svg</normaloff>:/icons/search_backward.svg</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../resources/kiwix.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -7,6 +7,7 @@
#include "webpage.h"
#include <QToolTip>
#include <QWebEngineSettings>
#include <QVBoxLayout>
WebView::WebView(QWidget *parent)
: QWebEngineView(parent)
@ -32,7 +33,7 @@ QWebEngineView* WebView::createWindow(QWebEnginePage::WebWindowType type)
|| type==QWebEnginePage::WebBrowserTab )
{
auto tabWidget = KiwixApp::instance()->getTabWidget();
return tabWidget->createNewTab(type==QWebEnginePage::WebBrowserTab);
return tabWidget->createNewTab(type==QWebEnginePage::WebBrowserTab)->getWebView();
}
return nullptr;
}

View File

@ -6,6 +6,7 @@
#include <QWheelEvent>
#include <kiwix/reader.h>
#include "findinpagebar.h"
class WebView : public QWebEngineView
{

101
src/zimview.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "zimview.h"
#include "kiwixapp.h"
#include <QAction>
#include <QVBoxLayout>
#include <QToolTip>
ZimView::ZimView(TabBar *tabBar, QWidget *parent)
: QWidget(parent),
mp_tabBar(tabBar),
mp_findInPageBar(new FindInPageBar(this))
{
mp_webView = new WebView();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mp_webView);
layout->addWidget(mp_findInPageBar);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
setLayout(layout);
mp_findInPageBar->hide();
auto app = KiwixApp::instance();
connect(app->getAction(KiwixApp::ZoomInAction), &QAction::triggered,
this, [=]() {
auto zoomFactor = mp_webView->zoomFactor();
zoomFactor += 0.1;
zoomFactor = max(min(zoomFactor, 5.0), 0.25);
mp_webView->setZoomFactor(zoomFactor);
auto key = mp_webView->zimId() + "/zoomFactor";
KiwixApp::instance()->getSettingsManager()->setSettings(key, zoomFactor);
});
connect(app->getAction(KiwixApp::ZoomOutAction), &QAction::triggered,
this, [=]() {
auto zoomFactor = mp_webView->zoomFactor();
zoomFactor -= 0.1;
zoomFactor = max(min(zoomFactor, 5.0), 0.25);
mp_webView->setZoomFactor(zoomFactor);
auto key = mp_webView->zimId() + "/zoomFactor";
KiwixApp::instance()->getSettingsManager()->setSettings(key, zoomFactor);
});
connect(app->getAction(KiwixApp::ZoomResetAction), &QAction::triggered,
this, [=]() {
auto settingsManager = KiwixApp::instance()->getSettingsManager();
mp_webView->setZoomFactor(settingsManager->getZoomFactor());
auto key = mp_webView->zimId() + "/zoomFactor";
settingsManager->deleteSettings(key);
});
connect(mp_webView->page(), &QWebEnginePage::fullScreenRequested, mp_tabBar, &TabBar::fullScreenRequested);
connect(mp_webView, &WebView::titleChanged, this,
[=](const QString& str) {
mp_tabBar->setTitleOf(str, this);
if (mp_tabBar->currentWidget() != this) {
return;
}
emit mp_tabBar->currentTitleChanged(str);
});
connect(mp_webView, &WebView::iconChanged, this,
[=](const QIcon& icon) { mp_tabBar->setIconOf(icon, this); });
connect(mp_webView, &WebView::zimIdChanged, this,
[=](const QString& zimId) {
if (mp_tabBar->currentWidget() != this) {
return;
}
emit mp_tabBar->currentZimIdChanged(zimId);
});
connect(mp_webView->page()->action(QWebEnginePage::Back), &QAction::changed,
[=]() {
if (mp_tabBar->currentWidget() != this) {
return;
}
emit mp_tabBar->webActionEnabledChanged(QWebEnginePage::Back, mp_webView->isWebActionEnabled(QWebEnginePage::Back));
});
connect(mp_webView->page()->action(QWebEnginePage::Forward), &QAction::changed,
[=]() {
if (mp_tabBar->currentWidget() != this) {
return;
}
emit mp_tabBar->webActionEnabledChanged(QWebEnginePage::Forward, mp_webView->isWebActionEnabled(QWebEnginePage::Forward));
});
connect(mp_webView->page(), &QWebEnginePage::linkHovered, this,
[=](const QString& url) {
if (mp_tabBar->currentIndex() == 0) {
return;
}
if (url.isEmpty()) {
QToolTip::hideText();
} else {
auto link = url;
if (url.startsWith("zim://")) {
link = QUrl(url).path();
}
auto height = mp_tabBar->currentWebView()->height() + 1;
auto pos = mp_tabBar->mapToGlobal(QPoint(-3, height));
QToolTip::showText(pos, link);
}
});
}
void ZimView::openFindInPageBar()
{
mp_findInPageBar->show();
mp_findInPageBar->getFindLineEdit()->setFocus();
}

29
src/zimview.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef ZIMVIEW_H
#define ZIMVIEW_H
#include <QWidget>
#include "webview.h"
#include "findinpagebar.h"
class TabBar;
class ZimView : public QWidget
{
Q_OBJECT
public:
explicit ZimView(TabBar* tabBar, QWidget *parent = nullptr);
WebView *getWebView() { return mp_webView; }
FindInPageBar *getFindInPageBar() { return mp_findInPageBar; }
void openFindInPageBar();
signals:
private:
WebView *mp_webView;
TabBar *mp_tabBar;
FindInPageBar *mp_findInPageBar;
};
#endif // ZIMVIEW_H

View File

@ -67,7 +67,6 @@
<property name="lineWidth">
<number>0</number>
</property>
<widget class="TocSideBar" name="tocsidebar"/>
<widget class="ContentManagerSide" name="contentmanagerside">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
@ -108,12 +107,6 @@
<extends>QToolBar</extends>
<header>src/topwidget.h</header>
</customwidget>
<customwidget>
<class>TocSideBar</class>
<extends>QWidget</extends>
<header>src/tocsidebar.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TabBar</class>
<extends>QWidget</extends>