[kde-doc-english] [trojita] src/Gui: GUI: Update zoom mode for all parts in sync
Jan Kundrát
jkt at kde.org
Thu May 26 09:52:06 UTC 2016
Git commit 64055232b202328252e3bea28524614968453372 by Jan Kundrát.
Committed on 21/05/2016 at 16:12.
Pushed by gerrit into branch 'master'.
GUI: Update zoom mode for all parts in sync
This is similar to that Ctrl-F shortcut handling -- if we have more than
a single part in an e-mail, multiple actions with the same shortcut are
going to be active, which is a Bad Thing™.
Let's handle this centrally, then. Provisions are still in place for a
possibility of no enclosing MessageView.
Change-Id: I778f479877b830824e0556220ae8d3a0d50819c7
M +3 -0 src/Gui/AbstractPartWidget.h
M +10 -4 src/Gui/AttachmentView.cpp
M +3 -0 src/Gui/AttachmentView.h
M +0 -28 src/Gui/EmbeddedWebView.cpp
M +1 -5 src/Gui/EmbeddedWebView.h
M +10 -4 src/Gui/LoadablePartWidget.cpp
M +6 -3 src/Gui/LoadablePartWidget.h
M +42 -7 src/Gui/MessageView.cpp
M +6 -2 src/Gui/MessageView.h
M +30 -19 src/Gui/PartWidget.cpp
M +19 -7 src/Gui/PartWidget.h
M +37 -17 src/Gui/SimplePartWidget.cpp
M +6 -3 src/Gui/SimplePartWidget.h
http://commits.kde.org/trojita/64055232b202328252e3bea28524614968453372
diff --git a/src/Gui/AbstractPartWidget.h b/src/Gui/AbstractPartWidget.h
index e0a1c15..78e1cbd 100644
--- a/src/Gui/AbstractPartWidget.h
+++ b/src/Gui/AbstractPartWidget.h
@@ -34,6 +34,9 @@ public:
virtual QString quoteMe() const = 0;
virtual ~AbstractPartWidget() {}
virtual void reloadContents() = 0;
+ virtual void zoomIn() = 0;
+ virtual void zoomOut() = 0;
+ virtual void zoomOriginal() = 0;
};
}
diff --git a/src/Gui/AttachmentView.cpp b/src/Gui/AttachmentView.cpp
index dee7ead..10043e9 100644
--- a/src/Gui/AttachmentView.cpp
+++ b/src/Gui/AttachmentView.cpp
@@ -373,12 +373,18 @@ QString AttachmentView::quoteMe() const
return widget && !m_contentWidget->isHidden() ? widget->quoteMe() : QString();
}
-void AttachmentView::reloadContents()
-{
- if (AbstractPartWidget *w = dynamic_cast<AbstractPartWidget*>(m_contentWidget))
- w->reloadContents();
+#define IMPL_PART_FORWARD_ONE_METHOD(METHOD) \
+void AttachmentView::METHOD() \
+{\
+ if (AbstractPartWidget *w = dynamic_cast<AbstractPartWidget*>(m_contentWidget)) \
+ w->METHOD(); \
}
+IMPL_PART_FORWARD_ONE_METHOD(reloadContents)
+IMPL_PART_FORWARD_ONE_METHOD(zoomIn)
+IMPL_PART_FORWARD_ONE_METHOD(zoomOut)
+IMPL_PART_FORWARD_ONE_METHOD(zoomOriginal)
+
void AttachmentView::showMessageSource()
{
auto w = MainWindow::messageSourceWidget(m_partIndex);
diff --git a/src/Gui/AttachmentView.h b/src/Gui/AttachmentView.h
index 3abf1d4..1c40441 100644
--- a/src/Gui/AttachmentView.h
+++ b/src/Gui/AttachmentView.h
@@ -61,6 +61,9 @@ public:
MessageView *messageView, QWidget *contentWidget);
virtual QString quoteMe() const;
virtual void reloadContents();
+ virtual void zoomIn();
+ virtual void zoomOut();
+ virtual void zoomOriginal();
protected:
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
diff --git a/src/Gui/EmbeddedWebView.cpp b/src/Gui/EmbeddedWebView.cpp
index 9e0128e..103849c 100644
--- a/src/Gui/EmbeddedWebView.cpp
+++ b/src/Gui/EmbeddedWebView.cpp
@@ -234,34 +234,6 @@ void EmbeddedWebView::mouseReleaseEvent(QMouseEvent *e)
QWebView::mouseReleaseEvent(e);
}
-void EmbeddedWebView::wheelEvent(QWheelEvent *e)
-{
- if (e->modifiers() == Qt::ControlModifier) {
- if (e->delta() > 0) {
- zoomIn();
- } else {
- zoomOut();
- }
- e->accept();
- } else {
- e->ignore();
- }
-}
-
-const auto zoomConstant = 1.1;
-
-void EmbeddedWebView::zoomIn()
-{
- setZoomFactor(zoomFactor() * zoomConstant);
- constrainSize();
-}
-
-void EmbeddedWebView::zoomOut()
-{
- setZoomFactor(zoomFactor() / zoomConstant);
- constrainSize();
-}
-
void EmbeddedWebView::findScrollParent()
{
if (m_scrollParent)
diff --git a/src/Gui/EmbeddedWebView.h b/src/Gui/EmbeddedWebView.h
index 283a6e9..9ac83d1 100644
--- a/src/Gui/EmbeddedWebView.h
+++ b/src/Gui/EmbeddedWebView.h
@@ -69,19 +69,15 @@ protected:
bool eventFilter(QObject *o, QEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
- void wheelEvent(QWheelEvent *e);
void showEvent(QShowEvent *se);
void addCustomStylesheet(const QString &css);
-protected slots:
- void zoomIn();
- void zoomOut();
+ void constrainSize();
private:
void findScrollParent();
private slots:
void autoScroll();
void slotLinkClicked(const QUrl &url);
void handlePageLoadFinished();
- void constrainSize();
private:
QWidget *m_scrollParent;
int m_scrollParentPadding;
diff --git a/src/Gui/LoadablePartWidget.cpp b/src/Gui/LoadablePartWidget.cpp
index 31dce1e..211acb4 100644
--- a/src/Gui/LoadablePartWidget.cpp
+++ b/src/Gui/LoadablePartWidget.cpp
@@ -89,10 +89,16 @@ void LoadablePartWidget::showEvent(QShowEvent *event)
}
}
-void LoadablePartWidget::reloadContents()
-{
- if (AbstractPartWidget *w = dynamic_cast<AbstractPartWidget*>(realPart))
- w->reloadContents();
+#define IMPL_PART_FORWARD_ONE_METHOD(METHOD) \
+void LoadablePartWidget::METHOD() \
+{\
+ if (AbstractPartWidget *w = dynamic_cast<AbstractPartWidget*>(realPart)) \
+ w->METHOD(); \
}
+IMPL_PART_FORWARD_ONE_METHOD(reloadContents)
+IMPL_PART_FORWARD_ONE_METHOD(zoomIn)
+IMPL_PART_FORWARD_ONE_METHOD(zoomOut)
+IMPL_PART_FORWARD_ONE_METHOD(zoomOriginal)
+
}
diff --git a/src/Gui/LoadablePartWidget.h b/src/Gui/LoadablePartWidget.h
index 58ed280..a4cc7de 100644
--- a/src/Gui/LoadablePartWidget.h
+++ b/src/Gui/LoadablePartWidget.h
@@ -49,10 +49,13 @@ public:
LoadablePartWidget(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager, const QModelIndex &part,
PartWidgetFactory *factory, int recursionDepth,
const UiUtils::PartLoadingOptions loadingMode);
- QString quoteMe() const;
- virtual void reloadContents();
+ QString quoteMe() const override;
+ virtual void reloadContents() override;
+ virtual void zoomIn() override;
+ virtual void zoomOut() override;
+ virtual void zoomOriginal() override;
protected:
- virtual void showEvent(QShowEvent *event);
+ virtual void showEvent(QShowEvent *event) override;
private slots:
void loadClicked();
private:
diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index 829164c..5532b79 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -62,6 +62,7 @@
#include "Imap/Model/Utils.h"
#include "Imap/Network/MsgPartNetAccessManager.h"
#include "Plugins/PluginManager.h"
+#include "UiUtils/IconLoader.h"
namespace Gui
{
@@ -85,6 +86,21 @@ MessageView::MessageView(QWidget *parent, QSettings *settings, Plugins::PluginMa
setFocusPolicy(Qt::StrongFocus); // not by the wheel
+ m_zoomIn = new QAction(UiUtils::loadIcon(QStringLiteral("zoom-in")), tr("Zoom In"), this);
+ m_zoomIn->setShortcut(QKeySequence::ZoomIn);
+ addAction(m_zoomIn);
+ connect(m_zoomIn, &QAction::triggered, this, &MessageView::zoomIn);
+
+ m_zoomOut = new QAction(UiUtils::loadIcon(QStringLiteral("zoom-out")), tr("Zoom Out"), this);
+ m_zoomOut->setShortcut(QKeySequence::ZoomOut);
+ addAction(m_zoomOut);
+ connect(m_zoomOut, &QAction::triggered, this, &MessageView::zoomOut);
+
+ m_zoomOriginal = new QAction(UiUtils::loadIcon(QStringLiteral("zoom-original")), tr("Original Size"), this);
+ addAction(m_zoomOriginal);
+ connect(m_zoomOriginal, &QAction::triggered, this, &MessageView::zoomOriginal);
+
+
// The homepage widget -- our poor man's splashscreen
m_homePage = new EmbeddedWebView(this, new QNetworkAccessManager(this));
m_homePage->setFixedSize(450,300);
@@ -302,13 +318,21 @@ void MessageView::stopAutoMarkAsRead()
bool MessageView::eventFilter(QObject *object, QEvent *event)
{
- if (event->type() == QEvent::Wheel && static_cast<QWheelEvent*>(event)->modifiers() == Qt::NoModifier) {
- // while the containing scrollview has Qt::StrongFocus, the event forwarding breaks that
- // -> completely disable focus for the following wheel event ...
- parentWidget()->setFocusPolicy(Qt::NoFocus);
- MessageView::event(event);
- // ... set reset it
- parentWidget()->setFocusPolicy(Qt::StrongFocus);
+ if (event->type() == QEvent::Wheel) {
+ if (static_cast<QWheelEvent *>(event)->modifiers() == Qt::ControlModifier) {
+ if (static_cast<QWheelEvent *>(event)->delta() > 0) {
+ zoomIn();
+ } else {
+ zoomOut();
+ }
+ } else {
+ // while the containing scrollview has Qt::StrongFocus, the event forwarding breaks that
+ // -> completely disable focus for the following wheel event ...
+ parentWidget()->setFocusPolicy(Qt::NoFocus);
+ MessageView::event(event);
+ // ... set reset it
+ parentWidget()->setFocusPolicy(Qt::StrongFocus);
+ }
return true;
} else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
@@ -351,6 +375,17 @@ QString MessageView::quoteText() const
return QString();
}
+#define FORWARD_METHOD(METHOD) \
+void MessageView::METHOD() \
+{ \
+ if (auto w = bodyWidget()) { \
+ w->METHOD(); \
+ } \
+}
+FORWARD_METHOD(zoomIn)
+FORWARD_METHOD(zoomOut)
+FORWARD_METHOD(zoomOriginal)
+
void MessageView::setNetworkWatcher(Imap::Mailbox::NetworkWatcher *netWatcher)
{
m_netWatcher = netWatcher;
diff --git a/src/Gui/MessageView.h b/src/Gui/MessageView.h
index 12ffa9d..2cc2028 100644
--- a/src/Gui/MessageView.h
+++ b/src/Gui/MessageView.h
@@ -92,8 +92,11 @@ public slots:
void setEmpty();
void setHomepageUrl(const QUrl &homepage);
void stopAutoMarkAsRead();
+ void zoomIn();
+ void zoomOut();
+ void zoomOriginal();
protected:
- void showEvent(QShowEvent *se);
+ void showEvent(QShowEvent *se) override;
private slots:
void markAsRead();
void externalsRequested(const QUrl &url);
@@ -112,7 +115,7 @@ signals:
void searchRequestedBy(EmbeddedWebView *webView);
void transferError(const QString &errorString);
private:
- bool eventFilter(QObject *object, QEvent *event);
+ bool eventFilter(QObject *object, QEvent *event) override;
Imap::Message::Envelope envelope() const;
QString quoteText() const;
void showMessageNow();
@@ -134,6 +137,7 @@ private:
QPointer<Imap::Mailbox::NetworkWatcher> m_netWatcher;
QTimer *markAsReadTimer;
QWidget *m_bodyWidget;
+ QAction *m_zoomIn, *m_zoomOut, *m_zoomOriginal;
std::unique_ptr<PartWidgetFactory> factory;
Spinner *m_loadingSpinner;
diff --git a/src/Gui/PartWidget.cpp b/src/Gui/PartWidget.cpp
index 41e2f24..9adc8f5 100644
--- a/src/Gui/PartWidget.cpp
+++ b/src/Gui/PartWidget.cpp
@@ -157,18 +157,6 @@ QString MultipartAlternativeWidget::quoteMe() const
return w ? w->quoteMe() : QString();
}
-void MultipartAlternativeWidget::reloadContents()
-{
- if (count()) {
- for (int i = 0; i < count(); ++i) {
- AbstractPartWidget *w = dynamic_cast<AbstractPartWidget *>(widget(i));
- if (w) {
- w->reloadContents();
- }
- }
- }
-}
-
bool MultipartAlternativeWidget::eventFilter(QObject *o, QEvent *e)
{
if (e->type() == QEvent::Wheel && qobject_cast<QTabBar*>(o)) { // don't alter part while wheeling
@@ -417,25 +405,48 @@ QString Message822Widget::quoteMe() const
return quoteMeHelper(children());
}
-#define IMPL_RELOAD(CLASS) void CLASS::reloadContents() \
+#define IMPL_PART_FORWARD_ONE_METHOD(CLASS, METHOD) \
+void CLASS::METHOD() \
{\
/*qDebug() << metaObject()->className() << children().size();*/\
Q_FOREACH( QObject* const obj, children() ) {\
/*qDebug() << obj->metaObject()->className();*/\
AbstractPartWidget* w = dynamic_cast<AbstractPartWidget*>( obj );\
if ( w ) {\
- /*qDebug() << "reloadContents:" << w;*/\
- w->reloadContents();\
+ /*qDebug() << METHOD ":" << w;*/\
+ w->METHOD();\
}\
}\
}
-IMPL_RELOAD(MultipartSignedEncryptedWidget)
-IMPL_RELOAD(GenericMultipartWidget)
-IMPL_RELOAD(Message822Widget)
+#define IMPL_PART_FORWARDED_METHODS(CLASS) \
+ IMPL_PART_FORWARD_ONE_METHOD(CLASS, reloadContents) \
+ IMPL_PART_FORWARD_ONE_METHOD(CLASS, zoomIn) \
+ IMPL_PART_FORWARD_ONE_METHOD(CLASS, zoomOut) \
+ IMPL_PART_FORWARD_ONE_METHOD(CLASS, zoomOriginal)
+
+IMPL_PART_FORWARDED_METHODS(MultipartSignedEncryptedWidget)
+IMPL_PART_FORWARDED_METHODS(GenericMultipartWidget)
+IMPL_PART_FORWARDED_METHODS(Message822Widget)
+
+#undef IMPL_PART_FORWARD_ONE_METHOD
+#define IMPL_PART_FORWARD_ONE_METHOD(CLASS, METHOD) \
+void CLASS::METHOD() \
+{\
+ if (count()) { \
+ for (int i = 0; i < count(); ++i) { \
+ AbstractPartWidget *w = dynamic_cast<AbstractPartWidget *>(widget(i)); \
+ if (w) { \
+ w->METHOD(); \
+ } \
+ } \
+ } \
+}
-#undef IMPL_RELOAD
+IMPL_PART_FORWARDED_METHODS(MultipartAlternativeWidget)
+#undef IMPL_PART_FORWARD_ONE_METHOD
+#undef IMPL_PART_FORWARDED_METHODS
}
diff --git a/src/Gui/PartWidget.h b/src/Gui/PartWidget.h
index 3709d75..4712132 100644
--- a/src/Gui/PartWidget.h
+++ b/src/Gui/PartWidget.h
@@ -45,10 +45,13 @@ public:
MultipartAlternativeWidget(QWidget *parent, PartWidgetFactory *factory,
const QModelIndex &partIndex,
const int recursionDepth, const UiUtils::PartLoadingOptions options);
- virtual QString quoteMe() const;
- virtual void reloadContents();
+ virtual QString quoteMe() const override;
+ virtual void reloadContents() override;
+ virtual void zoomIn() override;
+ virtual void zoomOut() override;
+ virtual void zoomOriginal() override;
protected:
- bool eventFilter(QObject *o, QEvent *e);
+ bool eventFilter(QObject *o, QEvent *e) override;
};
/** @short Widget to display status information when processing message parts */
@@ -107,6 +110,9 @@ public:
const UiUtils::PartLoadingOptions loadingOptions);
virtual QString quoteMe() const override;
virtual void reloadContents() override;
+ virtual void zoomIn() override;
+ virtual void zoomOut() override;
+ virtual void zoomOriginal() override;
protected slots:
virtual void updateStatusIndicator() override;
protected:
@@ -121,8 +127,11 @@ public:
GenericMultipartWidget(QWidget *parent, PartWidgetFactory *factory,
const QModelIndex &partIndex, const int recursionDepth,
const UiUtils::PartLoadingOptions loadingOptions);
- virtual QString quoteMe() const;
- virtual void reloadContents();
+ virtual QString quoteMe() const override;
+ virtual void reloadContents() override;
+ virtual void zoomIn() override;
+ virtual void zoomOut() override;
+ virtual void zoomOriginal() override;
};
/** @short Message quoting support for generic multipart/ * */
@@ -133,8 +142,11 @@ public:
Message822Widget(QWidget *parent, PartWidgetFactory *factory,
const QModelIndex &partIndex, const int recursionDepth,
const UiUtils::PartLoadingOptions loadingOptions);
- virtual QString quoteMe() const;
- virtual void reloadContents();
+ virtual QString quoteMe() const override;
+ virtual void reloadContents() override;
+ virtual void zoomIn() override;
+ virtual void zoomOut() override;
+ virtual void zoomOriginal() override;
};
diff --git a/src/Gui/SimplePartWidget.cpp b/src/Gui/SimplePartWidget.cpp
index c9b388f..e9f8592 100644
--- a/src/Gui/SimplePartWidget.cpp
+++ b/src/Gui/SimplePartWidget.cpp
@@ -25,6 +25,7 @@
#include <QMenu>
#include <QNetworkReply>
#include <QWebFrame>
+#include <QWheelEvent>
#include "SimplePartWidget.h"
#include "Common/MetaTypes.h"
@@ -84,20 +85,6 @@ SimplePartWidget::SimplePartWidget(QWidget *parent, Imap::Network::MsgPartNetAcc
connect(m_findAction, &QAction::triggered, this, &SimplePartWidget::searchDialogRequested);
addAction(m_findAction);
- m_zoomIn = new QAction(UiUtils::loadIcon(QStringLiteral("zoom-in")), tr("Zoom In"), this);
- m_zoomIn->setShortcut(QKeySequence::ZoomIn);
- addAction(m_zoomIn);
- connect(m_zoomIn, &QAction::triggered, this, &SimplePartWidget::zoomIn);
-
- m_zoomOut = new QAction(UiUtils::loadIcon(QStringLiteral("zoom-out")), tr("Zoom Out"), this);
- m_zoomOut->setShortcut(QKeySequence::ZoomOut);
- addAction(m_zoomOut);
- connect(m_zoomOut, &QAction::triggered, this, &SimplePartWidget::zoomOut);
-
- m_zoomReset = new QAction(UiUtils::loadIcon(QStringLiteral("zoom-original")), tr("Original Size"), this);
- addAction(m_zoomReset);
- connect(m_zoomReset, &QAction::triggered, this, [this]() { setZoomFactor(1); });
-
setContextMenuPolicy(Qt::CustomContextMenu);
// It is actually OK to construct this widget without any connection to a messageView -- this is often used when
@@ -154,6 +141,26 @@ void SimplePartWidget::reloadContents()
EmbeddedWebView::reload();
}
+const auto zoomConstant = 1.1;
+
+void SimplePartWidget::zoomIn()
+{
+ setZoomFactor(zoomFactor() * zoomConstant);
+ constrainSize();
+}
+
+void SimplePartWidget::zoomOut()
+{
+ setZoomFactor(zoomFactor() / zoomConstant);
+ constrainSize();
+}
+
+void SimplePartWidget::zoomOriginal()
+{
+ setZoomFactor(1);
+ constrainSize();
+}
+
void SimplePartWidget::buildContextMenu(const QPoint &point, QMenu &menu) const
{
menu.addAction(m_findAction);
@@ -193,9 +200,22 @@ void SimplePartWidget::buildContextMenu(const QPoint &point, QMenu &menu) const
}
auto zoomMenu = menu.addMenu(UiUtils::loadIcon(QStringLiteral("zoom")), tr("Zoom"));
- zoomMenu->addAction(m_zoomIn);
- zoomMenu->addAction(m_zoomOut);
- zoomMenu->addAction(m_zoomReset);
+ if (m_messageView) {
+ zoomMenu->addAction(m_messageView->m_zoomIn);
+ zoomMenu->addAction(m_messageView->m_zoomOut);
+ zoomMenu->addAction(m_messageView->m_zoomOriginal);
+ } else {
+ auto zoomIn = zoomMenu->addAction(UiUtils::loadIcon(QStringLiteral("zoom-in")), tr("Zoom In"));
+ zoomIn->setShortcut(QKeySequence::ZoomIn);
+ connect(zoomIn, &QAction::triggered, this, &SimplePartWidget::zoomIn);
+
+ auto zoomOut = zoomMenu->addAction(UiUtils::loadIcon(QStringLiteral("zoom-out")), tr("Zoom Out"));
+ zoomOut->setShortcut(QKeySequence::ZoomOut);
+ connect(zoomOut, &QAction::triggered, this, &SimplePartWidget::zoomOut);
+
+ auto zoomOriginal = zoomMenu->addAction(UiUtils::loadIcon(QStringLiteral("zoom-original")), tr("Original Size"));
+ connect(zoomOriginal, &QAction::triggered, this, &SimplePartWidget::zoomOriginal);
+ }
}
void SimplePartWidget::slotDownloadPart()
diff --git a/src/Gui/SimplePartWidget.h b/src/Gui/SimplePartWidget.h
index 7c6f12d..d04370c 100644
--- a/src/Gui/SimplePartWidget.h
+++ b/src/Gui/SimplePartWidget.h
@@ -57,8 +57,11 @@ class SimplePartWidget : public EmbeddedWebView, public AbstractPartWidget
public:
SimplePartWidget(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager, const QModelIndex &partIndex,
MessageView *messageView);
- virtual QString quoteMe() const;
- virtual void reloadContents();
+ virtual QString quoteMe() const override;
+ virtual void reloadContents() override;
+ virtual void zoomIn() override;
+ virtual void zoomOut() override;
+ virtual void zoomOriginal() override;
void buildContextMenu(const QPoint &point, QMenu &menu) const;
private slots:
void slotFileNameRequested(QString *fileName);
@@ -66,6 +69,7 @@ private slots:
void slotDownloadPart();
void slotDownloadMessage();
void slotDownloadImage(const QNetworkRequest &req);
+protected:
signals:
void linkHovered(const QString &link, const QString &title, const QString &textContent);
void searchDialogRequested();
@@ -74,7 +78,6 @@ private:
QAction *m_savePart;
QAction *m_saveMessage;
QAction *m_findAction;
- QAction *m_zoomIn, *m_zoomOut, *m_zoomReset;
MessageView *m_messageView;
Imap::Network::MsgPartNetAccessManager *m_netAccessManager;
More information about the kde-doc-english
mailing list