...
 
Commits (3)
......@@ -640,8 +640,7 @@ private Q_SLOTS:
void slotConfigChanged();
private:
public:
/**
* @brief try to clone the image. This method handles all the locking for you. If locking
* has failed, no cloning happens
......@@ -649,6 +648,8 @@ private:
*/
KisDocument *lockAndCloneForSaving();
private:
QString exportErrorToUserMessage(KisImportExportErrorCode status, const QString &errorMessage);
QString prettyPathOrUrl() const;
......
......@@ -51,6 +51,7 @@
#include <QStatusBar>
#include <QMoveEvent>
#include <QMdiSubWindow>
#include <QMap>
#include <kis_image.h>
#include <kis_node.h>
......@@ -88,6 +89,7 @@
#include "input/kis_input_manager.h"
#include "KisRemoteFileFetcher.h"
#include "kis_selection_manager.h"
#include <kis_signal_auto_connection.h>
//static
QString KisView::newObjectName()
......@@ -106,10 +108,12 @@ public:
KisDocument *document,
KoCanvasResourceProvider *resourceManager,
KActionCollection *actionCollection)
: actionCollection(actionCollection)
: q(_q)
, actionCollection(actionCollection)
, resourceManager(resourceManager)
, viewConverter()
, canvasController(_q, actionCollection)
, canvas(&viewConverter, resourceManager, _q, document->shapeController())
, canvas(new KisCanvas2(&viewConverter, resourceManager, _q, document->shapeController()))
, zoomManager(_q, &this->viewConverter, &this->canvasController)
, paintingAssistantsDecoration(new KisPaintingAssistantsDecoration(_q))
, referenceImagesDecoration(new KisReferenceImagesDecoration(_q, document))
......@@ -119,6 +123,7 @@ public:
bool inOperation; //in the middle of an operation (no screen refreshing)?
KisView *q;
QPointer<KisDocument> document; // our KisDocument
QWidget *tempActiveWidget = 0;
......@@ -131,9 +136,11 @@ public:
bool documentDeleted = false;
KActionCollection* actionCollection;
QPointer<KoCanvasResourceProvider> resourceManager;
KisCoordinatesConverter viewConverter;
KisCanvasController canvasController;
KisCanvas2 canvas;
QScopedPointer<KisCanvas2> canvas;
QMap<KisDocument*, QPointer<KisCanvas2> > docCanvasMap;
KisZoomManager zoomManager;
KisViewManager *viewManager = 0;
KisNodeSP currentNode;
......@@ -147,6 +154,8 @@ public:
bool softProofing = false;
bool gamutCheck = false;
KisSignalAutoConnectionsStore docConnections;
KisSignalAutoConnectionsStore imageConnections;
// Hmm sorry for polluting the private class with such a big inner class.
// At the beginning it was a little struct :)
......@@ -204,50 +213,64 @@ public:
};
void setupDocument();
void setupCanvas();
};
void KisView::Private::setupDocument()
{
docConnections.clear();
docConnections.addConnection(document, SIGNAL(titleModified(QString,bool)), q, SIGNAL(titleModified(QString,bool)));
QStatusBar * sb = q->statusBar();
if (sb) { // No statusbar in e.g. konqueror
docConnections.addConnection(document, SIGNAL(statusBarMessage(QString,int)),
q, SLOT(slotSavingStatusMessage(QString,int)));
docConnections.addConnection(document, SIGNAL(clearStatusBarMessage()),
q, SLOT(slotClearStatusText()));
}
docConnections.addConnection(document, SIGNAL(sigLoadingFinished()), q, SLOT(slotLoadingFinished()));
docConnections.addConnection(document, SIGNAL(sigSavingFinished()), q, SLOT(slotSavingFinished()));
}
void KisView::Private::setupCanvas()
{
canvas->setupDocument();
canvas->setup();
canvasController.setCanvas(canvas.get());
canvas->addDecoration(referenceImagesDecoration);
canvas->addDecoration(paintingAssistantsDecoration);
}
KisView::KisView(KisDocument *document, KoCanvasResourceProvider *resourceManager, KActionCollection *actionCollection, QWidget *parent)
: QWidget(parent)
, d(new Private(this, document, resourceManager, actionCollection))
{
Q_ASSERT(document);
connect(document, SIGNAL(titleModified(QString,bool)), this, SIGNAL(titleModified(QString,bool)));
setObjectName(newObjectName());
d->document = document;
setFocusPolicy(Qt::StrongFocus);
d->setupDocument();
d->setupCanvas();
QStatusBar * sb = statusBar();
if (sb) { // No statusbar in e.g. konqueror
connect(d->document, SIGNAL(statusBarMessage(QString,int)),
this, SLOT(slotSavingStatusMessage(QString,int)));
connect(d->document, SIGNAL(clearStatusBarMessage()),
this, SLOT(slotClearStatusText()));
}
setObjectName(newObjectName());
d->canvas.setup();
setFocusPolicy(Qt::StrongFocus);
KisConfig cfg(false);
d->canvasController.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
d->canvasController.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
d->canvasController.setVastScrolling(cfg.vastScrolling());
d->canvasController.setCanvas(&d->canvas);
d->zoomManager.setup(d->actionCollection);
connect(&d->canvasController, SIGNAL(documentSizeChanged()), &d->zoomManager, SLOT(slotScrollAreaSizeChanged()));
setAcceptDrops(true);
connect(d->document, SIGNAL(sigLoadingFinished()), this, SLOT(slotLoadingFinished()));
connect(d->document, SIGNAL(sigSavingFinished()), this, SLOT(slotSavingFinished()));
d->canvas.addDecoration(d->referenceImagesDecoration);
d->referenceImagesDecoration->setVisible(true);
d->canvas.addDecoration(d->paintingAssistantsDecoration);
d->paintingAssistantsDecoration->setVisible(true);
d->showFloatingMessage = cfg.showCanvasMessages();
......@@ -268,6 +291,9 @@ KisView::~KisView()
d->canvasController.setCanvas(0);
KisPart::instance()->removeView(this);
Q_FOREACH (QPointer<KisCanvas2> canvas, d->docCanvasMap.values()) {
delete canvas.data();
}
delete d;
}
......@@ -323,7 +349,7 @@ void KisView::showFloatingMessage(const QString &message, const QIcon& icon, int
bool KisView::canvasIsMirrored() const
{
return d->canvas.xAxisMirrored() || d->canvas.yAxisMirrored();
return canvasBase()->xAxisMirrored() || canvasBase()->yAxisMirrored();
}
void KisView::setViewManager(KisViewManager *view)
......@@ -332,7 +358,7 @@ void KisView::setViewManager(KisViewManager *view)
KoToolManager::instance()->addController(&d->canvasController);
KoToolManager::instance()->registerToolActions(d->actionCollection, &d->canvasController);
dynamic_cast<KisShapeController*>(d->document->shapeController())->setInitialShapeForCanvas(&d->canvas);
dynamic_cast<KisShapeController*>(d->document->shapeController())->setInitialShapeForCanvas(canvasBase());
if (resourceProvider()) {
resourceProvider()->slotImageSizeChanged();
......@@ -440,7 +466,7 @@ KisInputManager* KisView::globalInputManager() const
KisCanvas2 *KisView::canvasBase() const
{
return &d->canvas;
return d->canvas.get();
}
KisImageWSP KisView::image() const
......@@ -633,15 +659,14 @@ KisDocument *KisView::document() const
void KisView::setDocument(KisDocument *document)
{
d->document->disconnect(this);
KisDocument *oldDocument = d->document;
d->document = document;
QStatusBar *sb = statusBar();
if (sb) { // No statusbar in e.g. konqueror
connect(d->document, SIGNAL(statusBarMessage(QString,int)),
this, SLOT(slotSavingStatusMessage(QString,int)));
connect(d->document, SIGNAL(clearStatusBarMessage()),
this, SLOT(slotClearStatusText()));
}
d->setupDocument();
d->docCanvasMap.insert(oldDocument, QPointer<KisCanvas2>(d->canvas.take()));
dbgUI << (void*)&d->viewConverter;
d->canvas.reset(new KisCanvas2(&d->viewConverter, d->resourceManager, this, d->document->shapeController()));
d->canvasController.setCanvas(0);
d->setupCanvas();
}
void KisView::setDocumentDeleted()
......@@ -799,7 +824,7 @@ void KisView::resetImageSizeAndScroll(bool changeCentering,
const QPointF &oldImageStillPoint,
const QPointF &newImageStillPoint)
{
const KisCoordinatesConverter *converter = d->canvas.coordinatesConverter();
const KisCoordinatesConverter *converter = canvasBase()->coordinatesConverter();
QPointF oldPreferredCenter = d->canvasController.preferredCenter();
......@@ -866,7 +891,7 @@ void KisView::saveViewState(KisPropertiesConfiguration &config) const
}
config.setProperty("zoomMode", (int)zoomController()->zoomMode());
config.setProperty("zoom", d->canvas.coordinatesConverter()->zoom());
config.setProperty("zoom", canvasBase()->coordinatesConverter()->zoom());
d->canvasController.saveCanvasState(config);
}
......@@ -887,7 +912,7 @@ void KisView::restoreViewState(const KisPropertiesConfiguration &config)
void KisView::setCurrentNode(KisNodeSP node)
{
d->currentNode = node;
d->canvas.slotTrySwitchShapeManager();
canvasBase()->slotTrySwitchShapeManager();
syncLastActiveNodeToDocument();
}
......@@ -1005,9 +1030,10 @@ void KisView::slotLoadingFinished()
if (viewConverter()) {
viewConverter()->setZoomMode(KoZoomMode::ZOOM_PAGE);
}
connect(image(), SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), this, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)));
connect(image(), SIGNAL(sigProfileChanged(const KoColorProfile*)), this, SIGNAL(sigProfileChanged(const KoColorProfile*)));
connect(image(), SIGNAL(sigSizeChanged(QPointF,QPointF)), this, SIGNAL(sigSizeChanged(QPointF,QPointF)));
d->imageConnections.clear();
d->imageConnections.addConnection(image(), SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), this, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)));
d->imageConnections.addConnection(image(), SIGNAL(sigProfileChanged(const KoColorProfile*)), this, SIGNAL(sigProfileChanged(const KoColorProfile*)));
d->imageConnections.addConnection(image(), SIGNAL(sigSizeChanged(QPointF,QPointF)), this, SIGNAL(sigSizeChanged(QPointF,QPointF)));
KisNodeSP activeNode = document()->preActivatedNode();
......@@ -1045,7 +1071,7 @@ void KisView::slotImageResolutionChanged()
// update KoUnit value for the document
if (resourceProvider()) {
resourceProvider()->resourceManager()->
setResource(KoCanvasResourceProvider::Unit, d->canvas.unit());
setResource(KoCanvasResourceProvider::Unit, canvasBase()->unit());
}
}
......
......@@ -100,6 +100,7 @@
#include "kis_image_signal_router.h"
#include "KisSnapPixelStrategy.h"
#include <kis_signal_auto_connection.h>
class Q_DECL_HIDDEN KisCanvas2::KisCanvas2Private
......@@ -157,6 +158,9 @@ public:
QRect renderingLimit;
int isBatchUpdateActive = 0;
KisSignalAutoConnectionsStore docConnections;
KisSignalAutoConnectionsStore imageConnections;
bool effectiveLodAllowedInImage() {
return lodAllowedInImage && !bootstrapLodBlocked;
}
......@@ -260,7 +264,7 @@ void KisCanvas2::setup()
connect(&m_d->regionOfInterestUpdateCompressor, SIGNAL(timeout()), SLOT(slotUpdateRegionOfInterest()));
connect(m_d->view->document(), SIGNAL(sigReferenceImagesChanged()), this, SLOT(slotReferenceImagesChanged()));
setupDocument();
initializeFpsDecoration();
}
......@@ -569,21 +573,23 @@ void KisCanvas2::initializeImage()
{
KisImageSP image = m_d->view->image();
m_d->imageConnections.clear();
m_d->displayColorConverter.setImageColorSpace(image->colorSpace());
m_d->coordinatesConverter->setImage(image);
m_d->toolProxy.initializeImage(image);
connect(image, SIGNAL(sigImageUpdated(QRect)), SLOT(startUpdateCanvasProjection(QRect)), Qt::DirectConnection);
connect(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateStarted()), SLOT(slotBeginUpdatesBatch()), Qt::DirectConnection);
connect(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateEnded()), SLOT(slotEndUpdatesBatch()), Qt::DirectConnection);
connect(image->signalRouter(), SIGNAL(sigRequestLodPlanesSyncBlocked(bool)), SLOT(slotSetLodUpdatesBlocked(bool)), Qt::DirectConnection);
m_d->imageConnections.addConnection(image, SIGNAL(sigImageUpdated(QRect)), this, SLOT(startUpdateCanvasProjection(QRect)), Qt::DirectConnection);
m_d->imageConnections.addConnection(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateStarted()), this, SLOT(slotBeginUpdatesBatch()), Qt::DirectConnection);
m_d->imageConnections.addConnection(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateEnded()), this, SLOT(slotEndUpdatesBatch()), Qt::DirectConnection);
m_d->imageConnections.addConnection(image->signalRouter(), SIGNAL(sigRequestLodPlanesSyncBlocked(bool)), this, SLOT(slotSetLodUpdatesBlocked(bool)), Qt::DirectConnection);
connect(image, SIGNAL(sigProofingConfigChanged()), SLOT(slotChangeProofingConfig()));
connect(image, SIGNAL(sigSizeChanged(QPointF,QPointF)), SLOT(startResizingImage()), Qt::DirectConnection);
connect(image->undoAdapter(), SIGNAL(selectionChanged()), SLOT(slotTrySwitchShapeManager()));
m_d->imageConnections.addConnection(image, SIGNAL(sigProofingConfigChanged()), this, SLOT(slotChangeProofingConfig()));
m_d->imageConnections.addConnection(image, SIGNAL(sigSizeChanged(QPointF,QPointF)), this, SLOT(startResizingImage()), Qt::DirectConnection);
m_d->imageConnections.addConnection(image->undoAdapter(), SIGNAL(selectionChanged()), this, SLOT(slotTrySwitchShapeManager()));
connect(image, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), SLOT(slotImageColorSpaceChanged()));
connect(image, SIGNAL(sigProfileChanged(const KoColorProfile*)), SLOT(slotImageColorSpaceChanged()));
m_d->imageConnections.addConnection(image, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), this, SLOT(slotImageColorSpaceChanged()));
m_d->imageConnections.addConnection(image, SIGNAL(sigProfileChanged(const KoColorProfile*)), this, SLOT(slotImageColorSpaceChanged()));
connectCurrentCanvas();
}
......@@ -1109,6 +1115,13 @@ void KisCanvas2::slotConfigChanged()
initializeFpsDecoration();
}
void KisCanvas2::setupDocument()
{
m_d->docConnections.clear();
m_d->docConnections.addConnection(m_d->view->document(), SIGNAL(sigReferenceImagesChanged()),
this, SLOT(slotReferenceImagesChanged()));
}
void KisCanvas2::refetchDataFromImage()
{
KisImageSP image = this->image();
......
......@@ -273,7 +273,7 @@ public Q_SLOTS:
* Called whenever the configuration settings change.
*/
void slotConfigChanged();
void setupDocument();
private Q_SLOTS:
......
......@@ -33,3 +33,4 @@ if(NOT APPLE AND HAVE_QT_QUICK)
endif()
add_subdirectory(logdocker)
add_subdirectory(snapshotdocker)
\ No newline at end of file
......@@ -137,6 +137,9 @@ void OverviewDockerDock::rotateCanvasView(qreal rotation)
void OverviewDockerDock::updateSlider()
{
if (!m_canvas) {
return;
}
KisSignalsBlocker l(m_rotateSlider);
qreal rotation = m_canvas->rotationAngle();
......
set(kritasnapshotdocker_SOURCES
KisSnapshotModel.cpp
SnapshotDocker.cpp
SnapshotPlugin.cpp
)
add_library(kritasnapshotdocker MODULE ${kritasnapshotdocker_SOURCES})
target_link_libraries(kritasnapshotdocker kritaimage kritaui)
install(TARGETS kritasnapshotdocker DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
\ No newline at end of file
/*
* Copyright (c) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KisSnapshotModel.h"
#include <QMap>
#include <QList>
#include <QPointer>
#include <QPair>
#include <QString>
#include <KisDocument.h>
#include <KisView.h>
#include <KisPart.h>
#include <KisViewManager.h>
struct KisSnapshotModel::Private
{
Private();
virtual ~Private();
QPointer<KisDocument> curDocument();
bool switchToDocument(QPointer<KisDocument> doc);
using DocPList = QList<QPair<QString, QPointer<KisDocument> > >;
DocPList curDocList;
QList<DocPList> documentGroups;
QPointer<KisCanvas2> curCanvas;
};
KisSnapshotModel::Private::Private()
{
}
KisSnapshotModel::Private::~Private()
{
}
QPointer<KisDocument> KisSnapshotModel::Private::curDocument()
{
if (curCanvas && curCanvas->imageView()) {
return curCanvas->imageView()->document();
}
return 0;
}
bool KisSnapshotModel::Private::switchToDocument(QPointer<KisDocument> doc)
{
if (curCanvas && curCanvas->imageView()) {
KisPart::instance()->addDocument(doc);
KisView *view = curCanvas->imageView();
view->setDocument(doc);
view->slotLoadingFinished();
// to reset the view
view->viewManager()->setCurrentView(view);
curCanvas->updateCanvas();
// FIXME: more things need to be done
return true;
}
return false;
}
KisSnapshotModel::KisSnapshotModel()
: QAbstractListModel()
, m_d(new Private)
{
}
KisSnapshotModel::~KisSnapshotModel()
{
}
int KisSnapshotModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
} else {
return m_d->curDocList.size();
}
}
QVariant KisSnapshotModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= rowCount(QModelIndex())) {
return QVariant();
}
int i = index.row();
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:
return m_d->curDocList[i].first;
break;
}
return QVariant();
}
bool KisSnapshotModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
return false;
}
void KisSnapshotModel::setCanvas(QPointer<KisCanvas2> canvas)
{
if (m_d->curCanvas == canvas) {
return;
}
if (m_d->curCanvas) {
// if any one doc in the group is no longer valid (is closed)
// destroy all other snapshots
bool docValid = true;
Q_FOREACH (auto const &i, m_d->curDocList) {
if (! i.second) {
docValid = false;
break;
}
}
if (docValid) {
m_d->documentGroups << m_d->curDocList;
} else {
Q_FOREACH (auto const &i, m_d->curDocList) {
delete i.second.data();
}
}
}
if (!m_d->curDocList.isEmpty()) {
beginRemoveRows(QModelIndex(), 0, m_d->curDocList.size() - 1);
m_d->curDocList.clear();
endRemoveRows();
}
m_d->curCanvas = canvas;
QPointer<KisDocument> curDoc = m_d->curDocument();
if (curDoc) {
for (int i = 0; i < m_d->documentGroups.size(); ++i) {
const Private::DocPList &docList = m_d->documentGroups[i];
Q_FOREACH (auto const &j, docList) {
if (j.second == curDoc) {
m_d->curDocList = m_d->documentGroups.takeAt(i);
return;
}
}
}
// we have not found any existing group containing the current document
beginInsertRows(QModelIndex(), m_d->curDocList.size(), m_d->curDocList.size());
m_d->curDocList << qMakePair(i18n("Original Document"), curDoc); /// XXX: a better title for it?
endInsertRows();
}
}
bool KisSnapshotModel::slotCreateSnapshot()
{
QPointer<KisDocument> clonedDoc(m_d->curDocument()->lockAndCloneForSaving());
if (clonedDoc) {
beginInsertRows(QModelIndex(), m_d->curDocList.size(), m_d->curDocList.size());
m_d->curDocList << qMakePair(i18n("Snapshot"), clonedDoc);
endInsertRows();
return true;
}
return false;
}
bool KisSnapshotModel::slotRemoveActivatedSnapshot()
{
return false;
}
bool KisSnapshotModel::slotSwitchToActivatedSnapshot(const QModelIndex &index)
{
if (!index.isValid() || index.row() >= m_d->curDocList.size()) {
return false;
}
return m_d->switchToDocument(m_d->curDocList[index.row()].second);
}
/*
* Copyright (c) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_SNAPSHOT_MODEL_H_
#define KIS_SNAPSHOT_MODEL_H_
#include <QAbstractListModel>
#include <QScopedPointer>
#include <QPointer>
#include <kis_canvas2.h>
class KisSnapshotModel : public QAbstractListModel
{
public:
KisSnapshotModel();
~KisSnapshotModel() override;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
void setCanvas(QPointer<KisCanvas2> canvas);
public Q_SLOTS:
bool slotCreateSnapshot();
bool slotRemoveActivatedSnapshot();
bool slotSwitchToActivatedSnapshot(const QModelIndex &index);
private:
struct Private;
QScopedPointer<Private> m_d;
};
#endif // KIS_SNAPSHOT_MODEL_H_
/*
* Copyright (c) 2019 Tusooa Zhu <tusooa@vista.aero>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "SnapshotDocker.h"
#include <QWidget>
#include <QListView>
#include <QToolButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "KisSnapshotModel.h"
#include <kis_canvas2.h>
#include <kis_icon_utils.h>
struct SnapshotDocker::Private
{
Private();
~Private();
QScopedPointer<KisSnapshotModel> model;
QPointer<QListView> view;
QPointer<KisCanvas2> canvas;
QPointer<QToolButton> bnAdd;
QPointer<QToolButton> bnRemove;
};
SnapshotDocker::Private::Private()
: model(new KisSnapshotModel)
, view(new QListView)
, canvas(0)
, bnAdd(new QToolButton)
, bnRemove(new QToolButton)
{
}
SnapshotDocker::Private::~Private()
{
}
SnapshotDocker::SnapshotDocker()
: QDockWidget()
, m_d(new Private)
{
QWidget *widget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(widget);
connect(m_d->view, &QListView::activated, m_d->model.data(), &KisSnapshotModel::slotSwitchToActivatedSnapshot);
m_d->view->setModel(m_d->model.data());
mainLayout->addWidget(m_d->view);
QHBoxLayout *buttonsLayout = new QHBoxLayout(widget);
m_d->bnAdd->setIcon(KisIconUtils::loadIcon("addlayer"));
connect(m_d->bnAdd, &QToolButton::clicked, m_d->model.data(), &KisSnapshotModel::slotCreateSnapshot);
buttonsLayout->addWidget(m_d->bnAdd);
m_d->bnRemove->setIcon(KisIconUtils::loadIcon("deletelayer"));
connect(m_d->bnRemove, &QToolButton::clicked, m_d->model.data(), &KisSnapshotModel::slotRemoveActivatedSnapshot);
buttonsLayout->addWidget(m_d->bnRemove);
mainLayout->addLayout(buttonsLayout);
setWidget(widget);
setWindowTitle(i18n("Snapshot Docker"));
}
SnapshotDocker::~SnapshotDocker()
{
}
void SnapshotDocker::setCanvas(KoCanvasBase *canvas)
{
KisCanvas2 *c = dynamic_cast<KisCanvas2 *>(canvas);
if (c) {
if (m_d->canvas == c) {
return;
}
}
m_d->canvas = c;
m_d->model->setCanvas(c);
}
void SnapshotDocker::unsetCanvas()
{
setCanvas(0);
}
#include "SnapshotDocker.moc"
/* This file is part of the KDE project
* Copyright (C) 2010 Matus Talcik <matus.talcik@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef SNAPSHOT_DOCKER_H_
#define SNAPSHOT_DOCKER_H_
#include <QDockWidget>
#include <QScopedPointer>
#include <KoCanvasObserverBase.h>
#include <klocalizedstring.h>
#include <KoShapeController.h>
#include <KoCanvasBase.h>
class SnapshotDocker : public QDockWidget, public KoCanvasObserverBase
{
Q_OBJECT
public:
SnapshotDocker();
~SnapshotDocker() override;
QString observerName() override { return "SnapshotDocker"; }
void setCanvas(KoCanvasBase *canvas) override;
void unsetCanvas() override;
private Q_SLOTS:
private:
struct Private;
QScopedPointer<Private> m_d;
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2010 Matus Talcik <matus.talcik@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "SnapshotPlugin.h"
#include <kpluginfactory.h>
#include <klocalizedstring.h>
#include <KoDockFactoryBase.h>
#include <KoDockRegistry.h>
#include "SnapshotDocker.h"
K_PLUGIN_FACTORY_WITH_JSON(SnapshotPluginFactory, "kritasnapshotdocker.json", registerPlugin<SnapshotPlugin>();)
class SnapshotDockFactory : public KoDockFactoryBase
{
public:
SnapshotDockFactory() {
}
QString id() const override {
return QString("Snapshot");
}
virtual Qt::DockWidgetArea defaultDockWidgetArea() const {
return Qt::RightDockWidgetArea;
}
QDockWidget *createDockWidget() override {
SnapshotDocker *dockWidget = new SnapshotDocker();
dockWidget->setObjectName(id());
return dockWidget;
}
DockPosition defaultDockPosition() const override {
return DockRight;
}
};
SnapshotPlugin::SnapshotPlugin(QObject *parent, const QVariantList &)
: QObject(parent)
{
KoDockRegistry::instance()->add(new SnapshotDockFactory());
}
SnapshotPlugin::~SnapshotPlugin()
{
}
#include "SnapshotPlugin.moc"
/* This file is part of the KDE project
* Copyright (C) 2010 Matus Talcik <matus.talcik@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef SNAPSHOT_PLUGIN_H_
#define SNAPSHOT_PLUGIN_H_
#include <QObject>
#include <QVariant>
class SnapshotPlugin : public QObject
{
Q_OBJECT
public:
SnapshotPlugin(QObject *parent, const QVariantList &);
~SnapshotPlugin() override;
};
#endif
{
"Id": "Krita Snapshot Docker plugin",
"Type": "Service",
"X-KDE-Library": "kritasnapshotdocker",
"X-KDE-ServiceTypes": [
"Krita/Dock"
],
"X-Krita-Version": "28"
}