File indexing completed on 2024-05-12 15:59:08

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<View*> Window::views() const
0061 {
0062     QList<View *> ret;
0063     if (d->window) {
0064         foreach(QPointer<KisView> view, KisPart::instance()->views()) {
0065             if (view->mainWindow() == d->window) {
0066                 ret << new View(view);
0067             }
0068         }
0069     }
0070     return ret;
0071 
0072 }
0073 
0074 View *Window::addView(Document *document)
0075 {
0076     if (d->window && document) {
0077         // Once the document is shown in the ui, it's owned by Krita
0078         // If the Document instance goes out of scope, it shouldn't
0079         // delete the owned image.
0080         document->setOwnsDocument(false);
0081         KisView *view = d->window->newView(document->document());
0082         return new View(view);
0083     }
0084     return 0;
0085 }
0086 
0087 void Window::showView(View *view)
0088 {
0089     if (views().contains(view)) {
0090         KisView *v = view->view();
0091         d->window->showView(v);
0092     }
0093 }
0094 
0095 View *Window::activeView() const
0096 {
0097     if (d->window) {
0098         return new View(d->window->activeView());
0099     }
0100     return 0;
0101 }
0102 
0103 void Window::activate()
0104 {
0105     if (d->window) {
0106         d->window->activateWindow();
0107     }
0108 }
0109 
0110 void Window::close()
0111 {
0112     if (d->window) {
0113         KisPart::instance()->removeMainWindow(d->window);
0114         d->window->close();
0115     }
0116 }
0117 
0118 
0119 QAction *Window::createAction(const QString &id, const QString &text, const QString &menuLocation)
0120 {
0121     KisAction *action = d->window->viewManager()->actionManager()->createAction(id);
0122     if (!text.isEmpty()) {
0123         action->setText(text);
0124     }
0125     action->setObjectName(id);
0126     action->setProperty("menulocation", menuLocation);
0127     return action;
0128 }
0129 
0130 
0131