Compare commits
10 Commits
master
...
Webengine-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0057c06fb | ||
|
|
e5915ca4f2 | ||
|
|
47f52cd4d1 | ||
|
|
38bfb3de16 | ||
|
|
528559334f | ||
|
|
042addc30a | ||
|
|
f620a2c09d | ||
|
|
9aced3f49a | ||
|
|
9583173425 | ||
|
|
e7977ee280 |
3
.github/workflows/linux-bionic-5.9.yml
vendored
3
.github/workflows/linux-bionic-5.9.yml
vendored
@ -29,12 +29,13 @@ jobs:
|
|||||||
qml-module-qtquick2 qt5-default qt5-qmake qtchooser qtconnectivity5-dev \
|
qml-module-qtquick2 qt5-default qt5-qmake qtchooser qtconnectivity5-dev \
|
||||||
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
||||||
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
||||||
|
qtwebengine5-dev \
|
||||||
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
||||||
|
|
||||||
- name: build Subsurface
|
- name: build Subsurface
|
||||||
run: |
|
run: |
|
||||||
cd ..
|
cd ..
|
||||||
bash -x subsurface/scripts/build.sh -desktop -build-with-webkit
|
bash -x subsurface/scripts/build.sh -desktop -build-with-webkit -print-with-webengine
|
||||||
|
|
||||||
- name: test desktop build
|
- name: test desktop build
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.github/workflows/linux-focal-5.12.yml
vendored
3
.github/workflows/linux-focal-5.12.yml
vendored
@ -33,6 +33,7 @@ jobs:
|
|||||||
qml-module-qtquick2 qt5-qmake qtchooser qtconnectivity5-dev \
|
qml-module-qtquick2 qt5-qmake qtchooser qtconnectivity5-dev \
|
||||||
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
||||||
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
||||||
|
qtwebengine5-dev \
|
||||||
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
||||||
|
|
||||||
- name: build Subsurface-mobile
|
- name: build Subsurface-mobile
|
||||||
@ -60,7 +61,7 @@ jobs:
|
|||||||
|
|
||||||
# now build for the desktop version (including WebKit)
|
# now build for the desktop version (including WebKit)
|
||||||
cd ..
|
cd ..
|
||||||
bash -e -x subsurface/scripts/build.sh -desktop -build-with-webkit
|
bash -e -x subsurface/scripts/build.sh -desktop -build-with-webkit -print-with-webengine
|
||||||
|
|
||||||
- name: test desktop build
|
- name: test desktop build
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.github/workflows/linux-groovy-5.14.yml
vendored
3
.github/workflows/linux-groovy-5.14.yml
vendored
@ -33,6 +33,7 @@ jobs:
|
|||||||
qml-module-qtquick2 qt5-qmake qtchooser qtconnectivity5-dev \
|
qml-module-qtquick2 qt5-qmake qtchooser qtconnectivity5-dev \
|
||||||
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
||||||
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
||||||
|
qtwebengine5-dev \
|
||||||
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
||||||
|
|
||||||
- name: build Subsurface-mobile
|
- name: build Subsurface-mobile
|
||||||
@ -60,7 +61,7 @@ jobs:
|
|||||||
|
|
||||||
# now build for the desktop version (including WebKit)
|
# now build for the desktop version (including WebKit)
|
||||||
cd ..
|
cd ..
|
||||||
bash -e -x subsurface/scripts/build.sh -desktop -build-with-webkit
|
bash -e -x subsurface/scripts/build.sh -desktop -build-with-webkit -print-with-webengine
|
||||||
|
|
||||||
- name: test desktop build
|
- name: test desktop build
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.github/workflows/linux-hirsute-5.15.yml
vendored
3
.github/workflows/linux-hirsute-5.15.yml
vendored
@ -33,6 +33,7 @@ jobs:
|
|||||||
qml-module-qtquick2 qt5-qmake qtchooser qtconnectivity5-dev \
|
qml-module-qtquick2 qt5-qmake qtchooser qtconnectivity5-dev \
|
||||||
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
qtdeclarative5-dev qtdeclarative5-private-dev qtlocation5-dev \
|
||||||
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
qtpositioning5-dev qtscript5-dev qttools5-dev qttools5-dev-tools \
|
||||||
|
qtwebengine5-dev \
|
||||||
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
qtquickcontrols2-5-dev xvfb libbluetooth-dev libmtp-dev
|
||||||
|
|
||||||
- name: build Subsurface-mobile
|
- name: build Subsurface-mobile
|
||||||
@ -60,7 +61,7 @@ jobs:
|
|||||||
|
|
||||||
# now build for the desktop version (including WebKit)
|
# now build for the desktop version (including WebKit)
|
||||||
cd ..
|
cd ..
|
||||||
bash -e -x subsurface/scripts/build.sh -desktop -build-with-webkit
|
bash -e -x subsurface/scripts/build.sh -desktop -build-with-webkit -print-with-webengine
|
||||||
|
|
||||||
- name: test desktop build
|
- name: test desktop build
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@ -51,6 +51,7 @@ option(NO_USERMANUAL "don't include a viewer for the user manual" OFF)
|
|||||||
#Options regarding enabling parts of subsurface
|
#Options regarding enabling parts of subsurface
|
||||||
option(BTSUPPORT "enable support for QtBluetooth (requires Qt5.4 or newer)" ON)
|
option(BTSUPPORT "enable support for QtBluetooth (requires Qt5.4 or newer)" ON)
|
||||||
option(FTDISUPPORT "enable support for libftdi based serial" OFF)
|
option(FTDISUPPORT "enable support for libftdi based serial" OFF)
|
||||||
|
option(USE_WEBENGINE "Use QWebEngine instead of QWebKit" OFF)
|
||||||
|
|
||||||
# Options regarding What should we build on subsurface
|
# Options regarding What should we build on subsurface
|
||||||
option(MAKE_TESTS "Make the tests" ON)
|
option(MAKE_TESTS "Make the tests" ON)
|
||||||
@ -189,10 +190,14 @@ if (SUBSURFACE_TARGET_EXECUTABLE MATCHES "DesktopExecutable")
|
|||||||
add_definitions(-DNO_PRINTING)
|
add_definitions(-DNO_PRINTING)
|
||||||
else()
|
else()
|
||||||
LIST(APPEND QT_EXTRA_COMPONENTS PrintSupport)
|
LIST(APPEND QT_EXTRA_COMPONENTS PrintSupport)
|
||||||
|
if(USE_WEBENGINE)
|
||||||
|
LIST(APPEND QT_EXTRA_COMPONENTS WebEngine)
|
||||||
|
else()
|
||||||
# Because Qt5WebKitWidgets isn't a part of the "regular" Qt5, we can't get it the normal way
|
# Because Qt5WebKitWidgets isn't a part of the "regular" Qt5, we can't get it the normal way
|
||||||
find_package(Qt5WebKitWidgets REQUIRED)
|
find_package(Qt5WebKitWidgets REQUIRED)
|
||||||
set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} Qt5::WebKitWidgets)
|
set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} Qt5::WebKitWidgets)
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
elseif (SUBSURFACE_TARGET_EXECUTABLE MATCHES "MobileExecutable")
|
elseif (SUBSURFACE_TARGET_EXECUTABLE MATCHES "MobileExecutable")
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||||
set(SUBSURFACE_TARGET Subsurface-mobile)
|
set(SUBSURFACE_TARGET Subsurface-mobile)
|
||||||
@ -531,6 +536,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
|||||||
install(CODE "execute_process(COMMAND cp -a ${_qt5Core_install_prefix}/qml/QtQml ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)")
|
install(CODE "execute_process(COMMAND cp -a ${_qt5Core_install_prefix}/qml/QtQml ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)")
|
||||||
install(CODE "execute_process(COMMAND cp -a ${_qt5Core_install_prefix}/qml/QtPositioning ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)")
|
install(CODE "execute_process(COMMAND cp -a ${_qt5Core_install_prefix}/qml/QtPositioning ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Resources/qml)")
|
||||||
endif()
|
endif()
|
||||||
|
# if we build with WebEngine we need to copy the helper which macdeployqt appears to get wrong as well
|
||||||
|
if(USE_WEBENGINE)
|
||||||
|
install(CODE "execute_process(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Frameworks/QtWebEngineCore.framework/Helpers)")
|
||||||
|
install(CODE "execute_process(COMMAND cp -a ${_qt5Core_install_prefix}/lib/QtWebEngineCore.framework/Helpers/QtWebEngineProcess.app ${CMAKE_BINARY_DIR}/${APP_BUNDLE_DIR}/Contents/Frameworks/QtWebEngineCore.framework/Helpers/)")
|
||||||
|
endif()
|
||||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||||
if(NOT DEFINED OBJCOPY)
|
if(NOT DEFINED OBJCOPY)
|
||||||
|
|||||||
@ -2,5 +2,11 @@ if(NO_USERMANUAL)
|
|||||||
message(STATUS "building without usermanual")
|
message(STATUS "building without usermanual")
|
||||||
add_definitions(-DNO_USERMANUAL)
|
add_definitions(-DNO_USERMANUAL)
|
||||||
else()
|
else()
|
||||||
|
if(USE_WEBENGINE)
|
||||||
|
message(STATUS "building with QWebEngine")
|
||||||
|
list(APPEND QT_EXTRA_COMPONENTS WebEngineWidgets)
|
||||||
|
add_definitions(-DUSE_WEBENGINE)
|
||||||
|
else()
|
||||||
list(APPEND QT_EXTRA_COMPONENTS WebKitWidgets)
|
list(APPEND QT_EXTRA_COMPONENTS WebKitWidgets)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -148,8 +148,6 @@ if(NOT NO_PRINTING)
|
|||||||
set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE}
|
set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE}
|
||||||
printdialog.cpp
|
printdialog.cpp
|
||||||
printdialog.h
|
printdialog.h
|
||||||
printer.cpp
|
|
||||||
printer.h
|
|
||||||
printoptions.cpp
|
printoptions.cpp
|
||||||
printoptions.h
|
printoptions.h
|
||||||
templateedit.cpp
|
templateedit.cpp
|
||||||
@ -159,6 +157,18 @@ if(NOT NO_PRINTING)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(USE_WEBENGINE)
|
||||||
|
set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE}
|
||||||
|
printerwebengine.cpp
|
||||||
|
printerwebengine.h
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE}
|
||||||
|
printer.cpp
|
||||||
|
printer.h
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BTSUPPORT)
|
if (BTSUPPORT)
|
||||||
set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE}
|
set(SUBSURFACE_INTERFACE ${SUBSURFACE_INTERFACE}
|
||||||
btdeviceselectiondialog.cpp
|
btdeviceselectiondialog.cpp
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "printdialog.h"
|
#include "printdialog.h"
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
#include "printerwebengine.h"
|
||||||
|
#else
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
|
#endif
|
||||||
#include "core/pref.h"
|
#include "core/pref.h"
|
||||||
#include "core/dive.h" // for existing_filename
|
#include "core/dive.h" // for existing_filename
|
||||||
|
|
||||||
@ -14,6 +18,9 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
#include <QWebEngineView>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SETTINGS_GROUP "PrintDialog"
|
#define SETTINGS_GROUP "PrintDialog"
|
||||||
|
|
||||||
@ -110,8 +117,11 @@ PrintDialog::PrintDialog(bool inPlanner, QWidget *parent) :
|
|||||||
QPushButton *printButton = new QPushButton(tr("P&rint"));
|
QPushButton *printButton = new QPushButton(tr("P&rint"));
|
||||||
connect(printButton, SIGNAL(clicked(bool)), this, SLOT(printClicked()));
|
connect(printButton, SIGNAL(clicked(bool)), this, SLOT(printClicked()));
|
||||||
|
|
||||||
|
// To do: Port preview to WebEngine. For the time being: Use OS print preview
|
||||||
|
#ifndef USE_WEBENGINE
|
||||||
QPushButton *previewButton = new QPushButton(tr("&Preview"));
|
QPushButton *previewButton = new QPushButton(tr("&Preview"));
|
||||||
connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked()));
|
connect(previewButton, SIGNAL(clicked(bool)), this, SLOT(previewClicked()));
|
||||||
|
#endif
|
||||||
|
|
||||||
QPushButton *exportHtmlButton = new QPushButton(tr("Export Html"));
|
QPushButton *exportHtmlButton = new QPushButton(tr("Export Html"));
|
||||||
connect(exportHtmlButton, SIGNAL(clicked(bool)), this, SLOT(exportHtmlClicked()));
|
connect(exportHtmlButton, SIGNAL(clicked(bool)), this, SLOT(exportHtmlClicked()));
|
||||||
@ -119,7 +129,9 @@ PrintDialog::PrintDialog(bool inPlanner, QWidget *parent) :
|
|||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
||||||
buttonBox->addButton(QDialogButtonBox::Cancel);
|
buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
buttonBox->addButton(printButton, QDialogButtonBox::AcceptRole);
|
buttonBox->addButton(printButton, QDialogButtonBox::AcceptRole);
|
||||||
|
#ifndef USE_WEBENGINE
|
||||||
buttonBox->addButton(previewButton, QDialogButtonBox::ActionRole);
|
buttonBox->addButton(previewButton, QDialogButtonBox::ActionRole);
|
||||||
|
#endif
|
||||||
buttonBox->addButton(exportHtmlButton, QDialogButtonBox::AcceptRole);
|
buttonBox->addButton(exportHtmlButton, QDialogButtonBox::AcceptRole);
|
||||||
|
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
@ -178,7 +190,7 @@ void PrintDialog::createPrinterObj()
|
|||||||
qprinter = new QPrinter;
|
qprinter = new QPrinter;
|
||||||
qprinter->setResolution(printOptions.resolution);
|
qprinter->setResolution(printOptions.resolution);
|
||||||
qprinter->setOrientation((QPrinter::Orientation)printOptions.landscape);
|
qprinter->setOrientation((QPrinter::Orientation)printOptions.landscape);
|
||||||
printer = new Printer(qprinter, printOptions, templateOptions, Printer::PRINT, inPlanner);
|
printer = new Printer(qprinter, printOptions, templateOptions, Printer::PRINT, inPlanner, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,13 +227,26 @@ void PrintDialog::printClicked(void)
|
|||||||
{
|
{
|
||||||
createPrinterObj();
|
createPrinterObj();
|
||||||
QPrintDialog printDialog(qprinter, this);
|
QPrintDialog printDialog(qprinter, this);
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
|
connect(printer, &Printer::jobDone, this, &PrintDialog::printingDone);
|
||||||
|
printer->print();
|
||||||
|
#else
|
||||||
if (printDialog.exec() == QDialog::Accepted) {
|
if (printDialog.exec() == QDialog::Accepted) {
|
||||||
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
printer->print();
|
printer->print();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
void PrintDialog::printingDone()
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void PrintDialog::onPaintRequested(QPrinter*)
|
void PrintDialog::onPaintRequested(QPrinter*)
|
||||||
{
|
{
|
||||||
createPrinterObj();
|
createPrinterObj();
|
||||||
|
|||||||
@ -38,6 +38,13 @@ slots:
|
|||||||
void printClicked();
|
void printClicked();
|
||||||
void onPaintRequested(QPrinter *);
|
void onPaintRequested(QPrinter *);
|
||||||
void createPrinterObj();
|
void createPrinterObj();
|
||||||
|
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
public
|
||||||
|
slots:
|
||||||
|
void printingDone();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif // PRINTDIALOG_H
|
#endif // PRINTDIALOG_H
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
#include "profile-widget/profilewidget2.h"
|
#include "profile-widget/profilewidget2.h"
|
||||||
|
|
||||||
Printer::Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode, bool inPlanner) :
|
Printer::Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode, bool inPlanner, QWidget *parent = nullptr) :
|
||||||
paintDevice(paintDevice),
|
paintDevice(paintDevice),
|
||||||
webView(new QWebView),
|
webView(new QWebView),
|
||||||
printOptions(printOptions),
|
printOptions(printOptions),
|
||||||
@ -267,8 +267,6 @@ void Printer::previewOnePage()
|
|||||||
pageSize.setHeight(paintDevice->height());
|
pageSize.setHeight(paintDevice->height());
|
||||||
pageSize.setWidth(paintDevice->width());
|
pageSize.setWidth(paintDevice->width());
|
||||||
webView->page()->setViewportSize(pageSize);
|
webView->page()->setViewportSize(pageSize);
|
||||||
// initialize the border settings
|
|
||||||
// templateOptions.border_width = std::max(1, pageSize.width() / 1000);
|
|
||||||
if (printOptions.type == print_options::DIVELIST)
|
if (printOptions.type == print_options::DIVELIST)
|
||||||
webView->setHtml(t.generate(inPlanner));
|
webView->setHtml(t.generate(inPlanner));
|
||||||
else if (printOptions.type == print_options::STATISTICS )
|
else if (printOptions.type == print_options::STATISTICS )
|
||||||
|
|||||||
@ -38,7 +38,7 @@ private slots:
|
|||||||
void templateProgessUpdated(int value);
|
void templateProgessUpdated(int value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode, bool inPlanner);
|
Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode, bool inPlanner, QWidget *parent);
|
||||||
~Printer();
|
~Printer();
|
||||||
void print();
|
void print();
|
||||||
void previewOnePage();
|
void previewOnePage();
|
||||||
|
|||||||
193
desktop-widgets/printerwebengine.cpp
Normal file
193
desktop-widgets/printerwebengine.cpp
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#include "printerwebengine.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
#include "templatelayout.h"
|
||||||
|
#include "core/statistics.h"
|
||||||
|
#include "core/qthelper.h"
|
||||||
|
#include "core/settings/qPrefDisplay.h"
|
||||||
|
#include "profile-widget/profilewidget2.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QtWebEngineWidgets>
|
||||||
|
|
||||||
|
extern void exportProfile(const struct dive *dive, const QString filename);
|
||||||
|
|
||||||
|
Printer::Printer(QPaintDevice *paintDevice, print_options &printOptions, template_options &templateOptions, PrintMode printMode, bool inPlanner, QWidget *parent = nullptr) :
|
||||||
|
paintDevice(paintDevice),
|
||||||
|
printOptions(printOptions),
|
||||||
|
templateOptions(templateOptions),
|
||||||
|
printMode(printMode),
|
||||||
|
inPlanner(inPlanner),
|
||||||
|
done(0)
|
||||||
|
{
|
||||||
|
webView = new QWebEngineView(parent);
|
||||||
|
connect(webView, &QWebEngineView::loadFinished, this, &Printer::onLoadFinished);
|
||||||
|
if (printMode == PRINT) {
|
||||||
|
connect(this, &Printer::profilesInserted, this, &Printer::reopen);
|
||||||
|
connect(this, &Printer::jobDone, this, &Printer::printFinished);
|
||||||
|
}
|
||||||
|
profilesMissing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Printer::~Printer()
|
||||||
|
{
|
||||||
|
qDebug() << "deleting Printer object";
|
||||||
|
delete webView;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Printer::onLoadFinished()
|
||||||
|
{
|
||||||
|
qDebug() << "onLoadFinished called with profilesMissing" << profilesMissing << "and URL" << webView->url().toString();
|
||||||
|
if (profilesMissing) {
|
||||||
|
QString jsText(" var profiles = document.getElementsByClassName(\"diveProfile\");\
|
||||||
|
for (let profile of profiles) { \
|
||||||
|
var id = profile.attributes.getNamedItem(\"Id\").value; \
|
||||||
|
var img = document.createElement(\"img\"); \
|
||||||
|
img.src = \"TMPPATH\" + id + \".png\"; \
|
||||||
|
img.style.height = \"100%\"; \
|
||||||
|
img.style.width = \"100%\"; \
|
||||||
|
profile.appendChild(img); \
|
||||||
|
} \
|
||||||
|
document.documentElement.innerHTML; \
|
||||||
|
");
|
||||||
|
QString filePath = QStringLiteral("file://") + printDir.path() + QDir::separator();
|
||||||
|
jsText.replace("TMPPATH", filePath);
|
||||||
|
webView->page()->runJavaScript(jsText, [this](const QVariant &v) {
|
||||||
|
qDebug() << "JS finished";
|
||||||
|
QFile fd(printDir.filePath("finalprint.html"));
|
||||||
|
fd.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
|
QTextStream out(&fd);
|
||||||
|
out << v.toString();
|
||||||
|
fd.close();
|
||||||
|
qDebug() << "finalprint.html written";
|
||||||
|
profilesMissing = false;
|
||||||
|
emit(progessUpdated(80));
|
||||||
|
emit profilesInserted();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
qDebug() << "load of" << webView->url().toString() << "finished - open printing dialog";
|
||||||
|
emit(progessUpdated(100));
|
||||||
|
printing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the Javascript code injecting the profiles has completed, let's reload that page
|
||||||
|
void Printer::reopen()
|
||||||
|
{
|
||||||
|
qDebug() << "opening the finalprint.html file";
|
||||||
|
webView->load(QUrl::fromLocalFile(printDir.filePath("finalprint.html")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Printer::printing()
|
||||||
|
{
|
||||||
|
QPrintDialog printDialog(&printer, (QWidget *) nullptr);
|
||||||
|
if (printDialog.exec() == QDialog::Accepted)
|
||||||
|
webView->page()->print(&printer, [this](bool ok){
|
||||||
|
if (ok)
|
||||||
|
emit jobDone();
|
||||||
|
qDebug() << "printing done with status " << ok ;
|
||||||
|
qDebug() << "content of" << printDir.path();
|
||||||
|
qDebug() << QDir(printDir.path()).entryList();
|
||||||
|
});
|
||||||
|
qDebug() << "closing the dialog now";
|
||||||
|
printDialog.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//value: ranges from 0 : 100 and shows the progress of the templating engine
|
||||||
|
void Printer::templateProgessUpdated(int value)
|
||||||
|
{
|
||||||
|
done = value / 5; //template progess if 1/5 of total work
|
||||||
|
emit progessUpdated(done);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Printer::exportHtml()
|
||||||
|
{
|
||||||
|
// Does anybody actually use this? It will not contian profile images!!!
|
||||||
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
|
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||||
|
QString html;
|
||||||
|
|
||||||
|
if (printOptions.type == print_options::DIVELIST)
|
||||||
|
html = t.generate(inPlanner);
|
||||||
|
else if (printOptions.type == print_options::STATISTICS )
|
||||||
|
html = t.generateStatistics();
|
||||||
|
|
||||||
|
// TODO: write html to file
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Printer::updateOptions(print_options &poptions, template_options &toptions)
|
||||||
|
{
|
||||||
|
templateOptions = toptions;
|
||||||
|
printOptions = poptions;
|
||||||
|
profilesMissing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Printer::writeTmpTemplate(const QString templtext)
|
||||||
|
{
|
||||||
|
QFile fd(printDir.filePath("ssrftmptemplate.html"));
|
||||||
|
|
||||||
|
fd.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
|
QTextStream out(&fd);
|
||||||
|
out << templtext;
|
||||||
|
fd.close();
|
||||||
|
return fd.fileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Printer::print()
|
||||||
|
{
|
||||||
|
// we can only print if "PRINT" mode is selected
|
||||||
|
int i;
|
||||||
|
struct dive *dive;
|
||||||
|
QString fn;
|
||||||
|
int dives_to_print = 0;
|
||||||
|
for_each_dive(i, dive)
|
||||||
|
if (dive->selected || !printOptions.print_selected)
|
||||||
|
++dives_to_print;
|
||||||
|
|
||||||
|
for_each_dive (i, dive) {
|
||||||
|
//TODO check for exporting selected dives only
|
||||||
|
if (!dive->selected && printOptions.print_selected)
|
||||||
|
continue;
|
||||||
|
exportProfile(dive, printDir.filePath(QString("dive_%1.png").arg(dive->id)));
|
||||||
|
emit(progessUpdated(done + lrint(i * 80.0 / dives_to_print)));
|
||||||
|
}
|
||||||
|
|
||||||
|
profilesMissing = true;
|
||||||
|
TemplateLayout t(printOptions, templateOptions);
|
||||||
|
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
|
||||||
|
int dpi = printer.resolution();
|
||||||
|
webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
|
||||||
|
|
||||||
|
if (printOptions.type == print_options::DIVELIST) {
|
||||||
|
QFile printFile(printDir.filePath("print.html"));
|
||||||
|
printFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
|
QTextStream out(&printFile);
|
||||||
|
out << t.generate(inPlanner);
|
||||||
|
printFile.close();
|
||||||
|
webView->load(QUrl::fromLocalFile(printDir.filePath("print.html")));
|
||||||
|
} else if (printOptions.type == print_options::STATISTICS )
|
||||||
|
webView->setHtml(t.generateStatistics());
|
||||||
|
if (printOptions.color_selected && printer.colorMode())
|
||||||
|
printer.setColorMode(QPrinter::Color);
|
||||||
|
else
|
||||||
|
printer.setColorMode(QPrinter::GrayScale);
|
||||||
|
printer.setResolution(dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Printer::printFinished()
|
||||||
|
{
|
||||||
|
qDebug() << "received the jobDone signal, closing the dialog; page should have referenced:";
|
||||||
|
webView->page()->toHtml([](const QString h){
|
||||||
|
QRegularExpression img("img src=([^ ]+) ");
|
||||||
|
QRegularExpressionMatchIterator iter = img.globalMatch(h);
|
||||||
|
while(iter.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = iter.next();
|
||||||
|
QString filename = match.captured(1).replace("file://", "");
|
||||||
|
qDebug() << filename << (QFile(filename).exists() ? "which does" : "which doesn't") << "exist";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
62
desktop-widgets/printerwebengine.h
Normal file
62
desktop-widgets/printerwebengine.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#ifndef PRINTER_H
|
||||||
|
#define PRINTER_H
|
||||||
|
|
||||||
|
#include "printoptions.h"
|
||||||
|
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
|
class ProfileWidget2;
|
||||||
|
class QPainter;
|
||||||
|
class QPaintDevice;
|
||||||
|
class QRect;
|
||||||
|
class QWebEngineView;
|
||||||
|
|
||||||
|
|
||||||
|
class Printer : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum PrintMode {
|
||||||
|
PRINT,
|
||||||
|
PREVIEW
|
||||||
|
};
|
||||||
|
QWebEngineView *webView;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPaintDevice *paintDevice;
|
||||||
|
QPrinter printer;
|
||||||
|
QTemporaryDir printDir;
|
||||||
|
print_options &printOptions;
|
||||||
|
template_options &templateOptions;
|
||||||
|
QSize pageSize;
|
||||||
|
PrintMode printMode;
|
||||||
|
bool inPlanner;
|
||||||
|
int done;
|
||||||
|
void onLoadFinished();
|
||||||
|
bool profilesMissing;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void templateProgessUpdated(int value);
|
||||||
|
void printing();
|
||||||
|
void printFinished();
|
||||||
|
void reopen();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Printer(QPaintDevice *paintDevice, print_options &printOptions, template_options &templateOptions, PrintMode printMode, bool inPlanner, QWidget *parent);
|
||||||
|
~Printer();
|
||||||
|
void print();
|
||||||
|
void previewOnePage();
|
||||||
|
QString writeTmpTemplate(const QString templtext);
|
||||||
|
QString exportHtml();
|
||||||
|
void updateOptions(print_options &poptions, template_options &toptions);
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void progessUpdated(int value);
|
||||||
|
void profilesInserted();
|
||||||
|
void jobDone();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //PRINTER_H
|
||||||
@ -1,15 +1,22 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "templateedit.h"
|
#include "templateedit.h"
|
||||||
#include "templatelayout.h"
|
#include "templatelayout.h"
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
#include "printerwebengine.h"
|
||||||
|
#else
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
|
#endif
|
||||||
#include "ui_templateedit.h"
|
#include "ui_templateedit.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
#include <QWebEngineView>
|
||||||
|
#endif
|
||||||
|
|
||||||
TemplateEdit::TemplateEdit(QWidget *parent, const print_options &printOptions, template_options &templateOptions) :
|
TemplateEdit::TemplateEdit(QWidget *parent, print_options &printOptions, template_options &templateOptions) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::TemplateEdit),
|
ui(new Ui::TemplateEdit),
|
||||||
printOptions(printOptions),
|
printOptions(printOptions),
|
||||||
@ -43,7 +50,20 @@ TemplateEdit::TemplateEdit(QWidget *parent, const print_options &printOptions, t
|
|||||||
|
|
||||||
ui->plainTextEdit->setPlainText(grantlee_template);
|
ui->plainTextEdit->setPlainText(grantlee_template);
|
||||||
editingCustomColors = false;
|
editingCustomColors = false;
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
QWebEngineView *view;
|
||||||
|
preview = new Printer(nullptr, printOptions, newTemplateOptions, Printer::PREVIEW, false, this);
|
||||||
|
view = preview->webView;
|
||||||
|
int w = ui->label->width();
|
||||||
|
int h = ui->label->height();
|
||||||
|
view->resize(w, h);
|
||||||
|
preview->print();
|
||||||
|
view->setZoomFactor(0.25);
|
||||||
|
view->show();
|
||||||
|
ui->verticalLayout_3->replaceWidget(ui->label, view);
|
||||||
|
#else
|
||||||
updatePreview();
|
updatePreview();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateEdit::~TemplateEdit()
|
TemplateEdit::~TemplateEdit()
|
||||||
@ -54,14 +74,16 @@ TemplateEdit::~TemplateEdit()
|
|||||||
|
|
||||||
void TemplateEdit::updatePreview()
|
void TemplateEdit::updatePreview()
|
||||||
{
|
{
|
||||||
|
#ifndef USE_WEBENGINE
|
||||||
// update Qpixmap preview
|
// update Qpixmap preview
|
||||||
int width = ui->label->width();
|
int width = ui->label->width();
|
||||||
int height = ui->label->height();
|
int height = ui->label->height();
|
||||||
QPixmap map(width * 2, height * 2);
|
QPixmap map(width * 2, height * 2);
|
||||||
map.fill(QColor::fromRgb(255, 255, 255));
|
map.fill(QColor::fromRgb(255, 255, 255));
|
||||||
Printer printer(&map, printOptions, newTemplateOptions, Printer::PREVIEW, false);
|
Printer printer(&map, printOptions, newTemplateOptions, Printer::PREVIEW, false, nullptr);
|
||||||
printer.previewOnePage();
|
printer.previewOnePage();
|
||||||
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
|
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
|
||||||
|
#endif
|
||||||
|
|
||||||
// update colors tab
|
// update colors tab
|
||||||
ui->colorLable1->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color1.name() + "\";}");
|
ui->colorLable1->setStyleSheet("QLabel { background-color : \"" + newTemplateOptions.color_palette.color1.name() + "\";}");
|
||||||
@ -158,6 +180,7 @@ void TemplateEdit::saveSettings()
|
|||||||
}
|
}
|
||||||
if (templateOptions.color_palette_index == CUSTOM)
|
if (templateOptions.color_palette_index == CUSTOM)
|
||||||
custom_colors = templateOptions.color_palette;
|
custom_colors = templateOptions.color_palette;
|
||||||
|
emit accept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,6 +188,7 @@ void TemplateEdit::saveSettings()
|
|||||||
void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button)
|
void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button)
|
||||||
{
|
{
|
||||||
QDialogButtonBox::StandardButton standardButton = ui->buttonBox->standardButton(button);
|
QDialogButtonBox::StandardButton standardButton = ui->buttonBox->standardButton(button);
|
||||||
|
QString template_file = printOptions.p_template;
|
||||||
switch (standardButton) {
|
switch (standardButton) {
|
||||||
case QDialogButtonBox::Ok:
|
case QDialogButtonBox::Ok:
|
||||||
saveSettings();
|
saveSettings();
|
||||||
@ -172,7 +196,14 @@ void TemplateEdit::on_buttonBox_clicked(QAbstractButton *button)
|
|||||||
case QDialogButtonBox::Cancel:
|
case QDialogButtonBox::Cancel:
|
||||||
break;
|
break;
|
||||||
case QDialogButtonBox::Apply:
|
case QDialogButtonBox::Apply:
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
printOptions.p_template = preview->writeTmpTemplate(ui->plainTextEdit->toPlainText());
|
||||||
|
preview->updateOptions(printOptions, templateOptions);
|
||||||
|
preview->print();
|
||||||
|
printOptions.p_template = template_file;
|
||||||
|
#else
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
#endif
|
||||||
updatePreview();
|
updatePreview();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "printoptions.h"
|
#include "printoptions.h"
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
#include "printerwebengine.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class TemplateEdit;
|
class TemplateEdit;
|
||||||
@ -14,7 +17,7 @@ class TemplateEdit : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TemplateEdit(QWidget *parent, const print_options &printOptions, template_options &templateOptions);
|
explicit TemplateEdit(QWidget *parent, print_options &printOptions, template_options &templateOptions);
|
||||||
~TemplateEdit();
|
~TemplateEdit();
|
||||||
private slots:
|
private slots:
|
||||||
void on_fontsize_valueChanged(int font_size);
|
void on_fontsize_valueChanged(int font_size);
|
||||||
@ -29,13 +32,15 @@ private:
|
|||||||
Ui::TemplateEdit *ui;
|
Ui::TemplateEdit *ui;
|
||||||
QButtonGroup *btnGroup;
|
QButtonGroup *btnGroup;
|
||||||
bool editingCustomColors;
|
bool editingCustomColors;
|
||||||
const print_options &printOptions;
|
print_options &printOptions;
|
||||||
template_options &templateOptions;
|
template_options &templateOptions;
|
||||||
struct template_options newTemplateOptions;
|
struct template_options newTemplateOptions;
|
||||||
QString grantlee_template;
|
QString grantlee_template;
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
Printer *preview;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEMPLATEEDIT_H
|
#endif // TEMPLATEEDIT_H
|
||||||
|
|||||||
@ -571,22 +571,6 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>accepted()</signal>
|
|
||||||
<receiver>TemplateEdit</receiver>
|
|
||||||
<slot>accept()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>248</x>
|
|
||||||
<y>254</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>157</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
|
|||||||
@ -152,7 +152,13 @@ QString TemplateLayout::generateStatistics()
|
|||||||
|
|
||||||
QString TemplateLayout::readTemplate(QString template_name)
|
QString TemplateLayout::readTemplate(QString template_name)
|
||||||
{
|
{
|
||||||
QFile qfile(getPrintingTemplatePathUser() + QDir::separator() + template_name);
|
QString filename;
|
||||||
|
// are we using a temporary file while editing?
|
||||||
|
if (template_name.contains("ssrftmptemplate.html"))
|
||||||
|
filename = template_name;
|
||||||
|
else
|
||||||
|
filename = getPrintingTemplatePathUser() + QDir::separator() + template_name;
|
||||||
|
QFile qfile(filename);
|
||||||
if (qfile.open(QFile::ReadOnly | QFile::Text)) {
|
if (qfile.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
QTextStream in(&qfile);
|
QTextStream in(&qfile);
|
||||||
return in.readAll();
|
return in.readAll();
|
||||||
|
|||||||
@ -35,6 +35,26 @@ void SearchBar::enableButtons(const QString &s)
|
|||||||
ui.findNext->setEnabled(s.length());
|
ui.findNext->setEnabled(s.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
MyQWebEnginePage::MyQWebEnginePage(QObject* parent) : QWebEnginePage(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MyQWebEnginePage::acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
|
||||||
|
{
|
||||||
|
if (type == QWebEnginePage::NavigationTypeLinkClicked)
|
||||||
|
{
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MyQWebEngineView::MyQWebEngineView(QWidget* parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
UserManual::UserManual(QWidget *parent) : QDialog(parent)
|
UserManual::UserManual(QWidget *parent) : QDialog(parent)
|
||||||
{
|
{
|
||||||
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
||||||
@ -55,12 +75,19 @@ UserManual::UserManual(QWidget *parent) : QDialog(parent)
|
|||||||
setWindowTitle(tr("User manual"));
|
setWindowTitle(tr("User manual"));
|
||||||
setWindowIcon(QIcon(":subsurface-icon"));
|
setWindowIcon(QIcon(":subsurface-icon"));
|
||||||
|
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
userManual = new MyQWebEngineView(this);
|
||||||
|
MyQWebEnginePage *page = new MyQWebEnginePage();
|
||||||
|
userManual->setPage(page);
|
||||||
|
#else
|
||||||
userManual = new QWebView(this);
|
userManual = new QWebView(this);
|
||||||
|
userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
|
||||||
|
#endif
|
||||||
|
|
||||||
QString colorBack = palette().highlight().color().name(QColor::HexRgb);
|
QString colorBack = palette().highlight().color().name(QColor::HexRgb);
|
||||||
QString colorText = palette().highlightedText().color().name(QColor::HexRgb);
|
QString colorText = palette().highlightedText().color().name(QColor::HexRgb);
|
||||||
userManual->setStyleSheet(QString("QWebView { selection-background-color: %1; selection-color: %2; }")
|
userManual->setStyleSheet(QString("QWebView { selection-background-color: %1; selection-color: %2; }")
|
||||||
.arg(colorBack).arg(colorText));
|
.arg(colorBack).arg(colorText));
|
||||||
userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
|
|
||||||
QString searchPath = getSubsurfaceDataPath("Documentation");
|
QString searchPath = getSubsurfaceDataPath("Documentation");
|
||||||
if (searchPath.size()) {
|
if (searchPath.size()) {
|
||||||
// look for localized versions of the manual first
|
// look for localized versions of the manual first
|
||||||
@ -85,7 +112,10 @@ UserManual::UserManual(QWidget *parent) : QDialog(parent)
|
|||||||
searchBar->hide();
|
searchBar->hide();
|
||||||
connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show()));
|
connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show()));
|
||||||
connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide()));
|
connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide()));
|
||||||
|
#ifndef USE_WEBENGINE
|
||||||
connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl)));
|
connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl)));
|
||||||
|
#endif
|
||||||
|
|
||||||
connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString)));
|
connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString)));
|
||||||
connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext()));
|
connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext()));
|
||||||
connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev()));
|
connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev()));
|
||||||
@ -97,6 +127,14 @@ UserManual::UserManual(QWidget *parent) : QDialog(parent)
|
|||||||
setLayout(vboxLayout);
|
setLayout(vboxLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
void UserManual::search(QString text, QWebEnginePage::FindFlags flags = QFlag(0))
|
||||||
|
{
|
||||||
|
userManual->findText(text, flags,
|
||||||
|
[this, text](bool found) {searchBar->setStyleSheet(found || text.length() == 0 ? "" : "QLineEdit{background: red;}");});
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
void UserManual::search(QString text, QWebPage::FindFlags flags = QFlag(0))
|
void UserManual::search(QString text, QWebPage::FindFlags flags = QFlag(0))
|
||||||
{
|
{
|
||||||
if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
|
if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
|
||||||
@ -105,6 +143,7 @@ void UserManual::search(QString text, QWebPage::FindFlags flags = QFlag(0))
|
|||||||
searchBar->setStyleSheet("QLineEdit{background: red;}");
|
searchBar->setStyleSheet("QLineEdit{background: red;}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void UserManual::searchTextChanged(const QString& text)
|
void UserManual::searchTextChanged(const QString& text)
|
||||||
{
|
{
|
||||||
@ -119,13 +158,21 @@ void UserManual::searchNext()
|
|||||||
|
|
||||||
void UserManual::searchPrev()
|
void UserManual::searchPrev()
|
||||||
{
|
{
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
search(mLastText, QWebEnginePage::FindBackward);
|
||||||
|
#else
|
||||||
search(mLastText, QWebPage::FindBackward);
|
search(mLastText, QWebPage::FindBackward);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef USE_WEBENGINE
|
||||||
void UserManual::linkClickedSlot(const QUrl& url)
|
void UserManual::linkClickedSlot(const QUrl& url)
|
||||||
{
|
{
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
void UserManual::showEvent(QShowEvent *e)
|
void UserManual::showEvent(QShowEvent *e)
|
||||||
|
|||||||
@ -2,7 +2,13 @@
|
|||||||
#ifndef USERMANUAL_H
|
#ifndef USERMANUAL_H
|
||||||
#define USERMANUAL_H
|
#define USERMANUAL_H
|
||||||
|
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
#include <QWebEngineView>
|
||||||
|
#include <QWebEnginePage>
|
||||||
|
#else
|
||||||
#include <QWebView>
|
#include <QWebView>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "ui_searchbar.h"
|
#include "ui_searchbar.h"
|
||||||
|
|
||||||
@ -22,6 +28,26 @@ private:
|
|||||||
Ui::SearchBar ui;
|
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 {
|
class UserManual : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -41,11 +67,19 @@ slots:
|
|||||||
void searchTextChanged(const QString& s);
|
void searchTextChanged(const QString& s);
|
||||||
void searchNext();
|
void searchNext();
|
||||||
void searchPrev();
|
void searchPrev();
|
||||||
|
#ifndef USE_WEBENGINE
|
||||||
void linkClickedSlot(const QUrl& url);
|
void linkClickedSlot(const QUrl& url);
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
SearchBar *searchBar;
|
SearchBar *searchBar;
|
||||||
QString mLastText;
|
QString mLastText;
|
||||||
|
#ifdef USE_WEBENGINE
|
||||||
|
QWebEngineView *userManual;
|
||||||
|
void search(QString, QWebEnginePage::FindFlags);
|
||||||
|
#else
|
||||||
QWebView *userManual;
|
QWebView *userManual;
|
||||||
void search(QString, QWebPage::FindFlags);
|
void search(QString, QWebPage::FindFlags);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USERMANUAL_H
|
#endif // USERMANUAL_H
|
||||||
|
|||||||
@ -84,6 +84,12 @@ while [[ $# -gt 0 ]] ; do
|
|||||||
shift
|
shift
|
||||||
BUILD_PREFIX="$1"
|
BUILD_PREFIX="$1"
|
||||||
;;
|
;;
|
||||||
|
-print-with-webengine)
|
||||||
|
# WebKit is no longer supported in Qt 6
|
||||||
|
# WebEngine doesn't build with our tools on Windows
|
||||||
|
# so allow to switch printing between the two flavors
|
||||||
|
BUILD_WITH_WEBENGINE="1"
|
||||||
|
;;
|
||||||
-build-with-webkit)
|
-build-with-webkit)
|
||||||
# unless you build Qt from source (or at least webkit from source, you won't have webkit installed
|
# unless you build Qt from source (or at least webkit from source, you won't have webkit installed
|
||||||
# -build-with-webkit tells the script that in fact we can assume that webkit is present (it usually
|
# -build-with-webkit tells the script that in fact we can assume that webkit is present (it usually
|
||||||
@ -126,7 +132,7 @@ while [[ $# -gt 0 ]] ; do
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown command line argument $arg"
|
echo "Unknown command line argument $arg"
|
||||||
echo "Usage: build.sh [-no-bt] [-quick] [-build-deps] [-src-dir <SUBSURFACE directory>] [-build-prefix <PREFIX>] [-build-with-webkit] [-mobile] [-desktop] [-downloader] [-both] [-all] [-create-appdir] [-release]"
|
echo "Usage: build.sh [-no-bt] [-quick] [-build-deps] [-src-dir <SUBSURFACE directory>] [-build-prefix <PREFIX>] [-print-with-webengine] [-build-with-webkit] [-mobile] [-desktop] [-downloader] [-both] [-all] [-create-appdir] [-release]"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -540,6 +546,11 @@ for (( i=0 ; i < ${#BUILDS[@]} ; i++ )) ; do
|
|||||||
else
|
else
|
||||||
EXTRA_OPTS="-DNO_USERMANUAL=ON -DNO_PRINTING=ON"
|
EXTRA_OPTS="-DNO_USERMANUAL=ON -DNO_PRINTING=ON"
|
||||||
fi
|
fi
|
||||||
|
if [ "$SUBSURFACE_EXECUTABLE" = "DesktopExecutable" ] && [ "$BUILD_WITH_WEBENGINE" = "1" ]; then
|
||||||
|
# if we build with QtWebKit as well then this is a bit redundant, but at least
|
||||||
|
# it's not wrong
|
||||||
|
EXTRA_OPTS="-DNO_USERMANUAL=OFF -DNO_PRINTING=OFF -DUSE_WEBENGINE=ON"
|
||||||
|
fi
|
||||||
|
|
||||||
cd "$SRC"/${SRC_DIR}
|
cd "$SRC"/${SRC_DIR}
|
||||||
|
|
||||||
|
|||||||
@ -146,6 +146,7 @@ cmake -DBTSUPPORT=OFF \
|
|||||||
-DMAKE_TESTS=OFF \
|
-DMAKE_TESTS=OFF \
|
||||||
-DNO_DOCS=ON \
|
-DNO_DOCS=ON \
|
||||||
-DNO_PRINTING=ON \
|
-DNO_PRINTING=ON \
|
||||||
|
-DUSE_WEBENGINE=OFF \
|
||||||
-DNO_USERMANUAL=ON \
|
-DNO_USERMANUAL=ON \
|
||||||
-DSUBSURFACE_TARGET_EXECUTABLE=DesktopExecutable \
|
-DSUBSURFACE_TARGET_EXECUTABLE=DesktopExecutable \
|
||||||
build
|
build
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user