Commit bc54383d authored by Tusooa Zhu's avatar Tusooa Zhu 🔼

Improve the replacing of grid config and assistants

KisDocument will emit a signal to notify the change to grid config.
Assistants are cloned using cloneAssistantList().
parent abf8f278
......@@ -271,14 +271,13 @@ public:
, nserver(new KisNameServer(*rhs.nserver))
, preActivatedNode(0) // the node is from another hierarchy!
, imageIdleWatcher(2000 /*ms*/)
, assistants(rhs.assistants) // WARNING: assistants should not store pointers to the document!
, assistants(KisPaintingAssistant::cloneAssistantList(rhs.assistants)) // WARNING: assistants should not store pointers to the document!
, globalAssistantsColor(rhs.globalAssistantsColor)
, paletteList(rhs.paletteList)
, gridConfig(rhs.gridConfig)
, savingLock(&savingMutex)
, batchMode(rhs.batchMode)
{
// TODO: clone assistants
}
~Private() {
......@@ -377,7 +376,6 @@ void KisDocument::Private::copyFrom(const Private &rhs, KisDocument *q)
delete docInfo;
docInfo = (new KoDocumentInfo(*rhs.docInfo, q));
unit = rhs.unit;
// , importExportManager(new KisImportExportManager(q))
mimeType = rhs.mimeType;
outputMimeType = rhs.outputMimeType;
// TODO: undo stacks may store pointers to the document and/or image
......@@ -393,11 +391,11 @@ void KisDocument::Private::copyFrom(const Private &rhs, KisDocument *q)
readwrite = rhs.readwrite;
firstMod = rhs.firstMod;
lastMod = rhs.lastMod;
// TODO clone assistants
assistants = (rhs.assistants); // WARNING: assistants should not store pointers to the document!
// XXX: the display properties will be shared between different snapshots
assistants = KisPaintingAssistant::cloneAssistantList(rhs.assistants);
globalAssistantsColor = rhs.globalAssistantsColor;
paletteList = rhs.paletteList;
gridConfig = rhs.gridConfig;
q->setGridConfig(rhs.gridConfig);
batchMode = rhs.batchMode;
}
......@@ -1677,7 +1675,10 @@ KisGridConfig KisDocument::gridConfig() const
void KisDocument::setGridConfig(const KisGridConfig &config)
{
d->gridConfig = config;
if (d->gridConfig != config) {
d->gridConfig = config;
emit sigGridConfigChanged(config);
}
}
QList<KoColorSet *> &KisDocument::paletteList()
......
......@@ -463,6 +463,8 @@ Q_SIGNALS:
void sigMirrorAxisConfigChanged();
void sigGridConfigChanged(const KisGridConfig &config);
private Q_SLOTS:
void finishExportInBackground();
void slotChildCompletedSavingInBackground(KisImportExportErrorCode status, const QString &errorMessage);
......
......@@ -37,10 +37,23 @@
#include "KisView.h"
#include "kis_grid_config.h"
#include "kis_signals_blocker.h"
#include <kis_signal_auto_connection.h>
struct KisGridManager::Private
{
KisAction *toggleGrid;
KisAction* toggleSnapToGrid;
QPointer<KisView> imageView;
KisGridDecoration* gridDecoration;
bool blockModifiedSignal;
KisSignalAutoConnectionsStore connections;
};
KisGridManager::KisGridManager(KisViewManager * parent)
: QObject(parent)
, m_d(new Private)
{
}
......@@ -57,25 +70,25 @@ void KisGridManager::setGridConfig(const KisGridConfig &config)
void KisGridManager::setGridConfigImpl(const KisGridConfig &config, bool /*emitModified*/)
{
if (!m_imageView) return;
if (!m_d->imageView) return;
config.saveStaticData();
m_imageView->document()->setGridConfig(config);
m_d->imageView->document()->setGridConfig(config);
m_gridDecoration->setGridConfig(config);
m_gridDecoration->setVisible(config.showGrid());
m_d->gridDecoration->setGridConfig(config);
m_d->gridDecoration->setVisible(config.showGrid());
m_toggleGrid->setChecked(config.showGrid());
m_toggleSnapToGrid->setChecked(config.snapToGrid());
m_d->toggleGrid->setChecked(config.showGrid());
m_d->toggleSnapToGrid->setChecked(config.snapToGrid());
}
void KisGridManager::setup(KisActionManager* actionManager)
{
m_toggleGrid = actionManager->createAction("view_grid");
connect(m_toggleGrid, SIGNAL(toggled(bool)), this, SLOT(slotChangeGridVisibilityTriggered(bool)));
m_d->toggleGrid = actionManager->createAction("view_grid");
connect(m_d->toggleGrid, SIGNAL(toggled(bool)), this, SLOT(slotChangeGridVisibilityTriggered(bool)));
m_toggleSnapToGrid = actionManager->createAction("view_snap_to_grid");
connect(m_toggleSnapToGrid, SIGNAL(toggled(bool)), this, SLOT(slotSnapToGridTriggered(bool)));
m_d->toggleSnapToGrid = actionManager->createAction("view_snap_to_grid");
connect(m_d->toggleSnapToGrid, SIGNAL(toggled(bool)), this, SLOT(slotSnapToGridTriggered(bool)));
}
void KisGridManager::updateGUI()
......@@ -85,34 +98,41 @@ void KisGridManager::updateGUI()
void KisGridManager::setView(QPointer<KisView> imageView)
{
if (m_imageView) {
m_gridDecoration = 0;
if (m_d->imageView) {
m_d->connections.clear();
m_d->gridDecoration = 0;
}
m_imageView = imageView;
m_d->imageView = imageView;
if (imageView) {
m_gridDecoration = qobject_cast<KisGridDecoration*>(imageView->canvasBase()->decoration("grid").data());
if (!m_gridDecoration) {
m_gridDecoration = new KisGridDecoration(imageView);
imageView->canvasBase()->addDecoration(m_gridDecoration);
if (!imageView->document()) {
return;
}
m_d->gridDecoration = qobject_cast<KisGridDecoration*>(imageView->canvasBase()->decoration("grid").data());
if (!m_d->gridDecoration) {
m_d->gridDecoration = new KisGridDecoration(imageView);
imageView->canvasBase()->addDecoration(m_d->gridDecoration);
}
m_d->connections.addConnection(imageView->document(), SIGNAL(sigGridConfigChanged(KisGridConfig)),
this, SIGNAL(sigRequestUpdateGridConfig(KisGridConfig)));
KisGridConfig config = imageView->document()->gridConfig();
setGridConfigImpl(config, false);
KisSignalsBlocker blocker(m_toggleGrid, m_toggleSnapToGrid);
KisSignalsBlocker blocker(m_d->toggleGrid, m_d->toggleSnapToGrid);
Q_UNUSED(blocker);
m_toggleGrid->setChecked(config.showGrid());
m_toggleSnapToGrid->setChecked(config.snapToGrid());
m_d->toggleGrid->setChecked(config.showGrid());
m_d->toggleSnapToGrid->setChecked(config.snapToGrid());
}
}
void KisGridManager::slotChangeGridVisibilityTriggered(bool value)
{
if (!m_imageView) return;
if (!m_d->imageView) return;
KisGridConfig config = m_imageView->document()->gridConfig();
KisGridConfig config = m_d->imageView->document()->gridConfig();
config.setShowGrid(value);
setGridConfig(config);
......@@ -121,9 +141,9 @@ void KisGridManager::slotChangeGridVisibilityTriggered(bool value)
void KisGridManager::slotSnapToGridTriggered(bool value)
{
if (!m_imageView) return;
if (!m_d->imageView) return;
KisGridConfig config = m_imageView->document()->gridConfig();
KisGridConfig config = m_d->imageView->document()->gridConfig();
config.setSnapToGrid(value);
setGridConfig(config);
......
......@@ -64,13 +64,9 @@ private:
private:
void setFastConfig(int size);
KisAction *m_toggleGrid;
KisAction* m_toggleSnapToGrid;
QPointer<KisView> m_imageView;
KisGridDecoration* m_gridDecoration;
bool m_blockModifiedSignal;
private:
struct Private;
QScopedPointer<Private> m_d;
};
#endif
......@@ -853,6 +853,16 @@ double KisPaintingAssistant::norm2(const QPointF& p)
return p.x() * p.x() + p.y() * p.y();
}
QList<KisPaintingAssistantSP> KisPaintingAssistant::cloneAssistantList(const QList<KisPaintingAssistantSP> &list)
{
QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> handleMap;
QList<KisPaintingAssistantSP> clonedList;
for (auto i = list.begin(); i != list.end(); ++i) {
clonedList << (*i)->clone(handleMap);
}
return clonedList;
}
/*
......
......@@ -203,6 +203,11 @@ protected:
QList<KisPaintingAssistantHandleSP> m_handles;
QPointF pixelToView(const QPoint pixelCoords) const;
public:
/// clones the list of assistants
/// the originally shared handles will still be shared
/// the cloned assistants do not share any handle with the original assistants
static QList<KisPaintingAssistantSP> cloneAssistantList(const QList<KisPaintingAssistantSP> &list);
private:
struct Private;
......
......@@ -100,7 +100,7 @@ void KisAssistantTool::deactivate()
void KisAssistantTool::beginPrimaryAction(KoPointerEvent *event)
{
setMode(KisTool::PAINT_MODE);
m_origAssistantList = cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants());
m_origAssistantList = KisPaintingAssistant::cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants());
bool newAssistantAllowed = true;
......@@ -524,7 +524,7 @@ void KisAssistantTool::endPrimaryAction(KoPointerEvent *event)
m_assistantDrag.clear();
}
dbgUI << "creating undo command...";
KUndo2Command *command = new EditAssistantsCommand(m_canvas, m_origAssistantList, cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants()));
KUndo2Command *command = new EditAssistantsCommand(m_canvas, m_origAssistantList, KisPaintingAssistant::cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants()));
m_canvas->viewManager()->undoAdapter()->addCommand(command);
dbgUI << "done";
} else if(m_internalMode == MODE_DRAGGING_TRANSLATING_TWONODES) {
......@@ -538,18 +538,6 @@ void KisAssistantTool::endPrimaryAction(KoPointerEvent *event)
m_canvas->updateCanvas(); // TODO update only the relevant part of the canvas
}
QList<KisPaintingAssistantSP> KisAssistantTool::cloneAssistantList(const QList<KisPaintingAssistantSP> &list) const
{
QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> handleMap;
QList<KisPaintingAssistantSP> clonedList;
dbgUI << "cloning assistants...";
for (auto i = list.begin(); i != list.end(); ++i) {
clonedList << (*i)->clone(handleMap);
}
dbgUI << "done";
return clonedList;
}
void KisAssistantTool::addAssistant()
{
m_canvas->paintingAssistantsDecoration()->addAssistant(m_newAssistant);
......@@ -560,7 +548,7 @@ void KisAssistantTool::addAssistant()
}
QList<KisPaintingAssistantSP> assistants = m_canvas->paintingAssistantsDecoration()->assistants();
KUndo2Command *addAssistantCmd = new EditAssistantsCommand(m_canvas, m_origAssistantList, cloneAssistantList(assistants), EditAssistantsCommand::ADD, assistants.indexOf(m_newAssistant));
KUndo2Command *addAssistantCmd = new EditAssistantsCommand(m_canvas, m_origAssistantList, KisPaintingAssistant::cloneAssistantList(assistants), EditAssistantsCommand::ADD, assistants.indexOf(m_newAssistant));
m_canvas->viewManager()->undoAdapter()->addCommand(addAssistantCmd);
m_handles = m_canvas->paintingAssistantsDecoration()->handles();
......@@ -580,7 +568,7 @@ void KisAssistantTool::removeAssistant(KisPaintingAssistantSP assistant)
}
m_canvas->paintingAssistantsDecoration()->removeAssistant(assistant);
KUndo2Command *removeAssistantCmd = new EditAssistantsCommand(m_canvas, m_origAssistantList, cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants()), EditAssistantsCommand::REMOVE, assistants.indexOf(assistant));
KUndo2Command *removeAssistantCmd = new EditAssistantsCommand(m_canvas, m_origAssistantList, KisPaintingAssistant::cloneAssistantList(m_canvas->paintingAssistantsDecoration()->assistants()), EditAssistantsCommand::REMOVE, assistants.indexOf(assistant));
m_canvas->viewManager()->undoAdapter()->addCommand(removeAssistantCmd);
m_handles = m_canvas->paintingAssistantsDecoration()->handles();
......
......@@ -75,11 +75,6 @@ public:
QWidget *createOptionWidget() override;
/// clones the list of assistants
/// the originally shared handles will still be shared
/// the cloned assistants do not share any handle with the original assistants
QList<KisPaintingAssistantSP> cloneAssistantList(const QList<KisPaintingAssistantSP> &list) const;
private:
// adds and removes assistant.
// this is event is forwarded to the kis_painting_decoration class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment