2011-06-25 18:47:00 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GROUPEDICONVIEW_H
|
|
|
|
#define GROUPEDICONVIEW_H
|
|
|
|
|
|
|
|
#include <QListView>
|
|
|
|
|
2011-07-26 13:17:28 +02:00
|
|
|
class MultiSortFilterProxy;
|
2011-06-25 18:47:00 +02:00
|
|
|
|
|
|
|
class GroupedIconView : public QListView {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
// Vertical space separating a header from the items above and below it.
|
|
|
|
Q_PROPERTY(int header_spacing READ header_spacing WRITE set_header_spacing)
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Horizontal space separating a header from the left and right edges of the
|
|
|
|
// widget.
|
2011-06-25 18:47:00 +02:00
|
|
|
Q_PROPERTY(int header_indent READ header_indent WRITE set_header_indent)
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Horizontal space separating an item from the left and right edges of the
|
|
|
|
// widget.
|
2011-06-25 18:47:00 +02:00
|
|
|
Q_PROPERTY(int item_indent READ item_indent WRITE set_item_indent)
|
|
|
|
|
|
|
|
// The text of each group's header. Must contain "%1".
|
|
|
|
Q_PROPERTY(QString header_text READ header_text WRITE set_header_text);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
GroupedIconView(QWidget* parent = nullptr);
|
2011-06-25 18:47:00 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
enum Role { Role_Group = 1158300, };
|
2011-06-25 18:47:00 +02:00
|
|
|
|
2011-07-26 13:17:28 +02:00
|
|
|
void AddSortSpec(int role, Qt::SortOrder order = Qt::AscendingOrder);
|
|
|
|
|
2011-06-25 18:47:00 +02:00
|
|
|
int header_spacing() const { return header_spacing_; }
|
|
|
|
int header_indent() const { return header_indent_; }
|
|
|
|
int item_indent() const { return item_indent_; }
|
2014-02-07 16:34:20 +01:00
|
|
|
const QString& header_text() const { return header_text_; }
|
2011-06-25 18:47:00 +02:00
|
|
|
|
|
|
|
void set_header_spacing(int value) { header_spacing_ = value; }
|
|
|
|
void set_header_indent(int value) { header_indent_ = value; }
|
|
|
|
void set_item_indent(int value) { item_indent_ = value; }
|
|
|
|
void set_header_text(const QString& value) { header_text_ = value; }
|
|
|
|
|
|
|
|
// QAbstractItemView
|
|
|
|
QModelIndex moveCursor(CursorAction action, Qt::KeyboardModifiers modifiers);
|
|
|
|
void setModel(QAbstractItemModel* model);
|
|
|
|
|
2011-10-30 17:51:43 +01:00
|
|
|
static void DrawHeader(QPainter* painter, const QRect& rect,
|
|
|
|
const QFont& font, const QPalette& palette,
|
|
|
|
const QString& text);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2011-06-25 18:47:00 +02:00
|
|
|
virtual int header_height() const;
|
|
|
|
|
|
|
|
// QWidget
|
|
|
|
void paintEvent(QPaintEvent* e);
|
|
|
|
void resizeEvent(QResizeEvent* e);
|
|
|
|
|
|
|
|
// QAbstractItemView
|
2011-06-26 17:06:59 +02:00
|
|
|
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
2011-06-25 18:47:00 +02:00
|
|
|
QModelIndex indexAt(const QPoint& p) const;
|
|
|
|
void rowsInserted(const QModelIndex& parent, int start, int end);
|
2014-02-07 16:34:20 +01:00
|
|
|
void setSelection(const QRect& rect,
|
|
|
|
QItemSelectionModel::SelectionFlags command);
|
2011-06-25 18:47:00 +02:00
|
|
|
QRect visualRect(const QModelIndex& index) const;
|
|
|
|
QRegion visualRegionForSelection(const QItemSelection& selection) const;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2011-06-25 18:47:00 +02:00
|
|
|
void LayoutItems();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-06-25 18:47:00 +02:00
|
|
|
static const int kBarThickness;
|
|
|
|
static const int kBarMarginTop;
|
|
|
|
|
|
|
|
struct Header {
|
|
|
|
int y;
|
|
|
|
int first_row;
|
|
|
|
QString text;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Returns the items that are wholly or partially inside the rect.
|
|
|
|
QVector<QModelIndex> IntersectingItems(const QRect& rect) const;
|
|
|
|
|
|
|
|
// Returns the index of the item above (d=-1) or below (d=+1) the given item.
|
|
|
|
int IndexAboveOrBelow(int index, int d) const;
|
|
|
|
|
2011-07-26 13:17:28 +02:00
|
|
|
MultiSortFilterProxy* proxy_model_;
|
2011-06-25 18:47:00 +02:00
|
|
|
QVector<QRect> visual_rects_;
|
|
|
|
QVector<Header> headers_;
|
|
|
|
|
|
|
|
const int default_header_height_;
|
|
|
|
int header_spacing_;
|
|
|
|
int header_indent_;
|
|
|
|
int item_indent_;
|
|
|
|
QString header_text_;
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // GROUPEDICONVIEW_H
|