diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index d06ce8352..0928d927d 100644 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -157,7 +157,7 @@ #define MAX_ZOOM_FACTOR 5.0f #define MIN_ZOOM_FACTOR 0.25f #define DEFAULT_ZOOM_FACTOR 1.0f -#define ZOOM_FACTOR_STEP 0.1f +#define ZOOM_FACTOR_STEP 0.05f #if defined(USE_WEBENGINE) #define HTTP_COMPLETE_USERAGENT (QWebEngineProfile::defaultProfile()->httpUserAgent().toLocal8Bit() + QByteArrayLiteral(" ") + QByteArrayLiteral(APP_USERAGENT)) diff --git a/src/librssguard/gui/litehtml/litehtmlviewer.cpp b/src/librssguard/gui/litehtml/litehtmlviewer.cpp index 080c71fdf..72fe8627f 100755 --- a/src/librssguard/gui/litehtml/litehtmlviewer.cpp +++ b/src/librssguard/gui/litehtml/litehtmlviewer.cpp @@ -9,6 +9,7 @@ #include "network-web/networkfactory.h" #include +#include LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent) { setResourceHandler([this](const QUrl& url) { @@ -31,6 +32,10 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) { browser->m_actionReload = new QAction(this); browser->m_actionStop = new QAction(this); + connect(this, &LiteHtmlViewer::zoomFactorChanged, browser, &WebBrowser::onZoomFactorChanged); + + // TODO: změna ikon, změna stavu akcí. + /* connect(this, &WebEngineViewer::urlChanged, browser, &WebBrowser::updateUrl); connect(this, &WebEngineViewer::loadStarted, browser, &WebBrowser::onLoadingStarted); @@ -157,19 +162,45 @@ void LiteHtmlViewer::setVerticalScrollBarPosition(double pos) {} void LiteHtmlViewer::reloadFontSettings(const QFont& fon) {} bool LiteHtmlViewer::canZoomIn() const { - return {}; + return zoomFactor() <= double(MAX_ZOOM_FACTOR) - double(ZOOM_FACTOR_STEP); } bool LiteHtmlViewer::canZoomOut() const { - return {}; + return zoomFactor() >= double(MIN_ZOOM_FACTOR) + double(ZOOM_FACTOR_STEP); } qreal LiteHtmlViewer::zoomFactor() const { - return {}; + return QLiteHtmlWidget::zoomFactor(); } -void LiteHtmlViewer::zoomIn() {} +void LiteHtmlViewer::zoomIn() { + setZoomFactor(zoomFactor() + double(ZOOM_FACTOR_STEP)); +} -void LiteHtmlViewer::zoomOut() {} +void LiteHtmlViewer::zoomOut() { + setZoomFactor(zoomFactor() - double(ZOOM_FACTOR_STEP)); +} -void LiteHtmlViewer::setZoomFactor(qreal zoom_factor) {} +void LiteHtmlViewer::setZoomFactor(qreal zoom_factor) { + if (zoom_factor == 0.0) { + QLiteHtmlWidget::setZoomFactor(0.1); + } + else { + QLiteHtmlWidget::setZoomFactor(zoom_factor); + } +} + +void LiteHtmlViewer::wheelEvent(QWheelEvent* event) { + if ((event->modifiers() & Qt::KeyboardModifier::ControlModifier) > 0) { + if (event->angleDelta().y() > 0 && canZoomIn()) { + zoomIn(); + emit zoomFactorChanged(); + } + else if (event->angleDelta().y() < 0 && canZoomOut()) { + zoomOut(); + emit zoomFactorChanged(); + } + } + + QLiteHtmlWidget::wheelEvent(event); +} diff --git a/src/librssguard/gui/litehtml/litehtmlviewer.h b/src/librssguard/gui/litehtml/litehtmlviewer.h index ba4223662..22640f5f4 100755 --- a/src/librssguard/gui/litehtml/litehtmlviewer.h +++ b/src/librssguard/gui/litehtml/litehtmlviewer.h @@ -6,7 +6,11 @@ #include "3rd-party/qlitehtml/qlitehtmlwidget.h" #include "gui/webviewer.h" +class QWheelEvent; + class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer { + Q_OBJECT + public: explicit LiteHtmlViewer(QWidget* parent = nullptr); @@ -28,6 +32,12 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer { virtual void zoomIn(); virtual void zoomOut(); virtual void setZoomFactor(qreal zoom_factor); + + signals: + void zoomFactorChanged(); + + protected: + virtual void wheelEvent(QWheelEvent* event); }; #endif // LITEHTMLVIEWER_H diff --git a/src/librssguard/gui/webbrowser.cpp b/src/librssguard/gui/webbrowser.cpp index 251223100..ccb333908 100644 --- a/src/librssguard/gui/webbrowser.cpp +++ b/src/librssguard/gui/webbrowser.cpp @@ -47,7 +47,7 @@ WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent), this)) { // Initialize the components and layout. m_webView->bindToBrowser(this); - m_webView->setZoomFactor(qApp->settings()->value(GROUP(Messages), Messages::Zoom).toReal()); + m_webView->setZoomFactor(qApp->settings()->value(GROUP(Messages), SETTING(Messages::Zoom)).toDouble()); initializeLayout(); @@ -112,6 +112,10 @@ void WebBrowser::reloadFontSettings() { m_webView->reloadFontSettings(fon); } +void WebBrowser::onZoomFactorChanged() { + qApp->settings()->setValue(GROUP(Messages), Messages::Zoom, m_webView->zoomFactor()); +} + void WebBrowser::increaseZoom() { if (m_webView->canZoomIn()) { m_webView->zoomIn(); diff --git a/src/librssguard/gui/webbrowser.h b/src/librssguard/gui/webbrowser.h index b4ed36b70..0eb70bb6c 100644 --- a/src/librssguard/gui/webbrowser.h +++ b/src/librssguard/gui/webbrowser.h @@ -57,6 +57,7 @@ class WebBrowser : public TabContent { virtual bool eventFilter(QObject* watched, QEvent* event); private slots: + void onZoomFactorChanged(); void openCurrentSiteInSystemBrowser(); void updateUrl(const QUrl& url); void onLoadingStarted(); diff --git a/src/librssguard/gui/webengine/webengineviewer.cpp b/src/librssguard/gui/webengine/webengineviewer.cpp index 250f369cc..1fbb6d79c 100644 --- a/src/librssguard/gui/webengine/webengineviewer.cpp +++ b/src/librssguard/gui/webengine/webengineviewer.cpp @@ -238,12 +238,14 @@ bool WebEngineViewer::eventFilter(QObject* object, QEvent* event) { QWheelEvent* wh_event = static_cast(event); if ((wh_event->modifiers() & Qt::KeyboardModifier::ControlModifier) > 0) { - if (wh_event->angleDelta().y() > 0) { + if (wh_event->angleDelta().y() > 0 && canZoomIn()) { zoomIn(); + emit zoomFactorChanged(); return true; } - else if (wh_event->angleDelta().y() < 0) { + else if (wh_event->angleDelta().y() < 0 && canZoomOut()) { zoomOut(); + emit zoomFactorChanged(); return true; } } diff --git a/src/librssguard/gui/webengine/webengineviewer.h b/src/librssguard/gui/webengine/webengineviewer.h index 71f22ba0b..cd269daec 100644 --- a/src/librssguard/gui/webengine/webengineviewer.h +++ b/src/librssguard/gui/webengine/webengineviewer.h @@ -40,6 +40,9 @@ class WebEngineViewer : public QWebEngineView, public WebViewer { virtual QString html() const; virtual QUrl url() const; + signals: + void zoomFactorChanged(); + protected: virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type); virtual void contextMenuEvent(QContextMenuEvent* event); diff --git a/src/librssguard/miscellaneous/settings.cpp b/src/librssguard/miscellaneous/settings.cpp index 1dae5cc33..1c22ee068 100644 --- a/src/librssguard/miscellaneous/settings.cpp +++ b/src/librssguard/miscellaneous/settings.cpp @@ -118,7 +118,7 @@ DKEY Messages::EnableMessagePreview = "enable_message_preview"; DVALUE(bool) Messages::EnableMessagePreviewDef = true; DKEY Messages::Zoom = "zoom"; -DVALUE(qreal) Messages::ZoomDef = double(1.0f); +DVALUE(qreal) Messages::ZoomDef = double(1.0); DKEY Messages::FixupFutureArticleDateTimes = "fixup_future_datetimes"; DVALUE(bool) Messages::FixupFutureArticleDateTimesDef = false;