panelview.h 8.03 KB
Newer Older
Sebastian Kügler's avatar
Sebastian Kügler committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 *  Copyright 2013 Marco Martin <mart@kde.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef PANELVIEW_H
#define PANELVIEW_H

22
#include <QPointer>
23
#include <Plasma/Theme>
24
#include <QTimer>
Sebastian Kügler's avatar
Sebastian Kügler committed
25

26
27
#include <PlasmaQuick/ContainmentView>
#include <PlasmaQuick/ConfigView>
28

29
class ShellCorona;
Sebastian Kügler's avatar
Sebastian Kügler committed
30

31
32
33
34
35
36
37
38
namespace KWayland
{
    namespace Client
    {
        class PlasmaShellSurface;
    }
}

Marco Martin's avatar
Marco Martin committed
39
class PanelView : public PlasmaQuick::ContainmentView
40

Sebastian Kügler's avatar
Sebastian Kügler committed
41
42
{
    Q_OBJECT
Marco Martin's avatar
Marco Martin committed
43
44
45
46
47
    /**
     * Alignment of the panel: when not fullsize it can be aligned at left,
     * right or center of the screen (left and right work as top/bottom
     * too for vertical panels)
     */
Marco Martin's avatar
Marco Martin committed
48
    Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Marco Martin's avatar
Marco Martin committed
49
50
51
52

    /**
     * how much the panel is moved from the left/right/center anchor point
     */
Marco Martin's avatar
Marco Martin committed
53
    Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
Marco Martin's avatar
Marco Martin committed
54
55
56
57

    /**
     * height of horizontal panels, width of vertical panels
     */
Marco Martin's avatar
Marco Martin committed
58
    Q_PROPERTY(int thickness READ thickness WRITE setThickness NOTIFY thicknessChanged)
Marco Martin's avatar
Marco Martin committed
59
60
61
62

    /**
     * width of horizontal panels, height of vertical panels
     */
63
    Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
Marco Martin's avatar
Marco Martin committed
64
65
66
67

    /**
     * if the panel resizes itself, never resize more than that
     */
68
    Q_PROPERTY(int maximumLength READ maximumLength WRITE setMaximumLength NOTIFY maximumLengthChanged)
Marco Martin's avatar
Marco Martin committed
69
70
71
72

    /**
     * if the panel resizes itself, never resize less than that
     */
73
    Q_PROPERTY(int minimumLength READ minimumLength WRITE setMinimumLength NOTIFY minimumLengthChanged)
Marco Martin's avatar
Marco Martin committed
74
75
76
77

    /**
     * how much the panel is distant for the screen edge: used by the panel controller to drag it around
     */
Marco Martin's avatar
Marco Martin committed
78
    Q_PROPERTY(int distance READ distance WRITE setDistance NOTIFY distanceChanged)
Marco Martin's avatar
Marco Martin committed
79

80
81
82
83
84
85
86
    /**
     * support NoBackground in order to disable blur/contrast effects and remove
     * the panel shadows
     * @since 5.9
     */    
    Q_PROPERTY(Plasma::Types::BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints NOTIFY backgroundHintsChanged)

87
88
89
90
91
92
    /**
     * The borders that should have a shadow
     * @since 5.7
     */
    Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged)

Marco Martin's avatar
Marco Martin committed
93
    /**
Yuri Chornoivan's avatar
Yuri Chornoivan committed
94
     * information about the screen in which the panel is in
Marco Martin's avatar
Marco Martin committed
95
     */
96
    Q_PROPERTY(QScreen *screenToFollow READ screenToFollow WRITE setScreenToFollow NOTIFY screenToFollowChanged)
Marco Martin's avatar
Marco Martin committed
97
98
99
100

    /**
     *  how the panel behaves, visible, autohide etc.
     */
101
    Q_PROPERTY(VisibilityMode visibilityMode READ visibilityMode WRITE setVisibilityMode NOTIFY visibilityModeChanged)
Sebastian Kügler's avatar
Sebastian Kügler committed
102
103

public:
Marco Martin's avatar
Marco Martin committed
104
105

    enum VisibilityMode {
Marco Martin's avatar
Marco Martin committed
106
107
108
109
        NormalPanel = 0, /** default, always visible panel, the windowmanager reserves a places for it */
        AutoHide, /**the panel will be shownn only if the mouse cursor is on screen edges */
        LetWindowsCover, /** always visible, windows will go over the panel, no area reserved */
        WindowsGoBelow /** always visible, windows will go under the panel, no area reserved */
Marco Martin's avatar
Marco Martin committed
110
    };
111
    Q_ENUM(VisibilityMode)
Marco Martin's avatar
Marco Martin committed
112

Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
113
    explicit PanelView(ShellCorona *corona, QScreen *targetScreen = nullptr, QWindow *parent = nullptr);
114
    ~PanelView() override;
Sebastian Kügler's avatar
Sebastian Kügler committed
115

116
    KConfigGroup config() const override;
117
    KConfigGroup configDefaults() const;
Marco Martin's avatar
Marco Martin committed
118

119
    Q_INVOKABLE QString fileFromPackage(const QString &key, const QString &fileName);
120
121
    Q_INVOKABLE void maximize();

122
123
124
    Qt::Alignment alignment() const;
    void setAlignment(Qt::Alignment alignment);

125
126
127
    int offset() const;
    void setOffset(int offset);

Marco Martin's avatar
Marco Martin committed
128
129
130
    int thickness() const;
    void setThickness(int thickness);

131
132
133
    int length() const;
    void setLength(int value);

134
135
136
137
138
139
    int maximumLength() const;
    void setMaximumLength(int length);

    int minimumLength() const;
    void setMinimumLength(int length);

Marco Martin's avatar
Marco Martin committed
140
141
142
    int distance() const;
    void setDistance(int dist);

143
144
145
    Plasma::Types::BackgroundHints backgroundHints() const;
    void setBackgroundHints(Plasma::Types::BackgroundHints hint);

146
147
    Plasma::FrameSvg::EnabledBorders enabledBorders() const;

Marco Martin's avatar
Marco Martin committed
148
149
150
    VisibilityMode visibilityMode() const;
    void setVisibilityMode(PanelView::VisibilityMode mode);

151
152
153
154
155
    /**
     * @returns the geometry of the panel given a distance
     */
    QRect geometryByDistance(int distance) const;

156
    /* Both Shared with script/panel.cpp */
157
    static KConfigGroup panelConfig(ShellCorona *corona, Plasma::Containment *containment, QScreen *screen);
158
    static KConfigGroup panelConfigDefaults(ShellCorona *corona, Plasma::Containment *containment, QScreen *screen);
159

160
161
    void updateStruts();

162
    /*This is different from screen() as is always there, even if the window is
163
      temporarily outside the screen or if is hidden: only plasmashell will ever
164
165
166
167
      change this property, unlike QWindow::screen()*/
    void setScreenToFollow(QScreen* screen);
    QScreen* screenToFollow() const;

168
protected:
169
170
171
172
    void resizeEvent(QResizeEvent *ev) override;
    void showEvent(QShowEvent *event) override;
    void moveEvent(QMoveEvent *ev) override;
    bool event(QEvent *e) override;
173

Marco Martin's avatar
Marco Martin committed
174
Q_SIGNALS:
Marco Martin's avatar
Marco Martin committed
175
    void alignmentChanged();
Marco Martin's avatar
Marco Martin committed
176
    void offsetChanged();
Marco Martin's avatar
Marco Martin committed
177
    void screenGeometryChanged();
Marco Martin's avatar
Marco Martin committed
178
    void thicknessChanged();
179
    void lengthChanged();
180
181
    void maximumLengthChanged();
    void minimumLengthChanged();
Marco Martin's avatar
Marco Martin committed
182
    void distanceChanged();
183
    void backgroundHintsChanged();
184
    void enabledBordersChanged();
185
186

    //QWindow does not have a property for screen. Adding this property requires re-implementing the signal
187
    void screenToFollowChanged(QScreen *screen);
188
    void visibilityModeChanged();
Marco Martin's avatar
Marco Martin committed
189

190
191
192
193
protected Q_SLOTS:
    /**
     * It will be called when the configuration is requested
     */
194
    void showConfigurationInterface(Plasma::Applet *applet) override;
195

196
197
private Q_SLOTS:
    void positionPanel();
Marco Martin's avatar
Marco Martin committed
198
    void restore();
199
200
201
202
203
    void setAutoHideEnabled(bool autoHideEnabled);
    void showTemporarily();
    void containmentChanged();
    void statusChanged(Plasma::Types::ItemStatus);
    void restoreAutoHide();
204
    void screenDestroyed(QObject* screen);
205
    void adaptToScreen();
206
207
    void handleQmlStatusChange(QQmlComponent::Status status);
    void updateMask();
208
    void updateEnabledBorders();    
209

Sebastian Kügler's avatar
Sebastian Kügler committed
210
private:
211
    int readConfigValueWithFallBack(const QString &key, int defaultValue);
212
    void resizePanel();
213
    void integrateScreen();
David Edmundson's avatar
David Edmundson committed
214
215
    bool containmentContainsPosition(const QPointF &point) const;
    QPointF positionAdjustedForContainment(const QPointF &point) const;
216
    void setupWaylandIntegration();
217
    void visibilityModeToWayland();
218
    bool edgeActivated() const;
219
    bool canSetStrut() const;
220

Marco Martin's avatar
Marco Martin committed
221
222
223
    int m_offset;
    int m_maxLength;
    int m_minLength;
224
    int m_contentLength;
Marco Martin's avatar
Marco Martin committed
225
    int m_distance;
226
    int m_thickness;
227
    bool m_initCompleted;
228
    bool m_containsMouse = false;
Marco Martin's avatar
Marco Martin committed
229
    Qt::Alignment m_alignment;
Marco Martin's avatar
Marco Martin committed
230
    QPointer<PlasmaQuick::ConfigView> m_panelConfigView;
231
    ShellCorona *m_corona;
232
    QTimer m_strutsTimer;
Marco Martin's avatar
Marco Martin committed
233
    VisibilityMode m_visibilityMode;
234
    Plasma::Theme m_theme;
235
    QTimer m_positionPaneltimer;
236
    QTimer m_unhideTimer;
237
    Plasma::Types::BackgroundHints m_backgroundHints;
238
    Plasma::FrameSvg::EnabledBorders m_enabledBorders = Plasma::FrameSvg::AllBorders;
239
    KWayland::Client::PlasmaShellSurface *m_shellSurface;
240
241
    QPointer<QScreen> m_lastScreen;
    QPointer<QScreen> m_screenToFollow;
242
    QMetaObject::Connection m_transientWindowVisibleWatcher;
Marco Martin's avatar
Marco Martin committed
243
244

    static const int STRUTSTIMERDELAY = 200;
Sebastian Kügler's avatar
Sebastian Kügler committed
245
246
247
};

#endif // PANELVIEW_H