KWin
Loading...
Searching...
No Matches
expolayout.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QObject>
10#include <QQuickItem>
11#include <QRect>
12
13#include <optional>
14
15class ExpoCell;
16
17class ExpoLayout : public QQuickItem
18{
19 Q_OBJECT
20 Q_PROPERTY(LayoutMode mode READ mode WRITE setMode NOTIFY modeChanged)
21 Q_PROPERTY(bool fillGaps READ fillGaps WRITE setFillGaps NOTIFY fillGapsChanged)
22 Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
23 Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
24
25public:
26 enum LayoutMode : uint {
29 LayoutNone = 2
30 };
31 Q_ENUM(LayoutMode)
32
33 explicit ExpoLayout(QQuickItem *parent = nullptr);
34
35 LayoutMode mode() const;
37
38 bool fillGaps() const;
39 void setFillGaps(bool fill);
40
41 int spacing() const;
42 void setSpacing(int spacing);
43
44 void addCell(ExpoCell *cell);
45 void removeCell(ExpoCell *cell);
46
47 bool isReady() const;
48 void setReady();
49
50 Q_INVOKABLE void forceLayout();
51
52protected:
53 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
54 void updatePolish() override;
55
56Q_SIGNALS:
61
62private:
63 void calculateWindowTransformationsClosest();
64 void calculateWindowTransformationsNatural();
65 void resetTransformations();
66
67 QList<ExpoCell *> m_cells;
69 int m_accuracy = 20;
70 int m_spacing = 10;
71 bool m_ready = false;
72 bool m_fillGaps = false;
73};
74
75class ExpoCell : public QObject
76{
77 Q_OBJECT
78 Q_PROPERTY(ExpoLayout *layout READ layout WRITE setLayout NOTIFY layoutChanged)
79 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
80 Q_PROPERTY(int naturalX READ naturalX WRITE setNaturalX NOTIFY naturalXChanged)
81 Q_PROPERTY(int naturalY READ naturalY WRITE setNaturalY NOTIFY naturalYChanged)
84 Q_PROPERTY(int x READ x NOTIFY xChanged)
85 Q_PROPERTY(int y READ y NOTIFY yChanged)
86 Q_PROPERTY(int width READ width NOTIFY widthChanged)
87 Q_PROPERTY(int height READ height NOTIFY heightChanged)
90
91public:
92 explicit ExpoCell(QObject *parent = nullptr);
93 ~ExpoCell() override;
94
95 bool isEnabled() const;
96 void setEnabled(bool enabled);
97
98 ExpoLayout *layout() const;
100
101 int naturalX() const;
102 void setNaturalX(int x);
103
104 int naturalY() const;
105 void setNaturalY(int y);
106
107 int naturalWidth() const;
108 void setNaturalWidth(int width);
109
110 int naturalHeight() const;
111 void setNaturalHeight(int height);
112
113 QRect naturalRect() const;
114 QMargins margins() const;
115
116 int x() const;
117 void setX(int x);
118
119 int y() const;
120 void setY(int y);
121
122 int width() const;
123 void setWidth(int width);
124
125 int height() const;
126 void setHeight(int height);
127
128 QString persistentKey() const;
129 void setPersistentKey(const QString &key);
130
131 int bottomMargin() const;
132 void setBottomMargin(int margin);
133
134public Q_SLOTS:
135 void update();
136
137Q_SIGNALS:
144 void xChanged();
145 void yChanged();
150
151private:
152 QString m_persistentKey;
153 bool m_enabled = true;
154 int m_naturalX = 0;
155 int m_naturalY = 0;
156 int m_naturalWidth = 0;
157 int m_naturalHeight = 0;
158 QMargins m_margins;
159 std::optional<int> m_x;
160 std::optional<int> m_y;
161 std::optional<int> m_width;
162 std::optional<int> m_height;
163 QPointer<ExpoLayout> m_layout;
164};
int bottomMargin
Definition expolayout.h:89
void bottomMarginChanged()
void naturalHeightChanged()
void persistentKeyChanged()
void naturalXChanged()
void update()
void setHeight(int height)
void enabledChanged()
void setX(int x)
int height
Definition expolayout.h:87
QString persistentKey
Definition expolayout.h:88
void yChanged()
int width
Definition expolayout.h:86
int naturalY
Definition expolayout.h:81
void naturalYChanged()
void naturalWidthChanged()
QMargins margins() const
void setNaturalY(int y)
void setNaturalHeight(int height)
ExpoLayout * layout
Definition expolayout.h:78
int naturalX
Definition expolayout.h:80
void setY(int y)
void setNaturalX(int x)
int naturalHeight
Definition expolayout.h:83
bool enabled
Definition expolayout.h:79
void widthChanged()
void setNaturalWidth(int width)
void setBottomMargin(int margin)
void heightChanged()
void setLayout(ExpoLayout *layout)
QRect naturalRect() const
void setEnabled(bool enabled)
void setPersistentKey(const QString &key)
void setWidth(int width)
int naturalWidth
Definition expolayout.h:82
void xChanged()
bool isEnabled() const
void layoutChanged()
Q_INVOKABLE void forceLayout()
ExpoLayout(QQuickItem *parent=nullptr)
void setFillGaps(bool fill)
bool isReady() const
void setMode(LayoutMode mode)
void removeCell(ExpoCell *cell)
void spacingChanged()
LayoutMode mode
Definition expolayout.h:20
void setReady()
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void readyChanged()
void modeChanged()
void updatePolish() override
void fillGapsChanged()
bool fillGaps
Definition expolayout.h:21
void addCell(ExpoCell *cell)
void setSpacing(int spacing)
#define private
#define explicit