Skip to content

Commit

Permalink
Merge pull request #5 from hkiel/omedit_documentation_zoom
Browse files Browse the repository at this point in the history
Implement zoom in DocumentationView with ctrl+scroll
  • Loading branch information
hkiel committed Dec 15, 2015
2 parents cd54849 + d939ff7 commit 309db77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions OMEdit/OMEditGUI/Modeling/DocumentationWidget.cpp
Expand Up @@ -192,6 +192,8 @@ DocumentationViewer::DocumentationViewer(DocumentationWidget *pParent)
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
mpDocumentationWidget = pParent;
zoomFact = 1.;
setZoomFactor(zoomFact);
// set DocumentationViewer settings
settings()->setFontFamily(QWebSettings::StandardFont, "Verdana");
settings()->setFontSize(QWebSettings::DefaultFontSize, 10);
Expand Down Expand Up @@ -297,15 +299,52 @@ void DocumentationViewer::keyPressEvent(QKeyEvent *event)
if (event->modifiers().testFlag(Qt::ShiftModifier) && event->key() == Qt::Key_Backspace)
{
if (mpDocumentationWidget->getNextToolButton()->isEnabled())
{
mpDocumentationWidget->nextDocumentation();
}
}
else if (event->key() == Qt::Key_Backspace)
{
if (mpDocumentationWidget->getPreviousToolButton()->isEnabled())
{
mpDocumentationWidget->previousDocumentation();
}
}
else
{
QWebView::keyPressEvent(event);
}
}

//! Reimplementation of wheelevent.
//! Defines what to do for control+scrolling the wheel
void DocumentationViewer::wheelEvent(QWheelEvent *event)
{
if (event->orientation() == Qt::Vertical && event->modifiers().testFlag(Qt::ControlModifier))
{
zoomFact+=event->delta()/120.;
if (zoomFact > 5.) zoomFact = 5.;
if (zoomFact < .1) zoomFact = .1;
setZoomFactor(zoomFact);
}
else
{
QWebView::wheelEvent(event);
}
}

//! Reimplementation of mousedoubleclickevent.
//! Defines what to do for control+doubleclick
void DocumentationViewer::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->modifiers().testFlag(Qt::ControlModifier))
{
zoomFact=1.;
setZoomFactor(zoomFact);
}
else
{
QWebView::mouseDoubleClickEvent(event);
}
}

3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Modeling/DocumentationWidget.h
Expand Up @@ -79,6 +79,7 @@ class DocumentationViewer : public QWebView
Q_OBJECT
private:
DocumentationWidget *mpDocumentationWidget;
qreal zoomFact;
public:
DocumentationViewer(DocumentationWidget *pParent);
public slots:
Expand All @@ -89,6 +90,8 @@ public slots:
protected:
virtual QWebView* createWindow(QWebPage::WebWindowType type);
virtual void keyPressEvent(QKeyEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
};

#endif // DOCUMENTATIONWIDGET_H

0 comments on commit 309db77

Please sign in to comment.