1 /*
2  *  Copyright (c) 2018 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 #include "KisCloneDocumentStroke.h"
19 
20 #include "KisDocument.h"
21 #include "kis_layer_utils.h"
22 
23 #include <QApplication>
24 
25 
26 struct KRITAIMAGE_NO_EXPORT KisCloneDocumentStroke::Private
27 {
PrivateKisCloneDocumentStroke::Private28     Private(KisDocument *_document)
29         : document(_document)
30     {
31     }
32 
33     KisDocument *document = 0;
34 };
35 
KisCloneDocumentStroke(KisDocument * document)36 KisCloneDocumentStroke::KisCloneDocumentStroke(KisDocument *document)
37     : KisSimpleStrokeStrategy(QLatin1String("clone-document-stroke"), kundo2_i18n("Clone Document")),
38       m_d(new Private(document))
39 {
40     setClearsRedoOnStart(false);
41     setRequestsOtherStrokesToEnd(false);
42     enableJob(JOB_INIT, true, KisStrokeJobData::BARRIER, KisStrokeJobData::EXCLUSIVE);
43     enableJob(JOB_FINISH, true, KisStrokeJobData::BARRIER, KisStrokeJobData::EXCLUSIVE);
44 }
45 
~KisCloneDocumentStroke()46 KisCloneDocumentStroke::~KisCloneDocumentStroke()
47 {
48 }
49 
initStrokeCallback()50 void KisCloneDocumentStroke::initStrokeCallback()
51 {
52     KisLayerUtils::forceAllDelayedNodesUpdate(m_d->document->image()->root());
53 }
54 
finishStrokeCallback()55 void KisCloneDocumentStroke::finishStrokeCallback()
56 {
57     KisDocument *doc = m_d->document->clone();
58     doc->moveToThread(qApp->thread());
59     emit sigDocumentCloned(doc);
60 }
61