Skip to content

Commit

Permalink
ticket:4156 Find a proper base zoom factor for documentation browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Dec 1, 2016
1 parent 6e46b93 commit 30ec275
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions OMEdit/OMEditGUI/Modeling/DocumentationWidget.cpp
Expand Up @@ -46,6 +46,8 @@
#include <QNetworkReply>
#include <QMenu>
#include <QDesktopServices>
#include <QApplication>
#include <QDesktopWidget>

/*!
* \class DocumentationWidget
Expand Down Expand Up @@ -452,8 +454,7 @@ DocumentationViewer::DocumentationViewer(DocumentationWidget *pParent)
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
mpDocumentationWidget = pParent;
mZoomFactor = 1.;
setZoomFactor(mZoomFactor);
resetZoom();
// set DocumentationViewer settings
settings()->setFontFamily(QWebSettings::StandardFont, Helper::systemFontInfo.family());
settings()->setFontSize(QWebSettings::DefaultFontSize, Helper::systemFontInfo.pointSize());
Expand All @@ -475,6 +476,17 @@ void DocumentationViewer::createActions()
page()->action(QWebPage::Copy)->setShortcut(QKeySequence("Ctrl+c"));
}

/*!
* \brief DocumentationViewer::resetZoom
* Resets the zoom. \n
* QWebView seems to be using fixed 96 dpi so set a proper base zoomfactor for high resolution screens.
*/
void DocumentationViewer::resetZoom()
{
QWidget *pScreenWidget = QApplication::desktop()->screen();
setZoomFactor(pScreenWidget->logicalDpiX() / 96);
}

/*!
* \brief DocumentationViewer::processLinkClick
* \param url
Expand Down Expand Up @@ -611,10 +623,11 @@ void DocumentationViewer::keyPressEvent(QKeyEvent *event)
void DocumentationViewer::wheelEvent(QWheelEvent *event)
{
if (event->orientation() == Qt::Vertical && event->modifiers().testFlag(Qt::ControlModifier)) {
mZoomFactor+=event->delta()/120.;
if (mZoomFactor > 5.) mZoomFactor = 5.;
if (mZoomFactor < .1) mZoomFactor = .1;
setZoomFactor(mZoomFactor);
qreal zf = zoomFactor();
zf += event->delta()/120.;
if (zf > 5.) zf = 5.;
if (zf < .1) zf = .1;
setZoomFactor(zf);
} else {
QWebView::wheelEvent(event);
}
Expand All @@ -629,8 +642,7 @@ void DocumentationViewer::wheelEvent(QWheelEvent *event)
void DocumentationViewer::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->modifiers().testFlag(Qt::ControlModifier)) {
mZoomFactor=1.;
setZoomFactor(mZoomFactor);
resetZoom();
} else {
QWebView::mouseDoubleClickEvent(event);
}
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/DocumentationWidget.h
Expand Up @@ -97,11 +97,11 @@ class DocumentationViewer : public QWebView
Q_OBJECT
private:
DocumentationWidget *mpDocumentationWidget;
qreal mZoomFactor;
public:
DocumentationViewer(DocumentationWidget *pParent);
private:
void createActions();
void resetZoom();
public slots:
void processLinkClick(QUrl url);
void requestFinished();
Expand Down

0 comments on commit 30ec275

Please sign in to comment.