• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Plasma

framesvg.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 by Aaron Seigo <aseigo@kde.org>
00003  *   Copyright 2008 Marco Martin <notmart@gmail.com>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "framesvg.h"
00022 #include "private/framesvg_p.h"
00023 
00024 #include <QPainter>
00025 #include <QSize>
00026 #include <QBitmap>
00027 #include <QRegion>
00028 #include <QTimer>
00029 #include <QCryptographicHash>
00030 
00031 #include <kdebug.h>
00032 
00033 #include <plasma/theme.h>
00034 #include <plasma/applet.h>
00035 
00036 namespace Plasma
00037 {
00038 
00039 FrameSvg::FrameSvg(QObject *parent)
00040     : Svg(parent),
00041       d(new FrameSvgPrivate(this))
00042 {
00043     connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
00044     d->frames.insert(QString(), new FrameData());
00045 
00046     d->saveTimer = new QTimer(this);
00047     d->saveTimer->setSingleShot(true);
00048     connect(d->saveTimer, SIGNAL(timeout()), this, SLOT(scheduledCacheUpdate()));
00049 }
00050 
00051 FrameSvg::~FrameSvg()
00052 {
00053     delete d;
00054 }
00055 
00056 void FrameSvg::setImagePath(const QString &path)
00057 {
00058     if (path == imagePath()) {
00059         return;
00060     }
00061 
00062     Svg::setImagePath(path);
00063     setContainsMultipleImages(true);
00064 
00065     clearCache();
00066     d->updateAndSignalSizes();
00067 }
00068 
00069 void FrameSvg::setEnabledBorders(const EnabledBorders borders)
00070 {
00071     if (borders == d->frames[d->prefix]->enabledBorders) {
00072         return;
00073     }
00074 
00075     d->frames[d->prefix]->enabledBorders = borders;
00076     d->updateAndSignalSizes();
00077 }
00078 
00079 FrameSvg::EnabledBorders FrameSvg::enabledBorders() const
00080 {
00081     QHash<QString, FrameData*>::const_iterator it = d->frames.constFind(d->prefix);
00082 
00083     if (it != d->frames.constEnd()) {
00084         return it.value()->enabledBorders;
00085     } else {
00086         return NoBorder;
00087     }
00088 }
00089 
00090 void FrameSvg::setElementPrefix(Plasma::Location location)
00091 {
00092     switch (location) {
00093         case TopEdge:
00094             setElementPrefix("north");
00095             break;
00096         case BottomEdge:
00097             setElementPrefix("south");
00098             break;
00099         case LeftEdge:
00100             setElementPrefix("west");
00101             break;
00102         case RightEdge:
00103             setElementPrefix("east");
00104             break;
00105         default:
00106             setElementPrefix(QString());
00107             break;
00108     }
00109     d->location = location;
00110 }
00111 
00112 void FrameSvg::setElementPrefix(const QString & prefix)
00113 {
00114     const QString oldPrefix(d->prefix);
00115 
00116     if (!hasElement(prefix + "-center")) {
00117         d->prefix.clear();
00118     } else {
00119         d->prefix = prefix;
00120         if (!d->prefix.isEmpty()) {
00121             d->prefix += '-';
00122         }
00123 
00124     }
00125 
00126     if (oldPrefix == d->prefix && d->frames[oldPrefix]) {
00127         return;
00128     }
00129 
00130     if (!d->frames.contains(d->prefix)) {
00131         d->frames.insert(d->prefix, new FrameData(*(d->frames[oldPrefix])));
00132         d->updateSizes();
00133     }
00134 
00135     if (!d->cacheAll) {
00136         delete d->frames[oldPrefix];
00137         d->framesToSave.removeAll(oldPrefix);
00138         d->frames.remove(oldPrefix);
00139     }
00140 
00141     d->location = Floating;
00142 }
00143 
00144 bool FrameSvg::hasElementPrefix(const QString & prefix) const
00145 {
00146     //for now it simply checks if a center element exists,
00147     //because it could make sense for certain themes to not have all the elements
00148     if (prefix.isEmpty()) {
00149         return hasElement("center");
00150     } else {
00151         return hasElement(prefix + "-center");
00152     }
00153 }
00154 
00155 bool FrameSvg::hasElementPrefix(Plasma::Location location) const
00156 {
00157     switch (location) {
00158         case TopEdge:
00159             return hasElementPrefix("north");
00160             break;
00161         case BottomEdge:
00162             return hasElementPrefix("south");
00163             break;
00164         case LeftEdge:
00165             return hasElementPrefix("west");
00166             break;
00167         case RightEdge:
00168             return hasElementPrefix("east");
00169             break;
00170         default:
00171             return hasElementPrefix(QString());
00172             break;
00173     }
00174 }
00175 
00176 QString FrameSvg::prefix()
00177 {
00178     if (d->prefix.isEmpty()) {
00179         return d->prefix;
00180     }
00181 
00182     return d->prefix.left(d->prefix.size() - 1);
00183 }
00184 
00185 void FrameSvg::resizeFrame(const QSizeF &size)
00186 {
00187     if (size.isEmpty()) {
00188         kWarning() << "Invalid size" << size;
00189         return;
00190     }
00191 
00192     if (size == d->frames[d->prefix]->frameSize) {
00193         return;
00194     }
00195 
00196     d->updateSizes();
00197     d->frames[d->prefix]->frameSize = size;
00198 }
00199 
00200 QSizeF FrameSvg::frameSize() const
00201 {
00202     QHash<QString, FrameData*>::const_iterator it = d->frames.constFind(d->prefix);
00203 
00204     if (it != d->frames.constEnd()) {
00205         return it.value()->frameSize;
00206     } else {
00207         return QSize(-1, -1);
00208     }
00209 }
00210 
00211 qreal FrameSvg::marginSize(const Plasma::MarginEdge edge) const
00212 {
00213     if (d->frames[d->prefix]->noBorderPadding) {
00214         return .0;
00215     }
00216 
00217     switch (edge) {
00218     case Plasma::TopMargin:
00219         return d->frames[d->prefix]->topMargin;
00220     break;
00221 
00222     case Plasma::LeftMargin:
00223         return d->frames[d->prefix]->leftMargin;
00224     break;
00225 
00226     case Plasma::RightMargin:
00227         return d->frames[d->prefix]->rightMargin;
00228     break;
00229 
00230     //Plasma::BottomMargin
00231     default:
00232         return d->frames[d->prefix]->bottomMargin;
00233     break;
00234     }
00235 }
00236 
00237 void FrameSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
00238 {
00239     FrameData *frame = d->frames[d->prefix];
00240 
00241     if (!frame || frame->noBorderPadding) {
00242         left = top = right = bottom = 0;
00243         return;
00244     }
00245 
00246     top = frame->topMargin;
00247     left = frame->leftMargin;
00248     right = frame->rightMargin;
00249     bottom = frame->bottomMargin;
00250 }
00251 
00252 QRectF FrameSvg::contentsRect() const
00253 {
00254     QSizeF size(frameSize());
00255 
00256     if (size.isValid()) {
00257         QRectF rect(QPointF(0, 0), size);
00258         FrameData *frame = d->frames[d->prefix];
00259 
00260         return rect.adjusted(frame->leftMargin, frame->topMargin,
00261                              -frame->rightMargin, -frame->bottomMargin);
00262     } else {
00263         return QRectF();
00264     }
00265 }
00266 
00267 QPixmap FrameSvg::alphaMask() const
00268 {
00269     FrameData *frame = d->frames[d->prefix];
00270 
00271     if (hasElement("mask-" + d->prefix + "center")) {
00272         QString oldPrefix = d->prefix;
00273 
00274         // We are setting the prefix only temporary to generate
00275         // the needed mask image
00276         d->prefix = "mask-" + oldPrefix;
00277 
00278         if (!d->frames.contains(d->prefix)) {
00279             d->frames.insert(d->prefix, new FrameData(*(d->frames[oldPrefix])));
00280             d->updateSizes();
00281         }
00282 
00283         FrameData *maskFrame = d->frames[d->prefix];
00284         if (maskFrame->cachedBackground.isNull() || maskFrame->frameSize != frame->frameSize ) {
00285             maskFrame->frameSize = frame->frameSize;
00286             maskFrame->cachedBackground = QPixmap();
00287 
00288             d->generateBackground(maskFrame);
00289             if (maskFrame->cachedBackground.isNull()) {
00290                 return QPixmap();
00291             }
00292         }
00293 
00294         d->prefix = oldPrefix;
00295         return maskFrame->cachedBackground;
00296     } else {
00297         if (frame->cachedBackground.isNull()) {
00298             d->generateBackground(frame);
00299             if (frame->cachedBackground.isNull()) {
00300                 return QPixmap();
00301             }
00302         }
00303         return frame->cachedBackground;
00304     }
00305 }
00306 
00307 QRegion FrameSvg::mask() const
00308 {
00309     FrameData *frame = d->frames[d->prefix];
00310     frame->cachedMask = QRegion(QBitmap(alphaMask().alphaChannel().createMaskFromColor(Qt::black)));
00311     return frame->cachedMask;
00312 }
00313 
00314 void FrameSvg::setCacheAllRenderedFrames(bool cache)
00315 {
00316     if (d->cacheAll && !cache) {
00317         clearCache();
00318     }
00319 
00320     d->cacheAll = cache;
00321 }
00322 
00323 bool FrameSvg::cacheAllRenderedFrames() const
00324 {
00325     return d->cacheAll;
00326 }
00327 
00328 void FrameSvg::clearCache()
00329 {
00330     FrameData *frame = d->frames[d->prefix];
00331 
00332     d->saveTimer->stop();
00333     d->framesToSave.clear();
00334 
00335     // delete all the frames that aren't this one
00336     QMutableHashIterator<QString, FrameData*> it(d->frames);
00337     while (it.hasNext()) {
00338         FrameData *p = it.next().value();
00339 
00340         if (frame != p) {
00341             delete p;
00342             it.remove();
00343         }
00344     }
00345 }
00346 
00347 QPixmap FrameSvg::framePixmap()
00348 {
00349     FrameData *frame = d->frames[d->prefix];
00350     if (frame->cachedBackground.isNull()) {
00351         d->generateBackground(frame);
00352         if (frame->cachedBackground.isNull()) {
00353             return QPixmap();
00354         }
00355     }
00356 
00357 
00358     return frame->cachedBackground;
00359 }
00360 
00361 void FrameSvg::paintFrame(QPainter *painter, const QRectF &target, const QRectF &source)
00362 {
00363     FrameData *frame = d->frames[d->prefix];
00364     if (frame->cachedBackground.isNull()) {
00365         d->generateBackground(frame);
00366         if (frame->cachedBackground.isNull()) {
00367             return;
00368         }
00369     }
00370 
00371     painter->drawPixmap(target, frame->cachedBackground, source.isValid() ? source : target);
00372 }
00373 
00374 void FrameSvg::paintFrame(QPainter *painter, const QPointF &pos)
00375 {
00376     FrameData *frame = d->frames[d->prefix];
00377     if (frame->cachedBackground.isNull()) {
00378         d->generateBackground(frame);
00379         if (frame->cachedBackground.isNull()) {
00380             return;
00381         }
00382     }
00383 
00384     painter->drawPixmap(pos, frame->cachedBackground);
00385 }
00386 
00387 void FrameSvgPrivate::generateBackground(FrameData *frame)
00388 {
00389     if (!frame->cachedBackground.isNull()) {
00390         return;
00391     }
00392 
00393 
00394     QString id = QString::fromLatin1("%5_%4_%3_%2_%1_").
00395                          arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
00396 
00397     Theme *theme = Theme::defaultTheme();
00398     if (theme->findInCache(id, frame->cachedBackground) && !frame->cachedBackground.isNull()) {
00399         return;
00400     }
00401 
00402     //kDebug() << "generating background";
00403     const int topWidth = q->elementSize(prefix + "top").width();
00404     const int leftHeight = q->elementSize(prefix + "left").height();
00405     const int topOffset = 0;
00406     const int leftOffset = 0;
00407 
00408 
00409     if (!frame->frameSize.isValid()) {
00410         kWarning() << "Invalid frame size" << frame->frameSize;
00411         return;
00412     }
00413 
00414     const int contentWidth = frame->frameSize.width() - frame->leftWidth  - frame->rightWidth;
00415     const int contentHeight = frame->frameSize.height() - frame->topHeight  - frame->bottomHeight;
00416     int contentTop = 0;
00417     int contentLeft = 0;
00418     int rightOffset = contentWidth;
00419     int bottomOffset = contentHeight;
00420 
00421     frame->cachedBackground = QPixmap(frame->leftWidth + contentWidth + frame->rightWidth,
00422                                       frame->topHeight + contentHeight + frame->bottomHeight);
00423     frame->cachedBackground.fill(Qt::transparent);
00424     QPainter p(&frame->cachedBackground);
00425     p.setCompositionMode(QPainter::CompositionMode_Source);
00426     p.setRenderHint(QPainter::SmoothPixmapTransform);
00427 
00428     //if we must stretch the center or the borders we compute how much we will have to stretch
00429     //the svg to get the desired element sizes
00430     QSizeF  scaledContentSize(0, 0);
00431     if (q->elementSize(prefix + "center").width() > 0 &&
00432         q->elementSize(prefix + "center").height() > 0 &&
00433         (!frame->tileCenter || frame->stretchBorders)) {
00434         scaledContentSize = QSizeF(contentWidth * ((qreal)q->size().width() / (qreal)q->elementSize(prefix + "center").width()),
00435                                    contentHeight * ((qreal)q->size().height() / (qreal)q->elementSize(prefix + "center").height()));
00436     }
00437 
00438     //CENTER
00439     if (frame->tileCenter) {
00440         if (contentHeight > 0 && contentWidth > 0) {
00441             int centerTileHeight;
00442             int centerTileWidth;
00443             centerTileHeight = q->elementSize(prefix + "center").height();
00444             centerTileWidth = q->elementSize(prefix + "center").width();
00445             QPixmap center(centerTileWidth, centerTileHeight);
00446             center.fill(Qt::transparent);
00447 
00448             {
00449                 QPainter centerPainter(&center);
00450                 centerPainter.setCompositionMode(QPainter::CompositionMode_Source);
00451                 q->paint(&centerPainter, QRect(QPoint(0, 0), q->elementSize(prefix + "center")), prefix + "center");
00452             }
00453 
00454             p.drawTiledPixmap(QRect(frame->leftWidth, frame->topHeight,
00455                                     contentWidth, contentHeight), center);
00456         }
00457     } else {
00458         if (contentHeight > 0 && contentWidth > 0) {
00459             q->paint(&p, QRect(frame->leftWidth, frame->topHeight,
00460                                contentWidth, contentHeight),
00461                                prefix + "center");
00462         }
00463     }
00464 
00465     // Corners
00466     if (frame->enabledBorders & FrameSvg::TopBorder && q->hasElement(prefix + "top")) {
00467         contentTop = frame->topHeight;
00468         bottomOffset += frame->topHeight;
00469 
00470         if (q->hasElement(prefix + "topleft") && frame->enabledBorders & FrameSvg::LeftBorder) {
00471             q->paint(&p, QRect(leftOffset, topOffset, frame->leftWidth, frame->topHeight), prefix + "topleft");
00472 
00473             contentLeft = frame->leftWidth;
00474             rightOffset = contentWidth + frame->leftWidth;
00475         }
00476 
00477         if (q->hasElement(prefix + "topright") && frame->enabledBorders & FrameSvg::RightBorder) {
00478             q->paint(&p, QRect(rightOffset, topOffset, frame->rightWidth, frame->topHeight), prefix + "topright");
00479         }
00480     }
00481 
00482     if (frame->enabledBorders & FrameSvg::BottomBorder && q->hasElement(prefix + "bottom")) {
00483         if (q->hasElement(prefix + "bottomleft") && frame->enabledBorders & FrameSvg::LeftBorder) {
00484             q->paint(&p, QRect(leftOffset, bottomOffset, frame->leftWidth, frame->bottomHeight), prefix + "bottomleft");
00485 
00486             contentLeft = frame->leftWidth;
00487             rightOffset = contentWidth + frame->leftWidth;
00488         }
00489 
00490         if (frame->enabledBorders & FrameSvg::RightBorder && q->hasElement(prefix + "bottomright")) {
00491             q->paint(&p, QRect(rightOffset, bottomOffset, frame->rightWidth, frame->bottomHeight), prefix + "bottomright");
00492         }
00493     }
00494 
00495     // Sides
00496     if (frame->stretchBorders) {
00497         if (frame->enabledBorders & FrameSvg::LeftBorder || frame->enabledBorders & FrameSvg::RightBorder) {
00498             if (q->hasElement(prefix + "left") &&
00499                 frame->enabledBorders & FrameSvg::LeftBorder) {
00500                 q->paint(&p, QRect(leftOffset, contentTop, frame->leftWidth, contentHeight), prefix + "left");
00501             }
00502 
00503             if (q->hasElement(prefix + "right") &&
00504                 frame->enabledBorders & FrameSvg::RightBorder) {
00505                 q->paint(&p, QRect(rightOffset, contentTop, frame->rightWidth, contentHeight), prefix + "right");
00506             }
00507         }
00508 
00509         if (frame->enabledBorders & FrameSvg::TopBorder || frame->enabledBorders & FrameSvg::BottomBorder) {
00510             if (frame->enabledBorders & FrameSvg::TopBorder && q->hasElement(prefix + "top")) {
00511                 q->paint(&p, QRect(contentLeft, topOffset, contentWidth, frame->topHeight), prefix + "top");
00512             }
00513 
00514             if (frame->enabledBorders & FrameSvg::BottomBorder && q->hasElement(prefix + "bottom")) {
00515                 q->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, frame->bottomHeight), prefix + "bottom");
00516             }
00517         }
00518     } else {
00519         if (frame->enabledBorders & FrameSvg::LeftBorder && q->hasElement(prefix + "left")
00520                 && leftHeight > 0 && frame->leftWidth > 0) {
00521             QPixmap left(frame->leftWidth, leftHeight);
00522             left.fill(Qt::transparent);
00523 
00524             QPainter sidePainter(&left);
00525             sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
00526             q->paint(&sidePainter, QRect(QPoint(0, 0), left.size()), prefix + "left");
00527 
00528             p.drawTiledPixmap(QRect(leftOffset, contentTop, frame->leftWidth, contentHeight), left);
00529         }
00530 
00531         if (frame->enabledBorders & FrameSvg::RightBorder && q->hasElement(prefix + "right") &&
00532                 leftHeight > 0 && frame->rightWidth > 0) {
00533             QPixmap right(frame->rightWidth, leftHeight);
00534             right.fill(Qt::transparent);
00535 
00536             QPainter sidePainter(&right);
00537             sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
00538             q->paint(&sidePainter, QRect(QPoint(0, 0), right.size()), prefix + "right");
00539 
00540             p.drawTiledPixmap(QRect(rightOffset, contentTop, frame->rightWidth, contentHeight), right);
00541         }
00542 
00543         if (frame->enabledBorders & FrameSvg::TopBorder && q->hasElement(prefix + "top")
00544                 && topWidth > 0 && frame->topHeight > 0) {
00545             QPixmap top(topWidth, frame->topHeight);
00546             top.fill(Qt::transparent);
00547 
00548             QPainter sidePainter(&top);
00549             sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
00550             q->paint(&sidePainter, QRect(QPoint(0, 0), top.size()), prefix + "top");
00551 
00552             p.drawTiledPixmap(QRect(contentLeft, topOffset, contentWidth, frame->topHeight), top);
00553         }
00554 
00555         if (frame->enabledBorders & FrameSvg::BottomBorder && q->hasElement(prefix + "bottom")
00556                 && topWidth > 0 && frame->bottomHeight > 0) {
00557             QPixmap bottom(topWidth, frame->bottomHeight);
00558             bottom.fill(Qt::transparent);
00559 
00560             QPainter sidePainter(&bottom);
00561             sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
00562             q->paint(&sidePainter, QRect(QPoint(0, 0), bottom.size()), prefix + "bottom");
00563 
00564             p.drawTiledPixmap(QRect(contentLeft, bottomOffset, contentWidth, frame->bottomHeight), bottom);
00565         }
00566     }
00567 
00568     //Overlays
00569     if (!prefix.startsWith("mask-") && q->hasElement(prefix+"overlay")) {
00570         QPoint pos = QPoint(0, 0);
00571         QSize overlaySize = q->elementSize(prefix+"overlay");
00572 
00573         //Random pos, stretched and tiled are mutually exclusive
00574         if (q->hasElement(prefix+"hint-overlay-random-pos")) {
00575             pos = overlayPos;
00576         //Stretched or Tiled?
00577         } else if (q->hasElement(prefix+"hint-overlay-stretch") || q->hasElement(prefix+"hint-overlay-tile")) {
00578             overlaySize = frame->frameSize.toSize();
00579         }
00580 
00581         QString id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_").
00582                             arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
00583 
00584         QPixmap overlay = q->alphaMask();
00585 
00586         QPainter overlayPainter(&overlay);
00587         overlayPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
00588 
00589         //Tiling?
00590         if (q->hasElement(prefix+"hint-overlay-tile")) {
00591             q->resize(q->elementSize(prefix+"overlay"));
00592             overlayPainter.drawTiledPixmap(QRect(QPoint(0,0), overlaySize), q->pixmap(prefix+"overlay"));
00593             q->resize();
00594         } else {
00595             q->paint(&overlayPainter, QRect(overlayPos, overlaySize), prefix+"overlay");
00596         }
00597         overlayPainter.end();
00598 
00599         p.setCompositionMode(QPainter::CompositionMode_SourceOver);
00600 
00601         p.drawPixmap(overlayPos, overlay, QRect(overlayPos, overlaySize));
00602     }
00603 
00604     if (!framesToSave.contains(prefix)) {
00605         framesToSave.append(prefix);
00606     }
00607 
00608     saveTimer->start(300);
00609 }
00610 
00611 
00612 void FrameSvgPrivate::scheduledCacheUpdate()
00613 {
00614     foreach ( QString prefixToSave, framesToSave) {
00615         //insert background
00616         FrameData *frame = frames[prefix];
00617         framesToSave.removeAll(prefixToSave);
00618 
00619         QString id = QString::fromLatin1("%5_%4_%3_%2_%1_").
00620                             arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
00621 
00622         //kDebug()<<"Saving to cache frame"<<id;
00623 
00624         Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
00625 
00626         //insert overlay
00627         id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_").
00628                             arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(frame->frameSize.width()).arg(frame->frameSize.height()).arg(prefix).arg(q->imagePath());
00629 
00630         Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
00631     }
00632 }
00633 
00634 void FrameSvgPrivate::updateSizes()
00635 {
00636     //kDebug() << "!!!!!!!!!!!!!!!!!!!!!! updating sizes" << prefix;
00637     FrameData *frame = frames[prefix];
00638     Q_ASSERT(frame);
00639 
00640     QSize s = q->size();
00641     q->resize();
00642     frame->cachedBackground = QPixmap();
00643     frame->cachedMask = QRegion();
00644 
00645     if (frame->enabledBorders & FrameSvg::TopBorder) {
00646         frame->topHeight = q->elementSize(prefix + "top").height();
00647 
00648         if (q->hasElement(prefix + "hint-top-margin")) {
00649             frame->topMargin = q->elementSize(prefix + "hint-top-margin").height();
00650         } else {
00651             frame->topMargin = frame->topHeight;
00652         }
00653     } else {
00654         frame->topMargin = frame->topHeight = 0;
00655     }
00656 
00657     if (frame->enabledBorders & FrameSvg::LeftBorder) {
00658         frame->leftWidth = q->elementSize(prefix + "left").width();
00659 
00660         if (q->hasElement(prefix + "hint-left-margin")) {
00661             frame->leftMargin = q->elementSize(prefix + "hint-left-margin").height();
00662         } else {
00663             frame->leftMargin = frame->leftWidth;
00664         }
00665     } else {
00666         frame->leftMargin = frame->leftWidth = 0;
00667     }
00668 
00669     if (frame->enabledBorders & FrameSvg::RightBorder) {
00670         frame->rightWidth = q->elementSize(prefix + "right").width();
00671 
00672         if (q->hasElement(prefix + "hint-right-margin")) {
00673             frame->rightMargin = q->elementSize(prefix + "hint-right-margin").height();
00674         } else {
00675             frame->rightMargin = frame->rightWidth;
00676         }
00677     } else {
00678         frame->rightMargin = frame->rightWidth = 0;
00679     }
00680 
00681     if (frame->enabledBorders & FrameSvg::BottomBorder) {
00682         frame->bottomHeight = q->elementSize(prefix + "bottom").height();
00683 
00684         if (q->hasElement(prefix + "hint-bottom-margin")) {
00685             frame->bottomMargin = q->elementSize(prefix + "hint-bottom-margin").height();
00686         } else {
00687             frame->bottomMargin = frame->bottomHeight;
00688         }
00689     } else {
00690         frame->bottomMargin = frame->bottomHeight = 0;
00691     }
00692 
00693     //since it's rectangular, topWidth and bottomWidth must be the same
00694     frame->tileCenter = q->hasElement("hint-tile-center");
00695     frame->noBorderPadding = q->hasElement("hint-no-border-padding");
00696     frame->stretchBorders = q->hasElement("hint-stretch-borders");
00697     q->resize(s);
00698 }
00699 
00700 void FrameSvgPrivate::updateNeeded()
00701 {
00702     q->clearCache();
00703     updateSizes();
00704 }
00705 
00706 void FrameSvgPrivate::updateAndSignalSizes()
00707 {
00708     updateSizes();
00709     emit q->repaintNeeded();
00710 }
00711 
00712 } // Plasma namespace
00713 
00714 #include "framesvg.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal