Rev 18438 | Rev 18846 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
12775 | jghali | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | /*************************************************************************** |
||
8 | * * |
||
9 | * This program is free software; you can redistribute it and/or modify * |
||
10 | * it under the terms of the GNU General Public License as published by * |
||
11 | * the Free Software Foundation; either version 2 of the License, or * |
||
12 | * (at your option) any later version. * |
||
13 | * * |
||
14 | ***************************************************************************/ |
||
15 | |||
16 | |||
17 | #include "canvasmode_edit.h" |
||
18 | |||
19 | #include <QApplication> |
||
20 | #include <QButtonGroup> |
||
21 | #include <QCheckBox> |
||
22 | #include <QCursor> |
||
23 | #include <QEvent> |
||
24 | #include <QMessageBox> |
||
25 | #include <QMouseEvent> |
||
26 | #include <QPainterPath> |
||
27 | #include <QPoint> |
||
16856 | craig | 28 | #include <QPointF> |
12775 | jghali | 29 | #include <QRect> |
30 | #include <QTimer> |
||
31 | #include <QWidgetAction> |
||
32 | #include <QDebug> |
||
33 | |||
14371 | jghali | 34 | |
12775 | jghali | 35 | #include "canvas.h" |
14371 | jghali | 36 | |
12775 | jghali | 37 | #include "fpoint.h" |
38 | #include "fpointarray.h" |
||
39 | #include "hyphenator.h" |
||
40 | #include "pageitem_textframe.h" |
||
41 | #include "prefscontext.h" |
||
42 | #include "prefsfile.h" |
||
43 | #include "prefsmanager.h" |
||
12809 | pierre | 44 | #include "sccolorengine.h" |
12841 | jghali | 45 | #include "scmimedata.h" |
12775 | jghali | 46 | #include "scribus.h" |
47 | #include "scribusdoc.h" |
||
48 | #include "scribusview.h" |
||
49 | #include "scribusXml.h" |
||
50 | #include "selection.h" |
||
14371 | jghali | 51 | #include "ui/aligndistribute.h" |
52 | #include "ui/contextmenu.h" |
||
15465 | avox | 53 | #include "ui/hruler.h" |
14371 | jghali | 54 | #include "ui/insertTable.h" |
55 | #include "ui/pageselector.h" |
||
56 | #include "ui/propertiespalette.h" |
||
12775 | jghali | 57 | #include "undomanager.h" |
58 | #include "units.h" |
||
59 | #include "util.h" |
||
60 | #include "util_icon.h" |
||
61 | #include "util_math.h" |
||
62 | |||
63 | |||
64 | CanvasMode_Edit::CanvasMode_Edit(ScribusView* view) : CanvasMode(view), m_ScMW(view->m_ScMW) |
||
65 | { |
||
66 | Mxp = Myp = -1; |
||
67 | Dxp = Dyp = -1; |
||
68 | oldCp = Cp = -1; |
||
69 | frameResizeHandle = -1; |
||
12809 | pierre | 70 | m_blinker = new QTimer(view); |
12775 | jghali | 71 | connect(m_blinker, SIGNAL(timeout()), this, SLOT(blinkTextCursor())); |
15465 | avox | 72 | connect(view->horizRuler, SIGNAL(MarkerMoved(double, double)), this, SLOT(rulerPreview(double, double))); |
73 | mRulerGuide = -1; |
||
16474 | craig | 74 | m_longCursorTime=false; |
12775 | jghali | 75 | } |
76 | |||
77 | inline bool CanvasMode_Edit::GetItem(PageItem** pi) |
||
78 | { |
||
79 | *pi = m_doc->m_Selection->itemAt(0); |
||
80 | return (*pi) != NULL; |
||
81 | } |
||
82 | |||
83 | |||
84 | void CanvasMode_Edit::blinkTextCursor() |
||
85 | { |
||
86 | PageItem* currItem; |
||
87 | if (m_doc->appMode == modeEdit && GetItem(&currItem)) |
||
88 | { |
||
17119 | fschmid | 89 | QRectF brect = QRectF(0, 0, currItem->width(), currItem->height()); |
90 | QTransform m = currItem->getTransform(); |
||
91 | brect = m.mapRect(brect); |
||
12775 | jghali | 92 | m_canvas->update(QRectF(m_canvas->canvasToLocal(brect.topLeft()), QSizeF(brect.width(),brect.height())*m_canvas->scale()).toRect()); |
93 | } |
||
94 | } |
||
95 | |||
16474 | craig | 96 | void CanvasMode_Edit::keyPressEvent(QKeyEvent *e) |
97 | { |
||
98 | PageItem* currItem; |
||
99 | if (GetItem(&currItem)) |
||
100 | { |
||
101 | PageItem_TextFrame* textframe = currItem->asTextFrame(); |
||
102 | if (textframe) |
||
103 | { |
||
104 | m_cursorVisible=true; |
||
105 | int kk = e->key(); |
||
106 | switch (kk) |
||
107 | { |
||
108 | case Qt::Key_PageUp: |
||
109 | case Qt::Key_PageDown: |
||
110 | case Qt::Key_Up: |
||
111 | case Qt::Key_Down: |
||
112 | case Qt::Key_Home: |
||
113 | case Qt::Key_End: |
||
114 | m_longCursorTime=true; |
||
115 | break; |
||
116 | default: |
||
117 | m_longCursorTime=false; |
||
118 | break; |
||
119 | } |
||
120 | blinkTextCursor(); |
||
121 | } |
||
122 | } |
||
123 | } |
||
15465 | avox | 124 | |
16474 | craig | 125 | |
126 | |||
15465 | avox | 127 | void CanvasMode_Edit::rulerPreview(double base, double xp) |
128 | { |
||
129 | PageItem* currItem; |
||
130 | if (m_doc->appMode == modeEdit && GetItem(&currItem)) |
||
131 | { |
||
17119 | fschmid | 132 | QTransform mm = currItem->getTransform(); |
133 | QPointF itPos = mm.map(QPointF(0, currItem->yPos())); |
||
134 | QPoint oldP = m_canvas->canvasToLocal(QPointF(mRulerGuide, itPos.y())); |
||
15465 | avox | 135 | mRulerGuide = base + xp; |
17119 | fschmid | 136 | QPoint p = m_canvas->canvasToLocal(QPointF(mRulerGuide, itPos.y() + currItem->height() * mm.m22())); |
15465 | avox | 137 | m_canvas->update(QRect(oldP.x()-2, oldP.y(), p.x()+2, p.y())); |
138 | } |
||
139 | } |
||
140 | |||
141 | |||
12775 | jghali | 142 | void CanvasMode_Edit::drawControls(QPainter* p) |
143 | { |
||
14371 | jghali | 144 | commonDrawControls(p, false); |
12775 | jghali | 145 | PageItem* currItem; |
146 | if (GetItem(&currItem)) |
||
147 | { |
||
17122 | fschmid | 148 | QPen pp = QPen(Qt::blue, 1.0 / m_canvas->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
149 | pp.setCosmetic(true); |
||
12775 | jghali | 150 | PageItem_TextFrame* textframe = currItem->asTextFrame(); |
151 | if (textframe) |
||
15465 | avox | 152 | { |
153 | if (mRulerGuide >= 0) |
||
154 | { |
||
17119 | fschmid | 155 | QTransform mm = currItem->getTransform(); |
156 | QPointF itPos = mm.map(QPointF(0, currItem->yPos())); |
||
15465 | avox | 157 | p->save(); |
17119 | fschmid | 158 | p->setTransform(mm, true); |
15465 | avox | 159 | p->setPen(QPen(Qt::blue, 1.0 / m_canvas->scale(), Qt::DashLine, Qt::FlatCap, Qt::MiterJoin)); |
160 | p->setClipRect(QRectF(0.0, 0.0, currItem->width(), currItem->height())); |
||
161 | p->setBrush(Qt::NoBrush); |
||
162 | p->setRenderHint(QPainter::Antialiasing); |
||
17119 | fschmid | 163 | p->drawLine(mRulerGuide - itPos.x(), 0, mRulerGuide - itPos.x(), currItem->height() * mm.m22()); |
15465 | avox | 164 | p->restore(); |
165 | } |
||
12775 | jghali | 166 | drawTextCursor(p, textframe); |
15465 | avox | 167 | } |
14860 | fschmid | 168 | else if (currItem->asImageFrame()) |
169 | { |
||
17122 | fschmid | 170 | QTransform mm = currItem->getTransform(); |
14860 | fschmid | 171 | p->save(); |
17122 | fschmid | 172 | p->setTransform(mm, true); |
14860 | fschmid | 173 | p->setClipRect(QRectF(0.0, 0.0, currItem->width(), currItem->height())); |
17122 | fschmid | 174 | p->setPen(pp); |
14860 | fschmid | 175 | p->setBrush(QColor(0,0,255,10)); |
176 | p->setRenderHint(QPainter::Antialiasing); |
||
177 | p->translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale()); |
||
14861 | fschmid | 178 | p->rotate(currItem->imageRotation()); |
14945 | fschmid | 179 | p->drawRect(0, 0, currItem->OrigW*currItem->imageXScale(), currItem->OrigH*currItem->imageYScale()); |
180 | p->translate(currItem->OrigW*currItem->imageXScale() / 2, currItem->OrigH*currItem->imageYScale() / 2); |
||
14860 | fschmid | 181 | p->scale(1.0 / m_canvas->scale(), 1.0 / m_canvas->scale()); |
17122 | fschmid | 182 | QPen pps = QPen(Qt::blue, 1.0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
183 | pps.setCosmetic(true); |
||
184 | p->setPen(pps); |
||
14860 | fschmid | 185 | p->drawLine(-10, 0, 10, 0); |
186 | p->drawLine(0, -10, 0, 10); |
||
187 | p->setBrush(QColor(0,0,255,70)); |
||
188 | p->drawEllipse(QPointF(0.0, 0.0), 10.0, 10.0); |
||
189 | p->restore(); |
||
190 | } |
||
12775 | jghali | 191 | } |
192 | } |
||
193 | |||
194 | |||
13079 | pierre | 195 | void CanvasMode_Edit::drawTextCursor ( QPainter *p, PageItem_TextFrame* textframe ) |
12775 | jghali | 196 | { |
16474 | craig | 197 | if ((!m_longCursorTime && m_blinkTime.elapsed() > qApp->cursorFlashTime() / 2 ) || |
198 | (m_longCursorTime && m_blinkTime.elapsed() > qApp->cursorFlashTime() ) |
||
199 | ) |
||
12775 | jghali | 200 | { |
13079 | pierre | 201 | m_cursorVisible = !m_cursorVisible; |
202 | m_blinkTime.restart(); |
||
16474 | craig | 203 | m_longCursorTime=false; |
12775 | jghali | 204 | } |
13079 | pierre | 205 | if ( m_cursorVisible ) |
12775 | jghali | 206 | { |
16856 | craig | 207 | commonDrawTextCursor(p, textframe, QPointF()); |
12775 | jghali | 208 | } |
209 | } |
||
210 | |||
211 | void CanvasMode_Edit::enterEvent(QEvent *) |
||
212 | { |
||
213 | if (!m_canvas->m_viewMode.m_MouseButtonPressed) |
||
214 | { |
||
215 | setModeCursor(); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | void CanvasMode_Edit::leaveEvent(QEvent *e) |
||
220 | { |
||
221 | } |
||
222 | |||
223 | void CanvasMode_Edit::activate(bool fromGesture) |
||
224 | { |
||
225 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
226 | m_canvas->resetRenderMode(); |
||
227 | m_doc->DragP = false; |
||
228 | m_doc->leaveDrag = false; |
||
229 | m_canvas->m_viewMode.operItemMoving = false; |
||
230 | m_canvas->m_viewMode.operItemResizing = false; |
||
231 | m_view->MidButt = false; |
||
232 | Mxp = Myp = -1; |
||
233 | Dxp = Dyp = -1; |
||
234 | oldCp = Cp = -1; |
||
235 | frameResizeHandle = -1; |
||
236 | setModeCursor(); |
||
237 | if (fromGesture) |
||
238 | { |
||
239 | m_view->update(); |
||
240 | } |
||
15465 | avox | 241 | mRulerGuide = -1; |
13106 | pierre | 242 | PageItem * it(0); |
243 | if(GetItem(&it)) |
||
244 | { |
||
14816 | fschmid | 245 | if (it->asTextFrame()) |
16474 | craig | 246 | { |
14816 | fschmid | 247 | m_canvas->setupEditHRuler(it, true); |
16474 | craig | 248 | if (m_doc->appMode == modeEdit) |
249 | { |
||
250 | m_blinker->start(200); |
||
251 | m_blinkTime.start(); |
||
252 | m_cursorVisible = true; |
||
253 | blinkTextCursor(); |
||
254 | } |
||
255 | } |
||
13106 | pierre | 256 | } |
12775 | jghali | 257 | } |
258 | |||
259 | void CanvasMode_Edit::deactivate(bool forGesture) |
||
260 | { |
||
18438 | craig | 261 | m_view->setRedrawMarkerShown(false); |
12775 | jghali | 262 | if (!forGesture) |
15465 | avox | 263 | { |
264 | mRulerGuide = -1; |
||
12775 | jghali | 265 | m_blinker->stop(); |
15465 | avox | 266 | } |
12775 | jghali | 267 | } |
268 | |||
269 | void CanvasMode_Edit::mouseDoubleClickEvent(QMouseEvent *m) |
||
270 | { |
||
271 | m->accept(); |
||
272 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
273 | m_canvas->resetRenderMode(); |
||
274 | PageItem *currItem = 0; |
||
13054 | pierre | 275 | if (GetItem(&currItem) && (m_doc->appMode == modeEdit) && currItem->asTextFrame()) |
12775 | jghali | 276 | { |
13054 | pierre | 277 | //CB if annotation, open the annotation dialog |
278 | if (currItem->isAnnotation()) |
||
279 | { |
||
18181 | fschmid | 280 | // qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
13054 | pierre | 281 | m_view->requestMode(submodeAnnotProps); |
282 | } |
||
283 | //otherwise, select between the whitespace |
||
284 | else |
||
15950 | craig | 285 | { |
286 | if (m->modifiers() & Qt::ControlModifier) |
||
287 | { |
||
288 | int start=0, stop=0; |
||
289 | |||
290 | if (m->modifiers() & Qt::ShiftModifier) |
||
291 | {//Double click with Ctrl+Shift in a frame to select few paragraphs |
||
292 | uint oldPar = currItem->itemText.nrOfParagraph(oldCp); |
||
16626 | jghali | 293 | uint newPar = currItem->itemText.nrOfParagraph(); |
15950 | craig | 294 | if (oldPar < newPar) |
295 | { |
||
296 | start = currItem->itemText.startOfParagraph(oldPar); |
||
297 | stop = currItem->itemText.endOfParagraph(newPar); |
||
298 | } |
||
299 | else |
||
300 | { |
||
301 | start = currItem->itemText.startOfParagraph(newPar); |
||
302 | stop = currItem->itemText.endOfParagraph(oldPar); |
||
303 | } |
||
304 | } |
||
305 | else |
||
306 | {//Double click with Ctrl in a frame to select a paragraph |
||
16626 | jghali | 307 | oldCp = currItem->itemText.cursorPosition(); |
15950 | craig | 308 | uint nrPar = currItem->itemText.nrOfParagraph(oldCp); |
309 | start = currItem->itemText.startOfParagraph(nrPar); |
||
310 | stop = currItem->itemText.endOfParagraph(nrPar); |
||
311 | } |
||
16020 | craig | 312 | currItem->itemText.deselectAll(); |
15950 | craig | 313 | currItem->itemText.extendSelection(start, stop); |
16626 | jghali | 314 | currItem->itemText.setCursorPosition(stop); |
15950 | craig | 315 | } |
18524 | avox | 316 | else if ((currItem->itemText.cursorPosition() < currItem->itemText.length()) && (currItem->itemText.hasMark(currItem->itemText.cursorPosition()))) |
17826 | craig | 317 | { //invoke edit marker dialog |
318 | m_ScMW->slotEditMark(); |
||
319 | return; |
||
320 | } |
||
15950 | craig | 321 | else |
322 | { //Double click in a frame to select a word |
||
16626 | jghali | 323 | oldCp = currItem->itemText.cursorPosition(); |
17603 | jghali | 324 | bool validPos = (oldCp >= 0 && oldCp < currItem->itemText.length()); |
325 | if (validPos && currItem->itemText.hasObject(oldCp)) |
||
17422 | fschmid | 326 | { |
327 | currItem->itemText.select(oldCp, 1, true); |
||
328 | PageItem *iItem = currItem->itemText.object(oldCp); |
||
329 | m_ScMW->editInlineStart(iItem->inlineCharID); |
||
330 | } |
||
331 | else |
||
17603 | jghali | 332 | { |
333 | int newPos = currItem->itemText.selectWord(oldCp); |
||
334 | currItem->itemText.setCursorPosition(newPos); |
||
335 | } |
||
15950 | craig | 336 | } |
16020 | craig | 337 | currItem->HasSel = (currItem->itemText.lengthOfSelection() > 0); |
13054 | pierre | 338 | } |
339 | } |
||
340 | else |
||
341 | { |
||
12775 | jghali | 342 | mousePressEvent(m); |
343 | return; |
||
344 | } |
||
345 | } |
||
346 | |||
347 | |||
348 | void CanvasMode_Edit::mouseMoveEvent(QMouseEvent *m) |
||
349 | { |
||
350 | // const double mouseX = m->globalX(); |
||
351 | // const double mouseY = m->globalY(); |
||
352 | const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
||
353 | |||
354 | m_lastPosWasOverGuide = false; |
||
355 | double newX, newY; |
||
356 | PageItem *currItem; |
||
14633 | subik | 357 | //bool erf = false; |
12775 | jghali | 358 | m->accept(); |
13132 | pierre | 359 | if (commonMouseMove(m)) |
13128 | jghali | 360 | return; |
12775 | jghali | 361 | if (GetItem(&currItem)) |
362 | { |
||
363 | newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x()); |
||
364 | newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y()); |
||
365 | if (m_doc->DragP) |
||
366 | return; |
||
14371 | jghali | 367 | if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeEdit)) |
12775 | jghali | 368 | { |
369 | if (currItem->asImageFrame()) |
||
370 | { |
||
14869 | fschmid | 371 | if (m->modifiers() & Qt::ShiftModifier) |
372 | { |
||
18181 | fschmid | 373 | m_view->setCursor(QCursor(loadIcon("Rotieren2.png"))); |
17119 | fschmid | 374 | QTransform p = currItem->getTransform(); |
14869 | fschmid | 375 | p.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale()); |
376 | QPointF rotP = p.map(QPointF(0.0, 0.0)); |
||
377 | double itemRotation = xy2Deg(mousePointDoc.x() - rotP.x(), mousePointDoc.y() - rotP.y()); |
||
378 | currItem->setImageRotation(itemRotation); |
||
379 | m_canvas->displayRotHUD(m->globalPos(), itemRotation); |
||
380 | } |
||
381 | else |
||
382 | { |
||
18181 | fschmid | 383 | m_view->setCursor(QCursor(loadIcon("HandC.xpm"))); |
14869 | fschmid | 384 | QTransform ro; |
385 | ro.rotate(-currItem->rotation()); |
||
386 | QPointF rota = ro.map(QPointF(newX-Mxp,newY-Myp)); |
||
17122 | fschmid | 387 | QTransform mm = currItem->getTransform(); |
388 | double sx, sy; |
||
389 | getScaleFromMatrix(mm, sx, sy); |
||
390 | currItem->moveImageInFrame((rota.x() / sx) / currItem->imageXScale(), (rota.y() / sy) / currItem->imageYScale()); |
||
14869 | fschmid | 391 | m_canvas->displayXYHUD(m->globalPos(), currItem->imageXOffset() * currItem->imageXScale(), currItem->imageYOffset() * currItem->imageYScale()); |
392 | } |
||
13289 | jghali | 393 | currItem->update(); |
12775 | jghali | 394 | Mxp = newX; |
395 | Myp = newY; |
||
396 | } |
||
397 | if (currItem->asTextFrame()) |
||
398 | { |
||
13614 | pierre | 399 | int refStartSel(currItem->asTextFrame()->itemText.startOfSelection()); |
400 | int refEndSel(currItem->asTextFrame()->itemText.endOfSelection()); |
||
12775 | jghali | 401 | currItem->itemText.deselectAll(); |
402 | currItem->HasSel = false; |
||
13297 | pierre | 403 | m_view->slotSetCurs(m->globalPos().x(), m->globalPos().y()); |
12775 | jghali | 404 | //Make sure we dont go here if the old cursor position was not set |
405 | if (oldCp!=-1 && currItem->itemText.length() > 0) |
||
406 | { |
||
16626 | jghali | 407 | if (currItem->itemText.cursorPosition() < oldCp) |
12775 | jghali | 408 | { |
16626 | jghali | 409 | currItem->itemText.select(currItem->itemText.cursorPosition(), oldCp - currItem->itemText.cursorPosition()); |
12775 | jghali | 410 | currItem->HasSel = true; |
411 | } |
||
16626 | jghali | 412 | if (currItem->itemText.cursorPosition() > oldCp) |
12775 | jghali | 413 | { |
16626 | jghali | 414 | currItem->itemText.select(oldCp, currItem->itemText.cursorPosition() - oldCp); |
12775 | jghali | 415 | currItem->HasSel = true; |
416 | } |
||
417 | } |
||
418 | if(currItem->HasSel) |
||
13132 | pierre | 419 | { |
12775 | jghali | 420 | m_ScMW->EnableTxEdit(); |
13132 | pierre | 421 | m_canvas->m_viewMode.operTextSelecting = true; |
13614 | pierre | 422 | if((refStartSel != currItem->asTextFrame()->itemText.startOfSelection()) |
423 | || (refEndSel != currItem->asTextFrame()->itemText.endOfSelection())) |
||
424 | { |
||
425 | QRectF br(currItem->getBoundingRect()); |
||
426 | m_canvas->update(QRectF(m_canvas->canvasToLocal(br.topLeft()), br.size() * m_canvas->scale()).toRect()); |
||
427 | } |
||
13132 | pierre | 428 | } |
12775 | jghali | 429 | else |
430 | m_ScMW->DisableTxEdit(); |
||
13614 | pierre | 431 | |
12775 | jghali | 432 | } |
433 | } |
||
434 | if (!m_canvas->m_viewMode.m_MouseButtonPressed) |
||
435 | { |
||
436 | if (m_doc->m_Selection->isMultipleSelection()) |
||
437 | { |
||
438 | setModeCursor(); |
||
439 | return; |
||
440 | } |
||
441 | for (int a = 0; a < m_doc->m_Selection->count(); ++a) |
||
442 | { |
||
443 | currItem = m_doc->m_Selection->itemAt(a); |
||
444 | if (currItem->locked()) |
||
445 | break; |
||
13297 | pierre | 446 | int hitTest = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem); |
17825 | jghali | 447 | if (hitTest >= 0) |
12775 | jghali | 448 | { |
17825 | jghali | 449 | if (hitTest == Canvas::INSIDE) |
12775 | jghali | 450 | { |
451 | if (currItem->asTextFrame()) |
||
18181 | fschmid | 452 | m_view->setCursor(QCursor(Qt::IBeamCursor)); |
12775 | jghali | 453 | if (currItem->asImageFrame()) |
14869 | fschmid | 454 | { |
455 | if (m->modifiers() & Qt::ShiftModifier) |
||
18181 | fschmid | 456 | m_view->setCursor(QCursor(loadIcon("Rotieren2.png"))); |
14869 | fschmid | 457 | else |
18181 | fschmid | 458 | m_view->setCursor(QCursor(loadIcon("HandC.xpm"))); |
14869 | fschmid | 459 | } |
12775 | jghali | 460 | } |
461 | } |
||
462 | else |
||
463 | { |
||
12799 | pierre | 464 | // setModeCursor(); |
18181 | fschmid | 465 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
12775 | jghali | 466 | } |
467 | } |
||
468 | } |
||
469 | } |
||
470 | else |
||
471 | { |
||
472 | if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton)) |
||
473 | { |
||
474 | newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x()); |
||
475 | newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y()); |
||
476 | SeRx = newX; |
||
477 | SeRy = newY; |
||
478 | QPoint startP = m_canvas->canvasToGlobal(QPointF(Mxp, Myp)); |
||
18353 | fschmid | 479 | m_view->redrawMarker->setGeometry(QRect(m_view->mapFromGlobal(startP), m_view->mapFromGlobal(m->globalPos())).normalized()); |
18438 | craig | 480 | m_view->setRedrawMarkerShown(true); |
12775 | jghali | 481 | m_view->HaveSelRect = true; |
482 | return; |
||
483 | } |
||
484 | } |
||
485 | } |
||
486 | |||
487 | void CanvasMode_Edit::mousePressEvent(QMouseEvent *m) |
||
488 | { |
||
17641 | craig | 489 | if (UndoManager::undoEnabled()) |
490 | { |
||
491 | SimpleState *ss = dynamic_cast<SimpleState*>(undoManager->getLastUndo()); |
||
492 | if(ss) |
||
493 | ss->set("ETEA",QString("")); |
||
17646 | craig | 494 | else |
495 | { |
||
496 | TransactionState *ts = dynamic_cast<TransactionState*>(undoManager->getLastUndo()); |
||
497 | if(ts) |
||
498 | ss = dynamic_cast<SimpleState*>(ts->at(0)); |
||
499 | if(ss) |
||
500 | ss->set("ETEA",QString("")); |
||
501 | } |
||
17641 | craig | 502 | } |
12775 | jghali | 503 | // const double mouseX = m->globalX(); |
504 | // const double mouseY = m->globalY(); |
||
505 | const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
||
506 | |||
507 | bool inText; |
||
508 | PageItem *currItem; |
||
509 | m_canvas->PaintSizeRect(QRect()); |
||
510 | FPoint npf, npf2; |
||
13951 | fschmid | 511 | QTransform pm; |
12775 | jghali | 512 | m_canvas->m_viewMode.m_MouseButtonPressed = true; |
513 | m_canvas->m_viewMode.operItemMoving = false; |
||
514 | m_view->HaveSelRect = false; |
||
515 | m_doc->DragP = false; |
||
516 | m_doc->leaveDrag = false; |
||
517 | // oldClip = 0; |
||
518 | m->accept(); |
||
519 | m_view->registerMousePress(m->globalPos()); |
||
520 | Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x()); |
||
521 | Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y()); |
||
14932 | cbradney | 522 | // QRect mpo(m->x()-m_doc->guidesPrefs().grabRad, m->y()-m_doc->guidesPrefs().grabRad, m_doc->guidesPrefs().grabRad*2, m_doc->guidesPrefs().grabRad*2); |
12775 | jghali | 523 | // mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale())); |
524 | SeRx = Mxp; |
||
525 | SeRy = Myp; |
||
526 | if (m->button() == Qt::MidButton) |
||
527 | { |
||
528 | m_view->MidButt = true; |
||
13124 | fschmid | 529 | if (m->modifiers() & Qt::ControlModifier) |
530 | m_view->DrawNew(); |
||
12775 | jghali | 531 | return; |
532 | } |
||
533 | |||
534 | frameResizeHandle = 0; |
||
535 | int oldP=0; |
||
536 | if (GetItem(&currItem)) |
||
537 | { |
||
538 | // m_view->slotDoCurs(false); |
||
16024 | jghali | 539 | if ((!currItem->locked() || currItem->isTextFrame()) && !currItem->asLine()) |
12775 | jghali | 540 | { |
14816 | fschmid | 541 | FPoint canvasPoint = m_canvas->globalToCanvas(m->globalPos()); |
14371 | jghali | 542 | if (m_canvas->frameHitTest(QPointF(canvasPoint.x(), canvasPoint.y()), currItem) < 0) |
12775 | jghali | 543 | { |
15989 | jghali | 544 | m_doc->m_Selection->delaySignalsOn(); |
12775 | jghali | 545 | m_view->Deselect(true); |
14256 | jghali | 546 | bool wantNormal = true; |
12775 | jghali | 547 | if (SeleItem(m)) |
548 | { |
||
549 | currItem = m_doc->m_Selection->itemAt(0); |
||
550 | if ((currItem->asTextFrame()) || (currItem->asImageFrame())) |
||
13106 | pierre | 551 | { |
12775 | jghali | 552 | m_view->requestMode(modeEdit); |
14256 | jghali | 553 | wantNormal = false; |
13106 | pierre | 554 | } |
12775 | jghali | 555 | else |
556 | { |
||
557 | m_view->requestMode(submodePaintingDone); |
||
18181 | fschmid | 558 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
12775 | jghali | 559 | } |
14256 | jghali | 560 | if (currItem->asTextFrame()) |
561 | m_view->slotSetCurs(m->globalPos().x(), m->globalPos().y()); |
||
12775 | jghali | 562 | } |
563 | else |
||
564 | { |
||
565 | m_view->requestMode(submodePaintingDone); |
||
18181 | fschmid | 566 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
12775 | jghali | 567 | } |
15989 | jghali | 568 | m_doc->m_Selection->delaySignalsOff(); |
14256 | jghali | 569 | if (wantNormal) |
570 | m_view->requestMode(modeNormal); |
||
12775 | jghali | 571 | return; |
572 | } |
||
573 | } |
||
16626 | jghali | 574 | oldP = currItem->itemText.cursorPosition(); |
12775 | jghali | 575 | //CB Where we set the cursor for a click in text frame |
576 | if (currItem->asTextFrame()) |
||
577 | { |
||
13297 | pierre | 578 | inText = m_view->slotSetCurs(m->globalPos().x(), m->globalPos().y()); |
12775 | jghali | 579 | //CB If we clicked outside a text frame to go out of edit mode and deselect the frame |
580 | if (!inText) |
||
581 | { |
||
582 | currItem->invalidateLayout(); |
||
583 | m_view->Deselect(true); |
||
584 | //m_view->slotDoCurs(true); |
||
585 | m_view->requestMode(modeNormal); |
||
586 | return; |
||
587 | } |
||
13614 | pierre | 588 | |
13227 | fschmid | 589 | if (m->button() != Qt::RightButton) |
12775 | jghali | 590 | { |
15950 | craig | 591 | //currItem->asTextFrame()->deselectAll(); |
13227 | fschmid | 592 | //<<CB Add in shift select to text frames |
15950 | craig | 593 | if (m->modifiers() & Qt::ShiftModifier) |
12775 | jghali | 594 | { |
15950 | craig | 595 | if (currItem->itemText.lengthOfSelection() > 0) |
596 | { |
||
16626 | jghali | 597 | if (currItem->itemText.cursorPosition() < (currItem->itemText.startOfSelection() + currItem->itemText.endOfSelection()) / 2) |
16020 | craig | 598 | { |
599 | if (m->modifiers() & Qt::ControlModifier) |
||
16626 | jghali | 600 | currItem->itemText.setCursorPosition(currItem->itemText.startOfParagraph()); |
15950 | craig | 601 | oldP = currItem->itemText.startOfSelection(); |
16020 | craig | 602 | } |
15950 | craig | 603 | else |
16020 | craig | 604 | { |
605 | if (m->modifiers() & Qt::ControlModifier) |
||
16626 | jghali | 606 | currItem->itemText.setCursorPosition(currItem->itemText.endOfParagraph()); |
15950 | craig | 607 | oldP = currItem->itemText.endOfSelection(); |
16020 | craig | 608 | } |
16626 | jghali | 609 | currItem->asTextFrame()->itemText.extendSelection(oldP, currItem->itemText.cursorPosition()); |
610 | oldCp = currItem->itemText.cursorPosition(); |
||
15950 | craig | 611 | } |
612 | else |
||
613 | { |
||
614 | int dir=1; |
||
16626 | jghali | 615 | if (oldCp > currItem->itemText.cursorPosition()) |
15950 | craig | 616 | dir=-1; |
16020 | craig | 617 | if (m->modifiers() & Qt::ControlModifier) //no selection but Ctrl+Shift+click still select paragraphs |
618 | { |
||
619 | if (dir == 1) |
||
16626 | jghali | 620 | currItem->itemText.setCursorPosition(currItem->itemText.endOfParagraph()); |
16020 | craig | 621 | else |
16626 | jghali | 622 | currItem->itemText.setCursorPosition(currItem->itemText.startOfParagraph()); |
16020 | craig | 623 | } |
624 | currItem->asTextFrame()->ExpandSel(dir, oldP); |
||
15950 | craig | 625 | oldCp = oldP; |
626 | } |
||
12775 | jghali | 627 | } |
13227 | fschmid | 628 | else //>>CB |
12775 | jghali | 629 | { |
16626 | jghali | 630 | oldCp = currItem->itemText.cursorPosition(); |
13227 | fschmid | 631 | currItem->itemText.deselectAll(); |
632 | currItem->HasSel = false; |
||
12775 | jghali | 633 | } |
13227 | fschmid | 634 | currItem->emitAllToGUI(); |
635 | if (m->button() == Qt::MidButton) |
||
636 | { |
||
637 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
638 | m_view->MidButt = false; |
||
639 | QString cc; |
||
640 | cc = QApplication::clipboard()->text(QClipboard::Selection); |
||
641 | if (cc.isNull()) |
||
642 | cc = QApplication::clipboard()->text(QClipboard::Clipboard); |
||
643 | if (!cc.isNull()) |
||
644 | { |
||
645 | // K.I.S.S.: |
||
646 | currItem->itemText.insertChars(0, cc, true); |
||
647 | if (m_doc->docHyphenator->AutoCheck) |
||
648 | m_doc->docHyphenator->slotHyphenate(currItem); |
||
649 | m_ScMW->BookMarkTxT(currItem); |
||
650 | // m_ScMW->outlinePalette->BuildTree(); |
||
651 | } |
||
652 | else |
||
653 | { |
||
654 | if (ScMimeData::clipboardHasScribusText()) |
||
655 | m_ScMW->slotEditPaste(); |
||
656 | } |
||
657 | currItem->update(); |
||
658 | } |
||
12775 | jghali | 659 | } |
660 | } |
||
14869 | fschmid | 661 | else if (!currItem->asImageFrame() || m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem) < 0) |
12775 | jghali | 662 | { |
663 | m_view->Deselect(true); |
||
664 | if (SeleItem(m)) |
||
665 | { |
||
666 | currItem = m_doc->m_Selection->itemAt(0); |
||
667 | if ((currItem->asTextFrame()) || (currItem->asImageFrame())) |
||
13106 | pierre | 668 | { |
12775 | jghali | 669 | m_view->requestMode(modeEdit); |
13106 | pierre | 670 | } |
12775 | jghali | 671 | else |
672 | { |
||
673 | m_view->requestMode(submodePaintingDone); |
||
18181 | fschmid | 674 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
12775 | jghali | 675 | } |
676 | } |
||
677 | else |
||
678 | { |
||
679 | m_view->requestMode(submodePaintingDone); |
||
18181 | fschmid | 680 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
12775 | jghali | 681 | } |
682 | } |
||
683 | } |
||
684 | } |
||
685 | |||
686 | |||
687 | |||
688 | void CanvasMode_Edit::mouseReleaseEvent(QMouseEvent *m) |
||
689 | { |
||
13034 | pierre | 690 | #ifdef GESTURE_FRAME_PREVIEW |
691 | clearPixmapCache(); |
||
692 | #endif // GESTURE_FRAME_PREVIEW |
||
12775 | jghali | 693 | const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
694 | PageItem *currItem; |
||
695 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
696 | m_canvas->resetRenderMode(); |
||
697 | m->accept(); |
||
13285 | fschmid | 698 | // m_view->stopDragTimer(); |
12775 | jghali | 699 | if ((GetItem(&currItem)) && (m->button() == Qt::RightButton) && (!m_doc->DragP)) |
700 | { |
||
701 | createContextMenu(currItem, mousePointDoc.x(), mousePointDoc.y()); |
||
702 | return; |
||
703 | } |
||
704 | if (m_view->moveTimerElapsed() && (GetItem(&currItem))) |
||
705 | { |
||
13285 | fschmid | 706 | // m_view->stopDragTimer(); |
12775 | jghali | 707 | m_canvas->setRenderModeUseBuffer(false); |
708 | if (!m_doc->m_Selection->isMultipleSelection()) |
||
709 | { |
||
710 | m_doc->setRedrawBounding(currItem); |
||
711 | currItem->OwnPage = m_doc->OnPage(currItem); |
||
712 | m_canvas->m_viewMode.operItemResizing = false; |
||
713 | if (currItem->asLine()) |
||
714 | m_view->updateContents(); |
||
715 | } |
||
716 | if (m_canvas->m_viewMode.operItemMoving) |
||
717 | { |
||
718 | m_view->updatesOn(false); |
||
719 | if (m_doc->m_Selection->isMultipleSelection()) |
||
720 | { |
||
721 | if (!m_view->groupTransactionStarted()) |
||
722 | { |
||
723 | m_view->startGroupTransaction(Um::Move, "", Um::IMove); |
||
724 | } |
||
725 | m_doc->m_Selection->setGroupRect(); |
||
726 | double gx, gy, gh, gw; |
||
727 | m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
728 | double nx = gx; |
||
729 | double ny = gy; |
||
17744 | craig | 730 | if (!m_doc->ApplyGuides(&nx, &ny) && !m_doc->ApplyGuides(&nx, &ny,true)) |
12775 | jghali | 731 | { |
732 | FPoint npx = m_doc->ApplyGridF(FPoint(gx, gy)); |
||
733 | FPoint npw = m_doc->ApplyGridF(FPoint(gx+gw, gy+gh)); |
||
734 | if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x()))) |
||
735 | nx = npw.x() - gw; |
||
736 | else |
||
737 | nx = npx.x(); |
||
738 | if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y()))) |
||
739 | ny = npw.y() - gh; |
||
740 | else |
||
741 | ny = npx.y(); |
||
742 | } |
||
743 | m_doc->moveGroup(nx-gx, ny-gy, false); |
||
744 | m_doc->m_Selection->setGroupRect(); |
||
745 | m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
746 | nx = gx+gw; |
||
747 | ny = gy+gh; |
||
17744 | craig | 748 | if (m_doc->ApplyGuides(&nx, &ny) || m_doc->ApplyGuides(&nx,&ny,true)) |
12775 | jghali | 749 | m_doc->moveGroup(nx-(gx+gw), ny-(gy+gh), false); |
750 | m_doc->m_Selection->setGroupRect(); |
||
751 | } |
||
752 | else |
||
753 | { |
||
754 | currItem = m_doc->m_Selection->itemAt(0); |
||
18027 | jghali | 755 | if (m_doc->SnapGrid) |
12775 | jghali | 756 | { |
757 | double nx = currItem->xPos(); |
||
758 | double ny = currItem->yPos(); |
||
17744 | craig | 759 | if (!m_doc->ApplyGuides(&nx, &ny) && !m_doc->ApplyGuides(&nx, &ny,true)) |
12775 | jghali | 760 | { |
761 | m_doc->m_Selection->setGroupRect(); |
||
762 | double gx, gy, gh, gw; |
||
763 | m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
764 | FPoint npx = m_doc->ApplyGridF(FPoint(gx, gy)); |
||
765 | FPoint npw = m_doc->ApplyGridF(FPoint(gx+gw, gy+gh)); |
||
766 | if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x()))) |
||
767 | nx = npw.x() - gw; |
||
768 | else |
||
769 | nx = npx.x(); |
||
770 | if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y()))) |
||
771 | ny = npw.y() - gh; |
||
772 | else |
||
773 | ny = npx.y(); |
||
774 | } |
||
775 | m_doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem); |
||
776 | } |
||
777 | else |
||
778 | m_doc->MoveItem(0, 0, currItem, false); |
||
779 | } |
||
780 | m_canvas->m_viewMode.operItemMoving = false; |
||
781 | if (m_doc->m_Selection->isMultipleSelection()) |
||
782 | { |
||
783 | double gx, gy, gh, gw; |
||
784 | m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); |
||
14924 | cbradney | 785 | FPoint maxSize(gx+gw+m_doc->scratch()->Right, gy+gh+m_doc->scratch()->Bottom); |
786 | FPoint minSize(gx-m_doc->scratch()->Left, gy-m_doc->scratch()->Top); |
||
12775 | jghali | 787 | m_doc->adjustCanvas(minSize, maxSize); |
788 | } |
||
789 | m_doc->setRedrawBounding(currItem); |
||
790 | currItem->OwnPage = m_doc->OnPage(currItem); |
||
791 | if (currItem->OwnPage != -1) |
||
792 | { |
||
793 | m_doc->setCurrentPage(m_doc->Pages->at(currItem->OwnPage)); |
||
794 | m_view->setMenTxt(currItem->OwnPage); |
||
795 | } |
||
796 | //CB done with emitAllToGUI |
||
797 | //emit HaveSel(currItem->itemType()); |
||
798 | //EmitValues(currItem); |
||
799 | //CB need this for? a moved item will send its new data with the new xpos/ypos emits |
||
800 | //CB TODO And what if we have dragged to a new page. Items X&Y are not updated anyway now |
||
801 | //currItem->emitAllToGUI(); |
||
802 | m_view->updatesOn(true); |
||
803 | m_view->updateContents(); |
||
804 | } |
||
805 | } |
||
806 | //CB Drag selection performed here |
||
807 | if ((m_doc->m_Selection->count() == 0) && (m_view->HaveSelRect) && (!m_view->MidButt)) |
||
808 | { |
||
809 | QRectF Sele = QRectF(Dxp, Dyp, SeRx-Dxp, SeRy-Dyp).normalized(); |
||
810 | if (!m_doc->masterPageMode()) |
||
811 | { |
||
812 | uint docPagesCount=m_doc->Pages->count(); |
||
813 | uint docCurrPageNo=m_doc->currentPageNumber(); |
||
814 | for (uint i = 0; i < docPagesCount; ++i) |
||
815 | { |
||
816 | if (QRectF(m_doc->Pages->at(i)->xOffset(), m_doc->Pages->at(i)->yOffset(), m_doc->Pages->at(i)->width(), m_doc->Pages->at(i)->height()).intersects(Sele)) |
||
817 | { |
||
818 | if (docCurrPageNo != i) |
||
819 | { |
||
820 | m_doc->setCurrentPage(m_doc->Pages->at(i)); |
||
821 | m_view->setMenTxt(i); |
||
822 | } |
||
823 | break; |
||
824 | } |
||
825 | } |
||
826 | m_view->setRulerPos(m_view->contentsX(), m_view->contentsY()); |
||
827 | } |
||
828 | int docItemCount=m_doc->Items->count(); |
||
829 | if (docItemCount != 0) |
||
830 | { |
||
831 | m_doc->m_Selection->delaySignalsOn(); |
||
832 | for (int a = 0; a < docItemCount; ++a) |
||
833 | { |
||
834 | PageItem* docItem = m_doc->Items->at(a); |
||
13951 | fschmid | 835 | QTransform p; |
12775 | jghali | 836 | m_canvas->Transform(docItem, p); |
837 | QRegion apr = QRegion(docItem->Clip * p); |
||
838 | QRect apr2(docItem->getRedrawBounding(1.0)); |
||
839 | if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName())) |
||
840 | continue; |
||
17454 | fschmid | 841 | if (((Sele.contains(apr.boundingRect())) || (Sele.contains(apr2))) && ((docItem->LayerID == m_doc->activeLayer()) || (m_doc->layerSelectable(docItem->LayerID))) && (!m_doc->layerLocked(docItem->LayerID))) |
12775 | jghali | 842 | { |
843 | bool redrawSelection=false; |
||
844 | m_view->SelectItemNr(a, redrawSelection); |
||
845 | } |
||
846 | } |
||
847 | m_doc->m_Selection->delaySignalsOff(); |
||
848 | if (m_doc->m_Selection->count() > 1) |
||
849 | { |
||
850 | m_doc->m_Selection->setGroupRect(); |
||
851 | double x, y, w, h; |
||
852 | m_doc->m_Selection->getGroupRect(&x, &y, &w, &h); |
||
853 | m_view->getGroupRectScreen(&x, &y, &w, &h); |
||
854 | } |
||
855 | } |
||
856 | m_view->HaveSelRect = false; |
||
18438 | craig | 857 | m_view->setRedrawMarkerShown(false); |
12775 | jghali | 858 | m_view->updateContents(); |
859 | } |
||
860 | if (GetItem(&currItem)) |
||
861 | { |
||
862 | if (m_doc->m_Selection->count() > 1) |
||
863 | { |
||
864 | m_doc->m_Selection->setGroupRect(); |
||
865 | double x, y, w, h; |
||
866 | m_doc->m_Selection->getGroupRect(&x, &y, &w, &h); |
||
867 | m_canvas->m_viewMode.operItemMoving = false; |
||
868 | m_canvas->m_viewMode.operItemResizing = false; |
||
869 | m_view->updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10))); |
||
870 | } |
||
871 | /*else |
||
872 | currItem->emitAllToGUI();*/ |
||
873 | } |
||
874 | m_canvas->setRenderModeUseBuffer(false); |
||
875 | m_doc->DragP = false; |
||
876 | m_doc->leaveDrag = false; |
||
877 | m_canvas->m_viewMode.operItemMoving = false; |
||
878 | m_canvas->m_viewMode.operItemResizing = false; |
||
879 | m_view->MidButt = false; |
||
880 | if (m_view->groupTransactionStarted()) |
||
881 | { |
||
882 | for (int i = 0; i < m_doc->m_Selection->count(); ++i) |
||
883 | m_doc->m_Selection->itemAt(i)->checkChanges(true); |
||
884 | m_view->endGroupTransaction(); |
||
885 | } |
||
886 | for (int i = 0; i < m_doc->m_Selection->count(); ++i) |
||
887 | m_doc->m_Selection->itemAt(i)->checkChanges(true); |
||
888 | //Commit drag created items to undo manager. |
||
889 | if (m_doc->m_Selection->itemAt(0)!=NULL) |
||
890 | { |
||
16943 | fschmid | 891 | m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)); |
12775 | jghali | 892 | } |
893 | //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas |
||
894 | m_view->zoomSpinBox->clearFocus(); |
||
895 | m_view->pageSelector->clearFocus(); |
||
896 | if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action |
||
897 | { |
||
898 | currItem = m_doc->m_Selection->itemAt(0); |
||
899 | m_doc->nodeEdit.finishTransaction(currItem); |
||
900 | } |
||
901 | } |
||
902 | |||
903 | //CB-->Doc/Fix |
||
904 | bool CanvasMode_Edit::SeleItem(QMouseEvent *m) |
||
905 | { |
||
906 | const unsigned SELECT_IN_GROUP = Qt::AltModifier; |
||
907 | const unsigned SELECT_MULTIPLE = Qt::ShiftModifier; |
||
908 | const unsigned SELECT_BENEATH = Qt::ControlModifier; |
||
13951 | fschmid | 909 | QTransform p; |
14371 | jghali | 910 | QRectF mpo; |
12775 | jghali | 911 | PageItem *currItem; |
912 | m_canvas->m_viewMode.m_MouseButtonPressed = true; |
||
913 | FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
||
914 | Mxp = mousePointDoc.x(); //m->x()/m_canvas->scale()); |
||
915 | Myp = mousePointDoc.y(); //m->y()/m_canvas->scale()); |
||
14932 | cbradney | 916 | double grabRadius = m_doc->guidesPrefs().grabRadius / m_canvas->scale(); |
12775 | jghali | 917 | int MxpS = static_cast<int>(mousePointDoc.x()); //m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x()); |
918 | int MypS = static_cast<int>(mousePointDoc.y()); //m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y()); |
||
919 | mpo = QRectF(Mxp-grabRadius, Myp-grabRadius, grabRadius*2, grabRadius*2); |
||
920 | // mpo.translate(m_doc->minCanvasCoordinate.x() * m_canvas->scale(), m_doc->minCanvasCoordinate.y() * m_canvas->scale()); |
||
921 | m_doc->nodeEdit.deselect(); |
||
922 | // int a; |
||
923 | if (!m_doc->masterPageMode()) |
||
924 | { |
||
925 | int pgNum = -1; |
||
926 | int docPageCount = static_cast<int>(m_doc->Pages->count() - 1); |
||
927 | MarginStruct pageBleeds; |
||
928 | bool drawBleed = false; |
||
14992 | cbradney | 929 | if (m_doc->bleeds()->hasNonZeroValue() && m_doc->guidesPrefs().showBleed) |
12775 | jghali | 930 | drawBleed = true; |
931 | for (int a = docPageCount; a > -1; a--) |
||
932 | { |
||
933 | if (drawBleed) |
||
934 | m_doc->getBleeds(a, pageBleeds); |
||
935 | int x = static_cast<int>(m_doc->Pages->at(a)->xOffset() - pageBleeds.Left); |
||
936 | int y = static_cast<int>(m_doc->Pages->at(a)->yOffset() - pageBleeds.Top); |
||
937 | int w = static_cast<int>(m_doc->Pages->at(a)->width() + pageBleeds.Left + pageBleeds.Right); |
||
938 | int h = static_cast<int>(m_doc->Pages->at(a)->height() + pageBleeds.Bottom + pageBleeds.Top); |
||
939 | if (QRect(x, y, w, h).contains(MxpS, MypS)) |
||
940 | { |
||
941 | pgNum = static_cast<int>(a); |
||
942 | if (drawBleed) // check again if its really on the correct page |
||
943 | { |
||
944 | for (int a2 = docPageCount; a2 > -1; a2--) |
||
945 | { |
||
946 | int xn = static_cast<int>(m_doc->Pages->at(a2)->xOffset()); |
||
947 | int yn = static_cast<int>(m_doc->Pages->at(a2)->yOffset()); |
||
948 | int wn = static_cast<int>(m_doc->Pages->at(a2)->width()); |
||
949 | int hn = static_cast<int>(m_doc->Pages->at(a2)->height()); |
||
950 | if (QRect(xn, yn, wn, hn).contains(MxpS, MypS)) |
||
951 | { |
||
952 | pgNum = static_cast<int>(a2); |
||
953 | break; |
||
954 | } |
||
955 | } |
||
956 | } |
||
957 | break; |
||
958 | } |
||
959 | } |
||
960 | if (pgNum >= 0) |
||
961 | { |
||
962 | if (m_doc->currentPageNumber() != pgNum) |
||
963 | { |
||
964 | m_doc->setCurrentPage(m_doc->Pages->at(unsigned(pgNum))); |
||
965 | m_view->setMenTxt(unsigned(pgNum)); |
||
966 | m_view->DrawNew(); |
||
967 | } |
||
968 | } |
||
969 | m_view->setRulerPos(m_view->contentsX(), m_view->contentsY()); |
||
970 | } |
||
971 | |||
972 | currItem = NULL; |
||
973 | if ((m->modifiers() & SELECT_BENEATH) != 0) |
||
974 | { |
||
975 | for (int i=0; i < m_doc->m_Selection->count(); ++i) |
||
976 | { |
||
977 | if (m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), m_doc->m_Selection->itemAt(i)) >= 0) |
||
978 | { |
||
979 | currItem = m_doc->m_Selection->itemAt(i); |
||
16113 | fschmid | 980 | m_doc->m_Selection->removeItem(currItem); |
12775 | jghali | 981 | break; |
982 | } |
||
983 | } |
||
984 | } |
||
985 | else if ( (m->modifiers() & SELECT_MULTIPLE) == Qt::NoModifier) |
||
986 | { |
||
987 | m_view->Deselect(false); |
||
988 | } |
||
989 | currItem = m_canvas->itemUnderCursor(m->globalPos(), currItem, (m->modifiers() & SELECT_IN_GROUP)); |
||
990 | if (currItem) |
||
991 | { |
||
992 | m_doc->m_Selection->delaySignalsOn(); |
||
993 | if (m_doc->m_Selection->containsItem(currItem)) |
||
994 | { |
||
995 | m_doc->m_Selection->removeItem(currItem); |
||
996 | } |
||
997 | else |
||
998 | { |
||
999 | //CB: If we have a selection but the user clicks with control on another item that is not below the current |
||
1000 | //then clear and select the new item |
||
1001 | if ((m->modifiers() == SELECT_BENEATH) && m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem) >= 0) |
||
1002 | m_doc->m_Selection->clear(); |
||
1003 | //CB: #7186: This was prependItem, does not seem to need to be anymore with current select code |
||
1004 | m_doc->m_Selection->addItem(currItem); |
||
16113 | fschmid | 1005 | if ( (m->modifiers() & SELECT_IN_GROUP) && (!currItem->isGroup())) |
12775 | jghali | 1006 | { |
1007 | currItem->isSingleSel = true; |
||
1008 | } |
||
1009 | } |
||
13132 | pierre | 1010 | m_canvas->update(); |
12775 | jghali | 1011 | m_doc->m_Selection->delaySignalsOff(); |
1012 | if (m_doc->m_Selection->count() > 1) |
||
1013 | { |
||
1014 | m_doc->m_Selection->setGroupRect(); |
||
1015 | double x, y, w, h; |
||
1016 | m_doc->m_Selection->getGroupRect(&x, &y, &w, &h); |
||
1017 | m_view->getGroupRectScreen(&x, &y, &w, &h); |
||
1018 | } |
||
1019 | if (m_doc->m_Selection->count() == 1) |
||
1020 | { |
||
1021 | frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem); |
||
1022 | if ((frameResizeHandle == Canvas::INSIDE) && (!currItem->locked())) |
||
18181 | fschmid | 1023 | m_view->setCursor(QCursor(Qt::SizeAllCursor)); |
12775 | jghali | 1024 | } |
1025 | else |
||
1026 | { |
||
18181 | fschmid | 1027 | m_view->setCursor(QCursor(Qt::SizeAllCursor)); |
12775 | jghali | 1028 | m_canvas->m_viewMode.operItemResizing = false; |
1029 | } |
||
1030 | return true; |
||
1031 | } |
||
1032 | m_doc->m_Selection->connectItemToGUI(); |
||
1033 | if ( !(m->modifiers() & SELECT_MULTIPLE)) |
||
1034 | m_view->Deselect(true); |
||
1035 | return false; |
||
1036 | } |
||
1037 | |||
1038 | void CanvasMode_Edit::createContextMenu(PageItem* currItem, double mx, double my) |
||
1039 | { |
||
1040 | ContextMenu* cmen=NULL; |
||
18181 | fschmid | 1041 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
12775 | jghali | 1042 | m_view->setObjectUndoMode(); |
1043 | Mxp = mx; |
||
1044 | Myp = my; |
||
1045 | if(currItem!=NULL) |
||
1046 | cmen = new ContextMenu(*(m_doc->m_Selection), m_ScMW, m_doc); |
||
1047 | else |
||
1048 | cmen = new ContextMenu(m_ScMW, m_doc, mx, my); |
||
1049 | if (cmen) |
||
1050 | cmen->exec(QCursor::pos()); |
||
1051 | m_view->setGlobalUndoMode(); |
||
1052 | delete cmen; |
||
1053 | } |