File indexing completed on 2024-04-28 15:27:41

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef ENUMS_H
0008 #define ENUMS_H
0009 
0010 #include <QObject>
0011 
0012 /**
0013  * @brief Types used in org::kde::kirigami::PageRow and org::kde::kirigami::Page that indicate how
0014  * top bar controls should be represented to the user.
0015  */
0016 class ApplicationHeaderStyle : public QObject
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     /**
0022      * @brief Types that indicate how the global toolbar should be shown to the
0023      * user.
0024      */
0025     enum Status {
0026         /**
0027          * @brief Automatically choose other values depending on the device's
0028          * form factor.
0029          */
0030         Auto = 0,
0031 
0032         /**
0033          * @brief Display the main, left, and right actions horizontally
0034          * centered at the bottom of the page in a mobile-friendly way.
0035          */
0036         Breadcrumb,
0037 
0038         /**
0039          * @brief Each page will only have its title at the top alongside breadcrumb
0040          * page actions controls.
0041          */
0042         Titles,
0043 
0044         /**
0045          * @brief Each page will be shown as a tab button inside the tab bar.
0046          * @deprecated This implementation in Kirigami.PageRow will be removed in
0047          * KF6 (this enum value might be removed too).
0048          */
0049         TabBar,
0050 
0051         /**
0052          * @brief Each page will show its title at the top together with action buttons and menus
0053          * that represent global and current pages actions.
0054          *
0055          * org::kde::kirigami::PageRow does not implement this mode for mobile formfactor devices.
0056          */
0057         ToolBar,
0058 
0059         /**
0060          * @brief Do not display the global toolbar.
0061          *
0062          * The global drawer handle will be shown at the bottom left corner of the application
0063          * alongside breadcrumb controls.
0064          */
0065         None,
0066     };
0067     Q_ENUM(Status)
0068 
0069     /**
0070      * @brief Flags for implementations using navigation buttons indicating
0071      * which buttons to display.
0072      */
0073     enum NavigationButton {
0074         /**
0075          * @brief Display no navigation buttons.
0076          */
0077         NoNavigationButtons = 0,
0078 
0079         /**
0080          * @brief Display the back navigation button.
0081          */
0082         ShowBackButton = 0x1,
0083 
0084         /**
0085          * @brief Display the forward navigation button.
0086          */
0087         ShowForwardButton = 0x2,
0088     };
0089     Q_ENUM(NavigationButton)
0090     Q_DECLARE_FLAGS(NavigationButtons, NavigationButton)
0091 };
0092 
0093 /**
0094  * @brief Types for implementations using messages indicating preference
0095  * about how to display the message (e.g. color).
0096  */
0097 class MessageType : public QObject
0098 {
0099     Q_OBJECT
0100 
0101 public:
0102     enum Type {
0103         /**
0104          * @brief Display an informative message to the user.
0105          *
0106          * Use this to announce a result or provide commentary.
0107          */
0108         Information = 0,
0109 
0110         /**
0111          * @brief Display a positive message to the user.
0112          *
0113          * Use this to announce a successful result
0114          * or the successful completion of a procedure.
0115          */
0116         Positive,
0117 
0118         /**
0119          * @brief Display a warning message to the user.
0120          *
0121          * Use this to provide critical guidance or
0122          * a warning about something that is not going to work.
0123          */
0124         Warning,
0125 
0126         /**
0127          * @brief Display an error message to the user.
0128          *
0129          * Use this to announce something has gone wrong
0130          * or that input will not be accepted.
0131          */
0132         Error,
0133     };
0134     Q_ENUM(Type)
0135 };
0136 
0137 /**
0138  * @brief This enum contains hints on how a @link Kirigami.Action Kirigami.Action @endlink should be displayed.
0139  * @note Implementations may choose to disregard the set hint.
0140  */
0141 class DisplayHint : public QObject
0142 {
0143     Q_OBJECT
0144 
0145 public:
0146     enum Hint : uint {
0147         /**
0148          * @brief No specific preference on how to display this Action.
0149          */
0150         NoPreference = 0,
0151 
0152         /**
0153          * @brief Only display an icon for this Action.
0154          */
0155         IconOnly = 1,
0156 
0157         /**
0158          * @brief Try to keep the Action visible even with constrained space.
0159          *
0160          * Mutually exclusive with AlwaysHide, KeepVisible has priority.
0161          */
0162         KeepVisible = 2,
0163 
0164         /**
0165          * @brief If possible, hide the action in an overflow menu or similar
0166          * location.
0167          *
0168          * Mutually exclusive with KeepVisible, KeepVisible has priority.
0169          */
0170         AlwaysHide = 4,
0171 
0172         /**
0173          * @brief When this action has children, do not display any indicator
0174          * (like a menu arrow) for this action.
0175          */
0176         HideChildIndicator = 8,
0177     };
0178     Q_DECLARE_FLAGS(DisplayHints, Hint)
0179     Q_ENUM(Hint)
0180     Q_FLAG(DisplayHints)
0181 
0182     // Note: These functions are instance methods because they need to be
0183     // exposed to QML. Unfortunately static methods are not supported.
0184 
0185     /**
0186      * @brief A helper function to check if a certain display hint has been set.
0187      *
0188      * This function is mostly convenience to enforce certain behaviour of the
0189      * various display hints, primarily the mutual exclusivity of ::KeepVisible
0190      * and ::AlwaysHide.
0191      *
0192      * @param values The display hints to check.
0193      * @param hint The display hint to check if it is set.
0194      *
0195      * @return @c true if the hint was set for this action, @c false if not.
0196      *
0197      * @since org.kde.kirigami 2.14
0198      */
0199     Q_INVOKABLE bool displayHintSet(DisplayHints values, Hint hint);
0200 
0201     /**
0202      * @brief Check if a certain display hint has been set on an object.
0203      *
0204      * This overloads displayHintSet(DisplayHints, Hint) to accept a QObject
0205      * instance. This object is checked to see if it has a ``displayHint`` property
0206      * and if so, if that property has a @p hint set.
0207      *
0208      * @param object The object to check.
0209      * @param hint The hint to check for.
0210      *
0211      * @return @c false if object is null, object has no displayHint property or
0212      * the hint was not set. @c true if it has the property and the hint
0213      * is set.
0214      */
0215     Q_INVOKABLE bool displayHintSet(QObject *object, Hint hint);
0216 
0217     /**
0218      * Static version of displayHintSet(DisplayHints, Hint) that can be
0219      * called from C++ code.
0220      */
0221     static bool isDisplayHintSet(DisplayHints values, Hint hint);
0222 };
0223 
0224 Q_DECLARE_OPERATORS_FOR_FLAGS(DisplayHint::DisplayHints)
0225 
0226 #endif // ENUMS_H