forked from qt-creator/qt-creator
TextEditor: Delay tooltips for text marks area
Like the tooltips on breakpoints. Tooltips on mouse hover should show up with a delay. Show them on QEvent::ToolTip, which is the usual way to handle that. Change-Id: Icb4cd3bc9ffc5bb5ff84020d72eade3e9980b79f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -343,6 +343,14 @@ protected:
|
|||||||
void wheelEvent(QWheelEvent *event) override {
|
void wheelEvent(QWheelEvent *event) override {
|
||||||
QCoreApplication::sendEvent(textEdit->viewport(), event);
|
QCoreApplication::sendEvent(textEdit->viewport(), event);
|
||||||
}
|
}
|
||||||
|
bool event(QEvent *event) override
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::ToolTip) {
|
||||||
|
textEdit->extraAreaToolTipEvent(static_cast<QHelpEvent *>(event));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return QWidget::event(event);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditorWidget *textEdit;
|
TextEditorWidget *textEdit;
|
||||||
@@ -7371,6 +7379,25 @@ void TextEditorWidget::updateFoldingHighlight(const QTextCursor &cursor)
|
|||||||
d->m_highlightBlocksTimer.start(d->m_highlightBlocksInfo.isEmpty() ? 120 : 0);
|
d->m_highlightBlocksTimer.start(d->m_highlightBlocksInfo.isEmpty() ? 120 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::extraAreaToolTipEvent(QHelpEvent *e)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
|
||||||
|
|
||||||
|
int markWidth = 0;
|
||||||
|
extraAreaWidth(&markWidth);
|
||||||
|
const bool inMarkArea = e->pos().x() <= markWidth && e->pos().x() >= 0;
|
||||||
|
if (!inMarkArea)
|
||||||
|
return;
|
||||||
|
int line = cursor.blockNumber() + 1;
|
||||||
|
if (d->extraAreaPreviousMarkTooltipRequestedLine != line) {
|
||||||
|
if (auto data = static_cast<TextBlockUserData *>(cursor.block().userData())) {
|
||||||
|
if (!data->marks().isEmpty())
|
||||||
|
d->showTextMarksToolTip(mapToGlobal(e->pos()), data->marks());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d->extraAreaPreviousMarkTooltipRequestedLine = line;
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
|
QTextCursor cursor = cursorForPosition(QPoint(0, e->pos().y()));
|
||||||
@@ -7387,16 +7414,14 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
|||||||
// Set whether the mouse cursor is a hand or normal arrow
|
// Set whether the mouse cursor is a hand or normal arrow
|
||||||
if (e->type() == QEvent::MouseMove) {
|
if (e->type() == QEvent::MouseMove) {
|
||||||
if (inMarkArea) {
|
if (inMarkArea) {
|
||||||
|
// tool tips are shown in extraAreaToolTipEvent
|
||||||
int line = cursor.blockNumber() + 1;
|
int line = cursor.blockNumber() + 1;
|
||||||
if (d->extraAreaPreviousMarkTooltipRequestedLine != line) {
|
if (d->extraAreaPreviousMarkTooltipRequestedLine != line) {
|
||||||
if (auto data = static_cast<TextBlockUserData *>(cursor.block().userData())) {
|
if (auto data = static_cast<TextBlockUserData *>(cursor.block().userData())) {
|
||||||
if (data->marks().isEmpty())
|
if (data->marks().isEmpty())
|
||||||
ToolTip::hide();
|
ToolTip::hide();
|
||||||
else
|
|
||||||
d->showTextMarksToolTip(mapToGlobal(e->pos()), data->marks());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d->extraAreaPreviousMarkTooltipRequestedLine = line;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->m_markDragging && e->buttons() & Qt::LeftButton && !d->m_markDragStart.isNull()) {
|
if (!d->m_markDragging && e->buttons() & Qt::LeftButton && !d->m_markDragStart.isNull()) {
|
||||||
|
@@ -312,6 +312,7 @@ public:
|
|||||||
virtual void extraAreaLeaveEvent(QEvent *);
|
virtual void extraAreaLeaveEvent(QEvent *);
|
||||||
virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
|
virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
|
||||||
virtual void extraAreaMouseEvent(QMouseEvent *);
|
virtual void extraAreaMouseEvent(QMouseEvent *);
|
||||||
|
virtual void extraAreaToolTipEvent(QHelpEvent *e);
|
||||||
void updateFoldingHighlight(const QPoint &pos);
|
void updateFoldingHighlight(const QPoint &pos);
|
||||||
void updateFoldingHighlight(const QTextCursor &cursor);
|
void updateFoldingHighlight(const QTextCursor &cursor);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user