Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateviewinternal.cpp
Show All 38 Lines | |||||
39 | #include "spellcheck/spellingmenu.h" | 39 | #include "spellcheck/spellingmenu.h" | ||
40 | #include "kateviewaccessible.h" | 40 | #include "kateviewaccessible.h" | ||
41 | #include "katetextanimation.h" | 41 | #include "katetextanimation.h" | ||
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 | #include "inlinenotedata.h" | ||||
47 | 48 | | |||
48 | #include <ktexteditor/movingrange.h> | 49 | #include <ktexteditor/movingrange.h> | ||
49 | #include <ktexteditor/documentcursor.h> | 50 | #include <ktexteditor/documentcursor.h> | ||
50 | #include <ktexteditor/inlinenoteprovider.h> | 51 | #include <ktexteditor/inlinenoteprovider.h> | ||
51 | #include <ktexteditor/texthintinterface.h> | 52 | #include <ktexteditor/texthintinterface.h> | ||
52 | #include <KCursor> | 53 | #include <KCursor> | ||
53 | 54 | | |||
54 | #include <QMimeData> | 55 | #include <QMimeData> | ||
▲ Show 20 Lines • Show All 2529 Lines • ▼ Show 20 Line(s) | 2583 | if (m_view->contextMenu()) { | |||
2584 | m_view->contextMenu()->popup(mapToGlobal(p)); | 2585 | m_view->contextMenu()->popup(mapToGlobal(p)); | ||
2585 | e->accept(); | 2586 | e->accept(); | ||
2586 | } | 2587 | } | ||
2587 | } | 2588 | } | ||
2588 | 2589 | | |||
2589 | void KateViewInternal::mousePressEvent(QMouseEvent *e) | 2590 | void KateViewInternal::mousePressEvent(QMouseEvent *e) | ||
2590 | { | 2591 | { | ||
2591 | // was an inline note clicked? | 2592 | // was an inline note clicked? | ||
2592 | auto note = inlineNoteAt(e->pos()); | 2593 | const auto noteData = inlineNoteAt(e->pos()); | ||
2593 | if (note.isValid()) { | 2594 | const KTextEditor::InlineNote note(noteData); | ||
2594 | note.provider()->inlineNoteActivated(note, e->button(), toNoteCoordinates(e->pos(), note)); | 2595 | if (note.position().isValid()) { | ||
2596 | note.provider()->inlineNoteActivated(noteData, e->button(), toNoteCoordinates(e->pos(), noteData)); | ||||
2595 | return; | 2597 | return; | ||
2596 | } | 2598 | } | ||
2597 | 2599 | | |||
2598 | // no -- continue with normal handling | 2600 | // no -- continue with normal handling | ||
2599 | switch (e->button()) { | 2601 | switch (e->button()) { | ||
2600 | case Qt::LeftButton: | 2602 | case Qt::LeftButton: | ||
2601 | 2603 | | |||
2602 | m_selChangedByUser = false; | 2604 | m_selChangedByUser = false; | ||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Line(s) | |||||
2881 | { | 2883 | { | ||
2882 | KTextEditor::Cursor newPosition = coordinatesToCursor(e->pos(), false); | 2884 | KTextEditor::Cursor newPosition = coordinatesToCursor(e->pos(), false); | ||
2883 | if (newPosition != m_mouse) { | 2885 | if (newPosition != m_mouse) { | ||
2884 | m_mouse = newPosition; | 2886 | m_mouse = newPosition; | ||
2885 | mouseMoved(); | 2887 | mouseMoved(); | ||
2886 | } | 2888 | } | ||
2887 | 2889 | | |||
2888 | if (e->buttons() == Qt::NoButton) { | 2890 | if (e->buttons() == Qt::NoButton) { | ||
2889 | auto note = inlineNoteAt(e->pos()); | 2891 | const auto noteData = inlineNoteAt(e->pos()); | ||
2890 | if (note.isValid()) { | 2892 | const KTextEditor::InlineNote note(noteData); | ||
2891 | const auto notePos = toNoteCoordinates(e->pos(), note); | 2893 | const KTextEditor::InlineNote activeNote(m_activeInlineNote); | ||
2892 | if (!m_activeInlineNote.isValid()) { | 2894 | if (note.position().isValid()) { | ||
2895 | const auto notePos = toNoteCoordinates(e->pos(), noteData); | ||||
2896 | if (!activeNote.position().isValid()) { | ||||
2893 | // no active note -- focus in | 2897 | // no active note -- focus in | ||
2894 | note.provider()->inlineNoteFocusInEvent(note, notePos); | 2898 | note.provider()->inlineNoteFocusInEvent(note, notePos); | ||
2895 | m_activeInlineNote = note; | 2899 | m_activeInlineNote = noteData; | ||
2896 | } | 2900 | } | ||
2897 | else { | 2901 | else { | ||
2898 | note.provider()->inlineNoteMouseMoveEvent(note, notePos); | 2902 | note.provider()->inlineNoteMouseMoveEvent(note, notePos); | ||
2899 | } | 2903 | } | ||
2900 | // the note might change its appearance in result to the event | 2904 | // the note might change its appearance in result to the event | ||
2901 | tagLines(note.position(), note.position(), true); | 2905 | tagLines(note.position(), note.position(), true); | ||
2902 | } | 2906 | } | ||
2903 | else if (m_activeInlineNote.isValid()) { | 2907 | else if (activeNote.position().isValid()) { | ||
2904 | m_activeInlineNote.provider()->inlineNoteFocusOutEvent(m_activeInlineNote); | 2908 | activeNote.provider()->inlineNoteFocusOutEvent(activeNote); | ||
2905 | tagLines(m_activeInlineNote.position(), m_activeInlineNote.position(), true); | 2909 | tagLines(activeNote.position(), activeNote.position(), true); | ||
2906 | m_activeInlineNote = {}; | 2910 | m_activeInlineNote = {}; | ||
2907 | } | 2911 | } | ||
2908 | } | 2912 | } | ||
2909 | 2913 | | |||
2910 | if (e->buttons() & Qt::LeftButton) { | 2914 | if (e->buttons() & Qt::LeftButton) { | ||
2911 | if (m_dragInfo.state == diPending) { | 2915 | if (m_dragInfo.state == diPending) { | ||
2912 | // we had a mouse down, but haven't confirmed a drag yet | 2916 | // we had a mouse down, but haven't confirmed a drag yet | ||
2913 | // if the mouse has moved sufficiently, we will confirm | 2917 | // if the mouse has moved sufficiently, we will confirm | ||
▲ Show 20 Lines • Show All 984 Lines • ▼ Show 20 Line(s) | 3901 | #ifndef QT_NO_ACCESSIBILITY | |||
3898 | if (QAccessible::isActive()) { | 3902 | if (QAccessible::isActive()) { | ||
3899 | QAccessibleTextRemoveEvent ev(this, | 3903 | QAccessibleTextRemoveEvent ev(this, | ||
3900 | static_cast<KateViewAccessible *>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, range.start()), oldText); | 3904 | static_cast<KateViewAccessible *>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, range.start()), oldText); | ||
3901 | QAccessible::updateAccessibility(&ev); | 3905 | QAccessible::updateAccessibility(&ev); | ||
3902 | } | 3906 | } | ||
3903 | #endif | 3907 | #endif | ||
3904 | } | 3908 | } | ||
3905 | 3909 | | |||
3906 | QRect KateViewInternal::inlineNoteRect(const KTextEditor::InlineNote& note) const | 3910 | QRect KateViewInternal::inlineNoteRect(const KateInlineNoteData& noteData) const | ||
3907 | { | 3911 | { | ||
3912 | KTextEditor::InlineNote note(noteData); | ||||
3908 | // compute note width and position | 3913 | // compute note width and position | ||
3909 | auto noteWidth = note.width(); | 3914 | const auto noteWidth = note.width(); | ||
3910 | auto noteCursor = KTextEditor::Cursor(note.position().line(), note.column()); | 3915 | auto noteCursor = note.position(); | ||
3911 | 3916 | | |||
3912 | // The cursor might be outside of the text. In that case, clamp it to the text and | 3917 | // The cursor might be outside of the text. In that case, clamp it to the text and | ||
3913 | // later on add the missing x offset. | 3918 | // later on add the missing x offset. | ||
3914 | const auto lineLength = view()->document()->lineLength(noteCursor.line()); | 3919 | const auto lineLength = view()->document()->lineLength(noteCursor.line()); | ||
3915 | int extraOffset = 0; | 3920 | int extraOffset = 0; | ||
3916 | if (noteCursor.column() > lineLength) { | 3921 | if (noteCursor.column() > lineLength) { | ||
3917 | extraOffset = (noteCursor.column() - lineLength) * renderer()->spaceWidth(); | 3922 | extraOffset = (noteCursor.column() - lineLength) * renderer()->spaceWidth(); | ||
3918 | noteCursor.setColumn(lineLength); | 3923 | noteCursor.setColumn(lineLength); | ||
3919 | } | 3924 | } | ||
3920 | auto noteStartPos = cursorToCoordinate(noteCursor, true, false); | 3925 | auto noteStartPos = cursorToCoordinate(noteCursor, true, false); | ||
3921 | 3926 | | |||
3922 | // compute the note's rect | 3927 | // compute the note's rect | ||
3923 | auto noteRect = QRect(noteStartPos + QPoint{extraOffset, 0}, QSize(noteWidth, renderer()->lineHeight())); | 3928 | auto noteRect = QRect(noteStartPos + QPoint{extraOffset, 0}, QSize(noteWidth, renderer()->lineHeight())); | ||
3924 | return noteRect; | 3929 | return noteRect; | ||
3925 | } | 3930 | } | ||
3926 | 3931 | | |||
3927 | KTextEditor::InlineNote KateViewInternal::inlineNoteAt(const QPoint& pos) const | 3932 | KateInlineNoteData KateViewInternal::inlineNoteAt(const QPoint& pos) const | ||
3928 | { | 3933 | { | ||
3929 | // compute the associated cursor to get the right line | 3934 | // compute the associated cursor to get the right line | ||
3930 | auto cursor = m_view->coordinatesToCursor(pos); | 3935 | auto cursor = m_view->coordinatesToCursor(pos); | ||
3931 | auto inlineNotes = m_view->inlineNotes(cursor.line()); | 3936 | auto inlineNotes = m_view->inlineNotes(cursor.line()); | ||
3932 | // loop over all notes and check if the point is inside it | 3937 | // loop over all notes and check if the point is inside it | ||
3933 | foreach (const auto& note, inlineNotes) { | 3938 | foreach (const auto& note, inlineNotes) { | ||
3934 | auto noteRect = inlineNoteRect(note); | 3939 | auto noteRect = inlineNoteRect(note); | ||
3935 | if (noteRect.contains(pos)) { | 3940 | if (noteRect.contains(pos)) { | ||
3936 | return note; | 3941 | return note; | ||
3937 | } | 3942 | } | ||
3938 | } | 3943 | } | ||
3939 | // none found -- return an invalid note | 3944 | // none found -- return an invalid note | ||
3940 | return {}; | 3945 | return {}; | ||
3941 | } | 3946 | } | ||
3942 | 3947 | | |||
3943 | QPoint KateViewInternal::toNoteCoordinates(const QPoint& pos, const KTextEditor::InlineNote& note) const | 3948 | QPoint KateViewInternal::toNoteCoordinates(const QPoint& pos, const KateInlineNoteData& note) const | ||
3944 | { | 3949 | { | ||
3945 | return pos - inlineNoteRect(note).topLeft(); | 3950 | return pos - inlineNoteRect(note).topLeft(); | ||
3946 | } | 3951 | } |