Blame toonz/sources/include/toonzqt/glwidget_for_highdpi.h
|
shun_iwasawa |
7c988d |
#pragma once
|
|
shun_iwasawa |
7c988d |
|
|
shun_iwasawa |
7c988d |
#ifndef GLWIDGET_FOR_HIGHDPI_H
|
|
shun_iwasawa |
7c988d |
#define GLWIDGET_FOR_HIGHDPI_H
|
|
shun_iwasawa |
7c988d |
|
|
Jeremy Bullock |
d165bb |
#include <qopenglwidget></qopenglwidget>
|
|
shun_iwasawa |
7c988d |
#include <qapplication></qapplication>
|
|
shun_iwasawa |
7c988d |
#include <qdesktopwidget></qdesktopwidget>
|
|
shun_iwasawa |
7c988d |
|
|
shun_iwasawa |
7c988d |
// use obsolete QGLWidget instead of QOpenGLWidget for now...
|
|
shun_iwasawa |
7c988d |
// TODO: replace with the "modern" OpenGL source and transfer to QOpenGLWidget
|
|
Jeremy Bullock |
d165bb |
class GLWidgetForHighDpi : public QOpenGLWidget {
|
|
shun_iwasawa |
7c988d |
public:
|
|
shun_iwasawa |
7c988d |
GLWidgetForHighDpi(QWidget *parent = Q_NULLPTR,
|
|
Jeremy Bullock |
d165bb |
const QOpenGLWidget *shareWidget = Q_NULLPTR,
|
|
shun_iwasawa |
7c988d |
Qt::WindowFlags f = Qt::WindowFlags())
|
|
Jeremy Bullock |
d165bb |
: QOpenGLWidget(parent, f) {}
|
|
shun_iwasawa |
7c988d |
|
|
shun_iwasawa |
f01305 |
// returns device-pixel ratio. It is 1 for normal monitors and 2 (or higher
|
|
shun_iwasawa |
f01305 |
// ratio) for high DPI monitors. Setting "Display > Set custom text size(DPI)"
|
|
shun_iwasawa |
f01305 |
// for Windows corresponds to this ratio.
|
|
shun_iwasawa |
7c988d |
int getDevPixRatio() const {
|
|
shun_iwasawa |
7c988d |
static int devPixRatio = QApplication::desktop()->devicePixelRatio();
|
|
shun_iwasawa |
7c988d |
return devPixRatio;
|
|
shun_iwasawa |
7c988d |
}
|
|
shun_iwasawa |
7c988d |
// modify sizes for high DPI monitors
|
|
Jeremy Bullock |
d165bb |
int width() const { return QOpenGLWidget::width() * getDevPixRatio(); }
|
|
Jeremy Bullock |
d165bb |
int height() const { return QOpenGLWidget::height() * getDevPixRatio(); }
|
|
shun_iwasawa |
7c988d |
QRect rect() const { return QRect(0, 0, width(), height()); }
|
|
shun_iwasawa |
7c988d |
};
|
|
shun_iwasawa |
7c988d |
|
|
shun_iwasawa |
7c988d |
#endif
|