QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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:
40
44 QgsScreenHelper( QWidget *parent SIP_TRANSFERTHIS );
45
49 QScreen *screen();
50
54 QWindow *windowHandle();
55
61 double screenDpi() const { return mScreenDpi; }
62
70 QRect availableGeometry() const { return mAvailableGeometry; }
71
72 signals:
73
79 void screenDpiChanged( double dpi );
80
86 void availableGeometryChanged( const QRect &geometry );
87
88 protected:
89 bool eventFilter( QObject *watched, QEvent *event ) override;
90
91 private slots:
92
93 void updateDevicePixelFromScreen();
94 void updateAvailableGeometryFromScreen();
95
96 private:
97 QWidget *mWidget = nullptr;
98
99 double mScreenDpi = 96.0;
100 QMetaObject::Connection mScreenDpiChangedConnection;
101
102 QRect mAvailableGeometry;
103 QMetaObject::Connection mAvailableGeometryChangedConnection;
104};
105
106
107#endif // QGSSCREENHELPER_H
QWindow * windowHandle()
Returns the window handle for the window the parent widget is associated with, or nullptr.
QScreen * screen()
Returns the screen that the parent widget appears on, or nullptr.
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.
bool eventFilter(QObject *watched, QEvent *event) override
QgsScreenHelper(QWidget *parent)
Constructor for QgsScreenHelper for the specified parent widget.
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