From fa4680cb38028aceb68d41e1937d27c71d1f121b Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sun, 12 Jul 2009 14:00:45 +0000 Subject: Enable Dolphin to show the revision states of files that are under revision control systems like SVN, Git, CVS, ... The current code is an early draft and it is planned that all plugins (SVN, Git, CVS, ...) are maintained outside Dolphin. If the API is stable enough, a discussion will be done at kfm-devel@kde.org regarding the location of the plugins (the current implementation of SubversionPlugin is only temporary located in Dolphin for testing purposes). RevisionControlObserver is implemented in a way that no recognizable slowdown is given for directories that are not under revision control. CCBUG: 192158 svn path=/trunk/KDE/kdebase/apps/; revision=995351 --- src/dolphinfileitemdelegate.cpp | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'src/dolphinfileitemdelegate.cpp') diff --git a/src/dolphinfileitemdelegate.cpp b/src/dolphinfileitemdelegate.cpp index 9be70647b..6478baf3b 100644 --- a/src/dolphinfileitemdelegate.cpp +++ b/src/dolphinfileitemdelegate.cpp @@ -19,12 +19,13 @@ #include "dolphinfileitemdelegate.h" +#include +#include + #include #include #include - -#include -#include +#include DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) : KFileItemDelegate(parent), @@ -40,17 +41,19 @@ void DolphinFileItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + const QAbstractProxyModel* proxyModel = static_cast(index.model()); + const DolphinModel* dolphinModel = static_cast(proxyModel->sourceModel()); + if (m_hasMinimizedNameColumn && (index.column() == KDirModel::Name)) { QStyleOptionViewItemV4 opt(option); - const QAbstractProxyModel* proxyModel = static_cast(index.model()); - const KDirModel* dirModel = static_cast(proxyModel->sourceModel()); const QModelIndex dirIndex = proxyModel->mapToSource(index); - const KFileItem item = dirModel->itemForIndex(dirIndex); + const KFileItem item = dolphinModel->itemForIndex(dirIndex); if (!item.isNull()) { - // Symbolic links are displayed in an italic font - if (item.isLink()) + // symbolic links are displayed in an italic font + if (item.isLink()) { opt.font.setItalic(true); + } const int width = nameColumnWidth(item.text(), opt); opt.rect.setWidth(width); @@ -59,6 +62,26 @@ void DolphinFileItemDelegate::paint(QPainter* painter, } else { KFileItemDelegate::paint(painter, option, index); } + + if (dolphinModel->hasRevisionData()) { + // The currently shown items are under revision control. Show the current revision + // state above the decoration. + const QModelIndex dirIndex = proxyModel->mapToSource(index); + const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Revision); + const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole); + const DolphinModel::RevisionState state = static_cast(data.toInt()); + + if (state != DolphinModel::LocalRevision) { + // TODO: The following code is just a proof of concept. Icons will be used later... + QColor color(200, 0, 0, 32); + switch (state) { + case DolphinModel::LatestRevision: color = QColor(0, 180, 0, 32); break; + // ... + default: break; + } + painter->fillRect(option.rect, color); + } + } } int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option) -- cgit v1.3