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"
23 #include <KIconLoader>
26 #include "dolphindebug.h"
28 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant
* informant
,
29 QGraphicsItem
* parent
) :
30 KFileItemListWidget(informant
, parent
)
34 DolphinFileItemListWidget::~DolphinFileItemListWidget()
38 void DolphinFileItemListWidget::refreshCache()
41 const QHash
<QByteArray
, QVariant
> values
= data();
42 if (values
.contains("version")) {
43 // The item is under version control. Apply the text color corresponding
44 // to its version state.
45 const KVersionControlPlugin::ItemVersion version
= static_cast<KVersionControlPlugin::ItemVersion
>(values
.value("version").toInt());
46 const QColor textColor
= styleOption().palette
.text().color();
47 QColor tintColor
= textColor
;
49 // Using hardcoded colors is generally a bad idea. In this case the colors just act
50 // as tint colors and are mixed with the current set text color. The tint colors
51 // have been optimized for the base colors of the corresponding Oxygen emblems.
53 case KVersionControlPlugin::UpdateRequiredVersion
: tintColor
= Qt::yellow
; break;
54 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
: tintColor
= Qt::green
; break;
55 case KVersionControlPlugin::LocallyModifiedVersion
: tintColor
= Qt::green
; break;
56 case KVersionControlPlugin::AddedVersion
: tintColor
= Qt::green
; break;
57 case KVersionControlPlugin::RemovedVersion
: tintColor
= Qt::darkRed
; break;
58 case KVersionControlPlugin::ConflictingVersion
: tintColor
= Qt::red
; break;
59 case KVersionControlPlugin::IgnoredVersion
: tintColor
= Qt::white
; break;
60 case KVersionControlPlugin::MissingVersion
: tintColor
= Qt::red
; break;
61 case KVersionControlPlugin::NormalVersion
:
62 case KVersionControlPlugin::UnversionedVersion
:
67 color
= QColor((tintColor
.red() + textColor
.red()) / 2,
68 (tintColor
.green() + textColor
.green()) / 2,
69 (tintColor
.blue() + textColor
.blue()) / 2,
70 (tintColor
.alpha() + textColor
.alpha()) / 2);
72 setOverlay(overlayForState(version
, styleOption().iconSize
));
73 } else if (!overlay().isNull()) {
74 setOverlay(QPixmap());
80 QPixmap
DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::ItemVersion version
, int size
)
82 int overlayHeight
= KIconLoader::SizeSmall
;
83 if (size
>= KIconLoader::SizeEnormous
) {
84 overlayHeight
= KIconLoader::SizeMedium
;
85 } else if (size
>= KIconLoader::SizeLarge
) {
86 overlayHeight
= KIconLoader::SizeSmallMedium
;
87 } else if (size
>= KIconLoader::SizeMedium
) {
88 overlayHeight
= KIconLoader::SizeSmall
;
90 overlayHeight
= KIconLoader::SizeSmall
/ 2;
95 case KVersionControlPlugin::NormalVersion
:
96 iconName
= QStringLiteral("vcs-normal");
98 case KVersionControlPlugin::UpdateRequiredVersion
:
99 iconName
= QStringLiteral("vcs-update-required");
101 case KVersionControlPlugin::LocallyModifiedVersion
:
102 iconName
= QStringLiteral("vcs-locally-modified");
104 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
105 iconName
= QStringLiteral("vcs-locally-modified-unstaged");
107 case KVersionControlPlugin::AddedVersion
:
108 iconName
= QStringLiteral("vcs-added");
110 case KVersionControlPlugin::RemovedVersion
:
111 iconName
= QStringLiteral("vcs-removed");
113 case KVersionControlPlugin::ConflictingVersion
:
114 iconName
= QStringLiteral("vcs-conflicting");
116 case KVersionControlPlugin::UnversionedVersion
:
117 case KVersionControlPlugin::IgnoredVersion
:
118 case KVersionControlPlugin::MissingVersion
:
125 return QIcon::fromTheme(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
));