diff options
| author | Peter Penz <[email protected]> | 2011-09-09 20:34:55 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-09-09 20:35:57 +0200 |
| commit | c7272df5c17c804fd379e4bac2758850f03695da (patch) | |
| tree | e613a2ee48df15be046fd365bc7feeaf2021619b /src/kitemviews | |
| parent | 93cb7e02616df9746f7cdae09434e7488f4e7d28 (diff) | |
Improve cache handling in KItemListWidget
Provide a hook for derived KItemListWidget where the cache
can be updated.
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.cpp | 32 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.h | 14 |
2 files changed, 33 insertions, 13 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index d162ed8a2..d9a1cbfd1 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -88,7 +88,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte { KItemListWidget::paint(painter, option, widget); - const_cast<KFileItemListWidget*>(this)->updateCache(); + const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing(); // Draw expansion toggle '>' or 'V' if (m_isDir && !m_expansionArea.isEmpty()) { @@ -135,7 +135,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte QRectF KFileItemListWidget::iconBoundingRect() const { - const_cast<KFileItemListWidget*>(this)->updateCache(); + const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing(); QRectF bounds = m_hoverPixmapRect; const qreal margin = styleOption().margin; @@ -145,16 +145,26 @@ QRectF KFileItemListWidget::iconBoundingRect() const QRectF KFileItemListWidget::textBoundingRect() const { - const_cast<KFileItemListWidget*>(this)->updateCache(); + const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing(); return m_textBoundingRect; } QRectF KFileItemListWidget::expansionToggleRect() const { - const_cast<KFileItemListWidget*>(this)->updateCache(); + const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing(); return m_isDir ? m_expansionArea : QRectF(); } +void KFileItemListWidget::invalidateCache() +{ + m_dirtyLayout = true; + m_dirtyContent = true; +} + +void KFileItemListWidget::refreshCache() +{ +} + void KFileItemListWidget::setTextColor(const QColor& color) { if (color != m_customTextColor) { @@ -171,13 +181,9 @@ QColor KFileItemListWidget::textColor() const void KFileItemListWidget::setOverlay(const QPixmap& overlay) { - const bool updateContent = (overlay.isNull() && !m_overlay.isNull()) || - (!overlay.isNull() && m_overlay.isNull()); - if (updateContent) { - m_overlay = overlay; - m_dirtyContent = true; - update(); - } + m_overlay = overlay; + m_dirtyContent = true; + update(); } QPixmap KFileItemListWidget::overlay() const @@ -263,12 +269,14 @@ void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) m_dirtyLayout = true; } -void KFileItemListWidget::updateCache() +void KFileItemListWidget::triggerCacheRefreshing() { if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) { return; } + refreshCache(); + m_isDir = data()["isDir"].toBool(); updateExpansionArea(); diff --git a/src/kitemviews/kfileitemlistwidget.h b/src/kitemviews/kfileitemlistwidget.h index a16e75a8e..50e746fad 100644 --- a/src/kitemviews/kfileitemlistwidget.h +++ b/src/kitemviews/kfileitemlistwidget.h @@ -53,6 +53,18 @@ public: virtual QRectF expansionToggleRect() const; protected: + /** + * Invalidates the cache which results in calling KFileItemListWidget::refreshCache() as + * soon as the item need to gets repainted. + */ + void invalidateCache(); + + /** + * Is called if the cache got invalidated by KFileItemListWidget::invalidateCache(). + * The default implementation is empty. + */ + virtual void refreshCache(); + void setTextColor(const QColor& color); QColor textColor() const; @@ -80,7 +92,7 @@ private: TextIdCount // Mandatory last entry }; - void updateCache(); + void triggerCacheRefreshing(); void updateExpansionArea(); void updatePixmapCache(); |
