Krita

DockWidget.h
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#ifndef LIBKIS_DOCKWIDGET_H
7#define LIBKIS_DOCKWIDGET_H
8
9#include <QDockWidget>
10
11#include "kritalibkis_export.h"
12#include "libkis.h"
13
14#include <KoCanvasObserverBase.h>
15
16class KoCanvasBase;
17
18/**
19 * DockWidget is the base class for custom Dockers. Dockers are created by a
20 * factory class which needs to be registered by calling Application.addDockWidgetFactory:
21 *
22 * @code
23 * class HelloDocker(DockWidget):
24 * def __init__(self):
25 * super().__init__()
26 * label = QLabel("Hello", self)
27 * self.setWidget(label)
28 * self.label = label
29 * self.setWindowTitle("Hello Docker")
30 *
31 * def canvasChanged(self, canvas):
32 * self.label.setText("Hellodocker: canvas changed");
33 *
34 * Application.addDockWidgetFactory(DockWidgetFactory("hello", DockWidgetFactoryBase.DockRight, HelloDocker))
35 *
36 * @endcode
37 *
38 * One docker per window will be created, not one docker per canvas or view. When the user
39 * switches between views/canvases, canvasChanged will be called. You can override that
40 * method to reset your docker's internal state, if necessary.
41 */
42class KRITALIBKIS_EXPORT DockWidget : public QDockWidget, public KoCanvasObserverBase
43{
44 Q_OBJECT
45 Q_DISABLE_COPY(DockWidget)
46
47public:
48 explicit DockWidget();
49 ~DockWidget() override;
50
51protected Q_SLOTS: // Krita API
52
53 void setCanvas(KoCanvasBase* canvas) override;
54 void unsetCanvas() override;
55
56protected Q_SLOTS: // PyKrita API
57
58 /**
59 * @@return the canvas object that this docker is currently associated with
60 */
61 Canvas* canvas() const;
62
63 /**
64 * @brief canvasChanged is called whenever the current canvas is changed
65 * in the mainwindow this dockwidget instance is shown in.
66 * @param canvas The new canvas.
67 */
68 virtual void canvasChanged(Canvas *canvas) = 0;
69
70private:
71 struct Private;
72 Private *const d;
73
74};
75
76#endif // LIBKIS_DOCKWIDGET_H
Canvas wraps the canvas inside a view on an image/document.
Definition Canvas.h:23
DockWidget is the base class for custom Dockers.
Definition DockWidget.h:43
virtual void canvasChanged(Canvas *canvas)=0
canvasChanged is called whenever the current canvas is changed in the mainwindow this dockwidget inst...
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.