aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2018-03-08 08:40:48 +0100
committerEike Ziller <eike.ziller@qt.io>2018-03-13 10:11:16 +0000
commit1d2b476320b8ba579587455bbd34b1ef485711e1 (patch)
tree75409b2a249e4691c671b75410f0636b388394ed /src
parent0bcc983cdbb74baebccfdb09f7d2ffb22ebf950d (diff)
BinEditor: Do now show tool tip if mouse is not over data
Task-number: QTCREATORBUG-17573 Change-Id: Ida0497006e702dfafe70f434373088325bbc6db7 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/bineditor/bineditorwidget.cpp39
-rw-r--r--src/plugins/bineditor/bineditorwidget.h4
2 files changed, 28 insertions, 15 deletions
diff --git a/src/plugins/bineditor/bineditorwidget.cpp b/src/plugins/bineditor/bineditorwidget.cpp
index 51d80a73c5..cb10c8a466 100644
--- a/src/plugins/bineditor/bineditorwidget.cpp
+++ b/src/plugins/bineditor/bineditorwidget.cpp
@@ -548,18 +548,21 @@ QRect BinEditorWidget::cursorRect() const
return QRect(x, y, w, m_lineHeight);
}
-int BinEditorWidget::posAt(const QPoint &pos) const
+Utils::optional<qint64> BinEditorWidget::posAt(const QPoint &pos, bool includeEmptyArea) const
{
const int xoffset = horizontalScrollBar()->value();
int x = xoffset + pos.x() - m_margin - m_labelWidth;
+ if (!includeEmptyArea && x < 0)
+ return Utils::nullopt;
int column = qMin(15, qMax(0,x) / m_columnWidth);
const qint64 topLine = verticalScrollBar()->value();
const qint64 line = topLine + pos.y() / m_lineHeight;
+ // "clear text" area
if (x > m_bytesPerLine * m_columnWidth + m_charWidth/2) {
x -= m_bytesPerLine * m_columnWidth + m_charWidth;
- for (column = 0; column < 15; ++column) {
- const int dataPos = line * m_bytesPerLine + column;
+ for (column = 0; column < 16; ++column) {
+ const qint64 dataPos = line * m_bytesPerLine + column;
if (dataPos < 0 || dataPos >= m_size)
break;
QChar qc(QLatin1Char(dataAt(dataPos)));
@@ -569,9 +572,14 @@ int BinEditorWidget::posAt(const QPoint &pos) const
if (x <= 0)
break;
}
+ if (!includeEmptyArea && x > 0) // right of the text area
+ return Utils::nullopt;
}
- return qMin(m_size - 1, line * m_bytesPerLine + column);
+ const qint64 bytePos = line * m_bytesPerLine + column;
+ if (!includeEmptyArea && bytePos >= m_size)
+ return Utils::nullopt;
+ return qMin(m_size - 1, bytePos);
}
bool BinEditorWidget::inTextArea(const QPoint &pos) const
@@ -1041,7 +1049,7 @@ void BinEditorWidget::mousePressEvent(QMouseEvent *e)
if (e->button() != Qt::LeftButton)
return;
MoveMode moveMode = e->modifiers() & Qt::ShiftModifier ? KeepAnchor : MoveAnchor;
- setCursorPosition(posAt(e->pos()), moveMode);
+ setCursorPosition(posAt(e->pos()).value(), moveMode);
setBlinkingCursorEnabled(true);
if (m_hexCursor == inTextArea(e->pos())) {
m_hexCursor = !m_hexCursor;
@@ -1053,7 +1061,7 @@ void BinEditorWidget::mouseMoveEvent(QMouseEvent *e)
{
if (!(e->buttons() & Qt::LeftButton))
return;
- setCursorPosition(posAt(e->pos()), KeepAnchor);
+ setCursorPosition(posAt(e->pos()).value(), KeepAnchor);
if (m_hexCursor == inTextArea(e->pos())) {
m_hexCursor = !m_hexCursor;
updateLines();
@@ -1144,17 +1152,17 @@ bool BinEditorWidget::event(QEvent *e)
QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
{
- int selStart = selectionStart();
- int selEnd = selectionEnd();
- int byteCount = std::min(8, selEnd - selStart + 1);
+ qint64 selStart = selectionStart();
+ qint64 selEnd = selectionEnd();
+ qint64 byteCount = std::min(8LL, selEnd - selStart + 1);
// check even position against selection line by line
bool insideSelection = false;
- int startInLine = selStart;
+ qint64 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 qint64 lineIndex = startInLine / m_bytesPerLine;
+ const qint64 endOfLine = (lineIndex + 1) * m_bytesPerLine - 1;
+ const qint64 endInLine = std::min(selEnd, endOfLine);
const QPoint &startPoint = offsetToPos(startInLine);
const QPoint &endPoint = offsetToPos(endInLine) + QPoint(m_columnWidth, 0);
QRect selectionLineRect(startPoint, endPoint);
@@ -1167,7 +1175,10 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
} while (startInLine <= selEnd);
if (!insideSelection) {
// show popup for byte under cursor
- selStart = posAt(helpEvent->pos());
+ Utils::optional<qint64> pos = posAt(helpEvent->pos(), /*includeEmptyArea*/false);
+ if (!pos)
+ return QString();
+ selStart = pos.value();
selEnd = selStart;
byteCount = 1;
}
diff --git a/src/plugins/bineditor/bineditorwidget.h b/src/plugins/bineditor/bineditorwidget.h
index 6794a77d38..ce02c93793 100644
--- a/src/plugins/bineditor/bineditorwidget.h
+++ b/src/plugins/bineditor/bineditorwidget.h
@@ -29,6 +29,8 @@
#include "markup.h"
#include "bineditorservice.h"
+#include <utils/optional.h>
+
#include <QBasicTimer>
#include <QMap>
#include <QSet>
@@ -210,7 +212,7 @@ private:
QBasicTimer m_cursorBlinkTimer;
void init();
- int posAt(const QPoint &pos) const;
+ Utils::optional<qint64> posAt(const QPoint &pos, bool includeEmptyArea = true) const;
bool inTextArea(const QPoint &pos) const;
QRect cursorRect() const;
void updateLines();