Kirigami2

displayhint.h
1/*
2 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef DISPLAYHINT_H
8#define DISPLAYHINT_H
9
10#include <QObject>
11#include <QQmlEngine>
12
13class DisplayHint : public QObject
14{
16 QML_ELEMENT
17 QML_SINGLETON
18
19public:
20 /**
21 * Hints for implementations using Actions indicating preferences about how to display the action.
22 */
23 enum Hint : uint {
24 /**
25 * Indicates there is no specific preference.
26 */
27 NoPreference = 0,
28 /**
29 * Only display an icon for this Action.
30 */
31 IconOnly = 1,
32 /**
33 * Try to keep the action visible even when space constrained.
34 * Mutually exclusive with AlwaysHide, KeepVisible has priority.
35 */
36 KeepVisible = 2,
37 /**
38 * If possible, hide the action in an overflow menu or similar location.
39 * Mutually exclusive with KeepVisible, KeepVisible has priority.
40 */
41 AlwaysHide = 4,
42 /**
43 * When this action has children, do not display any indicator (like a
44 * menu arrow) for this action.
45 */
46 HideChildIndicator = 8,
47 };
48 Q_DECLARE_FLAGS(DisplayHints, Hint)
49 Q_ENUM(Hint)
50 Q_FLAG(DisplayHints)
51
52 // Note: These functions are instance methods because they need to be
53 // exposed to QML. Unfortunately static methods are not supported.
54
55 /**
56 * Helper function to check if a certain display hint has been set.
57 *
58 * This function is mostly convenience to enforce certain behaviour of the
59 * various display hints, primarily the mutual exclusivity of KeepVisible
60 * and AlwaysHide.
61 *
62 * @param values The display hints to check.
63 * @param hint The display hint to check if it is set.
64 *
65 * @return true if the hint was set for this action, false if not.
66 *
67 * @since 2.14
68 */
69 Q_INVOKABLE bool displayHintSet(DisplayHints values, Hint hint);
70
71 /**
72 * Check if a certain display hint has been set on an object.
73 *
74 * This overloads @f displayHintSet(DisplayHints, Hint) to accept a QObject
75 * instance. This object is checked to see if it has a displayHint property
76 * and if so, if that property has @p hint set.
77 *
78 * @param object The object to check.
79 * @param hint The hint to check for.
80 *
81 * @return false if object is null, object has no displayHint property or
82 * the hint was not set. true if it has the property and the hint is
83 * set.
84 */
85 Q_INVOKABLE bool displayHintSet(QObject *object, Hint hint);
86
87 /**
88 * Static version of \f displayHintSet(DisplayHints, Hint) that can be
89 * called from C++ code.
90 */
91 static bool isDisplayHintSet(DisplayHints values, Hint hint);
92};
93
94Q_DECLARE_OPERATORS_FOR_FLAGS(DisplayHint::DisplayHints)
95
96#endif // DISPLAYHINT_H
Q_ENUM(...)
Q_FLAG(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:54:50 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.