Warning, file /office/calligra/libs/flake/KoToolManager_p.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 * Copyright (C) 2006 Thomas Zander <zander@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #ifndef KO_TOOL_MANAGER_P 0020 #define KO_TOOL_MANAGER_P 0021 0022 #include <QList> 0023 #include <QObject> 0024 #include <QString> 0025 #include <QTimer> 0026 #include <QHash> 0027 0028 #include <QKeySequence> 0029 #include <QAction> 0030 0031 #include "KoInputDevice.h" 0032 #include "KoToolManager.h" 0033 0034 class KoToolFactoryBase; 0035 class KoShapeManager; 0036 class KoCanvasBase; 0037 class KoToolBase; 0038 class KoShape; 0039 class KoToolManager; 0040 class KoCanvasController; 0041 class KoShapeLayer; 0042 class ToolHelper; 0043 class CanvasData; 0044 class KoToolProxy; 0045 0046 class Q_DECL_HIDDEN KoToolManager::Private 0047 { 0048 public: 0049 Private(KoToolManager *qq); 0050 ~Private(); 0051 0052 void setup(); 0053 0054 void connectActiveTool(); 0055 void disconnectActiveTool(); 0056 void switchTool(KoToolBase *tool, bool temporary); 0057 void switchTool(const QString &id, bool temporary); 0058 void postSwitchTool(bool temporary); 0059 void switchCanvasData(CanvasData *cd); 0060 0061 bool eventFilter(QObject *object, QEvent *event); 0062 void toolActivated(ToolHelper *tool); 0063 0064 void detachCanvas(KoCanvasController *controller); 0065 void attachCanvas(KoCanvasController *controller); 0066 void movedFocus(QWidget *from, QWidget *to); 0067 void updateCursor(const QCursor &cursor); 0068 void switchBackRequested(); 0069 void selectionChanged(const QList<KoShape*> &shapes); 0070 void currentLayerChanged(const KoShapeLayer *layer); 0071 void updateToolForProxy(); 0072 void switchToolTemporaryRequested(const QString &id); 0073 CanvasData *createCanvasData(KoCanvasController *controller, const KoInputDevice &device); 0074 0075 /** 0076 * Request a switch from to the param input device. 0077 * This will cause the tool for that device to be selected. 0078 */ 0079 void switchInputDevice(const KoInputDevice &device); 0080 0081 /** 0082 * Whenever a new tool proxy class is instantiated, it will use this method to register itself 0083 * so the toolManager can update it to the latest active tool. 0084 * @param proxy the proxy to register. 0085 * @param canvas which canvas the proxy is associated with; whenever a new tool is selected for that canvas, 0086 * the proxy gets an update. 0087 */ 0088 void registerToolProxy(KoToolProxy *proxy, KoCanvasBase *canvas); 0089 0090 void switchToolByShortcut(QKeyEvent *event); 0091 0092 0093 KoToolManager *q; 0094 0095 QList<ToolHelper*> tools; // list of all available tools via their factories. 0096 0097 QHash<KoToolBase*, int> uniqueToolIds; // for the changedTool signal 0098 QHash<KoCanvasController*, QList<CanvasData*> > canvasses; 0099 QHash<KoCanvasBase*, KoToolProxy*> proxies; 0100 0101 CanvasData *canvasData; // data about the active canvas. 0102 0103 KoInputDevice inputDevice; 0104 0105 bool layerExplicitlyDisabled; 0106 }; 0107 0108 class ShortcutToolAction; 0109 0110 /// \internal 0111 class ToolHelper : public QObject 0112 { 0113 Q_OBJECT 0114 public: 0115 explicit ToolHelper(KoToolFactoryBase *tool); 0116 KoToolAction *toolAction(); 0117 /// wrapper around KoToolFactoryBase::id(); 0118 QString id() const; 0119 /// wrapper around KoToolFactoryBase::iconName(); 0120 QString iconName() const; 0121 /// descriptive text, as ; 0122 QString text() const; 0123 /// descriptive icon text, e.g. use on a button next to an icon or without one; 0124 QString iconText() const; 0125 /// tooltip of the tool, e.g. for tooltip of a button; 0126 QString toolTip() const; 0127 /// wrapper around KoToolFactoryBase::toolType(); 0128 QString toolType() const; 0129 /// wrapper around KoToolFactoryBase::activationShapeId(); 0130 QString activationShapeId() const; 0131 /// wrapper around KoToolFactoryBase::priority(); 0132 int priority() const; 0133 KoToolBase *createTool(KoCanvasBase *canvas) const; 0134 ShortcutToolAction *createShortcutToolAction(QObject *parent); 0135 /// unique id, >= 0 0136 int uniqueId() const { 0137 return m_uniqueId; 0138 } 0139 /// QAction->shortcut() if it exists, otherwise KoToolFactoryBase::shortcut() 0140 QKeySequence shortcut() const; 0141 0142 public Q_SLOTS: 0143 void activate(); 0144 0145 Q_SIGNALS: 0146 /// Emitted when the tool should be activated, e.g. by pressing the tool's assigned button in the toolbox 0147 void toolActivated(ToolHelper *tool); 0148 0149 private Q_SLOTS: 0150 void shortcutToolActionUpdated(); 0151 0152 private: 0153 KoToolFactoryBase * const m_toolFactory; 0154 const int m_uniqueId; 0155 QKeySequence m_customShortcut; 0156 bool m_hasCustomShortcut; 0157 KoToolAction *m_toolAction; 0158 }; 0159 0160 /// \internal 0161 /// Helper class to transform a simple signal selection changed into a signal with a parameter 0162 class Connector : public QObject 0163 { 0164 Q_OBJECT 0165 public: 0166 explicit Connector(KoShapeManager *parent); 0167 0168 public Q_SLOTS: 0169 void selectionChanged(); 0170 0171 Q_SIGNALS: 0172 void selectionChanged(const QList<KoShape*> &shape); 0173 0174 private: 0175 KoShapeManager *m_shapeManager; 0176 }; 0177 0178 /// \internal 0179 /// Helper class to provide a action for tool shortcuts 0180 class ShortcutToolAction : public QAction 0181 { 0182 Q_OBJECT 0183 public: 0184 ShortcutToolAction(const QString &id, const QString &name, QObject *parent); 0185 ~ShortcutToolAction() override; 0186 0187 private Q_SLOTS: 0188 void actionTriggered(); 0189 0190 private: 0191 QString m_toolID; 0192 }; 0193 0194 #endif