┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/klistview_p.h
blob: c0a4289a81e21d35ca82b34fd67b8091aa74eecd (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
  * This file is part of the KDE project
  * Copyright (C) 2007 Rafael Fernández López <[email protected]>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library 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
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  */

#ifndef KLISTVIEW_P_H
#define KLISTVIEW_P_H

class KSortFilterProxyModel;

/**
  * @internal
  */
class KListView::Private
{
public:
    Private(KListView *listView);
    ~Private();


    // Methods

    /**
      * Returns the list of items that intersects with @p rect
      */
    const QModelIndexList &intersectionSet(const QRect &rect);

    /**
      * Gets the item rect in the viewport for @p index
      */
    QRect visualRectInViewport(const QModelIndex &index) const;

    /**
      * Returns the category rect in the viewport for @p category
      */
    QRect visualCategoryRectInViewport(const QString &category) const;

    /**
      * Caches and returns the rect that corresponds to @p index
      */
    const QRect &cacheIndex(const QModelIndex &index);

    /**
      * Caches and returns the rect that corresponds to @p category
      */
    const QRect &cacheCategory(const QString &category);

    /**
      * Returns the rect that corresponds to @p index
      * @note If the rect is not cached, it becomes cached
      */
    const QRect &cachedRectIndex(const QModelIndex &index);

    /**
      * Returns the rect that corresponds to @p category
      * @note If the rect is not cached, it becomes cached
      */
    const QRect &cachedRectCategory(const QString &category);

    /**
      * Returns the visual rect (taking in count x and y offsets) for @p index
      * @note If the rect is not cached, it becomes cached
      */
    QRect visualRect(const QModelIndex &index);

    /**
      * Returns the visual rect (taking in count x and y offsets) for @p category
      * @note If the rect is not cached, it becomes cached
      */
    QRect categoryVisualRect(const QString &category);

    /**
      * This method will draw a new category with name @p category on the rect
      * specified by @p option.rect, with painter @p painter
      */
    void drawNewCategory(const QString &category,
                         const QStyleOption &option,
                         QPainter *painter);

    /**
      * This method will update scrollbars ranges. Called when our model changes
      * or when the view is resized
      */
    void updateScrollbars();

    /**
      * This method will draw dragged items
      */
    void drawDraggedItems(QPainter *painter);


    // Attributes

    struct ElementInfo
    {
        QString category;
        int relativeOffsetToCategory;
    };

    // Basic data
    KListView *listView;
    KItemCategorizer *itemCategorizer;

    // Behavior data
    bool mouseButtonPressed;
    bool isDragging;
    bool dragLeftViewport;
    QModelIndex hovered;
    QPoint initialPressPosition;
    QPoint mousePosition;
    QItemSelection lastSelection;

    // Cache data
    // We cannot merge some of them into structs because it would affect
    // performance
    QHash<QModelIndex, struct ElementInfo> elementsInfo; // in source model
    QHash<QModelIndex, QRect> elementsPosition;          // in source model
    QHash<QModelIndex, QModelIndex> elementDictionary;   // mapped indexes
    QHash<QString, QModelIndexList> categoriesIndexes;
    QHash<QString, QRect> categoriesPosition;
    QStringList categories;
    QModelIndexList intersectedIndexes;

    // Attributes for speed reasons
    KSortFilterProxyModel *proxyModel;
    QModelIndexList sourceModelIndexList;                // in source model
    QModelIndex lastIndex;
};

#endif // KLISTVIEW_P_H