Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

canvasmode_drawfreehand.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_drawfreehand.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 <QWidgetAction>
00030 
00031 
00032 #include "canvas.h"
00033 #include "canvasgesture_resize.h"
00034 #include "fpoint.h"
00035 #include "fpointarray.h"
00036 #include "hruler.h"
00037 #include "vruler.h"
00038 #include "hyphenator.h"
00039 #include "insertTable.h"
00040 #include "KarbonCurveFit.h"
00041 #include "oneclick.h"
00042 #include "pageitem_textframe.h"
00043 #include "pageselector.h"
00044 #include "prefscontext.h"
00045 #include "prefsfile.h"
00046 #include "prefsmanager.h"
00047 #include "propertiespalette.h"
00048 #include "scraction.h"
00049 #include "scrapbookpalette.h"
00050 #include "scribus.h"
00051 #include "scribusdoc.h"
00052 #include "scribusview.h"
00053 #include "scribusXml.h"
00054 #include "selection.h"
00055 #include "undomanager.h"
00056 #include "units.h"
00057 #include "util.h"
00058 #include "util_icon.h"
00059 #include "util_math.h"
00060 
00061 
00062 
00063 FreehandMode::FreehandMode(ScribusView* view) : CanvasMode(view) 
00064 {
00065     GxM = GyM = -1;
00066     Mxp = Myp = -1;
00067     Dxp = Dyp = -1;
00068     MoveGX = MoveGY = false;
00069     oldCp = Cp = -1;
00070     frameResizeHandle = -1;
00071     RotMode = 0;
00072     inItemCreation = false;
00073     shiftSelItems = false;
00074     FirstPoly = true;
00075 }
00076 
00077 
00078 void FreehandMode::drawControls(QPainter* p) 
00079 {
00080     //
00081 }
00082 
00083 inline bool FreehandMode::GetItem(PageItem** pi)
00084 { 
00085     *pi = m_doc->m_Selection->itemAt(0); 
00086     return (*pi) != NULL; 
00087 }
00088 
00089 
00090 
00091 
00092 // the following code was moved from scribusview.cpp:
00093 
00094 
00095 void FreehandMode::enterEvent(QEvent *)
00096 {
00097     if (!m_MouseButtonPressed)
00098     {
00099         setModeCursor();
00100     }
00101 }
00102 
00103 
00104 void FreehandMode::leaveEvent(QEvent *e)
00105 {
00106     if (!m_MouseButtonPressed)
00107         qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00108 }
00109 
00110 
00111 void FreehandMode::activate(bool flag)
00112 {
00113     qDebug() << "FreehandMode::activate" << flag;
00114     GxM = GyM = -1;
00115     Mxp = Myp = -1;
00116     Dxp = Dyp = -1;
00117     MoveGX = MoveGY = false;
00118     oldCp = Cp = -1;
00119     frameResizeHandle = -1;
00120     RotMode = 0;
00121     inItemCreation = false;
00122     shiftSelItems = false;
00123     FirstPoly = true;
00124     setModeCursor();
00125 }
00126 
00127 void FreehandMode::deactivate(bool flag)
00128 {
00129     qDebug() << "FreehandMode::deactivate" << flag;
00130     m_view->redrawMarker->hide();
00131 }
00132 
00133 void FreehandMode::mouseDoubleClickEvent(QMouseEvent *m)
00134 {
00135     m->accept();
00136     m_MouseButtonPressed = false;
00137     m_canvas->resetRenderMode();
00138     mousePressEvent(m);
00139 }
00140 
00141 
00142 void FreehandMode::mouseMoveEvent(QMouseEvent *m)
00143 {
00144     const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
00145     
00146     double newX, newY;
00147     PageItem *currItem;
00148     QPoint np, np2, mop;
00149     FPoint npf, npf2;
00150     QPainter p;
00151     QRect tx;
00152     m->accept();
00153 //  qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
00154 //  emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(), 
00155 //                m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
00156 /*  if (m_doc->guidesSettings.guidesShown)
00157     {
00158         if (MoveGY)
00159         {
00160             m_view->FromHRuler(m);
00161             return;
00162         }
00163         if (MoveGX)
00164         {
00165             m_view->FromVRuler(m);
00166             return;
00167         }
00168     }
00169 */
00170     
00171     if (m_MouseButtonPressed && (m->buttons() & Qt::RightButton) && (m->modifiers() & Qt::ControlModifier))
00172     {
00173         m_view->requestMode(modePanning);
00174     }
00175 
00176     
00177     if (m_MouseButtonPressed && (m_doc->appMode == modeDrawFreehandLine))
00178     {
00179         //newX = m->x();
00180         //newY = m->y();
00181         double newXF = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
00182         double newYF = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
00183         if (RecordP.size() > 0)
00184         {
00185             if (FPoint(newXF, newYF) != RecordP.point(RecordP.size()-1))
00186                 RecordP.addPoint(FPoint(newXF, newYF));
00187         }
00188         else
00189             RecordP.addPoint(FPoint(newXF, newYF));
00190         QPolygon& redrawPolygon(m_canvas->newRedrawPolygon());
00191         for (uint pp = 0; pp < RecordP.size(); pp++)
00192         {
00193             redrawPolygon << RecordP.pointQ(pp);
00194         }
00195 //FIXME     
00196         m_canvas->m_viewMode.operItemResizing = true;
00197         QRect bRect = m_canvas->redrawPolygon().boundingRect();
00198 //      QPoint in(qRound(bRect.x()*m_canvas->scale()), qRound(bRect.y()*m_canvas->scale()));
00199 //      in -= QPoint(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
00200 //      QPoint out = contentsToViewport(in);
00201 //      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));
00202     //  m_canvas->update(bRect);
00203         m_view->updateCanvas(bRect);
00204         return;
00205     }
00206     
00207     if ((GetItem(&currItem)) && (!shiftSelItems))
00208     {
00209         newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
00210         newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
00211         
00212         if (m_doc->DragP)
00213             return;
00214                 
00215         if ((!m_MouseButtonPressed) && (m_doc->appMode != modeDrawBezierLine))
00216         {
00217             if (m_doc->m_Selection->isMultipleSelection())
00218             {
00219                 setModeCursor();
00220                 return;
00221             }
00222             for (int a = 0; a < m_doc->m_Selection->count(); ++a)
00223             {
00224                 currItem = m_doc->m_Selection->itemAt(a);
00225                 if (currItem->locked())
00226                     break;
00227                 setModeCursor();
00228             }
00229         }
00230     }
00231     else
00232     {
00233         if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1))
00234         {
00235             newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
00236             newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
00237             SeRx = newX;
00238             SeRy = newY;
00239             /*
00240             if (m_doc->appMode == modeDrawTable)
00241                 m_view->redrawMarker->setGeometry(QRect(Dxp, Dyp, m->globalPos().x() - Dxp, m->globalPos().y() - Dyp).normalized());
00242             else
00243                 m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
00244             */
00245             QPoint startP = m_canvas->canvasToGlobal(m_doc->appMode == modeDrawTable? QPointF(Dxp, Dyp) : QPointF(Mxp, Myp));
00246             m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
00247             if (!m_view->redrawMarker->isVisible())
00248                 m_view->redrawMarker->show();
00249             m_view->HaveSelRect = true;
00250             return;
00251         }
00252     }
00253 }
00254 
00255 void FreehandMode::mousePressEvent(QMouseEvent *m)
00256 {
00257     const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
00258     double Rxp = 0;
00259     double Ryp = 0;
00260     double Rxpd = 0;
00261     double Rypd = 0;
00262     QPainter p;
00263 //  m_canvas->PaintSizeRect(QRect());
00264     FPoint npf, npf2;
00265     QRect tx;
00266     QMatrix pm;
00267     m_MouseButtonPressed = true;
00268     m_view->HaveSelRect = false;
00269     m_doc->DragP = false;
00270     m_doc->leaveDrag = false;
00271     MoveGX = MoveGY = false;
00272     inItemCreation = false;
00273 //  oldClip = 0;
00274     m->accept();
00275     m_view->registerMousePress(m->globalPos());
00276     Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
00277     Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
00278     QRect mpo(m->x()-m_doc->guidesSettings.grabRad, m->y()-m_doc->guidesSettings.grabRad, m_doc->guidesSettings.grabRad*2, m_doc->guidesSettings.grabRad*2);
00279 //  mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
00280     Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
00281     Rxpd = Mxp - Rxp;
00282     Mxp = qRound(Rxp);
00283     Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
00284     Rypd = Myp - Ryp;
00285     Myp = qRound(Ryp);
00286     SeRx = Mxp;
00287     SeRy = Myp;
00288     if (m->button() == Qt::MidButton)
00289     {
00290         m_view->MidButt = true;
00291         m_view->DrawNew();
00292         return;
00293     }
00294     if (m->button() != Qt::LeftButton)
00295     {
00296         m_view->stopGesture();
00297         return;
00298     }
00299     RecordP.resize(0);
00300     m_view->Deselect(false);
00301     Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
00302     Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
00303     SeRx = Mxp;
00304     SeRy = Myp;
00305     m_canvas->setRenderModeFillBuffer();
00306 }
00307 
00308 
00309 
00310 void FreehandMode::mouseReleaseEvent(QMouseEvent *m)
00311 {
00312     const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
00313     
00314 
00315     PageItem *currItem;
00316     m_MouseButtonPressed = false;
00317     m_canvas->resetRenderMode();
00318     m->accept();
00319     m_view->stopDragTimer();
00320     
00321     if (m_doc->appMode == modeDrawFreehandLine)
00322     {
00323         if (RecordP.size() > 1)
00324         {
00325             UndoTransaction createTransaction(UndoManager::instance()->beginTransaction());
00326             uint z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->toolSettings.dWidth, CommonStrings::None, m_doc->toolSettings.dPenLine, true);
00327             currItem = m_doc->Items->at(z);
00328             currItem->PoLine.resize(0);
00329             if (m->modifiers() & Qt::ControlModifier)
00330             {
00331                 QList<QPointF> clip;
00332                 for (uint px = 0; px < RecordP.size()-1; ++px)
00333                 {
00334                     FPoint clp = RecordP.point(px);
00335                     clip.append(QPointF(clp.x(), clp.y()));
00336                 }
00337                 QPainterPath pp = bezierFit(clip, 5.0);
00338                 currItem->PoLine.fromQPainterPath(pp);
00339             }
00340             else
00341             {
00342                 currItem->PoLine.addPoint(RecordP.point(0));
00343                 currItem->PoLine.addPoint(RecordP.point(0));
00344                 for (uint px = 1; px < RecordP.size()-1; ++px)
00345                 {
00346                     currItem->PoLine.addPoint(RecordP.point(px));
00347                     currItem->PoLine.addPoint(RecordP.point(px));
00348                     currItem->PoLine.addPoint(RecordP.point(px));
00349                     currItem->PoLine.addPoint(RecordP.point(px));
00350                 }
00351                 currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
00352                 currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
00353             }
00354             FPoint tp2(getMinClipF(&currItem->PoLine));
00355             currItem->setXYPos(tp2.x(), tp2.y(), true);
00356             currItem->PoLine.translate(-tp2.x(), -tp2.y());
00357             FPoint tp(getMaxClipF(&currItem->PoLine));
00358             m_doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
00359             m_doc->AdjustItemSize(currItem);
00360             m_doc->m_Selection->clear();
00361             m_doc->m_Selection->addItem(currItem);
00362             currItem->ClipEdited = true;
00363             currItem->FrameType = 3;
00364             currItem->OwnPage = m_doc->OnPage(currItem);
00365             m_view->resetMousePressed();
00366             currItem->checkChanges();
00367             QString targetName = Um::ScratchSpace;
00368             if (currItem->OwnPage > -1)
00369                 targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
00370             createTransaction.commit(targetName, currItem->getUPixmap(),
00371                                             Um::Create + " " + currItem->getUName(),  "", Um::ICreate);
00372             //FIXME 
00373             m_canvas->m_viewMode.operItemResizing = false;
00374             inItemCreation = false;
00375             m_doc->changed();
00376 //          m_view->updateContents(currItem->getRedrawBounding(m_canvas->scale()).adjusted(-10, -10, 20, 20));
00377         }
00378         if (!PrefsManager::instance()->appPrefs.stickyTools)
00379         {
00380             m_view->requestMode(modeNormal);
00381 //          m_view->requestMode(submodePaintingDone);
00382         }
00383         else
00384             m_view->requestMode(m_doc->appMode);
00385 // itemAdd calls PageItem::update       emit DocChanged();
00386         return;
00387     }
00388     
00389     
00390     assert(false);
00391     if (m_doc->appMode != modeDrawBezierLine) //FIXME: that should be dead - av
00392     {       
00393         if (inItemCreation)
00394         {
00395             currItem = m_doc->m_Selection->itemAt(0);
00396             double itemX = 0.0;
00397             double itemY = 0.0;
00398             if (m_doc->appMode == modeDrawLine)
00399             {
00400                 QMatrix p = currItem->getTransform();
00401                 FPoint np = m_doc->ApplyGridF(mousePointDoc).transformPoint(p, true);
00402                 itemX = sqrt(pow(np.x(),2.0)+pow(np.y(),2.0));
00403                 itemY = 1.0;
00404             }
00405             else if (m_doc->appMode == modeDrawRegularPolygon)
00406             {
00407                 FPoint np1(mousePointDoc); //m_view->translateToDoc(m->x(), m->y()));
00408                 np1 = m_doc->ApplyGridF(np1);
00409                 itemX = fabs(np1.x() - currItem->xPos());
00410                 itemY = fabs(np1.y() - currItem->yPos());
00411             }
00412             else
00413             {
00414                 itemX = fabs(currItem->width());
00415                 itemY = fabs(currItem->height());
00416             }
00417             if ((!m_view->moveTimerElapsed()) || ((itemX < 2.0) && (itemY < 2.0)) || ((m_doc->appMode == modeDrawLine) && (itemX < 2.0)))
00418             {
00419                 int lmode = 0;
00420                 if (m_doc->appMode == modeDrawLine)
00421                     lmode = 1;
00422                 PrefsContext* sizes = PrefsManager::instance()->prefsFile->getContext("ObjectSize");
00423                 double xSize, ySize;
00424                 int originPoint;
00425                 if (lmode == 0)
00426                 {
00427                     xSize = sizes->getDouble("defWidth", 100.0);
00428                     ySize = sizes->getDouble("defHeight", 100.0);
00429                     originPoint = sizes->getInt("Origin", 0);
00430                 }
00431                 else
00432                 {
00433                     xSize = sizes->getDouble("defLength", 100.0);
00434                     ySize = sizes->getDouble("defAngle", 0.0);
00435                     originPoint = sizes->getInt("OriginL", 0);
00436                 }
00437                 bool doRemember = sizes->getBool("Remember", true);
00438                 bool doCreate = false;
00439                 if (m->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier))
00440                     doCreate = true;
00441                 else
00442                 {
00443                     qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00444                     OneClick *dia = new OneClick(m_view, ScribusView::tr("Enter Object Size"), m_doc->unitIndex(), xSize, ySize, doRemember, originPoint, lmode);
00445                     if (dia->exec())
00446                     {
00447                         doRemember = dia->checkRemember->isChecked();
00448                         if (lmode == 0)
00449                         {
00450                             xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex());
00451                             ySize = dia->spinHeight->value() / unitGetRatioFromIndex(m_doc->unitIndex());
00452                             originPoint = dia->RotationGroup->checkedId();
00453                             if (doRemember)
00454                             {
00455                                 sizes->set("defWidth", xSize);
00456                                 sizes->set("defHeight", ySize);
00457                                 sizes->set("Origin", originPoint);
00458                             }
00459                         }
00460                         else
00461                         {
00462                             xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex());
00463                             ySize = dia->spinHeight->value();
00464                             originPoint = dia->RotationGroup->checkedId();
00465                             if (doRemember)
00466                             {
00467                                 sizes->set("defLength", xSize);
00468                                 sizes->set("defAngle", ySize);
00469                                 sizes->set("OriginL", originPoint);
00470                             }
00471                         }
00472                         sizes->set("Remember", doRemember);
00473                         doCreate = true;
00474                     }
00475                     else
00476                     {
00477                         m_view->Deselect(false);
00478                         m_doc->Items->removeAt(currItem->ItemNr);
00479                     }
00480                     delete dia;
00481                 }
00482                 if (doCreate)
00483                 {
00484                     bool oldSnap = m_doc->SnapGuides;
00485                     m_doc->SnapGuides = false;
00486                     m_doc->SizeItem(xSize, ySize, currItem->ItemNr, false, false, false);
00487                     currItem->updateClip();
00488                     currItem->ContourLine = currItem->PoLine.copy();
00489                     switch (originPoint)
00490                     {
00491                         case 0:
00492                             break;
00493                         case 1:
00494                             if (lmode == 0)
00495                                 m_doc->MoveItem(-currItem->width(), 0.0, currItem, false);
00496                             else
00497                                 m_doc->MoveRotated(currItem, FPoint(-currItem->width() / 2.0, 0.0), false);
00498                             break;
00499                         case 2:
00500                             if (lmode == 0)
00501                                 m_doc->MoveItem(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem, false);
00502                             else
00503                                 m_doc->MoveRotated(currItem, FPoint(-currItem->width(), 0.0), false);
00504                             break;
00505                         case 3:
00506                             m_doc->MoveItem(0.0, -currItem->height(), currItem, false);
00507                             break;
00508                         case 4:
00509                             m_doc->MoveItem(-currItem->width(), -currItem->height(), currItem, false);
00510                             break;
00511                     }
00512                     m_doc->setRedrawBounding(currItem);
00513                     currItem->OwnPage = m_doc->OnPage(currItem);
00514                     currItem->OldB2 = currItem->width();
00515                     currItem->OldH2 = currItem->height();
00516                     currItem->Sizing = false;
00517                     m_doc->SnapGuides = oldSnap;
00518                     if (!PrefsManager::instance()->appPrefs.stickyTools)
00519                     {
00520                         m_view->requestMode(modeNormal);
00521 //                      m_view->requestMode(submodePaintingDone);
00522                     }
00523                     else
00524                     {
00525                         int appMode = m_doc->appMode;
00526                         if ((inItemCreation) && (appMode == modeNormal))
00527                         {
00528                             currItem = m_doc->m_Selection->itemAt(0);
00529                             if (currItem->asTextFrame())
00530                                 appMode = modeDrawText;
00531                             else if (currItem->asImageFrame())
00532                                 appMode = modeDrawImage;
00533                             else if (m_doc->SubMode != -1)
00534                                 appMode = modeDrawShapes;
00535                         }
00536                         m_view->requestMode(appMode);
00537                     }
00538                     currItem->update();
00539                     m_doc->changed();
00540 //                  emit DocChanged();
00541                 }
00542                 else
00543                 {
00544                     m_view->requestMode(submodePaintingDone);
00545 //                  emit HaveSel(-1);
00546                 }
00547                 inItemCreation = false;
00548                 m_doc->DragP = false;
00549                 m_doc->leaveDrag = false;
00550 //FIXME             m_canvas->m_viewMode.operItemResizing = false;
00551                 m_canvas->setRenderModeUseBuffer(false);
00552                 m_view->MidButt = false;
00553                 shiftSelItems = false;
00554                 m_view->updateCanvas();
00555                 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00556             }
00557         }
00558         if (m_view->moveTimerElapsed() && (GetItem(&currItem)))
00559         {
00560             m_canvas->setRenderModeUseBuffer(false);
00561             if (m_doc->m_Selection->isMultipleSelection())
00562             {
00563                 
00564             }
00565             else
00566             {
00567                 //Where a single frame resize stops when the mouse buttno is released
00568                 //FIXME: reduce code!
00569                 if (currItem->Sizing)
00570                 {
00571                     FPoint npx;
00572                     double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
00573                     double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
00574                     if (m_doc->SnapGuides)
00575                     {
00576                         m_doc->ApplyGuides(&nx, &ny);
00577                         npx = FPoint(nx, ny, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
00578                     }
00579                     else
00580                     {
00581                         npx = m_doc->ApplyGridF(FPoint(nx, ny));
00582                         npx = FPoint(npx.x(), npx.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
00583                     }
00584                     if ((frameResizeHandle == 1) && !(currItem->asLine()) && (m_doc->SnapGuides))
00585                         m_doc->SizeItem(npx.x(), npx.y(), currItem->ItemNr);
00586                     bool sav = m_doc->SnapGuides;
00587                     m_doc->SnapGuides = false;
00588                     UndoTransaction* activeTransaction = NULL;
00589                     if (UndoManager::undoEnabled())
00590                     {
00591                         activeTransaction = new UndoTransaction(m_view->undoManager->beginTransaction(currItem->getUName(), currItem->getUPixmap(),
00592                                                                                                   Um::Resize, QString(Um::ResizeFromTo).arg(currItem->width()).arg(currItem->height()).arg(currItem->width() - npx.x()).arg(currItem->height() - npx.y()), Um::IResize));
00593                     }
00594 //                  m_canvas->m_viewMode.operItemResizing = false;
00595                     switch (frameResizeHandle)
00596                     {
00597                     case 1:
00598                         if (!currItem->asLine())
00599                         {
00600                             //<<Swap location if width/height is <0
00601                             if (currItem->width()<0)
00602                             {
00603                                 currItem->setWidth(-currItem->width());
00604                                 currItem->setXPos(currItem->xPos()-currItem->width());
00605                             }
00606                             if (currItem->height()<0)
00607                             {
00608                                 currItem->setHeight(-currItem->height());
00609                                 currItem->setYPos(currItem->yPos()-currItem->height());
00610                             }
00611                             //>>
00612                             if (currItem->imageFlippedH())
00613                                 currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
00614                             if (currItem->imageFlippedV())
00615                                 currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
00616                         }
00617                         else
00618                         {
00619                             if (sav)
00620                             {
00621                                 double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
00622                                 double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
00623                                 if (m_doc->useRaster)
00624                                 {
00625                                     FPoint ra(m_doc->ApplyGridF(FPoint(nx, ny)));
00626                                     nx = ra.x();
00627                                     ny = ra.y();
00628                                 }
00629                                 m_doc->SnapGuides = sav;
00630                                 m_doc->ApplyGuides(&nx, &ny);
00631                                 m_doc->SnapGuides = false;
00632                                 double r = atan2(ny - currItem->yPos(), nx - currItem->xPos())*(180.0/M_PI);
00633                                 m_doc->RotateItem(r, currItem->ItemNr);
00634                                 double w = sqrt(pow(nx - currItem->xPos(), 2) + pow(ny - currItem->yPos(),2));
00635                                 m_doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
00636                             }
00637                         }
00638                         currItem->Sizing = false;
00639                         break;
00640                     case 2:
00641                         if (!currItem->asLine())
00642                         {
00643                             m_doc->MoveSizeItem(npx, npx, currItem->ItemNr);
00644                                 
00645                             //<<Swap location if width/height is <0
00646                             if (currItem->width()<0)
00647                             {
00648                                 currItem->setWidth(-currItem->width());
00649                                 currItem->setXPos(currItem->xPos()-currItem->width());
00650                             }
00651                             if (currItem->height()<0)
00652                             {
00653                                 currItem->setHeight(-currItem->height());
00654                                 currItem->setYPos(currItem->yPos()-currItem->height());
00655                             }
00656                             //>>
00657                                 
00658                             currItem->Sizing = false;
00659                             if (!currItem->imageFlippedH())
00660                             {
00661                                 currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
00662                                 currItem->update();
00663                             }
00664                             if (!currItem->imageFlippedV())
00665                             {
00666                                 currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
00667                                 currItem->update();
00668                             }
00669                         }
00670                         else
00671                         {
00672                             if (sav)
00673                             {
00674                                 double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
00675                                 double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
00676                                 if (m_doc->useRaster)
00677                                 {
00678                                     FPoint ra(m_doc->ApplyGridF(FPoint(nx, ny)));
00679                                     nx = ra.x();
00680                                     ny = ra.y();
00681                                 }
00682                                 m_doc->SnapGuides = sav;
00683                                 m_doc->ApplyGuides(&nx, &ny);
00684                                 m_doc->SnapGuides = false;
00685                                 QMatrix ma;
00686                                 ma.translate(currItem->xPos(), currItem->yPos());
00687                                 ma.rotate(currItem->rotation());
00688                                 double mx = ma.m11() * currItem->width() + ma.m21() * currItem->height() + ma.dx();
00689                                 double my = ma.m22() * currItem->height() + ma.m12() * currItem->width() + ma.dy();
00690                                 double r = atan2(my-ny,mx-nx)*(180.0/M_PI);
00691                                 double w = sqrt(pow(mx-nx,2)+pow(my-ny,2));
00692                                 m_doc->MoveItem(nx - currItem->xPos(), ny - currItem->yPos(), currItem, true);
00693                                 m_doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
00694                                 m_doc->RotateItem(r, currItem->ItemNr);
00695                                 currItem->Sizing = false;
00696                             }
00697                         }
00698                         break;
00699                     case 3:
00700                         m_doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(currItem->width() - npx.x(), npx.y()), currItem->ItemNr);
00701                             
00702                         //<<Swap location if width/height is <0
00703                         if (currItem->width()<0)
00704                         {
00705                             currItem->setWidth(-currItem->width());
00706                             currItem->setXPos(currItem->xPos()-currItem->width());
00707                         }
00708                         if (currItem->height()<0)
00709                         {
00710                             currItem->setHeight(-currItem->height());
00711                             currItem->setYPos(currItem->yPos()-currItem->height());
00712                         }
00713                         //>>
00714                             
00715                         currItem->Sizing = false;
00716                         if (currItem->imageFlippedH())
00717                             currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
00718                         if (!currItem->imageFlippedV())
00719                             currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
00720                         break;
00721                     case 4:
00722                     
00723                         m_doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), currItem->height() - npx.y()), currItem->ItemNr);
00724                         
00725                         //<<Swap location if width/height is <0
00726                         if (currItem->width()<0)
00727                         {
00728                             currItem->setWidth(-currItem->width());
00729                             currItem->setXPos(currItem->xPos()-currItem->width());
00730                         }
00731                         if (currItem->height()<0)
00732                         {
00733                             currItem->setHeight(-currItem->height());
00734                             currItem->setYPos(currItem->yPos()-currItem->height());
00735                         }
00736                         //>>
00737                             
00738                         currItem->