aboutsummaryrefslogtreecommitdiff
path: root/application/groupview
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-07-15 14:51:05 +0200
committerPetr Mrázek <peterix@gmail.com>2018-07-15 14:51:05 +0200
commitbbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9 (patch)
treee6497e304b7b9368367565fbc7c06efab1124b1c /application/groupview
parent03280cc62e75f8073f8d3d9e9e3952acf21fa77d (diff)
downloadPrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.gz
PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.bz2
PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.zip
NOISSUE tabs -> spaces
Diffstat (limited to 'application/groupview')
-rw-r--r--application/groupview/GroupView.cpp1474
-rw-r--r--application/groupview/GroupView.h184
-rw-r--r--application/groupview/GroupedProxyModel.cpp34
-rw-r--r--application/groupview/GroupedProxyModel.h8
-rw-r--r--application/groupview/InstanceDelegate.cpp550
-rw-r--r--application/groupview/InstanceDelegate.h8
-rw-r--r--application/groupview/VisualGroup.cpp462
-rw-r--r--application/groupview/VisualGroup.h106
8 files changed, 1413 insertions, 1413 deletions
diff --git a/application/groupview/GroupView.cpp b/application/groupview/GroupView.cpp
index 0d6aa49e..a1b44e64 100644
--- a/application/groupview/GroupView.cpp
+++ b/application/groupview/GroupView.cpp
@@ -31,937 +31,937 @@
template <typename T> bool listsIntersect(const QList<T> &l1, const QList<T> t2)
{
- for (auto &item : l1)
- {
- if (t2.contains(item))
- {
- return true;
- }
- }
- return false;
+ for (auto &item : l1)
+ {
+ if (t2.contains(item))
+ {
+ return true;
+ }
+ }
+ return false;
}
GroupView::GroupView(QWidget *parent)
- : QAbstractItemView(parent)
+ : QAbstractItemView(parent)
{
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- setAcceptDrops(true);
- setAutoScroll(true);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ setAcceptDrops(true);
+ setAutoScroll(true);
}
GroupView::~GroupView()
{
- qDeleteAll(m_groups);
- m_groups.clear();
+ qDeleteAll(m_groups);
+ m_groups.clear();
}
void GroupView::setModel(QAbstractItemModel *model)
{
- QAbstractItemView::setModel(model);
- connect(model, &QAbstractItemModel::modelReset, this, &GroupView::modelReset);
- connect(model, &QAbstractItemModel::rowsRemoved, this, &GroupView::rowsRemoved);
+ QAbstractItemView::setModel(model);
+ connect(model, &QAbstractItemModel::modelReset, this, &GroupView::modelReset);
+ connect(model, &QAbstractItemModel::rowsRemoved, this, &GroupView::rowsRemoved);
}
void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
- const QVector<int> &roles)
+ const QVector<int> &roles)
{
- scheduleDelayedItemsLayout();
+ scheduleDelayedItemsLayout();
}
void GroupView::rowsInserted(const QModelIndex &parent, int start, int end)
{
- scheduleDelayedItemsLayout();
+ scheduleDelayedItemsLayout();
}
void GroupView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
- scheduleDelayedItemsLayout();
+ scheduleDelayedItemsLayout();
}
void GroupView::modelReset()
{
- scheduleDelayedItemsLayout();
+ scheduleDelayedItemsLayout();
}
void GroupView::rowsRemoved()
{
- scheduleDelayedItemsLayout();
+ scheduleDelayedItemsLayout();
}
class LocaleString : public QString
{
public:
- LocaleString(const char *s) : QString(s)
- {
- }
- LocaleString(const QString &s) : QString(s)
- {
- }
+ LocaleString(const char *s) : QString(s)
+ {
+ }
+ LocaleString(const QString &s) : QString(s)
+ {
+ }
};
inline bool operator<(const LocaleString &lhs, const LocaleString &rhs)
{
- return (QString::localeAwareCompare(lhs, rhs) < 0);
+ return (QString::localeAwareCompare(lhs, rhs) < 0);
}
void GroupView::updateScrollbar()
{
- int previousScroll = verticalScrollBar()->value();
- if (m_groups.isEmpty())
- {
- verticalScrollBar()->setRange(0, 0);
- }
- else
- {
- int totalHeight = 0;
- // top margin
- totalHeight += m_categoryMargin;
- int itemScroll = 0;
- for (auto category : m_groups)
- {
- category->m_verticalPosition = totalHeight;
- totalHeight += category->totalHeight() + m_categoryMargin;
- if(!itemScroll && category->totalHeight() != 0)
- {
- itemScroll = category->contentHeight() / category->numRows();
- }
- }
- // do not divide by zero
- if(itemScroll == 0)
- itemScroll = 64;
-
- totalHeight += m_bottomMargin;
- verticalScrollBar()->setSingleStep ( itemScroll );
- const int rowsPerPage = qMax ( viewport()->height() / itemScroll, 1 );
- verticalScrollBar()->setPageStep ( rowsPerPage * itemScroll );
-
- verticalScrollBar()->setRange(0, totalHeight - height());
- }
-
- verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
+ int previousScroll = verticalScrollBar()->value();
+ if (m_groups.isEmpty())
+ {
+ verticalScrollBar()->setRange(0, 0);
+ }
+ else
+ {
+ int totalHeight = 0;
+ // top margin
+ totalHeight += m_categoryMargin;
+ int itemScroll = 0;
+ for (auto category : m_groups)
+ {
+ category->m_verticalPosition = totalHeight;
+ totalHeight += category->totalHeight() + m_categoryMargin;
+ if(!itemScroll && category->totalHeight() != 0)
+ {
+ itemScroll = category->contentHeight() / category->numRows();
+ }
+ }
+ // do not divide by zero
+ if(itemScroll == 0)
+ itemScroll = 64;
+
+ totalHeight += m_bottomMargin;
+ verticalScrollBar()->setSingleStep ( itemScroll );
+ const int rowsPerPage = qMax ( viewport()->height() / itemScroll, 1 );
+ verticalScrollBar()->setPageStep ( rowsPerPage * itemScroll );
+
+ verticalScrollBar()->setRange(0, totalHeight - height());
+ }
+
+ verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
}
void GroupView::updateGeometries()
{
- geometryCache.clear();
-
- QMap<LocaleString, VisualGroup *> cats;
-
- for (int i = 0; i < model()->rowCount(); ++i)
- {
- const QString groupName = model()->index(i, 0).data(GroupViewRoles::GroupRole).toString();
- if (!cats.contains(groupName))
- {
- VisualGroup *old = this->category(groupName);
- if (old)
- {
- auto cat = new VisualGroup(old);
- cats.insert(groupName, cat);
- cat->update();
- }
- else
- {
- auto cat = new VisualGroup(groupName, this);
- cats.insert(groupName, cat);
- cat->update();
- }
- }
- }
-
- qDeleteAll(m_groups);
- m_groups = cats.values();
- updateScrollbar();
- viewport()->update();
+ geometryCache.clear();
+
+ QMap<LocaleString, VisualGroup *> cats;
+
+ for (int i = 0; i < model()->rowCount(); ++i)
+ {
+ const QString groupName = model()->index(i, 0).data(GroupViewRoles::GroupRole).toString();
+ if (!cats.contains(groupName))
+ {
+ VisualGroup *old = this->category(groupName);
+ if (old)
+ {
+ auto cat = new VisualGroup(old);
+ cats.insert(groupName, cat);
+ cat->update();
+ }
+ else
+ {
+ auto cat = new VisualGroup(groupName, this);
+ cats.insert(groupName, cat);
+ cat->update();
+ }
+ }
+ }
+
+ qDeleteAll(m_groups);
+ m_groups = cats.values();
+ updateScrollbar();
+ viewport()->update();
}
bool GroupView::isIndexHidden(const QModelIndex &index) const
{
- VisualGroup *cat = category(index);
- if (cat)
- {
- return cat->collapsed;
- }
- else
- {
- return false;
- }
+ VisualGroup *cat = category(index);
+ if (cat)
+ {
+ return cat->collapsed;
+ }
+ else
+ {
+ return false;
+ }
}
VisualGroup *GroupView::category(const QModelIndex &index) const
{
- return category(index.data(GroupViewRoles::GroupRole).toString());
+ return category(index.data(GroupViewRoles::GroupRole).toString());
}
VisualGroup *GroupView::category(const QString &cat) const
{
- for (auto group : m_groups)
- {
- if (group->text == cat)
- {
- return group;
- }
- }
- return nullptr;
+ for (auto group : m_groups)
+ {
+ if (group->text == cat)
+ {
+ return group;
+ }
+ }
+ return nullptr;
}
VisualGroup *GroupView::categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const
{
- for (auto group : m_groups)
- {
- result = group->hitScan(pos);
- if(result != VisualGroup::NoHit)
- {
- return group;
- }
- }
- result = VisualGroup::NoHit;
- return nullptr;
+ for (auto group : m_groups)
+ {
+ 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();
+ 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));
+ return qFloor((qreal)(contentWidth()) / (qreal)(itemWidth() + m_spacing));
}
int GroupView::contentWidth() const
{
- return width() - m_leftMargin - m_rightMargin;
+ return width() - m_leftMargin - m_rightMargin;
}
int GroupView::itemWidth() const
{
- return m_itemWidth;
+ return m_itemWidth;
}
void GroupView::mousePressEvent(QMouseEvent *event)
{
- // endCategoryEditor();
-
- QPoint visualPos = event->pos();
- QPoint geometryPos = event->pos() + offset();
-
- QPersistentModelIndex index = indexAt(visualPos);
-
- m_pressedIndex = index;
- m_pressedAlreadySelected = selectionModel()->isSelected(m_pressedIndex);
- m_pressedPosition = geometryPos;
-
- VisualGroup::HitResults hitresult;
- m_pressedCategory = categoryAt(geometryPos, hitresult);
- if (m_pressedCategory && hitresult & VisualGroup::CheckboxHit)
- {
- setState(m_pressedCategory->collapsed ? ExpandingState : CollapsingState);
- event->accept();
- return;
- }
-
- if (index.isValid() && (index.flags() & Qt::ItemIsEnabled))
- {
- if(index != currentIndex())
- {
- // FIXME: better!
- m_currentCursorColumn = -1;
- }
- // we disable scrollTo for mouse press so the item doesn't change position
- // when the user is interacting with it (ie. clicking on it)
- bool autoScroll = hasAutoScroll();
- setAutoScroll(false);
- selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
-
- setAutoScroll(autoScroll);
- QRect rect(visualPos, visualPos);
- setSelection(rect, QItemSelectionModel::ClearAndSelect);
-
- // signal handlers may change the model
- emit pressed(index);
- }
- else
- {
- // Forces a finalize() even if mouse is pressed, but not on a item
- selectionModel()->select(QModelIndex(), QItemSelectionModel::Select);
- }
+ // endCategoryEditor();
+
+ QPoint visualPos = event->pos();
+ QPoint geometryPos = event->pos() + offset();
+
+ QPersistentModelIndex index = indexAt(visualPos);
+
+ m_pressedIndex = index;
+ m_pressedAlreadySelected = selectionModel()->isSelected(m_pressedIndex);
+ m_pressedPosition = geometryPos;
+
+ VisualGroup::HitResults hitresult;
+ m_pressedCategory = categoryAt(geometryPos, hitresult);
+ if (m_pressedCategory && hitresult & VisualGroup::CheckboxHit)
+ {
+ setState(m_pressedCategory->collapsed ? ExpandingState : CollapsingState);
+ event->accept();
+ return;
+ }
+
+ if (index.isValid() && (index.flags() & Qt::ItemIsEnabled))
+ {
+ if(index != currentIndex())
+ {
+ // FIXME: better!
+ m_currentCursorColumn = -1;
+ }
+ // we disable scrollTo for mouse press so the item doesn't change position
+ // when the user is interacting with it (ie. clicking on it)
+ bool autoScroll = hasAutoScroll();
+ setAutoScroll(false);
+ selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
+
+ setAutoScroll(autoScroll);
+ QRect rect(visualPos, visualPos);
+ setSelection(rect, QItemSelectionModel::ClearAndSelect);
+
+ // signal handlers may change the model
+ emit pressed(index);
+ }
+ else
+ {
+ // Forces a finalize() even if mouse is pressed, but not on a item
+ selectionModel()->select(QModelIndex(), QItemSelectionModel::Select);
+ }
}
void GroupView::mouseMoveEvent(QMouseEvent *event)
{
- QPoint topLeft;
- QPoint visualPos = event->pos();
- QPoint geometryPos = event->pos() + offset();
-
- if (state() == ExpandingState || state() == CollapsingState)
- {
- return;
- }
-
- if (state() == DraggingState)
- {
- topLeft = m_pressedPosition - offset();
- if ((topLeft - event->pos()).manhattanLength() > QApplication::startDragDistance())
- {
- m_pressedIndex = QModelIndex();
- startDrag(model()->supportedDragActions());
- setState(NoState);
- stopAutoScroll();
- }
- return;
- }
-
- if (selectionMode() != SingleSelection)
- {
- topLeft = m_pressedPosition - offset();
- }
- else
- {
- topLeft = geometryPos;
- }
-
- if (m_pressedIndex.isValid() && (state() != DragSelectingState) &&
- (event->buttons() != Qt::NoButton) && !selectedIndexes().isEmpty())
- {
- setState(DraggingState);
- return;
- }
-
- if ((event->buttons() & Qt::LeftButton) && selectionModel())
- {
- setState(DragSelectingState);
-
- setSelection(QRect(visualPos, visualPos), QItemSelectionModel::ClearAndSelect);
- QModelIndex index = indexAt(visualPos);
-
- // set at the end because it might scroll the view
- if (index.isValid() && (index != selectionModel()->currentIndex()) &&
- (index.flags() & Qt::ItemIsEnabled))
- {
- selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
- }
- }
+ QPoint topLeft;
+ QPoint visualPos = event->pos();
+ QPoint geometryPos = event->pos() + offset();
+
+ if (state() == ExpandingState || state() == CollapsingState)
+ {
+ return;
+ }
+
+ if (state() == DraggingState)
+ {
+ topLeft = m_pressedPosition - offset();
+ if ((topLeft - event->pos()).manhattanLength() > QApplication::startDragDistance())
+ {
+ m_pressedIndex = QModelIndex();
+ startDrag(model()->supportedDragActions());
+ setState(NoState);
+ stopAutoScroll();
+ }
+ return;
+ }
+
+ if (selectionMode() != SingleSelection)
+ {
+ topLeft = m_pressedPosition - offset();
+ }
+ else
+ {
+ topLeft = geometryPos;
+ }
+
+ if (m_pressedIndex.isValid() && (state() != DragSelectingState) &&
+ (event->buttons() != Qt::NoButton) && !selectedIndexes().isEmpty())
+ {
+ setState(DraggingState);
+ return;
+ }
+
+ if ((event->buttons() & Qt::LeftButton) && selectionModel())
+ {
+ setState(DragSelectingState);
+
+ setSelection(QRect(visualPos, visualPos), QItemSelectionModel::ClearAndSelect);
+ QModelIndex index = indexAt(visualPos);
+
+ // set at the end because it might scroll the view
+ if (index.isValid() && (index != selectionModel()->currentIndex()) &&
+ (index.flags() & Qt::ItemIsEnabled))
+ {
+ selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
+ }
+ }
}
void GroupView::mouseReleaseEvent(QMouseEvent *event)
{
- QPoint visualPos = event->pos();
- 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, hitresult));
-
- if (click && m_pressedCategory)
- {
- if (state() == ExpandingState)
- {
- m_pressedCategory->collapsed = false;
- updateGeometries();
- viewport()->update();
- event->accept();
- return;
- }
- else if (state() == CollapsingState)
- {
- m_pressedCategory->collapsed = true;
- updateGeometries();
- viewport()->update();
- event->accept();
- return;
- }
- }
-
- m_ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate;
-
- setState(NoState);
-
- if (click)
- {
- if (event->button() == Qt::LeftButton)
- {
- emit clicked(index);
- }
- QStyleOptionViewItem option = viewOptions();
- if (m_pressedAlreadySelected)
- {
- option.state |= QStyle::State_Selected;
- }
- if ((model()->flags(index) & Qt::ItemIsEnabled) &&
- style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
- {
- emit activated(index);
- }
- }
+ QPoint visualPos = event->pos();
+ 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, hitresult));
+
+ if (click && m_pressedCategory)
+ {
+ if (state() == ExpandingState)
+ {
+ m_pressedCategory->collapsed = false;
+ updateGeometries();
+ viewport()->update();
+ event->accept();
+ return;
+ }
+ else if (state() == CollapsingState)
+ {
+ m_pressedCategory->collapsed = true;
+ updateGeometries();
+ viewport()->update();
+ event->accept();
+ return;
+ }
+ }
+
+ m_ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate;
+
+ setState(NoState);
+
+ if (click)
+ {
+ if (event->button() == Qt::LeftButton)
+ {
+ emit clicked(index);
+ }
+ QStyleOptionViewItem option = viewOptions();
+ if (m_pressedAlreadySelected)
+ {
+ option.state |= QStyle::State_Selected;
+ }
+ if ((model()->flags(index) & Qt::ItemIsEnabled) &&
+ style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
+ {
+ emit activated(index);
+ }
+ }
}
void GroupView::mouseDoubleClickEvent(QMouseEvent *event)
{
- QModelIndex index = indexAt(event->pos());
- if (!index.isValid() || !(index.flags() & Qt::ItemIsEnabled) || (m_pressedIndex != index))
- {
- QMouseEvent me(QEvent::MouseButtonPress, event->localPos(), event->windowPos(),
- event->screenPos(), event->button(), event->buttons(),
- event->modifiers());
- mousePressEvent(&me);
- return;
- }
- // signal handlers may change the model
- QPersistentModelIndex persistent = index;
- emit doubleClicked(persistent);
+ QModelIndex index = indexAt(event->pos());
+ if (!index.isValid() || !(index.flags() & Qt::ItemIsEnabled) || (m_pressedIndex != index))
+ {
+ QMouseEvent me(QEvent::MouseButtonPress, event->localPos(), event->windowPos(),
+ event->screenPos(), event->button(), event->buttons(),
+ event->modifiers());
+ mousePressEvent(&me);
+ return;
+ }
+ // signal handlers may change the model
+ QPersistentModelIndex persistent = index;
+ emit doubleClicked(persistent);
}
void GroupView::paintEvent(QPaintEvent *event)
{
- executeDelayedItemsLayout();
-
- QPainter painter(this->viewport());
-
- QStyleOptionViewItem option(viewOptions());
- option.widget = this;
-
- int wpWidth = viewport()->width();
- option.rect.setWidth(wpWidth);
- for (int i = 0; i < m_groups.size(); ++i)
- {
- VisualGroup *category = m_groups.at(i);
- int y = category->verticalPosition();
- y -= verticalOffset();
- QRect backup = option.rect;
- int height = category->totalHeight();
- option.rect.setTop(y);
- option.rect.setHeight(height);
- option.rect.setLeft(m_leftMargin);
- option.rect.setRight(wpWidth - m_rightMargin);
- category->drawHeader(&painter, option);
- y += category->totalHeight() + m_categoryMargin;
- option.rect = backup;
- }
-
- for (int i = 0; i < model()->rowCount(); ++i)
- {
- const QModelIndex index = model()->index(i, 0);
- if (isIndexHidden(index))
- {
- continue;
- }
- Qt::ItemFlags flags = index.flags();
- option.rect = visualRect(index);
- option.features |= QStyleOptionViewItem::WrapText;
- if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
- {
- option.state |= selectionModel()->isSelected(index) ? QStyle::State_Selected
- : QStyle::State_None;
- }
- else
- {
- option.state &= ~QStyle::State_Selected;
- }
- option.state |= (index == currentIndex()) ? QStyle::State_HasFocus : QStyle::State_None;
- if (!(flags & Qt::ItemIsEnabled))
- {
- option.state &= ~QStyle::State_Enabled;
- }
- itemDelegate()->paint(&painter, option, index);
- }
-
- /*
- * Drop indicators for manual reordering...
- */
+ executeDelayedItemsLayout();
+
+ QPainter painter(this->viewport());
+
+ QStyleOptionViewItem option(viewOptions());
+ option.widget = this;
+
+ int wpWidth = viewport()->width();
+ option.rect.setWidth(wpWidth);
+ for (int i = 0; i < m_groups.size(); ++i)
+ {
+ VisualGroup *category = m_groups.at(i);
+ int y = category->verticalPosition();
+ y -= verticalOffset();
+ QRect backup = option.rect;
+ int height = category->totalHeight();
+ option.rect.setTop(y);
+ option.rect.setHeight(height);
+ option.rect.setLeft(m_leftMargin);
+ option.rect.setRight(wpWidth - m_rightMargin);
+ category->drawHeader(&painter, option);
+ y += category->totalHeight() + m_categoryMargin;
+ option.rect = backup;
+ }
+
+ for (int i = 0; i < model()->rowCount(); ++i)
+ {
+ const QModelIndex index = model()->index(i, 0);
+ if (isIndexHidden(index))
+ {
+ continue;
+ }
+ Qt::ItemFlags flags = index.flags();
+ option.rect = visualRect(index);
+ option.features |= QStyleOptionViewItem::WrapText;
+ if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
+ {
+ option.state |= selectionModel()->isSelected(index) ? QStyle::State_Selected
+ : QStyle::State_None;
+ }
+ else
+ {
+ option.state &= ~QStyle::State_Selected;
+ }
+ option.state |= (index == currentIndex()) ? QStyle::State_HasFocus : QStyle::State_None;
+ if (!(flags & Qt::ItemIsEnabled))
+ {
+ option.state &= ~QStyle::State_Enabled;
+ }
+ itemDelegate()->paint(&painter, option, index);
+ }
+
+ /*
+ * Drop indicators for manual reordering...
+ */
#if 0
- if (!m_lastDragPosition.isNull())
- {
- QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
- Group *category = pair.first;
- int row = pair.second;
- if (category)
- {
- int internalRow = row - category->firstItemIndex;
- QLine line;
- if (internalRow >= category->numItems())
- {
- QRect toTheRightOfRect = visualRect(category->lastItem());
- line = QLine(toTheRightOfRect.topRight(), toTheRightOfRect.bottomRight());
- }
- else
- {
- QRect toTheLeftOfRect = visualRect(model()->index(row, 0));
- line = QLine(toTheLeftOfRect.topLeft(), toTheLeftOfRect.bottomLeft());
- }
- painter.save();
- painter.setPen(QPen(Qt::black, 3));
- painter.drawLine(line);
- painter.restore();
- }
- }
+ if (!m_lastDragPosition.isNull())
+ {
+ QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
+ Group *category = pair.first;
+ int row = pair.second;
+ if (category)
+ {
+ int internalRow = row - category->firstItemIndex;
+ QLine line;
+ if (internalRow >= category->numItems())
+ {
+ QRect toTheRightOfRect = visualRect(category->lastItem());
+ line = QLine(toTheRightOfRect.topRight(), toTheRightOfRect.bottomRight());
+ }
+ else
+ {
+ QRect toTheLeftOfRect = visualRect(model()->index(row, 0));
+ line = QLine(toTheLeftOfRect.topLeft(), toTheLeftOfRect.bottomLeft());
+ }
+ painter.save();
+ painter.setPen(QPen(Qt::black, 3));
+ painter.drawLine(line);
+ painter.restore();
+ }
+ }
#endif
}
void GroupView::resizeEvent(QResizeEvent *event)
{
- int newItemsPerRow = calculateItemsPerRow();
- if(newItemsPerRow != m_currentItemsPerRow)
- {
- m_currentCursorColumn = -1;
- m_currentItemsPerRow = newItemsPerRow;
- updateGeometries();
- }
- else
- {
- updateScrollbar();
- }
+ int newItemsPerRow = calculateItemsPerRow();
+ if(newItemsPerRow != m_currentItemsPerRow)
+ {
+ m_currentCursorColumn = -1;
+ m_currentItemsPerRow = newItemsPerRow;
+ updateGeometries();
+ }
+ else
+ {
+ updateScrollbar();
+ }
}
void GroupView::dragEnterEvent(QDragEnterEvent *event)
{
- if (!isDragEventAccepted(event))
- {
- return;
- }
- m_lastDragPosition = event->pos() + offset();
- viewport()->update();
- event->accept();
+ if (!isDragEventAccepted(event))
+ {
+ return;
+ }
+ m_lastDragPosition = event->pos() + offset();
+ viewport()->update();
+ event->accept();
}
void GroupView::dragMoveEvent(QDragMoveEvent *event)
{
- if (!isDragEventAccepted(event))
- {
- return;
- }
- m_lastDragPosition = event->pos() + offset();
- viewport()->update();
- event->accept();
+ if (!isDragEventAccepted(event))
+ {
+ return;
+ }
+ m_lastDragPosition = event->pos() + offset();
+ viewport()->update();
+ event->accept();
}
void GroupView::dragLeaveEvent(QDragLeaveEvent *event)
{
- m_lastDragPosition = QPoint();
- viewport()->update();
+ m_lastDragPosition = QPoint();
+ viewport()->update();
}
void GroupView::dropEvent(QDropEvent *event)
{
- m_lastDragPosition = QPoint();
-
- stopAutoScroll();
- setState(NoState);
-
- if (event->source() == this)
- {
- if(event->possibleActions() & Qt::MoveAction)
- {
- QPair<VisualGroup *, int> dropPos = rowDropPos(event->pos() + offset());
- const VisualGroup *category = dropPos.first;
- const int row = dropPos.second;
-
- if (row == -1)
- {
- viewport()->update();
- return;
- }
-
- const QString categoryText = category->text;
- if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
- {
- model()->setData(model()->index(row, 0), categoryText,
- GroupViewRoles::GroupRole);
- event->setDropAction(Qt::MoveAction);
- event->accept();
- }
- updateGeometries();
- viewport()->update();
- }
- }
- auto mimedata = event->mimeData();
-
- // check if the action is supported
- if (!mimedata)
- {
- return;
- }
-
- // files dropped from outside?
- if (mimedata->hasUrls())
- {
- auto urls = mimedata->urls();
- event->accept();
- emit droppedURLs(urls);
- }
+ m_lastDragPosition = QPoint();
+
+ stopAutoScroll();
+ setState(NoState);
+
+ if (event->source() == this)
+ {
+ if(event->possibleActions() & Qt::MoveAction)
+ {
+ QPair<VisualGroup *, int> dropPos = rowDropPos(event->pos() + offset());
+ const VisualGroup *category = dropPos.first;
+ const int row = dropPos.second;
+
+ if (row == -1)
+ {
+ viewport()->update();
+ return;
+ }
+
+ const QString categoryText = category->text;
+ if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
+ {
+ model()->setData(model()->index(row, 0), categoryText,
+ GroupViewRoles::GroupRole);
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ }
+ updateGeometries();
+ viewport()->update();
+ }
+ }
+ auto mimedata = event->mimeData();
+
+ // check if the action is supported
+ if (!mimedata)
+ {
+ return;
+ }
+
+ // files dropped from outside?
+ if (mimedata->hasUrls())
+ {
+ auto urls = mimedata->urls();
+ event->accept();
+ emit droppedURLs(urls);
+ }
}
void GroupView::startDrag(Qt::DropActions supportedActions)
{
- QModelIndexList indexes = selectionModel()->selectedIndexes();
- if(indexes.count() == 0)
- return;
-
- QMimeData *data = model()->mimeData(indexes);
- if (!data)
- {
- return;
- }
- QRect rect;
- QPixmap pixmap = renderToPixmap(indexes, &rect);
- //rect.translate(offset());
- // rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
- QDrag *drag = new QDrag(this);
- drag->setPixmap(pixmap);
- drag->setMimeData(data);
- Qt::DropAction defaultDropAction = Qt::IgnoreAction;
- if (this->defaultDropAction() != Qt::IgnoreAction &&
- (supportedActions & this->defaultDropAction()))
- {
- defaultDropAction = this->defaultDropAction();
- }
- if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)
- {
- const QItemSelection selection = selectionModel()->selection();
-
- for (auto it = selection.constBegin(); it != selection.constEnd(); ++it)
- {
- QModelIndex parent = (*it).parent();
- if ((*it).left() != 0)
- {
- continue;
- }
- if ((*it).right() != (model()->columnCount(parent) - 1))
- {
- continue;
- }
- int count = (*it).bottom() - (*it).top() + 1;
- model()->removeRows((*it).top(), count, parent);
- }
- }
+ QModelIndexList indexes = selectionModel()->selectedIndexes();
+ if(indexes.count() == 0)
+ return;
+
+ QMimeData *data = model()->mimeData(indexes);
+ if (!data)
+ {
+ return;
+ }
+ QRect rect;
+ QPixmap pixmap = renderToPixmap(indexes, &rect);
+ //rect.translate(offset());
+ // rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
+ QDrag *drag = new QDrag(this);
+ drag->setPixmap(pixmap);
+ drag->setMimeData(data);
+ Qt::DropAction defaultDropAction = Qt::IgnoreAction;
+ if (this->defaultDropAction() != Qt::IgnoreAction &&
+ (supportedActions & this->defaultDropAction()))
+ {
+ defaultDropAction = this->defaultDropAction();
+ }
+ if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)