Krita

Window.cpp
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "Window.h"
7
8#include <QObject>
9#include <QAction>
10
11#include <kis_action.h>
12#include <KisMainWindow.h>
13#include <KisPart.h>
14#include <KisDocument.h>
15#include <KisViewManager.h>
16#include <kis_action_manager.h>
17#include <kis_debug.h>
18
19#include <Document.h>
20#include <View.h>
21
22
23struct Window::Private {
24 Private() {}
25
26 QPointer<KisMainWindow> window;
27};
28
29Window::Window(KisMainWindow *window, QObject *parent)
30 : QObject(parent)
31 , d(new Private)
32{
33 d->window = window;
34 connect(window, SIGNAL(destroyed(QObject*)), SIGNAL(windowClosed()));
35 connect(window, SIGNAL(themeChanged()), SIGNAL(themeChanged()));
36 connect(window, SIGNAL(activeViewChanged()), SIGNAL(activeViewChanged()));
37}
38
39Window::~Window()
40{
41 delete d;
42}
43
44bool Window::operator==(const Window &other) const
45{
46 return (d->window == other.d->window);
47}
48
49bool Window::operator!=(const Window &other) const
50{
51 return !(operator==(other));
52}
53
55{
56 return d->window;
57}
58
60{
61 KisMainWindow *mainWindow = d->window;
62
63 if (!mainWindow) return {};
64
65 return mainWindow->dockWidgets();
66}
67
69{
70 QList<View *> ret;
71 if (d->window) {
72 foreach(QPointer<KisView> view, KisPart::instance()->views()) {
73 if (view->mainWindow() == d->window) {
74 ret << new View(view);
75 }
76 }
77 }
78 return ret;
79
80}
81
83{
84 if (d->window && document) {
85 // Once the document is shown in the ui, it's owned by Krita
86 // If the Document instance goes out of scope, it shouldn't
87 // delete the owned image.
88 document->setOwnsDocument(false);
89 KisView *view = d->window->newView(document->document());
90 return new View(view);
91 }
92 return 0;
93}
94
96{
97 if (v && v->view()) {
98 KisView *view = v->view();
99 view->setVisible(true);
100 d->window->setActiveView(view);
101 }
102}
103
105{
106 if (d->window) {
107 return new View(d->window->activeView());
108 }
109 return 0;
110}
111
113{
114 if (d->window) {
115 d->window->activateWindow();
116 }
117}
118
120{
121 if (d->window) {
122 KisPart::instance()->removeMainWindow(d->window);
123 d->window->close();
124 }
125}
126
127
128QAction *Window::createAction(const QString &id, const QString &text, const QString &menuLocation)
129{
130 KisAction *action = d->window->viewManager()->actionManager()->createAction(id);
131 if (!text.isEmpty()) {
132 action->setText(text);
133 }
134 action->setObjectName(id);
135 action->setProperty("menulocation", menuLocation);
136 return action;
137}
138
139
140
The Document class encapsulates a Krita Document/Image.
Definition Document.h:37
View represents one view on a document.
Definition View.h:25
Window represents one Krita mainwindow.
Definition Window.h:23
void close()
close the active window and all its Views.
Definition Window.cpp:119
View * activeView() const
Definition Window.cpp:104
QList< QDockWidget * > dockers() const
dockers
Definition Window.cpp:59
QList< View * > views() const
Definition Window.cpp:68
QAction * createAction(const QString &id, const QString &text=QString(), const QString &menuLocation=QString("tools/scripts"))
createAction creates a QAction object and adds it to the action manager for this Window.
Definition Window.cpp:128
QMainWindow * qwindow() const
Return a handle to the QMainWindow widget.
Definition Window.cpp:54
void showView(View *v)
Make the given view active in this window.
Definition Window.cpp:95
void activate()
activate activates this Window.
Definition Window.cpp:112
View * addView(Document *document)
Open a new view on the given document in this window.
Definition Window.cpp:82
QWidget * window(QObject *job)
void setObjectName(QAnyStringView name)
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QWidget * window() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 12:05:08 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.