diff options
Diffstat (limited to 'application/groupview')
-rw-r--r-- | application/groupview/GroupView.cpp | 26 | ||||
-rw-r--r-- | application/groupview/GroupView.h | 6 |
2 files changed, 24 insertions, 8 deletions
diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp index ab9e71cf..aa85bec7 100644 --- a/application/groupview/GroupView.cpp +++ b/application/groupview/GroupView.cpp @@ -188,18 +188,31 @@ VisualGroup *GroupView::category(const QString &cat) const return nullptr; } -VisualGroup *GroupView::categoryAt(const QPoint &pos) const +VisualGroup *GroupView::categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const { for (auto group : m_groups) { - if(group->hitScan(pos) & VisualGroup::CheckboxHit) + result = group->hitScan(pos); + if(result != VisualGroup::NoHit) { return group; } } + result = VisualGroup::NoHit; return nullptr; } +QString GroupView::groupNameAt(const QPoint &point) +{ + VisualGroup::HitResults hitresult; + auto group = categoryAt(point + offset(), hitresult); + if(group && (hitresult & (VisualGroup::HeaderHit | VisualGroup::BodyHit))) + { + return group->text; + } + return QString(); +} + int GroupView::calculateItemsPerRow() const { return qFloor((qreal)(contentWidth()) / (qreal)(itemWidth() + m_spacing)); @@ -228,8 +241,9 @@ void GroupView::mousePressEvent(QMouseEvent *event) m_pressedAlreadySelected = selectionModel()->isSelected(m_pressedIndex); m_pressedPosition = geometryPos; - m_pressedCategory = categoryAt(geometryPos); - if (m_pressedCategory) + VisualGroup::HitResults hitresult; + m_pressedCategory = categoryAt(geometryPos, hitresult); + if (m_pressedCategory && hitresult & VisualGroup::CheckboxHit) { setState(m_pressedCategory->collapsed ? ExpandingState : CollapsingState); event->accept(); @@ -325,8 +339,10 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event) QPoint geometryPos = event->pos() + offset(); QPersistentModelIndex index = indexAt(visualPos); + VisualGroup::HitResults hitresult; + bool click = (index == m_pressedIndex && index.isValid()) || - (m_pressedCategory && m_pressedCategory == categoryAt(geometryPos)); + (m_pressedCategory && m_pressedCategory == categoryAt(geometryPos, hitresult)); if (click && m_pressedCategory) { diff --git a/application/groupview/GroupView.h b/application/groupview/GroupView.h index b97d3a3c..a3863b6d 100644 --- a/application/groupview/GroupView.h +++ b/application/groupview/GroupView.h @@ -4,6 +4,7 @@ #include <QLineEdit> #include <QScrollBar> #include <QCache> +#include "VisualGroup.h" struct GroupViewRoles { @@ -15,8 +16,6 @@ struct GroupViewRoles }; }; -struct VisualGroup; - class GroupView : public QAbstractItemView { Q_OBJECT @@ -33,6 +32,7 @@ public: virtual QRect visualRect(const QModelIndex &index) const override; /// get the model index at the specified visual point virtual QModelIndex indexAt(const QPoint &point) const override; + QString groupNameAt(const QPoint &point); void setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) override; @@ -102,7 +102,7 @@ private: VisualGroup *category(const QModelIndex &index) const; VisualGroup *category(const QString &cat) const; - VisualGroup *categoryAt(const QPoint &pos) const; + VisualGroup *categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const; int itemsPerRow() const { |