File: abstractlayoutmanager.h

package info (click to toggle)
plasma-workspace 4%3A5.27.5-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 102,040 kB
  • sloc: cpp: 121,800; xml: 3,238; python: 645; perl: 586; sh: 254; javascript: 113; ruby: 62; makefile: 15; ansic: 13
file content (128 lines) | stat: -rw-r--r-- 4,008 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
    SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#pragma once

#include "appletslayout.h"
#include <QObject>

class ItemContainer;

class AbstractLayoutManager : public QObject
{
    Q_OBJECT

public:
    AbstractLayoutManager(AppletsLayout *layout);
    ~AbstractLayoutManager();

    AppletsLayout *layout() const;

    void setCellSize(const QSizeF &size);
    QSizeF cellSize() const;

    /**
     * A size aligned to the gid that fully contains the given size
     */
    QSizeF cellAlignedContainingSize(const QSizeF &size) const;

    /**
     * Positions the item, does *not* assign the space as taken
     */
    void positionItem(ItemContainer *item);

    /**
     * Positions the item and assigns the space as taken by this item
     */
    void positionItemAndAssign(ItemContainer *item);

    /**
     * Set the space of item's rect as occupied by item.
     * The operation may fail if some space of the item's geometry is already occupied.
     * @returns true if the operation succeeded
     */
    bool assignSpace(ItemContainer *item);

    /**
     * If item is occupying space, set it as available
     */
    void releaseSpace(ItemContainer *item);

    // VIRTUALS
    virtual QString serializeLayout() const = 0;

    virtual void parseLayout(const QString &savedLayout) = 0;

    virtual void layoutGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);

    /**
     * true if the item is managed by the grid
     */
    virtual bool itemIsManaged(ItemContainer *item) = 0;

    /**
     * Forget about layout information and relayout all items based solely on their current geometry
     */
    virtual void resetLayout() = 0;

    /**
     * Forget about layout information and relayout all items based on their stored geometry first,
     * and if that fails from their current geometry.
     * If this function has been called from a resize, oldGeomety and newGeometry
     * represent the geometries that this layout had before and after the resize, for placing strategies
     * of items that weren't in the stored config.
     * If one of those rects are empty, neither should be considered in the layouting strategy.
     */
    virtual void resetLayoutFromConfig(const QRectF &newGeom, const QRectF &oldGeom) = 0;

    /**
     * Restores an item geometry from the serialized config
     * parseLayout needs to be called before this
     * @returns true if the item was stored in the config
     * and the restore has been performed.
     * Otherwise, the item is not touched and returns false
     */
    virtual bool restoreItem(ItemContainer *item) = 0;

    /**
     * @returns true if the given rectangle is all free space
     */
    virtual bool isRectAvailable(const QRectF &rect) = 0;

Q_SIGNALS:
    /**
     * Emitted when the layout has been changed and now needs saving
     */
    void layoutNeedsSaving();

protected:
    /**
     * Subclasses implement their assignSpace logic here
     */
    virtual bool assignSpaceImpl(ItemContainer *item) = 0;

    /**
     * Subclasses implement their releasespace logic here
     */
    virtual void releaseSpaceImpl(ItemContainer *item) = 0;

    /**
     * @returns a rectangle big at least as minimumSize, trying to be as near as possible to the current item's geometry, displaced in the direction we asked,
     * forwards or backwards
     * @param item the item container we want to place an item in
     * @param minimumSize the minimum size we need to make sure is available
     * @param direction the preferred item layout direction, can be Closest, LeftToRight, RightToLeft, TopToBottom, and BottomToTop
     */
    virtual QRectF nextAvailableSpace(ItemContainer *item, const QSizeF &minimumSize, AppletsLayout::PreferredLayoutDirection direction) const = 0;

private:
    QRectF candidateGeometry(ItemContainer *item) const;

    AppletsLayout *m_layout;

    // size in pixels of a crid cell
    QSizeF m_cellSize;
};