Fix binary editor tool tip

It should show up also over the last column, it should also show up if
the selection spans multiple lines, and if the mouse is not over the
selection it show up with information about the single byte under
cursor. If the mouse is over a selection that is longer than 8 bytes,
the tool tip is restricted to the first 8 bytes of the selection.

Task-number: QTCREATORBUG-17573
Change-Id: Ie7aaf1e52ceadd6be815d4ce3386a60df1418297
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-03-07 16:30:27 +01:00
parent 84e0573cad
commit 7ac1b852b7

View File

@@ -1147,16 +1147,31 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
{
int selStart = selectionStart();
int selEnd = selectionEnd();
int byteCount = selEnd - selStart + 1;
if (m_hexCursor == 0 || byteCount > 8)
return QString();
int byteCount = std::min(8, selEnd - selStart + 1);
const QPoint &startPoint = offsetToPos(selStart);
const QPoint &endPoint = offsetToPos(selEnd + 1);
QRect selRect(startPoint, endPoint);
selRect.setHeight(m_lineHeight);
if (!selRect.contains(helpEvent->pos()))
return QString();
// check even position against selection line by line
bool insideSelection = false;
int startInLine = selStart;
do {
const int lineIndex = startInLine / m_bytesPerLine;
const int endOfLine = (lineIndex + 1) * m_bytesPerLine - 1;
const int endInLine = std::min(selEnd, endOfLine);
const QPoint &startPoint = offsetToPos(startInLine);
const QPoint &endPoint = offsetToPos(endInLine) + QPoint(m_columnWidth, 0);
QRect selectionLineRect(startPoint, endPoint);
selectionLineRect.setHeight(m_lineHeight);
if (selectionLineRect.contains(helpEvent->pos())) {
insideSelection = true;
break;
}
startInLine = endInLine + 1;
} while (startInLine <= selEnd);
if (!insideSelection) {
// show popup for byte under cursor
selStart = posAt(helpEvent->pos());
selEnd = selStart;
byteCount = 1;
}
quint64 bigEndianValue, littleEndianValue;
quint64 bigEndianValueOld, littleEndianValueOld;