2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinfileitemlistwidget.h"
9 #include "dolphindebug.h"
11 #include <KIconLoader>
13 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant
* informant
,
14 QGraphicsItem
* parent
) :
15 KFileItemListWidget(informant
, parent
)
19 DolphinFileItemListWidget::~DolphinFileItemListWidget()
23 void DolphinFileItemListWidget::refreshCache()
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
;
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.
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
:
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);
57 setOverlay(overlayForState(version
, styleOption().iconSize
));
58 } else if (!overlay().isNull()) {
59 setOverlay(QPixmap());
65 QPixmap
DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::ItemVersion version
, int size
)
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
;
75 overlayHeight
= KIconLoader::SizeSmall
/ 2;
80 case KVersionControlPlugin::NormalVersion
:
81 iconName
= QStringLiteral("vcs-normal");
83 case KVersionControlPlugin::UpdateRequiredVersion
:
84 iconName
= QStringLiteral("vcs-update-required");
86 case KVersionControlPlugin::LocallyModifiedVersion
:
87 iconName
= QStringLiteral("vcs-locally-modified");
89 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
90 iconName
= QStringLiteral("vcs-locally-modified-unstaged");
92 case KVersionControlPlugin::AddedVersion
:
93 iconName
= QStringLiteral("vcs-added");
95 case KVersionControlPlugin::RemovedVersion
:
96 iconName
= QStringLiteral("vcs-removed");
98 case KVersionControlPlugin::ConflictingVersion
:
99 iconName
= QStringLiteral("vcs-conflicting");
101 case KVersionControlPlugin::UnversionedVersion
:
102 case KVersionControlPlugin::IgnoredVersion
:
103 case KVersionControlPlugin::MissingVersion
:
110 return QIcon::fromTheme(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
));