summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_part_layer.h
blob: 377b37a08e65aa0f71dc27f0436ad2d5125679c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 *  Copyright (c) 2005 Boudewijn Rempt <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#ifndef _KIS_PART_LAYER_
#define _KIS_PART_LAYER_

#include <tqrect.h>

#include <KoDocument.h>
#include <KoDocumentChild.h>

#include "kis_paint_layer.h"
#include "kis_types.h"
#include "kis_doc.h"
#include "kis_part_layer_iface.h"
#include "kis_view.h"
#include "kis_layer_visitor.h"

class KoFrame;
class KoDocument;


/**
 * The child document is responsible for saving and loading the embedded layers.
 */
class KisChildDoc : public KoDocumentChild
{

public:
    KisChildDoc ( KisDoc * kisDoc, const TQRect& rect, KoDocument * childDoc );
    KisChildDoc ( KisDoc * kisDdoc );

    virtual ~KisChildDoc();

    KisDoc * parent() const { return m_doc; }

    void setPartLayer (KisPartLayerSP layer) { m_partLayer = layer; }

    KisPartLayerSP partLayer() const { return m_partLayer; }
protected:

    KisDoc * m_doc;
    KisPartLayerSP m_partLayer;
};


/**
 * A PartLayer is a layer that contains a KOffice Part like a KWord document
 * or a KSpread spreadsheet. Or whatever. A Karbon drawing.
 *
 * The part is rendered into an RBGA8 paint device so we can composite it with
 * the other layers.
 *
 * When it is activated (see activate()), it draws a rectangle around itself on the kisdoc,
 * whereas when it is deactivated (deactivate()), it removes that rectangle and commits
 * the child to the paint device.
 *
 * Embedded parts should get loaded and saved to the Native Chalk Fileformat natively.
 */
class KisPartLayerImpl : public KisPartLayer {
    Q_OBJECT
  TQ_OBJECT
    typedef KisPartLayer super;
public:
    KisPartLayerImpl(KisImageSP img, KisChildDoc * doc);
    virtual ~KisPartLayerImpl();

    virtual KisLayerSP clone() const;

    /// Called when the layer is made active
    virtual void activate() {}

    /// Called when another layer is made inactive
    virtual void deactivate() {}

    /// Returns the childDoc so that we can access the doc from other places, if need be (KisDoc)
    virtual KisChildDoc* childDoc() const { return m_doc; }

    void setDocType(const TQString& type) { m_docType = type; }
    TQString docType() const { return m_docType; }

    virtual void setX(TQ_INT32 x);
    virtual void setY(TQ_INT32 y);
    virtual TQ_INT32 x() const { return m_doc->geometry() . x(); }
    virtual TQ_INT32 y() const { return m_doc->geometry() . y(); } //m_paintLayer->y(); }
    virtual TQRect extent() const { return m_doc->geometry(); }
    virtual TQRect exactBounds() const { return m_doc->geometry(); }

    virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h);

    virtual bool accept(KisLayerVisitor& visitor) {
        return visitor.visit(this);
    }

    virtual KisPaintDeviceSP prepareProjection(KisPaintDeviceSP projection, const TQRect& r);

    virtual void paintSelection(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);

    virtual bool saveToXML(TQDomDocument doc, TQDomElement elem);
private slots:
    /// Repaints our device with the data from the embedded part
    //void repaint();
    /// When we activate the embedding, we clear ourselves
    void childActivated(KoDocumentChild* child);
    void childDeactivated(bool activated);


private:
    // KisPaintLayerSP m_paintLayer;
    KisPaintDeviceSP m_cache;
    KoFrame * m_frame; // The widget that holds the editable view of the embedded part
    KisChildDoc * m_doc; // The sub-document
    TQString m_docType;
    bool m_activated;
};

/**
 * Visitor that connects all partlayers in an image to a KisView's signals
 */
class KisConnectPartLayerVisitor : public KisLayerVisitor {
    KisImageSP m_img;
    KisView* m_view;
    bool m_connect; // connects, or disconnects signals
public:
    KisConnectPartLayerVisitor(KisImageSP img, KisView* view, bool mode);
    virtual ~KisConnectPartLayerVisitor() {}

    virtual bool visit(KisPaintLayer *layer);
    virtual bool visit(KisGroupLayer *layer);
    virtual bool visit(KisPartLayer *layer);
    virtual bool visit(KisAdjustmentLayer *layer);
};

#endif // _KIS_PART_LAYER_