File indexing completed on 2024-05-19 04:24:59

0001 /*
0002  * SPDX-FileCopyrightText: 2006-2010 Thomas Zander <zander@kde.org>
0003  * SPDX-FileCopyrightText: 2010 Halla Rempt <halla@valdyas.org>
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOTOOLBASE_P_H
0008 #define KOTOOLBASE_P_H
0009 
0010 #include "KoDocumentResourceManager.h"
0011 #include "KoCanvasResourceProvider.h"
0012 #include "KoCanvasBase.h"
0013 #include "KoShapeController.h"
0014 #include <QHash>
0015 #include <QWidget>
0016 #include <QString>
0017 #include <QPointer>
0018 #include <string.h> // for the qt version check
0019 
0020 class QAction;
0021 class KoToolBase;
0022 class KoToolFactoryBase;
0023 
0024 class KoToolBasePrivate
0025 {
0026 public:
0027     KoToolBasePrivate(KoToolBase *qq, KoCanvasBase *canvas_)
0028         : currentCursor(Qt::ArrowCursor),
0029         q(qq),
0030         canvas(canvas_),
0031         isInTextMode(false),
0032         isActivated(false)
0033     {
0034     }
0035 
0036     virtual ~KoToolBasePrivate()
0037     {
0038         Q_FOREACH (QPointer<QWidget> optionWidget, optionWidgets) {
0039             if (optionWidget) {
0040                 optionWidget->setParent(0);
0041                 delete optionWidget;
0042             }
0043         }
0044         optionWidgets.clear();
0045     }
0046 
0047     void connectSignals()
0048     {
0049         if (canvas) { // in the case of KoToolManagers dummy tool it can be zero :(
0050             KoCanvasResourceProvider * crp = canvas->resourceManager();
0051             Q_ASSERT_X(crp, "KoToolBase::KoToolBase", "No Canvas KoResourceManager");
0052             if (crp)
0053                 q->connect(crp, SIGNAL(canvasResourceChanged(int, const QVariant &)),
0054                         SLOT(canvasResourceChanged(int, const QVariant &)));
0055 
0056             KoDocumentResourceManager *scrm = canvas->shapeController()->resourceManager();
0057             if (scrm) {
0058                 q->connect(scrm, SIGNAL(resourceChanged(int, const QVariant &)),
0059                         SLOT(documentResourceChanged(int, const QVariant &)));
0060             }
0061         }
0062     }
0063 
0064     QList<QPointer<QWidget> > optionWidgets; ///< the optionwidgets associated with this tool
0065     bool optionWidgetsCreated {false};
0066     QCursor currentCursor;
0067     KoToolBase *q;
0068     KoToolFactoryBase *factory {0};
0069     KoCanvasBase *canvas; ///< the canvas interface this tool will work for.
0070     bool isInTextMode;
0071     bool maskSyntheticEvents{false}; ///< Whether this tool masks synthetic events
0072     bool isActivated;
0073     QRectF lastDecorationsRect;
0074 };
0075 
0076 #endif