Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

canvasmode_legacy.cpp

Go to the documentation of this file.
00001 /*
00002  For general Scribus (>=1.3.2) copyright and licensing information please refer
00003  to the COPYING file provided with the program. Following this notice may exist
00004  a copyright and/or license notice that predates the release of Scribus 1.3.2
00005  for which a new license (GPL+exception) is in place.
00006  */
00007 /***************************************************************************
00008 *                                                                         *
00009 *   This program is free software; you can redistribute it and/or modify  *
00010 *   it under the terms of the GNU General Public License as published by  *
00011 *   the Free Software Foundation; either version 2 of the License, or     *
00012 *   (at your option) any later version.                                   *
00013 *                                                                         *
00014 ***************************************************************************/
00015 
00016 
00017 #include "canvasmode_legacy.h"
00018 
00019 #include <QApplication>
00020 #include <QButtonGroup>
00021 #include <QCheckBox>
00022 #include <QCursor>
00023 #include <QEvent>
00024 #include <QMessageBox>
00025 #include <QMouseEvent>
00026 #include <QPainterPath>
00027 #include <QPoint>
00028 #include <QRect>
00029 #include <QTimer>
00030 #include <QWidgetAction>
00031 
00032 
00033 #include "canvas.h"
00034 #include "canvasgesture_linemove.h"
00035 #include "canvasgesture_resize.h"
00036 #include "canvasgesture_rulermove.h"
00037 #include "contextmenu.h"
00038 #include "customfdialog.h"
00039 #include "fpoint.h"
00040 #include "fpointarray.h"
00041 // #include "hruler.h"
00042 // #include "vruler.h"
00043 #include "hyphenator.h"
00044 #include "insertTable.h"
00045 #include "oneclick.h"
00046 #include "pageitem_textframe.h"
00047 #include "pageselector.h"
00048 #include "prefscontext.h"
00049 #include "prefsfile.h"
00050 #include "prefsmanager.h"
00051 #include "propertiespalette.h"
00052 // #include "scraction.h"
00053 #include "scribus.h"
00054 #include "scribusdoc.h"
00055 #include "scribusview.h"
00056 #include "scribusXml.h"
00057 #include "selection.h"
00058 #include "stencilreader.h"
00059 #include "undomanager.h"
00060 #include "units.h"
00061 #include "util.h"
00062 #include "util_icon.h"
00063 #include "util_math.h"
00064 #include "loadsaveplugin.h"
00065 #include "fileloader.h"
00066 #include "plugins/formatidlist.h"
00067 
00068 
00069 
00070 LegacyMode::LegacyMode(ScribusView* view) : QObject(), CanvasMode(view), m_ScMW(view->m_ScMW) 
00071 {
00072     GxM = GyM = -1;
00073     Mxp = Myp = -1;
00074     Dxp = Dyp = -1;
00075     MoveGX = MoveGY = false;
00076     oldCp = Cp = -1;
00077     frameResizeHandle = -1;
00078     RotMode = 0;
00079     inItemCreation = false;
00080     shiftSelItems = false;
00081     FirstPoly = true;
00082     resizeGesture = NULL;
00083     lineMoveGesture = NULL;
00084     guideMoveGesture = NULL;
00085     m_blinker = new QTimer(view);
00086     connect(m_blinker, SIGNAL(timeout()), this, SLOT(blinkTextCursor()));
00087 }
00088 
00089 inline bool LegacyMode::GetItem(PageItem** pi)
00090 { 
00091     *pi = m_doc->m_Selection->itemAt(0); 
00092     return (*pi) != NULL; 
00093 }
00094 
00095 
00096 void LegacyMode::blinkTextCursor()
00097 {
00098     PageItem* currItem;
00099     if (m_doc->appMode == modeEdit && GetItem(&currItem))
00100     {
00101         QRectF brect = currItem->getBoundingRect();
00102 //      qDebug() << "update cursor" << brect;
00103         m_canvas->update(QRectF(m_canvas->canvasToLocal(brect.topLeft()), QSizeF(brect.width(),brect.height())*m_canvas->scale()).toRect());
00104     }
00105 }
00106 
00107 
00108 
00109 void LegacyMode::drawControls(QPainter* p)
00110 {
00111 //  qDebug() << "LegacyMode::drawControls";
00112     if (m_canvas->m_viewMode.operItemMoving)
00113     {
00114         drawOutline(p);
00115     }
00116     else
00117     {
00118         drawSelection(p);
00119     }
00120     PageItem* currItem;
00121     if (m_doc->appMode == modeEdit && GetItem(&currItem))
00122     {
00123         PageItem_TextFrame* textframe = currItem->asTextFrame();
00124         if (textframe)
00125             drawTextCursor(p, textframe);
00126     }
00127 }
00128 
00129 
00130 void LegacyMode::drawTextCursor(QPainter *p, PageItem_TextFrame* textframe)
00131 {
00132     int x, y, y1;
00133     if (textframe->CPos > textframe->itemText.length())
00134     {
00135         textframe->CPos = textframe->itemText.length();
00136     }
00137     if (textframe->lastInFrame() >= signed(textframe->itemText.nrOfItems()) 
00138         || textframe->itemText.length() == 0)
00139     {
00140         x = 0;
00141         y = 0;
00142         y1 = static_cast<int>(textframe->itemText.defaultStyle().charStyle().fontSize() / 10);
00143     }
00144     else if ( textframe->CPos > textframe->itemText.endOfItem(textframe->lastInFrame())
00145               || (textframe->CPos >= textframe->itemText.length() && textframe->itemText.text(textframe->itemText.length()-1) != SpecialChars::PARSEP) )
00146     {
00147         FRect bbox = textframe->itemText.boundingBox(qMax(0,qMin(textframe->lastInFrame(), textframe->itemText.length()-1)));
00148         x = static_cast<int>(bbox.x() + textframe->itemText.item(qMax(0,qMin(textframe->lastInFrame(), textframe->itemText.length()-1)))->glyph.wide());
00149         y = static_cast<int>(bbox.y());
00150         if (bbox.height() <= 2)
00151             y1 = static_cast<int>(bbox.y() + textframe->itemText.defaultStyle().charStyle().fontSize() / 30);
00152         else
00153             y1 = static_cast<int>(bbox.y() + bbox.height());
00154     }
00155     else
00156     {
00157         FRect bbox = textframe->itemText.boundingBox(qMax(0,qMin(textframe->CPos, textframe->itemText.length())));
00158         x = static_cast<int>(bbox.x());
00159         y = static_cast<int>(bbox.y());
00160         if (bbox.height() <= 2) 
00161             y1 = static_cast<int>(bbox.y() + textframe->itemText.charStyle(textframe->CPos).fontSize() / 30);
00162         else
00163             y1 = static_cast<int>(bbox.y() + bbox.height());
00164     }
00165 
00166     // avoid displaying the cursor on the frameborder
00167     if (x < 1)
00168         x = 1;
00169                 
00170     p->save();
00171     p->translate(textframe->xPos(), textframe->yPos());
00172     p->rotate(textframe->rotation());
00173     p->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
00174     if (m_blinkTime.elapsed() > qApp->cursorFlashTime() / 2)
00175     {
00176 //      qDebug() << "blink";
00177         m_cursorVisible = !m_cursorVisible;
00178         m_blinkTime.restart();
00179     }
00180 //  else
00181 //      qDebug() << "no blink" << m_blinkTime.elapsed() ;
00182     if (m_cursorVisible)
00183     {
00184         int p1 = qMin(qMax(y,0),static_cast<int>(textframe->height()));
00185         int p2 = qMin(qMax(y1,0),static_cast<int>(textframe->height()));
00186         p->drawLine(x, p1, x, p2);
00187     }
00188     p->restore();
00189 }
00190 
00191 void LegacyMode::enterEvent(QEvent *)
00192 {
00193     if (!m_canvas->m_viewMode.m_MouseButtonPressed)
00194     {
00195         setModeCursor();
00196     }
00197 }
00198 
00199 
00200 void LegacyMode::leaveEvent(QEvent *e)
00201 {
00202     if (!m_canvas->m_viewMode.m_MouseButtonPressed)
00203         qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00204 }
00205 
00206 
00207 void LegacyMode::activate(bool fromGesture)
00208 {
00209     qDebug() << "LegacyMode::activate" << fromGesture;
00210     m_canvas->m_viewMode.m_MouseButtonPressed = false;
00211     m_canvas->resetRenderMode();
00212     m_doc->DragP = false;
00213     m_doc->leaveDrag = false;
00214     m_canvas->m_viewMode.operItemMoving = false;
00215     m_canvas->m_viewMode.operItemResizing = false;
00216     m_view->MidButt = false;
00217     GxM = GyM = -1;
00218     Mxp = Myp = -1;
00219     Dxp = Dyp = -1;
00220     MoveGX = MoveGY = false;
00221     oldCp = Cp = -1;
00222     frameResizeHandle = -1;
00223     RotMode = 0;
00224     inItemCreation = false;
00225     shiftSelItems = false;
00226     FirstPoly = true;
00227     setModeCursor();
00228     if (m_doc->appMode == modeEdit)
00229     {
00230         m_blinker->start(500);
00231         m_blinkTime.start();
00232         m_cursorVisible = true;
00233     }
00234     if (fromGesture)
00235     {
00236         m_canvas->m_viewMode.operItemResizeInEditMode = false;
00237         m_view->update();
00238     }
00239 }
00240 
00241 void LegacyMode::deactivate(bool forGesture)
00242 {
00243     qDebug() << "LegacyMode::deactivate" << forGesture;
00244     m_view->redrawMarker->hide();
00245     if (!forGesture)
00246         m_blinker->stop();
00247 }
00248 
00249 void LegacyMode::mouseDoubleClickEvent(QMouseEvent *m)
00250 {
00251     m->accept();
00252     m_canvas->m_viewMode.m_MouseButtonPressed = false;
00253     m_canvas->resetRenderMode();
00254     m_view->stopDragTimer();
00255     PageItem *currItem = 0;
00256     if ((m_doc->m_Selection->isMultipleSelection()) || (m_doc->appMode != modeNormal))
00257     {
00258         if ((m_doc->m_Selection->isMultipleSelection()) && (m_doc->appMode == modeNormal))
00259         {
00260             if (GetItem(&currItem))
00261             {
00262                 if (currItem->isTableItem)
00263                 {
00264                     m_view->Deselect(false);
00265                     m_doc->m_Selection->addItem(currItem);
00266                     currItem->isSingleSel = true;
00267                     //CB FIXME dont call this if the added item is item 0
00268                     if (!m_doc->m_Selection->primarySelectionIs(currItem))
00269                         currItem->emitAllToGUI();
00270                     m_view->updateContents(currItem->getRedrawBounding(m_canvas->scale()));
00271                 }
00272             }
00273             return;
00274         }
00275         else
00276         {
00277             if (!(GetItem(&currItem) && (m_doc->appMode == modeEdit) && currItem->asTextFrame()))
00278             {
00279                 mousePressEvent(m);
00280                 return;
00281             }
00282         }
00283     }
00284     if (GetItem(&currItem))
00285     {
00286         if (currItem->asLatexFrame()) {
00287             if ((currItem->locked()) || (!currItem->ScaleType))
00288             {
00289                 return;
00290             }
00291             if (currItem->imageShown())
00292                 m_view->requestMode(modeEdit);
00293         } else if ((currItem->itemType() == PageItem::Polygon) || (currItem->itemType() == PageItem::PolyLine) || (currItem->itemType() == PageItem::ImageFrame) || (currItem->itemType() == PageItem::PathText))
00294         {
00295             if ((currItem->locked()) || (!currItem->ScaleType))
00296             {
00297                 //              mousePressEvent(m);
00298                 return;
00299             }
00300             //If we double click on an image frame and theres no image assigned, open the
00301             //load picture dialog, else put it into edit mode if the frame is set to show the image
00302             if (currItem->itemType() == PageItem::ImageFrame)
00303             {
00304                 if (currItem->Pfile.isEmpty())
00305                     m_view->requestMode(submodeLoadPic);
00306                 else if (!currItem->PicAvail)
00307                     m_view->requestMode(submodeStatusPic);
00308                 else if (currItem->imageShown())
00309                     m_view->requestMode(modeEdit);
00310             }
00311             else if (currItem->itemType() == PageItem::TextFrame)
00312                 m_view->requestMode(modeEdit);
00313             else
00314                 m_view->requestMode(modeEditClip);              
00315         }
00316         else
00317             if (currItem->itemType() == PageItem::TextFrame)
00318             {
00319                 //CB old code
00320                 //emit currItem->isAnnotation() ? AnnotProps() : Amode(modeEdit);
00321                 //mousePressEvent(m);
00322                 //CB if annotation, open the annotation dialog
00323                 if (currItem->isAnnotation())
00324                 {
00325                     m_view->requestMode(submodeAnnotProps);
00326                     //                  mousePressEvent(m);
00327                 }
00328                 //else if not in mode edit, set mode edit
00329                 else if (m_doc->appMode != modeEdit)
00330                 {
00331                     m_view->requestMode(modeEdit);
00332                     m_view->slotSetCurs(m->x(), m->y());
00333                     //CB ignore the double click and go with a single one
00334                     //if we werent in mode edit before.
00335                     //unsure if this is correct, but its ok given we had no
00336                     //double click select until now.
00337 //                  mousePressEvent(m);
00338                 }
00339                 //otherwise, select between the whitespace
00340                 else
00341                 {   //Double click in a frame to select a word
00342                     PageItem_TextFrame *cItem=currItem->asTextFrame();
00343                     bool inText = m_view->slotSetCurs(m->x(), m->y());
00344                     if (!inText)
00345                     {
00346                         m_view->Deselect(true);
00347 //                      m_view->slotDoCurs(true);
00348                         m_view->requestMode(modeNormal);
00349                         return;
00350                     }
00351                     int a=cItem->CPos;
00352                     while(a>0)
00353                     {
00354                         if (cItem->itemText.text(a-1).isLetterOrNumber())
00355                             --a;
00356                         else
00357                             break;
00358                     }
00359                     int b=cItem->CPos;
00360                     while(b<cItem->itemText.length())
00361                     {
00362                         if (cItem->itemText.text(b).isLetterOrNumber())
00363                             ++b;
00364                         else
00365                             break;
00366                     }
00367                     oldCp = a;
00368                     cItem->CPos=b;
00369                     cItem->ExpandSel(1, oldCp);
00370 //                  m_view->slotDoCurs(true);
00371                 }
00372             }
00373     }
00374 }
00375 
00376 
00377 void LegacyMode::mouseMoveEvent(QMouseEvent *m)
00378 {
00379 //  const double mouseX = m->globalX();
00380 //  const double mouseY = m->globalY();
00381     const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
00382     
00383     double newX, newY;
00384     double nx, ny;
00385     PageItem *currItem;
00386     QPoint np, np2, mop;
00387     FPoint npf, npf2;
00388     QPainter p;
00389     QRect tx;
00390     bool erf = false;
00391 //  double sc = m_canvas->scale();
00392 //  m_view->horizRuler->Draw(m->x());
00393 //  m_view->vertRuler->Draw(m->y());
00394     m->accept();
00395 //  qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
00396 //  emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(), 
00397 //                m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
00398 /*  if (false && m_doc->guidesSettings.guidesShown)
00399     {
00400         if (MoveGY)
00401         {
00402             m_view->FromHRuler(m);
00403             return;
00404         }
00405         if (MoveGX)
00406         {
00407             m_view->FromVRuler(m);
00408             return;
00409         }
00410     }*/
00411 /*  if ((!m_doc->DragP) && (m_canvas->m_viewMode.m_MouseButtonPressed) && (SelItem.count() != 0))
00412     {
00413         int cx = Anz->contentsX() - Anz->childX(doku->currentPage->parentWidget());
00414         int cy = Anz->contentsY() - Anz->childY(doku->currentPage->parentWidget());
00415         int cw = Anz->visibleWidth();
00416         int ch = Anz->visibleHeight();
00417         if ((m->y() < cy+10) || ((ch - (m->y() - cy)) - 10 < 0) || (m->x() < cx + 10) || ((cw - (m->x() - cx)) - 10 < 0))
00418         {
00419             if (m->y() < cy+10)
00420                 Anz->scrollBy(0, m->y() - cy - 10);
00421             else if ((ch - (m->y() - cy)) - 10 < 0)
00422                 Anz->scrollBy(0, m->y() - cy - ch +10);
00423             else if (m->x() < cx + 10)
00424                 Anz->scrollBy(m->x() - cx - 10, 0);
00425             else if ((cw - (m->x() - cx)) - 10 < 0)
00426                 Anz->scrollBy(m->x() - cx - cw + 10, 0);
00427             BlockLeave = true;
00428             update();
00429         }
00430     else
00431         BlockLeave = false;
00432     } */
00433 
00434     if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeEditGradientVectors))
00435     {
00436         PageItem *currItem = m_doc->m_Selection->itemAt(0);
00437         newX = mousePointDoc.x(); //m->x();
00438         newY = mousePointDoc.y(); //m->y();
00439         double dx = fabs(Mxp - newX) + 5.0 / m_canvas->scale();
00440         double dy = fabs(Myp - newY) + 5.0 / m_canvas->scale();
00441         if (m->buttons() & Qt::LeftButton)
00442         {
00443             currItem->GrStartX -= (Mxp - newX); // / m_canvas->scale();
00444             currItem->GrStartY -= (Myp - newY); // / m_canvas->scale();
00445         }
00446         if (m->buttons() & Qt::RightButton)
00447         {
00448             currItem->GrEndX -= (Mxp - newX); // / m_canvas->scale();
00449             currItem->GrEndY -= (Myp - newY); // / m_canvas->scale();
00450         }
00451         Mxp = newX;
00452         Myp = newY;
00453         m_view->RefreshGradient(currItem, dx * m_canvas->scale(), dy * m_canvas->scale());
00454         m_ScMW->propertiesPalette->updateColorSpecialGradient();
00455         return;
00456     }
00457     if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeMeasurementTool))
00458     {
00459         // bloody hack since signal MVals is declared with ScribusView for now
00460         // measurements palette should be controlled directly by MeasurementMode
00461 //FIXME:av      m_view->contentsMouseMoveEvent(m);
00462         
00463 /*
00464         newX = m->x();
00465         newY = m->y();
00466         m_canvas->newRedrawPolygon() << QPoint(Dxp, Dyp) << QPoint(newX, newY);
00467         m_view->updateContents(QRect(QPoint(Dxp, Dyp), QPoint(newX, newY)).normalized().adjusted(-10, -10, 20, 20));
00468         Mxp = newX;
00469         Myp = newY;
00470         double dxp = Dxp / sc - m_doc->currentPage()->xOffset();//+ m_doc->minCanvasCoordinate.x();
00471             double dyp = Dyp / sc - m_doc->currentPage()->yOffset();//+ m_doc->minCanvasCoordinate.y();
00472                 double nxp = newX / sc - m_doc->currentPage()->xOffset();//+ m_doc->minCanvasCoordinate.x();
00473                     double nyp = newY / sc - m_doc->currentPage()->yOffset();//+ m_doc->minCanvasCoordinate.y();
00474         emit MVals(dxp, dyp, nxp, nyp, -xy2Deg(newX/sc - Dxp/sc, newY/sc - Dyp/sc), sqrt(pow(newX/sc - Dxp/sc,2)+pow(newY/sc - Dyp/sc,2)), m_doc->unitIndex());
00475 */
00476         return;
00477     }
00478     if (m_canvas->m_viewMode.m_MouseButtonPressed && (m->buttons() & Qt::RightButton) && (m->modifiers() & Qt::ControlModifier))
00479     {
00480         m_ScMW->setAppMode(modePanning);
00481     }
00482     if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modePanning))
00483     {
00484         double sc = m_canvas->scale();
00485         int scroX = qRound((mousePointDoc.x() - Mxp) * sc);
00486         int scroY = qRound((mousePointDoc.y() - Myp) * sc);
00487         m_view->scrollBy(-scroX, -scroY);
00488 //      Mxp = static_cast<int>((m->x()-scroX)/sc);
00489 //      Myp = static_cast<int>((m->y()-scroY)/sc);
00490         Mxp = mousePointDoc.x();
00491         Myp = mousePointDoc.y();
00492         return;
00493     }
00494     if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeDrawFreehandLine))
00495     {
00496         //newX = m->x();
00497         //newY = m->y();
00498         double newXF = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
00499         double newYF = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
00500         if (RecordP.size() > 0)
00501         {
00502             if (FPoint(newXF, newYF) != RecordP.point(RecordP.size()-1))
00503                 RecordP.addPoint(FPoint(newXF, newYF));
00504         }
00505         else
00506             RecordP.addPoint(FPoint(newXF, newYF));
00507         QPolygon& redrawPolygon(m_canvas->newRedrawPolygon());
00508         for (uint pp = 0; pp < RecordP.size(); pp++)
00509         {
00510             redrawPolygon << RecordP.pointQ(pp);
00511         }
00512         m_canvas->m_viewMode.operItemResizing = true;
00513         QRect bRect = m_canvas->redrawPolygon().boundingRect();
00514 //      QPoint in(qRound(bRect.x()*m_canvas->scale()), qRound(bRect.y()*m_canvas->scale()));
00515 //      in -= QPoint(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
00516 //      QPoint out = contentsToViewport(in);
00517 //      m_view->updateContents(QRect(out.x()+0*contentsX(), out.y()+0*contentsY(), qRound(bRect.width()*m_canvas->scale()), qRound(bRect.height()*m_canvas->scale())).adjusted(-10, -10, 20, 20));
00518         m_view->updateContents(bRect);
00519         return;
00520     }
00521     if ((GetItem(&currItem)) && (!shiftSelItems))
00522     {
00523         newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
00524         newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
00525         if ((((m_view->dragTimerElapsed()) && (m->buttons() & Qt::LeftButton)) || (m_view->moveTimerElapsed() && (m->buttons() & Qt::RightButton)))
00526             && (m_canvas->m_viewMode.m_MouseButtonPressed)
00527             && (!m_doc->DragP) 
00528             && (m_doc->appMode == modeNormal) 
00529             && (!(currItem->isSingleSel)))
00530         {
00531             // start drag
00532             m_view->stopDragTimer();
00533             if ((fabs(Dxp - newX) > 10) || (fabs(Dyp - newY) > 10))
00534             {
00535                 m_canvas->setRenderMode(Canvas::RENDER_NORMAL);
00536                 m_view->resetDragTimer();
00537                 m_doc->DragP = true;
00538                 m_doc->leaveDrag = false;
00539                 m_doc->DraggedElem = currItem;
00540                 m_doc->DragElements.clear();
00541                 for (int dre=0; dre<m_doc->m_Selection->count(); ++dre)
00542                     m_doc->DragElements.append(m_doc->m_Selection->itemAt(dre)->ItemNr);
00543                 ScriXmlDoc *ss = new ScriXmlDoc();
00544                 //Q_3DragObject *dr = new Q_3TextDrag(ss->WriteElem(Doc, this, m_doc->m_Selection), this);
00545                 QMimeData* md = new QMimeData();
00546                 md->setText(ss->WriteElem(m_doc, m_view, m_doc->m_Selection));
00547                 QDrag* dr = new QDrag(m_view);
00548                 dr->setMimeData(md);
00549                 const QPixmap& pm = loadIcon("DragPix.xpm");
00550                 dr->setDragCursor(pm, Qt::CopyAction);
00551                 dr->setDragCursor(pm, Qt::MoveAction);
00552                 dr->setDragCursor(pm, Qt::LinkAction);
00553                 dr->exec();
00554 //              QImage drImg = currItem->DrawObj_toImage();
00555 //              QPixmap pm;
00556 //              pm.convertFromImage(drImg);
00557 //              dr->setPixmap(pm);
00558 //              dr->setPixmap(loadIcon("DragPix.xpm"));
00559 //              dr->drag();
00560 //              if (!dr->drag())
00561 //                  qDebug("ScribusView::contentsMouseMoveEvent: couldn't start drag operation!");
00562 /* commented out the code above as the debug message is incorrect,
00563    see the Qt Reference: "The function returns TRUE if the caller should delete the original copy
00564     of the dragged data (but see target()); otherwise returns FALSE." */
00565                 delete ss;
00566                 ss=NULL;
00567                 m_doc->DragP = false;
00568                 m_doc->leaveDrag = false;
00569                 m_canvas->m_viewMode.m_MouseButtonPressed = false;
00570                 m_doc->DraggedElem = 0;
00571                 m_doc->DragElements.clear();
00572                 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00573                 m_view->updateContents();
00574             }
00575             return;
00576         }
00577         if (m_doc->DragP)
00578             return;
00579         if (m_view->moveTimerElapsed() && m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeRotation))
00580         {
00581             m_view->stopDragTimer();
00582             if (!m_view->groupTransactionStarted() && m_doc->m_Selection->isMultipleSelection())
00583             {
00584                 m_view->startGroupTransaction(Um::Rotate, "", Um::IRotate);
00585             }
00586             double newW = xy2Deg(mousePointDoc.x()-m_view->RCenter.x(), mousePointDoc.y()-m_view->RCenter.y()); //xy2Deg(m->x()/sc - m_view->RCenter.x(), m->y()/sc - m_view->RCenter.y());
00587             if (m->modifiers() & Qt::ControlModifier)
00588             {
00589                 newW=constrainAngle(newW, m_doc->toolSettings.constrain);
00590                 m_view->oldW=constrainAngle(m_view->oldW, m_doc->toolSettings.constrain);
00591                 //RotateGroup uses MoveBy so its pretty hard to constrain the result
00592                 if (m_doc->m_Selection->isMultipleSelection())
00593                     m_doc->rotateGroup(newW-m_view->oldW, m_view->RCenter);
00594                 else
00595                     m_doc->RotateItem(newW, currItem->ItemNr);
00596             }
00597             else
00598             {
00599                 if (m_doc->m_Selection->isMultipleSelection())
00600                     m_doc->rotateGroup(newW - m_view->oldW, m_view->RCenter);
00601                 else
00602                     m_doc->RotateItem(currItem->rotation() - (m_view->oldW - newW), currItem->ItemNr);
00603             }
00604             m_view->oldW = newW;
00605 // rotate calls PageItem::update            emit DocChanged();
00606         }
00607         if (m_doc->appMode == modeDrawBezierLine)
00608         {
00609             if ((m_doc->useRaster) && (m_doc->OnPage(currItem) != -1))
00610             {
00611                 newX = qRound(newX / m_doc->guidesSettings.minorGrid) * m_doc->guidesSettings.minorGrid;
00612                 newY = qRound(newY / m_doc->guidesSettings.minorGrid) * m_doc->guidesSettings.minorGrid;
00613             }
00614             m_canvas->newRedrawPolygon() << QPoint(qRound(newX - currItem->xPos()), qRound(newY - currItem->yPos()));
00615             m_view->updateContents();
00616             Mxp = newX;
00617             Myp = newY;
00618         }
00619         if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeDrawRegularPolygon))
00620         {
00621             if (m->modifiers() & Qt::ShiftModifier)
00622             {
00623 //              mop = QPoint(m->x(), static_cast<int>((currItem->yPos() + (newX - currItem->xPos())) * sc));
00624                 newY = static_cast<int>(currItem->yPos() + (newX - currItem->xPos()));
00625                 QCursor::setPos(m_canvas->canvasToGlobal(FPoint(newX, newY)));
00626 //              newY = static_cast<int>(mop.y()/sc);
00627             }
00628             if ((m_doc->useRaster) && (m_doc->OnPage(currItem) != -1))
00629             {
00630                 newX = qRound(newX / m_doc->guidesSettings.minorGrid) * m_doc->guidesSettings.minorGrid;
00631                 newY = qRound(newY / m_doc->guidesSettings.minorGrid) * m_doc->guidesSettings.minorGrid;
00632             }
00633             QMatrix mp = currItem->getTransform();
00634 //          mp.translate(currItem->xPos(),// - m_doc->minCanvasCoordinate.x(), 
00635 //                       currItem->yPos()); // - m_doc->minCanvasCoordinate.y());
00636 //          mp.rotate(currItem->rotation());
00637             np2 = QPoint(static_cast<int>(newX), static_cast<int>(newY)) * mp.inverted();
00638             QMatrix pm;
00639             m_canvas->Transform(currItem, pm);
00640             m_canvas->PaintSizeRect(pm.mapToPolygon(QRect(QPoint(0, 0), np2)));
00641 //          emit ItemGeom(newX - currItem->xPos(), newY - currItem->yPos());
00642             Mxp = newX;
00643             Myp = newY;
00644         }
00645         if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeDrawLine))
00646         {
00647             if (m_doc->useRaster)
00648             {
00649                 newX = qRound(newX / m_doc->guidesSettings.minorGrid) * m_doc->guidesSettings.minorGrid;
00650                 newY = qRound(newY / m_doc->guidesSettings.minorGrid) * m_doc->guidesSettings.minorGrid;
00651             }
00652             double newRot=xy2Deg(newX - currItem->xPos(), newY - currItem->yPos());
00653             //Constrain rotation angle, when the mouse is being dragged around for a new line
00654             if (m->modifiers() & Qt::ControlModifier)
00655             {
00656                 //Flip our angles around here
00657                 if (newRot<0.0)
00658                     newRot=-newRot;
00659                 else
00660                     newRot=360-newRot;
00661                 newRot=constrainAngle(newRot, m_doc->toolSettings.constrain);
00662                 double hlen=sqrt(pow(newX - currItem->xPos(),2)+pow(newY - currItem->yPos(),2));
00663                 newX = qRound(currItem->xPos()+(hlen * cos(newRot/(180.0/M_PI))));
00664                 newY = qRound(currItem->yPos()-(hlen * sin(newRot/(180.0/M_PI))));
00665             }
00666 //          emit SetAngle(newRot);
00667 //          emit ItemGeom(sqrt(pow(newX - currItem->xPos(),2)+pow(newY - currItem->yPos(),2)), 0);
00668             m_canvas->newRedrawPolygon() << QPoint(qRound(currItem->xPos()), qRound(currItem->yPos())) << QPoint(qRound(newX), qRound(newY));
00669             newX = mousePointDoc.x(); //m->x();
00670             newY = mousePointDoc.y(); //m->y();
00671             m_view->updateCanvas(QRectF(QPointF(Dxp, Dyp), QPointF(newX, newY)).normalized().adjusted(-10, -10, 20, 20));
00672             Mxp = newX;
00673             Myp = newY;
00674         }
00675         if (m_canvas->m_viewMode.m_MouseButtonPressed && (m_doc->appMode == modeEdit) && (!m_canvas->m_viewMode.operItemResizeInEditMode))
00676         {
00677             if (currItem->asImageFrame())
00678             {
00679                 QMatrix ro;
00680                 ro.rotate(-currItem->rotation());
00681                 QPointF rota = ro.map(QPointF(newX-Mxp,newY-Myp));
00682                 currItem->moveImageInFrame(rota.x()/currItem->imageXScale(), rota.y()/currItem->imageYScale());
00683         //      m_view->updateContents(currItem->getRedrawBounding(m_canvas->scale()));
00684                 currItem->update();
00685                 Mxp = newX;
00686                 Myp = newY;
00687             }
00688             if (currItem->asTextFrame())
00689             {
00690                 currItem->itemText.deselectAll();
00691                 currItem->HasSel = false;
00692                 m_view->slotSetCurs(m->x(), m->y());
00693                 //Make sure we dont go here if the old cursor position was not set
00694                 if (oldCp!=-1 && currItem->itemText.length() > 0)
00695                 {
00696                     if (currItem->CPos < oldCp)
00697                     {
00698                         currItem->itemText.select(currItem->CPos, oldCp - currItem->CPos);
00699                         currItem->HasSel = true;
00700                     }
00701                     if (currItem->CPos > oldCp)
00702                     {
00703                         currItem->itemText.select(oldCp, currItem->CPos - oldCp);
00704                         currItem->HasSel = true;
00705                     }
00706                 }
00707                 currItem->update();
00708                 if(currItem->HasSel)
00709                     m_ScMW->EnableTxEdit();
00710                 else
00711                     m_ScMW->DisableTxEdit();
00712             }
00713         }
00714         //Operations run here:
00715         //Item resize, esp after creating a new one
00716         if (m_view->moveTimerElapsed() && m_canvas->m_viewMode.m_MouseButtonPressed && (m->buttons() & Qt::LeftButton) && 
00717             ((m_doc->appMode == modeNormal) || ((m_doc->appMode == modeEdit) && m_canvas->m_viewMode.operItemResizeInEditMode)) && (!currItem->locked()))
00718         {
00719             m_view->stopDragTimer();
00720             if (m_canvas->m_viewMode.operItemResizing)
00721             {
00722 //              newX = static_cast<int>(m->x()/sc);
00723 //              newY = static_cast<int>(m->y()/sc);
00724                 m_canvas->m_viewMode.operItemMoving = false;
00725                 if (m_doc->m_Selection->isMultipleSelection())
00726                 {
00727 //                  newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
00728 //                  newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
00729                     double gx, gy, gh, gw;
00730                     m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
00731                     const double sc=1;
00732                     int ox1 = qRound(gx*sc);
00733                     int oy1 = qRound(gy*sc);
00734                     int ox2 = qRound((gx+gw)*sc);
00735                     int oy2 = qRound((gy+gh)*sc);
00736                     FPoint np2 = FPoint(newX, newY);
00737                     np2 = m_doc->ApplyGridF(mousePointDoc);
00738                     double nx = np2.x();