File indexing completed on 2024-05-19 04:26:58

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #include "Window.h"
0007 
0008 #include <QMenuBar>
0009 #include <QObject>
0010 #include <QAction>
0011 
0012 #include <kis_action.h>
0013 #include <KisMainWindow.h>
0014 #include <KisPart.h>
0015 #include <KisDocument.h>
0016 #include <KisViewManager.h>
0017 #include <kis_action_manager.h>
0018 #include <kis_debug.h>
0019 
0020 #include <Document.h>
0021 #include <View.h>
0022 
0023 
0024 struct Window::Private {
0025     Private() {}
0026 
0027     QPointer<KisMainWindow> window;
0028 };
0029 
0030 Window::Window(KisMainWindow *window, QObject *parent)
0031     : QObject(parent)
0032     , d(new Private)
0033 {
0034     d->window = window;
0035     connect(window, SIGNAL(destroyed(QObject*)), SIGNAL(windowClosed()));
0036     connect(window, SIGNAL(themeChanged()), SIGNAL(themeChanged()));
0037     connect(window, SIGNAL(activeViewChanged()), SIGNAL(activeViewChanged()));
0038 }
0039 
0040 Window::~Window()
0041 {
0042     delete d;
0043 }
0044 
0045 bool Window::operator==(const Window &other) const
0046 {
0047     return (d->window == other.d->window);
0048 }
0049 
0050 bool Window::operator!=(const Window &other) const
0051 {
0052     return !(operator==(other));
0053 }
0054 
0055 QMainWindow *Window::qwindow() const
0056 {
0057     return d->window;
0058 }
0059 
0060 QList<QDockWidget*> Window::dockers() const
0061 {
0062     KisMainWindow *mainWindow = d->window;
0063 
0064     if (!mainWindow) return {};
0065 
0066     return mainWindow->dockWidgets();
0067 }
0068 
0069 QList<View*> Window::views() const
0070 {
0071     QList<View *> ret;
0072     if (d->window) {
0073         foreach(QPointer<KisView> view, KisPart::instance()->views()) {
0074             if (view->mainWindow() == d->window) {
0075                 ret << new View(view);
0076             }
0077         }
0078     }
0079     return ret;
0080 
0081 }
0082 
0083 View *Window::addView(Document *document)
0084 {
0085     if (d->window && document) {
0086         // Once the document is shown in the ui, it's owned by Krita
0087         // If the Document instance goes out of scope, it shouldn't
0088         // delete the owned image.
0089         document->setOwnsDocument(false);
0090         KisView *view = d->window->newView(document->document());
0091         return new View(view);
0092     }
0093     return 0;
0094 }
0095 
0096 void Window::showView(View *view)
0097 {
0098     if (views().contains(view)) {
0099         KisView *v = view->view();
0100         d->window->showView(v);
0101     }
0102 }
0103 
0104 View *Window::activeView() const
0105 {
0106     if (d->window) {
0107         return new View(d->window->activeView());
0108     }
0109     return 0;
0110 }
0111 
0112 void Window::activate()
0113 {
0114     if (d->window) {
0115         d->window->activateWindow();
0116     }
0117 }
0118 
0119 void Window::close()
0120 {
0121     if (d->window) {
0122         KisPart::instance()->removeMainWindow(d->window);
0123         d->window->close();
0124     }
0125 }
0126 
0127 
0128 QAction *Window::createAction(const QString &id, const QString &text, const QString &menuLocation)
0129 {
0130     KisAction *action = d->window->viewManager()->actionManager()->createAction(id);
0131     if (!text.isEmpty()) {
0132         action->setText(text);
0133     }
0134     action->setObjectName(id);
0135     action->setProperty("menulocation", menuLocation);
0136     return action;
0137 }
0138 
0139 
0140