Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
2.3 KB
Raw Blame
/*
 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <[email protected]>
 *
 * SPDX-License-Identifier: LGPL-2.0-or-later
 */

#ifndef NodeTypeCheck_H
#define NodeTypeCheck_H

#include "KisExportCheckRegistry.h"
#include <KoID.h>
#include <klocalizedstring.h>
#include <kis_image.h>
#include <kis_count_visitor.h>

class NodeTypeCheck : public KisExportCheckBase
{
public:

    NodeTypeCheck(const QString &nodeType, const QString &description, const QString &id, Level level, const QString &customWarning = QString())
        : KisExportCheckBase(id, level, customWarning, true)
        , m_nodeType(nodeType)
    {
        if (customWarning.isEmpty()) {
            m_warning = i18nc("image conversion warning", "The image contains layers of unsupported type <b>%1</b>. Only the rendered result will be saved.", description);
        }
    }

    bool checkNeeded(KisImageSP image) const override
    {
        QStringList nodetypes = QStringList() << m_nodeType;
        KoProperties props;
        KisCountVisitor v(nodetypes, props);
        image->rootLayer()->accept(v);

        // There is always one group layer, the root layer. When checking
        // selection masks, discount the global selection mask, since that's
        // ephemeral and not worth warning about.
        if (m_nodeType == QStringLiteral("KisGroupLayer")
            || (m_nodeType == QStringLiteral("KisSelectionMask") && image->rootLayer()->selectionMask())) {
            return (v.count() > 1);
        }
        else {
            return (v.count() > 0);
        }
    }

    Level check(KisImageSP /*image*/) const override
    {
        return m_level;
    }

    QString m_nodeType;
};

class NodeTypeCheckFactory : public KisExportCheckFactory
{
public:

    NodeTypeCheckFactory(const QString &nodeType, const QString &description)
        : m_nodeType(nodeType)
        , m_description(description)
    {}

    ~NodeTypeCheckFactory() override {}

    KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
    {
        return new NodeTypeCheck(m_nodeType, m_description, id(), level, customWarning);
    }

    QString id() const override {
        return "NodeTypeCheck/" + m_nodeType;
    }

    QString m_nodeType;
    QString m_description;

};

#endif // NodeTypeCheck_H