KDecoration2

decorationbuttongroup.h
1 /*
2  * SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5  */
6 #ifndef KDECORATION2_DECORATIONBUTTONGROUP_H
7 #define KDECORATION2_DECORATIONBUTTONGROUP_H
8 #include "decorationbutton.h"
9 #include <functional>
10 #include <kdecoration2/kdecoration2_export.h>
11 
12 class QPainter;
13 
14 namespace KDecoration2
15 {
16 class Decoration;
17 class DecorationButtonGroupPrivate;
18 
19 /**
20  * @brief Helper class to layout DecorationButton.
21  *
22  * A Decoration normally has two groups of DecorationButtons: one left of the caption and one
23  * right of the caption. The DecorationButtonGroup helps in positioning the DecorationButtons in
24  * these groups and to update the position of each of the DecorationButtons whenever the state
25  * changes in a way that they should be repositioned.
26  *
27  * A DecorationButtonGroup is a visual layout element not accepting input events. As a visual
28  * element it provides a paint method allowing a sub class to provide custom painting for the
29  * DecorationButtonGroup.
30  **/
31 class KDECORATIONS2_EXPORT DecorationButtonGroup : public QObject
32 {
33  Q_OBJECT
34  /**
35  * The spacing to use between the DecorationButtons
36  **/
37  Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
38  /**
39  * The geometry of the DecorationButtonGroup in Decoration-local coordinates.
40  * The size of the DecorationButtonGroup depends on the sizes of the individual
41  * DecorationButtons and the spacing.
42  **/
43  Q_PROPERTY(QRectF geometry READ geometry NOTIFY geometryChanged)
44  // TODO: pos must consider whether it's left or right
45  /**
46  * The top left Position of the DecorationButtonGroup. This property needs to be
47  * changed to reposition the DecorationButtonGroup. An update should normally be
48  * triggered after e.g. a state change like maximization.
49  **/
50  Q_PROPERTY(QPointF pos READ pos WRITE setPos NOTIFY posChanged)
51 public:
52  enum class Position {
53  Left,
54  Right,
55  };
56  explicit DecorationButtonGroup(Position type,
57  Decoration *parent,
58  std::function<DecorationButton *(DecorationButtonType, Decoration *, QObject *)> buttonCreator);
59  explicit DecorationButtonGroup(Decoration *parent);
60  ~DecorationButtonGroup() override;
61 
62  /**
63  * Paints the DecorationButtonGroup. This method should normally be invoked from the
64  * Decoration's paint method. Base implementation just calls the paint method on each
65  * of the DecorationButtons. Overwriting sub classes need to either call the base
66  * implementation or ensure that the DecorationButtons are painted.
67  *
68  * @param painter The QPainter which is used to paint this DecorationButtonGroup
69  * @param repaintArea The area which is going to be repainted in Decoration coordinates
70  **/
71  virtual void paint(QPainter *painter, const QRect &repaintArea);
72 
73  QPointer<Decoration> decoration() const;
74 
75  qreal spacing() const;
76  void setSpacing(qreal spacing);
77 
78  QRectF geometry() const;
79  QPointF pos() const;
80  void setPos(const QPointF &pos);
81 
82  /**
83  * Adds @p button to the DecorationButtonGroup and triggers a re-layout of all
84  * DecorationButtons.
85  **/
86  void addButton(const QPointer<DecorationButton> &button);
87  /**
88  * Removes @p button from the DecorationButtonGroup and triggers a re-layout of all
89  * DecorationButtons.
90  **/
91  void removeButton(const QPointer<DecorationButton> &button);
92  /**
93  * Removes all DecorationButtons with @p type from the DecorationButtonGroup and
94  * triggers a re-layout of all DecorationButtons.
95  **/
96  void removeButton(DecorationButtonType type);
97  /**
98  * @returns @c true if the DecorationButtonGroup contains a DecorationButton of @p type
99  **/
100  bool hasButton(DecorationButtonType type) const;
101  /**
102  * @returns All DecorationButtons in this DecorationButtonGroup
103  **/
104  QVector<QPointer<DecorationButton>> buttons() const;
105 
106 Q_SIGNALS:
107  void spacingChanged(qreal);
108  void geometryChanged(const QRectF &);
109  void posChanged(const QPointF &);
110 
111 private:
112  class Private;
114 };
115 
116 } // namespace
117 
118 #endif
A button to be used in a Decoration.
Framework for creating window decorations.
Left
DecorationButtonType
The DecorationButtonType is a helper type for the DecorationButton.
Helper class to layout DecorationButton.
Base class for the Decoration.
Definition: decoration.h:59
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Jun 20 2021 23:07:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.