Robert C. Helling e7977ee280 desktop: re-add WebEngine support
This reverts commit 643f4a5726 and finishes the task of adding WebEngine as an
alternate backend to be used in printing.

The ultimate goal is to be able to build without QtWebKit (as that is no longer
supported in Qt6). WebKit was used in two places: The user manual and printing.
This patch makes printing work with WebEngine.

The main obstacle is that WebEngine no longer allows accessing HTML elements
from C++ code and rendering the page to a QPainter.

The old version used this to figure out dimensions and page breaks for the
pages and then in the QPainter placed the profile images. With WebEninge, you
need to access the elements using JavaScript which is now used to place the
profile in the html proplerly as an <img> tag. To this end, both html and
profile images are written to a temporary directory on disk.

This image replacement by JavaScript is only necessary to make old templates
still work. It could be replaced by actually putting <img> tags in the
templates (but this would break user edited templates).

In my experiments, the page breaking was done great by html/css, so the
additional magic seems superflous.

What remains to be done:
* remove empty page at the end of printout
* make preview great again (in particlar needed for template editing)

Note: since QtWebEngine currently cannot be built with our toolchain on
Windows, this patch keeps QtWebKit support around by making the QtWebEngine
compile-time conditional via #ifdefs.

[Dirk Hohndel: merged a few commits to make this more logical - the resulting
commit is fairly big, but IMHO preferrable]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-26 12:32:10 -08:00

86 lines
1.5 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef USERMANUAL_H
#define USERMANUAL_H
#ifdef USE_WEBENGINE
#include <QWebEngineView>
#include <QWebEnginePage>
#else
#include <QWebView>
#endif
#include <QDialog>
#include "ui_searchbar.h"
class SearchBar : public QWidget{
Q_OBJECT
public:
SearchBar(QWidget *parent = 0);
signals:
void searchTextChanged(const QString& s);
void searchNext();
void searchPrev();
protected:
void setVisible(bool visible);
private slots:
void enableButtons(const QString& s);
private:
Ui::SearchBar ui;
};
#ifdef USE_WEBENGINE
class MyQWebEnginePage : public QWebEnginePage
{
Q_OBJECT
public:
MyQWebEnginePage(QObject* parent = 0);
bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool);
};
class MyQWebEngineView : public QWebEngineView
{
Q_OBJECT
public:
MyQWebEngineView(QWidget* parent = 0);
MyQWebEnginePage* page() const;
};
#endif
class UserManual : public QDialog {
Q_OBJECT
public:
explicit UserManual(QWidget *parent = 0);
#ifdef Q_OS_MAC
protected:
void showEvent(QShowEvent *e);
void hideEvent(QHideEvent *e);
QAction *closeAction;
QAction *filterAction;
#endif
private
slots:
void searchTextChanged(const QString& s);
void searchNext();
void searchPrev();
#ifndef USE_WEBENGINE
void linkClickedSlot(const QUrl& url);
#endif
private:
SearchBar *searchBar;
QString mLastText;
#ifdef USE_WEBENGINE
QWebEngineView *userManual;
void search(QString, QWebEnginePage::FindFlags);
#else
QWebView *userManual;
void search(QString, QWebPage::FindFlags);
#endif
};
#endif // USERMANUAL_H