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 (hovered) {
|
||||||
if (index != m_previousIndex) {
|
if (index != m_previousIndex) {
|
||||||
m_previousIndex = index;
|
m_previousIndex = index;
|
||||||
|
m_currentTagRects.clear();
|
||||||
m_blurredThumbnail = QPixmap();
|
m_blurredThumbnail = QPixmap();
|
||||||
m_startTime.start();
|
m_startTime.start();
|
||||||
m_currentWidget = qobject_cast<QAbstractItemView *>(
|
m_currentWidget = qobject_cast<QAbstractItemView *>(
|
||||||
@@ -521,10 +522,10 @@ void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
|||||||
painter->drawText(tagsLabelRect, tagsLabelText);
|
painter->drawText(tagsLabelRect, tagsLabelText);
|
||||||
|
|
||||||
painter->setPen(themeColor(Theme::Welcome_LinkColor));
|
painter->setPen(themeColor(Theme::Welcome_LinkColor));
|
||||||
m_currentTagRects.clear();
|
|
||||||
int emptyTagRowsLeft = 2;
|
int emptyTagRowsLeft = 2;
|
||||||
int xx = 0;
|
int xx = 0;
|
||||||
int yy = 0;
|
int yy = 0;
|
||||||
|
const bool populateTagsRects = m_currentTagRects.empty();
|
||||||
for (const QString &tag : item->tags) {
|
for (const QString &tag : item->tags) {
|
||||||
const int ww = fm.horizontalAdvance(tag) + tagsHorSpacing;
|
const int ww = fm.horizontalAdvance(tag) + tagsHorSpacing;
|
||||||
if (xx + ww > textArea.width() - tagsLabelRect.width()) {
|
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())
|
const QRect tagRect = QRect(xx, yy, ww, tagsLabelRect.height())
|
||||||
.translated(tagsLabelRect.topRight());
|
.translated(tagsLabelRect.topRight());
|
||||||
painter->drawText(tagRect, tag);
|
painter->drawText(tagRect, tag);
|
||||||
m_currentTagRects.append({ tag, tagRect.translated(rc.topLeft()) });
|
if (populateTagsRects)
|
||||||
|
m_currentTagRects.append({ tag, tagRect });
|
||||||
xx += ww;
|
xx += ww;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,16 +558,16 @@ bool ListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
const QPoint pos = mev->pos();
|
const QPoint mousePos = mev->pos() - option.rect.topLeft();
|
||||||
if (pos.y() > option.rect.y() + TagsSeparatorY) {
|
const auto tagUnderMouse =
|
||||||
//const QStringList tags = idx.data(Tags).toStringList();
|
Utils::findOrDefault(m_currentTagRects,
|
||||||
for (const auto &it : qAsConst(m_currentTagRects)) {
|
[&mousePos](const QPair<QString, QRect> &tag) {
|
||||||
if (it.second.contains(pos))
|
return tag.second.contains(mousePos);
|
||||||
emit tagClicked(it.first);
|
});
|
||||||
}
|
if (!tagUnderMouse.first.isEmpty())
|
||||||
} else {
|
emit tagClicked(tagUnderMouse.first);
|
||||||
|
else
|
||||||
clickAction(item);
|
clickAction(item);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||||
|
|||||||
Reference in New Issue
Block a user