File indexing completed on 2024-12-22 04:14:05
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2006, 2007 Andreas Hartmetz (ahartmetz@gmail.com) 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KGESTURE_H 0008 #define KGESTURE_H 0009 0010 #include <kritawidgetutils_export.h> 0011 0012 #include <QString> 0013 #include <QHash> 0014 #include <QPolygon> 0015 0016 /* 0017 kinds of gestures: 0018 -shapes like triangle, right angle, line 0019 -"rocker" (i.e. two mouse button) gestures 0020 */ 0021 0022 class KisKShapeGesturePrivate; 0023 //TODO: implement operator== for special situations like in KKeyChooser. 0024 class KRITAWIDGETUTILS_EXPORT KisKShapeGesture 0025 { 0026 public: 0027 /** 0028 * Create a new invalid shape gesture. 0029 */ 0030 KisKShapeGesture(); 0031 0032 /** 0033 * Creates a new gesture consisting of given shape. 0034 * If the gesture belongs to a KAction, and the user draws approximately the same shape 0035 * on the screen while holding down the right mouse button, the action will trigger. 0036 * @p shape must be a "reasonable" polygon. It must contain at least two points 0037 * and it should contain at most 50 for performance reasons. No two consecutive points 0038 * are allowed to be at the same position. 0039 * @param shape to draw to trigger this gesture 0040 */ 0041 KisKShapeGesture(const QPolygon &shape); 0042 0043 /** 0044 * Creates a new gesture from a string description. 0045 * @param description create gesture according to this 0046 */ 0047 KisKShapeGesture(const QString &description); 0048 0049 /** 0050 * Copies the given gesture. 0051 * @param other gesture to copy 0052 */ 0053 KisKShapeGesture(const KisKShapeGesture &other); 0054 0055 /** 0056 * Destructor. 0057 */ 0058 ~KisKShapeGesture(); 0059 0060 /** 0061 * Set the shape to draw to trigger this gesture. 0062 */ 0063 void setShape(const QPolygon &shape); 0064 0065 /** 0066 * set a user-visible name for this gesture's shape, like "triangle" or "line". 0067 */ 0068 void setShapeName(const QString &friendlyName); 0069 0070 /** 0071 * Return the user-visible name for this gesture's shape, like "triangle" or "line". 0072 */ 0073 QString shapeName() const; 0074 0075 /** 0076 * Return true if this gesture is valid. 0077 * 0078 */ 0079 bool isValid() const; 0080 0081 /** 0082 * Return a string representation of this gesture. 0083 * Return empty string if invalid. 0084 * This function is mainly for use with config files. 0085 * 0086 * @see shapeName() 0087 */ 0088 QString toString() const; 0089 0090 /** 0091 * Return an idealized SVG image of this gesture. 0092 * Return an empty image if invalid. 0093 * @param attributes SVG attributes to apply to the SVG "path" element that 0094 * makes up the drawing of the gesture. By default, only a 'fill="none"' 0095 * attribute will be set. 0096 */ 0097 QByteArray toSvg(const QString &attributes = QString()) const; 0098 0099 /** 0100 * Return a difference measurement between this gesture and the @p other 0101 * gesture. Abort comparison if difference is larger than @p abortThreshold 0102 * and return a very large difference in that case. 0103 * Usual return values range from x to y //TODO: fill in x and y 0104 */ 0105 float distance(const KisKShapeGesture &other, float abortThreshold) const; 0106 0107 /** 0108 * Set this gesture to the other gesture. 0109 */ 0110 KisKShapeGesture &operator=(const KisKShapeGesture &other); 0111 0112 /** 0113 * Return whether this gesture is equal to the other gesture. 0114 */ 0115 bool operator==(const KisKShapeGesture &other) const; 0116 0117 /** 0118 * Return the opposite of operator==() 0119 */ 0120 bool operator!=(const KisKShapeGesture &other) const; 0121 0122 /** 0123 * Return an opaque value for use in hash tables 0124 */ 0125 uint hashable() const; 0126 0127 private: 0128 KisKShapeGesturePrivate *const d; 0129 }; 0130 0131 inline uint qHash(const KisKShapeGesture &key) 0132 { 0133 return qHash(key.hashable()); 0134 } 0135 0136 class KisKRockerGesturePrivate; 0137 0138 class KRITAWIDGETUTILS_EXPORT KisKRockerGesture 0139 { 0140 public: 0141 /** 0142 * Create a new invalid rocker gesture. 0143 */ 0144 KisKRockerGesture(); 0145 0146 /** 0147 * Creates a new gesture consisting of given buttons. 0148 * @param hold create gesture according to this hold 0149 * @param thenPush create gesture according to this push 0150 */ 0151 KisKRockerGesture(enum Qt::MouseButton hold, enum Qt::MouseButton thenPush); 0152 0153 /** 0154 * Creates a new gesture from a string description. 0155 * @param description create gesture according to this 0156 */ 0157 KisKRockerGesture(const QString &description); 0158 0159 /** 0160 * Copies the given gesture. 0161 * @param other gesture to copy 0162 */ 0163 KisKRockerGesture(const KisKRockerGesture &other); 0164 0165 /** 0166 * Destructor. 0167 */ 0168 ~KisKRockerGesture(); 0169 0170 /** 0171 * set button combination to trigger 0172 */ 0173 void setButtons(Qt::MouseButton hold, Qt::MouseButton thenPush); 0174 0175 /** 0176 * Write the button combination to hold and thenPush 0177 */ 0178 void getButtons(Qt::MouseButton *hold, Qt::MouseButton *thenPush) const; 0179 0180 /** 0181 * Return a user-friendly name of the button combination. 0182 */ 0183 QString rockerName() const; 0184 0185 /** 0186 * Return a user-friendly name for the mouse button button 0187 */ 0188 static QString mouseButtonName(Qt::MouseButton button); 0189 0190 /** 0191 * Return true if this gesture is valid. 0192 */ 0193 bool isValid() const; 0194 0195 /** 0196 * Return a string representation of this gesture. 0197 * Return an empty string if invalid. 0198 * This function is mainly for use with config files. 0199 * 0200 * @see rockerName() 0201 */ 0202 QString toString() const; 0203 0204 /** 0205 * Set this gesture to the other gesture. 0206 */ 0207 KisKRockerGesture &operator=(const KisKRockerGesture &other); 0208 0209 /** 0210 * Return whether this gesture is equal to the other gesture. 0211 */ 0212 bool operator==(const KisKRockerGesture &other) const; 0213 0214 /** 0215 * Return the opposite of operator==() 0216 */ 0217 bool operator!=(const KisKRockerGesture &other) const; 0218 0219 /** 0220 * Return an opaque value for use in hash tables 0221 */ 0222 uint hashable() const; 0223 0224 private: 0225 KisKRockerGesturePrivate *const d; 0226 }; 0227 0228 inline uint qHash(const KisKRockerGesture &key) 0229 { 0230 return qHash(key.hashable()); 0231 } 0232 0233 //KGESTURE_H 0234 #endif