QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsscreenhelper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsscreenhelper.h
3 ---------------
4 Date : August 2022
5 Copyright : (C) 2022 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSSCREENHELPER_H
16#define QGSSCREENHELPER_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
20
21#include <QObject>
22#include <QRect>
23
24class QWidget;
25class QScreen;
26class QWindow;
27
35class GUI_EXPORT QgsScreenHelper : public QObject
36{
37 Q_OBJECT
38
39 public:
43 QgsScreenHelper( QWidget *parent SIP_TRANSFERTHIS );
44
48 QScreen *screen();
49
53 QWindow *windowHandle();
54
60 double screenDpi() const { return mScreenDpi; }
61
69 QRect availableGeometry() const { return mAvailableGeometry; }
70
71 signals:
72
78 void screenDpiChanged( double dpi );
79
85 void availableGeometryChanged( const QRect &geometry );
86
87 protected:
88 bool eventFilter( QObject *watched, QEvent *event ) override;
89
90 private slots:
91
92 void updateDevicePixelFromScreen();
93 void updateAvailableGeometryFromScreen();
94
95 private:
96 QWidget *mWidget = nullptr;
97
98 double mScreenDpi = 96.0;
99 QMetaObject::Connection mScreenDpiChangedConnection;
100
101 QRect mAvailableGeometry;
102 QMetaObject::Connection mAvailableGeometryChangedConnection;
103};
104
105
106#endif // QGSSCREENHELPER_H
A utility class for dynamic handling of changes to screen properties.
QRect availableGeometry() const
Returns the current screen available geometry in pixels.
double screenDpi() const
Returns the current screen DPI for the screen that the parent widget appears on.
void availableGeometryChanged(const QRect &geometry)
Emitted whenever the available geometry of the screen associated with the widget is changed.
void screenDpiChanged(double dpi)
Emitted whenever the screen dpi associated with the widget is changed.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53