mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-26 15:34:59 +01:00
make zoom work
This commit is contained in:
parent
d48309cd17
commit
02c183b2c7
@ -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))
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "network-web/networkfactory.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QWheelEvent>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -238,12 +238,14 @@ bool WebEngineViewer::eventFilter(QObject* object, QEvent* event) {
|
||||
QWheelEvent* wh_event = static_cast<QWheelEvent*>(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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user