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 <QMenuBar>
9#include <QObject>
10#include <QAction>
11
12#include <kis_action.h>
13#include <KisMainWindow.h>
14#include <KisPart.h>
15#include <KisDocument.h>
16#include <KisViewManager.h>
17#include <kis_action_manager.h>
18#include <kis_debug.h>
19
20#include <Document.h>
21#include <View.h>
22
23
24struct Window::Private {
25 Private() {}
26
27 QPointer<KisMainWindow> window;
28};
29
30Window::Window(KisMainWindow *window, QObject *parent)
31 : QObject(parent)
32 , d(new Private)
33{
34 d->window = window;
35 connect(window, SIGNAL(destroyed(QObject*)), SIGNAL(windowClosed()));
36 connect(window, SIGNAL(themeChanged()), SIGNAL(themeChanged()));
37 connect(window, SIGNAL(activeViewChanged()), SIGNAL(activeViewChanged()));
38}
39
40Window::~Window()
41{
42 delete d;
43}
44
45bool Window::operator==(const Window &other) const
46{
47 return (d->window == other.d->window);
48}
49
50bool Window::operator!=(const Window &other) const
51{
52 return !(operator==(other));
53}
54
56{
57 return d->window;
58}
59
61{
62 KisMainWindow *mainWindow = d->window;
63
64 if (!mainWindow) return {};
65
66 return mainWindow->dockWidgets();
67}
68
70{
71 QList<View *> ret;
72 if (d->window) {
73 foreach(QPointer<KisView> view, KisPart::instance()->views()) {
74 if (view->mainWindow() == d->window) {
75 ret << new View(view);
76 }
77 }
78 }
79 return ret;
80
81}
82
84{
85 if (d->window && document) {
86 // Once the document is shown in the ui, it's owned by Krita
87 // If the Document instance goes out of scope, it shouldn't
88 // delete the owned image.
89 document->setOwnsDocument(false);
90 KisView *view = d->window->newView(document->document());
91 return new View(view);
92 }
93 return 0;
94}
95
97{
98 if (v && v->view()) {
99 KisView *view = v->view();
100 view->setVisible(true);
101 d->window->setActiveView(view);
102 }
103}
104
106{
107 if (d->window) {
108 return new View(d->window->activeView());
109 }
110 return 0;
111}
112
114{
115 if (d->window) {
116 d->window->activateWindow();
117 }
118}
119
121{
122 if (d->window) {
123 KisPart::instance()->removeMainWindow(d->window);
124 d->window->close();
125 }
126}
127
128
129QAction *Window::createAction(const QString &id, const QString &text, const QString &menuLocation)
130{
131 KisAction *action = d->window->viewManager()->actionManager()->createAction(id);
132 if (!text.isEmpty()) {
133 action->setText(text);
134 }
135 action->setObjectName(id);
136 action->setProperty("menulocation", menuLocation);
137 return action;
138}
139
140
141
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:120
View * activeView() const
Definition Window.cpp:105
QList< QDockWidget * > dockers() const
dockers
Definition Window.cpp:60
QList< View * > views() const
Definition Window.cpp:69
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:129
QMainWindow * qwindow() const
Return a handle to the QMainWindow widget.
Definition Window.cpp:55
void showView(View *v)
Make the given view active in this window.
Definition Window.cpp:96
void activate()
activate activates this Window.
Definition Window.cpp:113
View * addView(Document *document)
Open a new view on the given document in this window.
Definition Window.cpp:83
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 Apr 25 2025 12:04:00 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.