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>
28 DolphinFileItemListWidget::DolphinFileItemListWidget(QGraphicsItem
* parent
) :
29 KFileItemListWidget(parent
)
33 DolphinFileItemListWidget::~DolphinFileItemListWidget()
37 void DolphinFileItemListWidget::refreshCache()
40 const QHash
<QByteArray
, QVariant
> values
= data();
41 if (values
.contains("version")) {
42 // The item is under version control. Apply the text color corresponding
43 // to its version state.
44 const KVersionControlPlugin::VersionState version
= static_cast<KVersionControlPlugin::VersionState
>(values
.value("version").toInt());
45 const QColor textColor
= styleOption().palette
.text().color();
46 QColor tintColor
= textColor
;
48 // Using hardcoded colors is generally a bad idea. In this case the colors just act
49 // as tint colors and are mixed with the current set text color. The tint colors
50 // have been optimized for the base colors of the corresponding Oxygen emblems.
52 case KVersionControlPlugin::UpdateRequiredVersion
: tintColor
= Qt::yellow
; break;
53 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
: tintColor
= Qt::green
; break;
54 case KVersionControlPlugin::LocallyModifiedVersion
: tintColor
= Qt::green
; break;
55 case KVersionControlPlugin::AddedVersion
: tintColor
= Qt::green
; break;
56 case KVersionControlPlugin::RemovedVersion
: tintColor
= Qt::darkRed
; break;
57 case KVersionControlPlugin::ConflictingVersion
: tintColor
= Qt::red
; break;
58 case KVersionControlPlugin::UnversionedVersion
: tintColor
= Qt::white
; break;
59 case KVersionControlPlugin::NormalVersion
:
64 color
= QColor((tintColor
.red() + textColor
.red()) / 2,
65 (tintColor
.green() + textColor
.green()) / 2,
66 (tintColor
.blue() + textColor
.blue()) / 2,
67 (tintColor
.alpha() + textColor
.alpha()) / 2);
69 setOverlay(overlayForState(version
, styleOption().iconSize
));
70 } else if (!overlay().isNull()) {
71 setOverlay(QPixmap());
77 QPixmap
DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::VersionState version
, int size
)
79 int overlayHeight
= KIconLoader::SizeSmall
;
80 if (size
>= KIconLoader::SizeEnormous
) {
81 overlayHeight
= KIconLoader::SizeMedium
;
82 } else if (size
>= KIconLoader::SizeLarge
) {
83 overlayHeight
= KIconLoader::SizeSmallMedium
;
84 } else if (size
>= KIconLoader::SizeMedium
) {
85 overlayHeight
= KIconLoader::SizeSmall
;
87 overlayHeight
= KIconLoader::SizeSmall
/ 2;
92 case KVersionControlPlugin::NormalVersion
:
93 iconName
= "vcs-normal";
95 case KVersionControlPlugin::UpdateRequiredVersion
:
96 iconName
= "vcs-update-required";
98 case KVersionControlPlugin::LocallyModifiedVersion
:
99 iconName
= "vcs-locally-modified";
101 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
102 iconName
= "vcs-locally-modified-unstaged";
104 case KVersionControlPlugin::AddedVersion
:
105 iconName
= "vcs-added";
107 case KVersionControlPlugin::RemovedVersion
:
108 iconName
= "vcs-removed";
110 case KVersionControlPlugin::ConflictingVersion
:
111 iconName
= "vcs-conflicting";
113 case KVersionControlPlugin::UnversionedVersion
:
120 return KIcon(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
));
123 #include "dolphinfileitemlistwidget.moc"