Provide a hook for derived KItemListWidget where the cache
can be updated.
{
KItemListWidget::paint(painter, option, widget);
{
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()) {
// Draw expansion toggle '>' or 'V'
if (m_isDir && !m_expansionArea.isEmpty()) {
QRectF KFileItemListWidget::iconBoundingRect() const
{
QRectF KFileItemListWidget::iconBoundingRect() const
{
- const_cast<KFileItemListWidget*>(this)->updateCache();
+ const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
QRectF bounds = m_hoverPixmapRect;
const qreal margin = styleOption().margin;
QRectF bounds = m_hoverPixmapRect;
const qreal margin = styleOption().margin;
QRectF KFileItemListWidget::textBoundingRect() const
{
QRectF KFileItemListWidget::textBoundingRect() const
{
- const_cast<KFileItemListWidget*>(this)->updateCache();
+ const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
return m_textBoundingRect;
}
QRectF KFileItemListWidget::expansionToggleRect() const
{
return m_textBoundingRect;
}
QRectF KFileItemListWidget::expansionToggleRect() const
{
- const_cast<KFileItemListWidget*>(this)->updateCache();
+ const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
return m_isDir ? m_expansionArea : QRectF();
}
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) {
void KFileItemListWidget::setTextColor(const QColor& color)
{
if (color != m_customTextColor) {
void KFileItemListWidget::setOverlay(const QPixmap& overlay)
{
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
}
QPixmap KFileItemListWidget::overlay() const
-void KFileItemListWidget::updateCache()
+void KFileItemListWidget::triggerCacheRefreshing()
{
if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) {
return;
}
{
if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) {
return;
}
m_isDir = data()["isDir"].toBool();
updateExpansionArea();
m_isDir = data()["isDir"].toBool();
updateExpansionArea();
virtual QRectF expansionToggleRect() const;
protected:
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;
void setTextColor(const QColor& color);
QColor textColor() const;
TextIdCount // Mandatory last entry
};
TextIdCount // Mandatory last entry
};
+ void triggerCacheRefreshing();
void updateExpansionArea();
void updatePixmapCache();
void updateExpansionArea();
void updatePixmapCache();
-void DolphinFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles)
+void DolphinFileItemListWidget::refreshCache()
- KFileItemListWidget::dataChanged(current, roles);
-
- 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.
// 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;
const QColor textColor = styleOption().palette.text().color();
QColor tintColor = textColor;
(tintColor.blue() + textColor.blue()) / 2,
(tintColor.alpha() + textColor.alpha()) / 2);
(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());
- 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)
}
QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::VersionState version, int size)
virtual ~DolphinFileItemListWidget();
protected:
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);
private:
static QPixmap overlayForState(KVersionControlPlugin::VersionState state, int size);