On Wednesday 15 October 2008, Aaron J. Seigo wrote: > On Wednesday 15 October 2008, Marco Martin wrote: > > with a kconfigroup? would make sense? > > it's the easy answer, so i'd say: "let's go for it". > > we can benchmark it once it is in place and working. changing the cache > implementation will be an easy task after we have it there in the first > place. > > i'll commit my changes shortly here then, once i figure out the problem > with the applet backgrounds still very rough and probably wrong in many points posting here because i'm too tired right now to think, probably tomorrow will come up with a slightly better version :)
Cheers, Marco Martin
Index: theme.h =================================================================== --- theme.h (revision 871879) +++ theme.h (working copy) @@ -192,6 +192,10 @@ **/ void insertIntoCache(const QString& key, const QPixmap& pix); + bool findInRectsCache(const QString &image, const QString &element, QRectF &rect) const; + void insertIntoRectsCache(const QString& image, const QString &element, const QRectF &rect); + void invalidateRectsCache(const QString& image); + Q_SIGNALS: /** * Emitted when the user changes the theme. SVGs should be reloaded at Index: svg.cpp =================================================================== --- svg.cpp (revision 871879) +++ svg.cpp (working copy) @@ -81,6 +81,12 @@ { bool isThemed = !QDir::isAbsolutePath(imagePath); + if (isThemed == themed && + ((themed && themePath == imagePath) || + (!themed && path == imagePath))) { + return false; + } + // lets check to see if we're already set to this file if (isThemed == themed && ((themed && themePath == imagePath) || @@ -218,32 +224,31 @@ QSize elementSize(const QString &elementId) { - createRenderer(); - - if (!renderer->elementExists(elementId)) { - return QSize(0, 0); - } - - QSizeF elementSize = renderer->boundsOnElement(elementId).size(); - QSizeF naturalSize = renderer->defaultSize(); - qreal dx = size.width() / naturalSize.width(); - qreal dy = size.height() / naturalSize.height(); - elementSize.scale(elementSize.width() * dx, elementSize.height() * dy, - Qt::IgnoreAspectRatio); - - return elementSize.toSize(); + return elementRect(elementId).size().toSize(); } QRectF elementRect(const QString &elementId) { + QRectF rect; + bool found = Theme::defaultTheme()->findInRectsCache(themePath, elementId, rect); + + if (!found) { + return QRect(); + } else if (rect.isValid()) { + return rect; + } + createRenderer(); QRectF elementRect = renderer->boundsOnElement(elementId); QSizeF naturalSize = renderer->defaultSize(); qreal dx = size.width() / naturalSize.width(); qreal dy = size.height() / naturalSize.height(); - return QRectF(elementRect.x() * dx, elementRect.y() * dy, - elementRect.width() * dx, elementRect.height() * dy); + elementRect = QRectF(elementRect.x() * dx, elementRect.y() * dy, + elementRect.width() * dx, elementRect.height() * dy); + Theme::defaultTheme()->insertIntoRectsCache(themePath, elementId, elementRect); + + return elementRect; } QMatrix matrixForElement(const QString &elementId) Index: theme.cpp =================================================================== --- theme.cpp (revision 871879) +++ theme.cpp (working copy) @@ -110,6 +110,8 @@ int defaultWallpaperWidth; int defaultWallpaperHeight; KPixmapCache pixmapCache; + KSharedConfigPtr svgElementsCache; + QHash<QString, QList<QString> > invalidElements; #ifdef Q_WS_X11 KSelectionWatcher *compositeWatch; @@ -182,6 +184,9 @@ { settingsChanged(); + QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements"); + d->svgElementsCache = KSharedConfig::openConfig(svgElementsFile); + #ifdef Q_WS_X11 Display *dpy = QX11Info::display(); int screen = DefaultScreen(dpy); @@ -297,6 +302,12 @@ } } +//KRASH :) + /*foreach (QString groupName, d->svgElementsCache->groupList()) { + KConfigGroup group(d->svgElementsCache, groupName); + group.deleteGroup(); + }*/ + emit themeChanged(); } @@ -492,6 +503,38 @@ d->pixmapCache.insert(key, pix); } +bool Theme::findInRectsCache(const QString &image, const QString &element, QRectF &rect) const +{ + KConfigGroup imageGroup(d->svgElementsCache, image); + rect = imageGroup.readEntry(element, QRectF()); + + if (!d->invalidElements.contains(image)) { + d->invalidElements[image] = imageGroup.readEntry("invalidGroups", QStringList()); + } + + return !d->invalidElements[image].contains(element); } +void Theme::insertIntoRectsCache(const QString& image, const QString &element, const QRectF &rect) +{ + KConfigGroup imageGroup(d->svgElementsCache, image); + if (rect.isValid()) { + imageGroup.writeEntry(element, rect); + } else { + d->invalidElements[image].append(element); + if (d->invalidElements[image].count() > 1000) { + d->invalidElements[image].pop_front(); + } + imageGroup.writeEntry("invalidElements", d->invalidElements[image]); + } +} + +void Theme::invalidateRectsCache(const QString& image) +{ + KConfigGroup imageGroup(d->svgElementsCache, image); + imageGroup.deleteGroup(); +} + +} + #include <theme.moc>
_______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel