1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dolphinfileitemlistwidget.h"
22 #include "dolphindebug.h"
24 #include <KIconLoader>
26 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant
* informant
,
27 QGraphicsItem
* parent
) :
28 KFileItemListWidget(informant
, parent
)
32 DolphinFileItemListWidget::~DolphinFileItemListWidget()
36 void DolphinFileItemListWidget::refreshCache()
39 const QHash
<QByteArray
, QVariant
> values
= data();
40 if (values
.contains("version")) {
41 // The item is under version control. Apply the text color corresponding
42 // to its version state.
43 const KVersionControlPlugin::ItemVersion version
= static_cast<KVersionControlPlugin::ItemVersion
>(values
.value("version").toInt());
44 const QColor textColor
= styleOption().palette
.text().color();
45 QColor tintColor
= textColor
;
47 // Using hardcoded colors is generally a bad idea. In this case the colors just act
48 // as tint colors and are mixed with the current set text color. The tint colors
49 // have been optimized for the base colors of the corresponding Oxygen emblems.
51 case KVersionControlPlugin::UpdateRequiredVersion
: tintColor
= Qt::yellow
; break;
52 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
: tintColor
= Qt::green
; break;
53 case KVersionControlPlugin::LocallyModifiedVersion
: tintColor
= Qt::green
; break;
54 case KVersionControlPlugin::AddedVersion
: tintColor
= Qt::green
; break;
55 case KVersionControlPlugin::RemovedVersion
: tintColor
= Qt::darkRed
; break;
56 case KVersionControlPlugin::ConflictingVersion
: tintColor
= Qt::red
; break;
57 case KVersionControlPlugin::IgnoredVersion
: tintColor
= Qt::white
; break;
58 case KVersionControlPlugin::MissingVersion
: tintColor
= Qt::red
; break;
59 case KVersionControlPlugin::NormalVersion
:
60 case KVersionControlPlugin::UnversionedVersion
:
65 color
= QColor((tintColor
.red() + textColor
.red()) / 2,
66 (tintColor
.green() + textColor
.green()) / 2,
67 (tintColor
.blue() + textColor
.blue()) / 2,
68 (tintColor
.alpha() + textColor
.alpha()) / 2);
70 setOverlay(overlayForState(version
, styleOption().iconSize
));
71 } else if (!overlay().isNull()) {
72 setOverlay(QPixmap());
78 QPixmap
DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::ItemVersion version
, int size
)
80 int overlayHeight
= KIconLoader::SizeSmall
;
81 if (size
>= KIconLoader::SizeEnormous
) {
82 overlayHeight
= KIconLoader::SizeMedium
;
83 } else if (size
>= KIconLoader::SizeLarge
) {
84 overlayHeight
= KIconLoader::SizeSmallMedium
;
85 } else if (size
>= KIconLoader::SizeMedium
) {
86 overlayHeight
= KIconLoader::SizeSmall
;
88 overlayHeight
= KIconLoader::SizeSmall
/ 2;
93 case KVersionControlPlugin::NormalVersion
:
94 iconName
= QStringLiteral("vcs-normal");
96 case KVersionControlPlugin::UpdateRequiredVersion
:
97 iconName
= QStringLiteral("vcs-update-required");
99 case KVersionControlPlugin::LocallyModifiedVersion
:
100 iconName
= QStringLiteral("vcs-locally-modified");
102 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
103 iconName
= QStringLiteral("vcs-locally-modified-unstaged");
105 case KVersionControlPlugin::AddedVersion
:
106 iconName
= QStringLiteral("vcs-added");
108 case KVersionControlPlugin::RemovedVersion
:
109 iconName
= QStringLiteral("vcs-removed");
111 case KVersionControlPlugin::ConflictingVersion
:
112 iconName
= QStringLiteral("vcs-conflicting");
114 case KVersionControlPlugin::UnversionedVersion
:
115 case KVersionControlPlugin::IgnoredVersion
:
116 case KVersionControlPlugin::MissingVersion
:
123 return QIcon::fromTheme(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
));