1 /*
2 Copyright (C) 2012 Dan Leinir Turthra Jensen <admin@leinir.dk>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19
20 #include "ToolManager.h"
21 #include <KoToolRegistry.h>
22 #include <KoToolManager.h>
23 #include <KoToolBase.h>
24 #include <KoCanvasController.h>
25 #include <QPointer>
26
27 class ToolManager::Private
28 {
29 public:
Private()30 Private()
31 {
32 toolManager = KoToolManager::instance();
33 };
34
35 QPointer<KoToolManager> toolManager;
36 QPointer<KoToolBase> currentTool;
37 };
38
ToolManager(QQuickItem * parent)39 ToolManager::ToolManager(QQuickItem* parent)
40 : QQuickItem(parent)
41 , d(new Private)
42 {
43 connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)),
44 this, SLOT(slotToolChanged(KoCanvasController*,int)));
45 }
46
~ToolManager()47 ToolManager::~ToolManager()
48 {
49 delete d;
50 }
51
requestToolChange(QString toolID)52 void ToolManager::requestToolChange(QString toolID)
53 {
54 d->toolManager->switchToolRequested(toolID);
55 }
56
currentTool() const57 QObject* ToolManager::currentTool() const
58 {
59 return d->currentTool;
60 }
61
slotToolChanged(KoCanvasController * canvas,int toolId)62 void ToolManager::slotToolChanged(KoCanvasController* canvas, int toolId)
63 {
64 Q_UNUSED(canvas);
65 Q_UNUSED(toolId);
66
67 if(!d->toolManager)
68 return;
69
70 QString id = KoToolManager::instance()->activeToolId();
71 d->currentTool = qobject_cast<KoToolBase*>(KoToolManager::instance()->toolById(canvas->canvas(), id));
72 emit currentToolChanged();
73 }
74