forked from qt-creator/qt-creator
Welcome: Fix issues with handling of mouse presses on tags
1) Handle all clicks anywhere on the item area. If a tag gets clicked, handle that, otherwise always open the item. 2) Ensure that m_currentTagRects is up-to-date. It sometimes contained the tag list of another item. Now it is handled in the same way as m_blurredThumbnail. Task-number: QTCREATORBUG-27106 Change-Id: I394ceb55987f903d17254225b69cae347021f78c Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -406,6 +406,7 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||
if (hovered) {
|
||||
if (index != m_previousIndex) {
|
||||
m_previousIndex = index;
|
||||
m_currentTagRects.clear();
|
||||
m_blurredThumbnail = QPixmap();
|
||||
m_startTime.start();
|
||||
m_currentWidget = qobject_cast<QAbstractItemView *>(
|
||||
@@ -521,10 +522,10 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||
painter->drawText(tagsLabelRect, tagsLabelText);
|
||||
|
||||
painter->setPen(themeColor(Theme::Welcome_LinkColor));
|
||||
m_currentTagRects.clear();
|
||||
int emptyTagRowsLeft = 2;
|
||||
int xx = 0;
|
||||
int yy = 0;
|
||||
const bool populateTagsRects = m_currentTagRects.empty();
|
||||
for (const QString &tag : item->tags) {
|
||||
const int ww = fm.horizontalAdvance(tag) + tagsHorSpacing;
|
||||
if (xx + ww > textArea.width() - tagsLabelRect.width()) {
|
||||
@@ -536,7 +537,8 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||
const QRect tagRect = QRect(xx, yy, ww, tagsLabelRect.height())
|
||||
.translated(tagsLabelRect.topRight());
|
||||
painter->drawText(tagRect, tag);
|
||||
m_currentTagRects.append({ tag, tagRect.translated(rc.topLeft()) });
|
||||
if (populateTagsRects)
|
||||
m_currentTagRects.append({ tag, tagRect });
|
||||
xx += ww;
|
||||
}
|
||||
|
||||
@@ -556,18 +558,18 @@ bool ListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
return false;
|
||||
|
||||
if (index.isValid()) {
|
||||
const QPoint pos = mev->pos();
|
||||
if (pos.y() > option.rect.y() + TagsSeparatorY) {
|
||||
//const QStringList tags = idx.data(Tags).toStringList();
|
||||
for (const auto &it : qAsConst(m_currentTagRects)) {
|
||||
if (it.second.contains(pos))
|
||||
emit tagClicked(it.first);
|
||||
}
|
||||
} else {
|
||||
const QPoint mousePos = mev->pos() - option.rect.topLeft();
|
||||
const auto tagUnderMouse =
|
||||
Utils::findOrDefault(m_currentTagRects,
|
||||
[&mousePos](const QPair<QString, QRect> &tag) {
|
||||
return tag.second.contains(mousePos);
|
||||
});
|
||||
if (!tagUnderMouse.first.isEmpty())
|
||||
emit tagClicked(tagUnderMouse.first);
|
||||
else
|
||||
clickAction(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user