From 7ac1b852b75837c391ae06490b17037bf9ac7591 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 7 Mar 2018 16:30:27 +0100 Subject: [PATCH] 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 --- src/plugins/bineditor/bineditorwidget.cpp | 33 ++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/plugins/bineditor/bineditorwidget.cpp b/src/plugins/bineditor/bineditorwidget.cpp index e647432723c..bb61571fb17 100644 --- a/src/plugins/bineditor/bineditorwidget.cpp +++ b/src/plugins/bineditor/bineditorwidget.cpp @@ -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;