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>
24 #include <kversioncontrolplugin2.h>
29 DolphinFileItemListWidget::DolphinFileItemListWidget(KItemListWidgetInformant
* informant
,
30 QGraphicsItem
* parent
) :
31 KFileItemListWidget(informant
, parent
)
35 DolphinFileItemListWidget::~DolphinFileItemListWidget()
39 void DolphinFileItemListWidget::refreshCache()
42 const QHash
<QByteArray
, QVariant
> values
= data();
43 if (values
.contains("version")) {
44 // The item is under version control. Apply the text color corresponding
45 // to its version state.
46 const KVersionControlPlugin2::ItemVersion version
= static_cast<KVersionControlPlugin2::ItemVersion
>(values
.value("version").toInt());
47 const QColor textColor
= styleOption().palette
.text().color();
48 QColor tintColor
= textColor
;
50 // Using hardcoded colors is generally a bad idea. In this case the colors just act
51 // as tint colors and are mixed with the current set text color. The tint colors
52 // have been optimized for the base colors of the corresponding Oxygen emblems.
54 case KVersionControlPlugin2::UpdateRequiredVersion
: tintColor
= Qt::yellow
; break;
55 case KVersionControlPlugin2::LocallyModifiedUnstagedVersion
: tintColor
= Qt::green
; break;
56 case KVersionControlPlugin2::LocallyModifiedVersion
: tintColor
= Qt::green
; break;
57 case KVersionControlPlugin2::AddedVersion
: tintColor
= Qt::green
; break;
58 case KVersionControlPlugin2::RemovedVersion
: tintColor
= Qt::darkRed
; break;
59 case KVersionControlPlugin2::ConflictingVersion
: tintColor
= Qt::red
; break;
60 case KVersionControlPlugin2::IgnoredVersion
: tintColor
= Qt::white
; break;
61 case KVersionControlPlugin2::MissingVersion
: tintColor
= Qt::red
; break;
62 case KVersionControlPlugin2::NormalVersion
:
63 case KVersionControlPlugin2::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(KVersionControlPlugin2::ItemVersion version
, int size
)
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
= "vcs-normal";
99 case KVersionControlPlugin::UpdateRequiredVersion
:
100 iconName
= "vcs-update-required";
102 case KVersionControlPlugin::LocallyModifiedVersion
:
103 iconName
= "vcs-locally-modified";
105 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
106 iconName
= "vcs-locally-modified-unstaged";
108 case KVersionControlPlugin::AddedVersion
:
109 iconName
= "vcs-added";
111 case KVersionControlPlugin::RemovedVersion
:
112 iconName
= "vcs-removed";
114 case KVersionControlPlugin::ConflictingVersion
:
115 iconName
= "vcs-conflicting";
117 case KVersionControlPlugin::UnversionedVersion
:
118 case KVersionControlPlugin2::IgnoredVersion
:
119 case KVersionControlPlugin2::MissingVersion
:
126 return QIcon::fromTheme(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
));