┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-09-09 20:34:55 +0200
committerPeter Penz <[email protected]>2011-09-09 20:35:57 +0200
commitc7272df5c17c804fd379e4bac2758850f03695da (patch)
treee613a2ee48df15be046fd365bc7feeaf2021619b /src
parent93cb7e02616df9746f7cdae09434e7488f4e7d28 (diff)
Improve cache handling in KItemListWidget
Provide a hook for derived KItemListWidget where the cache can be updated.
Diffstat (limited to 'src')
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp32
-rw-r--r--src/kitemviews/kfileitemlistwidget.h14
-rw-r--r--src/views/dolphinfileitemlistwidget.cpp26
-rw-r--r--src/views/dolphinfileitemlistwidget.h3
4 files changed, 41 insertions, 34 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();
diff --git a/src/views/dolphinfileitemlistwidget.cpp b/src/views/dolphinfileitemlistwidget.cpp
index a3fac7b2e..d39d58cd0 100644
--- a/src/views/dolphinfileitemlistwidget.cpp
+++ b/src/views/dolphinfileitemlistwidget.cpp
@@ -34,16 +34,14 @@ DolphinFileItemListWidget::~DolphinFileItemListWidget()
{
}
-void DolphinFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles)
+void DolphinFileItemListWidget::refreshCache()
{
- KFileItemListWidget::dataChanged(current, roles);
-
QColor color;
- QPixmap overlay;
- if (roles.contains("version")) {
+ const QHash<QByteArray, QVariant> values = data();
+ if (values.contains("version")) {
// The item is under version control. Apply the text color corresponding
// to its version state.
- const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(current.value("version").toInt());
+ const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(values.value("version").toInt());
const QColor textColor = styleOption().palette.text().color();
QColor tintColor = textColor;
@@ -68,22 +66,12 @@ void DolphinFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& c
(tintColor.blue() + textColor.blue()) / 2,
(tintColor.alpha() + textColor.alpha()) / 2);
- overlay = overlayForState(version, styleOption().iconSize);
+ setOverlay(overlayForState(version, styleOption().iconSize));
+ } else if (!overlay().isNull()) {
+ setOverlay(QPixmap());
}
setTextColor(color);
- setOverlay(overlay);
-}
-
-void DolphinFileItemListWidget::styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous)
-{
- KFileItemListWidget::styleOptionChanged(current, previous);
-
- if (!overlay().isNull() && current.iconSize != previous.iconSize) {
- const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(data().value("version").toInt());
- const QPixmap newOverlay = overlayForState(version, current.iconSize);
- setOverlay(newOverlay);
- }
}
QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::VersionState version, int size)
diff --git a/src/views/dolphinfileitemlistwidget.h b/src/views/dolphinfileitemlistwidget.h
index b08b96428..8435b5c18 100644
--- a/src/views/dolphinfileitemlistwidget.h
+++ b/src/views/dolphinfileitemlistwidget.h
@@ -40,8 +40,7 @@ public:
virtual ~DolphinFileItemListWidget();
protected:
- virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
- virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
+ virtual void refreshCache();
private:
static QPixmap overlayForState(KVersionControlPlugin::VersionState state, int size);