Changeset View
Changeset View
Standalone View
Standalone View
views/kpView_Selections.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 40 | return selection () ? | |||
---|---|---|---|---|---|
42 | QRect (); | 42 | QRect (); | ||
43 | 43 | | |||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | 46 | | |||
47 | // public | 47 | // public | ||
48 | QPoint kpView::mouseViewPointRelativeToSelection (const QPoint &viewPoint) const | 48 | QPoint kpView::mouseViewPointRelativeToSelection (const QPoint &viewPoint) const | ||
49 | { | 49 | { | ||
50 | if (!selection ()) | 50 | if (!selection ()) { | ||
51 | return KP_INVALID_POINT; | 51 | return KP_INVALID_POINT; | ||
52 | } | ||||
52 | 53 | | |||
53 | return mouseViewPoint (viewPoint) - transformDocToView (selection ()->topLeft ()); | 54 | return mouseViewPoint (viewPoint) - transformDocToView (selection ()->topLeft ()); | ||
54 | } | 55 | } | ||
55 | 56 | | |||
56 | // public | 57 | // public | ||
57 | bool kpView::mouseOnSelection (const QPoint &viewPoint) const | 58 | bool kpView::mouseOnSelection (const QPoint &viewPoint) const | ||
58 | { | 59 | { | ||
59 | const QRect selViewRect = selectionViewRect (); | 60 | const QRect selViewRect = selectionViewRect (); | ||
60 | if (!selViewRect.isValid ()) | 61 | if (!selViewRect.isValid ()) { | ||
61 | return false; | 62 | return false; | ||
63 | } | ||||
62 | 64 | | |||
63 | return selViewRect.contains (mouseViewPoint (viewPoint)); | 65 | return selViewRect.contains (mouseViewPoint (viewPoint)); | ||
64 | } | 66 | } | ||
65 | 67 | | |||
66 | 68 | | |||
67 | // public | 69 | // public | ||
68 | int kpView::textSelectionMoveBorderAtomicSize () const | 70 | int kpView::textSelectionMoveBorderAtomicSize () const | ||
69 | { | 71 | { | ||
70 | if (!textSelection ()) | 72 | if (!textSelection ()) { | ||
71 | return 0; | 73 | return 0; | ||
74 | } | ||||
72 | 75 | | |||
73 | return qMax (4, zoomLevelX () / 100); | 76 | return qMax (4, zoomLevelX () / 100); | ||
74 | } | 77 | } | ||
75 | 78 | | |||
76 | // public | 79 | // public | ||
77 | bool kpView::mouseOnSelectionToMove (const QPoint &viewPoint) const | 80 | bool kpView::mouseOnSelectionToMove (const QPoint &viewPoint) const | ||
78 | { | 81 | { | ||
79 | if (!mouseOnSelection (viewPoint)) | 82 | if (!mouseOnSelection (viewPoint)) { | ||
80 | return false; | 83 | return false; | ||
84 | } | ||||
81 | 85 | | |||
82 | if (!textSelection ()) | 86 | if (!textSelection ()) { | ||
83 | return true; | 87 | return true; | ||
88 | } | ||||
84 | 89 | | |||
85 | if (mouseOnSelectionResizeHandle (viewPoint)) | 90 | if (mouseOnSelectionResizeHandle (viewPoint)) { | ||
86 | return false; | 91 | return false; | ||
92 | } | ||||
87 | 93 | | |||
88 | 94 | | |||
89 | const QPoint viewPointRelSel = mouseViewPointRelativeToSelection (viewPoint); | 95 | const QPoint viewPointRelSel = mouseViewPointRelativeToSelection (viewPoint); | ||
90 | 96 | | |||
91 | // Middle point should always be selectable | 97 | // Middle point should always be selectable | ||
92 | const QPoint selCenterDocPoint = selection ()->boundingRect ().center (); | 98 | const QPoint selCenterDocPoint = selection ()->boundingRect ().center (); | ||
93 | if (tool () && | 99 | if (tool () && | ||
94 | tool ()->calculateCurrentPoint () == selCenterDocPoint) | 100 | tool ()->calculateCurrentPoint () == selCenterDocPoint) | ||
Show All 11 Lines | 109 | return (viewPointRelSel.x () < atomicSize || | |||
106 | viewPointRelSel.y () >= selViewRect.height () - atomicSize); | 112 | viewPointRelSel.y () >= selViewRect.height () - atomicSize); | ||
107 | } | 113 | } | ||
108 | 114 | | |||
109 | //--------------------------------------------------------------------- | 115 | //--------------------------------------------------------------------- | ||
110 | 116 | | |||
111 | // protected | 117 | // protected | ||
112 | bool kpView::selectionLargeEnoughToHaveResizeHandlesIfAtomicSize (int atomicSize) const | 118 | bool kpView::selectionLargeEnoughToHaveResizeHandlesIfAtomicSize (int atomicSize) const | ||
113 | { | 119 | { | ||
114 | if (!selection ()) | 120 | if (!selection ()) { | ||
115 | return false; | 121 | return false; | ||
122 | } | ||||
116 | 123 | | |||
117 | const QRect selViewRect = selectionViewRect (); | 124 | const QRect selViewRect = selectionViewRect (); | ||
118 | 125 | | |||
119 | return (selViewRect.width () >= atomicSize * 5 || | 126 | return (selViewRect.width () >= atomicSize * 5 || | ||
120 | selViewRect.height () >= atomicSize * 5); | 127 | selViewRect.height () >= atomicSize * 5); | ||
121 | } | 128 | } | ||
122 | 129 | | |||
123 | //--------------------------------------------------------------------- | 130 | //--------------------------------------------------------------------- | ||
Show All 20 Lines | |||||
144 | } | 151 | } | ||
145 | 152 | | |||
146 | //--------------------------------------------------------------------- | 153 | //--------------------------------------------------------------------- | ||
147 | 154 | | |||
148 | // public | 155 | // public | ||
149 | QRegion kpView::selectionResizeHandlesViewRegion (bool forRenderer) const | 156 | QRegion kpView::selectionResizeHandlesViewRegion (bool forRenderer) const | ||
150 | { | 157 | { | ||
151 | const int atomicLength = selectionResizeHandleAtomicSize (); | 158 | const int atomicLength = selectionResizeHandleAtomicSize (); | ||
152 | if (atomicLength <= 0) | 159 | if (atomicLength <= 0) { | ||
153 | return QRegion (); | 160 | return QRegion (); | ||
161 | } | ||||
154 | 162 | | |||
155 | 163 | | |||
156 | // HACK: At low zoom (e.g. 100%), resize handles will probably be too | 164 | // HACK: At low zoom (e.g. 100%), resize handles will probably be too | ||
157 | // big and overlap text / cursor / too much of selection. | 165 | // big and overlap text / cursor / too much of selection. | ||
158 | // | 166 | // | ||
159 | // So limit the _visual_ size of handles at low zoom. The | 167 | // So limit the _visual_ size of handles at low zoom. The | ||
160 | // handles' grab area remains the same for usability; so yes, | 168 | // handles' grab area remains the same for usability; so yes, | ||
161 | // there are a few pixels that don't look grabable but they are. | 169 | // there are a few pixels that don't look grabable but they are. | ||
162 | // | 170 | // | ||
163 | // The real solution is to be able to partially render the | 171 | // The real solution is to be able to partially render the | ||
164 | // handles outside of the selection view rect. If not possible, | 172 | // handles outside of the selection view rect. If not possible, | ||
165 | // at least for text boxes, render text on top of handles. | 173 | // at least for text boxes, render text on top of handles. | ||
166 | int normalAtomicLength = atomicLength; | 174 | int normalAtomicLength = atomicLength; | ||
167 | int vertEdgeAtomicLength = atomicLength; | 175 | int vertEdgeAtomicLength = atomicLength; | ||
168 | if (forRenderer && selection ()) | 176 | if (forRenderer && selection ()) | ||
169 | { | 177 | { | ||
170 | if (zoomLevelX () <= 150) | 178 | if (zoomLevelX () <= 150) | ||
171 | { | 179 | { | ||
172 | if (normalAtomicLength > 1) | 180 | if (normalAtomicLength > 1) { | ||
173 | normalAtomicLength--; | 181 | normalAtomicLength--; | ||
182 | } | ||||
174 | 183 | | |||
175 | if (vertEdgeAtomicLength > 1) | 184 | if (vertEdgeAtomicLength > 1) { | ||
176 | vertEdgeAtomicLength--; | 185 | vertEdgeAtomicLength--; | ||
177 | } | 186 | } | ||
187 | } | ||||
178 | 188 | | |||
179 | // 1 line of text? | 189 | // 1 line of text? | ||
180 | if (textSelection () && textSelection ()->textLines ().size () == 1) | 190 | if (textSelection () && textSelection ()->textLines ().size () == 1) | ||
181 | { | 191 | { | ||
182 | if (zoomLevelX () <= 150) | 192 | if (zoomLevelX () <= 150) { | ||
183 | vertEdgeAtomicLength = qMin (vertEdgeAtomicLength, qMax (2, zoomLevelX () / 100)); | 193 | vertEdgeAtomicLength = qMin (vertEdgeAtomicLength, qMax (2, zoomLevelX () / 100)); | ||
184 | else if (zoomLevelX () <= 250) | 194 | } | ||
195 | else if (zoomLevelX () <= 250) { | ||||
185 | vertEdgeAtomicLength = qMin (vertEdgeAtomicLength, qMax (3, zoomLevelX () / 100)); | 196 | vertEdgeAtomicLength = qMin (vertEdgeAtomicLength, qMax (3, zoomLevelX () / 100)); | ||
186 | } | 197 | } | ||
187 | } | 198 | } | ||
199 | } | ||||
188 | 200 | | |||
189 | 201 | | |||
190 | const QRect selViewRect = selectionViewRect (); | 202 | const QRect selViewRect = selectionViewRect (); | ||
191 | QRegion ret; | 203 | QRegion ret; | ||
192 | 204 | | |||
193 | // top left | 205 | // top left | ||
194 | ret += QRect(0, 0, normalAtomicLength, normalAtomicLength); | 206 | ret += QRect(0, 0, normalAtomicLength, normalAtomicLength); | ||
195 | 207 | | |||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 277 | #define LOCAL_POINT_IN_BOX_AT(x,y) \ | |||
266 | QRect ((x), (y), atomicLength, atomicLength).contains (viewPointRelSel) | 278 | QRect ((x), (y), atomicLength, atomicLength).contains (viewPointRelSel) | ||
267 | 279 | | |||
268 | // Favour the bottom & right and the corners. | 280 | // Favour the bottom & right and the corners. | ||
269 | if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, | 281 | if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, | ||
270 | selViewRect.height () - atomicLength)) | 282 | selViewRect.height () - atomicLength)) | ||
271 | { | 283 | { | ||
272 | return kpView::Bottom | kpView::Right; | 284 | return kpView::Bottom | kpView::Right; | ||
273 | } | 285 | } | ||
274 | else if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, 0)) | 286 | | ||
287 | if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, 0)) | ||||
275 | { | 288 | { | ||
276 | return kpView::Top | kpView::Right; | 289 | return kpView::Top | kpView::Right; | ||
277 | } | 290 | } | ||
278 | else if (LOCAL_POINT_IN_BOX_AT (0, selViewRect.height () - atomicLength)) | 291 | | ||
292 | if (LOCAL_POINT_IN_BOX_AT (0, selViewRect.height () - atomicLength)) | ||||
279 | { | 293 | { | ||
280 | return kpView::Bottom | kpView::Left; | 294 | return kpView::Bottom | kpView::Left; | ||
281 | } | 295 | } | ||
282 | else if (LOCAL_POINT_IN_BOX_AT (0, 0)) | 296 | | ||
297 | if (LOCAL_POINT_IN_BOX_AT (0, 0)) | ||||
283 | { | 298 | { | ||
284 | return kpView::Top | kpView::Left; | 299 | return kpView::Top | kpView::Left; | ||
285 | } | 300 | } | ||
286 | else if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, | 301 | | ||
302 | if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, | ||||
287 | (selViewRect.height () - atomicLength) / 2)) | 303 | (selViewRect.height () - atomicLength) / 2)) | ||
288 | { | 304 | { | ||
289 | return kpView::Right; | 305 | return kpView::Right; | ||
290 | } | 306 | } | ||
291 | else if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, | 307 | | ||
308 | if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, | ||||
292 | selViewRect.height () - atomicLength)) | 309 | selViewRect.height () - atomicLength)) | ||
293 | { | 310 | { | ||
294 | return kpView::Bottom; | 311 | return kpView::Bottom; | ||
295 | } | 312 | } | ||
296 | else if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, 0)) | 313 | | ||
314 | if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, 0)) | ||||
297 | { | 315 | { | ||
298 | return kpView::Top; | 316 | return kpView::Top; | ||
299 | } | 317 | } | ||
300 | else if (LOCAL_POINT_IN_BOX_AT (0, (selViewRect.height () - atomicLength) / 2)) | 318 | | ||
319 | if (LOCAL_POINT_IN_BOX_AT (0, (selViewRect.height () - atomicLength) / 2)) | ||||
301 | { | 320 | { | ||
302 | return kpView::Left; | 321 | return kpView::Left; | ||
303 | } | 322 | } | ||
304 | else | 323 | | ||
305 | { | | |||
306 | qCDebug(kpLogViews) << "\tnot on sel resize handle"; | 324 | qCDebug(kpLogViews) << "\tnot on sel resize handle"; | ||
307 | return 0; | 325 | return 0; | ||
308 | } | 326 | | ||
309 | #undef LOCAL_POINT_IN_BOX_AT | 327 | #undef LOCAL_POINT_IN_BOX_AT | ||
310 | } | 328 | } | ||
311 | 329 | | |||
312 | // public | 330 | // public | ||
313 | bool kpView::mouseOnSelectionToSelectText (const QPoint &viewPoint) const | 331 | bool kpView::mouseOnSelectionToSelectText (const QPoint &viewPoint) const | ||
314 | { | 332 | { | ||
315 | qCDebug(kpLogViews) << "kpView::mouseOnSelectionToSelectText(viewPoint=" | 333 | qCDebug(kpLogViews) << "kpView::mouseOnSelectionToSelectText(viewPoint=" | ||
316 | << viewPoint << ")"; | 334 | << viewPoint << ")"; | ||
Show All 19 Lines |