File indexing completed on 2024-05-12 15:59:04

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #ifndef LIBKIS_DOCKWIDGET_H
0007 #define LIBKIS_DOCKWIDGET_H
0008 
0009 #include <QDockWidget>
0010 
0011 #include "kritalibkis_export.h"
0012 #include "libkis.h"
0013 
0014 #include <KoCanvasObserverBase.h>
0015 
0016 class KoCanvasBase;
0017 
0018 /**
0019  * DockWidget is the base class for custom Dockers. Dockers are created by a
0020  * factory class which needs to be registered by calling Application.addDockWidgetFactory:
0021  *
0022  * @code
0023  * class HelloDocker(DockWidget):
0024  *   def __init__(self):
0025  *       super().__init__()
0026  *       label = QLabel("Hello", self)
0027  *       self.setWidget(label)
0028  *       self.label = label
0029  *       self.setWindowTitle("Hello Docker")
0030  *
0031  * def canvasChanged(self, canvas):
0032  *       self.label.setText("Hellodocker: canvas changed");
0033  *
0034  * Application.addDockWidgetFactory(DockWidgetFactory("hello", DockWidgetFactoryBase.DockRight, HelloDocker))
0035  *
0036  * @endcode
0037  *
0038  * One docker per window will be created, not one docker per canvas or view. When the user
0039  * switches between views/canvases, canvasChanged will be called. You can override that
0040  * method to reset your docker's internal state, if necessary.
0041  */
0042 class KRITALIBKIS_EXPORT DockWidget : public QDockWidget, public KoCanvasObserverBase
0043 {
0044     Q_OBJECT
0045     Q_DISABLE_COPY(DockWidget)
0046 
0047 public:
0048     explicit DockWidget();
0049     ~DockWidget() override;
0050 
0051 protected Q_SLOTS: // Krita API
0052 
0053     void setCanvas(KoCanvasBase* canvas) override;
0054     void unsetCanvas() override;
0055 
0056 protected Q_SLOTS: // PyKrita API
0057 
0058     /**
0059      * @@return the canvas object that this docker is currently associated with
0060      */
0061     Canvas* canvas() const;
0062 
0063     /**
0064      * @brief canvasChanged is called whenever the current canvas is changed
0065      * in the mainwindow this dockwidget instance is shown in.
0066      * @param canvas The new canvas.
0067      */
0068     virtual void canvasChanged(Canvas *canvas) = 0;
0069 
0070 private:
0071     struct Private;
0072     Private *const d;
0073 
0074 };
0075 
0076 #endif // LIBKIS_DOCKWIDGET_H