]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinfileitemdelegate.cpp
DolphinContextMenu: Set the properties action from actionCollection
[dolphin.git] / src / views / dolphinfileitemdelegate.cpp
index 6b706c88b2c2ebb46694a5f26858dbbd64153f89..4d66c73f10ef782d93c3664b45ea482906802a57 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com>             *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
 #include "dolphinfileitemdelegate.h"
 
 #include "dolphinmodel.h"
-#include <kfileitem.h>
-#include <kicon.h>
-#include <kiconloader.h>
+#include <KColorScheme>
+#include <KFileItem>
+#include <KGlobalSettings>
+#include <KIcon>
+#include <KIconLoader>
+#include <KStringHandler>
 
 #include <QAbstractItemModel>
 #include <QAbstractProxyModel>
@@ -35,9 +38,11 @@ DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) :
     KFileItemDelegate(parent),
     m_hasMinimizedNameColumn(false),
     m_cachedSize(),
-    m_cachedEmblems()
+    m_cachedEmblems(),
+    m_cachedInactiveTextColorDirty(true)
 {
     setJobTransfersVisible(true);
+    connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(handleDisplayPaletteChange()));
 }
 
 DolphinFileItemDelegate::~DolphinFileItemDelegate()
@@ -57,6 +62,18 @@ void DolphinFileItemDelegate::paint(QPainter* painter,
         adjustOptionWidth(opt, proxyModel, dolphinModel, index);
     }
 
+    if (!isNameColumn) {
+        // Use the inactive text color for all columns except the name column. This indicates for the user that
+        // hovering other columns does not change the actions context.
+        QPalette palette = opt.palette;
+        if (m_cachedInactiveTextColorDirty) {
+            m_cachedInactiveTextColor = KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText).color();
+            m_cachedInactiveTextColorDirty = false;
+        }
+        palette.setColor(QPalette::Text, m_cachedInactiveTextColor);
+        opt.palette = palette;
+    }
+
     if (dolphinModel->hasVersionData() && isNameColumn) {
         // The currently shown items are under revision control. Show the current revision
         // state by adding an emblem and changing the text tintColor.
@@ -82,7 +99,7 @@ void DolphinFileItemDelegate::paint(QPainter* painter,
 int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option)
 {
     QFontMetrics fontMetrics(option.font);
-    int width = option.decorationSize.width() + fontMetrics.width(name) + 16;
+    int width = option.decorationSize.width() + fontMetrics.width(KStringHandler::preProcessWrap(name)) + 16;
 
     const int defaultWidth = option.rect.width();
     if ((defaultWidth > 0) && (defaultWidth < width)) {
@@ -91,6 +108,11 @@ int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOp
     return width;
 }
 
+void DolphinFileItemDelegate::handleDisplayPaletteChange()
+{
+    m_cachedInactiveTextColorDirty = true;
+}
+
 void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option,
                                                 const QAbstractProxyModel* proxyModel,
                                                 const DolphinModel* dolphinModel,
@@ -118,11 +140,12 @@ void DolphinFileItemDelegate::adjustOptionTextColor(QStyleOptionViewItemV4& opti
     // as tint colors and are mixed with the current set text color. The tint colors
     // have been optimized for the base colors of the corresponding Oxygen emblems.
     switch (state) {
-    case KVersionControlPlugin::UpdateRequiredVersion:  tintColor = Qt::yellow; break;
-    case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break;
-    case KVersionControlPlugin::AddedVersion:           tintColor = Qt::darkGreen; break;
-    case KVersionControlPlugin::RemovedVersion:         tintColor = Qt::darkRed; break;
-    case KVersionControlPlugin::ConflictingVersion:     tintColor = Qt::red; break;
+    case KVersionControlPlugin::UpdateRequiredVersion:          tintColor = Qt::yellow; break;
+    case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::darkGreen; break;
+    case KVersionControlPlugin::LocallyModifiedVersion:         tintColor = Qt::green; break;
+    case KVersionControlPlugin::AddedVersion:                   tintColor = Qt::green; break;
+    case KVersionControlPlugin::RemovedVersion:                 tintColor = Qt::darkRed; break;
+    case KVersionControlPlugin::ConflictingVersion:             tintColor = Qt::red; break;
     case KVersionControlPlugin::UnversionedVersion:
     case KVersionControlPlugin::NormalVersion:
     default:
@@ -142,7 +165,7 @@ void DolphinFileItemDelegate::adjustOptionTextColor(QStyleOptionViewItemV4& opti
 
 QPixmap DolphinFileItemDelegate::emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const
 {
-    Q_ASSERT(state <= KVersionControlPlugin::ConflictingVersion);
+    Q_ASSERT(state <= KVersionControlPlugin::LocallyModifiedUnstagedVersion);
     if (m_cachedSize != size) {
         m_cachedSize = size;
 
@@ -159,17 +182,35 @@ QPixmap DolphinFileItemDelegate::emblemForState(KVersionControlPlugin::VersionSt
         }
 
         const QSize emblemSize(emblemHeight, emblemHeight);
-        for (int i = KVersionControlPlugin::NormalVersion; i <= KVersionControlPlugin::ConflictingVersion; ++i) {
+        for (int i = KVersionControlPlugin::NormalVersion; i <= KVersionControlPlugin::LocallyModifiedUnstagedVersion; ++i) {
             QString iconName;
             switch (i) {
-            case KVersionControlPlugin::NormalVersion:          iconName = "vcs-normal"; break;
-            case KVersionControlPlugin::UpdateRequiredVersion:  iconName = "vcs-update-required"; break;
-            case KVersionControlPlugin::LocallyModifiedVersion: iconName = "vcs-locally-modified"; break;
-            case KVersionControlPlugin::AddedVersion:           iconName = "vcs-added"; break;
-            case KVersionControlPlugin::RemovedVersion:         iconName = "vcs-removed"; break;
-            case KVersionControlPlugin::ConflictingVersion:     iconName = "vcs-conflicting"; break;
+            case KVersionControlPlugin::NormalVersion:
+                iconName = "vcs-normal";
+                break;
+            case KVersionControlPlugin::UpdateRequiredVersion:
+                iconName = "vcs-update-required";
+                break;
+            case KVersionControlPlugin::LocallyModifiedVersion:
+                iconName = "vcs-locally-modified";
+                break;
+            case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
+                iconName = "vcs-locally-modified-unstaged";
+                break;
+            case KVersionControlPlugin::AddedVersion:
+                iconName = "vcs-added";
+                break;
+            case KVersionControlPlugin::RemovedVersion:
+                iconName = "vcs-removed";
+                break;
+            case KVersionControlPlugin::ConflictingVersion:
+                iconName = "vcs-conflicting";
+                break;
             case KVersionControlPlugin::UnversionedVersion:
-            default:                                            Q_ASSERT(false); break;
+                break;
+            default:
+                Q_ASSERT(false);
+                break;
             }
 
             m_cachedEmblems[i] = KIcon(iconName).pixmap(emblemSize);