┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views/dolphinfileitemdelegate.h
blob: 405f24916f2743f01aae7e6ba100aeadc30e3dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/***************************************************************************
 *   Copyright (C) 2008 by Peter Penz <[email protected]>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

#ifndef DOLPHINFILEITEMDELEGATE_H
#define DOLPHINFILEITEMDELEGATE_H

#include <dolphinmodel.h>
#include <kfileitemdelegate.h>

class QAbstractProxyModel;

/**
 * Extends KFileItemDelegate by the ability to show the hover effect
 * and the selection in a minimized way for the name column of
 * the details view.
 *
 * Note that this is a workaround, as Qt does not support having custom
 * shapes within the visual rect of an item view. The visual part of
 * workaround is handled inside DolphinFileItemDelegate, the behavior
 * changes are handled in DolphinDetailsView.
 */
class DolphinFileItemDelegate : public KFileItemDelegate
{
public:
    explicit DolphinFileItemDelegate(QObject* parent = 0);
    virtual ~DolphinFileItemDelegate();

    /**
     * If \a minimized is true, the hover effect and the selection are
     * only drawn above the icon and text of an item. Per default
     * \a minimized is false, which means that the whole visual rect is
     * used like in KFileItemDelegate.
     */
    void setMinimizedNameColumn(bool minimized);
    bool hasMinimizedNameColumn() const;

    virtual void paint(QPainter* painter,
                       const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;

    /**
     * Returns the minimized width of the name column for the name \a name. This method
     * is also used in DolphinDetailsView to handle the selection of items correctly.
     */
    static int nameColumnWidth(const QString& name, const QStyleOptionViewItem& option);

private:
    static void adjustOptionWidth(QStyleOptionViewItemV4& option,
                                  const QAbstractProxyModel* proxyModel,
                                  const DolphinModel* dolphinModel,
                                  const QModelIndex& index);

    static void adjustOptionTextColor(QStyleOptionViewItemV4& option,
                                      KVersionControlPlugin::VersionState state);

    QPixmap emblemForState(KVersionControlPlugin::VersionState state, const QSize& size) const;

private:
    bool m_hasMinimizedNameColumn;
    mutable QSize m_cachedSize;
    mutable QPixmap m_cachedEmblems[KVersionControlPlugin::ConflictingVersion + 1];
};

inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized)
{
    m_hasMinimizedNameColumn = minimized;
}

inline bool DolphinFileItemDelegate::hasMinimizedNameColumn() const
{
    return m_hasMinimizedNameColumn;
}

#endif