mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
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:
parent
99ac7ab090
commit
135baf48cd
@ -45,6 +45,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
|||||||
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
src/findinpagebar.cpp \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/mainwindow.cpp \
|
src/mainwindow.cpp \
|
||||||
src/kiwixapp.cpp \
|
src/kiwixapp.cpp \
|
||||||
@ -60,7 +61,6 @@ SOURCES += \
|
|||||||
src/mainmenu.cpp \
|
src/mainmenu.cpp \
|
||||||
src/webpage.cpp \
|
src/webpage.cpp \
|
||||||
src/about.cpp \
|
src/about.cpp \
|
||||||
src/tocsidebar.cpp \
|
|
||||||
src/contentmanager.cpp \
|
src/contentmanager.cpp \
|
||||||
src/contentmanagerview.cpp \
|
src/contentmanagerview.cpp \
|
||||||
src/tabbar.cpp \
|
src/tabbar.cpp \
|
||||||
@ -70,9 +70,11 @@ SOURCES += \
|
|||||||
src/opdsrequestmanager.cpp \
|
src/opdsrequestmanager.cpp \
|
||||||
src/localkiwixserver.cpp \
|
src/localkiwixserver.cpp \
|
||||||
src/fullscreenwindow.cpp \
|
src/fullscreenwindow.cpp \
|
||||||
src/fullscreennotification.cpp
|
src/fullscreennotification.cpp \
|
||||||
|
src/zimview.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
src/findinpagebar.h \
|
||||||
src/mainwindow.h \
|
src/mainwindow.h \
|
||||||
src/kiwixapp.h \
|
src/kiwixapp.h \
|
||||||
src/kprofile.h \
|
src/kprofile.h \
|
||||||
@ -88,7 +90,6 @@ HEADERS += \
|
|||||||
src/mainmenu.h \
|
src/mainmenu.h \
|
||||||
src/webpage.h \
|
src/webpage.h \
|
||||||
src/about.h \
|
src/about.h \
|
||||||
src/tocsidebar.h \
|
|
||||||
src/contentmanager.h \
|
src/contentmanager.h \
|
||||||
src/contentmanagerview.h \
|
src/contentmanagerview.h \
|
||||||
src/tabbar.h \
|
src/tabbar.h \
|
||||||
@ -99,12 +100,13 @@ HEADERS += \
|
|||||||
src/localkiwixserver.h \
|
src/localkiwixserver.h \
|
||||||
src/fullscreenwindow.h \
|
src/fullscreenwindow.h \
|
||||||
src/fullscreennotification.h \
|
src/fullscreennotification.h \
|
||||||
src/menuproxystyle.h
|
src/menuproxystyle.h \
|
||||||
|
src/zimview.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
src/findinpagebar.ui \
|
||||||
ui/mainwindow.ui \
|
ui/mainwindow.ui \
|
||||||
ui/about.ui \
|
ui/about.ui \
|
||||||
src/tocsidebar.ui \
|
|
||||||
src/contentmanagerside.ui \
|
src/contentmanagerside.ui \
|
||||||
src/readinglistbar.ui \
|
src/readinglistbar.ui \
|
||||||
ui/localkiwixserver.ui
|
ui/localkiwixserver.ui
|
||||||
|
@ -174,6 +174,10 @@ QTabBar::tab:last QToolButton::hover {
|
|||||||
Find Search page
|
Find Search page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#FindInPageBar {
|
||||||
|
border-top: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
#findEdit {
|
#findEdit {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
@ -182,30 +186,25 @@ QTabBar::tab:last QToolButton::hover {
|
|||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
border-bottom-left-radius: 5px;
|
|
||||||
border-top-left-radius: 5px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#fNextButton,
|
#fNextButton,
|
||||||
#fPreviousButton {
|
#fPreviousButton,
|
||||||
|
#hideButton {
|
||||||
|
outline: none;
|
||||||
max-height: 36px;
|
max-height: 36px;
|
||||||
max-width: 36px;
|
max-width: 36px;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
margin-left: -2px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#fNextButton:pressed,
|
#fNextButton:pressed,
|
||||||
#fPreviousButton:pressed {
|
#fPreviousButton:pressed,
|
||||||
|
#hideButton:pressed {
|
||||||
background-color: #D9E9FF;
|
background-color: #D9E9FF;
|
||||||
border: 1px solid #3366CC;
|
border: 1px solid #3366CC;
|
||||||
}
|
}
|
||||||
|
|
||||||
#fPreviousButton {
|
|
||||||
border-top-right-radius: 5px;
|
|
||||||
border-bottom-right-radius: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------
|
/* ----------------------------------------
|
||||||
Find Search page
|
Find Search page
|
||||||
*/
|
*/
|
||||||
|
@ -230,7 +230,7 @@ void ContentManager::eraseBook(const QString& id)
|
|||||||
auto tabBar = KiwixApp::instance()->getTabWidget();
|
auto tabBar = KiwixApp::instance()->getTabWidget();
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (i < tabBar->count() - 1) {
|
while (i < tabBar->count() - 1) {
|
||||||
WebView* webView = tabBar->widget(i);
|
WebView* webView = tabBar->widget(i)->getWebView();
|
||||||
if (webView->zimId() == id) {
|
if (webView->zimId() == id) {
|
||||||
tabBar->closeTab(i);
|
tabBar->closeTab(i);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,63 +1,69 @@
|
|||||||
#include "tocsidebar.h"
|
#include "findinpagebar.h"
|
||||||
#include "ui_tocsidebar.h"
|
#include "ui_findinpagebar.h"
|
||||||
#include "kiwixapp.h"
|
#include "kiwixapp.h"
|
||||||
|
|
||||||
TocSideBar::TocSideBar(QWidget *parent) :
|
FindInPageBar::FindInPageBar(QWidget *parent) :
|
||||||
QWidget(parent),
|
QFrame(parent),
|
||||||
mp_ui(new Ui::TocSideBar)
|
mp_ui(new Ui::FindInPageBar)
|
||||||
{
|
{
|
||||||
mp_ui->setupUi(this);
|
mp_ui->setupUi(this);
|
||||||
mp_findLineEdit = mp_ui->findEdit;
|
mp_findLineEdit = mp_ui->findEdit;
|
||||||
connect(mp_ui->hideButton, &QPushButton::released,
|
connect(mp_ui->hideButton, &QPushButton::released,
|
||||||
this, &TocSideBar::findClose);
|
this, &FindInPageBar::findClose);
|
||||||
connect(mp_ui->fNextButton, &QPushButton::released,
|
connect(mp_ui->fNextButton, &QPushButton::released,
|
||||||
this, &TocSideBar::findNext);
|
this, &FindInPageBar::findNext);
|
||||||
connect(mp_ui->fPreviousButton, &QPushButton::released,
|
connect(mp_ui->fPreviousButton, &QPushButton::released,
|
||||||
this, &TocSideBar::findPrevious);
|
this, &FindInPageBar::findPrevious);
|
||||||
connect(mp_findLineEdit, &QLineEdit::returnPressed,
|
connect(mp_findLineEdit, &QLineEdit::returnPressed,
|
||||||
this, &TocSideBar::findNext);
|
this, &FindInPageBar::findNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
TocSideBar::~TocSideBar()
|
FindInPageBar::~FindInPageBar()
|
||||||
{
|
{
|
||||||
delete mp_ui;
|
delete mp_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TocSideBar::postInit()
|
void FindInPageBar::findNext()
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
auto searchText = mp_findLineEdit->text();
|
auto searchText = mp_findLineEdit->text();
|
||||||
if (searchText.isEmpty())
|
if (searchText.isEmpty())
|
||||||
return;
|
return;
|
||||||
auto current = KiwixApp::instance()->getTabWidget()->currentWidget();
|
auto current = KiwixApp::instance()->getTabWidget()->currentWebView();
|
||||||
if (!current)
|
if (!current)
|
||||||
return;
|
return;
|
||||||
auto page = current->page();
|
auto page = current->page();
|
||||||
page->findText(searchText);
|
page->findText(searchText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TocSideBar::findPrevious()
|
void FindInPageBar::findPrevious()
|
||||||
{
|
{
|
||||||
auto searchText = mp_findLineEdit->text();
|
auto searchText = mp_findLineEdit->text();
|
||||||
if (searchText.isEmpty())
|
if (searchText.isEmpty())
|
||||||
return;
|
return;
|
||||||
auto current = KiwixApp::instance()->getTabWidget()->currentWidget();
|
auto current = KiwixApp::instance()->getTabWidget()->currentWebView();
|
||||||
if (!current)
|
if (!current)
|
||||||
return;
|
return;
|
||||||
auto page = current->page();
|
auto page = current->page();
|
||||||
page->findText(searchText, QWebEnginePage::FindBackward);
|
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
34
src/findinpagebar.h
Normal 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
82
src/findinpagebar.ui
Normal 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>
|
@ -160,7 +160,7 @@ void KiwixApp::printPage()
|
|||||||
printDialog.setStyle(nullptr);
|
printDialog.setStyle(nullptr);
|
||||||
printDialog.setStyleSheet("");
|
printDialog.setStyleSheet("");
|
||||||
if (printDialog.exec() == QDialog::Accepted) {
|
if (printDialog.exec() == QDialog::Accepted) {
|
||||||
auto webview = mp_tabWidget->currentWidget();
|
auto webview = mp_tabWidget->currentWebView();
|
||||||
if(!webview)
|
if(!webview)
|
||||||
return;
|
return;
|
||||||
webview->page()->print(printer, [=](bool success) {
|
webview->page()->print(printer, [=](bool success) {
|
||||||
@ -184,8 +184,6 @@ void KiwixApp::setSideBar(KiwixApp::SideBarType type)
|
|||||||
{
|
{
|
||||||
auto sideDockWidget = mp_mainWindow->getSideDockWidget();
|
auto sideDockWidget = mp_mainWindow->getSideDockWidget();
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SEARCH_BAR:
|
|
||||||
mp_mainWindow->findChild<TocSideBar*>("tocsidebar")->getFindLineEdit()->setFocus();
|
|
||||||
case CONTENTMANAGER_BAR:
|
case CONTENTMANAGER_BAR:
|
||||||
case READINGLIST_BAR:
|
case READINGLIST_BAR:
|
||||||
sideDockWidget->setCurrentIndex(type);
|
sideDockWidget->setCurrentIndex(type);
|
||||||
@ -317,9 +315,9 @@ void KiwixApp::createAction()
|
|||||||
HIDE_ACTION(SearchLibraryAction);
|
HIDE_ACTION(SearchLibraryAction);
|
||||||
|
|
||||||
CREATE_ACTION(FindInPageAction, tr("Find in page"));
|
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,
|
connect(mpa_actions[FindInPageAction], &QAction::triggered,
|
||||||
this, [=]() { toggleSideBar(SEARCH_BAR); });
|
this, [=]() { mp_tabWidget->openFindInPageBar(); });
|
||||||
|
|
||||||
CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", tr("Set fullScreen"));
|
CREATE_ACTION_ICON(ToggleFullscreenAction, "full-screen-enter", tr("Set fullScreen"));
|
||||||
SET_SHORTCUT(ToggleFullscreenAction, QKeySequence::FullScreen);
|
SET_SHORTCUT(ToggleFullscreenAction, QKeySequence::FullScreen);
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include "kiwix/downloader.h"
|
#include "kiwix/downloader.h"
|
||||||
#include <kiwix/kiwixserve.h>
|
#include <kiwix/kiwixserve.h>
|
||||||
#include "tabbar.h"
|
#include "tabbar.h"
|
||||||
#include "tocsidebar.h"
|
|
||||||
#include "kprofile.h"
|
#include "kprofile.h"
|
||||||
|
#include "urlschemehandler.h"
|
||||||
#include "settingsmanager.h"
|
#include "settingsmanager.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -54,7 +54,6 @@ public:
|
|||||||
MAX_ACTION
|
MAX_ACTION
|
||||||
};
|
};
|
||||||
enum SideBarType {
|
enum SideBarType {
|
||||||
SEARCH_BAR,
|
|
||||||
CONTENTMANAGER_BAR,
|
CONTENTMANAGER_BAR,
|
||||||
READINGLIST_BAR,
|
READINGLIST_BAR,
|
||||||
NONE
|
NONE
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
#include "tabbar.h"
|
#include "tabbar.h"
|
||||||
#include "topwidget.h"
|
#include "topwidget.h"
|
||||||
#include "tocsidebar.h"
|
|
||||||
#include "about.h"
|
#include "about.h"
|
||||||
#include "contentmanagerside.h"
|
#include "contentmanagerside.h"
|
||||||
#include "localkiwixserver.h"
|
#include "localkiwixserver.h"
|
||||||
|
@ -122,7 +122,7 @@ void SearchBar::updateCompletion(const QString &text)
|
|||||||
{
|
{
|
||||||
QStringList wordList;
|
QStringList wordList;
|
||||||
m_urlList.clear();
|
m_urlList.clear();
|
||||||
auto currentWidget = KiwixApp::instance()->getTabWidget()->currentWidget();
|
auto currentWidget = KiwixApp::instance()->getTabWidget()->currentWebView();
|
||||||
if (!currentWidget) {
|
if (!currentWidget) {
|
||||||
m_completionModel.setStringList(wordList);
|
m_completionModel.setStringList(wordList);
|
||||||
return;
|
return;
|
||||||
|
128
src/tabbar.cpp
128
src/tabbar.cpp
@ -37,40 +37,9 @@ TabBar::TabBar(QWidget *parent) :
|
|||||||
}
|
}
|
||||||
this->closeTab(index);
|
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,
|
connect(app->getAction(KiwixApp::OpenHomePageAction), &QAction::triggered,
|
||||||
this, [=]() {
|
this, [=]() {
|
||||||
auto current = this->currentWidget();
|
auto current = this->currentWebView();
|
||||||
QUITIFNULL(current);
|
QUITIFNULL(current);
|
||||||
current->setUrl("zim://" + current->zimId() + ".zim/");
|
current->setUrl("zim://" + current->zimId() + ".zim/");
|
||||||
});
|
});
|
||||||
@ -80,6 +49,7 @@ TabBar::TabBar(QWidget *parent) :
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto index = currentIndex() + 1;
|
auto index = currentIndex() + 1;
|
||||||
|
m_settingsIndex = index;
|
||||||
auto view = KiwixApp::instance()->getSettingsManager()->getView();
|
auto view = KiwixApp::instance()->getSettingsManager()->getView();
|
||||||
mp_stackedWidget->insertWidget(index, view);
|
mp_stackedWidget->insertWidget(index, view);
|
||||||
insertTab(index,QIcon(":/icons/settings.svg"), tr("Settings"));
|
insertTab(index,QIcon(":/icons/settings.svg"), tr("Settings"));
|
||||||
@ -87,7 +57,6 @@ TabBar::TabBar(QWidget *parent) :
|
|||||||
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
|
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
|
||||||
setTabButton(index, QTabBar::RightSide, tb);
|
setTabButton(index, QTabBar::RightSide, tb);
|
||||||
setCurrentIndex(index);
|
setCurrentIndex(index);
|
||||||
m_settingsIndex = index;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,51 +88,11 @@ void TabBar::setNewTabButton()
|
|||||||
setTabButton(1, QTabBar::RightSide, 0);
|
setTabButton(1, QTabBar::RightSide, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebView* TabBar::createNewTab(bool setCurrent)
|
ZimView* TabBar::createNewTab(bool setCurrent)
|
||||||
{
|
{
|
||||||
WebView* webView = new WebView();
|
auto tab = new ZimView(this, this);
|
||||||
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 index = count() - 1;
|
auto index = count() - 1;
|
||||||
mp_stackedWidget->insertWidget(index, webView);
|
mp_stackedWidget->insertWidget(index, tab);
|
||||||
insertTab(index, "");
|
insertTab(index, "");
|
||||||
QToolButton *tb = new QToolButton(this);
|
QToolButton *tb = new QToolButton(this);
|
||||||
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
|
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
|
||||||
@ -171,55 +100,55 @@ WebView* TabBar::createNewTab(bool setCurrent)
|
|||||||
if (setCurrent) {
|
if (setCurrent) {
|
||||||
setCurrentIndex(index);
|
setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
return webView;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::openUrl(const QUrl& url, bool newTab)
|
void TabBar::openUrl(const QUrl& url, bool newTab)
|
||||||
{
|
{
|
||||||
WebView* webView = currentWidget();
|
WebView* webView = currentWebView();
|
||||||
if (newTab || !webView) {
|
if (newTab || !webView) {
|
||||||
webView = createNewTab(true);
|
webView = createNewTab(true)->getWebView();
|
||||||
}
|
}
|
||||||
QUITIFNULL(webView);
|
QUITIFNULL(webView);
|
||||||
webView->setUrl(url);
|
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://")) {
|
if (title.startsWith("zim://")) {
|
||||||
auto url = QUrl(title);
|
auto url = QUrl(title);
|
||||||
setTabText(mp_stackedWidget->indexOf(webView), url.path());
|
setTabText(mp_stackedWidget->indexOf(tab), url.path());
|
||||||
} else {
|
} 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);
|
CURRENTIFNULL(tab);
|
||||||
setTabIcon(mp_stackedWidget->indexOf(webView), icon);
|
setTabIcon(mp_stackedWidget->indexOf(tab), icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TabBar::currentZimId()
|
QString TabBar::currentZimId()
|
||||||
{
|
{
|
||||||
if (!currentWidget())
|
if (!currentWidget())
|
||||||
return "";
|
return "";
|
||||||
return currentWidget()->zimId();
|
return currentWebView()->zimId();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TabBar::currentArticleUrl()
|
QString TabBar::currentArticleUrl()
|
||||||
{
|
{
|
||||||
if(!currentWidget())
|
if(!currentWidget())
|
||||||
return "";
|
return "";
|
||||||
return currentWidget()->url().path();
|
return currentWebView()->url().path();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TabBar::currentArticleTitle()
|
QString TabBar::currentArticleTitle()
|
||||||
{
|
{
|
||||||
if(!currentWidget())
|
if(!currentWidget())
|
||||||
return "";
|
return "";
|
||||||
return currentWidget()->title();
|
return currentWebView()->title();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize TabBar::tabSizeHint(int index) const {
|
QSize TabBar::tabSizeHint(int index) const {
|
||||||
@ -228,12 +157,17 @@ QSize TabBar::tabSizeHint(int index) const {
|
|||||||
return QSize(40, 40);
|
return QSize(40, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, WebView *webView)
|
void TabBar::openFindInPageBar()
|
||||||
{
|
{
|
||||||
CURRENTIFNULL(webView);
|
currentWidget()->openFindInPageBar();
|
||||||
QUITIFNULL(webView);
|
}
|
||||||
webView->triggerPageAction(action);
|
|
||||||
webView->setFocus();
|
void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, ZimView *widget)
|
||||||
|
{
|
||||||
|
CURRENTIFNULL(widget);
|
||||||
|
QUITIFNULL(widget);
|
||||||
|
widget->getWebView()->triggerPageAction(action);
|
||||||
|
widget->getWebView()->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::closeTab(int index)
|
void TabBar::closeTab(int index)
|
||||||
@ -275,7 +209,7 @@ void TabBar::onCurrentChanged(int index)
|
|||||||
KiwixApp::instance()->setSideBar(KiwixApp::NONE);
|
KiwixApp::instance()->setSideBar(KiwixApp::NONE);
|
||||||
QTimer::singleShot(0, [=](){emit currentTitleChanged("");});
|
QTimer::singleShot(0, [=](){emit currentTitleChanged("");});
|
||||||
} else if (index) {
|
} else if (index) {
|
||||||
auto view = widget(index);
|
auto view = widget(index)->getWebView();
|
||||||
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
|
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
|
||||||
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
|
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
|
||||||
emit libraryPageDisplayed(false);
|
emit libraryPageDisplayed(false);
|
||||||
@ -298,7 +232,7 @@ void TabBar::fullScreenRequested(QWebEngineFullScreenRequest request)
|
|||||||
if (m_fullScreenWindow)
|
if (m_fullScreenWindow)
|
||||||
return;
|
return;
|
||||||
request.accept();
|
request.accept();
|
||||||
m_fullScreenWindow.reset(new FullScreenWindow(this->currentWidget()));
|
m_fullScreenWindow.reset(new FullScreenWindow(this->currentWebView()));
|
||||||
} else {
|
} else {
|
||||||
if (!m_fullScreenWindow)
|
if (!m_fullScreenWindow)
|
||||||
return;
|
return;
|
||||||
@ -314,4 +248,4 @@ void TabBar::mousePressEvent(QMouseEvent *event)
|
|||||||
} else {
|
} else {
|
||||||
QTabBar::mousePressEvent(event);
|
QTabBar::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
src/tabbar.h
22
src/tabbar.h
@ -5,6 +5,7 @@
|
|||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
|
#include "zimview.h"
|
||||||
#include "contentmanagerview.h"
|
#include "contentmanagerview.h"
|
||||||
#include "fullscreenwindow.h"
|
#include "fullscreenwindow.h"
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
@ -21,24 +22,29 @@ public:
|
|||||||
|
|
||||||
void setContentManagerView(ContentManagerView* view);
|
void setContentManagerView(ContentManagerView* view);
|
||||||
void setNewTabButton();
|
void setNewTabButton();
|
||||||
WebView* createNewTab(bool setCurrent);
|
ZimView* createNewTab(bool setCurrent);
|
||||||
WebView* widget(int index) { return (index != 0) ? static_cast<WebView*>(mp_stackedWidget->widget(index)) : nullptr; }
|
ZimView* widget(int index) { return (index != 0) ? static_cast<ZimView*>(mp_stackedWidget->widget(index)) : nullptr; }
|
||||||
WebView* currentWidget() { auto current = mp_stackedWidget->currentWidget();
|
WebView* currentWebView() { auto current = mp_stackedWidget->currentWidget();
|
||||||
if (current == mp_contentManagerView ||
|
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;
|
mp_stackedWidget->currentIndex() == m_settingsIndex) return nullptr;
|
||||||
return static_cast<WebView*>(current);
|
return static_cast<ZimView*>(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
void openUrl(const QUrl &url, bool newTab);
|
void openUrl(const QUrl &url, bool newTab);
|
||||||
// Redirect call to sub-webView
|
// Redirect call to sub-webView
|
||||||
void setTitleOf(const QString& title, WebView* webView=nullptr);
|
void setTitleOf(const QString& title, ZimView* tab=nullptr);
|
||||||
void setIconOf(const QIcon& icon, WebView* webView=nullptr);
|
void setIconOf(const QIcon& icon, ZimView* tab=nullptr);
|
||||||
QString currentZimId();
|
QString currentZimId();
|
||||||
|
|
||||||
void triggerWebPageAction(QWebEnginePage::WebAction action, WebView* webView=nullptr);
|
void triggerWebPageAction(QWebEnginePage::WebAction action, ZimView* widget=nullptr);
|
||||||
QString currentArticleUrl();
|
QString currentArticleUrl();
|
||||||
QString currentArticleTitle();
|
QString currentArticleTitle();
|
||||||
virtual QSize tabSizeHint(int index) const;
|
virtual QSize tabSizeHint(int index) const;
|
||||||
|
void openFindInPageBar();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
@ -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
|
|
@ -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>
|
|
@ -7,6 +7,7 @@
|
|||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QWebEngineSettings>
|
#include <QWebEngineSettings>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
WebView::WebView(QWidget *parent)
|
WebView::WebView(QWidget *parent)
|
||||||
: QWebEngineView(parent)
|
: QWebEngineView(parent)
|
||||||
@ -32,7 +33,7 @@ QWebEngineView* WebView::createWindow(QWebEnginePage::WebWindowType type)
|
|||||||
|| type==QWebEnginePage::WebBrowserTab )
|
|| type==QWebEnginePage::WebBrowserTab )
|
||||||
{
|
{
|
||||||
auto tabWidget = KiwixApp::instance()->getTabWidget();
|
auto tabWidget = KiwixApp::instance()->getTabWidget();
|
||||||
return tabWidget->createNewTab(type==QWebEnginePage::WebBrowserTab);
|
return tabWidget->createNewTab(type==QWebEnginePage::WebBrowserTab)->getWebView();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
|
||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
|
#include "findinpagebar.h"
|
||||||
|
|
||||||
class WebView : public QWebEngineView
|
class WebView : public QWebEngineView
|
||||||
{
|
{
|
||||||
|
101
src/zimview.cpp
Normal file
101
src/zimview.cpp
Normal 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
29
src/zimview.h
Normal 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
|
@ -67,7 +67,6 @@
|
|||||||
<property name="lineWidth">
|
<property name="lineWidth">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="TocSideBar" name="tocsidebar"/>
|
|
||||||
<widget class="ContentManagerSide" name="contentmanagerside">
|
<widget class="ContentManagerSide" name="contentmanagerside">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||||
@ -108,12 +107,6 @@
|
|||||||
<extends>QToolBar</extends>
|
<extends>QToolBar</extends>
|
||||||
<header>src/topwidget.h</header>
|
<header>src/topwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>TocSideBar</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>src/tocsidebar.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>TabBar</class>
|
<class>TabBar</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user