]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemlistwidget.cpp
Fix middle-click not following the "Open archives as folder" setting
[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 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:
39 tintColor = Qt::yellow;
40 break;
41 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
42 tintColor = Qt::green;
43 break;
44 case KVersionControlPlugin::LocallyModifiedVersion:
45 tintColor = Qt::green;
46 break;
47 case KVersionControlPlugin::AddedVersion:
48 tintColor = Qt::green;
49 break;
50 case KVersionControlPlugin::RemovedVersion:
51 tintColor = Qt::darkRed;
52 break;
53 case KVersionControlPlugin::ConflictingVersion:
54 tintColor = Qt::red;
55 break;
56 case KVersionControlPlugin::IgnoredVersion:
57 tintColor = Qt::white;
58 break;
59 case KVersionControlPlugin::MissingVersion:
60 tintColor = Qt::red;
61 break;
62 case KVersionControlPlugin::NormalVersion:
63 case KVersionControlPlugin::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(KVersionControlPlugin::ItemVersion version, int size) const
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 = QStringLiteral("vcs-normal");
98 break;
99 case KVersionControlPlugin::UpdateRequiredVersion:
100 iconName = QStringLiteral("vcs-update-required");
101 break;
102 case KVersionControlPlugin::LocallyModifiedVersion:
103 iconName = QStringLiteral("vcs-locally-modified");
104 break;
105 case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
106 iconName = QStringLiteral("vcs-locally-modified-unstaged");
107 break;
108 case KVersionControlPlugin::AddedVersion:
109 iconName = QStringLiteral("vcs-added");
110 break;
111 case KVersionControlPlugin::RemovedVersion:
112 iconName = QStringLiteral("vcs-removed");
113 break;
114 case KVersionControlPlugin::ConflictingVersion:
115 iconName = QStringLiteral("vcs-conflicting");
116 break;
117 case KVersionControlPlugin::UnversionedVersion:
118 case KVersionControlPlugin::IgnoredVersion:
119 case KVersionControlPlugin::MissingVersion:
120 break;
121 default:
122 Q_ASSERT(false);
123 break;
124 }
125
126 const qreal dpr = KItemViewsUtils::devicePixelRatio(this);
127 return QIcon::fromTheme(iconName).pixmap(QSize(overlayHeight, overlayHeight), dpr);
128 }
129
130 #include "moc_dolphinfileitemlistwidget.cpp"