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_ui->m_returnOnClose->setChecked(m_returnOnClose);
|
||||
|
||||
m_scrollWheelZoomingEnabled = LocalHelpManager::isScrollWheelZoomingEnabled();
|
||||
m_ui->scrollWheelZooming->setChecked(m_scrollWheelZoomingEnabled);
|
||||
}
|
||||
return m_widget;
|
||||
}
|
||||
@@ -159,6 +162,12 @@ void GeneralSettingsPage::apply()
|
||||
m_returnOnClose = close;
|
||||
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()
|
||||
|
@@ -69,6 +69,7 @@ private:
|
||||
|
||||
int m_startOption;
|
||||
bool m_returnOnClose;
|
||||
bool m_scrollWheelZoomingEnabled;
|
||||
|
||||
QPointer<QWidget> m_widget;
|
||||
Ui::GeneralSettingsPage *m_ui = nullptr;
|
||||
|
@@ -288,6 +288,13 @@
|
||||
<string>Behaviour</string>
|
||||
</property>
|
||||
<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>
|
||||
<widget class="QCheckBox" name="m_returnOnClose">
|
||||
<property name="toolTip">
|
||||
|
@@ -495,6 +495,9 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
|
||||
|
||||
// initialize zoom
|
||||
viewer->setScale(zoom);
|
||||
viewer->setScrollWheelZoomingEnabled(LocalHelpManager::isScrollWheelZoomingEnabled());
|
||||
connect(LocalHelpManager::instance(), &LocalHelpManager::scrollWheelZoomingEnabledChanged,
|
||||
viewer, &HelpViewer::setScrollWheelZoomingEnabled);
|
||||
|
||||
// add find support
|
||||
auto agg = new Aggregation::Aggregate;
|
||||
|
@@ -91,6 +91,16 @@ HelpViewer::~HelpViewer()
|
||||
restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void HelpViewer::setScrollWheelZoomingEnabled(bool enabled)
|
||||
{
|
||||
m_scrollWheelZoomingEnabled = enabled;
|
||||
}
|
||||
|
||||
bool HelpViewer::isScrollWheelZoomingEnabled() const
|
||||
{
|
||||
return m_scrollWheelZoomingEnabled;
|
||||
}
|
||||
|
||||
void HelpViewer::setActionVisible(Action action, bool visible)
|
||||
{
|
||||
if (visible)
|
||||
@@ -162,6 +172,16 @@ void HelpViewer::home()
|
||||
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()
|
||||
{
|
||||
++m_loadOverrideStack;
|
||||
|
@@ -57,6 +57,9 @@ public:
|
||||
virtual qreal scale() const = 0;
|
||||
virtual void setScale(qreal scale) = 0;
|
||||
|
||||
void setScrollWheelZoomingEnabled(bool enabled);
|
||||
bool isScrollWheelZoomingEnabled() const;
|
||||
|
||||
virtual QString title() const = 0;
|
||||
|
||||
virtual QUrl source() const = 0;
|
||||
@@ -105,12 +108,15 @@ signals:
|
||||
void externalPageRequested(const QUrl &url);
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
|
||||
void slotLoadStarted();
|
||||
void slotLoadFinished();
|
||||
|
||||
void restoreOverrideCursor();
|
||||
|
||||
Actions m_visibleActions;
|
||||
bool m_scrollWheelZoomingEnabled = true;
|
||||
int m_loadOverrideStack = 0;
|
||||
};
|
||||
|
||||
|
@@ -65,6 +65,7 @@ static const char kFontSizeKey[] = "Help/FallbackFontSize";
|
||||
static const char kStartOptionKey[] = "Help/StartOption";
|
||||
static const char kContextHelpOptionKey[] = "Help/ContextHelpOption";
|
||||
static const char kReturnOnCloseKey[] = "Help/ReturnOnClose";
|
||||
static const char kUseScrollWheelZooming[] = "Help/UseScrollWheelZooming";
|
||||
static const char kLastShownPagesKey[] = "Help/LastShownPages";
|
||||
static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom";
|
||||
static const char kLastSelectedTabKey[] = "Help/LastSelectedTab";
|
||||
@@ -225,6 +226,17 @@ void LocalHelpManager::setReturnOnClose(bool returnOnClose)
|
||||
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()
|
||||
{
|
||||
const QVariant value = Core::ICore::settings()->value(kLastShownPagesKey, QVariant());
|
||||
|
@@ -78,6 +78,9 @@ public:
|
||||
static bool returnOnClose();
|
||||
static void setReturnOnClose(bool returnOnClose);
|
||||
|
||||
static bool isScrollWheelZoomingEnabled();
|
||||
static void setScrollWheelZoomingEnabled(bool enabled);
|
||||
|
||||
static QStringList lastShownPages();
|
||||
static void setLastShownPages(const QStringList &pages);
|
||||
|
||||
@@ -106,6 +109,7 @@ signals:
|
||||
void filterIndexChanged(int index);
|
||||
void fallbackFontChanged(const QFont &font);
|
||||
void returnOnCloseChanged();
|
||||
void scrollWheelZoomingEnabledChanged(bool enabled);
|
||||
|
||||
private:
|
||||
static bool m_guiNeedsSetup;
|
||||
|
@@ -406,16 +406,6 @@ bool TextBrowserHelpWidget::eventFilter(QObject *obj, QEvent *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)
|
||||
{
|
||||
if (Utils::HostOsInfo::isLinuxHost() && m_parent->handleForwardBackwardMouseButtons(e))
|
||||
|
@@ -98,7 +98,6 @@ public:
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
void mousePressEvent(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)
|
||||
{
|
||||
QMenu *menu = page()->createStandardContextMenu();
|
||||
|
@@ -53,6 +53,9 @@ class WebView : public QWebEngineView
|
||||
public:
|
||||
explicit WebView(WebEngineHelpViewer *viewer);
|
||||
|
||||
bool event(QEvent *ev) override;
|
||||
bool eventFilter(QObject *src, QEvent *e) override;
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
|
||||
|
Reference in New Issue
Block a user