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