1
/***************************************************************************
2
* Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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
***************************************************************************/
20
#include "dolphinfileitemlistwidget.h"
23
#include <KIconLoader>
24
#include <kversioncontrolplugin2.h>
29
DolphinFileItemListWidget::DolphinFileItemListWidget(QGraphicsItem* parent) :
30
KFileItemListWidget(parent)
34
DolphinFileItemListWidget::~DolphinFileItemListWidget()
38
void DolphinFileItemListWidget::refreshCache()
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;
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.
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:
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);
72
setOverlay(overlayForState(version, styleOption().iconSize));
73
} else if (!overlay().isNull()) {
74
setOverlay(QPixmap());
80
QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin2::ItemVersion version, int size)
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;
90
overlayHeight = KIconLoader::SizeSmall / 2;
95
case KVersionControlPlugin::NormalVersion:
96
iconName = "vcs-normal";
98
case KVersionControlPlugin::UpdateRequiredVersion:
99
iconName = "vcs-update-required";
101
case KVersionControlPlugin::LocallyModifiedVersion:
102
iconName = "vcs-locally-modified";
104
case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
105
iconName = "vcs-locally-modified-unstaged";
107
case KVersionControlPlugin::AddedVersion:
108
iconName = "vcs-added";
110
case KVersionControlPlugin::RemovedVersion:
111
iconName = "vcs-removed";
113
case KVersionControlPlugin::ConflictingVersion:
114
iconName = "vcs-conflicting";
116
case KVersionControlPlugin::UnversionedVersion:
123
return KIcon(iconName).pixmap(QSize(overlayHeight, overlayHeight));
126
#include "dolphinfileitemlistwidget.moc"