File indexing completed on 2024-05-19 04:36:37

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2014 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TIKZ_UI_ABSTRACT_TOOL_H
0021 #define TIKZ_UI_ABSTRACT_TOOL_H
0022 
0023 #include "tikzui_export.h"
0024 #include <QObject>
0025 
0026 class QGraphicsSceneMouseEvent;
0027 class QKeyEvent;
0028 class QPointF;
0029 class QGraphicsScene;
0030 
0031 namespace tikz {
0032 namespace ui {
0033 
0034 class Document;
0035 
0036 /**
0037  * The AbstractTool provides an interface for arbitrary tools operating on the
0038  * graphics scene.
0039  *
0040  * The graphics scene forwards all key and mouse events to this tool handler.
0041  * This way, child classes can show interactive tools to the user with which
0042  * e.g. new nodes or edges can be created etc.
0043  */
0044 class TIKZKITUI_EXPORT AbstractTool : public QObject
0045 {
0046     Q_OBJECT
0047 
0048     public:
0049         /**
0050          * Constructor with graphics scene @p scene.
0051          */
0052         AbstractTool(tikz::ui::Document * doc, QGraphicsScene * scene);
0053 
0054         /**
0055          * Virtual destructor.
0056          */
0057         virtual ~AbstractTool();
0058 
0059         /**
0060          * Returns the graphics scene this tool works on.
0061          */
0062         QGraphicsScene * scene() const;
0063 
0064         /**
0065          * Returns the Document this tool works on.
0066          */
0067         tikz::ui::Document * document() const;
0068 
0069     //
0070     // sub classes: reimplement as needed
0071     //
0072     public:
0073         /**
0074          * This function is called whenever the mouse enters the graphics scene.
0075          * The default implementation does nothing.
0076          */
0077         virtual void mouseEnteredScene();
0078 
0079         /**
0080          * This function is called whenever the mouse leaves the graphics scene.
0081          * The default implementation does nothing.
0082          */
0083         virtual void mouseLeftScene();
0084 
0085         /**
0086          * This function is called whenever the mouse moves in the graphics
0087          * scene.
0088          */
0089         virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event) = 0;
0090 
0091         /**
0092          * This function is called whenever a mouse button is pressed in the
0093          * graphics scene.
0094          */
0095         virtual void mousePressEvent(QGraphicsSceneMouseEvent * event) = 0;
0096 
0097         /**
0098          * This function is called whenever a mouse button is released in the
0099          * graphics scene.
0100          */
0101         virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event) = 0;
0102 
0103         /**
0104          * This function is called whenever a key is pressed.
0105          * By default, the key press event is ignored.
0106          * @param event key event
0107          */
0108         virtual void keyPressEvent(QKeyEvent * event);
0109 
0110     private:
0111         // pointer to the Document
0112         tikz::ui::Document * m_document;
0113         // pointer to graphics scene
0114         QGraphicsScene * m_scene;
0115 };
0116 
0117 }
0118 }
0119 
0120 #endif // TIKZ_UI_ABSTRACT_TOOL_H
0121 
0122 // kate: indent-width 4; replace-tabs on;