Changeset View
Changeset View
Standalone View
Standalone View
autotests/src/inlinenote_test.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | 82 | } else if (note.position().column() == 10) { | |||
---|---|---|---|---|---|
83 | painter.setPen(Qt::darkRed); | 83 | painter.setPen(Qt::darkRed); | ||
84 | painter.setBrush(Qt::red); | 84 | painter.setBrush(Qt::red); | ||
85 | painter.drawRoundedRect(1, 1, note.width() - 2, note.lineHeight() - 2, 2, 2); | 85 | painter.drawRoundedRect(1, 1, note.width() - 2, note.lineHeight() - 2, 2, 2); | ||
86 | } | 86 | } | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | void inlineNoteActivated(const InlineNote ¬e, Qt::MouseButtons buttons, const QPoint &globalPos) override | 89 | void inlineNoteActivated(const InlineNote ¬e, Qt::MouseButtons buttons, const QPoint &globalPos) override | ||
90 | { | 90 | { | ||
91 | Q_UNUSED(note) | | |||
92 | Q_UNUSED(buttons) | 91 | Q_UNUSED(buttons) | ||
93 | Q_UNUSED(globalPos) | 92 | Q_UNUSED(globalPos) | ||
94 | ++noteActivatedCount; | 93 | ++noteActivatedCount; | ||
94 | lastUnderMouse = note.underMouse(); | ||||
95 | } | 95 | } | ||
96 | 96 | | |||
97 | void inlineNoteFocusInEvent(const InlineNote ¬e, const QPoint &globalPos) override | 97 | void inlineNoteFocusInEvent(const InlineNote ¬e, const QPoint &globalPos) override | ||
98 | { | 98 | { | ||
99 | Q_UNUSED(note) | | |||
100 | Q_UNUSED(globalPos) | 99 | Q_UNUSED(globalPos) | ||
101 | ++focusInCount; | 100 | ++focusInCount; | ||
101 | lastUnderMouse = note.underMouse(); | ||||
102 | | ||||
102 | } | 103 | } | ||
103 | 104 | | |||
104 | void inlineNoteFocusOutEvent(const InlineNote ¬e) override | 105 | void inlineNoteFocusOutEvent(const InlineNote ¬e) override | ||
105 | { | 106 | { | ||
106 | Q_UNUSED(note) | | |||
107 | ++focusOutCount; | 107 | ++focusOutCount; | ||
108 | // Here it should not be under the mosu | ||||
109 | lastUnderMouse = note.underMouse(); | ||||
108 | } | 110 | } | ||
109 | 111 | | |||
110 | void inlineNoteMouseMoveEvent(const InlineNote ¬e, const QPoint &globalPos) override | 112 | void inlineNoteMouseMoveEvent(const InlineNote ¬e, const QPoint &globalPos) override | ||
111 | { | 113 | { | ||
112 | Q_UNUSED(note) | | |||
113 | Q_UNUSED(globalPos) | 114 | Q_UNUSED(globalPos) | ||
114 | ++mouseMoveCount; | 115 | ++mouseMoveCount; | ||
116 | lastUnderMouse = note.underMouse(); | ||||
115 | } | 117 | } | ||
116 | 118 | | |||
117 | public: | 119 | public: | ||
118 | int noteActivatedCount = 0; | 120 | int noteActivatedCount = 0; | ||
119 | int focusInCount = 0; | 121 | int focusInCount = 0; | ||
120 | int focusOutCount = 0; | 122 | int focusOutCount = 0; | ||
121 | int mouseMoveCount = 0; | 123 | int mouseMoveCount = 0; | ||
124 | bool lastUnderMouse = false; | ||||
122 | }; | 125 | }; | ||
123 | } | 126 | } | ||
124 | 127 | | |||
125 | InlineNoteTest::InlineNoteTest() | 128 | InlineNoteTest::InlineNoteTest() | ||
126 | : QObject() | 129 | : QObject() | ||
127 | { | 130 | { | ||
128 | KTextEditor::EditorPrivate::enableUnitTestMode(); | 131 | KTextEditor::EditorPrivate::enableUnitTestMode(); | ||
129 | } | 132 | } | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 139 | { | |||
175 | QVERIFY(newCoordCol05.x() > coordCol05.x()); | 178 | QVERIFY(newCoordCol05.x() > coordCol05.x()); | ||
176 | QVERIFY(newCoordCol10.x() > coordCol10.x()); | 179 | QVERIFY(newCoordCol10.x() > coordCol10.x()); | ||
177 | 180 | | |||
178 | // so far, we should not have any activation event | 181 | // so far, we should not have any activation event | ||
179 | QCOMPARE(noteProvider.noteActivatedCount, 0); | 182 | QCOMPARE(noteProvider.noteActivatedCount, 0); | ||
180 | QCOMPARE(noteProvider.focusInCount, 0); | 183 | QCOMPARE(noteProvider.focusInCount, 0); | ||
181 | QCOMPARE(noteProvider.focusOutCount, 0); | 184 | QCOMPARE(noteProvider.focusOutCount, 0); | ||
182 | QCOMPARE(noteProvider.mouseMoveCount, 0); | 185 | QCOMPARE(noteProvider.mouseMoveCount, 0); | ||
186 | QVERIFY(noteProvider.lastUnderMouse == false); | ||||
183 | 187 | | |||
184 | // move mouse onto first note | 188 | // move mouse onto first note | ||
185 | auto internalView = findViewInternal(&view); | 189 | auto internalView = findViewInternal(&view); | ||
186 | QVERIFY(internalView); | 190 | QVERIFY(internalView); | ||
187 | 191 | | |||
188 | // focus in | 192 | // focus in | ||
189 | QTest::mouseMove(&view, coordCol05 + QPoint(xWidth / 2, 1)); | 193 | QTest::mouseMove(&view, coordCol05 + QPoint(xWidth / 2, 1)); | ||
190 | QTest::qWait(100); | 194 | QTest::qWait(100); | ||
191 | QCOMPARE(noteProvider.focusInCount, 1); | 195 | QCOMPARE(noteProvider.focusInCount, 1); | ||
192 | QCOMPARE(noteProvider.focusOutCount, 0); | 196 | QCOMPARE(noteProvider.focusOutCount, 0); | ||
193 | QCOMPARE(noteProvider.mouseMoveCount, 0); | 197 | QCOMPARE(noteProvider.mouseMoveCount, 0); | ||
194 | QCOMPARE(noteProvider.noteActivatedCount, 0); | 198 | QCOMPARE(noteProvider.noteActivatedCount, 0); | ||
199 | QVERIFY(noteProvider.lastUnderMouse); | ||||
195 | 200 | | |||
196 | // move one pixel | 201 | // move one pixel | ||
197 | QTest::mouseMove(&view, coordCol05 + QPoint(xWidth / 2 + 1, 1)); | 202 | QTest::mouseMove(&view, coordCol05 + QPoint(xWidth / 2 + 1, 1)); | ||
198 | QTest::qWait(100); | 203 | QTest::qWait(100); | ||
199 | QCOMPARE(noteProvider.focusInCount, 1); | 204 | QCOMPARE(noteProvider.focusInCount, 1); | ||
200 | QCOMPARE(noteProvider.focusOutCount, 0); | 205 | QCOMPARE(noteProvider.focusOutCount, 0); | ||
201 | QCOMPARE(noteProvider.mouseMoveCount, 1); | 206 | QCOMPARE(noteProvider.mouseMoveCount, 1); | ||
202 | QCOMPARE(noteProvider.noteActivatedCount, 0); | 207 | QCOMPARE(noteProvider.noteActivatedCount, 0); | ||
208 | QVERIFY(noteProvider.lastUnderMouse); | ||||
203 | 209 | | |||
204 | // activate | 210 | // activate | ||
205 | QTest::mousePress(internalView, Qt::LeftButton, Qt::NoModifier, internalView->mapFromGlobal(view.mapToGlobal(coordCol05 + QPoint(xWidth / 2 + 1, 1)))); | 211 | QTest::mousePress(internalView, Qt::LeftButton, Qt::NoModifier, internalView->mapFromGlobal(view.mapToGlobal(coordCol05 + QPoint(xWidth / 2 + 1, 1)))); | ||
206 | QTest::mouseRelease(internalView, Qt::LeftButton, Qt::NoModifier, internalView->mapFromGlobal(view.mapToGlobal(coordCol05 + QPoint(xWidth / 2 + 1, 1)))); | 212 | QTest::mouseRelease(internalView, Qt::LeftButton, Qt::NoModifier, internalView->mapFromGlobal(view.mapToGlobal(coordCol05 + QPoint(xWidth / 2 + 1, 1)))); | ||
207 | QTest::qWait(100); | 213 | QTest::qWait(100); | ||
208 | QCOMPARE(noteProvider.focusInCount, 1); | 214 | QCOMPARE(noteProvider.focusInCount, 1); | ||
209 | QCOMPARE(noteProvider.focusOutCount, 0); | 215 | QCOMPARE(noteProvider.focusOutCount, 0); | ||
210 | QCOMPARE(noteProvider.mouseMoveCount, 1); | 216 | QCOMPARE(noteProvider.mouseMoveCount, 1); | ||
211 | QCOMPARE(noteProvider.noteActivatedCount, 1); | 217 | QCOMPARE(noteProvider.noteActivatedCount, 1); | ||
218 | QVERIFY(noteProvider.lastUnderMouse); | ||||
212 | 219 | | |||
213 | // focus out | 220 | // focus out | ||
214 | QTest::mouseMove(&view, coordCol04 + QPoint(0, 1)); | 221 | QTest::mouseMove(&view, coordCol04 + QPoint(0, 1)); | ||
215 | QTest::mouseMove(&view, coordCol04 + QPoint(-1, 1)); | 222 | QTest::mouseMove(&view, coordCol04 + QPoint(-1, 1)); | ||
216 | QTest::qWait(200); | 223 | QTest::qWait(200); | ||
217 | QCOMPARE(noteProvider.focusInCount, 1); | 224 | QCOMPARE(noteProvider.focusInCount, 1); | ||
218 | QCOMPARE(noteProvider.focusOutCount, 1); | 225 | QCOMPARE(noteProvider.focusOutCount, 1); | ||
219 | QCOMPARE(noteProvider.mouseMoveCount, 1); | 226 | QCOMPARE(noteProvider.mouseMoveCount, 1); | ||
220 | QCOMPARE(noteProvider.noteActivatedCount, 1); | 227 | QCOMPARE(noteProvider.noteActivatedCount, 1); | ||
228 | QVERIFY(noteProvider.lastUnderMouse == false); | ||||
221 | 229 | | |||
222 | iface->unregisterInlineNoteProvider(¬eProvider); | 230 | iface->unregisterInlineNoteProvider(¬eProvider); | ||
223 | } | 231 | } | ||
224 | 232 | | |||
225 | // kate: indent-mode cstyle; indent-width 4; replace-tabs on; | 233 | // kate: indent-mode cstyle; indent-width 4; replace-tabs on; |