Krita Source Code Documentation
Loading...
Searching...
No Matches
LayerOpacityCheck.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Rasyuqa A. H. <qampidh@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef LAYEROPACITYCHECK_H
8#define LAYEROPACITYCHECK_H
9
11#include <KoID.h>
12#include <klocalizedstring.h>
13#include <kis_image.h>
14#include <KoColorSpace.h>
16#include <kis_layer.h>
17#include <kis_node_visitor.h>
18#include "kis_node.h"
19#include "kis_paint_layer.h"
20#include "kis_group_layer.h"
23#include "kis_clone_layer.h"
25
27{
28public:
29
31
36
37 quint32 count() {
38 return m_count;
39 }
40
41 bool visit(KisNode* node) override {
42 return check(node);
43 }
44
45 bool visit(KisPaintLayer *layer) override {
46 return check(layer);
47 }
48
49 bool visit(KisGroupLayer *layer) override {
50 return check(layer);
51 }
52
53
54 bool visit(KisAdjustmentLayer *layer) override {
55 return check(layer);
56 }
57
58 bool visit(KisExternalLayer *layer) override {
59 return check(layer);
60 }
61
62 bool visit(KisCloneLayer *layer) override {
63 return check(layer);
64 }
65
66 bool visit(KisGeneratorLayer * layer) override {
67 return check(layer);
68 }
69
70 bool visit(KisFilterMask *) override {return true;}
71
72 bool visit(KisTransformMask *) override {return true;}
73
74 bool visit(KisTransparencyMask *) override {return true;}
75
76 bool visit(KisSelectionMask *) override {return true;}
77
78 bool visit(KisColorizeMask *) override {return true;}
79
80
81private:
82 bool check(KisNode * node)
83 {
84 KisLayer *layer = dynamic_cast<KisLayer*>(node);
85 if (layer) {
86 // XXX: This need to be rewritten if true float opacity is implemented
87 if (layer->opacity() < OPACITY_OPAQUE_U8) {
88 m_count++;
89 }
90 }
91 visitAll(node);
92 return true;
93 }
94
95 quint32 m_count;
96
97};
98
100{
101public:
102
103 LayerOpacityCheck(const QString &id, Level level, const QString &customWarning = QString())
104 : KisExportCheckBase(id, level, customWarning, true)
105 {
106 if (customWarning.isEmpty()) {
107 m_warning = i18nc(
108 "image conversion warning",
109 "Your image contains layers with a partial opacity. The layers will be exported at full opacity.");
110 }
111 }
112
113 bool checkNeeded(KisImageSP image) const override
114 {
116 image->rootLayer()->accept(v);
117 return (v.count() > 0);
118 }
119
120 Level check(KisImageSP /*image*/) const override
121 {
122 return m_level;
123 }
124
125};
126
128{
129public:
130
134
136
137 KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
138 {
139 return new LayerOpacityCheck(id(), level, customWarning);
140 }
141
142 QString id() const override {
143 return "LayerOpacityCheck";
144 }
145
146};
147
148
149#endif // LAYEROPACITYCHECK_H
qreal v
const quint8 OPACITY_OPAQUE_U8
The KisExportCheckBase class defines the interface of the individual checks of an export filter's cap...
virtual QString id() const
KisGroupLayerSP rootLayer() const
bool visit(KisExternalLayer *layer) override
bool visit(KisFilterMask *) override
bool visit(KisTransparencyMask *) override
bool visit(KisNode *node) override
bool visit(KisSelectionMask *) override
bool visit(KisCloneLayer *layer) override
bool visit(KisGeneratorLayer *layer) override
bool visit(KisColorizeMask *) override
bool visit(KisAdjustmentLayer *layer) override
bool visit(KisTransformMask *) override
bool visit(KisPaintLayer *layer) override
bool visit(KisGroupLayer *layer) override
virtual bool visit(KisNode *node)=0
bool visitAll(KisNode *node, bool breakOnFail=false)
KisExportCheckBase * create(KisExportCheckBase::Level level, const QString &customWarning) override
QString id() const override
LayerOpacityCheck(const QString &id, Level level, const QString &customWarning=QString())
bool checkNeeded(KisImageSP image) const override
Level check(KisImageSP) const override
quint8 opacity() const
bool accept(KisNodeVisitor &v) override