SVN commit 1022993 by mart: cache the shadow, should be a lot faster, less oerations on QImage M +35 -24 abstracttaskitem.cpp M +4 -1 abstracttaskitem.h --- trunk/KDE/kdebase/workspace/plasma/applets/tasks/abstracttaskitem.cpp #1022992:1022993 @@ -168,6 +168,7 @@ void AbstractTaskItem::setText(const QString &text) { m_text = text; + m_cachedShadow = QPixmap(); } void AbstractTaskItem::setIcon(const QIcon &icon) @@ -541,6 +542,29 @@ itemBackground->setElementPrefix(m_backgroundPrefix); } +void AbstractTaskItem::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + m_cachedShadow = QPixmap(); + + syncActiveRect(); + + Plasma::FrameSvg *itemBackground = m_applet->itemBackground(); + + itemBackground->setElementPrefix("focus"); + m_applet->resizeItemBackground(event->newSize().toSize()); + itemBackground->setElementPrefix("normal"); + m_applet->resizeItemBackground(event->newSize().toSize()); + itemBackground->setElementPrefix("minimized"); + m_applet->resizeItemBackground(event->newSize().toSize()); + itemBackground->setElementPrefix("attention"); + m_applet->resizeItemBackground(event->newSize().toSize()); + itemBackground->setElementPrefix("hover"); + m_applet->resizeItemBackground(m_activeRect.size().toSize()); + + //restore the prefix + itemBackground->setElementPrefix(m_backgroundPrefix); +} + void AbstractTaskItem::drawBackground(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { // Do not paint with invalid sizes, the happens when the layout is being initialized @@ -554,25 +578,6 @@ */ Plasma::FrameSvg *itemBackground = m_applet->itemBackground(); - //if the size is changed have to resize all the elements - if (itemBackground->size() != size().toSize() && itemBackground->size() != m_activeRect.size().toSize()) { - syncActiveRect(); - - itemBackground->setElementPrefix("focus"); - m_applet->resizeItemBackground(m_activeRect.size().toSize()); - itemBackground->setElementPrefix("normal"); - m_applet->resizeItemBackground(size().toSize()); - itemBackground->setElementPrefix("minimized"); - m_applet->resizeItemBackground(size().toSize()); - itemBackground->setElementPrefix("attention"); - m_applet->resizeItemBackground(size().toSize()); - itemBackground->setElementPrefix("hover"); - m_applet->resizeItemBackground(m_activeRect.size().toSize()); - - //restore the prefix - itemBackground->setElementPrefix(m_backgroundPrefix); - } - if (!m_animId && ~option->state & QStyle::State_Sunken) { itemBackground->setElementPrefix(m_backgroundPrefix); if (itemBackground->frameSize() == m_activeRect.size().toSize()) { @@ -724,7 +729,7 @@ return QSize(widthUsed, height); } -void AbstractTaskItem::drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect) const +void AbstractTaskItem::drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect) { if (rect.width() < 1 || rect.height() < 1) { return; @@ -792,13 +797,19 @@ shadowColor = Qt::white; } - QImage shadow = pixmap.toImage(); - Plasma::PaintUtils::shadowBlur(shadow, 2, shadowColor); + if (m_cachedShadow.isNull()) { + QImage shadow = pixmap.toImage(); + Plasma::PaintUtils::shadowBlur(shadow, 2, shadowColor); + m_cachedShadow = QPixmap(shadow.size()); + m_cachedShadow.fill(Qt::transparent); + QPainter buffPainter(&m_cachedShadow); + buffPainter.drawImage(QPoint(0,0), shadow); + } if (shadowColor == Qt::white) { - painter->drawImage(rect.topLeft(), shadow); + painter->drawPixmap(rect.topLeft(), m_cachedShadow); } else { - painter->drawImage(rect.topLeft() + QPoint(1,2), shadow); + painter->drawPixmap(rect.topLeft() + QPoint(1,2), m_cachedShadow); } painter->drawPixmap(rect.topLeft(), pixmap); } --- trunk/KDE/kdebase/workspace/plasma/applets/tasks/abstracttaskitem.h #1022992:1022993 @@ -178,7 +178,7 @@ * the supplied painter. If the layout contains text lines that are longer than the rect * is wide, they will be elided by fading the text out. */ - void drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect) const; + void drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect); virtual void updateTask(::TaskManager::TaskChanges changes) = 0; // pure virtual function virtual void updateToolTip() = 0; // pure virtual function @@ -206,6 +206,8 @@ // text color, use this because it could be animated QColor textColor() const; + void resizeEvent(QGraphicsSceneResizeEvent *event); + TaskManager::AbstractGroupableItem * m_abstractItem; LayoutWidget *m_layoutWidget; @@ -215,6 +217,7 @@ QIcon m_icon; QString m_text; + QPixmap m_cachedShadow; int m_animId; qreal m_alpha;