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