File indexing completed on 2024-05-19 04:25:00

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 QFocusEvent;
0033 class QPainter;
0034 class QPointF;
0035 class QMenu;
0036 class KisPopupWidgetInterface;
0037 
0038 /**
0039  * Tool proxy object which allows an application to address the current tool.
0040  *
0041  * Applications typically have a canvas and a canvas requires a tool for
0042  * the user to do anything.  Since the flake system is responsible for handling
0043  * tools and also to change the active tool when needed we provide one class
0044  * that can be used by an application canvas to route all the native events too
0045  * which will transparently be routed to the active tool.  Without the application
0046  * having to bother about which tool is active.
0047  */
0048 class KRITAFLAKE_EXPORT KoToolProxy : public QObject
0049 {
0050     Q_OBJECT
0051 public:
0052     /**
0053      * Constructor
0054      * @param canvas Each canvas has 1 toolProxy. Pass the parent here.
0055      * @param parent a parent QObject for memory management purposes.
0056      */
0057     explicit KoToolProxy(KoCanvasBase *canvas, QObject *parent = 0);
0058     ~KoToolProxy() override;
0059 
0060     /// Forwarded to the current KoToolBase
0061     void paint(QPainter &painter, const KoViewConverter &converter);
0062 
0063     /// Forwarded to the current KoToolBase
0064     void repaintDecorations();
0065 
0066     /// Forwarded to the current KoToolBase
0067     void tabletEvent(QTabletEvent *event, const QPointF &point);
0068 
0069     /// Forwarded to the current KoToolBase
0070     void mousePressEvent(QMouseEvent *event, const QPointF &point);
0071     void mousePressEvent(KoPointerEvent *event);
0072 
0073     /// Forwarded to the current KoToolBase
0074     void mouseDoubleClickEvent(QMouseEvent *event, const QPointF &point);
0075     void mouseDoubleClickEvent(KoPointerEvent *event);
0076 
0077     /// Forwarded to the current KoToolBase
0078     void mouseMoveEvent(QMouseEvent *event, const QPointF &point);
0079     void mouseMoveEvent(KoPointerEvent *event);
0080 
0081     /// Forwarded to the current KoToolBase
0082     void mouseReleaseEvent(QMouseEvent *event, const QPointF &point);
0083     void mouseReleaseEvent(KoPointerEvent *event);
0084 
0085     /// Forwarded to the current KoToolBase
0086     void keyPressEvent(QKeyEvent *event);
0087 
0088     /// Forwarded to the current KoToolBase
0089     void keyReleaseEvent(QKeyEvent *event);
0090 
0091     /// Forwarded to the current KoToolBase
0092     void explicitUserStrokeEndRequest();
0093 
0094     /// Forwarded to the current KoToolBase
0095     QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
0096 
0097     /// Forwarded to the current KoToolBase
0098     void inputMethodEvent(QInputMethodEvent *event);
0099 
0100     /// Forwarded to the current KoToolBase
0101     void focusInEvent(QFocusEvent *event);
0102 
0103     /// Forwarded to the current KoToolBase
0104     void focusOutEvent(QFocusEvent *event);
0105 
0106     /// Forwarded to the current KoToolBase
0107     QMenu* popupActionsMenu();
0108 
0109     /// Forwarded to the current KoToolBase
0110     KisPopupWidgetInterface* popupWidget();
0111 
0112     /// Forwarded to the current KoToolBase
0113     void deleteSelection();
0114 
0115     /// This method gives the proxy a chance to do things. for example it is need to have working singlekey
0116     /// shortcuts. call it from the canvas' event function and forward it to QWidget::event() later.
0117     void processEvent(QEvent *) const;
0118 
0119     /// returns true if the current tool holds a selection
0120     bool hasSelection() const;
0121 
0122     /// Forwarded to the current KoToolBase
0123     void cut();
0124 
0125     /// Forwarded to the current KoToolBase
0126     void copy() const;
0127 
0128     /// Forwarded to the current KoToolBase
0129     bool paste();
0130 
0131     /// Forwarded to the current KoToolBase
0132     bool selectAll();
0133 
0134     /// Forwarded to the current KoToolBase
0135     void deselect();
0136 
0137     /// Forwarded to the current KoToolBase
0138     void dragMoveEvent(QDragMoveEvent *event, const QPointF &point);
0139 
0140     /// Forwarded to the current KoToolBase
0141     void dragLeaveEvent(QDragLeaveEvent *event);
0142 
0143     /// Forwarded to the current KoToolBase
0144     void dropEvent(QDropEvent *event, const QPointF &point);
0145 
0146     /// Set the new active tool.
0147     virtual void setActiveTool(KoToolBase *tool);
0148 
0149     void touchEvent(QTouchEvent* event, const QPointF& point);
0150 
0151     KoPointerEvent* lastDeliveredPointerEvent() const;
0152 
0153     QVector<QKeySequence> toolPriorityShortcuts() const;
0154 
0155     /// \internal
0156     KoToolProxyPrivate *priv();
0157 
0158 protected Q_SLOTS:
0159     /// Forwarded to the current KoToolBase
0160     void requestUndoDuringStroke();
0161 
0162     /// Forwarded to the current KoToolBase
0163     void requestRedoDuringStroke();
0164 
0165     /// Forwarded to the current KoToolBase
0166     void requestStrokeCancellation();
0167 
0168     /// Forwarded to the current KoToolBase
0169     void requestStrokeEnd();
0170 
0171 Q_SIGNALS:
0172     /**
0173      * A tool can have a selection that is copy-able, this signal is emitted when that status changes.
0174      * @param hasSelection is true when the tool holds selected data.
0175      */
0176     void selectionChanged(bool hasSelection);
0177 
0178     /**
0179      * Emitted every time a tool is changed.
0180      * @param toolId the id of the tool.
0181      * @see KoToolBase::toolId()
0182      */
0183     void toolChanged(const QString &toolId);
0184 
0185 protected:
0186     virtual QPointF widgetToDocument(const QPointF &widgetPoint) const;
0187     KoCanvasBase* canvas() const;
0188 
0189 
0190 private:
0191     Q_PRIVATE_SLOT(d, void timeout())
0192     Q_PRIVATE_SLOT(d, void selectionChanged(bool))
0193 
0194     void countMultiClick(KoPointerEvent *ev, int eventType);
0195 
0196     friend class KoToolProxyPrivate;
0197     KoToolProxyPrivate * const d;
0198 };
0199 
0200 #endif // _KO_TOOL_PROXY_H_