File indexing completed on 2024-05-19 05:42:19
0001 // ct_lvtqtw_itool.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef INCLUDED_LVTQTC_ITOOL 0021 #define INCLUDED_LVTQTC_ITOOL 0022 0023 #include <lvtqtc_export.h> 0024 0025 #include <QGraphicsView> 0026 #include <QIcon> 0027 #include <QLoggingCategory> 0028 #include <QObject> 0029 #include <QUndoCommand> 0030 0031 #include <KMessageWidget> 0032 0033 #include <memory> 0034 0035 Q_DECLARE_LOGGING_CATEGORY(LogTool) 0036 0037 class QMouseEvent; 0038 class QGraphicsSceneMouseEvent; 0039 class QToolButton; 0040 0041 namespace Codethink::lvtldr { 0042 class NodeStorage; 0043 } 0044 0045 namespace Codethink::lvtqtc { 0046 class GraphicsView; 0047 class GraphicsScene; 0048 0049 class LVTQTC_EXPORT ITool : public QObject { 0050 /* ITool. Interface for Tools that acts on the canvas. 0051 * An active tool has access to mouse and keyboard presses, and can act directly on 0052 * the view (the QGraphicsView) or the scene (QGraphicsScene) adding items, 0053 * triggering state changes, moving things around, etc. 0054 */ 0055 Q_OBJECT 0056 0057 public: 0058 ~ITool() noexcept override; 0059 0060 [[nodiscard]] QAction *action() const; 0061 [[nodiscard]] QString name() const; 0062 [[nodiscard]] QString toolTip() const; 0063 [[nodiscard]] QIcon icon() const; 0064 0065 void setEnabled(bool enabled); 0066 0067 virtual void activate(); 0068 // sets this tool as the active one. 0069 0070 virtual void deactivate(); 0071 // deactivates the tool. 0072 0073 // Those acts on the View. 0074 virtual void mousePressEvent(QMouseEvent *event); 0075 virtual void mouseMoveEvent(QMouseEvent *event); 0076 virtual void mouseReleaseEvent(QMouseEvent *event); 0077 virtual void drawForeground(QPainter *painter, const QRectF& rect); 0078 0079 // those acts on the scene 0080 virtual void sceneMousePressEvent(QGraphicsSceneMouseEvent *event); 0081 virtual void sceneMouseMoveEvent(QGraphicsSceneMouseEvent *event); 0082 virtual void sceneMouseReleaseEvent(QGraphicsSceneMouseEvent *event); 0083 0084 virtual void keyPressEvent(QKeyEvent *event); 0085 virtual void keyReleaseEvent(QKeyEvent *event); 0086 0087 bool eventFilter(QObject *obj, QEvent *ev) override; 0088 0089 Q_SIGNAL void activated(); 0090 Q_SIGNAL void deactivated(); 0091 Q_SIGNAL void undoCommandCreated(QUndoCommand *undoCommand); 0092 Q_SIGNAL void sendMessage(const QString& message, KMessageWidget::MessageType type); 0093 0094 protected: 0095 ITool(const QString& name, const QString& tooltip, const QIcon& icon, GraphicsView *gv); 0096 0097 [[nodiscard]] GraphicsView *graphicsView() const; 0098 [[nodiscard]] GraphicsScene *graphicsScene() const; 0099 0100 private: 0101 void setupInfra(bool install); 0102 struct Private; 0103 std::unique_ptr<Private> d; 0104 }; 0105 0106 } // namespace Codethink::lvtqtc 0107 0108 #endif