]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemlistwidget.cpp
Merge remote-tracking branch 'origin/master' into frameworks
[dolphin.git] / src / views / dolphinfileitemlistwidget.cpp
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 <QIcon>
23 #include <KIconLoader>
24 #include <kversioncontrolplugin2.h>
25 #include <QColor>
26
27 #include <KDebug>
28
29 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant* informant,
30 QGraphicsItem* parent) :
31 KFileItemListWidget(informant, parent)
32 {
33 }
34
35 DolphinFileItemListWidget::~DolphinFileItemListWidget()
36 {
37 }
38
39 void DolphinFileItemListWidget::refreshCache()
40 {
41 QColor color;
42 const QHash<QByteArray, QVariant> values = data();
43 if (values.contains("version")) {
44 // The item is under version control. Apply the text color corresponding
45 // to its version state.
46 const KVersionControlPlugin2::ItemVersion version = static_cast<KVersionControlPlugin2::ItemVersion>(values.value("version").toInt());
47 const QColor textColor = styleOption().palette.text().color();
48 QColor tintColor = textColor;
49
50 // Using hardcoded colors is generally a bad idea. In this case the colors just act
51 // as tint colors and are mixed with the current set text color. The tint colors
52 // have been optimized for the base colors of the corresponding Oxygen emblems.
53 switch (version) {
54 case KVersionControlPlugin2::UpdateRequiredVersion: tintColor = Qt::yellow; break;
55 case KVersionControlPlugin2::LocallyModifiedUnstagedVersion: tintColor = Qt::green; break;
56 case KVersionControlPlugin2::LocallyModifiedVersion: tintColor = Qt::green; break;
57 case KVersionControlPlugin2::AddedVersion: tintColor = Qt::green; break;
58 case KVersionControlPlugin2::RemovedVersion: tintColor = Qt::darkRed; break;
59 case KVersionControlPlugin2::ConflictingVersion: tintColor = Qt::red; break;
60 case KVersionControlPlugin2::IgnoredVersion: tintColor = Qt::white; break;
61 case KVersionControlPlugin2::MissingVersion: tintColor = Qt::red; break;
62 case KVersionControlPlugin2::NormalVersion:
63 case KVersionControlPlugin2::UnversionedVersion:
64 default:
65 break;
66 }
67
68 color = QColor((tintColor.red() + textColor.red()) / 2,
69 (tintColor.green() + textColor.green()) / 2,
70 (tintColor.blue() + textColor.blue()) / 2,
71 (tintColor.alpha() + textColor.alpha()) / 2);
72
73 setOverlay(overlayForState(version, styleOption().iconSize));
74 } else if (!overlay().isNull()) {
75 setOverlay(QPixmap());
76 }
77
78 setTextColor(color);
79 }
80
81 QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin2::ItemVersion version, int size)
82 {
83 int overlayHeight = KIconLoader::SizeSmall;
84 if (size >= KIconLoader::SizeEnormous) {
85 overlayHeight = KIconLoader::SizeMedium;
86 } else if (size >= KIconLoader::SizeLarge) {
87 overlayHeight = KIconLoader::SizeSmallMedium;
88 } else if (size >= KIconLoader::SizeMedium) {
89 overlayHeight = KIconLoader::SizeSmall;
90 } else {
91 overlayHeight = KIconLoader::SizeSmall / 2;
92 }
93
94 QString iconName;
95 switch (version) {
96 case KVersionControlPlugin::NormalVersion:
97 iconName = "vcs-normal";
98 break;
99 case KVersionControlPlugin::UpdateRequiredVersion:
100 iconName = "vcs-update-required";
101 break;
102 case KVersionControlPlugin::LocallyModifiedVersion:
103 iconName = "vcs-locally-modified";
104 break;
105 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
106 iconName = "vcs-locally-modified-unstaged";
107 break;
108 case KVersionControlPlugin::AddedVersion:
109 iconName = "vcs-added";
110 break;
111 case KVersionControlPlugin::RemovedVersion:
112 iconName = "vcs-removed";
113 break;
114 case KVersionControlPlugin::ConflictingVersion:
115 iconName = "vcs-conflicting";
116 break;
117 case KVersionControlPlugin::UnversionedVersion:
118 case KVersionControlPlugin2::IgnoredVersion:
119 case KVersionControlPlugin2::MissingVersion:
120 break;
121 default:
122 Q_ASSERT(false);
123 break;
124 }
125
126 return QIcon::fromTheme(iconName).pixmap(QSize(overlayHeight, overlayHeight));
127 }
128