]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemlistwidget.cpp
Fix build for KIO version < 6.14
[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 #include "../kitemviews/private/kitemviewsutils.h"
9
10 #include "dolphindebug.h"
11
12 #include <KIconLoader>
13
14 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent)
15 : KFileItemListWidget(informant, parent)
16 {
17 }
18
19 DolphinFileItemListWidget::~DolphinFileItemListWidget()
20 {
21 }
22
23 void DolphinFileItemListWidget::refreshCache()
24 {
25 QColor color;
26 const QHash<QByteArray, QVariant> values = data();
27 QHash<Qt::Corner, QString> overlays;
28 if (values.contains("version")) {
29 // The item is under version control. Apply the text color corresponding
30 // to its version state.
31 const KVersionControlPlugin::ItemVersion version = static_cast<KVersionControlPlugin::ItemVersion>(values.value("version").toInt());
32 const QColor textColor = styleOption().palette.text().color();
33 QColor tintColor = textColor;
34
35 // Using hardcoded colors is generally a bad idea. In this case the colors just act
36 // as tint colors and are mixed with the current set text color. The tint colors
37 // have been optimized for the base colors of the corresponding Oxygen emblems.
38 switch (version) {
39 case KVersionControlPlugin::UpdateRequiredVersion:
40 tintColor = Qt::yellow;
41 break;
42 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
43 tintColor = Qt::green;
44 break;
45 case KVersionControlPlugin::LocallyModifiedVersion:
46 tintColor = Qt::green;
47 break;
48 case KVersionControlPlugin::AddedVersion:
49 tintColor = Qt::green;
50 break;
51 case KVersionControlPlugin::RemovedVersion:
52 tintColor = Qt::darkRed;
53 break;
54 case KVersionControlPlugin::ConflictingVersion:
55 tintColor = Qt::red;
56 break;
57 case KVersionControlPlugin::IgnoredVersion:
58 tintColor = Qt::white;
59 break;
60 case KVersionControlPlugin::MissingVersion:
61 tintColor = Qt::red;
62 break;
63 case KVersionControlPlugin::NormalVersion:
64 case KVersionControlPlugin::UnversionedVersion:
65 default:
66 break;
67 }
68
69 color = QColor((tintColor.red() + textColor.red()) / 2,
70 (tintColor.green() + textColor.green()) / 2,
71 (tintColor.blue() + textColor.blue()) / 2,
72 (tintColor.alpha() + textColor.alpha()) / 2);
73
74 overlays.insert(Qt::Corner::BottomLeftCorner, overlayForState(version));
75 }
76
77 if (values.contains("iconOverlays")) {
78 const auto corners = {Qt::Corner::BottomRightCorner, Qt::Corner::TopLeftCorner, Qt::Corner::TopRightCorner};
79 const auto iconOverlays = values.value("iconOverlays").toStringList();
80 auto overlaysIt = iconOverlays.constBegin();
81 for (const auto &corner : corners) {
82 if (overlaysIt == iconOverlays.constEnd()) {
83 break;
84 }
85 overlays.insert(corner, *overlaysIt);
86 overlaysIt = ++overlaysIt;
87 }
88 }
89
90 setOverlays(overlays);
91 setTextColor(color);
92 }
93
94 QString DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::ItemVersion version) const
95 {
96 QString iconName;
97 switch (version) {
98 case KVersionControlPlugin::NormalVersion:
99 iconName = QStringLiteral("vcs-normal");
100 break;
101 case KVersionControlPlugin::UpdateRequiredVersion:
102 iconName = QStringLiteral("vcs-update-required");
103 break;
104 case KVersionControlPlugin::LocallyModifiedVersion:
105 iconName = QStringLiteral("vcs-locally-modified");
106 break;
107 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
108 iconName = QStringLiteral("vcs-locally-modified-unstaged");
109 break;
110 case KVersionControlPlugin::AddedVersion:
111 iconName = QStringLiteral("vcs-added");
112 break;
113 case KVersionControlPlugin::RemovedVersion:
114 iconName = QStringLiteral("vcs-removed");
115 break;
116 case KVersionControlPlugin::ConflictingVersion:
117 iconName = QStringLiteral("vcs-conflicting");
118 break;
119 case KVersionControlPlugin::UnversionedVersion:
120 case KVersionControlPlugin::IgnoredVersion:
121 case KVersionControlPlugin::MissingVersion:
122 break;
123 default:
124 Q_ASSERT(false);
125 break;
126 }
127
128 return iconName;
129 }
130
131 #include "moc_dolphinfileitemlistwidget.cpp"