KDecoration2

decorationbuttongroup.h
1/*
2 * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
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
11class QPainter;
12
13namespace KDecoration2
14{
15class Decoration;
16class 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 **/
30class 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)
50public:
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 QList<DecorationButton *> buttons() const;
104
105Q_SIGNALS:
106 void spacingChanged(qreal);
107 void geometryChanged(const QRectF &);
108 void posChanged(const QPointF &);
109
110private:
111 class Private;
112 std::unique_ptr<Private> d;
113};
114
115} // namespace
Helper class to layout DecorationButton.
A button to be used in a Decoration.
Base class for the Decoration.
Definition decoration.h:58
Framework for creating window decorations.
DecorationButtonType
The DecorationButtonType is a helper type for the DecorationButton.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:09 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.