summaryrefslogtreecommitdiffstats
path: root/src/gui/kdeext/QCanvasSimpleSprite.cpp
blob: f2aeb232335eec1890b0d0b21d9788eb6f6d25d9 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// -*- c-basic-offset: 4 -*-

/*
    Rosegarden
    A sequencer and musical notation editor.
 
    This program is Copyright 2000-2008
        Guillaume Laurent   <glaurent@telegraph-road.org>,
        Chris Cannam        <cannam@all-day-breakfast.com>,
        Richard Bown        <bownie@bownie.com>
 
    The moral right of the authors to claim authorship of this work
    has been asserted.
 
    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.  See the file
    COPYING included with this distribution for more information.
*/

#include <vector>
#include "misc/Debug.h"

#include <tqpainter.h>

#include "QCanvasSimpleSprite.h"

namespace Rosegarden {

QCanvasSimpleSprite::QCanvasSimpleSprite(TQPixmap *pixmap, TQCanvas *canvas)
        : TQCanvasSprite(0, canvas),
        m_pixmapArray(0)
{
    m_pixmapArray = makePixmapArray(pixmap);
    setSequence(m_pixmapArray);
}

QCanvasSimpleSprite::QCanvasSimpleSprite(TQCanvasPixmap *pixmap, TQCanvas *canvas)
        : TQCanvasSprite(0, canvas),
        m_pixmapArray(0)
{
    m_pixmapArray = makePixmapArray(pixmap);
    setSequence(m_pixmapArray);
}

QCanvasSimpleSprite::QCanvasSimpleSprite(const TQString &pixmapfile,
        TQCanvas *canvas)
        : TQCanvasSprite(0, canvas),
        m_pixmapArray(0)
{
    m_pixmapArray = makePixmapArray(pixmapfile);
    setSequence(m_pixmapArray);
}

QCanvasSimpleSprite::QCanvasSimpleSprite(TQCanvas *canvas)
        : TQCanvasSprite(0, canvas),
        m_pixmapArray(0)
{
    TQCanvasPixmapArray* tmpArray = makePixmapArray(new TQPixmap());
    setSequence(tmpArray);
}


QCanvasSimpleSprite::~QCanvasSimpleSprite()
{
    PixmapArrayGC::registerForDeletion(m_pixmapArray);
    m_pixmapArray = 0;

    // We can't delete m_pixmapArray or we get a core dump.
    //
    // The reason I think is that after the QCanvasSprite is deleted,
    // it is removed from the TQCanvas, which therefore needs the
    // pixmaps to know how to update itself (the crash is in
    // TQCanvas::removeChunks(), usually).
    //
    // So instead we have to do this GCish
    // thingy. PixmapArrayGC::deleteAll() is called by
    // NotationView::redoLayout
}

TQCanvasPixmapArray*
QCanvasSimpleSprite::makePixmapArray(TQPixmap *pixmap)
{
    TQList<TQPixmap> pixlist;
    pixlist.setAutoDelete(true); // the TQCanvasPixmapArray creates its
    // own copies of the pixmaps, so we
    // can delete the one we're passed
    pixlist.append(pixmap);

    TQList<TQPoint> spotlist;
    spotlist.setAutoDelete(true);
    spotlist.append(new TQPoint(0, 0));

    return new TQCanvasPixmapArray(pixlist, spotlist);
}

TQCanvasPixmapArray*
QCanvasSimpleSprite::makePixmapArray(TQCanvasPixmap *pixmap)
{
    TQList<TQPixmap> pixlist;
    pixlist.setAutoDelete(true); // the TQCanvasPixmapArray creates its
    // own copies of the pixmaps, so we
    // can delete the one we're passed
    pixlist.append(pixmap);

    TQList<TQPoint> spotlist;
    spotlist.setAutoDelete(true);
    spotlist.append(new TQPoint(pixmap->offsetX(), pixmap->offsetY()));

    return new TQCanvasPixmapArray(pixlist, spotlist);
}

TQCanvasPixmapArray*
QCanvasSimpleSprite::makePixmapArray(const TQString &pixmapfile)
{
    return new TQCanvasPixmapArray(pixmapfile);
}

//////////////////////////////////////////////////////////////////////

TQCanvasNotationSprite::TQCanvasNotationSprite(NotationElement& n,
        TQPixmap* pixmap,
        TQCanvas* canvas)
        : QCanvasSimpleSprite(pixmap, canvas),
        m_notationElement(n)
{}

TQCanvasNotationSprite::TQCanvasNotationSprite(NotationElement& n,
        TQCanvasPixmap* pixmap,
        TQCanvas* canvas)
        : QCanvasSimpleSprite(pixmap, canvas),
        m_notationElement(n)

{}

TQCanvasNotationSprite::~TQCanvasNotationSprite()
{}


TQCanvasNonElementSprite::TQCanvasNonElementSprite(TQPixmap *pixmap,
        TQCanvas *canvas) :
        QCanvasSimpleSprite(pixmap, canvas)
{}

TQCanvasNonElementSprite::TQCanvasNonElementSprite(TQCanvasPixmap *pixmap,
        TQCanvas *canvas) :
        QCanvasSimpleSprite(pixmap, canvas)
{}

TQCanvasNonElementSprite::~TQCanvasNonElementSprite()
{}

TQCanvasTimeSigSprite::TQCanvasTimeSigSprite(double layoutX,
        TQPixmap *pixmap,
        TQCanvas *canvas) :
        TQCanvasNonElementSprite(pixmap, canvas),
        m_layoutX(layoutX)
{}

TQCanvasTimeSigSprite::TQCanvasTimeSigSprite(double layoutX,
        TQCanvasPixmap *pixmap,
        TQCanvas *canvas) :
        TQCanvasNonElementSprite(pixmap, canvas),
        m_layoutX(layoutX)
{}

TQCanvasTimeSigSprite::~TQCanvasTimeSigSprite()
{}


QCanvasStaffNameSprite::QCanvasStaffNameSprite(TQPixmap *pixmap,
        TQCanvas *canvas) :
        TQCanvasNonElementSprite(pixmap, canvas)
{}

QCanvasStaffNameSprite::QCanvasStaffNameSprite(TQCanvasPixmap *pixmap,
        TQCanvas *canvas) :
        TQCanvasNonElementSprite(pixmap, canvas)
{}

QCanvasStaffNameSprite::~QCanvasStaffNameSprite()
{}


//////////////////////////////////////////////////////////////////////

void PixmapArrayGC::registerForDeletion(TQCanvasPixmapArray* array)
{
    m_pixmapArrays.push_back(array);
}

void PixmapArrayGC::deleteAll()
{
    RG_DEBUG << "PixmapArrayGC::deleteAll() : "
    << m_pixmapArrays.size() << " pixmap arrays to delete\n";

    static unsigned long total = 0;

    for (unsigned int i = 0; i < m_pixmapArrays.size(); ++i) {
        TQCanvasPixmapArray *array = m_pixmapArrays[i];
        TQPixmap *pixmap = array->image(0);
        if (pixmap) {
            total += pixmap->width() * pixmap->height();
            //	    NOTATION_DEBUG << "PixmapArrayGC::deleteAll(): " << pixmap->width() << "x" << pixmap->height() << " (" << (pixmap->width()*pixmap->height()) << " px, " << total << " total)" << endl;
        }
        delete m_pixmapArrays[i];
    }

    m_pixmapArrays.clear();
}

std::vector<TQCanvasPixmapArray*> PixmapArrayGC::m_pixmapArrays;

}

//////////////////////////////////////////////////////////////////////