Warning, file /graphics/krita/plugins/tools/tool_enclose_and_fill/subtools/KisDynamicDelegatedTool.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * KDE. Krita Project. 0003 * 0004 * SPDX-FileCopyrightText: 2021 Deif Lou <ginoba@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KISDYNAMICDELEGATEDTOOL_H 0010 #define KISDYNAMICDELEGATEDTOOL_H 0011 0012 #include <functional> 0013 #include <type_traits> 0014 0015 #include <KoToolBase.h> 0016 #include <KoToolBase_p.h> 0017 #include <KoToolFactoryBase.h> 0018 #include <KoCanvasBase.h> 0019 #include <KoPointerEvent.h> 0020 #include <KoDocumentResourceManager.h> 0021 #include <KoCanvasResourceProvider.h> 0022 #include <KoViewConverter.h> 0023 #include <KoShapeController.h> 0024 #include <KoShapeControllerBase.h> 0025 #include <KoToolSelection.h> 0026 #include <KoCanvasController.h> 0027 0028 template <typename BaseClass> 0029 class KisDynamicDelegateTool : public BaseClass 0030 { 0031 public: 0032 template <typename ... Args> 0033 explicit KisDynamicDelegateTool(Args ... args) : BaseClass(args...) {} 0034 KisDynamicDelegateTool() = delete; 0035 KisDynamicDelegateTool(const KisDynamicDelegateTool&) = delete; 0036 KisDynamicDelegateTool& operator=(const KisDynamicDelegateTool&) = delete; 0037 ~KisDynamicDelegateTool() override {} 0038 0039 using BaseClass::createOptionWidget; 0040 using BaseClass::listeningToModifiers; 0041 using BaseClass::listenToModifiers; 0042 using BaseClass::cursor; 0043 using BaseClass::setMode; 0044 using BaseClass::mode; 0045 using BaseClass::setCursor; 0046 using BaseClass::resetCursorStyle; 0047 using BaseClass::canvasResourceChanged; 0048 using BaseClass::paint; 0049 using BaseClass::activatePrimaryAction; 0050 using BaseClass::deactivatePrimaryAction; 0051 using BaseClass::activateAlternateAction; 0052 using BaseClass::deactivateAlternateAction; 0053 using BaseClass::beginAlternateAction; 0054 using BaseClass::continueAlternateAction; 0055 using BaseClass::endAlternateAction; 0056 using BaseClass::requestUpdateOutline; 0057 using BaseClass::getOutlinePath; 0058 }; 0059 0060 template <typename BaseClass> 0061 class KisDynamicDelegatedTool : public BaseClass 0062 { 0063 public: 0064 using DelegateType = KisDynamicDelegateTool<BaseClass>; 0065 0066 explicit KisDynamicDelegatedTool(KoCanvasBase *canvas, const QCursor &cursor) 0067 : BaseClass(canvas, cursor) 0068 , m_delegateTool(nullptr) 0069 {} 0070 0071 KisDynamicDelegatedTool() = delete; 0072 KisDynamicDelegatedTool(const KisDynamicDelegatedTool&) = delete; 0073 KisDynamicDelegatedTool& operator=(const KisDynamicDelegatedTool&) = delete; 0074 0075 ~KisDynamicDelegatedTool() override 0076 { 0077 if (m_delegateTool) { 0078 delete m_delegateTool; 0079 } 0080 } 0081 0082 DelegateType* delegateTool() const 0083 { 0084 return m_delegateTool; 0085 } 0086 0087 void setDelegateTool(DelegateType *newDelegateTool) 0088 { 0089 if (m_delegateTool == newDelegateTool) { 0090 return; 0091 } 0092 if (m_delegateTool) { 0093 delete m_delegateTool; 0094 } 0095 m_delegateTool = newDelegateTool; 0096 if (m_delegateTool) { 0097 BaseClass::connect(m_delegateTool, SIGNAL(activateTool(QString)), SIGNAL(activateTool(QString))); 0098 BaseClass::connect(m_delegateTool, &DelegateType::cursorChanged, [this](const QCursor &c) { this->BaseClass::useCursor(c); }); 0099 BaseClass::connect(m_delegateTool, SIGNAL(selectionChanged(bool)), SIGNAL(selectionChanged(bool))); 0100 BaseClass::connect(m_delegateTool, SIGNAL(statusTextChanged(QString)), SIGNAL(statusTextChanged(QString))); 0101 } 0102 } 0103 0104 QRectF decorationsRect() const override 0105 { 0106 if (m_delegateTool) return m_delegateTool->decorationsRect(); 0107 return QRect(); 0108 } 0109 0110 bool wantsAutoScroll() const override 0111 { 0112 if (m_delegateTool) return m_delegateTool->wantsAutoScroll(); 0113 return false; 0114 } 0115 0116 void paint(QPainter &painter, const KoViewConverter &converter) override 0117 { 0118 if (m_delegateTool) m_delegateTool->paint(painter, converter); 0119 } 0120 0121 void mousePressEvent(KoPointerEvent *event) override 0122 { 0123 if (m_delegateTool) m_delegateTool->mousePressEvent(event); 0124 } 0125 0126 void mouseDoubleClickEvent(KoPointerEvent *event) override 0127 { 0128 if (m_delegateTool) m_delegateTool->mouseDoubleClickEvent(event); 0129 } 0130 0131 void mouseTripleClickEvent(KoPointerEvent *event) override 0132 { 0133 if (m_delegateTool) m_delegateTool->mouseTripleClickEvent(event); 0134 } 0135 0136 void mouseMoveEvent(KoPointerEvent *event) override 0137 { 0138 if (m_delegateTool) m_delegateTool->mouseMoveEvent(event); 0139 } 0140 0141 void mouseReleaseEvent(KoPointerEvent *event) override 0142 { 0143 if (m_delegateTool) m_delegateTool->mouseReleaseEvent(event); 0144 } 0145 0146 void keyPressEvent(QKeyEvent *event) override 0147 { 0148 if (m_delegateTool) m_delegateTool->keyPressEvent(event); 0149 } 0150 0151 void keyReleaseEvent(QKeyEvent *event) override 0152 { 0153 if (m_delegateTool) m_delegateTool->keyReleaseEvent(event); 0154 } 0155 0156 void explicitUserStrokeEndRequest() override 0157 { 0158 if (m_delegateTool) m_delegateTool->explicitUserStrokeEndRequest(); 0159 } 0160 0161 QMenu* popupActionsMenu() override 0162 { 0163 if (m_delegateTool) return m_delegateTool->popupActionsMenu(); 0164 return nullptr; 0165 } 0166 0167 KisPopupWidgetInterface* popupWidget() override 0168 { 0169 if (m_delegateTool) return m_delegateTool->popupWidget(); 0170 return nullptr; 0171 } 0172 0173 void activatePrimaryAction() override 0174 { 0175 if (m_delegateTool) m_delegateTool->activatePrimaryAction(); 0176 } 0177 0178 void deactivatePrimaryAction() override 0179 { 0180 if (m_delegateTool) m_delegateTool->deactivatePrimaryAction(); 0181 } 0182 0183 void beginPrimaryAction(KoPointerEvent *event) override 0184 { 0185 if (m_delegateTool) m_delegateTool->beginPrimaryAction(event); 0186 } 0187 0188 void continuePrimaryAction(KoPointerEvent *event) override 0189 { 0190 if (m_delegateTool) m_delegateTool->continuePrimaryAction(event); 0191 } 0192 0193 void endPrimaryAction(KoPointerEvent *event) override 0194 { 0195 if (m_delegateTool) m_delegateTool->endPrimaryAction(event); 0196 } 0197 0198 void beginPrimaryDoubleClickAction(KoPointerEvent *event) override 0199 { 0200 if (m_delegateTool) m_delegateTool->beginPrimaryDoubleClickAction(event); 0201 } 0202 0203 bool primaryActionSupportsHiResEvents() const override 0204 { 0205 if (m_delegateTool) return m_delegateTool->primaryActionSupportsHiResEvents(); 0206 return false; 0207 } 0208 0209 void activateAlternateAction(typename BaseClass::AlternateAction action) override 0210 { 0211 if (m_delegateTool) m_delegateTool->activateAlternateAction(action); 0212 } 0213 0214 void deactivateAlternateAction(typename BaseClass::AlternateAction action) override 0215 { 0216 if (m_delegateTool) m_delegateTool->deactivateAlternateAction(action); 0217 } 0218 0219 void beginAlternateAction(KoPointerEvent *event, typename BaseClass::AlternateAction action) override 0220 { 0221 if (m_delegateTool) m_delegateTool->beginAlternateAction(event, action); 0222 } 0223 0224 void continueAlternateAction(KoPointerEvent *event, typename BaseClass::AlternateAction action) override 0225 { 0226 if (m_delegateTool) m_delegateTool->continueAlternateAction(event, action); 0227 } 0228 0229 void endAlternateAction(KoPointerEvent *event, typename BaseClass::AlternateAction action) override 0230 { 0231 if (m_delegateTool) m_delegateTool->endAlternateAction(event, action); 0232 } 0233 0234 void beginAlternateDoubleClickAction(KoPointerEvent *event, typename BaseClass::AlternateAction action) override 0235 { 0236 if (m_delegateTool) m_delegateTool->beginAlternateDoubleClickAction(event, action); 0237 } 0238 0239 bool alternateActionSupportsHiResEvents(typename BaseClass::AlternateAction action) const override 0240 { 0241 if (m_delegateTool) return m_delegateTool->alternateActionSupportsHiResEvents(action); 0242 return false; 0243 } 0244 0245 void newActivationWithExternalSource(KisPaintDeviceSP externalSource) override 0246 { 0247 if (m_delegateTool) m_delegateTool->newActivationWithExternalSource(externalSource); 0248 } 0249 0250 void requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event) override 0251 { 0252 if (m_delegateTool) m_delegateTool->requestUpdateOutline(outlineDocPoint, event); 0253 } 0254 0255 public Q_SLOTS: 0256 void requestUndoDuringStroke() override 0257 { 0258 if (m_delegateTool) m_delegateTool->requestUndoDuringStroke(); 0259 } 0260 0261 void requestRedoDuringStroke() override 0262 { 0263 if (m_delegateTool) m_delegateTool->requestRedoDuringStroke(); 0264 } 0265 0266 void requestStrokeCancellation() override 0267 { 0268 if (m_delegateTool) m_delegateTool->requestStrokeCancellation(); 0269 } 0270 0271 void requestStrokeEnd() override 0272 { 0273 if (m_delegateTool) m_delegateTool->requestStrokeEnd(); 0274 } 0275 0276 void activate(const QSet<KoShape*> &shapes) override 0277 { 0278 if (m_delegateTool) m_delegateTool->activate(shapes); 0279 KisTool::activate(shapes); 0280 } 0281 0282 void deactivate() override 0283 { 0284 if (m_delegateTool) m_delegateTool->deactivate(); 0285 KisTool::deactivate(); 0286 } 0287 0288 void canvasResourceChanged(int key, const QVariant &res) override 0289 { 0290 if (m_delegateTool) m_delegateTool->canvasResourceChanged(key, res); 0291 } 0292 0293 void documentResourceChanged(int key, const QVariant &res) override 0294 { 0295 if (m_delegateTool) m_delegateTool->documentResourceChanged(key, res); 0296 } 0297 0298 void repaintDecorations() override 0299 { 0300 if (m_delegateTool) m_delegateTool->repaintDecorations(); 0301 } 0302 0303 void updateSettingsViews() override 0304 { 0305 if (m_delegateTool) m_delegateTool->updateSettingsViews(); 0306 } 0307 0308 protected: 0309 QWidget* createOptionWidget() override 0310 { 0311 if (m_delegateTool) return m_delegateTool->createOptionWidget(); 0312 return nullptr; 0313 } 0314 0315 bool listeningToModifiers() override 0316 { 0317 if (m_delegateTool) return m_delegateTool->listeningToModifiers(); 0318 return false; 0319 } 0320 0321 void listenToModifiers(bool listen) override 0322 { 0323 if (m_delegateTool) m_delegateTool->listenToModifiers(listen); 0324 } 0325 0326 QCursor cursor() const 0327 { 0328 if (m_delegateTool) return m_delegateTool->cursor(); 0329 return BaseClass::cursor(); 0330 } 0331 0332 void setCursor(const QCursor &cursor) 0333 { 0334 if (m_delegateTool) m_delegateTool->setCursor(cursor); 0335 BaseClass::setCursor(cursor); 0336 } 0337 0338 void setMode(typename BaseClass::ToolMode mode) override 0339 { 0340 if (m_delegateTool) m_delegateTool->setMode(mode); 0341 BaseClass::setMode(mode); 0342 } 0343 0344 typename BaseClass::ToolMode mode() const override 0345 { 0346 if (m_delegateTool) return m_delegateTool->mode(); 0347 return BaseClass::mode(); 0348 } 0349 0350 protected Q_SLOTS: 0351 void resetCursorStyle() override 0352 { 0353 if (m_delegateTool) m_delegateTool->resetCursorStyle(); 0354 BaseClass::resetCursorStyle(); 0355 } 0356 0357 private: 0358 DelegateType *m_delegateTool; 0359 0360 }; 0361 0362 #endif