File indexing completed on 2024-05-19 04:29:17
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org> 0003 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org> 0004 SPDX-FileCopyrightText: 2007 Thorsten Zachmann <zachmann@kde.org> 0005 SPDX-FileCopyrightText: 2010 Boudewijn Rempt <boud@valdyas.org> 0006 SPDX-FileCopyrightText: 2015 Michael Abrahams <miabraha@gmail.com> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #ifndef KIS_PART_H 0012 #define KIS_PART_H 0013 0014 #include <QList> 0015 #include <QPointer> 0016 #include <QUrl> 0017 #include <QUuid> 0018 0019 #include <KisSessionResource.h> 0020 0021 #include "kritaui_export.h" 0022 #include <KConfigCore/kconfiggroup.h> 0023 #include <KoConfig.h> 0024 #include <kis_types.h> 0025 0026 namespace KIO { 0027 } 0028 0029 class KisAction; 0030 class KisDocument; 0031 class KisView; 0032 class KisDocument; 0033 class KisIdleWatcher; 0034 class KisAnimationCachePopulator; 0035 class KisMainWindow; 0036 class KisInputManager; 0037 class KisViewManager; 0038 0039 0040 /** 0041 * KisPart a singleton class which provides the main entry point to the application. 0042 * Krita supports multiple documents, multiple main windows, and multiple 0043 * components. KisPart manages these resources and provides them to the rest of 0044 * Krita. It manages lists of Actions and shortcuts as well. 0045 * 0046 * The terminology comes from KParts, which is a system allowing one KDE app 0047 * to be run from inside another, like pressing F4 inside dolphin to run konsole. 0048 * 0049 * Needless to say, KisPart hasn't got much to do with KParts anymore. 0050 */ 0051 class KRITAUI_EXPORT KisPart : public QObject 0052 { 0053 Q_OBJECT 0054 0055 public: 0056 0057 static KisPart *instance(); 0058 0059 /** 0060 * Constructor. 0061 * 0062 * @param parent may be another KisDocument, or anything else. 0063 * Usually passed by KPluginFactory::create. 0064 */ 0065 explicit KisPart(); 0066 0067 /** 0068 * Destructor. 0069 * 0070 * The destructor does not delete any attached KisView objects and it does not 0071 * delete the attached widget as returned by widget(). 0072 */ 0073 ~KisPart() override; 0074 0075 // ----------------- Document management ----------------- 0076 0077 /** 0078 * create an empty document. The document is not automatically registered with the part. 0079 */ 0080 KisDocument *createDocument() const; 0081 0082 /** 0083 * create a throwaway empty document. The document does not register a resource storage 0084 */ 0085 KisDocument *createTemporaryDocument() const; 0086 0087 /** 0088 * Add the specified document to the list of documents this KisPart manages. 0089 */ 0090 void addDocument(KisDocument *document, bool notify = true); 0091 0092 /** 0093 * @return a list of all documents this part manages 0094 */ 0095 QList<QPointer<KisDocument> > documents() const; 0096 0097 /** 0098 * @return number of documents this part manages. 0099 */ 0100 int documentCount() const; 0101 0102 void removeDocument(KisDocument *document, bool deleteDocument = true); 0103 0104 // ----------------- MainWindow management ----------------- 0105 0106 0107 /** 0108 * Create a new main window. 0109 */ 0110 KisMainWindow *createMainWindow(QUuid id = QUuid()); 0111 0112 /** 0113 * @brief notifyMainWindowIsBeingCreated emits the sigMainWindowCreated signal 0114 * @param mainWindow 0115 */ 0116 void notifyMainWindowIsBeingCreated(KisMainWindow *mainWindow); 0117 0118 0119 /** 0120 * Removes a main window from the list of managed windows. 0121 * 0122 * This is called by the MainWindow after it finishes its shutdown routine. 0123 */ 0124 void removeMainWindow(KisMainWindow *mainWindow); 0125 0126 /** 0127 * @return the list of main windows. 0128 */ 0129 const QList<QPointer<KisMainWindow> >& mainWindows() const; 0130 0131 /** 0132 * @return the number of shells for the main window 0133 */ 0134 int mainwindowCount() const; 0135 0136 void addRecentURLToAllMainWindows(QUrl url, QUrl oldUrl = QUrl()); 0137 0138 /** 0139 * Registers a file path to be added to the recents list, but do not apply 0140 * until the file has finished saving. 0141 */ 0142 void queueAddRecentURLToAllMainWindowsOnFileSaved(QUrl url, QUrl oldUrl = QUrl()); 0143 0144 /** 0145 * @return the currently active main window. 0146 */ 0147 KisMainWindow *currentMainwindow() const; 0148 0149 /** 0150 * Gets the currently active KisMainWindow as a QWidget, useful when you 0151 * just need it to be used as a parent to a dialog or window without 0152 * needing to include `KisMainWindow.h`. 0153 */ 0154 QWidget *currentMainwindowAsQWidget() const; 0155 0156 KisMainWindow *windowById(QUuid id) const; 0157 0158 /** 0159 * @return the application-wide KisIdleWatcher. 0160 */ 0161 KisIdleWatcher *idleWatcher() const; 0162 0163 // ----------------- Cache Populator Management ----------------- 0164 /** 0165 * @return the application-wide AnimationCachePopulator. 0166 */ 0167 KisAnimationCachePopulator *cachePopulator() const; 0168 0169 class KisPlaybackEngine* playbackEngine() const; 0170 0171 /** 0172 * Adds a frame time index to a priority stack, which should be 0173 * cached immediately and irregardless of whether it is the 0174 * the currently occupied frame. The process of regeneration is 0175 * started immediately. 0176 */ 0177 void prioritizeFrameForCache(KisImageSP image, int frame); 0178 0179 public Q_SLOTS: 0180 0181 /** 0182 * This slot loads an existing file. 0183 * @param path the file to load 0184 */ 0185 void openExistingFile(const QString &path); 0186 0187 /** 0188 * This slot loads a template and deletes the sender. 0189 * @param url the template to load 0190 */ 0191 void openTemplate(const QUrl &url); 0192 0193 0194 /** 0195 * @brief startCustomDocument adds the given document to the document list and deletes the sender() 0196 * @param doc 0197 */ 0198 void startCustomDocument(KisDocument *doc); 0199 0200 private Q_SLOTS: 0201 0202 void updateIdleWatcherConnections(); 0203 0204 void updateShortcuts(); 0205 0206 Q_SIGNALS: 0207 /** 0208 * emitted when a new document is opened. (for the idle watcher) 0209 */ 0210 void documentOpened(const QString &ref); 0211 0212 /** 0213 * emitted when an old document is closed. (for the idle watcher) 0214 */ 0215 void documentClosed(const QString &ref); 0216 0217 /** 0218 * Emitted when the animation PlaybackEngine is changed. 0219 * GUI objects that want to control playback should watch this signal 0220 * and connect to the new playbackEgine as needed. 0221 */ 0222 void playbackEngineChanged(KisPlaybackEngine *newPlaybackEngine); 0223 0224 // These signals are for libkis or sketch 0225 void sigViewAdded(KisView *view); 0226 void sigViewRemoved(KisView *view); 0227 void sigDocumentAdded(KisDocument *document); 0228 void sigDocumentSaved(const QString &url); 0229 void sigDocumentRemoved(const QString &filename); 0230 void sigMainWindowIsBeingCreated(KisMainWindow *window); 0231 void sigMainWindowCreated(); 0232 0233 public: 0234 0235 KisInputManager *currentInputManager(); 0236 0237 //------------------ View management ------------------ 0238 0239 /** 0240 * Create a new view for the document. The view is added to the list of 0241 * views, and if the document wasn't known yet, it's registered as well. 0242 */ 0243 KisView *createView(KisDocument *document, 0244 KisViewManager *viewManager, 0245 QWidget *parent); 0246 0247 /** 0248 * Adds a view to the document. If the part doesn't know yet about 0249 * the document, it is registered. 0250 * 0251 * This calls KisView::updateReadWrite to tell the new view 0252 * whether the document is readonly or not. 0253 */ 0254 void addView(KisView *view); 0255 0256 /** 0257 * Removes a view of the document. 0258 */ 0259 void removeView(KisView *view); 0260 0261 /** 0262 * @return a list of views this document is displayed in 0263 */ 0264 QList<QPointer<KisView> > views() const; 0265 0266 /** 0267 * @return number of views this document is displayed in 0268 */ 0269 int viewCount(KisDocument *doc) const; 0270 0271 //------------------ Session management ------------------ 0272 0273 void showSessionManager(); 0274 0275 void startBlankSession(); 0276 0277 /** 0278 * Restores a saved session by name 0279 */ 0280 bool restoreSession(const QString &sessionName); 0281 bool restoreSession(KisSessionResourceSP session); 0282 0283 void setCurrentSession(KisSessionResourceSP session); 0284 0285 /** 0286 * Attempts to save the session and close all windows. 0287 * This may involve asking the user to save open files. 0288 * @return false, if closing was cancelled by the user 0289 */ 0290 bool closeSession(bool keepWindows = false); 0291 0292 /** 0293 * Are we in the process of closing the application through closeSession(). 0294 */ 0295 bool closingSession() const; 0296 0297 /** 0298 * This function returns true if the instance has already been initialized, 0299 * false otherwise. This to prevent premature initialization that causes crash 0300 * on android see `1fbb25506a` 0301 * @see QGlobalStatic::exists() 0302 */ 0303 static bool exists(); 0304 0305 //------------------ Animation PlaybackEngine management ------------------ 0306 public: 0307 void upgradeToPlaybackEngineMLT(class KoCanvasBase *canvas); 0308 0309 private: 0310 0311 void setPlaybackEngine(KisPlaybackEngine *p_playbackEngine); 0312 0313 private Q_SLOTS: 0314 0315 void slotDocumentSaved(const QString &filePath); 0316 0317 private: 0318 0319 Q_DISABLE_COPY(KisPart) 0320 0321 class Private; 0322 Private *const d; 0323 0324 }; 0325 0326 #endif