Krita Source Code Documentation
Loading...
Searching...
No Matches
Window.cpp
Go to the documentation of this file.
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
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
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
54QMainWindow *Window::qwindow() const
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) {
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
qreal v
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
Main window for Krita.
QList< QDockWidget * > dockWidgets() const
Return the list of dock widgets belonging to this main window.
void removeMainWindow(KisMainWindow *mainWindow)
Definition KisPart.cpp:464
static KisPart * instance()
Definition KisPart.cpp:131
Definition View.h:25
void themeChanged()
Emitted when we change the color theme.
Window(KisMainWindow *window, QObject *parent=0)
Definition Window.cpp:29
bool operator!=(const Window &other) const
Definition Window.cpp:49
void windowClosed()
Emitted when the window is closed.
void close()
close the active window and all its Views. If there are no Views left for a given Document,...
Definition Window.cpp:119
Private *const d
Definition Window.h:106
~Window() override
Definition Window.cpp:39
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
bool operator==(const Window &other) const
Definition Window.cpp:44
QMainWindow * qwindow() const
Definition Window.cpp:54
void showView(View *v)
Definition Window.cpp:95
void activate()
activate activates this Window.
Definition Window.cpp:112
void activeViewChanged()
Emitted when the active view changes.
View * addView(Document *document)
Definition Window.cpp:82
QPointer< KisMainWindow > window
Definition Window.cpp:26