]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinfileitemlistwidget.cpp
Version control: Apply text-color if an item is versioned
[dolphin.git] / src / views / dolphinfileitemlistwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "dolphinfileitemlistwidget.h"
21
22 #include <kversioncontrolplugin.h>
23 #include <QColor>
24
25 #include <KDebug>
26
27 DolphinFileItemListWidget::DolphinFileItemListWidget(QGraphicsItem* parent) :
28 KFileItemListWidget(parent)
29 {
30 }
31
32 DolphinFileItemListWidget::~DolphinFileItemListWidget()
33 {
34 }
35
36 void DolphinFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles)
37 {
38 KFileItemListWidget::dataChanged(current, roles);
39
40 QColor color;
41 if (roles.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>(current.value("version").toInt());
45 if (version != KVersionControlPlugin::UnversionedVersion) {
46 const QColor textColor = styleOption().palette.text().color();
47 QColor tintColor = textColor;
48
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.
52 switch (version) {
53 case KVersionControlPlugin::UpdateRequiredVersion: tintColor = Qt::yellow; break;
54 case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::darkGreen; 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::UnversionedVersion:
60 case KVersionControlPlugin::NormalVersion:
61 default:
62 // use the default text color
63 return;
64 }
65
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);
70 }
71 }
72
73 setTextColor(color);
74 }
75
76 #include "dolphinfileitemlistwidget.moc"