Krita

Window.cpp
1 /*
2  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <[email protected]>
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 
24 struct Window::Private {
25  Private() {}
26 
28 };
29 
30 Window::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 
40 Window::~Window()
41 {
42  delete d;
43 }
44 
45 bool Window::operator==(const Window &other) const
46 {
47  return (d->window == other.d->window);
48 }
49 
50 bool 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 (views().contains(view)) {
99  KisView *v = view->view();
100  d->window->showView(v);
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 
128 QAction *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 
QList< View * > views() const
Definition: Window.cpp:69
Window represents one Krita mainwindow.
Definition: Window.h:22
The Document class encapsulates a Krita Document/Image.
Definition: Document.h:33
View represents one view on a document.
Definition: View.h:24
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
Window * window() const
Definition: View.cpp:61
QMainWindow * qwindow() const
Return a handle to the QMainWindow widget.
Definition: Window.cpp:55
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
bool isEmpty() const const
View * addView(Document *document)
Open a new view on the given document in this window.
Definition: Window.cpp:83
void showView(View *view)
Make the given view active in this window.
Definition: Window.cpp:96
QList< QDockWidget * > dockers() const
dockers
Definition: Window.cpp:60
void activate()
activate activates this Window.
Definition: Window.cpp:112
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
View * activeView() const
Definition: Window.cpp:104
void close()
close the active window and all its Views.
Definition: Window.cpp:119
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Nov 27 2022 04:10:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.