summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/qt-dpi.hpp19
-rw-r--r--spline/spline-widget.cpp9
-rw-r--r--spline/spline-widget.hpp5
-rw-r--r--video/video-widget.cpp6
-rw-r--r--video/video-widget.hpp3
5 files changed, 26 insertions, 16 deletions
diff --git a/compat/qt-dpi.hpp b/compat/qt-dpi.hpp
new file mode 100644
index 00000000..01659c8a
--- /dev/null
+++ b/compat/qt-dpi.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <algorithm>
+#include <QWidget>
+
+template<typename self>
+struct screen_dpi_mixin
+{
+protected:
+ double screen_dpi() const
+ {
+ const auto& x = *static_cast<const self*>(this);
+#ifdef _WIN32
+ return std::max(x.devicePixelRatioF(), 1.);
+#else
+ return std::max(std::max(x.logicalDpiX()/(double)x.physicalDpiX(), x.devicePixelRatioF()), 1.);
+#endif
+ }
+};
diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp
index 0ae3766d..e182e45a 100644
--- a/spline/spline-widget.cpp
+++ b/spline/spline-widget.cpp
@@ -258,15 +258,6 @@ void spline_widget::drawFunction()
}
}
-double spline_widget::screen_dpi() const
-{
-#ifdef _WIN32
- return std::max(devicePixelRatioF(), 1.);
-#else
- return std::max(std::max(logicalDpiX()/(double)physicalDpiX(), devicePixelRatioF()), 1.);
-#endif
-}
-
QSize spline_widget::minimumSizeHint() const
{
const double dpi = screen_dpi();
diff --git a/spline/spline-widget.hpp b/spline/spline-widget.hpp
index f1523361..610baf43 100644
--- a/spline/spline-widget.hpp
+++ b/spline/spline-widget.hpp
@@ -11,6 +11,7 @@
#include "spline.hpp"
#include "api/plugin-api.hpp"
+#include "compat/qt-dpi.hpp"
#include "options/options.hpp"
#include "export.hpp"
@@ -26,7 +27,7 @@ namespace spline_detail {
using namespace options;
-class OTR_SPLINE_EXPORT spline_widget final : public QWidget
+class OTR_SPLINE_EXPORT spline_widget final : public QWidget, public screen_dpi_mixin<spline_widget>
{
Q_OBJECT
Q_PROPERTY(QColor colorBezier READ colorBezier WRITE setColorBezier)
@@ -81,8 +82,6 @@ private:
void update_range();
void changeEvent(QEvent* e) override;
- double screen_dpi() const;
-
QPointF pixel_to_point(const QPointF& point);
QPointF point_to_pixel(const QPointF& point);
diff --git a/video/video-widget.cpp b/video/video-widget.cpp
index 9100e0ea..8262a380 100644
--- a/video/video-widget.cpp
+++ b/video/video-widget.cpp
@@ -11,9 +11,8 @@
void video_widget::init_image_nolock()
{
- double dpr = devicePixelRatioF();
- size_.store({ iround(width() * dpr), iround(height() * dpr) },
- std::memory_order_release);
+ double dpi = screen_dpi();
+ size_.store({ iround(width() * dpi), iround(height() * dpi) }, std::memory_order_release);
}
video_widget::video_widget(QWidget* parent) : QWidget(parent)
@@ -85,3 +84,4 @@ void video_widget::set_fresh(bool x)
{
fresh_.store(x, std::memory_order_release);
}
+
diff --git a/video/video-widget.hpp b/video/video-widget.hpp
index bb218c69..9218643b 100644
--- a/video/video-widget.hpp
+++ b/video/video-widget.hpp
@@ -7,6 +7,7 @@
#pragma once
+#include "compat/qt-dpi.hpp"
#include "compat/math.hpp"
#include "export.hpp"
@@ -20,7 +21,7 @@
#include <QMutex>
-struct OTR_VIDEO_EXPORT video_widget : QWidget
+struct OTR_VIDEO_EXPORT video_widget : QWidget, public screen_dpi_mixin<video_widget>
{
video_widget(QWidget* parent = nullptr);