~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/widgets/common/kcategorizedview_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2010-04-09 21:30:01 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409213001-4bfyibrd359rn7o3
Tags: 2:1.2.0-0ubuntu1
* New upstream release (LP: #560576)
* Remove all patches, fixed upstream
  - Remove quilt build-depend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
  * This file is part of the KDE project
 
3
  * Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
 
4
  *
 
5
  * This library is free software; you can redistribute it and/or
 
6
  * modify it under the terms of the GNU Library General Public
 
7
  * License as published by the Free Software Foundation; either
 
8
  * version 2 of the License, or (at your option) any later version.
 
9
  *
 
10
  * This library is distributed in the hope that it will be useful,
 
11
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
  * Library General Public License for more details.
 
14
  *
 
15
  * You should have received a copy of the GNU Library General Public License
 
16
  * along with this library; see the file COPYING.LIB.  If not, write to
 
17
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
  * Boston, MA 02110-1301, USA.
 
19
  */
 
20
 
 
21
#ifndef KCATEGORIZEDVIEW_P_H
 
22
#define KCATEGORIZEDVIEW_P_H
 
23
 
 
24
class KCategorizedSortFilterProxyModel;
 
25
class KCategoryDrawer;
 
26
 
 
27
/**
 
28
  * @internal
 
29
  */
 
30
class KCategorizedView::Private
 
31
{
 
32
public:
 
33
    Private(KCategorizedView *listView);
 
34
    ~Private();
 
35
 
 
36
 
 
37
    // Methods
 
38
 
 
39
    /**
 
40
      * Returns the list of items that intersects with @p rect
 
41
      */
 
42
    const QModelIndexList &intersectionSet(const QRect &rect);
 
43
 
 
44
    /**
 
45
      * Gets the item rect in the viewport for @p index
 
46
      */
 
47
    QRect visualRectInViewport(const QModelIndex &index) const;
 
48
 
 
49
    /**
 
50
      * Returns the category rect in the viewport for @p category
 
51
      */
 
52
    QRect visualCategoryRectInViewport(const QString &category) const;
 
53
 
 
54
    /**
 
55
      * Caches and returns the rect that corresponds to @p index
 
56
      */
 
57
    const QRect &cacheIndex(const QModelIndex &index);
 
58
 
 
59
    /**
 
60
      * Caches and returns the rect that corresponds to @p category
 
61
      */
 
62
    const QRect &cacheCategory(const QString &category);
 
63
 
 
64
    /**
 
65
      * Returns the rect that corresponds to @p index
 
66
      * @note If the rect is not cached, it becomes cached
 
67
      */
 
68
    const QRect &cachedRectIndex(const QModelIndex &index);
 
69
 
 
70
    /**
 
71
      * Returns the rect that corresponds to @p category
 
72
      * @note If the rect is not cached, it becomes cached
 
73
      */
 
74
    const QRect &cachedRectCategory(const QString &category);
 
75
 
 
76
    /**
 
77
      * Returns the visual rect (taking in count x and y offsets) for @p index
 
78
      * @note If the rect is not cached, it becomes cached
 
79
      */
 
80
    QRect visualRect(const QModelIndex &index);
 
81
 
 
82
    /**
 
83
      * Returns the visual rect (taking in count x and y offsets) for @p category
 
84
      * @note If the rect is not cached, it becomes cached
 
85
      */
 
86
    QRect categoryVisualRect(const QString &category);
 
87
 
 
88
    /**
 
89
      * Returns the contents size of this view (topmost category to bottommost index + spacing)
 
90
      */
 
91
    QSize contentsSize();
 
92
 
 
93
    /**
 
94
      * This method will draw a new category represented by index
 
95
      * @p index on the rect specified by @p option.rect, with
 
96
      * painter @p painter
 
97
      */
 
98
    void drawNewCategory(const QModelIndex &index,
 
99
                         int sortRole,
 
100
                         const QStyleOption &option,
 
101
                         QPainter *painter);
 
102
 
 
103
    /**
 
104
      * This method will update scrollbars ranges. Called when our model changes
 
105
      * or when the view is resized
 
106
      */
 
107
    void updateScrollbars();
 
108
 
 
109
    /**
 
110
      * This method will draw dragged items in the painting operation
 
111
      */
 
112
    void drawDraggedItems(QPainter *painter);
 
113
 
 
114
    /**
 
115
      * This method will determine which rect needs to be updated because of a
 
116
      * dragging operation
 
117
      */
 
118
    void drawDraggedItems();
 
119
 
 
120
    /**
 
121
      * This method will, starting from the index at begin in the given (sorted) modelIndex List,
 
122
      * find the last index having the same category as the index to begin with.
 
123
      */
 
124
    int categoryUpperBound(const QVector<QModelIndex> &modelIndexList, int begin, int averageSize = 0);
 
125
 
 
126
    /**
 
127
      * Returns a QItemSelection for all items intersection rect.
 
128
      */
 
129
    QItemSelection selectionForRect(const QRect &rect);
 
130
 
 
131
    // Attributes
 
132
 
 
133
    struct ElementInfo
 
134
    {
 
135
        QString category;
 
136
        int     relativeOffsetToCategory;
 
137
    };
 
138
 
 
139
    // Basic data
 
140
    KCategorizedView* listView;
 
141
    KCategoryDrawer*  categoryDrawer;
 
142
    QSize             biggestItemSize;
 
143
 
 
144
    // Behavior data
 
145
    bool        mouseButtonPressed;
 
146
    bool        rightMouseButtonPressed;
 
147
    bool        dragLeftViewport;
 
148
    bool        drawItemsWhileDragging;
 
149
    QModelIndex hovered;
 
150
    QString     hoveredCategory;
 
151
    QPoint      initialPressPosition;
 
152
    QPoint      mousePosition;
 
153
    int         forcedSelectionPosition;
 
154
 
 
155
    // Cache data
 
156
    // We cannot merge some of them into structs because it would affect
 
157
    // performance
 
158
    QVector<struct ElementInfo>   elementsInfo;
 
159
    QHash<int, QRect>             elementsPosition;
 
160
    QHash<QString, QVector<int> > categoriesIndexes;
 
161
    QHash<QString, QRect>         categoriesPosition;
 
162
    QStringList                   categories;
 
163
    QModelIndexList               intersectedIndexes;
 
164
    QRect                         lastDraggedItemsRect;
 
165
    QItemSelection                lastSelection;
 
166
 
 
167
    // Attributes for speed reasons
 
168
    KCategorizedSortFilterProxyModel* proxyModel;
 
169
};
 
170
 
 
171
#endif // KCATEGORIZEDVIEW_P_H