Skip to content

Commit 309db77

Browse files
committed
Merge pull request #5 from hkiel/omedit_documentation_zoom
Implement zoom in DocumentationView with ctrl+scroll
2 parents cd54849 + d939ff7 commit 309db77

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

OMEdit/OMEditGUI/Modeling/DocumentationWidget.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ DocumentationViewer::DocumentationViewer(DocumentationWidget *pParent)
192192
setContextMenuPolicy(Qt::CustomContextMenu);
193193
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
194194
mpDocumentationWidget = pParent;
195+
zoomFact = 1.;
196+
setZoomFactor(zoomFact);
195197
// set DocumentationViewer settings
196198
settings()->setFontFamily(QWebSettings::StandardFont, "Verdana");
197199
settings()->setFontSize(QWebSettings::DefaultFontSize, 10);
@@ -297,15 +299,52 @@ void DocumentationViewer::keyPressEvent(QKeyEvent *event)
297299
if (event->modifiers().testFlag(Qt::ShiftModifier) && event->key() == Qt::Key_Backspace)
298300
{
299301
if (mpDocumentationWidget->getNextToolButton()->isEnabled())
302+
{
300303
mpDocumentationWidget->nextDocumentation();
304+
}
301305
}
302306
else if (event->key() == Qt::Key_Backspace)
303307
{
304308
if (mpDocumentationWidget->getPreviousToolButton()->isEnabled())
309+
{
305310
mpDocumentationWidget->previousDocumentation();
311+
}
306312
}
307313
else
308314
{
309315
QWebView::keyPressEvent(event);
310316
}
311317
}
318+
319+
//! Reimplementation of wheelevent.
320+
//! Defines what to do for control+scrolling the wheel
321+
void DocumentationViewer::wheelEvent(QWheelEvent *event)
322+
{
323+
if (event->orientation() == Qt::Vertical && event->modifiers().testFlag(Qt::ControlModifier))
324+
{
325+
zoomFact+=event->delta()/120.;
326+
if (zoomFact > 5.) zoomFact = 5.;
327+
if (zoomFact < .1) zoomFact = .1;
328+
setZoomFactor(zoomFact);
329+
}
330+
else
331+
{
332+
QWebView::wheelEvent(event);
333+
}
334+
}
335+
336+
//! Reimplementation of mousedoubleclickevent.
337+
//! Defines what to do for control+doubleclick
338+
void DocumentationViewer::mouseDoubleClickEvent(QMouseEvent *event)
339+
{
340+
if (event->modifiers().testFlag(Qt::ControlModifier))
341+
{
342+
zoomFact=1.;
343+
setZoomFactor(zoomFact);
344+
}
345+
else
346+
{
347+
QWebView::mouseDoubleClickEvent(event);
348+
}
349+
}
350+

OMEdit/OMEditGUI/Modeling/DocumentationWidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class DocumentationViewer : public QWebView
7979
Q_OBJECT
8080
private:
8181
DocumentationWidget *mpDocumentationWidget;
82+
qreal zoomFact;
8283
public:
8384
DocumentationViewer(DocumentationWidget *pParent);
8485
public slots:
@@ -89,6 +90,8 @@ public slots:
8990
protected:
9091
virtual QWebView* createWindow(QWebPage::WebWindowType type);
9192
virtual void keyPressEvent(QKeyEvent *event);
93+
virtual void wheelEvent(QWheelEvent *event);
94+
virtual void mouseDoubleClickEvent(QMouseEvent *event);
9295
};
9396

9497
#endif // DOCUMENTATIONWIDGET_H

0 commit comments

Comments
 (0)