Skip to content

Commit

Permalink
Enable high dpi scaling (#7437)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed May 5, 2021
1 parent 9ebba11 commit 203aa2f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/main.cpp
Expand Up @@ -171,6 +171,9 @@ int main(int argc, char *argv[])
}
}
Q_INIT_RESOURCE(resource_omedit);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
OMEditApplication a(argc, argv, threadData);
return a.exec();

Expand Down
23 changes: 13 additions & 10 deletions OMEdit/OMEditLIB/Animation/ViewerWidget.cpp
Expand Up @@ -38,6 +38,8 @@
#include <QColorDialog>
#include <QKeyEvent>
#include <cassert>
#include <QtMath>
#include <QApplication>

#include "ViewerWidget.h"
#include "Modeling/MessagesWidget.h"
Expand Down Expand Up @@ -85,17 +87,14 @@ ViewerWidget::ViewerWidget(QWidget* parent, Qt::WindowFlags flags)
mpViewer = new Viewer;
mpSceneView = new osgViewer::View();
mpAnimationWidget = qobject_cast<AbstractAnimationWindow*>(parent);
// widget resolution
int height = rect().height();
int width = rect().width();
// add a scene to viewer
mpViewer->addView(mpSceneView);
// get the viewer widget
osg::ref_ptr<osg::Camera> camera = mpSceneView->getCamera();
camera->setGraphicsContext(mpGraphicsWindow);
camera->setClearColor(osg::Vec4(0.95, 0.95, 0.95, 1.0));
camera->setViewport(new osg::Viewport(0, 0, width, height));
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width/2) / static_cast<double>(height/2), 1.0f, 10000.0f);
camera->setViewport(new osg::Viewport(0, 0, width(), height()));
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width()/2) / static_cast<double>(height()/2), 1.0f, 10000.0f);
mpSceneView->addEventHandler(new osgViewer::StatsHandler());
// reverse the mouse wheel zooming
osgGA::MultiTouchTrackballManipulator *pMultiTouchTrackballManipulator = new osgGA::MultiTouchTrackballManipulator();
Expand Down Expand Up @@ -150,8 +149,9 @@ void ViewerWidget::paintGL()
*/
void ViewerWidget::resizeGL(int width, int height)
{
getEventQueue()->windowResize(x(), y(), width, height);
mpGraphicsWindow->resized(x(), y(), width, height);
int pixelRatio = qCeil(qApp->devicePixelRatio());
getEventQueue()->windowResize(x() * pixelRatio, y() * pixelRatio, width * pixelRatio, height * pixelRatio);
mpGraphicsWindow->resized(x() * pixelRatio, y() * pixelRatio, width * pixelRatio, height * pixelRatio);
}

/*!
Expand Down Expand Up @@ -185,7 +185,8 @@ void ViewerWidget::keyReleaseEvent(QKeyEvent *event)
*/
void ViewerWidget::mouseMoveEvent(QMouseEvent *event)
{
getEventQueue()->mouseMotion(static_cast<float>(event->x()), static_cast<float>(event->y()));
int pixelRatio = qCeil(qApp->devicePixelRatio());
getEventQueue()->mouseMotion(static_cast<float>(event->x() * pixelRatio), static_cast<float>(event->y() * pixelRatio));
}

/*!
Expand Down Expand Up @@ -218,7 +219,8 @@ void ViewerWidget::mousePressEvent(QMouseEvent *event)
default:
break;
}
getEventQueue()->mouseButtonPress(static_cast<float>(event->x()), static_cast<float>(event->y()), button);
int pixelRatio = qCeil(qApp->devicePixelRatio());
getEventQueue()->mouseButtonPress(static_cast<float>(event->x() * pixelRatio), static_cast<float>(event->y() * pixelRatio), button);
}

/*!
Expand Down Expand Up @@ -491,7 +493,8 @@ void ViewerWidget::mouseReleaseEvent(QMouseEvent *event)
default:
break;
}
getEventQueue()->mouseButtonRelease(static_cast<float>(event->x()), static_cast<float>(event->y()), button);
int pixelRatio = qCeil(qApp->devicePixelRatio());
getEventQueue()->mouseButtonRelease(static_cast<float>(event->x() * pixelRatio), static_cast<float>(event->y() * pixelRatio), button);
}

/*!
Expand Down
10 changes: 2 additions & 8 deletions OMEdit/OMEditLIB/Modeling/DocumentationWidget.cpp
Expand Up @@ -1204,17 +1204,11 @@ void DocumentationViewer::createActions()

/*!
* \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.
* Resets the zoom.
*/
void DocumentationViewer::resetZoom()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
qreal zoomFactor = QApplication::primaryScreen()->logicalDotsPerInchX() / 96;
#else // QT_VERSION_CHECK
qreal zoomFactor = QApplication::desktop()->screen()->logicalDpiX() / 96;
#endif // QT_VERSION_CHECK
setZoomFactor(zoomFactor < 1 ? 1 : zoomFactor);
setZoomFactor(1.0);
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3989,7 +3989,7 @@ WelcomePageWidget::WelcomePageWidget(QWidget *pParent)
QHBoxLayout *topFrameLayout = new QHBoxLayout;
topFrameLayout->setAlignment(Qt::AlignLeft);
topFrameLayout->addWidget(mpPixmapLabel);
topFrameLayout->addWidget(mpHeadingLabel);
topFrameLayout->addWidget(mpHeadingLabel, 1);
mpTopFrame->setLayout(topFrameLayout);
// RecentFiles Frame
mpRecentFilesFrame = new QFrame;
Expand Down
3 changes: 1 addition & 2 deletions OMEdit/OMEditLIB/OMEditApplication.cpp
Expand Up @@ -69,8 +69,7 @@ OMEditApplication::OMEditApplication(int &argc, char **argv, threadData_t* threa
//*a.severin/ add localization
const char *installationDirectoryPath = SettingsImpl__getInstallationDirectoryPath();
if (!installationDirectoryPath) {
QMessageBox::critical(0, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::INSTALLATIONDIRECTORY_NOT_FOUND), Helper::ok);
QMessageBox::critical(0, QString("%1 - %2").arg(Helper::applicationName, Helper::error), GUIMessages::getMessage(GUIMessages::INSTALLATIONDIRECTORY_NOT_FOUND), Helper::ok);
quit();
exit(1);
}
Expand Down

0 comments on commit 203aa2f

Please sign in to comment.