File indexing completed on 2024-05-05 17:04:28
0001 /* 0002 Copyright (C) 2012 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program 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 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License along 0015 with this program; if not, write to the Free Software Foundation, Inc., 0016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0017 */ 0018 0019 0020 #include "ToolManager.h" 0021 #include <KoToolRegistry.h> 0022 #include <KoToolManager.h> 0023 #include <KoToolBase.h> 0024 #include <KoCanvasController.h> 0025 #include <QPointer> 0026 0027 class ToolManager::Private 0028 { 0029 public: 0030 Private() 0031 { 0032 toolManager = KoToolManager::instance(); 0033 }; 0034 0035 QPointer<KoToolManager> toolManager; 0036 QPointer<KoToolBase> currentTool; 0037 }; 0038 0039 ToolManager::ToolManager(QQuickItem* parent) 0040 : QQuickItem(parent) 0041 , d(new Private) 0042 { 0043 connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)), 0044 this, SLOT(slotToolChanged(KoCanvasController*,int))); 0045 } 0046 0047 ToolManager::~ToolManager() 0048 { 0049 delete d; 0050 } 0051 0052 void ToolManager::requestToolChange(QString toolID) 0053 { 0054 d->toolManager->switchToolRequested(toolID); 0055 } 0056 0057 QObject* ToolManager::currentTool() const 0058 { 0059 return d->currentTool; 0060 } 0061 0062 void ToolManager::slotToolChanged(KoCanvasController* canvas, int toolId) 0063 { 0064 Q_UNUSED(canvas); 0065 Q_UNUSED(toolId); 0066 0067 if(!d->toolManager) 0068 return; 0069 0070 QString id = KoToolManager::instance()->activeToolId(); 0071 d->currentTool = qobject_cast<KoToolBase*>(KoToolManager::instance()->toolById(canvas->canvas(), id)); 0072 emit currentToolChanged(); 0073 }