Added wheel event for webpage zooming.
This commit is contained in:
parent
acb3cad958
commit
2774ffb655
@ -77,6 +77,11 @@
|
|||||||
#define ENCRYPTION_FILE_NAME "key.private"
|
#define ENCRYPTION_FILE_NAME "key.private"
|
||||||
#define RELOAD_MODEL_BORDER_NUM 10
|
#define RELOAD_MODEL_BORDER_NUM 10
|
||||||
|
|
||||||
|
#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 INTERNAL_URL_MESSAGE "rssguard.message"
|
#define INTERNAL_URL_MESSAGE "rssguard.message"
|
||||||
#define INTERNAL_URL_BLANK "rssguard.blank"
|
#define INTERNAL_URL_BLANK "rssguard.blank"
|
||||||
#define INTERNAL_URL_MESSAGE_HOST "message"
|
#define INTERNAL_URL_MESSAGE_HOST "message"
|
||||||
|
@ -708,7 +708,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="m_actionTabNewWebBrowser">
|
<action name="m_actionTabNewWebBrowser">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>New tab</string>
|
<string>New web browser tab</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="m_actionTabsCloseAll">
|
<action name="m_actionTabsCloseAll">
|
||||||
|
@ -104,6 +104,18 @@ void WebBrowser::reloadFontSettings() {
|
|||||||
QWebEngineSettings::globalSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, fon.pointSize());
|
QWebEngineSettings::globalSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, fon.pointSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowser::increaseZoom() {
|
||||||
|
m_webView->increaseWebPageZoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::decreaseZoom() {
|
||||||
|
m_webView->decreaseWebPageZoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::resetZoom() {
|
||||||
|
m_webView->resetWebPageZoom();
|
||||||
|
}
|
||||||
|
|
||||||
void WebBrowser::clear() {
|
void WebBrowser::clear() {
|
||||||
m_webView->clear();
|
m_webView->clear();
|
||||||
hide();
|
hide();
|
||||||
|
@ -53,6 +53,10 @@ class WebBrowser : public TabContent {
|
|||||||
void reloadFontSettings();
|
void reloadFontSettings();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void increaseZoom();
|
||||||
|
void decreaseZoom();
|
||||||
|
void resetZoom();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void loadUrl(const QString &url);
|
void loadUrl(const QString &url);
|
||||||
void loadUrl(const QUrl &url);
|
void loadUrl(const QUrl &url);
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
#include "network-web/webpage.h"
|
#include "network-web/webpage.h"
|
||||||
|
|
||||||
|
#include <QWheelEvent>
|
||||||
|
|
||||||
|
|
||||||
WebViewer::WebViewer(QWidget *parent) : QWebEngineView(parent) {
|
WebViewer::WebViewer(QWidget *parent) : QWebEngineView(parent) {
|
||||||
WebPage *page = new WebPage(this);
|
WebPage *page = new WebPage(this);
|
||||||
@ -30,10 +32,50 @@ WebViewer::WebViewer(QWidget *parent) : QWebEngineView(parent) {
|
|||||||
setPage(page);
|
setPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebViewer::canIncreaseZoom() {
|
||||||
|
return zoomFactor() <= MAX_ZOOM_FACTOR - ZOOM_FACTOR_STEP;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebViewer::canDecreaseZoom() {
|
||||||
|
return zoomFactor() >= MIN_ZOOM_FACTOR + ZOOM_FACTOR_STEP;
|
||||||
|
}
|
||||||
|
|
||||||
void WebViewer::displayMessage() {
|
void WebViewer::displayMessage() {
|
||||||
setHtml(m_messageContents, QUrl(INTERNAL_URL_MESSAGE));
|
setHtml(m_messageContents, QUrl(INTERNAL_URL_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebViewer::increaseWebPageZoom() {
|
||||||
|
if (canIncreaseZoom()) {
|
||||||
|
setZoomFactor(zoomFactor() + ZOOM_FACTOR_STEP);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebViewer::decreaseWebPageZoom() {
|
||||||
|
if (canDecreaseZoom()) {
|
||||||
|
setZoomFactor(zoomFactor() - ZOOM_FACTOR_STEP);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebViewer::resetWebPageZoom() {
|
||||||
|
const qreal new_factor = 1.0;
|
||||||
|
|
||||||
|
if (new_factor != zoomFactor()) {
|
||||||
|
setZoomFactor(new_factor);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebViewer::loadMessages(const QList<Message> &messages) {
|
void WebViewer::loadMessages(const QList<Message> &messages) {
|
||||||
Skin skin = qApp->skins()->currentSkin();
|
Skin skin = qApp->skins()->currentSkin();
|
||||||
QString messages_layout;
|
QString messages_layout;
|
||||||
@ -75,3 +117,16 @@ void WebViewer::loadMessage(const Message &message) {
|
|||||||
void WebViewer::clear() {
|
void WebViewer::clear() {
|
||||||
setHtml("<!DOCTYPE html><html><body</body></html>", QUrl(INTERNAL_URL_BLANK));
|
setHtml("<!DOCTYPE html><html><body</body></html>", QUrl(INTERNAL_URL_BLANK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebViewer::wheelEvent(QWheelEvent *event) {
|
||||||
|
QWebEngineView::wheelEvent(event);
|
||||||
|
|
||||||
|
if ((event->modifiers() & Qt::ControlModifier) > 0) {
|
||||||
|
if (event->delta() > 0) {
|
||||||
|
increaseWebPageZoom();
|
||||||
|
}
|
||||||
|
else if (event->delta() < 0) {
|
||||||
|
decreaseWebPageZoom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,12 +30,23 @@ class WebViewer : public QWebEngineView {
|
|||||||
public:
|
public:
|
||||||
explicit WebViewer(QWidget* parent = 0);
|
explicit WebViewer(QWidget* parent = 0);
|
||||||
|
|
||||||
|
bool canIncreaseZoom();
|
||||||
|
bool canDecreaseZoom();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
// Page zoom modifiers.
|
||||||
|
bool increaseWebPageZoom();
|
||||||
|
bool decreaseWebPageZoom();
|
||||||
|
bool resetWebPageZoom();
|
||||||
|
|
||||||
void displayMessage();
|
void displayMessage();
|
||||||
void loadMessages(const QList<Message> &messages);
|
void loadMessages(const QList<Message> &messages);
|
||||||
void loadMessage(const Message &message);
|
void loadMessage(const Message &message);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void messageStatusChangeRequested(int message_id, WebPage::MessageStatusChange change);
|
void messageStatusChangeRequested(int message_id, WebPage::MessageStatusChange change);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user