2013-12-24 10:47:30 +00:00
|
|
|
#ifndef WIDGET_H
|
|
|
|
#define WIDGET_H
|
|
|
|
|
|
|
|
#include <QListView>
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
2013-12-30 22:39:10 +00:00
|
|
|
struct CategorizedViewRoles
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CategoryRole = Qt::UserRole,
|
|
|
|
ProgressValueRole,
|
|
|
|
ProgressMaximumRole
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-12-31 16:26:36 +00:00
|
|
|
struct CategorizedViewCategory;
|
|
|
|
|
2013-12-24 10:47:30 +00:00
|
|
|
class CategorizedView : public QListView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
CategorizedView(QWidget *parent = 0);
|
|
|
|
~CategorizedView();
|
|
|
|
|
|
|
|
virtual QRect visualRect(const QModelIndex &index) const;
|
2013-12-26 20:16:03 +00:00
|
|
|
QModelIndex indexAt(const QPoint &point) const;
|
|
|
|
void setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) override;
|
2013-12-24 10:47:30 +00:00
|
|
|
|
|
|
|
protected slots:
|
2013-12-31 16:26:36 +00:00
|
|
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
2013-12-24 10:47:30 +00:00
|
|
|
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-26 20:16:03 +00:00
|
|
|
void startDrag(Qt::DropActions supportedActions) override;
|
|
|
|
|
2013-12-24 10:47:30 +00:00
|
|
|
private:
|
2013-12-31 16:26:36 +00:00
|
|
|
friend struct CategorizedViewCategory;
|
2013-12-24 10:47:30 +00:00
|
|
|
|
2013-12-31 16:26:36 +00:00
|
|
|
QList<CategorizedViewCategory *> m_categories;
|
2013-12-24 10:47:30 +00:00
|
|
|
|
|
|
|
int m_leftMargin;
|
|
|
|
int m_rightMargin;
|
2013-12-30 17:46:12 +00:00
|
|
|
int m_bottomMargin;
|
2013-12-24 10:47:30 +00:00
|
|
|
int m_categoryMargin;
|
|
|
|
|
|
|
|
//bool m_updatesDisabled;
|
|
|
|
|
2013-12-31 16:26:36 +00:00
|
|
|
CategorizedViewCategory *category(const QModelIndex &index) const;
|
|
|
|
CategorizedViewCategory *category(const QString &cat) const;
|
|
|
|
CategorizedViewCategory *categoryAt(const QPoint &pos) const;
|
2013-12-24 10:47:30 +00:00
|
|
|
|
|
|
|
int itemsPerRow() const;
|
|
|
|
int contentWidth() const;
|
|
|
|
|
|
|
|
private:
|
2013-12-30 17:45:40 +00:00
|
|
|
int itemWidth() const;
|
2013-12-31 16:26:36 +00:00
|
|
|
int categoryRowHeight(const QModelIndex &index) const;
|
2013-12-24 10:47:30 +00:00
|
|
|
|
|
|
|
/*QLineEdit *m_categoryEditor;
|
|
|
|
Category *m_editedCategory;
|
|
|
|
void startCategoryEditor(Category *category);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void endCategoryEditor();*/
|
2013-12-26 20:16:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QPoint m_pressedPosition;
|
|
|
|
QPersistentModelIndex m_pressedIndex;
|
|
|
|
bool m_pressedAlreadySelected;
|
2013-12-31 16:26:36 +00:00
|
|
|
CategorizedViewCategory *m_pressedCategory;
|
2013-12-26 20:16:03 +00:00
|
|
|
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
|
|
|
QPoint m_lastDragPosition;
|
|
|
|
|
2013-12-30 17:45:40 +00:00
|
|
|
QPair<int, int> categoryInternalPosition(const QModelIndex &index) const;
|
2013-12-31 16:26:36 +00:00
|
|
|
int categoryInternalRowTop(const QModelIndex &index) const;
|
|
|
|
int itemHeightForCategoryRow(const CategorizedViewCategory *category, const int internalRow) const;
|
2013-12-30 17:45:40 +00:00
|
|
|
|
2013-12-26 20:16:03 +00:00
|
|
|
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
|
|
|
QList<QPair<QRect, QModelIndex> > draggablePaintPairs(const QModelIndexList &indices, QRect *r) const;
|
|
|
|
|
|
|
|
bool isDragEventAccepted(QDropEvent *event);
|
|
|
|
|
2013-12-31 16:26:36 +00:00
|
|
|
QPair<CategorizedViewCategory *, int> rowDropPos(const QPoint &pos);
|
2013-12-30 17:46:12 +00:00
|
|
|
|
|
|
|
QPoint offset() const;
|
2013-12-24 10:47:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WIDGET_H
|