~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to apps/dolphin/src/dolphinfileitemdelegate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-12-19 18:29:39 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20091219182939-i4q5c16348k7vxuk
Tags: 4:4.3.85-0ubuntu1
* New upstream release
  - Bump build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(proxyModel->sourceModel());
52
52
    const bool isNameColumn = (index.column() == KDirModel::Name);
53
53
 
 
54
    QStyleOptionViewItemV4 opt(option);
54
55
    if (m_hasMinimizedNameColumn && isNameColumn) {
55
 
        QStyleOptionViewItemV4 opt(option);
56
56
        adjustOptionWidth(opt, proxyModel, dolphinModel, index);
57
 
        KFileItemDelegate::paint(painter, opt, index);
58
 
    } else {
59
 
        KFileItemDelegate::paint(painter, option, index);
60
57
    }
61
58
 
62
59
    if (dolphinModel->hasVersionData() && isNameColumn) {
63
60
        // The currently shown items are under revision control. Show the current revision
64
 
        // state by adding an emblem.
 
61
        // state by adding an emblem and changing the text tintColor.
65
62
        const QModelIndex dirIndex = proxyModel->mapToSource(index);
66
63
        const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Version, dirIndex.parent());
67
64
        const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole);
68
65
        const KVersionControlPlugin::VersionState state = static_cast<KVersionControlPlugin::VersionState>(data.toInt());
69
66
 
 
67
        adjustOptionTextColor(opt, state);
 
68
 
 
69
        KFileItemDelegate::paint(painter, opt, index);
 
70
 
70
71
        if (state != KVersionControlPlugin::UnversionedVersion) {
71
72
            const QRect rect = iconRect(option, index);
72
73
            const QPixmap emblem = emblemForState(state, rect.size());
73
74
            painter->drawPixmap(rect.x(), rect.y() + rect.height() - emblem.height(), emblem);
74
75
        }
 
76
    } else {
 
77
        KFileItemDelegate::paint(painter, opt, index);
75
78
    }
76
79
}
77
80
 
105
108
    }
106
109
}
107
110
 
 
111
void DolphinFileItemDelegate::adjustOptionTextColor(QStyleOptionViewItemV4& option,
 
112
                                                    KVersionControlPlugin::VersionState state)
 
113
{
 
114
    QColor tintColor;
 
115
 
 
116
    // Using hardcoded colors is generally a bad idea. In this case the colors just act
 
117
    // as tint colors and are mixed with the current set text color. The tint colors
 
118
    // have been optimized for the base colors of the corresponding Oxygen emblems.
 
119
    switch (state) {
 
120
    case KVersionControlPlugin::UpdateRequiredVersion:  tintColor = Qt::yellow; break;
 
121
    case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break;
 
122
    case KVersionControlPlugin::AddedVersion:           tintColor = Qt::darkGreen; break;
 
123
    case KVersionControlPlugin::RemovedVersion:         tintColor = Qt::darkRed; break;
 
124
    case KVersionControlPlugin::ConflictingVersion:     tintColor = Qt::red; break;
 
125
    case KVersionControlPlugin::UnversionedVersion:
 
126
    case KVersionControlPlugin::NormalVersion:
 
127
    default:
 
128
        // use the default text color
 
129
        return;
 
130
    }
 
131
 
 
132
    QPalette palette = option.palette;
 
133
    const QColor textColor = palette.color(QPalette::Text);
 
134
    tintColor = QColor((tintColor.red()   + textColor.red())   / 2,
 
135
                       (tintColor.green() + textColor.green()) / 2,
 
136
                       (tintColor.blue()  + textColor.blue())  / 2,
 
137
                       (tintColor.alpha() + textColor.alpha()) / 2);
 
138
    palette.setColor(QPalette::Text, tintColor);
 
139
    option.palette = palette;
 
140
}
 
141
 
108
142
QPixmap DolphinFileItemDelegate::emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const
109
143
{
110
 
    // TODO: all icons that are use here will be replaced by revision control emblems provided by the
111
 
    // Oxygen team before KDE 4.4
112
144
    Q_ASSERT(state <= KVersionControlPlugin::ConflictingVersion);
113
 
    if ((m_cachedSize != size) || !m_cachedEmblems[state].isNull()) {
 
145
    if (m_cachedSize != size) {
114
146
        m_cachedSize = size;
115
147
 
116
148
        const int iconHeight = size.height();
126
158
        }
127
159
 
128
160
        const QSize emblemSize(emblemHeight, emblemHeight);
129
 
        for (int i = 0; i <= KVersionControlPlugin::ConflictingVersion; ++i) {
 
161
        for (int i = KVersionControlPlugin::NormalVersion; i <= KVersionControlPlugin::ConflictingVersion; ++i) {
130
162
            QString iconName;
131
 
            switch (state) {
 
163
            switch (i) {
132
164
            case KVersionControlPlugin::NormalVersion:          iconName = "vcs-normal"; break;
133
165
            case KVersionControlPlugin::UpdateRequiredVersion:  iconName = "vcs-update-required"; break;
134
166
            case KVersionControlPlugin::LocallyModifiedVersion: iconName = "vcs-locally-modified"; break;
135
167
            case KVersionControlPlugin::AddedVersion:           iconName = "vcs-added"; break;
 
168
            case KVersionControlPlugin::RemovedVersion:         iconName = "vcs-removed"; break;
136
169
            case KVersionControlPlugin::ConflictingVersion:     iconName = "vcs-conflicting"; break;
137
 
            default: Q_ASSERT(false); break;
 
170
            case KVersionControlPlugin::UnversionedVersion:
 
171
            default:                                            Q_ASSERT(false); break;
138
172
            }
139
173
 
140
174
            m_cachedEmblems[i] = KIcon(iconName).pixmap(emblemSize);