Commit a2a0f7d8 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Made it easy to Import/Export masks

Now 'Layer' menu has a separate 'Import/Export' submenu
where one can import an external image as any type of layer/mask
parent 2bbf8241
<?xml version="1.0"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="Krita" version="55">
<kpartgui name="Krita" version="56">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
......@@ -95,22 +95,29 @@
<Action name="add_new_paint_layer"/>
<Action name="duplicatelayer"/>
<Separator/>
<Action name="import_layer_from_file"/>
<Separator/>
<Action name="cut_selection_to_new_layer"/>
<Action name="copy_selection_to_new_layer"/>
</Menu>
<Menu name="LayerConvert"><text>Convert</text>
<Menu name="LayerImportExport"><text>&amp;Import/Export</text>
<Action name="save_node_as_image"/>
<Action name="save_groups_as_images"/>
<Separator/>
<Action name="import_layer_from_file"/>
<Menu name="LayerImportAs"><text>Import</text>
<Action name="import_layer_as_paint_layer"/>
<Action name="import_layer_as_transparency_mask"/>
<Action name="import_layer_as_filter_mask"/>
<Action name="import_layer_as_selection_mask"/>
</Menu>
</Menu>
<Menu name="LayerConvert"><text>&amp;Convert</text>
<Action name="convert_to_paint_layer"/>
<Action name="convert_to_transparency_mask"/>
<Action name="convert_to_filter_mask"/>
<Action name="convert_to_selection_mask"/>
</Menu>
<Action name="resizelayertoowner"/>
<Separator/>
<Action name="save_node_as_image"/>
<Action name="save_groups_as_images"/>
<Action name="layer_to_image"/>
<Separator/>
<Action name="mirrorNodeX"/>
<Action name="mirrorNodeY"/>
......
......@@ -52,6 +52,22 @@ void KisImageManager::setup(KActionCollection * actionCollection)
actionCollection->addAction("import_layer_from_file", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerFromFile()));
action = new KAction(koIcon("document-new"), i18n("as Paint Layer..."), this);
actionCollection->addAction("import_layer_as_paint_layer", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerFromFile()));
action = new KAction(koIcon("edit-copy"), i18n("as Transparency Mask..."), this);
actionCollection->addAction("import_layer_as_transparency_mask", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerAsTransparencyMask()));
action = new KAction(koIcon("bookmarks"), i18n("as Filter Mask..."), this);
actionCollection->addAction("import_layer_as_filter_mask", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerAsFilterMask()));
action = new KAction(koIcon("edit-paste"), i18n("as Selection Mask..."), this);
actionCollection->addAction("import_layer_as_selection_mask", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImportLayerAsSelectionMask()));
action = new KAction(koIcon("document-properties"), i18n("Properties..."), this);
actionCollection->addAction("image_properties", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImageProperties()));
......@@ -65,10 +81,26 @@ void KisImageManager::setup(KActionCollection * actionCollection)
void KisImageManager::slotImportLayerFromFile()
{
importImage(KUrl(), true);
importImage(KUrl(), "KisPaintLayer");
}
void KisImageManager::slotImportLayerAsTransparencyMask()
{
importImage(KUrl(), "KisTransparencyMask");
}
qint32 KisImageManager::importImage(const KUrl& urlArg, bool importAsLayer)
void KisImageManager::slotImportLayerAsFilterMask()
{
importImage(KUrl(), "KisFilterMask");
}
void KisImageManager::slotImportLayerAsSelectionMask()
{
importImage(KUrl(), "KisSelectionMask");
}
qint32 KisImageManager::importImage(const KUrl& urlArg, const QString &layerType)
{
KisImageWSP currentImage = m_view->image();
......@@ -97,7 +129,7 @@ qint32 KisImageManager::importImage(const KUrl& urlArg, bool importAsLayer)
return 0;
for (KUrl::List::iterator it = urls.begin(); it != urls.end(); ++it) {
new KisImportCatcher(*it, m_view, importAsLayer);
new KisImportCatcher(*it, m_view, layerType);
}
m_view->canvas()->update();
......
......@@ -43,6 +43,9 @@ public:
public slots:
void slotImportLayerFromFile();
void slotImportLayerAsTransparencyMask();
void slotImportLayerAsFilterMask();
void slotImportLayerAsSelectionMask();
/**
* Import an image as a layer. If there is more than
......@@ -52,7 +55,7 @@ public slots:
* @param url the url to the image file
* @return the number of layers added
*/
qint32 importImage(const KUrl& url = KUrl(), bool importAsLayer = true);
qint32 importImage(const KUrl& url, const QString &layerType = "KisPaintLayer");
void resizeCurrentImage(qint32 w, qint32 h, qint32 xOffset, qint32 yOffset);
void scaleCurrentImage(const QSize &size, qreal xres, qreal yres, KisFilterStrategy *filterStrategy);
......
......@@ -47,7 +47,7 @@ public:
KisDoc2* doc;
KisView2* view;
KUrl url;
bool importAsLayer;
QString layerType;
QString prettyLayerName() const;
void importAsPaintLayer(KisPaintDeviceSP device);
......@@ -83,37 +83,7 @@ void KisImportCatcher::Private::importAsPaintLayer(KisPaintDeviceSP device)
adapter.addNode(newLayer, parent, currentActiveLayer);
}
// NOTE: Unused currently
void KisImportCatcher::Private::importAsTransparencyMask(KisPaintDeviceSP device)
{
KisLayerSP currentActiveLayer = view->activeLayer();
if (!currentActiveLayer) {
KisNodeSP node = view->activeNode();
if (!node) return;
do {
currentActiveLayer = dynamic_cast<KisLayer*>(node.data());
} while (!currentActiveLayer && (node = node->parent()));
if (!currentActiveLayer) return;
}
KisTransparencyMaskSP mask = new KisTransparencyMask();
mask->setSelection(new KisSelection(new KisDefaultBounds(currentActiveLayer->image())));
mask->setName(prettyLayerName());
QRect rc(device->exactBounds());
KisPainter painter(mask->paintDevice());
painter.bitBlt(rc.topLeft(), device, rc);
KisNodeCommandsAdapter adapter(view);
adapter.addNode(mask,
currentActiveLayer,
currentActiveLayer->lastChild());
}
KisImportCatcher::KisImportCatcher(const KUrl & url, KisView2 * view, bool importAsLayer)
KisImportCatcher::KisImportCatcher(const KUrl & url, KisView2 * view, const QString &layerType)
: m_d(new Private)
{
m_d->doc = new KisDoc2();
......@@ -122,7 +92,8 @@ KisImportCatcher::KisImportCatcher(const KUrl & url, KisView2 * view, bool impor
m_d->doc->setProgressProxy(progressProxy);
m_d->view = view;
m_d->url = url;
m_d->importAsLayer = importAsLayer;
m_d->layerType = layerType;
connect(m_d->doc, SIGNAL(sigLoadingFinished()), this, SLOT(slotLoadingFinished()));
bool result = m_d->doc->openUrl(url);
......@@ -137,10 +108,10 @@ void KisImportCatcher::slotLoadingFinished()
importedImage->waitForDone();
if (importedImage && importedImage->projection()->exactBounds().isValid()) {
if (m_d->importAsLayer) {
m_d->importAsPaintLayer(importedImage->projection());
if (m_d->layerType != "KisPaintLayer") {
m_d->view->nodeManager()->createNode(m_d->layerType, false, importedImage->projection());
} else {
m_d->importAsTransparencyMask(importedImage->projection());
m_d->importAsPaintLayer(importedImage->projection());
}
}
......
......@@ -43,7 +43,7 @@ class KisImportCatcher : QObject
public:
KisImportCatcher(const KUrl & url, KisView2* view, bool importAsLayer);
KisImportCatcher(const KUrl & url, KisView2* view, const QString &layerType);
~KisImportCatcher();
private slots:
......
......@@ -142,13 +142,13 @@ void KisMaskManager::adjustMaskPosition(KisNodeSP node, KisNodeSP activeNode, bo
}
}
void KisMaskManager::createMaskCommon(KisMaskSP mask, KisNodeSP activeNode, KisPaintDeviceSP copyFrom, const KUndo2MagicString& macroName, const QString &nodeType, const QString &nodeName, bool suppressSelection)
void KisMaskManager::createMaskCommon(KisMaskSP mask, KisNodeSP activeNode, KisPaintDeviceSP copyFrom, const KUndo2MagicString& macroName, const QString &nodeType, const QString &nodeName, bool suppressSelection, bool avoidActiveNode)
{
m_commandsAdapter->beginMacro(macroName);
KisNodeSP parent;
KisNodeSP above;
adjustMaskPosition(mask, activeNode, !!copyFrom, parent, above);
adjustMaskPosition(mask, activeNode, avoidActiveNode, parent, above);
KisLayerSP parentLayer = dynamic_cast<KisLayer*>(parent.data());
Q_ASSERT(parentLayer);
......@@ -172,23 +172,23 @@ void KisMaskManager::createMaskCommon(KisMaskSP mask, KisNodeSP activeNode, KisP
masksUpdated();
}
void KisMaskManager::createSelectionMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom)
void KisMaskManager::createSelectionMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool avoidActiveNode)
{
KisSelectionMaskSP mask = new KisSelectionMask(m_view->image());
createMaskCommon(mask, activeNode, copyFrom, kundo2_i18n("Add Selection Mask"), "KisSelectionMask", i18n("Selection"));
createMaskCommon(mask, activeNode, copyFrom, kundo2_i18n("Add Selection Mask"), "KisSelectionMask", i18n("Selection"), false, avoidActiveNode);
mask->setActive(true);
}
void KisMaskManager::createTransparencyMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom)
void KisMaskManager::createTransparencyMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool avoidActiveNode)
{
KisMaskSP mask = new KisTransparencyMask();
createMaskCommon(mask, activeNode, copyFrom, kundo2_i18n("Add Transparency Mask"), "KisTransparencyMask", i18n("Transparency Mask"));
createMaskCommon(mask, activeNode, copyFrom, kundo2_i18n("Add Transparency Mask"), "KisTransparencyMask", i18n("Transparency Mask"), false, avoidActiveNode);
}
void KisMaskManager::createFilterMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool quiet)
void KisMaskManager::createFilterMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool quiet, bool avoidActiveNode)
{
KisFilterMaskSP mask = new KisFilterMask();
createMaskCommon(mask, activeNode, copyFrom, kundo2_i18n("Add Filter Mask"), "KisFilterMask", i18n("Filter Mask"));
createMaskCommon(mask, activeNode, copyFrom, kundo2_i18n("Add Filter Mask"), "KisFilterMask", i18n("Filter Mask"), false, avoidActiveNode);
/**
* FIXME: We'll use layer's original for creation of a thumbnail.
......@@ -228,7 +228,7 @@ void KisMaskManager::createFilterMask(KisNodeSP activeNode, KisPaintDeviceSP cop
void KisMaskManager::createTransformMask(KisNodeSP activeNode)
{
KisTransformMaskSP mask = new KisTransformMask();
createMaskCommon(mask, activeNode, 0, kundo2_i18n("Add Transform Mask"), "KisTransformMask", i18n("Transform Mask"), true);
createMaskCommon(mask, activeNode, 0, kundo2_i18n("Add Transform Mask"), "KisTransformMask", i18n("Transform Mask"), false, false);
}
void KisMaskManager::duplicateMask()
......
......@@ -115,12 +115,12 @@ private:
void activateMask(KisMaskSP mask);
void adjustMaskPosition(KisNodeSP node, KisNodeSP activeNode, bool avoidActiveNode, KisNodeSP &parent, KisNodeSP &above);
void createMaskCommon(KisMaskSP mask, KisNodeSP activeNode, KisPaintDeviceSP copyFrom, const KUndo2MagicString &macroName, const QString &nodeType, const QString &nodeName, bool suppressSelection = false);
void createMaskCommon(KisMaskSP mask, KisNodeSP activeNode, KisPaintDeviceSP copyFrom, const KUndo2MagicString &macroName, const QString &nodeType, const QString &nodeName, bool suppressSelection, bool avoidActiveNode);
void createSelectionMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom);
void createFilterMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool quiet = false);
void createSelectionMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool avoidActiveNode);
void createFilterMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool quiet, bool avoidActiveNode);
void createTransformMask(KisNodeSP activeNode);
void createTransparencyMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom);
void createTransparencyMask(KisNodeSP activeNode, KisPaintDeviceSP copyFrom, bool avoidActiveNode);
KisView2 * m_view;
......
......@@ -419,7 +419,7 @@ void KisNodeManager::slotTryFinishIsolatedMode()
}
}
void KisNodeManager::createNode(const QString & nodeType, bool quiet)
void KisNodeManager::createNode(const QString & nodeType, bool quiet, KisPaintDeviceSP copyFrom)
{
KisNodeSP activeNode = this->activeNode();
if (!activeNode) {
......@@ -447,13 +447,13 @@ void KisNodeManager::createNode(const QString & nodeType, bool quiet)
} else if (nodeType == "KisCloneLayer") {
m_d->layerManager->addCloneLayer(activeNode);
} else if (nodeType == "KisTransparencyMask") {
m_d->maskManager->createTransparencyMask(activeNode, 0);
m_d->maskManager->createTransparencyMask(activeNode, copyFrom, false);
} else if (nodeType == "KisFilterMask") {
m_d->maskManager->createFilterMask(activeNode, 0, quiet);
m_d->maskManager->createFilterMask(activeNode, copyFrom, quiet, false);
} else if (nodeType == "KisTransformMask") {
m_d->maskManager->createTransformMask(activeNode);
} else if (nodeType == "KisSelectionMask") {
m_d->maskManager->createSelectionMask(activeNode, 0);
m_d->maskManager->createSelectionMask(activeNode, copyFrom, false);
} else if (nodeType == "KisFileLayer") {
m_d->layerManager->addFileLayer(activeNode);
}
......@@ -477,11 +477,11 @@ void KisNodeManager::convertNode(const QString &nodeType)
m_d->commandsAdapter->beginMacro(kundo2_i18n("Convert to a Selection Mask"));
if (nodeType == "KisSelectionMask") {
m_d->maskManager->createSelectionMask(activeNode, copyFrom);
m_d->maskManager->createSelectionMask(activeNode, copyFrom, true);
} else if (nodeType == "KisFilterMask") {
m_d->maskManager->createFilterMask(activeNode, copyFrom);
m_d->maskManager->createFilterMask(activeNode, copyFrom, false, true);
} else if (nodeType == "KisTransparencyMask") {
m_d->maskManager->createTransparencyMask(activeNode, copyFrom);
m_d->maskManager->createTransparencyMask(activeNode, copyFrom, true);
}
m_d->commandsAdapter->removeNode(activeNode);
......
......@@ -150,7 +150,7 @@ public slots:
void slotTryFinishIsolatedMode();
void moveNodeAt(KisNodeSP node, KisNodeSP parent, int index);
void createNode(const QString& nodeType, bool quiet = false);
void createNode(const QString& nodeType, bool quiet = false, KisPaintDeviceSP copyFrom = 0);
void convertNode(const QString &nodeType);
void nodesUpdated();
void nodeProperties(KisNodeSP node);
......
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