File indexing completed on 2024-05-12 15:56:53
0001 /* This file is part of the KDE project 0002 * 0003 * SPDX-FileCopyrightText: 2006, 2010 Boudewijn Rempt <boud@valdyas.org> 0004 * SPDX-FileCopyrightText: 2006-2010 Thomas Zander <zander@kde.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 #ifndef _KO_TOOL_PROXY_H_ 0009 #define _KO_TOOL_PROXY_H_ 0010 0011 #include "kritaflake_export.h" 0012 0013 #include <QObject> 0014 #include <QHash> 0015 0016 class QAction; 0017 class QAction; 0018 class QMouseEvent; 0019 class QKeyEvent; 0020 class QWheelEvent; 0021 class QTabletEvent; 0022 class KoCanvasBase; 0023 class KoViewConverter; 0024 class KoToolBase; 0025 class KoToolProxyPrivate; 0026 class QInputMethodEvent; 0027 class KoPointerEvent; 0028 class QDragMoveEvent; 0029 class QDragLeaveEvent; 0030 class QDropEvent; 0031 class QTouchEvent; 0032 class QPainter; 0033 class QPointF; 0034 class QMenu; 0035 class KisPopupWidgetInterface; 0036 0037 /** 0038 * Tool proxy object which allows an application to address the current tool. 0039 * 0040 * Applications typically have a canvas and a canvas requires a tool for 0041 * the user to do anything. Since the flake system is responsible for handling 0042 * tools and also to change the active tool when needed we provide one class 0043 * that can be used by an application canvas to route all the native events too 0044 * which will transparently be routed to the active tool. Without the application 0045 * having to bother about which tool is active. 0046 */ 0047 class KRITAFLAKE_EXPORT KoToolProxy : public QObject 0048 { 0049 Q_OBJECT 0050 public: 0051 /** 0052 * Constructor 0053 * @param canvas Each canvas has 1 toolProxy. Pass the parent here. 0054 * @param parent a parent QObject for memory management purposes. 0055 */ 0056 explicit KoToolProxy(KoCanvasBase *canvas, QObject *parent = 0); 0057 ~KoToolProxy() override; 0058 0059 /// Forwarded to the current KoToolBase 0060 void paint(QPainter &painter, const KoViewConverter &converter); 0061 0062 /// Forwarded to the current KoToolBase 0063 void repaintDecorations(); 0064 0065 /// Forwarded to the current KoToolBase 0066 void tabletEvent(QTabletEvent *event, const QPointF &point); 0067 0068 /// Forwarded to the current KoToolBase 0069 void mousePressEvent(QMouseEvent *event, const QPointF &point); 0070 void mousePressEvent(KoPointerEvent *event); 0071 0072 /// Forwarded to the current KoToolBase 0073 void mouseDoubleClickEvent(QMouseEvent *event, const QPointF &point); 0074 void mouseDoubleClickEvent(KoPointerEvent *event); 0075 0076 /// Forwarded to the current KoToolBase 0077 void mouseMoveEvent(QMouseEvent *event, const QPointF &point); 0078 void mouseMoveEvent(KoPointerEvent *event); 0079 0080 /// Forwarded to the current KoToolBase 0081 void mouseReleaseEvent(QMouseEvent *event, const QPointF &point); 0082 void mouseReleaseEvent(KoPointerEvent *event); 0083 0084 /// Forwarded to the current KoToolBase 0085 void keyPressEvent(QKeyEvent *event); 0086 0087 /// Forwarded to the current KoToolBase 0088 void keyReleaseEvent(QKeyEvent *event); 0089 0090 /// Forwarded to the current KoToolBase 0091 void explicitUserStrokeEndRequest(); 0092 0093 /// Forwarded to the current KoToolBase 0094 QVariant inputMethodQuery(Qt::InputMethodQuery query, const KoViewConverter &converter) const; 0095 0096 /// Forwarded to the current KoToolBase 0097 void inputMethodEvent(QInputMethodEvent *event); 0098 0099 /// Forwarded to the current KoToolBase 0100 QMenu* popupActionsMenu(); 0101 0102 /// Forwarded to the current KoToolBase 0103 KisPopupWidgetInterface* popupWidget(); 0104 0105 /// Forwarded to the current KoToolBase 0106 void deleteSelection(); 0107 0108 /// This method gives the proxy a chance to do things. for example it is need to have working singlekey 0109 /// shortcuts. call it from the canvas' event function and forward it to QWidget::event() later. 0110 void processEvent(QEvent *) const; 0111 0112 /// returns true if the current tool holds a selection 0113 bool hasSelection() const; 0114 0115 /// Forwarded to the current KoToolBase 0116 void cut(); 0117 0118 /// Forwarded to the current KoToolBase 0119 void copy() const; 0120 0121 /// Forwarded to the current KoToolBase 0122 bool paste(); 0123 0124 /// Forwarded to the current KoToolBase 0125 void dragMoveEvent(QDragMoveEvent *event, const QPointF &point); 0126 0127 /// Forwarded to the current KoToolBase 0128 void dragLeaveEvent(QDragLeaveEvent *event); 0129 0130 /// Forwarded to the current KoToolBase 0131 void dropEvent(QDropEvent *event, const QPointF &point); 0132 0133 /// Set the new active tool. 0134 virtual void setActiveTool(KoToolBase *tool); 0135 0136 void touchEvent(QTouchEvent* event, const QPointF& point); 0137 0138 KoPointerEvent* lastDeliveredPointerEvent() const; 0139 0140 /// \internal 0141 KoToolProxyPrivate *priv(); 0142 0143 protected Q_SLOTS: 0144 /// Forwarded to the current KoToolBase 0145 void requestUndoDuringStroke(); 0146 0147 /// Forwarded to the current KoToolBase 0148 void requestRedoDuringStroke(); 0149 0150 /// Forwarded to the current KoToolBase 0151 void requestStrokeCancellation(); 0152 0153 /// Forwarded to the current KoToolBase 0154 void requestStrokeEnd(); 0155 0156 Q_SIGNALS: 0157 /** 0158 * A tool can have a selection that is copy-able, this signal is emitted when that status changes. 0159 * @param hasSelection is true when the tool holds selected data. 0160 */ 0161 void selectionChanged(bool hasSelection); 0162 0163 /** 0164 * Emitted every time a tool is changed. 0165 * @param toolId the id of the tool. 0166 * @see KoToolBase::toolId() 0167 */ 0168 void toolChanged(const QString &toolId); 0169 0170 protected: 0171 virtual QPointF widgetToDocument(const QPointF &widgetPoint) const; 0172 KoCanvasBase* canvas() const; 0173 0174 private: 0175 Q_PRIVATE_SLOT(d, void timeout()) 0176 Q_PRIVATE_SLOT(d, void selectionChanged(bool)) 0177 0178 friend class KoToolProxyPrivate; 0179 KoToolProxyPrivate * const d; 0180 }; 0181 0182 #endif // _KO_TOOL_PROXY_H_