Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/text/kpToolText_Create.cpp
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 125 | #if DEBUG_KP_TOOL_TEXT && 1 | |||
---|---|---|---|---|---|
126 | qCDebug(kpLogTools) << "\ttext box deselect - NOP - return"; | 126 | qCDebug(kpLogTools) << "\ttext box deselect - NOP - return"; | ||
127 | #endif | 127 | #endif | ||
128 | // We must be attempting to deselect the text box. | 128 | // We must be attempting to deselect the text box. | ||
129 | // This deselection has already been done by kpAbstractSelectionTool::beginDraw(). | 129 | // This deselection has already been done by kpAbstractSelectionTool::beginDraw(). | ||
130 | // Therefore, we are not doing a drag. | 130 | // Therefore, we are not doing a drag. | ||
131 | return false; | 131 | return false; | ||
132 | } | 132 | } | ||
133 | // We are probably creating a new box. | 133 | // We are probably creating a new box. | ||
134 | else | 134 | | ||
135 | { | 135 | | ||
136 | // This drag is currently a click -- not a drag. | 136 | // This drag is currently a click -- not a drag. | ||
137 | // As a special case, allow user to create a text box, | 137 | // As a special case, allow user to create a text box, | ||
138 | // of reasonable ("preferred minimum") size, using a single | 138 | // of reasonable ("preferred minimum") size, using a single | ||
139 | // click. | 139 | // click. | ||
140 | // | 140 | // | ||
141 | // If the user drags further, the normal drag-to-create-a-textbox | 141 | // If the user drags further, the normal drag-to-create-a-textbox | ||
142 | // branch [x] will execute and the size will be determined based on | 142 | // branch [x] will execute and the size will be determined based on | ||
143 | // the size of the drag instead. | 143 | // the size of the drag instead. | ||
144 | 144 | | |||
145 | #if DEBUG_KP_TOOL_TEXT && 1 | 145 | #if DEBUG_KP_TOOL_TEXT && 1 | ||
146 | qCDebug(kpLogTools) << "\tclick creating text box"; | 146 | qCDebug(kpLogTools) << "\tclick creating text box"; | ||
147 | #endif | 147 | #endif | ||
148 | 148 | | |||
149 | // (Click creating text box with RMB would not be obvious | 149 | // (Click creating text box with RMB would not be obvious | ||
150 | // since RMB menu most likely hides text box immediately | 150 | // since RMB menu most likely hides text box immediately | ||
151 | // afterwards) | 151 | // afterwards) | ||
152 | // TODO: I suspect this logic is simply too late | 152 | // TODO: I suspect this logic is simply too late | ||
153 | // TODO: We setUserShapePoints() on return but didn't before. | 153 | // TODO: We setUserShapePoints() on return but didn't before. | ||
154 | if (mouseButton () == 1) | 154 | if (mouseButton () == 1) { | ||
155 | return false/*do not create text box*/; | 155 | return false/*do not create text box*/; | ||
156 | } | ||||
156 | 157 | | |||
157 | 158 | | |||
158 | // Calculate suggested width. | 159 | // Calculate suggested width. | ||
159 | *minimumWidthOut = calcClickCreateDimension ( | 160 | *minimumWidthOut = calcClickCreateDimension ( | ||
160 | startPoint ().x (), | 161 | startPoint ().x (), | ||
161 | accidentalDragAdjustedPoint.x (), | 162 | accidentalDragAdjustedPoint.x (), | ||
162 | kpTextSelection::PreferredMinimumWidthForTextStyle (textStyle), | 163 | kpTextSelection::PreferredMinimumWidthForTextStyle (textStyle), | ||
163 | kpTextSelection::MinimumWidthForTextStyle (textStyle), | 164 | kpTextSelection::MinimumWidthForTextStyle (textStyle), | ||
Show All 11 Lines | |||||
175 | // Do _not_ set "newDragAccepted" to true as we want | 176 | // Do _not_ set "newDragAccepted" to true as we want | ||
176 | // this text box to remain at the click-given size, in the absence | 177 | // this text box to remain at the click-given size, in the absence | ||
177 | // of any dragging. In other words, if draw() is called again | 178 | // of any dragging. In other words, if draw() is called again | ||
178 | // and therefore, we are called again, but the mouse has not | 179 | // and therefore, we are called again, but the mouse has not | ||
179 | // moved, we do want this branch to execute again, not | 180 | // moved, we do want this branch to execute again, not | ||
180 | // Branch [x]. | 181 | // Branch [x]. | ||
181 | return true/*do create text box*/; | 182 | return true/*do create text box*/; | ||
182 | } | 183 | } | ||
183 | } | | |||
184 | // Dragging to create a text box [x]. | 184 | // Dragging to create a text box [x]. | ||
185 | // | 185 | // | ||
186 | // The size will be determined based on the size of the drag. | 186 | // The size will be determined based on the size of the drag. | ||
187 | else | 187 | | ||
188 | { | 188 | | ||
189 | #if DEBUG_KP_TOOL_TEXT && 1 | 189 | #if DEBUG_KP_TOOL_TEXT && 1 | ||
190 | qCDebug(kpLogTools) << "\tdrag creating text box"; | 190 | qCDebug(kpLogTools) << "\tdrag creating text box"; | ||
191 | #endif | 191 | #endif | ||
192 | *minimumWidthOut = kpTextSelection::MinimumWidthForTextStyle (textStyle); | 192 | *minimumWidthOut = kpTextSelection::MinimumWidthForTextStyle (textStyle); | ||
193 | *minimumHeightOut = kpTextSelection::MinimumHeightForTextStyle (textStyle); | 193 | *minimumHeightOut = kpTextSelection::MinimumHeightForTextStyle (textStyle); | ||
194 | 194 | | |||
195 | *newDragAccepted = true; | 195 | *newDragAccepted = true; | ||
196 | return true/*do create text box*/; | 196 | return true/*do create text box*/; | ||
197 | } | 197 | } | ||
198 | 198 | | |||
199 | } | | |||
200 | | ||||
201 | // protected virtual [kpAbstractSelectionTool] | 199 | // protected virtual [kpAbstractSelectionTool] | ||
202 | bool kpToolText::drawCreateMoreSelectionAndUpdateStatusBar ( | 200 | bool kpToolText::drawCreateMoreSelectionAndUpdateStatusBar ( | ||
203 | bool dragAccepted, | 201 | bool dragAccepted, | ||
204 | const QPoint &accidentalDragAdjustedPoint, | 202 | const QPoint &accidentalDragAdjustedPoint, | ||
205 | const QRect &normalizedRectIn) | 203 | const QRect &normalizedRectIn) | ||
206 | { | 204 | { | ||
207 | // (will mutate this) | 205 | // (will mutate this) | ||
208 | QRect normalizedRect = normalizedRectIn; | 206 | QRect normalizedRect = normalizedRectIn; | ||
Show All 16 Lines | 221 | { | |||
225 | return newDragAccepted; | 223 | return newDragAccepted; | ||
226 | } | 224 | } | ||
227 | 225 | | |||
228 | 226 | | |||
229 | // Make sure the dragged out rectangle is of the minimum width we just | 227 | // Make sure the dragged out rectangle is of the minimum width we just | ||
230 | // calculated. | 228 | // calculated. | ||
231 | if (normalizedRect.width () < minimumWidth) | 229 | if (normalizedRect.width () < minimumWidth) | ||
232 | { | 230 | { | ||
233 | if (accidentalDragAdjustedPoint.x () >= startPoint ().x ()) | 231 | if (accidentalDragAdjustedPoint.x () >= startPoint ().x ()) { | ||
234 | normalizedRect.setWidth (minimumWidth); | 232 | normalizedRect.setWidth (minimumWidth); | ||
235 | else | 233 | } | ||
234 | else { | ||||
236 | normalizedRect.setX (normalizedRect.right () - minimumWidth + 1); | 235 | normalizedRect.setX (normalizedRect.right () - minimumWidth + 1); | ||
237 | } | 236 | } | ||
237 | } | ||||
238 | 238 | | |||
239 | // Make sure the dragged out rectangle is of the minimum height we just | 239 | // Make sure the dragged out rectangle is of the minimum height we just | ||
240 | // calculated. | 240 | // calculated. | ||
241 | if (normalizedRect.height () < minimumHeight) | 241 | if (normalizedRect.height () < minimumHeight) | ||
242 | { | 242 | { | ||
243 | if (accidentalDragAdjustedPoint.y () >= startPoint ().y ()) | 243 | if (accidentalDragAdjustedPoint.y () >= startPoint ().y ()) { | ||
244 | normalizedRect.setHeight (minimumHeight); | 244 | normalizedRect.setHeight (minimumHeight); | ||
245 | else | 245 | } | ||
246 | else { | ||||
246 | normalizedRect.setY (normalizedRect.bottom () - minimumHeight + 1); | 247 | normalizedRect.setY (normalizedRect.bottom () - minimumHeight + 1); | ||
247 | } | 248 | } | ||
249 | } | ||||
248 | 250 | | |||
249 | #if DEBUG_KP_TOOL_TEXT && 1 | 251 | #if DEBUG_KP_TOOL_TEXT && 1 | ||
250 | qCDebug(kpLogTools) << "\t\tnormalizedRect=" << normalizedRect | 252 | qCDebug(kpLogTools) << "\t\tnormalizedRect=" << normalizedRect | ||
251 | << " kpTextSelection::preferredMinimumSize=" | 253 | << " kpTextSelection::preferredMinimumSize=" | ||
252 | << QSize (minimumWidth, minimumHeight) | 254 | << QSize (minimumWidth, minimumHeight); | ||
253 | << endl; | | |||
254 | #endif | 255 | #endif | ||
255 | 256 | | |||
256 | 257 | | |||
257 | // | 258 | // | ||
258 | // Construct and Deploy Text Box. | 259 | // Construct and Deploy Text Box. | ||
259 | // | 260 | // | ||
260 | 261 | | |||
261 | // Create empty text box. | 262 | // Create empty text box. | ||
262 | QList <QString> textLines; | 263 | QList <QString> textLines; | ||
263 | kpTextSelection textSel (normalizedRect, textLines, textStyle); | 264 | kpTextSelection textSel (normalizedRect, textLines, textStyle); | ||
264 | 265 | | |||
265 | // Render. | 266 | // Render. | ||
266 | viewManager ()->setTextCursorPosition (0, 0); | 267 | viewManager ()->setTextCursorPosition (0, 0); | ||
267 | document ()->setSelection (textSel); | 268 | document ()->setSelection (textSel); | ||
268 | 269 | | |||
269 | 270 | | |||
270 | // | 271 | // | ||
271 | // Update Status Bar. | 272 | // Update Status Bar. | ||
272 | // | 273 | // | ||
273 | 274 | | |||
274 | QPoint actualEndPoint = KP_INVALID_POINT; | 275 | QPoint actualEndPoint = KP_INVALID_POINT; | ||
275 | if (startPoint () == normalizedRect.topLeft ()) | 276 | if (startPoint () == normalizedRect.topLeft ()) { | ||
276 | actualEndPoint = normalizedRect.bottomRight (); | 277 | actualEndPoint = normalizedRect.bottomRight (); | ||
277 | else if (startPoint () == normalizedRect.bottomRight ()) | 278 | } | ||
279 | else if (startPoint () == normalizedRect.bottomRight ()) { | ||||
278 | actualEndPoint = normalizedRect.topLeft (); | 280 | actualEndPoint = normalizedRect.topLeft (); | ||
279 | else if (startPoint () == normalizedRect.topRight ()) | 281 | } | ||
282 | else if (startPoint () == normalizedRect.topRight ()) { | ||||
280 | actualEndPoint = normalizedRect.bottomLeft (); | 283 | actualEndPoint = normalizedRect.bottomLeft (); | ||
281 | else if (startPoint () == normalizedRect.bottomLeft ()) | 284 | } | ||
285 | else if (startPoint () == normalizedRect.bottomLeft ()) { | ||||
282 | actualEndPoint = normalizedRect.topRight (); | 286 | actualEndPoint = normalizedRect.topRight (); | ||
287 | } | ||||
283 | 288 | | |||
284 | setUserShapePoints (startPoint (), actualEndPoint); | 289 | setUserShapePoints (startPoint (), actualEndPoint); | ||
285 | 290 | | |||
286 | return newDragAccepted; | 291 | return newDragAccepted; | ||
287 | } | 292 | } | ||
288 | 293 | |