1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLPREVIEWPOSITION_H |
5 | #define QQMLPREVIEWPOSITION_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qvector.h> |
19 | #include <QtCore/qpoint.h> |
20 | #include <QtCore/qurl.h> |
21 | #include <QtCore/qtimer.h> |
22 | #include <QtCore/qsettings.h> |
23 | #include <QtCore/qrect.h> |
24 | #include <QtCore/qdatastream.h> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QWindow; |
29 | |
30 | class QQmlPreviewPosition |
31 | { |
32 | public: |
33 | class ScreenData { |
34 | public: |
35 | bool operator==(const QQmlPreviewPosition::ScreenData &other) const; |
36 | QString name; |
37 | QRect rect; |
38 | }; |
39 | class Position { |
40 | public: |
41 | QString screenName; |
42 | QPoint nativePosition; |
43 | QSize size; |
44 | }; |
45 | enum InitializeState { |
46 | InitializePosition, |
47 | PositionInitialized |
48 | }; |
49 | |
50 | QQmlPreviewPosition(); |
51 | ~QQmlPreviewPosition(); |
52 | |
53 | |
54 | void takePosition(QWindow *window, InitializeState state = PositionInitialized); |
55 | void initLastSavedWindowPosition(QWindow *window); |
56 | void loadWindowPositionSettings(const QUrl &url); |
57 | |
58 | private: |
59 | void setPosition(const QQmlPreviewPosition::Position &position, QWindow *window); |
60 | QByteArray fromPositionToByteArray(const Position &position); |
61 | void readLastPositionFromByteArray(const QByteArray &array); |
62 | void saveWindowPosition(); |
63 | |
64 | bool m_hasPosition = false; |
65 | InitializeState m_initializeState = InitializePosition; |
66 | QSettings m_settings; |
67 | QString m_settingsKey; |
68 | QTimer m_savePositionTimer; |
69 | Position m_lastWindowPosition; |
70 | QVector<QWindow *> m_positionedWindows; |
71 | |
72 | QVector<ScreenData> m_currentInitScreensData; |
73 | }; |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | #endif // QQMLPREVIEWPOSITION_H |
78 | |