]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemlistwidget.cpp
429060221fafb2ecb42c20790f84baa74b39d042
[dolphin.git] / src / views / dolphinfileitemlistwidget.cpp
1 /*
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "dolphinfileitemlistwidget.h"
8
9 #include "dolphindebug.h"
10
11 #include <KIconLoader>
12
13 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent)
14 : KFileItemListWidget(informant, parent)
15 {
16 }
17
18 DolphinFileItemListWidget::~DolphinFileItemListWidget()
19 {
20 }
21
22 void DolphinFileItemListWidget::refreshCache()
23 {
24 QColor color;
25 const QHash<QByteArray, QVariant> values = data();
26 if (values.contains("version")) {
27 // The item is under version control. Apply the text color corresponding
28 // to its version state.
29 const KVersionControlPlugin::ItemVersion version = static_cast<KVersionControlPlugin::ItemVersion>(values.value("version").toInt());
30 const QColor textColor = styleOption().palette.text().color();
31 QColor tintColor = textColor;
32
33 // Using hardcoded colors is generally a bad idea. In this case the colors just act
34 // as tint colors and are mixed with the current set text color. The tint colors
35 // have been optimized for the base colors of the corresponding Oxygen emblems.
36 switch (version) {
37 case KVersionControlPlugin::UpdateRequiredVersion:
38 tintColor = Qt::yellow;
39 break;
40 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
41 tintColor = Qt::green;
42 break;
43 case KVersionControlPlugin::LocallyModifiedVersion:
44 tintColor = Qt::green;
45 break;
46 case KVersionControlPlugin::AddedVersion:
47 tintColor = Qt::green;
48 break;
49 case KVersionControlPlugin::RemovedVersion:
50 tintColor = Qt::darkRed;
51 break;
52 case KVersionControlPlugin::ConflictingVersion:
53 tintColor = Qt::red;
54 break;
55 case KVersionControlPlugin::IgnoredVersion:
56 tintColor = Qt::white;
57 break;
58 case KVersionControlPlugin::MissingVersion:
59 tintColor = Qt::red;
60 break;
61 case KVersionControlPlugin::NormalVersion:
62 case KVersionControlPlugin::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(KVersionControlPlugin::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 = QStringLiteral("vcs-normal");
97 break;
98 case KVersionControlPlugin::UpdateRequiredVersion:
99 iconName = QStringLiteral("vcs-update-required");
100 break;
101 case KVersionControlPlugin::LocallyModifiedVersion:
102 iconName = QStringLiteral("vcs-locally-modified");
103 break;
104 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
105 iconName = QStringLiteral("vcs-locally-modified-unstaged");
106 break;
107 case KVersionControlPlugin::AddedVersion:
108 iconName = QStringLiteral("vcs-added");
109 break;
110 case KVersionControlPlugin::RemovedVersion:
111 iconName = QStringLiteral("vcs-removed");
112 break;
113 case KVersionControlPlugin::ConflictingVersion:
114 iconName = QStringLiteral("vcs-conflicting");
115 break;
116 case KVersionControlPlugin::UnversionedVersion:
117 case KVersionControlPlugin::IgnoredVersion:
118 case KVersionControlPlugin::MissingVersion:
119 break;
120 default:
121 Q_ASSERT(false);
122 break;
123 }
124
125 return QIcon::fromTheme(iconName).pixmap(QSize(overlayHeight, overlayHeight));
126 }