summaryrefslogtreecommitdiffstats
path: root/ui/qt/widgets/follow_stream_text.cpp
blob: a8e0f2b9618daed54350523ba3404c97090c7d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* follow_stream_text.cpp
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <ui/qt/widgets/follow_stream_text.h>

#include <main_application.h>

#include <QMouseEvent>
#include <QTextCursor>

// To do:
// - Draw text by hand similar to ByteViewText. This would let us add
//   extra information, e.g. a timestamp column and get rid of
//   max_document_length_ in FollowStreamDialog.

FollowStreamText::FollowStreamText(QWidget *parent) :
    QPlainTextEdit(parent)
{
    setMouseTracking(true);
//    setMaximumBlockCount(1);
    QTextDocument *text_doc = document();
    text_doc->setDefaultFont(mainApp->monospaceFont());
}

void FollowStreamText::mouseMoveEvent(QMouseEvent *event)
{
    emit mouseMovedToTextCursorPosition(cursorForPosition(event->pos()).position());
    // Don't send the mouseMoveEvents with no buttons pushed to the base
    // class, effectively turning off mouse tracking for the base class.
    // It causes a lot of useless calculations that hurt scroll performance.
    if (event->buttons() != Qt::NoButton) {
        QPlainTextEdit::mouseMoveEvent(event);
    }
}

void FollowStreamText::mousePressEvent(QMouseEvent *event)
{
    emit mouseClickedOnTextCursorPosition(cursorForPosition(event->pos()).position());
    QPlainTextEdit::mousePressEvent(event);
}

void FollowStreamText::leaveEvent(QEvent *event)
{
    emit mouseMovedToTextCursorPosition(-1);
    QPlainTextEdit::leaveEvent(event);
}