~ubuntu-branches/debian/sid/kde-baseapps/sid

« back to all changes in this revision

Viewing changes to dolphin/src/views/dolphinfileitemlistwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Modestas Vainius, Eshat Cakar, Pino Toscano
  • Date: 2012-06-09 22:18:08 UTC
  • mfrom: (4.2.1) (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20120609221808-h1l0ekd5qmb8nefr
Tags: 4:4.8.4-1
* New upstream release.

[ Eshat Cakar ]
* Add watch file.
* Bump kde-sc-dev-latest build dependency to version 4:4.8.4.
* Update installed files.

[ Pino Toscano ]
* Move files of the konqueror documentation from kde-baseapps-data to
  konqueror itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 
18
 ***************************************************************************/
 
19
 
 
20
#include "dolphinfileitemlistwidget.h"
 
21
 
 
22
#include <KIcon>
 
23
#include <KIconLoader>
 
24
#include <kversioncontrolplugin2.h>
 
25
#include <QColor>
 
26
 
 
27
#include <KDebug>
 
28
 
 
29
DolphinFileItemListWidget::DolphinFileItemListWidget(QGraphicsItem* parent) :
 
30
    KFileItemListWidget(parent)
 
31
{
 
32
}
 
33
 
 
34
DolphinFileItemListWidget::~DolphinFileItemListWidget()
 
35
{
 
36
}
 
37
 
 
38
void DolphinFileItemListWidget::refreshCache()
 
39
{
 
40
    QColor color;
 
41
    const QHash<QByteArray, QVariant> values = data();
 
42
    if (values.contains("version")) {
 
43
        // The item is under version control. Apply the text color corresponding
 
44
        // to its version state.
 
45
        const KVersionControlPlugin2::ItemVersion version = static_cast<KVersionControlPlugin2::ItemVersion>(values.value("version").toInt());
 
46
        const QColor textColor = styleOption().palette.text().color();
 
47
        QColor tintColor = textColor;
 
48
 
 
49
        // Using hardcoded colors is generally a bad idea. In this case the colors just act
 
50
        // as tint colors and are mixed with the current set text color. The tint colors
 
51
        // have been optimized for the base colors of the corresponding Oxygen emblems.
 
52
        switch (version) {
 
53
        case KVersionControlPlugin2::UpdateRequiredVersion:          tintColor = Qt::yellow; break;
 
54
        case KVersionControlPlugin2::LocallyModifiedUnstagedVersion: tintColor = Qt::green; break;
 
55
        case KVersionControlPlugin2::LocallyModifiedVersion:         tintColor = Qt::green; break;
 
56
        case KVersionControlPlugin2::AddedVersion:                   tintColor = Qt::green; break;
 
57
        case KVersionControlPlugin2::RemovedVersion:                 tintColor = Qt::darkRed; break;
 
58
        case KVersionControlPlugin2::ConflictingVersion:             tintColor = Qt::red; break;
 
59
        case KVersionControlPlugin2::IgnoredVersion:                 tintColor = Qt::white; break;
 
60
        case KVersionControlPlugin2::MissingVersion:                 tintColor = Qt::red; break;
 
61
        case KVersionControlPlugin2::NormalVersion:
 
62
        case KVersionControlPlugin2::UnversionedVersion:
 
63
        default:
 
64
            break;
 
65
        }
 
66
 
 
67
        color = QColor((tintColor.red()   + textColor.red())   / 2,
 
68
                       (tintColor.green() + textColor.green()) / 2,
 
69
                       (tintColor.blue()  + textColor.blue())  / 2,
 
70
                       (tintColor.alpha() + textColor.alpha()) / 2);
 
71
 
 
72
        setOverlay(overlayForState(version, styleOption().iconSize));
 
73
    } else if (!overlay().isNull()) {
 
74
        setOverlay(QPixmap());
 
75
    }
 
76
 
 
77
    setTextColor(color);
 
78
}
 
79
 
 
80
QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin2::ItemVersion version, int size)
 
81
{
 
82
    int overlayHeight = KIconLoader::SizeSmall;
 
83
    if (size >= KIconLoader::SizeEnormous) {
 
84
        overlayHeight = KIconLoader::SizeMedium;
 
85
    } else if (size >= KIconLoader::SizeLarge) {
 
86
        overlayHeight = KIconLoader::SizeSmallMedium;
 
87
    } else if (size >= KIconLoader::SizeMedium) {
 
88
        overlayHeight = KIconLoader::SizeSmall;
 
89
    } else {
 
90
        overlayHeight = KIconLoader::SizeSmall / 2;
 
91
    }
 
92
 
 
93
    QString iconName;
 
94
    switch (version) {
 
95
    case KVersionControlPlugin::NormalVersion:
 
96
        iconName = "vcs-normal";
 
97
        break;
 
98
    case KVersionControlPlugin::UpdateRequiredVersion:
 
99
        iconName = "vcs-update-required";
 
100
        break;
 
101
    case KVersionControlPlugin::LocallyModifiedVersion:
 
102
        iconName = "vcs-locally-modified";
 
103
        break;
 
104
    case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
 
105
        iconName = "vcs-locally-modified-unstaged";
 
106
        break;
 
107
    case KVersionControlPlugin::AddedVersion:
 
108
        iconName = "vcs-added";
 
109
        break;
 
110
    case KVersionControlPlugin::RemovedVersion:
 
111
        iconName = "vcs-removed";
 
112
        break;
 
113
    case KVersionControlPlugin::ConflictingVersion:
 
114
        iconName = "vcs-conflicting";
 
115
        break;
 
116
    case KVersionControlPlugin::UnversionedVersion:
 
117
        break;
 
118
    default:
 
119
        Q_ASSERT(false);
 
120
        break;
 
121
    }
 
122
 
 
123
    return KIcon(iconName).pixmap(QSize(overlayHeight, overlayHeight));
 
124
}
 
125
 
 
126
#include "dolphinfileitemlistwidget.moc"