~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/widgets/groupediconview.h

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
4
   Clementine 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 3 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   Clementine 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 Clementine.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef GROUPEDICONVIEW_H
 
19
#define GROUPEDICONVIEW_H
 
20
 
 
21
#include <QListView>
 
22
 
 
23
class MultiSortFilterProxy;
 
24
 
 
25
 
 
26
class GroupedIconView : public QListView {
 
27
  Q_OBJECT
 
28
 
 
29
  // Vertical space separating a header from the items above and below it.
 
30
  Q_PROPERTY(int header_spacing READ header_spacing WRITE set_header_spacing)
 
31
 
 
32
  // Horizontal space separating a header from the left and right edges of the widget.
 
33
  Q_PROPERTY(int header_indent READ header_indent WRITE set_header_indent)
 
34
 
 
35
  // Horizontal space separating an item from the left and right edges of the widget.
 
36
  Q_PROPERTY(int item_indent READ item_indent WRITE set_item_indent)
 
37
 
 
38
  // The text of each group's header.  Must contain "%1".
 
39
  Q_PROPERTY(QString header_text READ header_text WRITE set_header_text);
 
40
 
 
41
public:
 
42
  GroupedIconView(QWidget* parent = 0);
 
43
 
 
44
  enum Role {
 
45
    Role_Group = 1158300,
 
46
  };
 
47
 
 
48
  void AddSortSpec(int role, Qt::SortOrder order = Qt::AscendingOrder);
 
49
 
 
50
  int header_spacing() const { return header_spacing_; }
 
51
  int header_indent() const { return header_indent_; }
 
52
  int item_indent() const { return item_indent_; }
 
53
  const QString& header_text() const { return header_text_;}
 
54
 
 
55
  void set_header_spacing(int value) { header_spacing_ = value; }
 
56
  void set_header_indent(int value) { header_indent_ = value; }
 
57
  void set_item_indent(int value) { item_indent_ = value; }
 
58
  void set_header_text(const QString& value) { header_text_ = value; }
 
59
 
 
60
  // QAbstractItemView
 
61
  QModelIndex moveCursor(CursorAction action, Qt::KeyboardModifiers modifiers);
 
62
  void setModel(QAbstractItemModel* model);
 
63
 
 
64
  static void DrawHeader(QPainter* painter, const QRect& rect,
 
65
                         const QFont& font, const QPalette& palette,
 
66
                         const QString& text);
 
67
 
 
68
protected:
 
69
  virtual int header_height() const;
 
70
 
 
71
  // QWidget
 
72
  void paintEvent(QPaintEvent* e);
 
73
  void resizeEvent(QResizeEvent* e);
 
74
 
 
75
  // QAbstractItemView
 
76
  void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
 
77
  QModelIndex indexAt(const QPoint& p) const;
 
78
  void rowsInserted(const QModelIndex& parent, int start, int end);
 
79
  void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
 
80
  QRect visualRect(const QModelIndex& index) const;
 
81
  QRegion visualRegionForSelection(const QItemSelection& selection) const;
 
82
 
 
83
private slots:
 
84
  void LayoutItems();
 
85
 
 
86
private:
 
87
  static const int kBarThickness;
 
88
  static const int kBarMarginTop;
 
89
 
 
90
  struct Header {
 
91
    int y;
 
92
    int first_row;
 
93
    QString text;
 
94
  };
 
95
 
 
96
  // Returns the items that are wholly or partially inside the rect.
 
97
  QVector<QModelIndex> IntersectingItems(const QRect& rect) const;
 
98
 
 
99
  // Returns the index of the item above (d=-1) or below (d=+1) the given item.
 
100
  int IndexAboveOrBelow(int index, int d) const;
 
101
 
 
102
  MultiSortFilterProxy* proxy_model_;
 
103
  QVector<QRect> visual_rects_;
 
104
  QVector<Header> headers_;
 
105
 
 
106
  const int default_header_height_;
 
107
  int header_spacing_;
 
108
  int header_indent_;
 
109
  int item_indent_;
 
110
  QString header_text_;
 
111
};
 
112
 
 
113
#endif // GROUPEDICONVIEW_H