2014-02-01 03:21:45 +05:30
|
|
|
#pragma once
|
2013-12-24 16:17:30 +05:30
|
|
|
|
|
|
|
#include <QListView>
|
|
|
|
#include <QLineEdit>
|
2014-02-02 18:57:43 +05:30
|
|
|
#include <QScrollBar>
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2013-12-31 04:09:10 +05:30
|
|
|
struct CategorizedViewRoles
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CategoryRole = Qt::UserRole,
|
|
|
|
ProgressValueRole,
|
|
|
|
ProgressMaximumRole
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-02-01 03:21:45 +05:30
|
|
|
struct Group;
|
2013-12-31 21:56:36 +05:30
|
|
|
|
2014-02-02 14:56:38 +05:30
|
|
|
class GroupView : public QAbstractItemView
|
2013-12-24 16:17:30 +05:30
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2014-02-01 03:21:45 +05:30
|
|
|
GroupView(QWidget *parent = 0);
|
|
|
|
~GroupView();
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2014-02-02 18:57:43 +05:30
|
|
|
virtual QRect geometryRect(const QModelIndex &index) const;
|
|
|
|
virtual QRect visualRect(const QModelIndex &index) const override;
|
2013-12-27 01:46:03 +05:30
|
|
|
QModelIndex indexAt(const QPoint &point) const;
|
2014-02-01 03:21:45 +05:30
|
|
|
void setSelection(const QRect &rect,
|
|
|
|
const QItemSelectionModel::SelectionFlags commands) override;
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2014-02-02 14:56:38 +05:30
|
|
|
/*
|
|
|
|
* BS
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual int horizontalOffset() const override
|
|
|
|
{
|
2014-02-02 18:57:43 +05:30
|
|
|
return horizontalScrollBar()->value();
|
2014-02-02 14:56:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual int verticalOffset() const override
|
|
|
|
{
|
2014-02-02 18:57:43 +05:30
|
|
|
return verticalScrollBar()->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void scrollContentsBy(int dx, int dy) override
|
|
|
|
{
|
|
|
|
scrollDirtyRegion(dx, dy);
|
|
|
|
viewport()->scroll(dx, dy);
|
2014-02-02 14:56:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
|
|
|
override
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
2014-02-02 18:57:43 +05:30
|
|
|
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
2014-02-02 14:56:38 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* End of BS
|
|
|
|
*/
|
|
|
|
|
2014-02-01 03:21:45 +05:30
|
|
|
protected
|
|
|
|
slots:
|
|
|
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
|
|
|
const QVector<int> &roles);
|
2013-12-24 16:17:30 +05:30
|
|
|
virtual void rowsInserted(const QModelIndex &parent, int start, int end);
|
|
|
|
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
|
|
|
virtual void updateGeometries();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool isIndexHidden(const QModelIndex &index) const;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
|
|
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
|
2013-12-27 01:46:03 +05:30
|
|
|
void startDrag(Qt::DropActions supportedActions) override;
|
|
|
|
|
2013-12-24 16:17:30 +05:30
|
|
|
private:
|
2014-02-01 03:21:45 +05:30
|
|
|
friend struct Group;
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2014-02-01 03:21:45 +05:30
|
|
|
QList<Group *> m_categories;
|
2013-12-24 16:17:30 +05:30
|
|
|
|
|
|
|
int m_leftMargin;
|
|
|
|
int m_rightMargin;
|
2013-12-30 23:16:12 +05:30
|
|
|
int m_bottomMargin;
|
2013-12-24 16:17:30 +05:30
|
|
|
int m_categoryMargin;
|
|
|
|
|
2014-02-01 03:21:45 +05:30
|
|
|
// bool m_updatesDisabled;
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2014-02-01 03:21:45 +05:30
|
|
|
Group *category(const QModelIndex &index) const;
|
|
|
|
Group *category(const QString &cat) const;
|
|
|
|
Group *categoryAt(const QPoint &pos) const;
|
2013-12-24 16:17:30 +05:30
|
|
|
|
|
|
|
int itemsPerRow() const;
|
|
|
|
int contentWidth() const;
|
|
|
|
|
|
|
|
private:
|
2013-12-30 23:15:40 +05:30
|
|
|
int itemWidth() const;
|
2013-12-31 21:56:36 +05:30
|
|
|
int categoryRowHeight(const QModelIndex &index) const;
|
2013-12-24 16:17:30 +05:30
|
|
|
|
|
|
|
/*QLineEdit *m_categoryEditor;
|
|
|
|
Category *m_editedCategory;
|
|
|
|
void startCategoryEditor(Category *category);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void endCategoryEditor();*/
|
2013-12-27 01:46:03 +05:30
|
|
|
|
2014-02-02 18:57:43 +05:30
|
|
|
private: /* variables */
|
2013-12-27 01:46:03 +05:30
|
|
|
QPoint m_pressedPosition;
|
|
|
|
QPersistentModelIndex m_pressedIndex;
|
|
|
|
bool m_pressedAlreadySelected;
|
2014-02-01 03:21:45 +05:30
|
|
|
Group *m_pressedCategory;
|
2013-12-27 01:46:03 +05:30
|
|
|
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
|
|
|
QPoint m_lastDragPosition;
|
2014-02-02 18:57:43 +05:30
|
|
|
int m_spacing = 5;
|
2013-12-27 01:46:03 +05:30
|
|
|
|
2014-02-02 18:57:43 +05:30
|
|
|
private: /* methods */
|
2013-12-30 23:15:40 +05:30
|
|
|
QPair<int, int> categoryInternalPosition(const QModelIndex &index) const;
|
2013-12-31 21:56:36 +05:30
|
|
|
int categoryInternalRowTop(const QModelIndex &index) const;
|
2014-02-01 03:28:57 +05:30
|
|
|
int itemHeightForCategoryRow(const Group *category, const int internalRow) const;
|
2013-12-30 23:15:40 +05:30
|
|
|
|
2013-12-27 01:46:03 +05:30
|
|
|
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
2014-02-01 03:21:45 +05:30
|
|
|
QList<QPair<QRect, QModelIndex>> draggablePaintPairs(const QModelIndexList &indices,
|
|
|
|
QRect *r) const;
|
2013-12-27 01:46:03 +05:30
|
|
|
|
|
|
|
bool isDragEventAccepted(QDropEvent *event);
|
|
|
|
|
2014-02-01 03:21:45 +05:30
|
|
|
QPair<Group *, int> rowDropPos(const QPoint &pos);
|
2013-12-30 23:16:12 +05:30
|
|
|
|
|
|
|
QPoint offset() const;
|
2013-12-24 16:17:30 +05:30
|
|
|
};
|