From 2d3ec33aa161b84d038b7decbad46e733b706dca Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 28 Nov 2018 20:14:16 +0100 Subject: [PATCH] musredit help system if neither QWebEngine nor QWebKit is found. If neither QWebEngine nor QWebKit is found, do not generate an build error anymore. Instead just show a default window stating that the help system is not available due to missing Qt web libs. --- src/musredit_qt5/musredit/CMakeLists.txt | 20 +++++++++++++++ src/musredit_qt5/musredit/PHelp.cpp | 31 ++++++++++++++++++++---- src/musredit_qt5/musredit/PHelp.h | 9 +++++-- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/musredit_qt5/musredit/CMakeLists.txt b/src/musredit_qt5/musredit/CMakeLists.txt index dd2995a4..cfa6c3c4 100644 --- a/src/musredit_qt5/musredit/CMakeLists.txt +++ b/src/musredit_qt5/musredit/CMakeLists.txt @@ -5,16 +5,20 @@ find_package(Qt5WebEngine QUIET) find_package(Qt5WebKit QUIET) set(qt_libs Qt5::Core Qt5::Widgets Qt5::Network Qt5::Xml Qt5::Svg Qt5::PrintSupport) +set(Qt5NoWeb 0) if (Qt5WebEngine_FOUND) message("-- Qt5WebEngine is present.") find_package(Qt5WebEngineWidgets QUIET CONFIG REQUIRED) set(qt_libs ${qt_libs} Qt5::WebEngine Qt5::WebEngineWidgets) + # unset a potentially found Qt5Webkit + unset(Qt5WebKit_FOUND) elseif (Qt5WebKit_FOUND) message("-- Qt5WebKit is present.") find_package(Qt5WebKitWidgets QUIET CONFIG REQUIRED) set(qt_libs ${qt_libs} Qt5::WebKit Qt5::WebKitWidgets) else (Qt5WebEngine_FOUND) message("-- Neither Qt5WebEngine nor Qt5WebKit found.") + set(Qt5NoWeb 1) endif (Qt5WebEngine_FOUND) set(musredit_src @@ -116,6 +120,15 @@ else (APPLE) ) endif (APPLE) +# set necessary tags depending if QtWebEngine, QtWebKit, +# or none of both are given +if (Qt5WebKit_FOUND) + target_compile_options(musredit + BEFORE PRIVATE + -DHAVE_QT_WEB_KIT + ) +endif (Qt5WebKit_FOUND) + if (Qt5WebEngine_FOUND) target_compile_options(musredit BEFORE PRIVATE @@ -123,6 +136,13 @@ if (Qt5WebEngine_FOUND) ) endif (Qt5WebEngine_FOUND) +if (Qt5NoWeb) + target_compile_options(musredit + BEFORE PRIVATE + -DHAVE_QT_NO_WEB + ) +endif (Qt5NoWeb) + target_include_directories(musredit BEFORE PRIVATE $ diff --git a/src/musredit_qt5/musredit/PHelp.cpp b/src/musredit_qt5/musredit/PHelp.cpp index 092925af..ca233b28 100644 --- a/src/musredit_qt5/musredit/PHelp.cpp +++ b/src/musredit_qt5/musredit/PHelp.cpp @@ -30,9 +30,13 @@ #include #ifdef HAVE_QT_WEB_ENGINE #include -#else +#endif +#ifdef HAVE_QT_WEB_KIT #include #endif +#ifdef HAVE_QT_NO_WEB +#include +#endif #include #include @@ -61,14 +65,24 @@ PHelp::PHelp(const QString &url, const bool isDarkTheme) : #ifdef HAVE_QT_WEB_ENGINE fView = new QWebEngineView(this); -#else +#endif +#ifdef HAVE_QT_WEB_KIT fView = new QWebView(this); #endif +#ifdef HAVE_QT_NO_WEB + fView = new QPlainTextEdit(this); +#endif +#ifndef HAVE_QT_NO_WEB fView->load(QUrl(url)); connect(fView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); connect(fView, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); connect(fView, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); connect(fView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); +#else + fView->setPlainText("Within the current setup there is NO Help available."); + fView->appendPlainText("The necessary Qt web libs where not found when setting up musredit."); + fView->setReadOnly(true); +#endif fLocationEdit = new QLineEdit(this); fLocationEdit->setSizePolicy(QSizePolicy::Expanding, fLocationEdit->sizePolicy().verticalPolicy()); @@ -80,12 +94,13 @@ PHelp::PHelp(const QString &url, const bool isDarkTheme) : toolBar->addAction(fView->pageAction(QWebEnginePage::Forward)); toolBar->addAction(fView->pageAction(QWebEnginePage::Reload)); toolBar->addAction(fView->pageAction(QWebEnginePage::Stop)); -#else +#endif +#ifdef HAVE_QT_WEB_KIT toolBar->addAction(fView->pageAction(QWebPage::Back)); toolBar->addAction(fView->pageAction(QWebPage::Forward)); toolBar->addAction(fView->pageAction(QWebPage::Reload)); toolBar->addAction(fView->pageAction(QWebPage::Stop)); -#endif +#endif toolBar->addWidget(fLocationEdit); QMenu *exitMenu = menuBar()->addMenu(tr("&File")); @@ -127,7 +142,9 @@ void PHelp::done() */ void PHelp::adjustLocation() { +#ifndef HAVE_QT_NO_WEB fLocationEdit->setText(fView->url().toString()); +#endif } //--------------------------------------------------------------------------- @@ -138,8 +155,10 @@ void PHelp::adjustLocation() void PHelp::changeLocation() { QUrl url = QUrl(fLocationEdit->text()); +#ifndef HAVE_QT_NO_WEB fView->load(url); fView->setFocus(); +#endif } //--------------------------------------------------------------------------- @@ -149,10 +168,12 @@ void PHelp::changeLocation() */ void PHelp::adjustTitle() { +#ifndef HAVE_QT_NO_WEB if (fProgress <= 0 || fProgress >= 100) - setWindowTitle(fView->title()); + setWindowTitle(fView->title()); else setWindowTitle(QString("%1 (%2%)").arg(fView->title()).arg(fProgress)); +#endif } //--------------------------------------------------------------------------- diff --git a/src/musredit_qt5/musredit/PHelp.h b/src/musredit_qt5/musredit/PHelp.h index 5b1f7b70..4a45db25 100644 --- a/src/musredit_qt5/musredit/PHelp.h +++ b/src/musredit_qt5/musredit/PHelp.h @@ -34,7 +34,8 @@ #ifdef HAVE_QT_WEB_ENGINE class QWebEngineView; -#else +#endif +#ifdef HAVE_QT_WEB_KIT class QWebView; #endif QT_BEGIN_NAMESPACE @@ -66,8 +67,12 @@ class PHelp : public QMainWindow bool fDarkTheme; #ifdef HAVE_QT_WEB_ENGINE QWebEngineView *fView; ///< web viewer -#else +#endif +#ifdef HAVE_QT_WEB_KIT QWebView *fView; ///< web viewer +#endif +#ifdef HAVE_QT_NO_WEB + QPlainTextEdit *fView; ///< dialog stating that there is NO web viewer #endif QLineEdit *fLocationEdit; ///< url address line edit int fProgress; ///< progress value (0-100) while loading an url