~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/image/kis_layer.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
    KisImageWSP image;
53
53
    QBitArray channelFlags;
54
 
    QString compositeOp;
55
54
    KisEffectMaskSP previewMask;
56
55
    KisMetaData::Store* metaDataStore;
57
56
    KisPaintDeviceSP projection;
58
57
};
59
58
 
60
59
 
61
 
KisLayer::KisLayer(KisImageWSP img, const QString &name, quint8 opacity)
 
60
KisLayer::KisLayer(KisImageWSP image, const QString &name, quint8 opacity)
62
61
        : KisNode()
63
62
        , m_d(new Private)
64
63
{
65
64
    setName(name);
66
65
    setOpacity(opacity);
67
 
    m_d->image = img;
68
 
    m_d->compositeOp = COMPOSITE_OVER;
 
66
    m_d->image = image;
69
67
    m_d->metaDataStore = new KisMetaData::Store();
70
68
}
71
69
 
75
73
{
76
74
    if (this != &rhs) {
77
75
        m_d->image = rhs.m_d->image;
78
 
        m_d->compositeOp = rhs.m_d->compositeOp;
79
76
        m_d->metaDataStore = new KisMetaData::Store(*rhs.m_d->metaDataStore);
80
77
    }
81
78
}
93
90
    return 0;
94
91
}
95
92
 
 
93
const KoCompositeOp * KisLayer::compositeOp() const
 
94
{
 
95
    /**
 
96
     * FIXME: This function duplicates the same function from
 
97
     * KisMask. We can't move it to KisBaseNode as it doesn't
 
98
     * know anything about parent() method of KisNode
 
99
     * Please think it over...
 
100
     */
 
101
 
 
102
    KisNodeSP parentNode = parent();
 
103
    if (!parentNode) return 0;
 
104
 
 
105
    if (!parentNode->colorSpace()) return 0;
 
106
    const KoCompositeOp* op = parentNode->colorSpace()->compositeOp(compositeOpId());
 
107
    return op ? op : parentNode->colorSpace()->compositeOp(COMPOSITE_OVER);
 
108
}
 
109
 
96
110
KoDocumentSectionModel::PropertyList KisLayer::sectionModelProperties() const
97
111
{
98
112
    KoDocumentSectionModel::PropertyList l = KisBaseNode::sectionModelProperties();
105
119
void KisLayer::setSectionModelProperties(const KoDocumentSectionModel::PropertyList &properties)
106
120
{
107
121
    KisBaseNode::setSectionModelProperties(properties);
108
 
    /// TODO no nope not at all, the state contains a use-visible string not the actual property
109
 
//     setOpacity( properties.at( 2 ).state.toInt() );
110
 
//     setCompositeOp( const_cast<KoCompositeOp*>( image()->colorSpace()->compositeOp( properties.at( 3 ).state.toString() ) ) );
111
122
}
112
123
 
113
124
void KisLayer::setChannelFlags(const QBitArray & channelFlags)
121
132
    return m_d->channelFlags;
122
133
}
123
134
 
124
 
quint8 KisLayer::opacity() const
125
 
{
126
 
    return nodeProperties().intProperty("opacity", OPACITY_OPAQUE);
127
 
}
128
 
 
129
 
void KisLayer::setOpacity(quint8 val)
130
 
{
131
 
    if (opacity() != val) {
132
 
        nodeProperties().setProperty("opacity", val);
133
 
    }
134
 
}
135
 
 
136
 
quint8 KisLayer::percentOpacity() const
137
 
{
138
 
    return int(float(opacity() * 100) / 255 + 0.5);
139
 
}
140
 
 
141
 
void KisLayer::setPercentOpacity(quint8 val)
142
 
{
143
 
    setOpacity(int(float(val * 255) / 100 + 0.5));
144
 
}
145
 
 
146
135
bool KisLayer::temporary() const
147
136
{
148
137
    return nodeProperties().boolProperty("temporary", false);
153
142
    nodeProperties().setProperty("temporary", t);
154
143
}
155
144
 
156
 
const QString& KisLayer::compositeOpId() const
157
 
{
158
 
    return m_d->compositeOp;
159
 
}
160
 
 
161
 
const KoCompositeOp * KisLayer::compositeOp() const
162
 
{
163
 
    KisLayerSP parent = parentLayer();
164
 
    if (!parent) {
165
 
        return 0;
166
 
    }
167
 
    const KoCompositeOp* op = parent->colorSpace()->compositeOp(m_d->compositeOp);
168
 
    if (op) return op;
169
 
    return parent->colorSpace()->compositeOp(COMPOSITE_OVER);
170
 
}
171
 
 
172
 
void KisLayer::setCompositeOp(const QString& compositeOp)
173
 
{
174
 
    m_d->compositeOp = compositeOp;
175
 
}
176
 
 
177
145
KisImageWSP KisLayer::image() const
178
146
{
179
147
    return m_d->image;
190
158
    }
191
159
}
192
160
 
193
 
void KisLayer::setDirty()
194
 
{
195
 
    setDirty(extent());
196
 
}
197
 
 
198
161
void KisLayer::setDirty(const QRect & rect)
199
162
{
200
163
    m_d->image->updateProjection(this, rect);
201
164
}
202
165
 
203
 
void KisLayer::setDirty(const QRegion & region)
204
 
{
205
 
    if (region.isEmpty()) return;
206
 
 
207
 
    foreach(const QRect & rc, region.rects()) {
208
 
        setDirty(rc);
209
 
    }
210
 
}
211
 
 
212
166
KisSelectionMaskSP KisLayer::selectionMask() const
213
167
{
214
 
    QList<KisNodeSP> masks = childNodes(QStringList("KisSelectionMask"), KoProperties());
215
 
    Q_ASSERT(masks.size() <= 1); // Or do we allow more than one selection mask to a layer?
 
168
    KoProperties properties;
 
169
    properties.setProperty("active", true);
 
170
    QList<KisNodeSP> masks = childNodes(QStringList("KisSelectionMask"), properties);
 
171
    Q_ASSERT(masks.size() <= 1); // only one active mask at a time
 
172
 
 
173
    //finds the active selection mask
216
174
    if (masks.size() == 1) {
217
175
        KisSelectionMaskSP selection = dynamic_cast<KisSelectionMask*>(masks[0].data());
218
176
        return selection;
222
180
 
223
181
KisSelectionSP KisLayer::selection() const
224
182
{
225
 
    KisSelectionMaskSP selMask = selectionMask();
226
 
    if (selMask && selMask->visible())
227
 
        return selMask->selection();
 
183
   KisLayer *layer=(KisLayer *)this;
 
184
 
 
185
    if (layer->selectionMask())
 
186
        return layer->selectionMask()->selection();
228
187
    else if (m_d->image)
229
188
        return m_d->image->globalSelection();
230
189
    else
231
 
        return 0;
 
190
        return KisSelectionSP(new KisSelection());
232
191
}
233
192
 
234
193
///////////////////////////////////////////////////////////////////////
272
231
    rectVariesFlag = false;
273
232
 
274
233
    QRect prevChangeRect = requestedRect;
275
 
    QRect changeRect;
 
234
 
 
235
    /**
 
236
     * We set default value of the change rect for the case
 
237
     * when there is no mask at all
 
238
     */
 
239
    QRect changeRect = requestedRect;
276
240
 
277
241
    foreach(const KisEffectMaskSP& mask, masks) {
278
242
        changeRect = mask->changeRect(prevChangeRect);
310
274
    return needRect;
311
275
}
312
276
 
313
 
 
314
277
QRect KisLayer::applyMasks(const KisPaintDeviceSP source,
315
278
                           const KisPaintDeviceSP destination,
316
279
                           const QRect &requestedRect) const
332
295
        bool changeRectVaries;
333
296
        bool needRectVaries;
334
297
 
335
 
        changeRect = masksChangeRect(masks, requestedRect,
336
 
                                     changeRectVaries);
 
298
        /**
 
299
         * FIXME: Assume that varying of the changeRect has already
 
300
         * been taken into account while preparing walkers
 
301
         */
 
302
        changeRectVaries = false;
 
303
        changeRect = requestedRect;
 
304
        //changeRect = masksChangeRect(masks, requestedRect,
 
305
        //                             changeRectVaries);
337
306
 
338
307
        needRect = masksNeedRect(masks, changeRect,
339
308
                                 applyRects, needRectVaries);
389
358
            !originalDevice) return QRect();
390
359
 
391
360
    if (!needProjection() && !hasEffectMasks()) {
392
 
        updatedRect = repaintOriginal(originalDevice, updatedRect);
393
361
        m_d->projection = 0;
394
362
    } else {
395
 
        updatedRect = repaintOriginal(originalDevice, updatedRect);
396
 
 
397
363
        if (!updatedRect.isEmpty()) {
398
364
 
399
365
            if (!m_d->projection ||
440
406
    return m_d->projection ? m_d->projection : original();
441
407
}
442
408
 
 
409
QRect KisLayer::changeRect(const QRect &rect, PositionToFilthy pos) const
 
410
{
 
411
    QRect changeRect = rect;
 
412
 
 
413
    if(pos == KisNode::N_FILTHY) {
 
414
        bool changeRectVaries;
 
415
        changeRect = masksChangeRect(effectMasks(), rect, changeRectVaries);
 
416
    }
 
417
 
 
418
    return changeRect;
 
419
}
 
420
 
443
421
QImage KisLayer::createThumbnail(qint32 w, qint32 h)
444
422
{
445
423
    KisPaintDeviceSP originalDevice = original();