]> cloud.milkyroute.net Git - dolphin.git/commitdiff
The Oxygen team will provide revision control emblems for KDE 4.4. Adjust the code...
authorPeter Penz <peter.penz19@gmail.com>
Mon, 13 Jul 2009 20:39:44 +0000 (20:39 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Mon, 13 Jul 2009 20:39:44 +0000 (20:39 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=996101

src/dolphinfileitemdelegate.cpp
src/dolphinfileitemdelegate.h
src/dolphinmodel.h
src/revisioncontrolplugin.h

index cc8c449834ffa69fcff837acfe4fa5148a97df25..7232c38f5883bcbd008d793a347d7f714a7ce2d5 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <dolphinmodel.h>
 #include <kfileitem.h>
+#include <kicon.h>
+#include <kiconloader.h>
 
 #include <QAbstractItemModel>
 #include <QAbstractProxyModel>
@@ -45,34 +47,32 @@ void DolphinFileItemDelegate::paint(QPainter* painter,
 {
     const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(index.model());
     const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(proxyModel->sourceModel());
-    const bool useMinimizedNameColumn = m_hasMinimizedNameColumn && (index.column() == KDirModel::Name);
+    const bool isNameColumn = (index.column() == KDirModel::Name);
 
-    if (dolphinModel->hasRevisionData()) {
+    if (m_hasMinimizedNameColumn && isNameColumn) {
+        QStyleOptionViewItemV4 opt(option);
+        adjustOptionWidth(opt, proxyModel, dolphinModel, index);
+        KFileItemDelegate::paint(painter, opt, index);
+    } else {
+        KFileItemDelegate::paint(painter, option, index);
+    }
+
+    if (dolphinModel->hasRevisionData() && isNameColumn) {
         // The currently shown items are under revision control. Show the current revision
-        // state by adjusting the text color.
+        // state by adding an emblem.
         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<DolphinModel::RevisionState>(data.toInt());
 
         if (state != DolphinModel::LocalRevision) {
-            QStyleOptionViewItemV4 opt(option);
-            // TODO: use different colors for different states
-            opt.palette.setColor(QPalette::Text, QColor(40, 150, 40));
-            if (useMinimizedNameColumn) {
-                adjustOptionWidth(opt, proxyModel, dolphinModel, index);
-            }
-            KFileItemDelegate::paint(painter, opt, index);
-            return;
+            // TODO: extend KFileItemDelegate to be able to get the icon boundaries
+            const QRect iconRect(option.rect.x(), option.rect.y(),
+                                 KIconLoader::SizeSmall, KIconLoader::SizeSmall);
+            const QPixmap emblem = emblemForState(state, iconRect.size());
+            painter->drawPixmap(iconRect.x(), iconRect.y(), emblem);
         }
-    } else if (useMinimizedNameColumn) {
-        QStyleOptionViewItemV4 opt(option);
-        adjustOptionWidth(opt, proxyModel, dolphinModel, index);
-        KFileItemDelegate::paint(painter, opt, index);
-        return;
     }
-
-    KFileItemDelegate::paint(painter, option, index);
 }
 
 int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option)
@@ -105,3 +105,25 @@ void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option,
     }
 }
 
+QPixmap DolphinFileItemDelegate::emblemForState(DolphinModel::RevisionState state, const QSize& size)
+{
+    // TODO #1: all icons that are use here will be replaced by revision control emblems provided by the
+    // Oxygen team before KDE 4.4
+    // TODO #2: cache the icons
+    switch (state) {
+    case DolphinModel::LatestRevision:
+        return KIcon("dialog-ok-apply").pixmap(size);
+        break;
+
+    case DolphinModel::ConflictingRevision:
+        return KIcon("emblem-important").pixmap(size);
+        break;
+
+    // ...
+
+    default:
+        break;
+    }
+    return QPixmap();
+}
+
index 70b30e99d16df8217c3d9956625ce79ab44511ea..b6a4d45b2f218c77c892457f93f1838b5da8a202 100644 (file)
@@ -20,9 +20,9 @@
 #ifndef DOLPHINFILEITEMDELEGATE_H
 #define DOLPHINFILEITEMDELEGATE_H
 
+#include <dolphinmodel.h>
 #include <kfileitemdelegate.h>
 
-class DolphinModel;
 class QAbstractProxyModel;
 
 /**
@@ -66,6 +66,8 @@ private:
                                   const DolphinModel* dolphinModel,
                                   const QModelIndex& index);
 
+    static QPixmap emblemForState(DolphinModel::RevisionState state, const QSize& size);
+
 private:
     bool m_hasMinimizedNameColumn;
 };
index b03507dc5790471903fb52711edf5308f03830c7..717f21d4e9de433993febccb40612b89365eae97 100644 (file)
@@ -39,7 +39,8 @@ public:
 
     enum RevisionState {
         LocalRevision,
-        LatestRevision
+        LatestRevision,
+        ConflictingRevision
         // TODO...
     };
 
index 6cacb9224acaeef0b58f85f05c61baa3365cafbb..2fd7d77c08ce14c7466779f37cbff01ad6122924 100644 (file)
@@ -36,7 +36,8 @@ public:
     enum RevisionState
     {
         LocalRevision,
-        LatestRevision
+        LatestRevision,
+        ConflictingRevision
         // TODO...
     };