Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPart Class Reference

#include <KisPart.h>

+ Inheritance diagram for KisPart:

Public Slots

void openExistingFile (const QString &path)
 
void openTemplate (const QUrl &url)
 
void startCustomDocument (KisDocument *doc)
 startCustomDocument adds the given document to the document list and deletes the sender()
 

Signals

void documentClosed (const QString &ref)
 
void documentOpened (const QString &ref)
 
void playbackEngineChanged (KisPlaybackEngine *newPlaybackEngine)
 
void sigDocumentAdded (KisDocument *document)
 
void sigDocumentRemoved (const QString &filename)
 
void sigDocumentSaved (const QString &url)
 
void sigMainWindowCreated ()
 
void sigMainWindowIsBeingCreated (KisMainWindow *window)
 
void sigViewAdded (KisView *view)
 
void sigViewRemoved (KisView *view)
 

Public Member Functions

void addDocument (KisDocument *document, bool notify=true)
 
void addRecentURLToAllMainWindows (QUrl url, QUrl oldUrl=QUrl())
 
void addView (KisView *view)
 
KisAnimationCachePopulatorcachePopulator () const
 
bool closeSession (bool keepWindows=false)
 
bool closingSession () const
 
KisDocumentcreateDocument () const
 
KisMainWindowcreateMainWindow (QUuid id=QUuid())
 
KisDocumentcreateTemporaryDocument () const
 
KisViewcreateView (KisDocument *document, KisViewManager *viewManager, QWidget *parent)
 
KisInputManagercurrentInputManager ()
 
KisMainWindowcurrentMainwindow () const
 
QWidget * currentMainwindowAsQWidget () const
 
int documentCount () const
 
QList< QPointer< KisDocument > > documents () const
 
KisIdleWatcheridleWatcher () const
 
 KisPart ()
 
int mainwindowCount () const
 
const QList< QPointer< KisMainWindow > > & mainWindows () const
 
void notifyMainWindowIsBeingCreated (KisMainWindow *mainWindow)
 notifyMainWindowIsBeingCreated emits the sigMainWindowCreated signal
 
class KisPlaybackEngineplaybackEngine () const
 
void prioritizeFrameForCache (KisImageSP image, int frame)
 
 Private (KisPart *_part)
 
bool queryCloseDocument (KisDocument *document)
 
void queueAddRecentURLToAllMainWindowsOnFileSaved (QUrl url, QUrl oldUrl=QUrl())
 
void removeDocument (KisDocument *document, bool deleteDocument=true)
 
void removeMainWindow (KisMainWindow *mainWindow)
 
void removeView (KisView *view)
 
bool restoreSession (const QString &sessionName)
 
bool restoreSession (KisSessionResourceSP session)
 
void setCurrentSession (KisSessionResourceSP session)
 
void showSessionManager ()
 
void startBlankSession ()
 
void unloadPlaybackEngine ()
 
void upgradeToPlaybackEngineMLT (class KoCanvasBase *canvas)
 
int viewCount (KisDocument *doc) const
 
QList< QPointer< KisView > > views () const
 
KisMainWindowwindowById (QUuid id) const
 
 ~KisPart () override
 
 ~Private ()
 

Static Public Member Functions

static bool exists ()
 
static KisPartinstance ()
 

Public Attributes

KisAnimationCachePopulator animationCachePopulator
 
bool closingSession {false}
 
KisSessionResourceSP currentSession
 
QList< QPointer< KisDocument > > documents
 
KisIdleWatcher idleWatcher
 
QList< QPointer< KisMainWindow > > mainWindows
 
KisPartpart
 
QMap< QUrl, QUrl > pendingAddRecentUrlMap
 
QScopedPointer< KisPlaybackEngineplaybackEngine
 
QScopedPointer< KisSessionManagerDialogsessionManager
 
QList< QPointer< KisView > > views
 

Private Slots

void slotDocumentSaved (const QString &filePath)
 
void updateIdleWatcherConnections ()
 
void updateShortcuts ()
 

Private Member Functions

void setPlaybackEngine (KisPlaybackEngine *p_playbackEngine)
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

KisPart a singleton class which provides the main entry point to the application. Krita supports multiple documents, multiple main windows, and multiple components. KisPart manages these resources and provides them to the rest of Krita. It manages lists of Actions and shortcuts as well.

The terminology comes from KParts, which is a system allowing one KDE app to be run from inside another, like pressing F4 inside dolphin to run konsole.

Needless to say, KisPart hasn't got much to do with KParts anymore.

Definition at line 89 of file KisPart.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KisPart::~Private ( )
inline

Definition at line 100 of file KisPart.cpp.

101 {
102 }

◆ KisPart()

KisPart::KisPart ( )
explicit

Constructor.

Parameters
parentmay be another KisDocument, or anything else. Usually passed by KPluginFactory::create.

Definition at line 147 of file KisPart.cpp.

148 : d(new Private(this))
149{
150 // Preload all the resources in the background
153 Q_UNUSED(KisColorManager::instance());
154
155 connect(this, SIGNAL(documentOpened(QString)),
156 this, SLOT(updateIdleWatcherConnections()));
157
158 connect(this, SIGNAL(documentClosed(QString)),
159 this, SLOT(updateIdleWatcherConnections()));
160
161 connect(KisActionRegistry::instance(), SIGNAL(shortcutsUpdated()),
162 this, SLOT(updateShortcuts()));
163 connect(&d->idleWatcher, SIGNAL(startedIdleMode()),
164 &d->animationCachePopulator, SLOT(slotRequestRegeneration()));
165 connect(&d->idleWatcher, SIGNAL(startedIdleMode()),
166 KisMemoryStatisticsServer::instance(), SLOT(tryForceUpdateMemoryStatisticsWhileIdle()));
167
168 // We start by loading the simple QTimer-based anim playback engine first.
169 // To save RAM, the MLT-based engine will be loaded later, once the KisImage in question becomes animated.
171
172 d->animationCachePopulator.slotRequestRegeneration();
173 KisBusyWaitBroker::instance()->setFeedbackCallback(&busyWaitWithFeedback);
174}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisActionRegistry * instance()
void setFeedbackCallback(std::function< void(KisImageSP)> callback)
static KisBusyWaitBroker * instance()
static KisColorManager * instance()
void updateShortcuts()
Definition KisPart.cpp:547
void setPlaybackEngine(KisPlaybackEngine *p_playbackEngine)
Definition KisPart.cpp:719
void documentClosed(const QString &ref)
Private *const d
Definition KisPart.h:328
void documentOpened(const QString &ref)
void updateIdleWatcherConnections()
Definition KisPart.cpp:193
The KisPlaybackEngineQT class is an implementation of KisPlaybackEngine that drives animation playbac...
static KisResourceServerProvider * instance()
static KisMemoryStatisticsServer * instance()
static KoResourceServerProvider * instance()

References connect(), d, documentClosed(), documentOpened(), KisColorManager::instance(), KisMemoryStatisticsServer::instance(), KisBusyWaitBroker::instance(), KisResourceServerProvider::instance(), KoResourceServerProvider::instance(), KisActionRegistry::instance(), KisBusyWaitBroker::setFeedbackCallback(), setPlaybackEngine(), updateIdleWatcherConnections(), and updateShortcuts().

◆ ~KisPart()

KisPart::~KisPart ( )
override

Destructor.

The destructor does not delete any attached KisView objects and it does not delete the attached widget as returned by widget().

Definition at line 176 of file KisPart.cpp.

177{
178 while (!d->documents.isEmpty()) {
179 delete d->documents.takeFirst();
180 }
181
182 while (!d->views.isEmpty()) {
183 delete d->views.takeFirst();
184 }
185
186 while (!d->mainWindows.isEmpty()) {
187 delete d->mainWindows.takeFirst();
188 }
189
190 delete d;
191}

References d.

Member Function Documentation

◆ addDocument()

void KisPart::addDocument ( KisDocument * document,
bool notify = true )

Add the specified document to the list of documents this KisPart manages.

Definition at line 211 of file KisPart.cpp.

212{
213 //dbgUI << "Adding document to part list" << document;
214 Q_ASSERT(document);
215 if (!d->documents.contains(document)) {
216 d->documents.append(document);
217 if (notify){
218 Q_EMIT documentOpened('/'+ objectName());
219 Q_EMIT sigDocumentAdded(document);
220 }
221 connect(document, SIGNAL(sigSavingFinished(QString)), SLOT(slotDocumentSaved(QString)));
222 }
223}
void sigDocumentAdded(KisDocument *document)
void slotDocumentSaved(const QString &filePath)
Definition KisPart.cpp:447

References connect(), d, documentOpened(), sigDocumentAdded(), and slotDocumentSaved().

◆ addRecentURLToAllMainWindows()

void KisPart::addRecentURLToAllMainWindows ( QUrl url,
QUrl oldUrl = QUrl() )

Definition at line 598 of file KisPart.cpp.

599{
600 // Add entry to recent documents list
601 // (call coming from KisDocument because it must work with cmd line, template dlg, file/open, etc.)
602 if (!url.isEmpty()) {
603 bool ok = true;
604 if (url.isLocalFile()) {
605 QString path = url.adjusted(QUrl::StripTrailingSlash).toLocalFile();
606 const QStringList tmpDirs = QStandardPaths::locateAll(QStandardPaths::TempLocation, "", QStandardPaths::LocateDirectory);
607 for (QStringList::ConstIterator it = tmpDirs.begin() ; ok && it != tmpDirs.end() ; ++it) {
608 if (path.contains(*it)) {
609 ok = false; // it's in the tmp resource
610 }
611 }
612
613 const QStringList templateDirs = KoResourcePaths::findDirs("templates");
614 for (QStringList::ConstIterator it = templateDirs.begin() ; ok && it != templateDirs.end() ; ++it) {
615 if (path.contains(*it)) {
616 ok = false; // it's in the templates directory.
617 break;
618 }
619 }
620 }
621 if (ok) {
622 if (!oldUrl.isEmpty()) {
624 }
626 }
627 }
628}
void remove(const QUrl &url)
static KisRecentFilesManager * instance()
static QStringList findDirs(const QString &type)

References KisRecentFilesManager::add(), KoResourcePaths::findDirs(), KisRecentFilesManager::instance(), and KisRecentFilesManager::remove().

◆ addView()

void KisPart::addView ( KisView * view)

Adds a view to the document. If the part doesn't know yet about the document, it is registered.

This calls KisView::updateReadWrite to tell the new view whether the document is readonly or not.

Definition at line 332 of file KisPart.cpp.

333{
334 if (!view)
335 return;
336
337 if (!d->views.contains(view)) {
338 d->views.append(view);
339 }
340
341 Q_EMIT sigViewAdded(view);
342}
void sigViewAdded(KisView *view)

References d, and sigViewAdded().

◆ cachePopulator()

KisAnimationCachePopulator * KisPart::cachePopulator ( ) const
Returns
the application-wide AnimationCachePopulator.

Definition at line 520 of file KisPart.cpp.

521{
522 return &d->animationCachePopulator;
523}

References d.

◆ closeSession()

bool KisPart::closeSession ( bool keepWindows = false)

Attempts to save the session and close all windows. This may involve asking the user to save open files.

Returns
false, if closing was cancelled by the user

Definition at line 406 of file KisPart.cpp.

407{
408 d->closingSession = true;
409
410 Q_FOREACH(auto document, d->documents) {
411 if (!d->queryCloseDocument(document.data())) {
412 d->closingSession = false;
413 return false;
414 }
415 }
416
417 if (d->currentSession) {
418 KisConfig kisCfg(false);
419 if (kisCfg.saveSessionOnQuit(false)) {
420
421 d->currentSession->storeCurrentWindows();
423 bool result = model.updateResource(d->currentSession);
424 Q_UNUSED(result);
425
426 KConfigGroup cfg = KSharedConfig::openConfig()->group("session");
427 cfg.writeEntry("previousSession", d->currentSession->name());
428 }
429
430 d->currentSession = nullptr;
431 }
432
433 if (!keepWindows) {
434 Q_FOREACH (auto window, d->mainWindows) {
435 window->close();
436 }
437
438 if (d->sessionManager) {
439 d->sessionManager->close();
440 }
441 }
442
443 d->closingSession = false;
444 return true;
445}
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
const QString Sessions

References d, KisConfig::saveSessionOnQuit(), ResourceType::Sessions, and KisResourceModel::updateResource().

◆ closingSession()

bool KisPart::closingSession ( ) const

Are we in the process of closing the application through closeSession().

◆ createDocument()

KisDocument * KisPart::createDocument ( ) const

create an empty document. The document is not automatically registered with the part.

Definition at line 230 of file KisPart.cpp.

231{
232 KisDocument *doc = new KisDocument();
233 return doc;
234}

◆ createMainWindow()

KisMainWindow * KisPart::createMainWindow ( QUuid id = QUuid())

Create a new main window.

Definition at line 260 of file KisPart.cpp.

261{
262 KisMainWindow *mw = new KisMainWindow(id);
263 dbgUI <<"mainWindow" << (void*)mw << "added to view" << this;
264 d->mainWindows.append(mw);
265
266 // Add all actions with a menu property to the main window
267 Q_FOREACH(QAction *action, mw->actionCollection()->actions()) {
268 QString menuLocation = action->property("menulocation").toString();
269 if (!menuLocation.isEmpty()) {
270 QAction *found = 0;
271 QList<QAction *> candidates = mw->menuBar()->actions();
272 Q_FOREACH(const QString &name, menuLocation.split("/")) {
273 Q_FOREACH(QAction *candidate, candidates) {
274 if (candidate->objectName().toLower() == name.toLower()) {
275 found = candidate;
276 candidates = candidate->menu()->actions();
277 break;
278 }
279 }
280 if (candidates.isEmpty()) {
281 break;
282 }
283 }
284
285 if (found && found->menu()) {
286 found->menu()->addAction(action);
287 }
288 }
289 }
290
291
292 return mw;
293}
QList< QAction * > actions() const
virtual KisKActionCollection * actionCollection() const
Main window for Krita.
#define dbgUI
Definition kis_debug.h:52
const char * name(StandardAction id)

References KisKXMLGUIClient::actionCollection(), KisKActionCollection::actions(), d, and dbgUI.

◆ createTemporaryDocument()

KisDocument * KisPart::createTemporaryDocument ( ) const

create a throwaway empty document. The document does not register a resource storage

Definition at line 236 of file KisPart.cpp.

237{
238 KisDocument *doc = new KisDocument(false);
239 return doc;
240}

◆ createView()

KisView * KisPart::createView ( KisDocument * document,
KisViewManager * viewManager,
QWidget * parent )

Create a new view for the document. The view is added to the list of views, and if the document wasn't known yet, it's registered as well.

Definition at line 301 of file KisPart.cpp.

304{
305 // If creating the canvas fails, record this and disable OpenGL next time
306 KisConfig cfg(false);
307 KConfigGroup grp( KSharedConfig::openConfig(), "crashprevention");
308 if (grp.readEntry("CreatingCanvas", false)) {
309 cfg.disableOpenGL();
310 }
311 if (cfg.canvasState() == "OPENGL_FAILED") {
312 cfg.disableOpenGL();
313 }
314 grp.writeEntry("CreatingCanvas", true);
315 grp.sync();
316
317 KisView *view = nullptr;
318 {
319 KisCursorOverrideLock cursorLock(Qt::WaitCursor);
320 view = new KisView(document, viewManager, parent);
321 }
322
323 // Record successful canvas creation
324 grp.writeEntry("CreatingCanvas", false);
325 grp.sync();
326
327 addView(view);
328
329 return view;
330}
void addView(KisView *view)
Definition KisPart.cpp:332

References addView(), KisConfig::canvasState(), and KisConfig::disableOpenGL().

◆ currentInputManager()

KisInputManager * KisPart::currentInputManager ( )

Definition at line 643 of file KisPart.cpp.

644{
646 KisViewManager *manager = mw ? mw->viewManager() : 0;
647 return manager ? manager->inputManager() : 0;
648}
KisViewManager * viewManager
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483
KisInputManager * inputManager() const
Filters events and sends them to canvas actions.

References currentMainwindow(), KisViewManager::inputManager(), and KisMainWindow::viewManager.

◆ currentMainwindow()

KisMainWindow * KisPart::currentMainwindow ( ) const
Returns
the currently active main window.

Definition at line 483 of file KisPart.cpp.

484{
485 QWidget *widget = qApp->activeWindow();
486 KisMainWindow *mainWindow = qobject_cast<KisMainWindow*>(widget);
487 while (!mainWindow && widget) {
488 widget = widget->parentWidget();
489 mainWindow = qobject_cast<KisMainWindow*>(widget);
490 }
491
492 if (!mainWindow && mainWindows().size() > 0) {
493 mainWindow = mainWindows().first();
494 }
495 return mainWindow;
496
497}
QList< QPointer< KisMainWindow > > mainWindows
Definition KisPart.cpp:107
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References mainWindows.

◆ currentMainwindowAsQWidget()

QWidget * KisPart::currentMainwindowAsQWidget ( ) const

Gets the currently active KisMainWindow as a QWidget, useful when you just need it to be used as a parent to a dialog or window without needing to include KisMainWindow.h.

Definition at line 499 of file KisPart.cpp.

500{
501 return currentMainwindow();
502}

References currentMainwindow().

◆ documentClosed

void KisPart::documentClosed ( const QString & ref)
signal

emitted when an old document is closed. (for the idle watcher)

◆ documentCount()

int KisPart::documentCount ( ) const
Returns
number of documents this part manages.

Definition at line 243 of file KisPart.cpp.

244{
245 return d->documents.size();
246}

References d.

◆ documentOpened

void KisPart::documentOpened ( const QString & ref)
signal

emitted when a new document is opened. (for the idle watcher)

◆ documents()

QList< QPointer< KisDocument > > KisPart::documents ( ) const
Returns
a list of all documents this part manages

◆ exists()

bool KisPart::exists ( )
static

This function returns true if the instance has already been initialized, false otherwise. This to prevent premature initialization that causes crash on android see 1fbb25506a

See also
QGlobalStatic::exists()

Definition at line 401 of file KisPart.cpp.

402{
403 return s_instance.exists();
404}

◆ idleWatcher()

KisIdleWatcher * KisPart::idleWatcher ( ) const
Returns
the application-wide KisIdleWatcher.

◆ instance()

KisPart * KisPart::instance ( )
static

Definition at line 131 of file KisPart.cpp.

132{
133 return s_instance;
134}

◆ mainwindowCount()

int KisPart::mainwindowCount ( ) const
Returns
the number of shells for the main window

Definition at line 477 of file KisPart.cpp.

478{
479 return d->mainWindows.count();
480}

References d.

◆ mainWindows()

const QList< QPointer< KisMainWindow > > & KisPart::mainWindows ( ) const
Returns
the list of main windows.

◆ notifyMainWindowIsBeingCreated()

void KisPart::notifyMainWindowIsBeingCreated ( KisMainWindow * mainWindow)

notifyMainWindowIsBeingCreated emits the sigMainWindowCreated signal

Parameters
mainWindow

Definition at line 295 of file KisPart.cpp.

296{
297 Q_EMIT sigMainWindowIsBeingCreated(mainWindow);
298}
void sigMainWindowIsBeingCreated(KisMainWindow *window)

References sigMainWindowIsBeingCreated().

◆ openExistingFile

void KisPart::openExistingFile ( const QString & path)
slot

This slot loads an existing file.

Parameters
paththe file to load

Definition at line 537 of file KisPart.cpp.

538{
539 // TODO: refactor out this method!
540
543
545}
bool openDocument(const QString &path, OpenFlags flags)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References currentMainwindow(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisMainWindow::None, and KisMainWindow::openDocument().

◆ openTemplate

void KisPart::openTemplate ( const QUrl & url)
slot

This slot loads a template and deletes the sender.

Parameters
urlthe template to load

Definition at line 558 of file KisPart.cpp.

559{
560 KisCursorOverrideLock cursorLock(Qt::BusyCursor);
561
562 KisDocument *document = createDocument();
563
564 bool ok = document->loadNativeFormat(url.toLocalFile());
565 document->setModified(false);
566 document->undoStack()->clear();
567 document->documentInfo()->resetMetaData();
568
569 if (ok) {
570 QString mimeType = KisMimeDatabase::mimeTypeForFile(url.toLocalFile());
571 // in case this is a open document template remove the -template from the end
572 mimeType.remove( QRegularExpression( "-template$" ) );
573 document->setMimeTypeAfterLoading(mimeType);
574 document->resetPath();
575 document->setReadWrite(true);
576 }
577 else {
578 if (document->errorMessage().isEmpty()) {
579 QMessageBox::critical(qApp->activeWindow(), i18nc("@title:window", "Krita"), i18n("Could not create document from template\n%1", document->localFilePath()));
580 }
581 else {
582 QMessageBox::critical(qApp->activeWindow(), i18nc("@title:window", "Krita"), i18n("Could not create document from template\n%1\nReason: %2", document->localFilePath(), document->errorMessage()));
583 }
584 delete document;
585 return;
586 }
587 QMap<QString, QString> dictionary;
588 // XXX: fill the dictionary from the desktop file
590 document->image()->rootLayer()->accept(v);
591
592 addDocument(document);
593
596}
qreal v
KisView * addViewAndNotifyLoadingCompleted(KisDocument *document, QMdiSubWindow *subWindow=0)
static QString mimeTypeForFile(const QString &file, bool checkExistingFiles=true)
Find the mimetype for the given filename. The filename must include a suffix.
void addDocument(KisDocument *document, bool notify=true)
Definition KisPart.cpp:211
KisDocument * createDocument() const
Definition KisPart.cpp:230
KisTranslateLayerNamesVisitor::KisTranslateLayerNamesVisitor translates layer names from templates.

References addDocument(), KisMainWindow::addViewAndNotifyLoadingCompleted(), createDocument(), currentMainwindow(), KisMimeDatabase::mimeTypeForFile(), and v.

◆ playbackEngine()

class KisPlaybackEngine * KisPart::playbackEngine ( ) const

◆ playbackEngineChanged

void KisPart::playbackEngineChanged ( KisPlaybackEngine * newPlaybackEngine)
signal

Emitted when the animation PlaybackEngine is changed. GUI objects that want to control playback should watch this signal and connect to the new playbackEgine as needed.

◆ prioritizeFrameForCache()

void KisPart::prioritizeFrameForCache ( KisImageSP image,
int frame )

Adds a frame time index to a priority stack, which should be cached immediately and irregardless of whether it is the the currently occupied frame. The process of regeneration is started immediately.

Definition at line 530 of file KisPart.cpp.

530 {
531 KisImageAnimationInterface* animInterface = image->animationInterface();
532 if ( animInterface && animInterface->documentPlaybackRange().contains(frame)) {
533 d->animationCachePopulator.requestRegenerationWithPriorityFrame(image, frame);
534 }
535}
const KisTimeSpan & documentPlaybackRange() const
documentPlaybackRange
KisImageAnimationInterface * animationInterface() const
bool contains(int time) const

References KisImage::animationInterface(), KisTimeSpan::contains(), d, and KisImageAnimationInterface::documentPlaybackRange().

◆ Private()

KisPart::Private ( KisPart * _part)
inline

Definition at line 92 of file KisPart.cpp.

93 : part(_part)
94 , idleWatcher(2500)
96 , playbackEngine(nullptr)
97 {
98 }
KisAnimationCachePopulator animationCachePopulator
Definition KisPart.cpp:110
QScopedPointer< KisPlaybackEngine > playbackEngine
Definition KisPart.cpp:111
KisIdleWatcher idleWatcher
Definition KisPart.cpp:109
KisPart * part
Definition KisPart.cpp:104

◆ queryCloseDocument()

bool KisPart::queryCloseDocument ( KisDocument * document)
inline

Definition at line 119 of file KisPart.cpp.

119 {
120 Q_FOREACH(auto view, views) {
121 if (view && view->isVisible() && view->document() == document) {
122 return view->queryClose();
123 }
124 }
125
126 return true;
127 }
QList< QPointer< KisView > > views
Definition KisPart.cpp:106

◆ queueAddRecentURLToAllMainWindowsOnFileSaved()

void KisPart::queueAddRecentURLToAllMainWindowsOnFileSaved ( QUrl url,
QUrl oldUrl = QUrl() )

Registers a file path to be added to the recents list, but do not apply until the file has finished saving.

Definition at line 630 of file KisPart.cpp.

631{
632 d->pendingAddRecentUrlMap.insert(url, oldUrl);
633}

References d.

◆ removeDocument()

void KisPart::removeDocument ( KisDocument * document,
bool deleteDocument = true )

Definition at line 248 of file KisPart.cpp.

249{
250 if (document) {
251 d->documents.removeAll(document);
252 Q_EMIT documentClosed('/' + objectName());
253 Q_EMIT sigDocumentRemoved(document->path());
254 if (deleteDocument) {
255 document->deleteLater();
256 }
257 }
258}
void sigDocumentRemoved(const QString &filename)

References d, documentClosed(), and sigDocumentRemoved().

◆ removeMainWindow()

void KisPart::removeMainWindow ( KisMainWindow * mainWindow)

Removes a main window from the list of managed windows.

This is called by the MainWindow after it finishes its shutdown routine.

Definition at line 464 of file KisPart.cpp.

465{
466 dbgUI <<"mainWindow" << (void*)mainWindow <<"removed from doc" << this;
467 if (mainWindow) {
468 d->mainWindows.removeAll(mainWindow);
469 }
470}

References d, and dbgUI.

◆ removeView()

void KisPart::removeView ( KisView * view)

Removes a view of the document.

HACK ALERT: we check here explicitly if the document (or main window), is saving the stuff. If we close the document before the saving is completed, a crash will happen.

Definition at line 344 of file KisPart.cpp.

345{
346 if (!view) return;
347
355
356 Q_EMIT sigViewRemoved(view);
357
358 QPointer<KisDocument> doc = view->document();
359 d->views.removeAll(view);
360
361 if (doc) {
362 bool found = false;
363 Q_FOREACH (QPointer<KisView> view, d->views) {
364 if (view && view->document() == doc) {
365 found = true;
366 break;
367 }
368 }
369 if (!found) {
370 removeDocument(doc);
371 }
372 }
373}
bool hackIsSaving() const
void removeDocument(KisDocument *document, bool deleteDocument=true)
Definition KisPart.cpp:248
void sigViewRemoved(KisView *view)
KisMainWindow * mainWindow() const
Definition KisView.cpp:1093
QPointer< KisDocument > document
Definition KisView.cpp:121
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References d, KisView::document, KisMainWindow::hackIsSaving(), KIS_ASSERT_RECOVER_RETURN, KisView::mainWindow(), removeDocument(), and sigViewRemoved().

◆ restoreSession() [1/2]

bool KisPart::restoreSession ( const QString & sessionName)

Restores a saved session by name

Definition at line 668 of file KisPart.cpp.

669{
670 if (sessionName.isNull()) return false;
671
673 KisSessionResourceSP session = rserver->resource("", "", sessionName);
674 if (!session || !session->valid()) return false;
675
676 return restoreSession(session);
677}
bool restoreSession(const QString &sessionName)
Definition KisPart.cpp:668
KoResourceServer< KisSessionResource > * sessionServer()
QSharedPointer< T > resource(const QString &md5, const QString &fileName, const QString &name)
resource retrieves a resource. If the md5sum is not empty, the resource will only be retrieved if a r...

References KisResourceServerProvider::instance(), KoResourceServer< T >::resource(), restoreSession(), and KisResourceServerProvider::sessionServer().

◆ restoreSession() [2/2]

bool KisPart::restoreSession ( KisSessionResourceSP session)

Definition at line 679 of file KisPart.cpp.

680{
681 session->restore();
682 d->currentSession = session;
683 return true;
684}

References d.

◆ setCurrentSession()

void KisPart::setCurrentSession ( KisSessionResourceSP session)

Definition at line 686 of file KisPart.cpp.

687{
688 d->currentSession = session;
689}

References d.

◆ setPlaybackEngine()

void KisPart::setPlaybackEngine ( KisPlaybackEngine * p_playbackEngine)
private

Definition at line 719 of file KisPart.cpp.

720{
721 // make sure that the old engine is still alive until the end
722 // of the emitted signal
723 QScopedPointer backup(p_playbackEngine);
724 d->playbackEngine.swap(backup);
725
726 // Log all changes to playback engine for easier debugging.
727 // (See `krita.log` or `Help > Show Krita log for bug reports`.)
728 KisUsageLogger::log("Audio Playback Engine: " + QString(p_playbackEngine->metaObject()->className()));
729
730 Q_EMIT playbackEngineChanged(p_playbackEngine);
731}
void playbackEngineChanged(KisPlaybackEngine *newPlaybackEngine)
static void log(const QString &message)
Logs with date/time.

References d, KisUsageLogger::log(), and playbackEngineChanged().

◆ showSessionManager()

void KisPart::showSessionManager ( )

Definition at line 650 of file KisPart.cpp.

651{
652 if (d->sessionManager.isNull()) {
653 d->sessionManager.reset(new KisSessionManagerDialog());
654 }
655
656 d->sessionManager->show();
657 d->sessionManager->activateWindow();
658}

References d.

◆ sigDocumentAdded

void KisPart::sigDocumentAdded ( KisDocument * document)
signal

◆ sigDocumentRemoved

void KisPart::sigDocumentRemoved ( const QString & filename)
signal

◆ sigDocumentSaved

void KisPart::sigDocumentSaved ( const QString & url)
signal

◆ sigMainWindowCreated

void KisPart::sigMainWindowCreated ( )
signal

◆ sigMainWindowIsBeingCreated

void KisPart::sigMainWindowIsBeingCreated ( KisMainWindow * window)
signal

◆ sigViewAdded

void KisPart::sigViewAdded ( KisView * view)
signal

◆ sigViewRemoved

void KisPart::sigViewRemoved ( KisView * view)
signal

◆ slotDocumentSaved

void KisPart::slotDocumentSaved ( const QString & filePath)
privateslot

Definition at line 447 of file KisPart.cpp.

448{
449 // We used to use doc->path(), but it does not contain the correct output
450 // file path when doing an export, therefore we now pass it directly from
451 // the sigSavingFinished signal.
452 // KisDocument *doc = qobject_cast<KisDocument*>(sender());
453 Q_EMIT sigDocumentSaved(filePath);
454
455 QUrl url = QUrl::fromLocalFile(filePath);
457 if (!d->pendingAddRecentUrlMap.contains(url)) {
458 return;
459 }
460 QUrl oldUrl = d->pendingAddRecentUrlMap.take(url);
461 addRecentURLToAllMainWindows(url, oldUrl);
462}
void sigDocumentSaved(const QString &url)
void addRecentURLToAllMainWindows(QUrl url, QUrl oldUrl=QUrl())
Definition KisPart.cpp:598
static KisRecentFileIconCache * instance()
void reloadFileIcon(const QUrl &url)

References addRecentURLToAllMainWindows(), d, KisRecentFileIconCache::instance(), KisRecentFileIconCache::reloadFileIcon(), and sigDocumentSaved().

◆ startBlankSession()

void KisPart::startBlankSession ( )

Definition at line 660 of file KisPart.cpp.

661{
663 window->initializeGeometry();
664 window->show();
665
666}
KisMainWindow * createMainWindow(QUuid id=QUuid())
Definition KisPart.cpp:260

References createMainWindow(), and KisMainWindow::initializeGeometry().

◆ startCustomDocument

void KisPart::startCustomDocument ( KisDocument * doc)
slot

startCustomDocument adds the given document to the document list and deletes the sender()

Parameters
doc

Definition at line 635 of file KisPart.cpp.

636{
637 addDocument(doc);
640
641}

References addDocument(), KisMainWindow::addViewAndNotifyLoadingCompleted(), and currentMainwindow().

◆ unloadPlaybackEngine()

void KisPart::unloadPlaybackEngine ( )

Called on application to make sure that the engine is unloaded before the MLT library is actually unloaded

Definition at line 710 of file KisPart.cpp.

711{
712#ifdef HAVE_MLT
713
714 d->playbackEngine.reset();
715
716#endif //HAVE_MLT
717}

References d.

◆ updateIdleWatcherConnections

void KisPart::updateIdleWatcherConnections ( )
privateslot

Update memory stats on changing the amount of images open in Krita

Definition at line 193 of file KisPart.cpp.

194{
195 QVector<KisImageSP> images;
196
197 Q_FOREACH (QPointer<KisDocument> document, documents()) {
198 if (document->image()) {
199 images << document->image();
200 }
201 }
202
203 d->idleWatcher.setTrackedImages(images);
204
208 d->idleWatcher.forceImageModified();
209}
QList< QPointer< KisDocument > > documents
Definition KisPart.cpp:108

References d, and documents.

◆ updateShortcuts

void KisPart::updateShortcuts ( )
privateslot

Definition at line 547 of file KisPart.cpp.

548{
549 // Update the UI actions. KisActionRegistry also takes care of updating
550 // shortcut hints in tooltips.
551 Q_FOREACH (KisMainWindow *mainWindow, d->mainWindows) {
552 KisKActionCollection *ac = mainWindow->actionCollection();
553
554 ac->updateShortcuts();
555 }
556}
A container for a set of QAction objects.

References KisKXMLGUIClient::actionCollection(), d, and KisKActionCollection::updateShortcuts().

◆ upgradeToPlaybackEngineMLT()

void KisPart::upgradeToPlaybackEngineMLT ( class KoCanvasBase * canvas)

Definition at line 691 of file KisPart.cpp.

692{
693#ifdef HAVE_MLT
694
695 // TODO: This is a slightly hacky workaround to loading the MLT engine over itself,
696 // as the QT-based engine no longer supports audio. Is there a better way?
697 if (d->playbackEngine->supportsAudio()) {
698 return;
699 }
700
702
703 if (canvas) {
704 d->playbackEngine->setObservedCanvas(canvas);
705 }
706
707#endif //HAVE_MLT
708}
The KisPlaybackEngineMLT class is an implementation of KisPlaybackEngine that uses MLT (Media Lovin' ...
KisCanvas2 * canvas

References Private::canvas, d, and setPlaybackEngine().

◆ viewCount()

int KisPart::viewCount ( KisDocument * doc) const
Returns
number of views this document is displayed in

Definition at line 380 of file KisPart.cpp.

381{
382 if (!doc) {
383 return d->views.count();
384 }
385 else {
386 int count = 0;
387 Q_FOREACH (QPointer<KisView> view, d->views) {
388 if (view && view->isVisible() && view->document() == doc) {
389 count++;
390 }
391 }
392 return count;
393 }
394}

References d.

◆ views()

QList< QPointer< KisView > > KisPart::views ( ) const
Returns
a list of views this document is displayed in

◆ windowById()

KisMainWindow * KisPart::windowById ( QUuid id) const

Definition at line 504 of file KisPart.cpp.

505{
506 Q_FOREACH(QPointer<KisMainWindow> mainWindow, d->mainWindows) {
507 if (mainWindow->id() == id) {
508 return mainWindow;
509 }
510 }
511
512 return nullptr;
513}

References d.

Member Data Documentation

◆ animationCachePopulator

KisAnimationCachePopulator KisPart::animationCachePopulator

Definition at line 110 of file KisPart.cpp.

◆ closingSession

bool KisPart::closingSession {false}

Definition at line 114 of file KisPart.cpp.

114{false};

◆ currentSession

KisSessionResourceSP KisPart::currentSession

Definition at line 113 of file KisPart.cpp.

◆ d

Private* const KisPart::d
private

Definition at line 328 of file KisPart.h.

◆ documents

QList< QPointer< KisDocument > > KisPart::documents

Definition at line 108 of file KisPart.cpp.

◆ idleWatcher

KisIdleWatcher * KisPart::idleWatcher

Definition at line 109 of file KisPart.cpp.

◆ mainWindows

const QList< QPointer< KisMainWindow > > & KisPart::mainWindows

Definition at line 107 of file KisPart.cpp.

◆ part

KisPart* KisPart::part

Definition at line 104 of file KisPart.cpp.

◆ pendingAddRecentUrlMap

QMap<QUrl, QUrl> KisPart::pendingAddRecentUrlMap

Definition at line 117 of file KisPart.cpp.

◆ playbackEngine

KisPlaybackEngine * KisPart::playbackEngine

Definition at line 111 of file KisPart.cpp.

◆ sessionManager

QScopedPointer<KisSessionManagerDialog> KisPart::sessionManager

Definition at line 115 of file KisPart.cpp.

◆ views

QList< QPointer< KisView > > KisPart::views

Definition at line 106 of file KisPart.cpp.


The documentation for this class was generated from the following files: