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