~ubuntu-branches/ubuntu/jaunty/kde4libs/jaunty-updates

« back to all changes in this revision

Viewing changes to plasma/svg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-12-11 18:26:08 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20081211182608-tsu6p8ncbw1gnqxt
Tags: 4:4.1.85-0ubuntu1
* New upstream release
* Patches:
  + Removed 15_kfreebsd_support.diff from patches/series (doesn't apply and
    has no use for Ubuntu)
  + Redid 20_use_dejavu_as_default_font.diff
  + Completely removed kubuntu_09_fix_application_menu.diff (applied upstream)
  + Refreshed kubuntu_54_use_xdg_menu_prefix.diff
  + Dropped plasma/widgets/toolbutton.cpp from kubuntu_qt_ftbfs.diff (applied
    upstream)
  + Global quilt refresh

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <QMatrix>
24
24
#include <QPainter>
25
25
#include <QSharedData>
 
26
#include <QTimer>
26
27
 
27
28
#include <kcolorscheme.h>
28
29
#include <kconfiggroup.h>
65
66
    public:
66
67
        SvgPrivate(Svg *svg)
67
68
            : q(svg),
 
69
              saveTimer(0),
68
70
              renderer(0),
69
71
              multipleImages(false),
70
72
              themed(false),
77
79
            eraseRenderer();
78
80
        }
79
81
 
 
82
        //This function is meant for the rects cache
80
83
        QString cacheId(const QString &elementId)
81
84
        {
82
85
            if (size.isValid() && size != naturalSize) {
89
92
            }
90
93
        }
91
94
 
 
95
        //This function is meant for the pixmap cache
 
96
        QString cachePath(const QString &path, const QSize &size)
 
97
        {
 
98
             return QString("%3_%2_%1_").arg(int(size.height()))
 
99
                                       .arg(int(size.width()))
 
100
                                       .arg(path);
 
101
        }
 
102
 
92
103
        bool setImagePath(const QString &imagePath, Svg *q)
93
104
        {
94
105
            bool isThemed = !QDir::isAbsolutePath(imagePath);
144
155
                size = elementRect(elementId).size().toSize();
145
156
            }
146
157
 
147
 
            if (!size.isValid()) {
 
158
            if (size.isEmpty()) {
148
159
                return QPixmap();
149
160
            }
150
161
 
151
 
            QString id = QString::fromLatin1("%3_%2_%1_").
152
 
                         arg(size.width()).arg(size.height()).arg(path);
 
162
            QString id = cachePath(path, size);
153
163
 
154
164
            if (!elementId.isEmpty()) {
155
165
                id.append(elementId);
191
201
                p = p.fromImage(itmp);
192
202
            }
193
203
 
194
 
            theme->insertIntoCache(id, p);
 
204
            if (!itemsToSave.contains(id)) {
 
205
                itemsToSave.insert(id, p);
 
206
                saveTimer->start(300);
 
207
            }
 
208
 
195
209
            return p;
196
210
        }
197
211
 
 
212
        void scheduledCacheUpdate()
 
213
        {
 
214
            QHash<QString, QPixmap>::const_iterator i = itemsToSave.constBegin();
 
215
 
 
216
            while (i != itemsToSave.constEnd()) {
 
217
                //kDebug()<<"Saving item to cache: "<<i.key();
 
218
                Theme::defaultTheme()->insertIntoCache(i.key(), i.value());
 
219
                ++i;
 
220
            }
 
221
 
 
222
            itemsToSave.clear();
 
223
        }
 
224
 
198
225
        void createRenderer()
199
226
        {
200
227
            if (renderer) {
233
260
            }
234
261
 
235
262
            renderer = 0;
 
263
            localRectCache.clear();
236
264
        }
237
265
 
238
266
        QRectF elementRect(const QString &elementId)
239
267
        {
 
268
            if (themed && path.isEmpty()) {
 
269
                path = Plasma::Theme::defaultTheme()->imagePath(themePath);
 
270
            }
 
271
 
 
272
            QString id = cacheId(elementId);
 
273
            if (localRectCache.contains(id)) {
 
274
                return localRectCache.value(id);
 
275
            }
 
276
 
240
277
            QRectF rect;
241
 
 
242
 
            if (themed && path.isEmpty()) {
243
 
                path = Plasma::Theme::defaultTheme()->imagePath(themePath);
244
 
            }
245
 
 
246
 
            bool found = Theme::defaultTheme()->findInRectsCache(path, cacheId(elementId), rect);
 
278
            bool found = Theme::defaultTheme()->findInRectsCache(path, id, rect);
247
279
 
248
280
            if (found) {
 
281
                localRectCache.insert(id, rect);
249
282
                return rect;
250
283
            }
251
284
 
316
349
                                    q, SLOT(colorsChanged()));
317
350
            }
318
351
 
 
352
            localRectCache.clear();
 
353
            itemsToSave.clear();
 
354
            saveTimer->stop();
 
355
 
319
356
            //kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed";
320
357
            emit q->repaintNeeded();
321
358
        }
332
369
 
333
370
        Svg *q;
334
371
        static QHash<QString, SharedSvgRenderer::Ptr> s_renderers;
 
372
        QHash<QString, QRectF> localRectCache;
 
373
        QHash<QString, QPixmap> itemsToSave;
 
374
        QTimer *saveTimer;
335
375
        SharedSvgRenderer::Ptr renderer;
336
376
        QString themePath;
337
377
        QString path;
348
388
    : QObject(parent),
349
389
      d(new SvgPrivate(this))
350
390
{
 
391
    d->saveTimer = new QTimer(this);
 
392
    d->saveTimer->setSingleShot(true);
 
393
    connect(d->saveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate()));
351
394
}
352
395
 
353
396
Svg::~Svg()
405
448
 
406
449
void Svg::resize(const QSizeF &size)
407
450
{
 
451
    if (qFuzzyCompare(size.width(), d->size.width()) &&
 
452
        qFuzzyCompare(size.height(), d->size.height())) {
 
453
        return;
 
454
    }
 
455
 
408
456
    d->size = size;
 
457
    d->localRectCache.clear();
409
458
}
410
459
 
411
460
void Svg::resize()
412
461
{
 
462
    QSizeF newSize;
413
463
    if (d->renderer) {
414
 
        d->size = d->renderer->defaultSize();
415
 
    } else {
416
 
        d->size = QSizeF();
417
 
    }
 
464
        newSize = d->renderer->defaultSize();
 
465
    }
 
466
 
 
467
    if (qFuzzyCompare(newSize.width(), d->size.width()) &&
 
468
        qFuzzyCompare(newSize.height(), d->size.height())) {
 
469
        return;
 
470
    }
 
471
 
 
472
    d->size = newSize;
 
473
    d->localRectCache.clear();
418
474
}
419
475
 
420
476
QSize Svg::elementSize(const QString &elementId) const
433
489
        return false;
434
490
    }
435
491
 
 
492
    QString id = d->cacheId(elementId);
 
493
    if (d->localRectCache.contains(id)) {
 
494
        return d->localRectCache.value(id).isValid();
 
495
    }
436
496
 
437
497
    QRectF elementRect;
438
 
    bool found = Theme::defaultTheme()->findInRectsCache(d->path, d->cacheId(elementId), elementRect);
 
498
    bool found = Theme::defaultTheme()->findInRectsCache(d->path, id, elementRect);
439
499
 
440
500
    if (found) {
441
501
        return elementRect.isValid();
448
508
 
449
509
QString Svg::elementAtPoint(const QPoint &point) const
450
510
{
 
511
    Q_UNUSED(point)
 
512
 
451
513
    return QString();
452
514
/*
453
515
FIXME: implement when Qt can support us!
484
546
 
485
547
void Svg::setImagePath(const QString &svgFilePath)
486
548
{
487
 
    if (d->setImagePath(svgFilePath, this)) {
488
 
    }
489
 
        d->eraseRenderer();
490
 
        emit repaintNeeded();
 
549
    d->setImagePath(svgFilePath, this);
 
550
    d->eraseRenderer();
 
551
    emit repaintNeeded();
491
552
}
492
553
 
493
554
QString Svg::imagePath() const