Warning, file /plasma/kwin/src/plugins/private/expolayout.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QQuickItem>
0011 #include <QRect>
0012 
0013 #include <optional>
0014 
0015 class ExpoCell;
0016 
0017 class ExpoLayout : public QQuickItem
0018 {
0019     Q_OBJECT
0020     Q_PROPERTY(LayoutMode mode READ mode WRITE setMode NOTIFY modeChanged)
0021     Q_PROPERTY(bool fillGaps READ fillGaps WRITE setFillGaps NOTIFY fillGapsChanged)
0022     Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
0023     Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
0024 
0025 public:
0026     enum LayoutMode : uint {
0027         LayoutClosest = 0,
0028         LayoutNatural = 1,
0029         LayoutNone = 2
0030     };
0031     Q_ENUM(LayoutMode)
0032 
0033     explicit ExpoLayout(QQuickItem *parent = nullptr);
0034 
0035     LayoutMode mode() const;
0036     void setMode(LayoutMode mode);
0037 
0038     bool fillGaps() const;
0039     void setFillGaps(bool fill);
0040 
0041     int spacing() const;
0042     void setSpacing(int spacing);
0043 
0044     void addCell(ExpoCell *cell);
0045     void removeCell(ExpoCell *cell);
0046 
0047     bool isReady() const;
0048     void setReady();
0049 
0050     Q_INVOKABLE void forceLayout();
0051 
0052 protected:
0053     void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
0054     void updatePolish() override;
0055 
0056 Q_SIGNALS:
0057     void modeChanged();
0058     void fillGapsChanged();
0059     void spacingChanged();
0060     void readyChanged();
0061 
0062 private:
0063     void calculateWindowTransformationsClosest();
0064     void calculateWindowTransformationsNatural();
0065     void resetTransformations();
0066 
0067     QList<ExpoCell *> m_cells;
0068     LayoutMode m_mode = LayoutNatural;
0069     int m_accuracy = 20;
0070     int m_spacing = 10;
0071     bool m_ready = false;
0072     bool m_fillGaps = false;
0073 };
0074 
0075 class ExpoCell : public QObject
0076 {
0077     Q_OBJECT
0078     Q_PROPERTY(ExpoLayout *layout READ layout WRITE setLayout NOTIFY layoutChanged)
0079     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
0080     Q_PROPERTY(int naturalX READ naturalX WRITE setNaturalX NOTIFY naturalXChanged)
0081     Q_PROPERTY(int naturalY READ naturalY WRITE setNaturalY NOTIFY naturalYChanged)
0082     Q_PROPERTY(int naturalWidth READ naturalWidth WRITE setNaturalWidth NOTIFY naturalWidthChanged)
0083     Q_PROPERTY(int naturalHeight READ naturalHeight WRITE setNaturalHeight NOTIFY naturalHeightChanged)
0084     Q_PROPERTY(int x READ x NOTIFY xChanged)
0085     Q_PROPERTY(int y READ y NOTIFY yChanged)
0086     Q_PROPERTY(int width READ width NOTIFY widthChanged)
0087     Q_PROPERTY(int height READ height NOTIFY heightChanged)
0088     Q_PROPERTY(QString persistentKey READ persistentKey WRITE setPersistentKey NOTIFY persistentKeyChanged)
0089     Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
0090 
0091 public:
0092     explicit ExpoCell(QObject *parent = nullptr);
0093     ~ExpoCell() override;
0094 
0095     bool isEnabled() const;
0096     void setEnabled(bool enabled);
0097 
0098     ExpoLayout *layout() const;
0099     void setLayout(ExpoLayout *layout);
0100 
0101     int naturalX() const;
0102     void setNaturalX(int x);
0103 
0104     int naturalY() const;
0105     void setNaturalY(int y);
0106 
0107     int naturalWidth() const;
0108     void setNaturalWidth(int width);
0109 
0110     int naturalHeight() const;
0111     void setNaturalHeight(int height);
0112 
0113     QRect naturalRect() const;
0114     QMargins margins() const;
0115 
0116     int x() const;
0117     void setX(int x);
0118 
0119     int y() const;
0120     void setY(int y);
0121 
0122     int width() const;
0123     void setWidth(int width);
0124 
0125     int height() const;
0126     void setHeight(int height);
0127 
0128     QString persistentKey() const;
0129     void setPersistentKey(const QString &key);
0130 
0131     int bottomMargin() const;
0132     void setBottomMargin(int margin);
0133 
0134 public Q_SLOTS:
0135     void update();
0136 
0137 Q_SIGNALS:
0138     void layoutChanged();
0139     void enabledChanged();
0140     void naturalXChanged();
0141     void naturalYChanged();
0142     void naturalWidthChanged();
0143     void naturalHeightChanged();
0144     void xChanged();
0145     void yChanged();
0146     void widthChanged();
0147     void heightChanged();
0148     void persistentKeyChanged();
0149     void bottomMarginChanged();
0150 
0151 private:
0152     QString m_persistentKey;
0153     bool m_enabled = true;
0154     int m_naturalX = 0;
0155     int m_naturalY = 0;
0156     int m_naturalWidth = 0;
0157     int m_naturalHeight = 0;
0158     QMargins m_margins;
0159     std::optional<int> m_x;
0160     std::optional<int> m_y;
0161     std::optional<int> m_width;
0162     std::optional<int> m_height;
0163     QPointer<ExpoLayout> m_layout;
0164 };