Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateviewinternal.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include "katemessagewidget.h" | 42 | #include "katemessagewidget.h" | ||
43 | #include "kateglobal.h" | 43 | #include "kateglobal.h" | ||
44 | #include "kateabstractinputmodefactory.h" | 44 | #include "kateabstractinputmodefactory.h" | ||
45 | #include "kateabstractinputmode.h" | 45 | #include "kateabstractinputmode.h" | ||
46 | #include "katepartdebug.h" | 46 | #include "katepartdebug.h" | ||
47 | 47 | | |||
48 | #include <ktexteditor/movingrange.h> | 48 | #include <ktexteditor/movingrange.h> | ||
49 | #include <ktexteditor/documentcursor.h> | 49 | #include <ktexteditor/documentcursor.h> | ||
50 | #include <ktexteditor/inlinenoteprovider.h> | ||||
50 | #include <ktexteditor/texthintinterface.h> | 51 | #include <ktexteditor/texthintinterface.h> | ||
51 | #include <KCursor> | 52 | #include <KCursor> | ||
52 | 53 | | |||
53 | #include <QMimeData> | 54 | #include <QMimeData> | ||
54 | #include <QAccessible> | 55 | #include <QAccessible> | ||
55 | #include <QClipboard> | 56 | #include <QClipboard> | ||
56 | #include <QKeyEvent> | 57 | #include <QKeyEvent> | ||
57 | #include <QPainter> | 58 | #include <QPainter> | ||
▲ Show 20 Lines • Show All 2524 Lines • ▼ Show 20 Line(s) | 2582 | if (m_view->contextMenu()) { | |||
2582 | m_view->spellingMenu()->setUseMouseForMisspelledRange((e->reason() == QContextMenuEvent::Mouse)); | 2583 | m_view->spellingMenu()->setUseMouseForMisspelledRange((e->reason() == QContextMenuEvent::Mouse)); | ||
2583 | m_view->contextMenu()->popup(mapToGlobal(p)); | 2584 | m_view->contextMenu()->popup(mapToGlobal(p)); | ||
2584 | e->accept(); | 2585 | e->accept(); | ||
2585 | } | 2586 | } | ||
2586 | } | 2587 | } | ||
2587 | 2588 | | |||
2588 | void KateViewInternal::mousePressEvent(QMouseEvent *e) | 2589 | void KateViewInternal::mousePressEvent(QMouseEvent *e) | ||
2589 | { | 2590 | { | ||
2591 | // was an inline note clicked? | ||||
2592 | auto note = inlineNoteAt(e->pos()); | ||||
2593 | if (note.isValid()) { | ||||
2594 | note.provider()->inlineNoteActivated(note, e->button(), toNoteCoordinates(e->pos(), note)); | ||||
2595 | return; | ||||
2596 | } | ||||
2597 | | ||||
2598 | // no -- continue with normal handling | ||||
2590 | switch (e->button()) { | 2599 | switch (e->button()) { | ||
2591 | case Qt::LeftButton: | 2600 | case Qt::LeftButton: | ||
2601 | | ||||
2592 | m_selChangedByUser = false; | 2602 | m_selChangedByUser = false; | ||
2593 | 2603 | | |||
2594 | if (m_possibleTripleClick) { | 2604 | if (m_possibleTripleClick) { | ||
2595 | m_possibleTripleClick = false; | 2605 | m_possibleTripleClick = false; | ||
2596 | 2606 | | |||
2597 | m_selectionMode = Line; | 2607 | m_selectionMode = Line; | ||
2598 | 2608 | | |||
2599 | if (e->modifiers() & Qt::ShiftModifier) { | 2609 | if (e->modifiers() & Qt::ShiftModifier) { | ||
▲ Show 20 Lines • Show All 270 Lines • ▼ Show 20 Line(s) | |||||
2870 | void KateViewInternal::mouseMoveEvent(QMouseEvent *e) | 2880 | void KateViewInternal::mouseMoveEvent(QMouseEvent *e) | ||
2871 | { | 2881 | { | ||
2872 | KTextEditor::Cursor newPosition = coordinatesToCursor(e->pos(), false); | 2882 | KTextEditor::Cursor newPosition = coordinatesToCursor(e->pos(), false); | ||
2873 | if (newPosition != m_mouse) { | 2883 | if (newPosition != m_mouse) { | ||
2874 | m_mouse = newPosition; | 2884 | m_mouse = newPosition; | ||
2875 | mouseMoved(); | 2885 | mouseMoved(); | ||
2876 | } | 2886 | } | ||
2877 | 2887 | | |||
2888 | if (e->buttons() == Qt::NoButton) { | ||||
2889 | auto note = inlineNoteAt(e->pos()); | ||||
2890 | if (note.isValid()) { | ||||
2891 | const auto notePos = toNoteCoordinates(e->pos(), note); | ||||
2892 | if (!m_activeInlineNote.isValid()) { | ||||
2893 | // no active note -- focus in | ||||
2894 | note.provider()->inlineNoteFocusInEvent(note, notePos); | ||||
2895 | m_activeInlineNote = note; | ||||
2896 | } | ||||
2897 | else { | ||||
2898 | note.provider()->inlineNoteMouseMoveEvent(note, notePos); | ||||
2899 | } | ||||
2900 | // the note might change its appearance in result to the event | ||||
2901 | tagLines(note.position(), note.position(), true); | ||||
2902 | } | ||||
2903 | else if (m_activeInlineNote.isValid()) { | ||||
2904 | m_activeInlineNote.provider()->inlineNoteFocusOutEvent(m_activeInlineNote); | ||||
2905 | tagLines(m_activeInlineNote.position(), m_activeInlineNote.position(), true); | ||||
2906 | m_activeInlineNote = {}; | ||||
2907 | } | ||||
2908 | } | ||||
2909 | | ||||
2878 | if (e->buttons() & Qt::LeftButton) { | 2910 | if (e->buttons() & Qt::LeftButton) { | ||
2879 | if (m_dragInfo.state == diPending) { | 2911 | if (m_dragInfo.state == diPending) { | ||
2880 | // we had a mouse down, but haven't confirmed a drag yet | 2912 | // we had a mouse down, but haven't confirmed a drag yet | ||
2881 | // if the mouse has moved sufficiently, we will confirm | 2913 | // if the mouse has moved sufficiently, we will confirm | ||
2882 | QPoint p(e->pos() - m_dragInfo.start); | 2914 | QPoint p(e->pos() - m_dragInfo.start); | ||
2883 | 2915 | | |||
2884 | // we've left the drag square, we can start a real drag operation now | 2916 | // we've left the drag square, we can start a real drag operation now | ||
2885 | if (p.manhattanLength() > QApplication::startDragDistance()) { | 2917 | if (p.manhattanLength() > QApplication::startDragDistance()) { | ||
▲ Show 20 Lines • Show All 966 Lines • ▼ Show 20 Line(s) | |||||
3852 | #ifndef QT_NO_ACCESSIBILITY | 3884 | #ifndef QT_NO_ACCESSIBILITY | ||
3853 | if (QAccessible::isActive()) { | 3885 | if (QAccessible::isActive()) { | ||
3854 | QAccessibleTextRemoveEvent ev(this, | 3886 | QAccessibleTextRemoveEvent ev(this, | ||
3855 | static_cast<KateViewAccessible *>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, range.start()), oldText); | 3887 | static_cast<KateViewAccessible *>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, range.start()), oldText); | ||
3856 | QAccessible::updateAccessibility(&ev); | 3888 | QAccessible::updateAccessibility(&ev); | ||
3857 | } | 3889 | } | ||
3858 | #endif | 3890 | #endif | ||
3859 | } | 3891 | } | ||
3892 | | ||||
3893 | QRect KateViewInternal::inlineNoteRect(const KTextEditor::InlineNote& note) const | ||||
3894 | { | ||||
3895 | // compute note width and position | ||||
3896 | auto noteWidth = note.width(); | ||||
3897 | auto noteCursor = KTextEditor::Cursor(note.position().line(), note.column()); | ||||
3898 | | ||||
3899 | // The cursor might be outside of the text. In that case, clamp it to the text and | ||||
3900 | // later on add the missing x offset. | ||||
3901 | const auto lineLength = view()->document()->lineLength(noteCursor.line()); | ||||
3902 | int extraOffset = 0; | ||||
3903 | if (noteCursor.column() > lineLength) { | ||||
3904 | extraOffset = (noteCursor.column() - lineLength) * renderer()->spaceWidth(); | ||||
3905 | noteCursor.setColumn(lineLength); | ||||
3906 | } | ||||
3907 | auto noteStartPos = cursorToCoordinate(noteCursor, true, false); | ||||
3908 | | ||||
3909 | // compute the note's rect | ||||
3910 | auto noteRect = QRect(noteStartPos + QPoint{extraOffset, 0}, QSize(noteWidth, renderer()->lineHeight())); | ||||
3911 | return noteRect; | ||||
3912 | } | ||||
3913 | | ||||
3914 | KTextEditor::InlineNote KateViewInternal::inlineNoteAt(const QPoint& pos) const | ||||
3915 | { | ||||
3916 | // compute the associated cursor to get the right line | ||||
3917 | auto cursor = m_view->coordinatesToCursor(pos); | ||||
3918 | auto inlineNotes = m_view->inlineNotes(cursor.line()); | ||||
3919 | // loop over all notes and check if the point is inside it | ||||
3920 | foreach (const auto& note, inlineNotes) { | ||||
3921 | auto noteRect = inlineNoteRect(note); | ||||
3922 | if (noteRect.contains(pos)) { | ||||
3923 | return note; | ||||
3924 | } | ||||
3925 | } | ||||
3926 | // none found -- return an invalid note | ||||
3927 | return {}; | ||||
3928 | } | ||||
3929 | | ||||
3930 | QPoint KateViewInternal::toNoteCoordinates(const QPoint& pos, const KTextEditor::InlineNote& note) const | ||||
3931 | { | ||||
3932 | return pos - inlineNoteRect(note).topLeft(); | ||||
3933 | } |