...
 
Commits (3)
...@@ -640,8 +640,7 @@ private Q_SLOTS: ...@@ -640,8 +640,7 @@ private Q_SLOTS:
void slotConfigChanged(); void slotConfigChanged();
public:
private:
/** /**
* @brief try to clone the image. This method handles all the locking for you. If locking * @brief try to clone the image. This method handles all the locking for you. If locking
* has failed, no cloning happens * has failed, no cloning happens
...@@ -649,6 +648,8 @@ private: ...@@ -649,6 +648,8 @@ private:
*/ */
KisDocument *lockAndCloneForSaving(); KisDocument *lockAndCloneForSaving();
private:
QString exportErrorToUserMessage(KisImportExportErrorCode status, const QString &errorMessage); QString exportErrorToUserMessage(KisImportExportErrorCode status, const QString &errorMessage);
QString prettyPathOrUrl() const; QString prettyPathOrUrl() const;
......
This diff is collapsed.
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
#include "kis_image_signal_router.h" #include "kis_image_signal_router.h"
#include "KisSnapPixelStrategy.h" #include "KisSnapPixelStrategy.h"
#include <kis_signal_auto_connection.h>
class Q_DECL_HIDDEN KisCanvas2::KisCanvas2Private class Q_DECL_HIDDEN KisCanvas2::KisCanvas2Private
...@@ -157,6 +158,9 @@ public: ...@@ -157,6 +158,9 @@ public:
QRect renderingLimit; QRect renderingLimit;
int isBatchUpdateActive = 0; int isBatchUpdateActive = 0;
KisSignalAutoConnectionsStore docConnections;
KisSignalAutoConnectionsStore imageConnections;
bool effectiveLodAllowedInImage() { bool effectiveLodAllowedInImage() {
return lodAllowedInImage && !bootstrapLodBlocked; return lodAllowedInImage && !bootstrapLodBlocked;
} }
...@@ -260,7 +264,7 @@ void KisCanvas2::setup() ...@@ -260,7 +264,7 @@ void KisCanvas2::setup()
connect(&m_d->regionOfInterestUpdateCompressor, SIGNAL(timeout()), SLOT(slotUpdateRegionOfInterest())); connect(&m_d->regionOfInterestUpdateCompressor, SIGNAL(timeout()), SLOT(slotUpdateRegionOfInterest()));
connect(m_d->view->document(), SIGNAL(sigReferenceImagesChanged()), this, SLOT(slotReferenceImagesChanged())); setupDocument();
initializeFpsDecoration(); initializeFpsDecoration();
} }
...@@ -569,21 +573,23 @@ void KisCanvas2::initializeImage() ...@@ -569,21 +573,23 @@ void KisCanvas2::initializeImage()
{ {
KisImageSP image = m_d->view->image(); KisImageSP image = m_d->view->image();
m_d->imageConnections.clear();
m_d->displayColorConverter.setImageColorSpace(image->colorSpace()); m_d->displayColorConverter.setImageColorSpace(image->colorSpace());
m_d->coordinatesConverter->setImage(image); m_d->coordinatesConverter->setImage(image);
m_d->toolProxy.initializeImage(image); m_d->toolProxy.initializeImage(image);
connect(image, SIGNAL(sigImageUpdated(QRect)), SLOT(startUpdateCanvasProjection(QRect)), Qt::DirectConnection); m_d->imageConnections.addConnection(image, SIGNAL(sigImageUpdated(QRect)), this, SLOT(startUpdateCanvasProjection(QRect)), Qt::DirectConnection);
connect(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateStarted()), SLOT(slotBeginUpdatesBatch()), Qt::DirectConnection); m_d->imageConnections.addConnection(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateStarted()), this, SLOT(slotBeginUpdatesBatch()), Qt::DirectConnection);
connect(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateEnded()), SLOT(slotEndUpdatesBatch()), Qt::DirectConnection); m_d->imageConnections.addConnection(image->signalRouter(), SIGNAL(sigNotifyBatchUpdateEnded()), this, SLOT(slotEndUpdatesBatch()), Qt::DirectConnection);
connect(image->signalRouter(), SIGNAL(sigRequestLodPlanesSyncBlocked(bool)), SLOT(slotSetLodUpdatesBlocked(bool)), Qt::DirectConnection); m_d->imageConnections.addConnection(image->signalRouter(), SIGNAL(sigRequestLodPlanesSyncBlocked(bool)), this, SLOT(slotSetLodUpdatesBlocked(bool)), Qt::DirectConnection);
connect(image, SIGNAL(sigProofingConfigChanged()), SLOT(slotChangeProofingConfig())); m_d->imageConnections.addConnection(image, SIGNAL(sigProofingConfigChanged()), this, SLOT(slotChangeProofingConfig()));
connect(image, SIGNAL(sigSizeChanged(QPointF,QPointF)), SLOT(startResizingImage()), Qt::DirectConnection); m_d->imageConnections.addConnection(image, SIGNAL(sigSizeChanged(QPointF,QPointF)), this, SLOT(startResizingImage()), Qt::DirectConnection);
connect(image->undoAdapter(), SIGNAL(selectionChanged()), SLOT(slotTrySwitchShapeManager())); m_d->imageConnections.addConnection(image->undoAdapter(), SIGNAL(selectionChanged()), this, SLOT(slotTrySwitchShapeManager()));
connect(image, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), SLOT(slotImageColorSpaceChanged())); m_d->imageConnections.addConnection(image, SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), this, SLOT(slotImageColorSpaceChanged()));
connect(image, SIGNAL(sigProfileChanged(const KoColorProfile*)), SLOT(slotImageColorSpaceChanged())); m_d->imageConnections.addConnection(image, SIGNAL(sigProfileChanged(const KoColorProfile*)), this, SLOT(slotImageColorSpaceChanged()));
connectCurrentCanvas(); connectCurrentCanvas();
} }
...@@ -1109,6 +1115,13 @@ void KisCanvas2::slotConfigChanged() ...@@ -1109,6 +1115,13 @@ void KisCanvas2::slotConfigChanged()
initializeFpsDecoration(); initializeFpsDecoration();
} }
void KisCanvas2::setupDocument()
{
m_d->docConnections.clear();
m_d->docConnections.addConnection(m_d->view->document(), SIGNAL(sigReferenceImagesChanged()),
this, SLOT(slotReferenceImagesChanged()));
}
void KisCanvas2::refetchDataFromImage() void KisCanvas2::refetchDataFromImage()
{ {
KisImageSP image = this->image(); KisImageSP image = this->image();
......
...@@ -273,7 +273,7 @@ public Q_SLOTS: ...@@ -273,7 +273,7 @@ public Q_SLOTS:
* Called whenever the configuration settings change. * Called whenever the configuration settings change.
*/ */
void slotConfigChanged(); void slotConfigChanged();
void setupDocument();
private Q_SLOTS: private Q_SLOTS:
......
...@@ -33,3 +33,4 @@ if(NOT APPLE AND HAVE_QT_QUICK) ...@@ -33,3 +33,4 @@ if(NOT APPLE AND HAVE_QT_QUICK)
endif() endif()
add_subdirectory(logdocker) add_subdirectory(logdocker)
add_subdirectory(snapshotdocker)
\ No newline at end of file
...@@ -137,6 +137,9 @@ void OverviewDockerDock::rotateCanvasView(qreal rotation) ...@@ -137,6 +137,9 @@ void OverviewDockerDock::rotateCanvasView(qreal rotation)
void OverviewDockerDock::updateSlider() void OverviewDockerDock::updateSlider()
{ {
if (!m_canvas) {
return;
}
KisSignalsBlocker l(m_rotateSlider); KisSignalsBlocker l(m_rotateSlider);
qreal rotation = m_canvas->rotationAngle(); 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"
}