Warning, file /office/calligra/libs/flake/KoToolProxy.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (c) 2006, 2010 Boudewijn Rempt <boud@valdyas.org>
0004  * Copyright (C) 2006-2010 Thomas Zander <zander@kde.org>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 #ifndef _KO_TOOL_PROXY_H_
0022 #define _KO_TOOL_PROXY_H_
0023 
0024 #include "flake_export.h"
0025 
0026 #include <QObject>
0027 #include <QHash>
0028 
0029 class QAction;
0030 class QAction;
0031 class QMouseEvent;
0032 class QKeyEvent;
0033 class QWheelEvent;
0034 class QTabletEvent;
0035 class KoCanvasBase;
0036 class KoViewConverter;
0037 class KoToolBase;
0038 class KoToolProxyPrivate;
0039 class QInputMethodEvent;
0040 class KoPointerEvent;
0041 class QDragMoveEvent;
0042 class QDragLeaveEvent;
0043 class QDropEvent;
0044 class QTouchEvent;
0045 class QPainter;
0046 class QPointF;
0047 
0048 /**
0049  * Tool proxy object which allows an application to address the current tool.
0050  *
0051  * Applications typically have a canvas and a canvas requires a tool for
0052  * the user to do anything.  Since the flake system is responsible for handling
0053  * tools and also to change the active tool when needed we provide one class
0054  * that can be used by an application canvas to route all the native events too
0055  * which will transparently be routed to the active tool.  Without the application
0056  * having to bother about which tool is active.
0057  */
0058 class FLAKE_EXPORT KoToolProxy : public QObject
0059 {
0060     Q_OBJECT
0061 public:
0062     /**
0063      * Constructor
0064      * @param canvas Each canvas has 1 toolProxy. Pass the parent here.
0065      * @param parent a parent QObject for memory management purposes.
0066      */
0067     explicit KoToolProxy(KoCanvasBase *canvas, QObject *parent = 0);
0068     ~KoToolProxy() override;
0069 
0070     /// Forwarded to the current KoToolBase
0071     void paint(QPainter &painter, const KoViewConverter &converter);
0072 
0073     /// Forwarded to the current KoToolBase
0074     void repaintDecorations();
0075 
0076     /**
0077      * Forward the given touch event to the current KoToolBase.
0078      * The viewconverter and document offset are necessary to convert all
0079      * the QTouchPoints to KoTouchPoints that work in document coordinates.
0080      */
0081     void touchEvent(QTouchEvent *event);
0082 
0083     /// Forwarded to the current KoToolBase
0084     void tabletEvent(QTabletEvent *event, const QPointF &point);
0085 
0086     /// Forwarded to the current KoToolBase
0087     void mousePressEvent(QMouseEvent *event, const QPointF &point);
0088     void mousePressEvent(KoPointerEvent *event);
0089 
0090     /// Forwarded to the current KoToolBase
0091     void mouseDoubleClickEvent(QMouseEvent *event, const QPointF &point);
0092     void mouseDoubleClickEvent(KoPointerEvent *event);
0093 
0094     /// Forwarded to the current KoToolBase
0095     void mouseMoveEvent(QMouseEvent *event, const QPointF &point);
0096     void mouseMoveEvent(KoPointerEvent *event);
0097 
0098     /// Forwarded to the current KoToolBase
0099     void mouseReleaseEvent(QMouseEvent *event, const QPointF &point);
0100     void mouseReleaseEvent(KoPointerEvent *event);
0101 
0102     /// Forwarded to the current KoToolBase
0103     void shortcutOverrideEvent(QKeyEvent *event);
0104 
0105     /// Forwarded to the current KoToolBase
0106     void keyPressEvent(QKeyEvent *event);
0107 
0108     /// Forwarded to the current KoToolBase
0109     void keyReleaseEvent(QKeyEvent *event);
0110 
0111     /// Forwarded to the current KoToolBase
0112     void wheelEvent(QWheelEvent * event, const QPointF &point);
0113     void wheelEvent(KoPointerEvent *event);
0114 
0115     /// Forwarded to the current KoToolBase
0116     QVariant inputMethodQuery(Qt::InputMethodQuery query, const KoViewConverter &converter) const;
0117 
0118     /// Forwarded to the current KoToolBase
0119     void inputMethodEvent(QInputMethodEvent *event);
0120 
0121     /// Forwarded to the current KoToolBase
0122     QList<QAction*> popupActionList() const;
0123 
0124     /// Forwarded to the current KoToolBase
0125     void deleteSelection();
0126 
0127     /// This method gives the proxy a chance to do things. for example it is need to have working singlekey
0128     /// shortcuts. call it from the canvas' event function and forward it to QWidget::event() later.
0129     void processEvent(QEvent *);
0130 
0131     /**
0132      * Retrieves the entire collection of actions for the active tool
0133      * or an empty hash if there is no active tool yet.
0134      */
0135     QHash<QString, QAction *> actions() const;
0136 
0137     /// returns true if the current tool holds a selection
0138     bool hasSelection() const;
0139 
0140     /// Forwarded to the current KoToolBase
0141     void cut();
0142 
0143     /// Forwarded to the current KoToolBase
0144     void copy() const;
0145 
0146     /// Forwarded to the current KoToolBase
0147     bool paste();
0148 
0149     /// Forwarded to the current KoToolBase
0150     QStringList supportedPasteMimeTypes() const;
0151 
0152     /// Forwarded to the current KoToolBase
0153     void dragMoveEvent(QDragMoveEvent *event, const QPointF &point);
0154 
0155     /// Forwarded to the current KoToolBase
0156     void dragLeaveEvent(QDragLeaveEvent *event);
0157 
0158     /// Forwarded to the current KoToolBase
0159     void dropEvent(QDropEvent *event, const QPointF &point);
0160  
0161     /// Set the new active tool.
0162     virtual void setActiveTool(KoToolBase *tool);
0163 
0164     /// \internal
0165     KoToolProxyPrivate *priv();
0166 
0167 Q_SIGNALS:
0168     /**
0169      * A tool can have a selection that is copy-able, this signal is emitted when that status changes.
0170      * @param hasSelection is true when the tool holds selected data.
0171      */
0172     void selectionChanged(bool hasSelection);
0173 
0174     /**
0175      * Emitted every time a tool is changed.
0176      * @param toolId the id of the tool.
0177      * @see KoToolBase::toolId()
0178      */
0179     void toolChanged(const QString &toolId);
0180 
0181 protected:
0182     virtual QPointF widgetToDocument(const QPointF &widgetPoint) const;
0183     KoCanvasBase* canvas() const;
0184 
0185 private:
0186     Q_PRIVATE_SLOT(d, void timeout())
0187     Q_PRIVATE_SLOT(d, void selectionChanged(bool))
0188 
0189     friend class KoToolProxyPrivate;
0190     KoToolProxyPrivate * const d;
0191 };
0192 
0193 #endif // _KO_TOOL_PROXY_H_