File indexing completed on 2024-05-26 04:30:38

0001 /*
0002  * SPDX-FileCopyrightText: 2005 Boudewijn Rempt <boud@valdyas.org>
0003  * SPDX-FileCopyrightText: 2005-2008 Thomas Zander <zander@kde.org>
0004  * SPDX-FileCopyrightText: 2009 Peter Simonsson <peter.simonsson@gmail.com>
0005  * SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net>
0006  * SPDX-FileCopyrightText: 2022 Alvin Wong <alvin@alvinhc.com>
0007  *
0008  * SPDX-License-Identifier: LGPL-2.0-or-later
0009  */
0010 #ifndef _KO_TOOLBOX_H_
0011 #define _KO_TOOLBOX_H_
0012 
0013 #include <KoCanvasObserverBase.h>
0014 
0015 #include <QWidget>
0016 #include <QList>
0017 
0018 #include <KoToolManager.h>
0019 
0020 class KisViewManager;
0021 class KoCanvasController;
0022 class KoShapeLayer;
0023 class KoToolBoxLayout;
0024 
0025 /**
0026  * KoToolBox is a dock widget that can order tools according to type and
0027  * priority.
0028  *
0029  * The ToolBox is a container for tool buttons which are themselves
0030  * divided into sections.
0031  *
0032  * Adding buttons using addButton() will allow you to show those buttons.  You should connect
0033  * the button to your handling method yourself.
0034  *
0035  * The unique property of this toolbox is that it can be shown horizontal as well as vertical,
0036  * rotating in a smart way to show the buttons optimally.
0037  * @see KoToolManager
0038  */
0039 class KoToolBox : public QWidget {
0040     Q_OBJECT
0041 public:
0042     /// constructor
0043     explicit KoToolBox();
0044     ~KoToolBox() override;
0045 
0046     void applyIconSize();
0047     void setViewManager(KisViewManager *viewManager);
0048 
0049 public Q_SLOTS:
0050     /**
0051      * Set the new active button based on the currently active tool.
0052      * @param canvas the currently active canvas.
0053      */
0054     void setActiveTool(KoCanvasController *canvas);
0055 
0056     /**
0057      * Show only the dynamic buttons that have a code from parameter codes.
0058      * The toolbox allows buttons to be optionally registered with a visibilityCode. This code
0059      * can be passed here and all buttons that have that code are shown. All buttons that
0060      * have another visibility code registered are hidden.
0061      * @param codes a list of all the codes to show.
0062      */
0063     void setButtonsVisible(const QList<QString> &codes);
0064 
0065 
0066     /// Set the orientation of the layout to @p orientation
0067     void setOrientation(Qt::Orientation orientation);
0068 
0069     void setFloating(bool v);
0070 
0071     KoToolBoxLayout *toolBoxLayout() const;
0072 
0073 private:
0074     /**
0075      * Add a button to the toolbox.
0076      * The buttons should all be added before the first showing since adding will not really add
0077      * them to the UI until setup() is called.
0078      *
0079      * @param toolAction the action of the tool
0080      * @see setup()
0081      */
0082     void addButton(KoToolAction *toolAction);
0083 
0084 private Q_SLOTS:
0085     void setCurrentLayer(const KoCanvasController *canvas, const KoShapeLayer* newLayer);
0086 
0087     /// add a tool post-initialization. The tool will also be activated.
0088     void toolAdded(KoToolAction *toolAction, KoCanvasController *canvas);
0089 
0090     /// set the icon size for all the buttons
0091     void slotContextIconSize();
0092 
0093 protected:
0094     void paintEvent(QPaintEvent *event) override;
0095     void changeEvent(QEvent *event) override;
0096 
0097 private:
0098     void setupIconSizeMenu(QMenu *menu);
0099 
0100     friend class KoToolBoxDocker;
0101 
0102 private:
0103     class Private;
0104     Private * const d;
0105 };
0106 
0107 #endif // _KO_TOOLBOX_H_