2017-05-23 03:12:47 +05:30
|
|
|
/* Copyright 2013-2017 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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>
|
2014-07-12 16:19:07 +05:30
|
|
|
#include <QCache>
|
2016-04-11 05:00:50 +05:30
|
|
|
#include "VisualGroup.h"
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2014-02-04 05:10:10 +05:30
|
|
|
struct GroupViewRoles
|
2013-12-31 04:09:10 +05:30
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
2014-02-04 05:10:10 +05:30
|
|
|
GroupRole = Qt::UserRole,
|
2013-12-31 04:09:10 +05:30
|
|
|
ProgressValueRole,
|
|
|
|
ProgressMaximumRole
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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-03-07 20:16:56 +05:30
|
|
|
void setModel(QAbstractItemModel *model) override;
|
|
|
|
|
2014-02-10 05:21:52 +05:30
|
|
|
/// return geometry rectangle occupied by the specified model item
|
2014-02-04 05:10:10 +05:30
|
|
|
QRect geometryRect(const QModelIndex &index) const;
|
2014-02-10 05:21:52 +05:30
|
|
|
/// return visual rectangle occupied by the specified model item
|
2014-02-02 18:57:43 +05:30
|
|
|
virtual QRect visualRect(const QModelIndex &index) const override;
|
2014-02-10 05:21:52 +05:30
|
|
|
/// get the model index at the specified visual point
|
|
|
|
virtual QModelIndex indexAt(const QPoint &point) const override;
|
2016-04-11 05:00:50 +05:30
|
|
|
QString groupNameAt(const QPoint &point);
|
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-07-13 00:43:23 +05:30
|
|
|
virtual int horizontalOffset() const override;
|
|
|
|
virtual int verticalOffset() const override;
|
|
|
|
virtual void scrollContentsBy(int dx, int dy) override;
|
|
|
|
virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
|
2014-02-02 14:56:38 +05:30
|
|
|
|
2014-02-04 05:10:10 +05:30
|
|
|
virtual QModelIndex moveCursor(CursorAction cursorAction,
|
|
|
|
Qt::KeyboardModifiers modifiers) override;
|
2014-02-02 14:56:38 +05:30
|
|
|
|
2014-02-02 18:57:43 +05:30
|
|
|
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
2014-02-02 14:56:38 +05:30
|
|
|
|
2014-07-13 00:43:23 +05:30
|
|
|
int spacing() const
|
|
|
|
{
|
|
|
|
return m_spacing;
|
|
|
|
};
|
2015-09-16 03:51:50 +05:30
|
|
|
|
|
|
|
public slots:
|
|
|
|
virtual void updateGeometries() override;
|
|
|
|
|
|
|
|
protected slots:
|
2014-02-04 05:10:10 +05:30
|
|
|
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
|
|
|
const QVector<int> &roles) override;
|
|
|
|
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
|
|
|
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
|
2014-03-07 20:16:56 +05:30
|
|
|
void modelReset();
|
2016-12-19 05:04:03 +05:30
|
|
|
void rowsRemoved();
|
2013-12-24 16:17:30 +05:30
|
|
|
|
2017-04-22 09:41:26 +05:30
|
|
|
signals:
|
|
|
|
void droppedURLs(QList<QUrl> urls);
|
|
|
|
|
2013-12-24 16:17:30 +05:30
|
|
|
protected:
|
2014-02-04 05:10:10 +05:30
|
|
|
virtual bool isIndexHidden(const QModelIndex &index) const override;
|
2013-12-24 16:17:30 +05:30
|
|
|
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;
|
|
|
|
|
2018-01-28 06:34:47 +05:30
|
|
|
void updateScrollbar();
|
|
|
|
|
2013-12-24 16:17:30 +05:30
|
|
|
private:
|
2014-07-13 00:43:23 +05:30
|
|
|
friend struct VisualGroup;
|
|
|
|
QList<VisualGroup *> m_groups;
|
|
|
|
|
|
|
|
// geometry
|
|
|
|
int m_leftMargin = 5;
|
|
|
|
int m_rightMargin = 5;
|
|
|
|
int m_bottomMargin = 5;
|
|
|
|
int m_categoryMargin = 5;
|
|
|
|
int m_spacing = 5;
|
|
|
|
int m_itemWidth = 100;
|
|
|
|
int m_currentItemsPerRow = -1;
|
|
|
|
int m_currentCursorColumn= -1;
|
|
|
|
mutable QCache<int, QRect> geometryCache;
|
2013-12-27 01:46:03 +05:30
|
|
|
|
2014-07-13 00:43:23 +05:30
|
|
|
// point where the currently active mouse action started in geometry coordinates
|
2013-12-27 01:46:03 +05:30
|
|
|
QPoint m_pressedPosition;
|
|
|
|
QPersistentModelIndex m_pressedIndex;
|
|
|
|
bool m_pressedAlreadySelected;
|
2014-07-13 00:43:23 +05:30
|
|
|
VisualGroup *m_pressedCategory;
|
2013-12-27 01:46:03 +05:30
|
|
|
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
|
|
|
QPoint m_lastDragPosition;
|
|
|
|
|
2014-07-13 00:43:23 +05:30
|
|
|
VisualGroup *category(const QModelIndex &index) const;
|
|
|
|
VisualGroup *category(const QString &cat) const;
|
2016-04-11 05:00:50 +05:30
|
|
|
VisualGroup *categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const;
|
2013-12-30 23:15:40 +05:30
|
|
|
|
2014-07-13 00:43:23 +05:30
|
|
|
int itemsPerRow() const
|
|
|
|
{
|
|
|
|
return m_currentItemsPerRow;
|
|
|
|
};
|
|
|
|
int contentWidth() const;
|
|
|
|
|
|
|
|
private: /* methods */
|
|
|
|
int itemWidth() const;
|
|
|
|
int calculateItemsPerRow() const;
|
|
|
|
int verticalScrollToValue(const QModelIndex &index, const QRect &rect,
|
|
|
|
QListView::ScrollHint hint) const;
|
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-07-13 00:43:23 +05:30
|
|
|
QPair<VisualGroup *, int> rowDropPos(const QPoint &pos);
|
2013-12-30 23:16:12 +05:30
|
|
|
|
|
|
|
QPoint offset() const;
|
2013-12-24 16:17:30 +05:30
|
|
|
};
|