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

KDE's Doxygen guidelines are available online.