1 /* 2 * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org> 3 * Copyright (c) 2005-2008 Thomas Zander <zander@kde.org> 4 * Copyright (c) 2009 Peter Simonsson <peter.simonsson@gmail.com> 5 * Copyright (c) 2010 Cyrille Berger <cberger@cberger.net> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 #ifndef _KO_TOOLBOX_H_ 23 #define _KO_TOOLBOX_H_ 24 25 #include <KoCanvasObserverBase.h> 26 27 #include <QWidget> 28 #include <QList> 29 30 #include <KoToolManager.h> 31 32 class KoCanvasController; 33 class KoShapeLayer; 34 class KoToolBoxLayout; 35 36 /** 37 * KoToolBox is a dock widget that can order tools according to type and 38 * priority. 39 * 40 * The ToolBox is a container for tool buttons which are themselves 41 * divided into sections. 42 * 43 * Adding buttons using addButton() will allow you to show those buttons. You should connect 44 * the button to your handling method yourself. 45 * 46 * The unique property of this toolbox is that it can be shown horizontal as well as vertical, 47 * rotating in a smart way to show the buttons optimally. 48 * @see KoToolManager 49 */ 50 class KoToolBox : public QWidget { 51 Q_OBJECT 52 public: 53 /// constructor 54 explicit KoToolBox(); 55 ~KoToolBox() override; 56 57 public Q_SLOTS: 58 /** 59 * Using the buttongroup id passed in addButton() you can set the new active button. 60 * If the id does not resolve to a visible button, this call is ignored. 61 * @param canvas the currently active canvas. 62 * @param id an id to identify the button to activate. 63 */ 64 void setActiveTool(KoCanvasController *canvas, int id); 65 66 /** 67 * Show only the dynamic buttons that have a code from parameter codes. 68 * The toolbox allows buttons to be optionally registered with a visibilityCode. This code 69 * can be passed here and all buttons that have that code are shown. All buttons that 70 * have another visibility code registered are hidden. 71 * @param codes a list of all the codes to show. 72 */ 73 void setButtonsVisible(const QList<QString> &codes); 74 75 76 /// Set the orientation of the layout to @p orientation 77 void setOrientation(Qt::Orientation orientation); 78 79 void setFloating(bool v); 80 81 KoToolBoxLayout *toolBoxLayout() const; 82 83 private: 84 /** 85 * Add a button to the toolbox. 86 * The buttons should all be added before the first showing since adding will not really add 87 * them to the UI until setup() is called. 88 * 89 * @param toolAction the action of the tool 90 * @see setup() 91 */ 92 void addButton(KoToolAction *toolAction); 93 94 private Q_SLOTS: 95 void setCurrentLayer(const KoCanvasController *canvas, const KoShapeLayer* newLayer); 96 97 /// add a tool post-initialization. The tool will also be activated. 98 void toolAdded(KoToolAction *toolAction, KoCanvasController *canvas); 99 100 /// set the icon size for all the buttons 101 void slotContextIconSize(); 102 103 protected: 104 void paintEvent(QPaintEvent *event) override; 105 void contextMenuEvent(QContextMenuEvent *event) override; 106 107 private: 108 class Private; 109 Private * const d; 110 }; 111 112 #endif // _KO_TOOLBOX_H_ 113