forked from qt-creator/qt-creator
Help viewer: Add option for scroll wheel zooming
Fixes: QTCREATORBUG-14154 Change-Id: Ia6c4aedb78954614477f0228ba82c4dc476a2525 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -119,6 +119,9 @@ QWidget *GeneralSettingsPage::widget()
|
|||||||
|
|
||||||
m_returnOnClose = LocalHelpManager::returnOnClose();
|
m_returnOnClose = LocalHelpManager::returnOnClose();
|
||||||
m_ui->m_returnOnClose->setChecked(m_returnOnClose);
|
m_ui->m_returnOnClose->setChecked(m_returnOnClose);
|
||||||
|
|
||||||
|
m_scrollWheelZoomingEnabled = LocalHelpManager::isScrollWheelZoomingEnabled();
|
||||||
|
m_ui->scrollWheelZooming->setChecked(m_scrollWheelZoomingEnabled);
|
||||||
}
|
}
|
||||||
return m_widget;
|
return m_widget;
|
||||||
}
|
}
|
||||||
@@ -159,6 +162,12 @@ void GeneralSettingsPage::apply()
|
|||||||
m_returnOnClose = close;
|
m_returnOnClose = close;
|
||||||
LocalHelpManager::setReturnOnClose(m_returnOnClose);
|
LocalHelpManager::setReturnOnClose(m_returnOnClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool zoom = m_ui->scrollWheelZooming->isChecked();
|
||||||
|
if (m_scrollWheelZoomingEnabled != zoom) {
|
||||||
|
m_scrollWheelZoomingEnabled = zoom;
|
||||||
|
LocalHelpManager::setScrollWheelZoomingEnabled(m_scrollWheelZoomingEnabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralSettingsPage::setCurrentPage()
|
void GeneralSettingsPage::setCurrentPage()
|
||||||
|
@@ -69,6 +69,7 @@ private:
|
|||||||
|
|
||||||
int m_startOption;
|
int m_startOption;
|
||||||
bool m_returnOnClose;
|
bool m_returnOnClose;
|
||||||
|
bool m_scrollWheelZoomingEnabled;
|
||||||
|
|
||||||
QPointer<QWidget> m_widget;
|
QPointer<QWidget> m_widget;
|
||||||
Ui::GeneralSettingsPage *m_ui = nullptr;
|
Ui::GeneralSettingsPage *m_ui = nullptr;
|
||||||
|
@@ -288,6 +288,13 @@
|
|||||||
<string>Behaviour</string>
|
<string>Behaviour</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="scrollWheelZooming">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable scroll wheel zooming</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="m_returnOnClose">
|
<widget class="QCheckBox" name="m_returnOnClose">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
|
@@ -495,6 +495,9 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
|
|||||||
|
|
||||||
// initialize zoom
|
// initialize zoom
|
||||||
viewer->setScale(zoom);
|
viewer->setScale(zoom);
|
||||||
|
viewer->setScrollWheelZoomingEnabled(LocalHelpManager::isScrollWheelZoomingEnabled());
|
||||||
|
connect(LocalHelpManager::instance(), &LocalHelpManager::scrollWheelZoomingEnabledChanged,
|
||||||
|
viewer, &HelpViewer::setScrollWheelZoomingEnabled);
|
||||||
|
|
||||||
// add find support
|
// add find support
|
||||||
auto agg = new Aggregation::Aggregate;
|
auto agg = new Aggregation::Aggregate;
|
||||||
|
@@ -91,6 +91,16 @@ HelpViewer::~HelpViewer()
|
|||||||
restoreOverrideCursor();
|
restoreOverrideCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HelpViewer::setScrollWheelZoomingEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
m_scrollWheelZoomingEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HelpViewer::isScrollWheelZoomingEnabled() const
|
||||||
|
{
|
||||||
|
return m_scrollWheelZoomingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
void HelpViewer::setActionVisible(Action action, bool visible)
|
void HelpViewer::setActionVisible(Action action, bool visible)
|
||||||
{
|
{
|
||||||
if (visible)
|
if (visible)
|
||||||
@@ -162,6 +172,16 @@ void HelpViewer::home()
|
|||||||
setSource(LocalHelpManager::homePage());
|
setSource(LocalHelpManager::homePage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HelpViewer::wheelEvent(QWheelEvent *event)
|
||||||
|
{
|
||||||
|
if (m_scrollWheelZoomingEnabled && event->modifiers() == Qt::ControlModifier) {
|
||||||
|
event->accept();
|
||||||
|
event->delta() > 0 ? scaleUp() : scaleDown();
|
||||||
|
} else {
|
||||||
|
QWidget::wheelEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HelpViewer::slotLoadStarted()
|
void HelpViewer::slotLoadStarted()
|
||||||
{
|
{
|
||||||
++m_loadOverrideStack;
|
++m_loadOverrideStack;
|
||||||
|
@@ -57,6 +57,9 @@ public:
|
|||||||
virtual qreal scale() const = 0;
|
virtual qreal scale() const = 0;
|
||||||
virtual void setScale(qreal scale) = 0;
|
virtual void setScale(qreal scale) = 0;
|
||||||
|
|
||||||
|
void setScrollWheelZoomingEnabled(bool enabled);
|
||||||
|
bool isScrollWheelZoomingEnabled() const;
|
||||||
|
|
||||||
virtual QString title() const = 0;
|
virtual QString title() const = 0;
|
||||||
|
|
||||||
virtual QUrl source() const = 0;
|
virtual QUrl source() const = 0;
|
||||||
@@ -105,12 +108,15 @@ signals:
|
|||||||
void externalPageRequested(const QUrl &url);
|
void externalPageRequested(const QUrl &url);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
|
||||||
void slotLoadStarted();
|
void slotLoadStarted();
|
||||||
void slotLoadFinished();
|
void slotLoadFinished();
|
||||||
|
|
||||||
void restoreOverrideCursor();
|
void restoreOverrideCursor();
|
||||||
|
|
||||||
Actions m_visibleActions;
|
Actions m_visibleActions;
|
||||||
|
bool m_scrollWheelZoomingEnabled = true;
|
||||||
int m_loadOverrideStack = 0;
|
int m_loadOverrideStack = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -65,6 +65,7 @@ static const char kFontSizeKey[] = "Help/FallbackFontSize";
|
|||||||
static const char kStartOptionKey[] = "Help/StartOption";
|
static const char kStartOptionKey[] = "Help/StartOption";
|
||||||
static const char kContextHelpOptionKey[] = "Help/ContextHelpOption";
|
static const char kContextHelpOptionKey[] = "Help/ContextHelpOption";
|
||||||
static const char kReturnOnCloseKey[] = "Help/ReturnOnClose";
|
static const char kReturnOnCloseKey[] = "Help/ReturnOnClose";
|
||||||
|
static const char kUseScrollWheelZooming[] = "Help/UseScrollWheelZooming";
|
||||||
static const char kLastShownPagesKey[] = "Help/LastShownPages";
|
static const char kLastShownPagesKey[] = "Help/LastShownPages";
|
||||||
static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom";
|
static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom";
|
||||||
static const char kLastSelectedTabKey[] = "Help/LastSelectedTab";
|
static const char kLastSelectedTabKey[] = "Help/LastSelectedTab";
|
||||||
@@ -225,6 +226,17 @@ void LocalHelpManager::setReturnOnClose(bool returnOnClose)
|
|||||||
emit m_instance->returnOnCloseChanged();
|
emit m_instance->returnOnCloseChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LocalHelpManager::isScrollWheelZoomingEnabled()
|
||||||
|
{
|
||||||
|
return Core::ICore::settings()->value(kUseScrollWheelZooming, true).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalHelpManager::setScrollWheelZoomingEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
Core::ICore::settings()->setValue(kUseScrollWheelZooming, enabled);
|
||||||
|
emit m_instance->scrollWheelZoomingEnabledChanged(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList LocalHelpManager::lastShownPages()
|
QStringList LocalHelpManager::lastShownPages()
|
||||||
{
|
{
|
||||||
const QVariant value = Core::ICore::settings()->value(kLastShownPagesKey, QVariant());
|
const QVariant value = Core::ICore::settings()->value(kLastShownPagesKey, QVariant());
|
||||||
|
@@ -78,6 +78,9 @@ public:
|
|||||||
static bool returnOnClose();
|
static bool returnOnClose();
|
||||||
static void setReturnOnClose(bool returnOnClose);
|
static void setReturnOnClose(bool returnOnClose);
|
||||||
|
|
||||||
|
static bool isScrollWheelZoomingEnabled();
|
||||||
|
static void setScrollWheelZoomingEnabled(bool enabled);
|
||||||
|
|
||||||
static QStringList lastShownPages();
|
static QStringList lastShownPages();
|
||||||
static void setLastShownPages(const QStringList &pages);
|
static void setLastShownPages(const QStringList &pages);
|
||||||
|
|
||||||
@@ -106,6 +109,7 @@ signals:
|
|||||||
void filterIndexChanged(int index);
|
void filterIndexChanged(int index);
|
||||||
void fallbackFontChanged(const QFont &font);
|
void fallbackFontChanged(const QFont &font);
|
||||||
void returnOnCloseChanged();
|
void returnOnCloseChanged();
|
||||||
|
void scrollWheelZoomingEnabledChanged(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool m_guiNeedsSetup;
|
static bool m_guiNeedsSetup;
|
||||||
|
@@ -406,16 +406,6 @@ bool TextBrowserHelpWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
return QTextBrowser::eventFilter(obj, event);
|
return QTextBrowser::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBrowserHelpWidget::wheelEvent(QWheelEvent *e)
|
|
||||||
{
|
|
||||||
if (e->modifiers() == Qt::ControlModifier) {
|
|
||||||
e->accept();
|
|
||||||
e->delta() > 0 ? scaleUp() : scaleDown();
|
|
||||||
} else {
|
|
||||||
QTextBrowser::wheelEvent(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBrowserHelpWidget::mousePressEvent(QMouseEvent *e)
|
void TextBrowserHelpWidget::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
if (Utils::HostOsInfo::isLinuxHost() && m_parent->handleForwardBackwardMouseButtons(e))
|
if (Utils::HostOsInfo::isLinuxHost() && m_parent->handleForwardBackwardMouseButtons(e))
|
||||||
|
@@ -98,7 +98,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
void wheelEvent(QWheelEvent *e) override;
|
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
|
@@ -292,6 +292,31 @@ WebView::WebView(WebEngineHelpViewer *viewer)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebView::event(QEvent *ev)
|
||||||
|
{
|
||||||
|
// work around QTBUG-43602
|
||||||
|
if (ev->type() == QEvent::ChildAdded) {
|
||||||
|
auto ce = static_cast<QChildEvent *>(ev);
|
||||||
|
ce->child()->installEventFilter(this);
|
||||||
|
} else if (ev->type() == QEvent::ChildRemoved) {
|
||||||
|
auto ce = static_cast<QChildEvent *>(ev);
|
||||||
|
ce->child()->removeEventFilter(this);
|
||||||
|
}
|
||||||
|
return QWebEngineView::event(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebView::eventFilter(QObject *src, QEvent *e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(src)
|
||||||
|
// work around QTBUG-43602
|
||||||
|
if (m_viewer->isScrollWheelZoomingEnabled() && e->type() == QEvent::Wheel) {
|
||||||
|
auto we = static_cast<QWheelEvent *>(e);
|
||||||
|
if (we->modifiers() == Qt::ControlModifier)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void WebView::contextMenuEvent(QContextMenuEvent *event)
|
void WebView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QMenu *menu = page()->createStandardContextMenu();
|
QMenu *menu = page()->createStandardContextMenu();
|
||||||
|
@@ -53,6 +53,9 @@ class WebView : public QWebEngineView
|
|||||||
public:
|
public:
|
||||||
explicit WebView(WebEngineHelpViewer *viewer);
|
explicit WebView(WebEngineHelpViewer *viewer);
|
||||||
|
|
||||||
|
bool event(QEvent *ev) override;
|
||||||
|
bool eventFilter(QObject *src, QEvent *e) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user