libs/flake

KoToolManager.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *  Copyright (c) 2005-2006 Boudewijn Rempt <boud@valdyas.org>
00003  * Copyright (C) 2006, 2008 Thomas Zander <zander@kde.org>
00004  * Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  */
00021 #ifndef KO_TOOL_MANAGER
00022 #define KO_TOOL_MANAGER
00023 
00024 #include <KoInputDevice.h>
00025 #include "flake_export.h"
00026 
00027 #include <QObject>
00028 #include <QCursor>
00029 #include <QList>
00030 
00031 class ToolHelper;
00032 class KoCanvasController;
00033 class KoCanvasBase;
00034 class KoTool;
00035 class KoCreateShapesTool;
00036 class KActionCollection;
00037 class KoShape;
00038 class KoToolProxy;
00039 class QToolButton;
00040 class KoDeviceEvent;
00041 class KoGuidesTool;
00042 class KoShapeLayer;
00043 
00098 class FLAKE_EXPORT KoToolManager : public QObject
00099 {
00100     Q_OBJECT
00101 
00102 public:
00104     static KoToolManager* instance();
00105     ~KoToolManager();
00106 
00115     void registerTools(KActionCollection *ac, KoCanvasController *controller = 0);
00116 
00121     void addController(KoCanvasController *controller);
00122 
00129     void removeCanvasController(KoCanvasController *controller);
00130 
00132     KoCanvasController *activeCanvasController() const;
00133 
00141     KoCreateShapesTool *shapeCreatorTool(KoCanvasBase *canvas) const;
00142 
00149     KoGuidesTool * guidesTool(KoCanvasBase * canvas) const;
00150 
00152     KoInputDevice currentInputDevice() const;
00153 
00159     QString preferredToolForSelection(const QList<KoShape*> &shapes);
00160 
00162     struct Button {
00163         QToolButton *button;
00164         QString section;        
00165         int priority;           
00166         int buttonGroupId;      
00167         QString visibilityCode; 
00168     };
00169 
00175     QList<Button> createToolList(KoCanvasBase *canvas) const;
00176 
00178     void requestToolActivation(KoCanvasController * controller);
00179 
00181     void injectDeviceEvent(KoDeviceEvent * event);
00182 
00184     QString activeToolId() const;
00185 public slots:
00190     void switchToolRequested(const QString &id);
00191 
00192 signals:
00198     void changedTool(KoCanvasController *canvas, int uniqueToolId);
00199 
00206     void toolCodesSelected(const KoCanvasController *canvas, QList<QString> types);
00207 
00213     void currentLayerChanged(const KoCanvasController *canvas, const KoShapeLayer* layer);
00214 
00219     void inputDeviceChanged(const KoInputDevice &device);
00220 
00225     void changedCanvas(const KoCanvasBase * canvas);
00226 
00231     void changedStatusText(const QString &statusText);
00232 protected:
00233     friend class KoToolProxy;
00238     void switchInputDevice(const KoInputDevice &device);
00239 
00247     void registerToolProxy(KoToolProxy *proxy, KoCanvasBase *canvas);
00248 
00249     // make it a friend so we can temporary switch tool from there
00250     friend class KoCanvasController;
00251     void switchToolByShortcut(QKeyEvent *event);
00252 
00253 protected slots:
00254     void switchToolTemporaryRequested(const QString &id);
00255 
00256 private:
00257     KoToolManager();
00258     KoToolManager(const KoToolManager&);
00259     KoToolManager operator=(const KoToolManager&);
00260     void setup();
00261     void switchTool(KoTool *tool, bool temporary);
00262     void switchTool(const QString &id, bool temporary);
00263     void postSwitchTool(bool temporary);
00264     bool eventFilter(QObject *object, QEvent *event);
00265 
00266 private slots:
00267     void toolActivated(ToolHelper *tool);
00268     void detachCanvas(KoCanvasController *controller);
00269     void attachCanvas(KoCanvasController *controller);
00270     void movedFocus(QWidget *from, QWidget *to);
00271     void updateCursor(const QCursor &cursor);
00272     void switchBackRequested();
00273     void selectionChanged(QList<KoShape*> shapes);
00274     void currentLayerChanged(const KoShapeLayer *layer);
00275 
00276 private:
00277     class Private;
00278     Private *const d;
00279 };
00280 
00281 #endif