File indexing completed on 2024-05-12 15:56:47

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOSHAPECONFIGWIDGETBASE_H
0008 #define KOSHAPECONFIGWIDGETBASE_H
0009 
0010 #include <QWidget>
0011 
0012 #include "kritaflake_export.h"
0013 
0014 class KoShape;
0015 class KUndo2Command;
0016 class KoUnit;
0017 class KoCanvasResourceProvider;
0018 
0019 /**
0020  * Base widget for shape-configuration panels.
0021  * This is an interface type class used by classes that intend to provide
0022  * a GUI for configuring newly created shapes as created by a KoShapeFactoryBase.
0023  *
0024  * Every time after a shape is created the KoShapeFactoryBase for that shape-type
0025  * will be queried for all the config widgets; both factory specific as well as
0026  * those set by the hosting application.
0027  * A dialog will be shown with all those panels, each extending this class.
0028  * The framework will then call open() to populate the widget with data from
0029  * the param shape.  After the user ok-ed the dialog the save() will be called
0030  * to allow the widget to apply all settings from the widget to the shape.
0031  */
0032 class KRITAFLAKE_EXPORT KoShapeConfigWidgetBase : public QWidget
0033 {
0034     Q_OBJECT
0035 public:
0036     /**
0037      * Default constructor
0038      */
0039     KoShapeConfigWidgetBase();
0040     ~KoShapeConfigWidgetBase() override;
0041 
0042     /**
0043      * Open the argument shape by interpreting the data and setting that data on this
0044      * widget.
0045      * @param shape the shape that is to be queried for the data this widget can edit.
0046      */
0047     virtual void open(KoShape *shape) = 0;
0048     /**
0049      * Save the data  of this widget to the shape passed to open earlier to
0050      * apply any user changed options.
0051      * Called by the tool that created the shape.
0052      */
0053     virtual void save() = 0;
0054 
0055     /**
0056      * Overwrite this method to set the application unit type and update all unit-widgets
0057      * in this panel.
0058      * Called by the tool that created the shape using KoCavasBase::unit()
0059      * @param unit the new unit to show data in.
0060      */
0061     virtual void setUnit(const KoUnit &unit);
0062 
0063     /// called to set the canvas resource manager of the canvas the user used to insert the new shape.
0064     void setResourceManager(KoCanvasResourceProvider *rm);
0065 
0066     /// Return true if the shape config panel should be shown after the shape is created
0067     virtual bool showOnShapeCreate();
0068 
0069     /// Return true if the shape config panel should be shown when the shape is selected
0070     virtual bool showOnShapeSelect();
0071 
0072     /// Creates a command which applies all changes to the opened shape
0073     virtual KUndo2Command * createCommand();
0074 
0075 Q_SIGNALS:
0076     /// is emitted after one of the config options has changed
0077     void propertyChanged();
0078 
0079     /// is emitted when the dialog should be accepted ie a file double clicked in a filebrowser
0080     void accept();
0081 
0082 protected:
0083     KoCanvasResourceProvider *m_resourceManager; ///< the resource provider with data for this canvas
0084 };
0085 
0086 #endif