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::dataChanged(const QHash
<QByteArray
, QVariant
>& current
, const QSet
<QByteArray
>& roles
)
39 KFileItemListWidget::dataChanged(current
, roles
);
43 if (roles
.contains("version")) {
44 // The item is under version control. Apply the text color corresponding
45 // to its version state.
46 const KVersionControlPlugin::VersionState version
= static_cast<KVersionControlPlugin::VersionState
>(current
.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 KVersionControlPlugin::UpdateRequiredVersion
: tintColor
= Qt::yellow
; break;
55 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
: tintColor
= Qt::green
; break;
56 case KVersionControlPlugin::LocallyModifiedVersion
: tintColor
= Qt::green
; break;
57 case KVersionControlPlugin::AddedVersion
: tintColor
= Qt::green
; break;
58 case KVersionControlPlugin::RemovedVersion
: tintColor
= Qt::darkRed
; break;
59 case KVersionControlPlugin::ConflictingVersion
: tintColor
= Qt::red
; break;
60 case KVersionControlPlugin::UnversionedVersion
: tintColor
= Qt::white
; break;
61 case KVersionControlPlugin::NormalVersion
:
66 color
= QColor((tintColor
.red() + textColor
.red()) / 2,
67 (tintColor
.green() + textColor
.green()) / 2,
68 (tintColor
.blue() + textColor
.blue()) / 2,
69 (tintColor
.alpha() + textColor
.alpha()) / 2);
71 overlay
= overlayForState(version
, styleOption().iconSize
);
78 void DolphinFileItemListWidget::styleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
)
80 KFileItemListWidget::styleOptionChanged(current
, previous
);
82 if (!overlay().isNull() && current
.iconSize
!= previous
.iconSize
) {
83 const KVersionControlPlugin::VersionState version
= static_cast<KVersionControlPlugin::VersionState
>(data().value("version").toInt());
84 const QPixmap newOverlay
= overlayForState(version
, current
.iconSize
);
85 setOverlay(newOverlay
);
89 QPixmap
DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::VersionState version
, int size
)
91 int overlayHeight
= KIconLoader::SizeSmall
;
92 if (size
>= KIconLoader::SizeEnormous
) {
93 overlayHeight
= KIconLoader::SizeMedium
;
94 } else if (size
>= KIconLoader::SizeLarge
) {
95 overlayHeight
= KIconLoader::SizeSmallMedium
;
96 } else if (size
>= KIconLoader::SizeMedium
) {
97 overlayHeight
= KIconLoader::SizeSmall
;
99 overlayHeight
= KIconLoader::SizeSmall
/ 2;
104 case KVersionControlPlugin::NormalVersion
:
105 iconName
= "vcs-normal";
107 case KVersionControlPlugin::UpdateRequiredVersion
:
108 iconName
= "vcs-update-required";
110 case KVersionControlPlugin::LocallyModifiedVersion
:
111 iconName
= "vcs-locally-modified";
113 case KVersionControlPlugin::LocallyModifiedUnstagedVersion
:
114 iconName
= "vcs-locally-modified-unstaged";
116 case KVersionControlPlugin::AddedVersion
:
117 iconName
= "vcs-added";
119 case KVersionControlPlugin::RemovedVersion
:
120 iconName
= "vcs-removed";
122 case KVersionControlPlugin::ConflictingVersion
:
123 iconName
= "vcs-conflicting";
125 case KVersionControlPlugin::UnversionedVersion
:
132 return KIcon(iconName
).pixmap(QSize(overlayHeight
, overlayHeight
));
135 #include "dolphinfileitemlistwidget.moc"