File indexing completed on 2024-05-19 04:07:51

0001 /*
0002     SPDX-FileCopyrightText: 2010 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PALAPELI_TRIGGER_H
0008 #define PALAPELI_TRIGGER_H
0009 
0010 #include <QMetaType>
0011 #include <QString>
0012 
0013 namespace Palapeli
0014 {
0015     struct Trigger
0016     {
0017         public:
0018             ///Constructs an invalid trigger. (The mouse button is set to -1.)
0019             Trigger();
0020             ///Constructs a trigger from the given serialization. If the parsing fails, this constructor returns an invalid trigger (just like the default constructor).
0021             ///Possible serializations include "MidButton;NoModifier", "RightButton;ShiftModifier" and "wheel:Horizontal;ShiftModifier|ControlModifier". (A formal specification of the format is left as an exercise to the reader.)
0022             Trigger(const QByteArray& serialization); //krazy:exclude=explicit (I want implicit conversions)
0023 
0024             ///Returns whether this triger is valid.
0025             bool isValid() const;
0026             ///Returns the serialization for this trigger, or an empty string if this trigger is invalid.
0027             ///\see isValid()
0028             QByteArray serialized() const;
0029             ///Returns a translated (i.e. user-compatible) string representation for this trigger. This representation is not suitable for machine-readable files, use serialized() instead.
0030             QString toString() const;
0031 
0032             Qt::KeyboardModifiers modifiers() const;
0033             void setModifiers(Qt::KeyboardModifiers modifiers);
0034             Qt::MouseButton button() const; ///< Returns 0 by default or when a trigger wheel direction has been set.
0035             void setButton(Qt::MouseButton button); ///< Setting this will reset wheelDirection().
0036             Qt::Orientation wheelDirection() const; ///< Returns 0 by default or when a trigger button has been set.
0037             void setWheelDirection(Qt::Orientation orientation); ///< Setting this will reset button().
0038 
0039             bool operator==(const Palapeli::Trigger& other) const;
0040             inline bool operator!=(const Palapeli::Trigger& other) const;
0041         private:
0042             Qt::KeyboardModifiers m_modifiers;
0043             Qt::MouseButton m_button;
0044             Qt::Orientation m_wheelDirection;
0045     };
0046 }
0047 
0048 bool Palapeli::Trigger::operator!=(const Palapeli::Trigger& other) const
0049 {
0050     return !(*this == other);
0051 }
0052 
0053 Q_DECLARE_METATYPE(Palapeli::Trigger)
0054 
0055 #endif // PALAPELI_TRIGGER_H