2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinfileitemlistwidget.h"
8 #include "../kitemviews/private/kitemviewsutils.h"
10 #include "dolphindebug.h"
12 #include <KIconLoader>
14 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant
*informant
, 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
:
39 tintColor
= Qt::yellow
;
41 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
42 tintColor
= Qt::green
;
44 case KVersionControlPlugin::LocallyModifiedVersion
:
45 tintColor
= Qt::green
;
47 case KVersionControlPlugin::AddedVersion
:
48 tintColor
= Qt::green
;
50 case KVersionControlPlugin::RemovedVersion
:
51 tintColor
= Qt::darkRed
;
53 case KVersionControlPlugin::ConflictingVersion
:
56 case KVersionControlPlugin::IgnoredVersion
:
57 tintColor
= Qt::white
;
59 case KVersionControlPlugin::MissingVersion
:
62 case KVersionControlPlugin::NormalVersion
:
63 case KVersionControlPlugin::UnversionedVersion
:
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);
73 setOverlay(overlayForState(version
, styleOption().iconSize
));
74 } else if (!overlay().isNull()) {
75 setOverlay(QPixmap());
81 QPixmap
DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::ItemVersion version
, int size
) const
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
;
91 overlayHeight
= KIconLoader::SizeSmall
/ 2;
96 case KVersionControlPlugin::NormalVersion
:
97 iconName
= QStringLiteral("vcs-normal");
99 case KVersionControlPlugin::UpdateRequiredVersion
:
100 iconName
= QStringLiteral("vcs-update-required");
102 case KVersionControlPlugin::LocallyModifiedVersion
:
103 iconName
= QStringLiteral("vcs-locally-modified");
105 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
106 iconName
= QStringLiteral("vcs-locally-modified-unstaged");
108 case KVersionControlPlugin::AddedVersion
:
109 iconName
= QStringLiteral("vcs-added");
111 case KVersionControlPlugin::RemovedVersion
:
112 iconName
= QStringLiteral("vcs-removed");
114 case KVersionControlPlugin::ConflictingVersion
:
115 iconName
= QStringLiteral("vcs-conflicting");
117 case KVersionControlPlugin::UnversionedVersion
:
118 case KVersionControlPlugin::IgnoredVersion
:
119 case KVersionControlPlugin::MissingVersion
:
126 const qreal dpr
= KItemViewsUtils::devicePixelRatio(this);
127 return QIcon::fromTheme(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
), dpr
);
130 #include "moc_dolphinfileitemlistwidget.cpp"