Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scribusview.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                           scribusview.cpp  -  description
00009                              -------------------
00010     begin                : Fre Apr  6 21:47:55 CEST 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "scribusview.h"
00025 #include "scribusview.moc"
00026 
00027 #include "scconfig.h"
00028 
00029 #include <qcolor.h>
00030 #include <qfont.h>
00031 #include <qfontmetrics.h>
00032 #include <qpixmap.h>
00033 #include <qpointarray.h>
00034 #include <qstringlist.h>
00035 #include <qdragobject.h>
00036 #include <qimage.h>
00037 #include <qcstring.h>
00038 #include <qfileinfo.h>
00039 #include <qfile.h>
00040 #include <qptrstack.h>
00041 #include <cmath>
00042 #include <cstdio>
00043 #include <cstdlib>
00044 
00045 #ifdef HAVE_UNISTD_H
00046 #include <unistd.h>
00047 #endif
00048 
00049 #include <qurl.h>
00050 #include <qdir.h>
00051 #include <qevent.h>
00052 #include <qsizegrip.h>
00053 #if QT_VERSION  > 0x030102
00054        #define SPLITVC SplitHCursor
00055        #define SPLITHC SplitVCursor
00056 #else
00057        #define SPLITVC SplitVCursor
00058        #define SPLITHC SplitHCursor
00059 #endif
00060 #include "scribus.h"
00061 //#include "tree.h"
00062 #include "mpalette.h"
00063 #include "scribusXml.h"
00064 #include "selection.h"
00065 #include "serializer.h"
00066 #include "insertTable.h"
00067 #include "hruler.h"
00068 #include "vruler.h"
00069 #include "filewatcher.h"
00070 #include "undomanager.h"
00071 #include "units.h"
00072 #include "extimageprops.h"
00073 #include "page.h"
00074 #include "pageitemattributes.h"
00075 #include "pageitem_imageframe.h"
00076 #include "pageitem_line.h"
00077 #include "pageitem_pathtext.h"
00078 #include "pageitem_polygon.h"
00079 #include "pageitem_polyline.h"
00080 #include "pageitem_textframe.h"
00081 #include "pageselector.h"
00082 #include "scpaths.h"
00083 #include "actionmanager.h"
00084 #include <tiffio.h>
00085 #include CMS_INC
00086 
00087 #include "scmessagebox.h"
00088 #include "util.h"
00089 #include "story.h"
00090 #include "prefsmanager.h"
00091 #include "prefscontext.h"
00092 #include "prefsfile.h"
00093 #include "rulermover.h"
00094 #include "hyphenator.h"
00095 #include "commonstrings.h"
00096 #include "guidemanager.h"
00097 #include "oneclick.h"
00098 #include "text/nlsconfig.h"
00099 #include "scrap.h"
00100 #include "stencilreader.h"
00101 #ifdef HAVE_CAIRO
00102 #include <cairo.h>
00103 #endif
00104 
00105 using namespace std;
00106 
00107 
00108 
00109 ScribusView::ScribusView(QWidget* win, ScribusMainWindow* mw, ScribusDoc *doc) :
00110        QScrollView(win, "s", WRepaintNoErase | WNorthWestGravity),
00111        Doc(doc),
00112        Prefs(&(PrefsManager::instance()->appPrefs)),
00113        undoManager(UndoManager::instance()),
00114        OldScale(0),
00115        dragX(0), dragY(0), dragW(0), dragH(0),
00116        oldW(-1), oldCp(-1),
00117        Mxp(-1), Myp(-1), Dxp(-1), Dyp(-1),
00118        frameResizeHandle(-1),
00119        SeRx(-1), SeRy(-1), GyM(-1), GxM(-1),
00120        ClRe(-1), ClRe2(-1),
00121        SegP1(-1), SegP2(-1),
00122        RotMode(0),
00123        DrHY(-1), DrVX(-1),
00124        EdPoints(true),
00125        m_MouseButtonPressed(false),       
00126        operItemMoving(false),
00127        MoveGY(false), MoveGX(false),
00128        HaveSelRect(false),
00129        operItemResizing(false),
00130        EditContour(false),
00131        //GroupSel(false),
00132        DraggedGroup(false),
00133        DraggedGroupFirst(false),
00134        operItemResizeInEditMode(false),
00135        MidButt(false),
00136        updateOn(true),
00137        FirstPoly(true),
00138        Magnify(false),
00139        MoveSym(false),
00140        previewMode(false),
00141        RCenter(-1,-1),
00142        RecordP(),
00143        Ready(false),
00144        oldX(0), oldY(0),
00145        _groupTransactionStarted(false),
00146        _isGlobalMode(true),
00147        evSpon(false),
00148        forceRedraw(false),
00149        Scale(Prefs->DisScale),
00150        oldClip(0),
00151        m_vhRulerHW(17),
00152        m_cursorVisible(false),
00153        m_ScMW(mw)
00154 {
00155        setHScrollBarMode(QScrollView::AlwaysOn);
00156        setVScrollBarMode(QScrollView::AlwaysOn);
00157        setMargins(m_vhRulerHW, m_vhRulerHW, 0, 0);
00158        setResizePolicy(Manual);
00159        viewport()->setBackgroundMode(PaletteBackground);
00160        QFont fo = QFont(font());
00161        int posi = fo.pointSize()-2;
00162        fo.setPointSize(posi);
00163        unitSwitcher = new QComboBox( false, this, "unitSwitcher" );
00164        unitSwitcher->setFocusPolicy(QWidget::NoFocus);
00165        unitSwitcher->setFont(fo);
00166        for (int i=0;i<=unitGetMaxIndex();++i)
00167               unitSwitcher->insertItem(unitGetStrFromIndex(i));
00168        zoomSpinBox = new MSpinBox( 10, 3200, this, 2 );
00169        zoomSpinBox->setTabAdvance(false);
00170        zoomSpinBox->setFont(fo);
00171        zoomSpinBox->setValue( 100 );
00172        zoomSpinBox->setLineStepM(10);
00173        zoomSpinBox->setFocusPolicy(QWidget::ClickFocus);
00174        zoomSpinBox->setSuffix( tr( " %" ) );
00175 #if OPTION_USE_QTOOLBUTTON
00176        zoomOutToolbarButton = new QToolButton(this);
00177        zoomDefaultToolbarButton = new QToolButton(this);
00178        zoomInToolbarButton = new QToolButton(this);
00179        cmsToolbarButton = new QToolButton(this);
00180        previewToolbarButton = new QToolButton(this);
00181        zoomDefaultToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
00182        zoomOutToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
00183        zoomInToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
00184        cmsToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
00185        cmsToolbarButton->setToggleButton(true);
00186        QIconSet ic2;
00187        ic2.setPixmap(loadIcon("cmsOff.png"), QIconSet::Automatic, QIconSet::Normal, QIconSet::Off);
00188        ic2.setPixmap(loadIcon("cmsOn.png"), QIconSet::Automatic, QIconSet::Normal, QIconSet::On);
00189        cmsToolbarButton->setIconSet(ic2);
00190        previewToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
00191        previewToolbarButton->setToggleButton(true);
00192        QIconSet ic;
00193        ic.setPixmap(loadIcon("previewOff.png"), QIconSet::Automatic, QIconSet::Normal, QIconSet::Off);
00194        ic.setPixmap(loadIcon("previewOn.png"), QIconSet::Automatic, QIconSet::Normal, QIconSet::On);
00195        previewToolbarButton->setIconSet(ic);
00196 #else
00197        zoomDefaultToolbarButton = new QPushButton(this);
00198        zoomDefaultToolbarButton->setFocusPolicy(QWidget::NoFocus);
00199        zoomDefaultToolbarButton->setDefault( false );
00200        zoomDefaultToolbarButton->setAutoDefault( false );
00201        zoomDefaultToolbarButton->setFlat(OPTION_FLAT_BUTTON);
00202        zoomOutToolbarButton = new QPushButton(this);
00203        zoomOutToolbarButton->setFocusPolicy(QWidget::NoFocus);
00204        zoomOutToolbarButton->setDefault( false );
00205        zoomOutToolbarButton->setAutoDefault( false );
00206        zoomOutToolbarButton->setFlat(OPTION_FLAT_BUTTON);
00207        zoomInToolbarButton = new QPushButton(this);
00208        zoomInToolbarButton->setFocusPolicy(QWidget::NoFocus);
00209        zoomInToolbarButton->setDefault( false );
00210        zoomInToolbarButton->setAutoDefault( false );
00211        zoomInToolbarButton->setFlat(OPTION_FLAT_BUTTON);
00212        previewToolbarButton = new QPushButton(this);
00213        cmsToolbarButton->setFocusPolicy(QWidget::NoFocus);
00214        cmsToolbarButton->setDefault( false );
00215        cmsToolbarButton->setAutoDefault( false );
00216        cmsToolbarButton->setFlat(OPTION_FLAT_BUTTON);
00217        cmsToolbarButton->setPixmap(loadIcon("cmsOn.png"));
00218        previewToolbarButton = new QPushButton(this);
00219        previewToolbarButton->setFocusPolicy(QWidget::NoFocus);
00220        previewToolbarButton->setDefault( false );
00221        previewToolbarButton->setAutoDefault( false );
00222        previewToolbarButton->setFlat(OPTION_FLAT_BUTTON);
00223        previewToolbarButton->setPixmap(loadIcon("previewOn.png"));
00224 #endif
00225        //zoomDefaultToolbarButton->setText("1:1");
00226        zoomDefaultToolbarButton->setPixmap(loadIcon("16/zoom-original.png"));
00227        zoomOutToolbarButton->setPixmap(loadIcon("16/zoom-out.png"));
00228        zoomInToolbarButton->setPixmap(loadIcon("16/zoom-in.png"));
00229        pageSelector = new PageSelector(this, Doc->Pages->count());
00230        pageSelector->setFont(fo);
00231        pageSelector->setFocusPolicy(QWidget::ClickFocus);
00232        layerMenu = new QComboBox( true, this, "LY" );
00233        layerMenu->setEditable(false);
00234        layerMenu->setFont(fo);
00235        layerMenu->setFocusPolicy(QWidget::NoFocus);
00236        visualMenu = new QComboBox( false, this, "visualMenu" );
00237        visualMenu->setFocusPolicy(QWidget::NoFocus);
00238        visualMenu->setFont(fo);
00239        visualMenu->setEnabled(false);
00240        horizRuler = new Hruler(this, Doc);
00241        vertRuler = new Vruler(this, Doc);
00242        rulerMover = new RulerMover(this);
00243        rulerMover->setFocusPolicy(QWidget::NoFocus);
00244        Ready = true;
00245        viewport()->setMouseTracking(true);
00246        setAcceptDrops(true);
00247        viewport()->setAcceptDrops(true);
00248        setDragAutoScroll(false);
00249        Doc->DragP = false;
00250        Doc->leaveDrag = false;
00251        Doc->SubMode = -1;
00252        storedFramesShown = Doc->guidesSettings.framesShown;
00253        storedShowControls = Doc->guidesSettings.showControls;
00254        viewAsPreview = false;
00255        previewVisual = 0;
00256        shiftSelItems = false;
00257        inItemCreation = false;
00258 #ifdef HAVE_CAIRO
00259        m_ScMW->scrActions["viewFitPreview"]->setOn(viewAsPreview);
00260 #endif
00261        m_SnapCounter = 0;
00262        connect(zoomOutToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
00263        connect(zoomInToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
00264        connect(zoomDefaultToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoom100()));
00265        connect(zoomSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setZoom()));
00266        connect(pageSelector, SIGNAL(GotoPage(int)), this, SLOT(GotoPa(int)));
00267        connect(layerMenu, SIGNAL(activated(int)), this, SLOT(GotoLa(int)));
00268        connect(unitSwitcher, SIGNAL(activated(int)), this, SLOT(ChgUnit(int)));
00269        connect(previewToolbarButton, SIGNAL(clicked()), this, SLOT(togglePreview()));
00270        connect(cmsToolbarButton, SIGNAL(clicked()), this, SLOT(toggleCMS()));
00271        connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int)));
00272        connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(setRulerPos(int, int)));
00273        connect(this, SIGNAL(HaveSel(int)), this, SLOT(selectionChanged()));
00274        languageChange();
00275 }
00276 
00277 void ScribusView::languageChange()
00278 {
00279        QToolTip::remove(cmsToolbarButton);
00280        QToolTip::remove(previewToolbarButton);
00281        QToolTip::remove(visualMenu);
00282        QToolTip::add(cmsToolbarButton, tr("Switches Color Management on or off"));
00283        QToolTip::add(previewToolbarButton, tr("Enables the Preview Mode"));
00284        QToolTip::add(visualMenu, tr("Here you can select the visual appearance of the display\nYou can choose between normal and several color blindness forms"));
00285        disconnect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int)));
00286        visualMenu->clear();
00287        visualMenu->insertItem(CommonStrings::trVisionNormal);
00288        visualMenu->insertItem(CommonStrings::trVisionProtanopia);
00289        visualMenu->insertItem(CommonStrings::trVisionDeuteranopia);
00290        visualMenu->insertItem(CommonStrings::trVisionTritanopia);
00291        visualMenu->insertItem(CommonStrings::trVisionFullColorBlind);
00292        visualMenu->setCurrentItem(previewVisual);
00293        connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int)));
00294 }
00295 
00296 void ScribusView::toggleCMS()
00297 {
00298        Doc->enableCMS(!Doc->HasCMS);
00299        updateContents();
00300 }
00301 
00302 void ScribusView::switchPreviewVisual(int vis)
00303 {
00304        previewVisual = vis;
00305        Doc->recalculateColors();
00306        Doc->recalcPicturesRes();
00307        updateContents();
00308 }
00309 
00310 void ScribusView::togglePreview()
00311 {
00312        viewAsPreview = !viewAsPreview;
00313        if (viewAsPreview)
00314        {
00315               storedFramesShown = Doc->guidesSettings.framesShown;
00316               Doc->guidesSettings.framesShown = false;
00317               storedShowControls = Doc->guidesSettings.showControls;
00318               Doc->guidesSettings.showControls = false;
00319               // warning popping up in case colour management and out-of-gamut-display are active
00320               // as from #4346: Add a preview for daltonian - PV
00321               if (Doc->HasCMS && Doc->Gamut)
00322                      QMessageBox::information(m_ScMW, tr("Preview Mode"),
00323                                           "<qt>" + tr("CMS is active. Therefore the color display may not match the perception by visually impaired") + "</qt>",
00324                                           QMessageBox::Ok);
00325        }
00326        else
00327        {
00328               Doc->guidesSettings.framesShown = storedFramesShown;
00329               Doc->guidesSettings.showControls = storedShowControls;
00330        }
00331        m_ScMW->scrActions["viewFitPreview"]->setOn(viewAsPreview);
00332        m_ScMW->scrActions["viewShowMargins"]->setEnabled(!viewAsPreview);
00333        m_ScMW->scrActions["viewShowFrames"]->setEnabled(!viewAsPreview);
00334        m_ScMW->scrActions["viewShowLayerMarkers"]->setEnabled(!viewAsPreview);
00335        m_ScMW->scrActions["viewShowGrid"]->setEnabled(!viewAsPreview);
00336        m_ScMW->scrActions["viewShowGuides"]->setEnabled(!viewAsPreview);
00337        m_ScMW->scrActions["viewShowColumnBorders"]->setEnabled(!viewAsPreview);
00338        m_ScMW->scrActions["viewShowBaseline"]->setEnabled(!viewAsPreview);
00339        m_ScMW->scrActions["viewShowTextChain"]->setEnabled(!viewAsPreview);
00340        m_ScMW->scrActions["viewShowTextControls"]->setEnabled(!viewAsPreview);
00341 #if OPTION_USE_QTOOLBUTTON
00342        previewToolbarButton->setOn(viewAsPreview);
00343 #endif
00344        visualMenu->setEnabled(viewAsPreview);
00345        Doc->recalculateColors();
00346        Doc->recalcPicturesRes();
00347        updateContents();
00348 }
00349 
00350 void ScribusView::viewportPaintEvent ( QPaintEvent * p )
00351 {
00352        #ifndef _WIN32
00353        if (p->spontaneous())
00354               evSpon = true;
00355        #endif
00356        QScrollView::viewportPaintEvent(p);
00357 }
00358 
00359 void ScribusView::drawContents(QPainter *psx, int clipx, int clipy, int clipw, int cliph)
00360 {
00361        if (Doc->isLoading())
00362               return;
00363        if (!updateOn)
00364               return;
00365 //     QTime tim;
00366 //     tim.start();
00367        if ((clipw > 0) && (cliph > 0))
00368        {
00369               QPoint vr = contentsToViewport(QPoint(clipx, clipy));
00370               ScPainter *painter=0;
00371 #ifdef HAVE_CAIRO
00372 //            struct Layer la;
00373 //            la.LNr = 0;
00374 //            int Lnr = 0;
00375 //            Level2Layer(Doc, &la, Lnr);
00376               QImage img = QImage(clipw, cliph, 32);
00377               painter = new ScPainter(&img, img.width(), img.height(), 1.0, 0);
00378               painter->clear(paletteBackgroundColor());
00379 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 6)
00380               painter->newPath();
00381               painter->moveTo(0, 0);
00382               painter->lineTo(clipw, 0);
00383               painter->lineTo(clipw, cliph);
00384               painter->lineTo(0, cliph);
00385               painter->closePath();
00386               painter->setClipPath();
00387 #endif
00388               painter->translate(-clipx, -clipy);
00389               painter->setZoomFactor(Scale);
00390               painter->translate(-Doc->minCanvasCoordinate.x(), -Doc->minCanvasCoordinate.y());
00391               painter->setLineWidth(1);
00392               painter->setFillMode(ScPainter::Solid);
00393 #else
00394               painter = new ScPainter(viewport(), clipw, cliph, vr.x(), vr.y());
00395               painter->clear(paletteBackgroundColor());
00396               painter->translate(-Doc->minCanvasCoordinate.x()*Scale, -Doc->minCanvasCoordinate.y()*Scale);
00397               painter->translate(-clipx, -clipy);
00398               painter->setLineWidth(1);
00399               painter->setFillMode(ScPainter::Solid);
00400               painter->setZoomFactor(1.0);
00401 #endif
00402 /* Draw Page Outlines */
00403               if (!Doc->masterPageMode())
00404               {
00405                      uint docPagesCount=Doc->Pages->count();
00406                      if (!viewAsPreview)
00407                      {
00408                             painter->setBrush(QColor(128,128,128));
00409 #ifdef HAVE_CAIRO
00410                             painter->setAntialiasing(false);
00411                             painter->beginLayer(1.0, 0);
00412                             painter->setPen(black, 1.0 / Scale, SolidLine, FlatCap, MiterJoin);
00413 #else
00414                             painter->setPen(black, 0.5 / Scale, SolidLine, FlatCap, MiterJoin);
00415 #endif
00416                             for (int a = 0; a < static_cast<int>(docPagesCount); ++a)
00417                             {
00418                                    double bleedRight = 0.0;
00419                                    double bleedLeft = 0.0;
00420                                    double bleedBottom = 0.0;
00421                                    double bleedTop = 0.0;
00422                                    Doc->getBleeds(Doc->Pages->at(a), &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
00423                                    int blx = qRound((Doc->Pages->at(a)->xOffset() - bleedLeft) * Scale);
00424                                    int bly = qRound((Doc->Pages->at(a)->yOffset() - bleedTop) * Scale);
00425                                    int blw = qRound((Doc->Pages->at(a)->width() + bleedLeft + bleedRight) * Scale);
00426                                    int blh = qRound((Doc->Pages->at(a)->height() + bleedBottom + bleedTop) * Scale);
00427        
00428                                    QRect drawRect = QRect(blx-1, bly-1, blw+6, blh+6);
00429                                    drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
00430                                    if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph)))
00431                                    {
00432                                           painter->setFillMode(ScPainter::Solid);
00433                                           double blx2, bly2, blw2, blh2;
00434                                           if (Doc->guidesSettings.showBleed)
00435                                           {
00436                                                  blx2 = Doc->Pages->at(a)->xOffset() - bleedLeft;
00437                                                  bly2 = Doc->Pages->at(a)->yOffset() - bleedTop;
00438                                                  blw2 = Doc->Pages->at(a)->width() + bleedLeft + bleedRight;
00439                                                  blh2 =  Doc->Pages->at(a)->height() + bleedBottom + bleedTop;
00440                                           }
00441                                           else
00442                                           {
00443                                                  blx2 = Doc->Pages->at(a)->xOffset();
00444                                                  bly2 = Doc->Pages->at(a)->yOffset();
00445                                                  blw2 = Doc->Pages->at(a)->width();
00446                                                  blh2 = Doc->Pages->at(a)->height();
00447                                           }
00448 #ifdef HAVE_CAIRO
00449                                           painter->drawRect(blx2 + 5.0 / Scale, bly2 + 5.0 / Scale, blw2, blh2);
00450 #else
00451                                           blx2 = blx2 * Scale;
00452                                           bly2 = bly2 * Scale;
00453                                           blw2 = blw2 * Scale;
00454                                           blh2 = blh2 * Scale;
00455                                           painter->drawRect(blx2 + 5, bly2 + 5, blw2, blh2);
00456 #endif
00457                                           if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
00458                                           {
00459                                                  painter->setFillMode(ScPainter::None);
00460 #ifdef HAVE_CAIRO
00461                                                  painter->setPen(black, 1.0 / Scale, SolidLine, FlatCap, MiterJoin);
00462                                                  painter->drawRect(blx2, bly2 - 1.0 / Scale, blw2 + 1.0 / Scale, blh2 + 2.0 / Scale);
00463 #else
00464                                                  painter->setPen(black, 0.5 / Scale, SolidLine, FlatCap, MiterJoin);
00465                                                  painter->drawRect(blx2, bly2 - 1.0, blw2 + 1.0, blh2 + 2.0);
00466 #endif
00467                                           }
00468                                    }
00469                             }
00470 #ifdef HAVE_CAIRO
00471                             painter->endLayer();
00472                             painter->setAntialiasing(true);
00473 #endif
00474                      }
00475                      painter->setFillMode(ScPainter::Solid);
00476                      for (int a = 0; a < static_cast<int>(docPagesCount); ++a)
00477                      {
00478 #ifdef HAVE_CAIRO
00479                             double x = Doc->Pages->at(a)->xOffset();
00480                             double y = Doc->Pages->at(a)->yOffset();
00481                             double w = Doc->Pages->at(a)->width();
00482                             double h = Doc->Pages->at(a)->height();
00483 #else
00484                             double x = Doc->Pages->at(a)->xOffset() * Scale;
00485                             double y = Doc->Pages->at(a)->yOffset() * Scale;
00486                             double w = Doc->Pages->at(a)->width() * Scale;
00487                             double h = Doc->Pages->at(a)->height() * Scale;
00488 #endif
00489                             double bleedRight = 0.0;
00490                             double bleedLeft = 0.0;
00491                             double bleedBottom = 0.0;
00492                             double bleedTop = 0.0;
00493                             bool drawBleed = false;
00494                             if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
00495                             {
00496                                    drawBleed = true;
00497                                    Doc->getBleeds(a, &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
00498                             }
00499                             int blx = qRound((Doc->Pages->at(a)->xOffset() - bleedLeft) * Scale);
00500                             int bly = qRound((Doc->Pages->at(a)->yOffset() - bleedTop) * Scale);
00501                             int blw = qRound((Doc->Pages->at(a)->width() + bleedLeft + bleedRight) * Scale);
00502                             int blh = qRound((Doc->Pages->at(a)->height() + bleedBottom + bleedTop) * Scale);
00503 
00504                             QRect drawRect = QRect(blx, bly, blw+5, blh+5);
00505                             drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
00506                             if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph)))
00507                             {
00508                                    painter->setFillMode(ScPainter::Solid);
00509                                    painter->setPen(black, 0, SolidLine, FlatCap, MiterJoin);
00510 #ifdef HAVE_CAIRO
00511                                    painter->setAntialiasing(false);
00512                                    painter->beginLayer(1.0, 0);
00513 #endif
00514                                    painter->setLineWidth(0.0);
00515                                    painter->setBrush(Doc->papColor);
00516                                    if (!viewAsPreview)
00517                                    {
00518 #ifdef HAVE_CAIRO
00519                                           double blx2 = Doc->Pages->at(a)->xOffset() - bleedLeft;
00520                                           double bly2 = Doc->Pages->at(a)->yOffset() - bleedTop;
00521                                           double blw2 = Doc->Pages->at(a)->width() + bleedLeft + bleedRight;
00522                                           double blh2 = Doc->Pages->at(a)->height() + bleedBottom + bleedTop;
00523                                           painter->drawRect(blx2, bly2, blw2, blh2);
00524 #else
00525                                           painter->drawRect(blx, bly, blw, blh);
00526 #endif
00527                                           if (drawBleed)
00528                                                  painter->drawRect(x, y, w, h);
00529                                    }
00530                                    else
00531                                           painter->drawRect(x, y, w, h);
00532 #ifdef HAVE_CAIRO
00533                                    painter->endLayer();
00534                                    painter->setAntialiasing(true);
00535 #endif
00536                             }
00537                      }
00538 #ifdef HAVE_CAIRO
00539                      if (viewAsPreview)
00540                      {
00541                             FPointArray PoLine;
00542                             bool first = true;
00543                             for (int a = 0; a < static_cast<int>(docPagesCount); ++a)
00544                             {
00545                                    if (!first)
00546                                           PoLine.setMarker();
00547                                    first = false;
00548                                    double x = Doc->Pages->at(a)->xOffset();
00549                                    double y = Doc->Pages->at(a)->yOffset();
00550                                    double w = Doc->Pages->at(a)->width();
00551                                    double h = Doc->Pages->at(a)->height();
00552                                    static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
00553                                                                                            1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
00554                                                                                            0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
00555                                    for (int a = 0; a < 29; a += 4)
00556                                    {
00557                                           PoLine.addPoint(x + w * rect[a], y + h * rect[a+1]);
00558                                           PoLine.addPoint(x + w * rect[a+2], y + h * rect[a+3]);
00559                                    }
00560                             }
00561                             painter->beginLayer(1.0, 0, &PoLine);
00562                      }
00563                      else
00564                             painter->beginLayer(1.0, 0);
00565 #endif
00566                      if ((Doc->guidesSettings.before) && (!viewAsPreview))
00567                      {
00568                             for (uint a = 0; a < docPagesCount; ++a)
00569                             {
00570                                    int x = qRound(Doc->Pages->at(a)->xOffset() * Scale);
00571                                    int y = qRound(Doc->Pages->at(a)->yOffset() * Scale);
00572                                    int w = qRound(Doc->Pages->at(a)->width() * Scale);
00573                                    int h = qRound(Doc->Pages->at(a)->height() * Scale);
00574                                    QRect drawRect = QRect(x, y, w+5, h+5);
00575                                    drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
00576                                    if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph)))
00577                                           DrawPageMarks(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph));
00578                             }
00579                      }
00580                      for (uint a = 0; a < docPagesCount; ++a)
00581                      {
00582                             DrawMasterItems(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph));
00583                      }
00584                      DrawPageItems(painter, QRect(clipx, clipy, clipw, cliph));
00585 #ifdef HAVE_CAIRO
00586                      painter->endLayer();
00587 #endif
00588                      if ((!Doc->guidesSettings.before) && (!viewAsPreview))
00589                      {
00590                             for (uint a = 0; a < docPagesCount; ++a)
00591                             {
00592                                    int x = qRound(Doc->Pages->at(a)->xOffset() * Scale);
00593                                    int y = qRound(Doc->Pages->at(a)->yOffset() * Scale);
00594                                    int w = qRound(Doc->Pages->at(a)->width() * Scale);
00595                                    int h = qRound(Doc->Pages->at(a)->height() * Scale);
00596                                    QRect drawRect = QRect(x, y, w+5, h+5);
00597                                    drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
00598                                    if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph)))
00599                                           DrawPageMarks(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph));
00600                             }
00601                      }
00602               }
00603               else
00604               {
00605                      int x = qRound(Doc->scratch.Left * Scale);
00606                      int y = qRound(Doc->scratch.Top * Scale);
00607                      int w = qRound(Doc->currentPage()->width() * Scale);
00608                      int h = qRound(Doc->currentPage()->height() * Scale);
00609                      QRect drawRect = QRect(x, y, w+5, h+5);
00610                      drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
00611                      if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph)))
00612                      {
00613                             painter->setFillMode(ScPainter::Solid);
00614                             painter->setBrush(QColor(128,128,128));
00615                             double bleedRight = 0.0;
00616                             double bleedLeft = 0.0;
00617                             double bleedBottom = 0.0;
00618                             double bleedTop = 0.0;
00619                             Doc->getBleeds(Doc->currentPage(), &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
00620 #ifdef HAVE_CAIRO
00621                             painter->beginLayer(1.0, 0);
00622                             painter->setAntialiasing(false);
00623                             painter->setPen(black, 1 / Scale, SolidLine, FlatCap, MiterJoin);
00624                             if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
00625                             {
00626                                    painter->drawRect(Doc->scratch.Left - bleedLeft+5 / Scale, Doc->scratch.Top - bleedTop+5 / Scale, Doc->currentPage()->width() + bleedLeft + bleedRight, Doc->currentPage()->height() + bleedBottom + bleedTop);
00627                                    painter->setBrush(Doc->papColor);
00628                                    painter->drawRect(Doc->scratch.Left - bleedLeft, Doc->scratch.Top - bleedTop, Doc->currentPage()->width() + bleedLeft + bleedRight, Doc->currentPage()->height() + bleedBottom + bleedTop);
00629                             }
00630                             else
00631                             {
00632                                    painter->drawRect(Doc->scratch.Left+5 / Scale, Doc->scratch.Top+5 / Scale, Doc->currentPage()->width(), Doc->currentPage()->height());
00633                                    painter->setBrush(Doc->papColor);
00634                                    painter->drawRect(Doc->scratch.Left, Doc->scratch.Top, Doc->currentPage()->width(), Doc->currentPage()->height());
00635                             }
00636                             painter->setAntialiasing(true);
00637 #else
00638                             if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
00639                             {
00640                                    x = qRound((Doc->scratch.Left - bleedLeft) * Scale);
00641                                    y = qRound((Doc->scratch.Top - bleedTop) * Scale);
00642                                    w = qRound((Doc->currentPage()->width() + bleedLeft + bleedRight) * Scale);
00643                                    h = qRound((Doc->currentPage()->height() + bleedBottom + bleedTop) * Scale);
00644                             }
00645                             painter->setPen(black, 1, SolidLine, FlatCap, MiterJoin);
00646                             painter->drawRect(x+5, y+5, w, h);
00647                             painter->setBrush(Doc->papColor);
00648                             painter->drawRect(x, y, w, h);
00649 #endif
00650                             if (Doc->guidesSettings.before)
00651                                    DrawPageMarks(painter, Doc->currentPage(), QRect(clipx, clipy, clipw, cliph));
00652 #ifdef HAVE_CAIRO
00653                             painter->endLayer();
00654 #endif
00655                      }
00656 #ifdef HAVE_CAIRO
00657                      painter->beginLayer(1.0, 0);
00658 #endif
00659                      DrawPageItems(painter, QRect(clipx, clipy, clipw, cliph));
00660 #ifdef HAVE_CAIRO
00661                      painter->endLayer();
00662 #endif
00663                      if ((!Doc->guidesSettings.before) && (drawRect.intersects(QRect(clipx, clipy, clipw, cliph))))
00664                             DrawPageMarks(painter, Doc->currentPage(), QRect(clipx, clipy, clipw, cliph));
00665               }
00666               if (((Doc->m_Selection->count() != 0) || (linkedFramesToShow.count() != 0))  && (!viewAsPreview))
00667               {
00668 #ifndef HAVE_CAIRO
00669                      double z = painter->zoomFactor();
00670                      painter->setZoomFactor(Scale);
00671 #endif
00672                      painter->save();
00673                      PageItem *currItem;
00674                      if ((Doc->guidesSettings.linkShown) && (linkedFramesToShow.count() != 0))
00675                             currItem = linkedFramesToShow.at(0);
00676                      else
00677                      {
00678                             if (linkedFramesToShow.count() != 0)
00679                                    currItem = linkedFramesToShow.at(0);
00680                             else
00681                                    currItem = Doc->m_Selection->itemAt(0);
00682                      }
00683                      //Draw the frame links
00684                      if ((((Doc->appMode == modeLinkFrames) || (Doc->appMode == modeUnlinkFrames))
00685                                && (currItem->itemType() == PageItem::TextFrame)) || (Doc->guidesSettings.linkShown))
00686                      {
00687                             PageItem *nextItem = currItem;
00688                             if (Doc->guidesSettings.linkShown)
00689                             {
00690                                    for (uint lks = 0; lks < linkedFramesToShow.count(); ++lks)
00691                                    {
00692                                           nextItem = linkedFramesToShow.at(lks);
00693                                           while (nextItem != 0)
00694                                           {
00695                                                  //Calculate the link points of the frames
00696                                                  double x11 = nextItem->xPos();
00697                                                  double y11 = nextItem->yPos();
00698                                                  double x12 = x11+nextItem->width();
00699                                                  double y12 = y11+nextItem->height();
00700                                                  double x1mid = x11+(x12-x11)/2;
00701                                                  double y1mid = y11+(y12-y11)/2;
00702 
00703                                                  if (nextItem->rotation()!=0.000)
00704                                                  {
00705                                                         FPoint tempPoint(0,0, x11, y11, nextItem->rotation(), 1, 1);
00706                                                         x11=tempPoint.x();
00707                                                         y11=tempPoint.y();
00708                                                         FPoint tempPoint2(0,0, x12, y12, nextItem->rotation(), 1, 1);
00709                                                         x12=tempPoint2.x();
00710                                                         y12=tempPoint2.y();
00711                                                         FPoint tempPoint3(0,0, x1mid, y1mid, nextItem->rotation(), 1, 1);
00712                                                         x1mid=tempPoint3.x();
00713                                                         y1mid=tempPoint3.y();
00714                                                  }
00715 
00716 
00717                                                  double a1, b1, a2, b2;
00718                                                  a1 = a2 = b1 = b2 = 0;
00719                                                  if (nextItem->nextInChain() != NULL)
00720                                                  {
00721                                                         double x21 = nextItem->nextInChain()->xPos();
00722                                                         double y21 = nextItem->nextInChain()->yPos();
00723                                                         double x22 = x21+nextItem->nextInChain()->width();
00724                                                         double y22 = y21+nextItem->nextInChain()->height();
00725                                                         double x2mid = x21 + nextItem->nextInChain()->width()/2;
00726                                                         double y2mid = y21 + nextItem->nextInChain()->height()/2;
00727                                                         //x2mid = x21+(x22-x21)/2;
00728                                                         //y2mid = y21+(y22-y21)/2;
00729 
00730                                                         if (nextItem->nextInChain()->rotation()!=0.000)
00731                                                         {
00732                                                                FPoint tempPoint(0,0, x21, y21, nextItem->nextInChain()->rotation(), 1, 1);
00733                                                                x21=tempPoint.x();
00734                                                                y21=tempPoint.y();
00735                                                                FPoint tempPoint2(0,0, x22, y22, nextItem->nextInChain()->rotation(), 1, 1);
00736                                                                x22=tempPoint2.x();
00737                                                                y22=tempPoint2.y();
00738                                                                FPoint tempPoint3(0,0, x2mid, y2mid, nextItem->nextInChain()->rotation(), 1, 1);
00739                                                                x2mid=tempPoint3.x();
00740                                                                y2mid=tempPoint3.y();
00741                                                         }
00742 
00743                                                         if (x22<x11) { a1 = x11; a2 = x22; }
00744                                                         if (x21>x12) { a1 = x12; a2 = x21; }
00745                                                         if (y22<y11) { b1 = y11; b2 = y22; }
00746                                                         if (y21>y12) { b1 = y12; b2 = y21; }
00747 
00748                                                         if (x21<x12 && x21>x11) { a1 = x1mid; a2 = x2mid; }
00749                                                         if (x21<x11 && x22>x11) { a1 = x1mid; a2 = x2mid; }
00750 
00751                                                         if (y21<y12 && y21>y11) { b1 = y1mid; b2 = y2mid; }
00752                                                         if (y21<y11 && y22>y11) { b1 = y1mid; b2 = y2mid; }
00753 
00754                                                  }
00755                                                  //Draw the link frame lines
00756                                                  FPoint Start(a1-nextItem->xPos(), b1-nextItem->yPos(), nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
00757                                                  //FPoint Start = transformPoint(FPoint(nextItem->Width/2, nextItem->Height), nextItem->xPos(), nextItem->yPos(), nextItem->Rot, 1, 1);
00758                                                  nextItem = nextItem->nextInChain();
00759                                                  if (nextItem != NULL)
00760                                                  {
00761                                                         FPoint End(a2-nextItem->xPos(), b2-nextItem->yPos(), nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
00762                                                         drawLinkFrameLine(painter, Start, End);
00763                                                  }
00764                                           }
00765                                    }
00766                             }
00767                             else
00768                             {
00769                                    while (nextItem != 0)
00770                                    {
00771                                           if (nextItem->prevInChain() != 0)
00772                                                  nextItem = nextItem->prevInChain();
00773                                           else
00774                                                  break;
00775                                    }
00776                                    while (nextItem != 0)
00777                                    {
00778                                           FPoint Start(nextItem->width()/2, nextItem->height(), nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
00779                                           nextItem = nextItem->nextInChain();
00780                                           //Draw the link frame indicator for a new link
00781                                           //CB unsure if we need to do this
00782                                           if (nextItem != 0)
00783                                           {
00784                                                  FPoint End(nextItem->width()/2, 0, nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
00785                                                  drawLinkFrameLine(painter, Start, End);
00786                                           }
00787                                    }
00788                             }
00789                      }
00790                      painter->setLineWidth(1);
00791                      painter->setPenOpacity(1.0);
00792                      painter->restore();
00793 #ifndef HAVE_CAIRO
00794                      painter->setZoomFactor(z);
00795 #endif
00796               }
00797               painter->end();
00798 #ifdef HAVE_CAIRO
00799               psx->drawImage(clipx, clipy, img);
00800 #endif
00801               delete painter;
00802               painter=NULL;
00803        }
00804        if (Doc->m_Selection->count() != 0)
00805        {
00806               PageItem *currItem = Doc->m_Selection->itemAt(0);
00807               currItem->paintObj();
00808               if ((Doc->EditClip) && (currItem->isSelected()))
00809               {
00810               if (EditContour)
00811                      MarkClip(currItem, currItem->ContourLine, true);
00812               else
00813                      MarkClip(currItem, currItem->PoLine, true);
00814               }
00815               if (Doc->m_Selection->isMultipleSelection())
00816               {
00817                      Doc->m_Selection->setGroupRect();
00818                      paintGroupRect();
00819               }
00820        }
00821        if (Doc->appMode == modeEdit)
00822               slotDoCurs(true);
00823        if (Doc->appMode == modeEditGradientVectors)
00824        {
00825               PageItem *currItem = Doc->m_Selection->itemAt(0);
00826               QPainter p;
00827               p.begin(viewport());
00828               ToView(&p);
00829               Transform(currItem, &p);
00830               p.setPen(QPen(blue, 1, SolidLine, FlatCap, MiterJoin));
00831               p.setBrush(NoBrush);
00832               p.drawLine(QPoint(qRound(currItem->GrStartX), qRound(currItem->GrStartY)), QPoint(qRound(currItem->GrEndX), qRound(currItem->GrEndY)));
00833               p.setPen(QPen(magenta, 8, SolidLine, RoundCap, MiterJoin));
00834               p.drawLine(QPoint(qRound(currItem->GrStartX), qRound(currItem->GrStartY)), QPoint(qRound(currItem->GrStartX), qRound(currItem->GrStartY)));
00835               p.drawLine(QPoint(qRound(currItem->GrEndX), qRound(currItem->GrEndY)), QPoint(qRound(currItem->GrEndX), qRound(currItem->GrEndY)));
00836               p.end();
00837        }
00838        evSpon = false;
00839        forceRedraw = false;
00840 //     qDebug( "Time elapsed: %d ms", tim.elapsed() );
00841 }
00842 
00843 void ScribusView::DrawMasterItems(ScPainter *painter, Page *page, QRect clip)
00844 {
00845        QRect oldR;
00846        QPtrStack<PageItem> groupStack;
00847        QPtrStack<PageItem> groupStack2;
00848 #ifndef HAVE_CAIRO
00849        double z = painter->zoomFactor();
00850 #endif
00851        if (!page->MPageNam.isEmpty())
00852        {
00853               Page* Mp = Doc->MasterPages.at(Doc->MasterNames[page->MPageNam]);
00854               if (page->FromMaster.count() != 0)
00855               {
00856                      int Lnr;
00857                      struct Layer ll;
00858                      PageItem *currItem;
00859                      ll.isViewable = false;
00860                      ll.LNr = 0;
00861                      Lnr = 0;
00862                      uint layerCount=Doc->layerCount();
00863                      for (uint la = 0; la < layerCount; ++la)
00864                      {
00865                             Level2Layer(Doc, &ll, Lnr);
00866                             bool pr = true;
00867                             if ((previewMode) && (!ll.isPrintable))
00868                                    pr = false;
00869                             if ((viewAsPreview) && (!ll.isPrintable))
00870                                    pr = false;
00871                             if ((ll.isViewable) && (pr))
00872                             {
00873 #ifdef HAVE_CAIRO
00874                                    if ((layerCount > 1) || (ll.transparency != 1.0))
00875                                           painter->beginLayer(ll.transparency, ll.blendMode);
00876 #endif
00877                                    uint pageFromMasterCount=page->FromMaster.count();
00878                                    for (uint a = 0; a < pageFromMasterCount; ++a)
00879                                    {
00880                                           currItem = page->FromMaster.at(a);
00881                                           if (currItem->LayerNr != ll.LNr)
00882                                                  continue;
00883                                           if ((currItem->OwnPage != -1) && (currItem->OwnPage != static_cast<int>(Mp->pageNr())))
00884                                                  continue;
00885                                           if ((previewMode) && (!currItem->printEnabled()))
00886                                                  continue;
00887                                           if ((viewAsPreview) && (!currItem->printEnabled()))
00888                                                  continue;
00889                                           double OldX = currItem->xPos();
00890                                           double OldY = currItem->yPos();
00891                                           double OldBX = currItem->BoundingX;
00892                                           double OldBY = currItem->BoundingY;
00893                                           if (!currItem->ChangedMasterItem)
00894                                           {
00895                                                  //Hack to not check for undo changes, indicate drawing only
00896                                                  currItem->moveBy(-Mp->xOffset() + page->xOffset(), -Mp->yOffset() + page->yOffset(), true);
00897                                                  currItem->BoundingX = OldBX - Mp->xOffset() + page->xOffset();
00898                                                  currItem->BoundingY = OldBY - Mp->yOffset() + page->yOffset();
00899                                           }
00900                                           oldR = currItem->getRedrawBounding(Scale);
00901                                           if (currItem->isGroupControl)
00902                                           {
00903                                                  painter->save();
00904                                                  currItem->savedOwnPage = currItem->OwnPage;
00905                                                  currItem->OwnPage = page->pageNr();
00906                                                  if ((clip.intersects(oldR)) && (Doc->guidesSettings.layerMarkersShown) && (Doc->layerCount() > 1))
00907                                                         currItem->DrawObj(painter, clip);
00908 #ifdef HAVE_CAIRO
00909                                                  FPointArray cl = currItem->PoLine.copy();
00910                                                  QWMatrix mm;
00911                                                  mm.translate(currItem->xPos(), currItem->yPos());
00912                                                  mm.rotate(currItem->rotation());
00913                                                  cl.map( mm );
00914                                                  painter->beginLayer(1.0 - currItem->fillTransparency(), currItem->fillBlendmode(), &cl);
00915 #endif
00916                                                  groupStack.push(currItem->groupsLastItem);
00917                                                  groupStack2.push(currItem);
00918                                                  currItem->OwnPage = currItem->savedOwnPage;
00919                                                  if (!currItem->ChangedMasterItem)
00920                                                  {
00921                                                         //Hack to not check for undo changes, indicate drawing only
00922                                                         currItem->setXYPos(OldX, OldY, true);
00923                                                         currItem->BoundingX = OldBX;
00924                                                         currItem->BoundingY = OldBY;
00925                                                  }
00926                                                  continue;
00927                                           }
00928                                           currItem->savedOwnPage = currItem->OwnPage;
00929                                           currItem->OwnPage = page->pageNr();
00930                                           if (!evSpon || forceRedraw)
00931                                                  currItem->invalid = true;
00932                                           if (clip.intersects(oldR))
00933                                                  currItem->DrawObj(painter, clip);
00934                                           currItem->OwnPage = currItem->savedOwnPage;
00935                                           if (!currItem->ChangedMasterItem)
00936                                           {
00937                                                  //Hack to not check for undo changes, indicate drawing only
00938                                                  currItem->setXYPos(OldX, OldY, true);
00939                                                  currItem->BoundingX = OldBX;
00940                                                  currItem->BoundingY = OldBY;
00941                                           }
00942                                           if (groupStack.count() != 0)
00943                                           {
00944                                                  while (currItem == groupStack.top())
00945                                                  {
00946 #ifdef HAVE_CAIRO
00947                                                         painter->endLayer();
00948 #endif
00949                                                         painter->restore();
00950                                                         PageItem *cite = groupStack2.pop();
00951                                                         double OldX = cite->xPos();
00952                                                         double OldY = cite->yPos();
00953                                                         double OldBX = cite->BoundingX;
00954                                                         double OldBY = cite->BoundingY;
00955                                                         if (!cite->ChangedMasterItem)
00956                                                         {
00957                                                                //Hack to not check for undo changes, indicate drawing only
00958                                                                cite->moveBy(-Mp->xOffset() + page->xOffset(), -Mp->yOffset() + page->yOffset(), true);
00959                                                                cite->BoundingX = OldBX - Mp->xOffset() + page->xOffset();
00960                                                                cite->BoundingY = OldBY - Mp->yOffset() + page->yOffset();
00961                                                         }
00962                                                         oldR = cite->getRedrawBounding(Scale);
00963                                                         if ((clip.intersects(oldR)) && (Doc->guidesSettings.layerMarkersShown) && (Doc->layerCount() > 1))
00964                                                                cite->DrawObj(painter, clip);
00965                                                         cite->OwnPage = cite->savedOwnPage;
00966                                                         if (!currItem->ChangedMasterItem)
00967                                                         {
00968                                                                //Hack to not check for undo changes, indicate drawing only
00969                                                                cite->setXYPos(OldX, OldY, true);
00970                                                                cite->BoundingX = OldBX;
00971                                                                cite->BoundingY = OldBY;
00972                                                         }
00973                                                         groupStack.pop();
00974                                                  }
00975                                           }
00976                                    }
00977                                    for (uint a = 0; a < pageFromMasterCount; ++a)
00978                                    {
00979                                           currItem = page->FromMaster.at(a);
00980                                           if (currItem->LayerNr != ll.LNr)
00981                                                  continue;
00982                                           if (!currItem->isTableItem)
00983                                                  continue;
00984                                           if ((previewMode) && (!currItem->printEnabled()))
00985                                                  continue;
00986                                           if ((viewAsPreview) && (!currItem->printEnabled()))
00987                                                  continue;
00988                                           if ((currItem->OwnPage != -1) && (currItem->OwnPage != static_cast<int>(Mp->pageNr())))
00989                                                  continue;
00990                                           if (currItem->isGroupControl)
00991                                                  continue;
00992                                           double OldX = currItem->xPos();
00993                                           double OldY = currItem->yPos();
00994                                           double OldBX = currItem->BoundingX;
00995                                           double OldBY = currItem->BoundingY;
00996                                           if (!currItem->ChangedMasterItem)
00997                                           {
00998                                                  //Hack to not check for undo changes, indicate drawing only
00999                                                  currItem->setXYPos(OldX - Mp->xOffset() + page->xOffset(), OldY - Mp->yOffset() + page->yOffset(), true);
01000                                                  currItem->BoundingX = OldBX - Mp->xOffset() + page->xOffset();
01001                                                  currItem->BoundingY = OldBY - Mp->yOffset() + page->yOffset();
01002                                           }
01003                                           oldR = currItem->getRedrawBounding(Scale);
01004                                           if (clip.intersects(oldR))
01005                                           {
01006 #ifdef HAVE_CAIRO
01007                                                  painter->save();
01008                                                  painter->translate(currItem->xPos(), currItem->yPos());
01009 #else
01010                                                  painter->setZoomFactor(Scale);
01011                                                  painter->save();
01012                                                  painter->translate(currItem->xPos()*Scale, currItem->yPos()*Scale);
01013 #endif
01014                                                  painter->rotate(currItem->rotation());
01015                                                  if ((currItem->lineColor() != CommonStrings::None) && (currItem->lineWidth() != 0.0))
01016                                                  {
01017                                                         QColor tmp;
01018                                                         currItem->SetFarbe(&tmp, currItem->lineColor(), currItem->lineShade());
01019                                                         if ((currItem->TopLine) || (currItem->RightLine) || (currItem->BottomLine) || (currItem->LeftLine))
01020                                                         {
01021                                                                painter->setPen(tmp, currItem->lineWidth(), currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin);
01022                                                                if (currItem->TopLine)
01023                                                                       painter->drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0));
01024                                                                if (currItem->RightLine)
01025                                                                       painter->drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height()));
01026                                                                if (currItem->BottomLine)
01027                                                                       painter->drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height()));
01028                                                                if (currItem->LeftLine)
01029                                                                       painter->drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0));
01030                                                         }
01031                                                  }
01032                                                  painter->restore();
01033                                           }
01034                                           if (!currItem->ChangedMasterItem)
01035                                           {
01036                                                  //Hack to not check for undo changes, indicate drawing only
01037                                                  currItem->setXYPos(OldX, OldY, true);
01038                                                  currItem->BoundingX = OldBX;
01039                                                  currItem->BoundingY = OldBY;
01040                                           }
01041                                    }
01042 #ifdef HAVE_CAIRO
01043                                    if ((layerCount > 1) || (ll.transparency != 1.0))
01044                                           painter->endLayer();
01045 #endif
01046                             }
01047                             Lnr++;
01048                      }
01049               }
01050        }
01051 #ifndef HAVE_CAIRO
01052        painter->setZoomFactor(z);
01053 #endif
01054 }
01055 
01056 void ScribusView::DrawPageItems(ScPainter *painter, QRect clip)
01057 {
01058        linkedFramesToShow.clear();
01059 #ifndef HAVE_CAIRO
01060        double z = painter->zoomFactor();
01061 #endif
01062        QRect oldR;
01063        QPtrStack<PageItem> groupStack;
01064        QPtrStack<PageItem> groupStack2;
01065        if (Doc->Items->count() != 0)
01066        {
01067               int Lnr=0;
01068               struct Layer ll;
01069               PageItem *currItem;
01070               ll.isViewable = false;
01071               ll.LNr = 0;
01072               uint layerCount=Doc->layerCount();
01073               int docCurrPageNo=static_cast<int>(Doc->currentPageNumber());
01074               for (uint la2 = 0; la2 < layerCount; ++la2)
01075               {
01076                      Level2Layer(Doc, &ll, Lnr);
01077                      bool pr = true;
01078                      if ((previewMode) && (!ll.isPrintable))
01079                             pr = false;
01080                      if ((viewAsPreview) && (!ll.isPrintable))
01081                             pr = false;
01082                      if ((ll.isViewable) && (pr))
01083                      {
01084 #ifdef HAVE_CAIRO
01085                             if ((layerCount > 1) || (ll.transparency != 1.0))
01086                                    painter->beginLayer(ll.transparency, ll.blendMode);
01087 #endif
01088                             QPtrListIterator<PageItem> docItem(*Doc->Items);
01089                             while ( (currItem = docItem.current()) != 0)
01090                             {
01091                                    ++docItem;
01092                                    if (currItem->LayerNr != ll.LNr)
01093                                           continue;
01094                                    if ((previewMode) && (!currItem->printEnabled()))
01095                                           continue;
01096                                    if ((viewAsPreview) && (!currItem->printEnabled()))
01097                                           continue;
01098                                    if ((Doc->masterPageMode()) && ((currItem->OwnPage != -1) && (currItem->OwnPage != docCurrPageNo)))
01099                                           continue;
01100                                    if (!Doc->masterPageMode() && !currItem->OnMasterPage.isEmpty())
01101                                    {
01102                                           if (currItem->OnMasterPage != Doc->currentPage()->pageName())
01103                                                  continue;
01104                                    }
01105                                    oldR = currItem->getRedrawBounding(Scale);
01106                                    if (currItem->isGroupControl)
01107                                    {
01108                                           painter->save();
01109 #ifdef HAVE_CAIRO
01110                                           FPointArray cl = currItem->PoLine.copy();
01111                                           QWMatrix mm;
01112                                           mm.translate(currItem->xPos(), currItem->yPos());
01113                                           mm.rotate(currItem->rotation());
01114                                           cl.map( mm );
01115                                           painter->beginLayer(1.0 - currItem->fillTransparency(), currItem->fillBlendmode(), &cl);
01116 #endif
01117                                           groupStack.push(currItem->groupsLastItem);
01118                                           groupStack2.push(currItem);
01119                                           continue;
01120                                    }
01121                                    if (clip.intersects(oldR))
01122                                    {
01123                                           if (!evSpon || forceRedraw) 
01124                                                  currItem->invalid = true;
01125 //                                        if ((!m_MouseButtonPressed) || (Doc->EditClip))
01126                                           currItem->DrawObj(painter, clip);
01127 //                                        currItem->Redrawn = true;
01128                                           if ((currItem->asTextFrame()) && ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0)))
01129                                           {
01130                                                  PageItem *nextItem = currItem;
01131                                                  while (nextItem != 0)
01132                                                  {
01133                                                         if (nextItem->prevInChain() != 0)
01134                                                                nextItem = nextItem->prevInChain();
01135                                                         else
01136                                                                break;
01137                                                  }
01138                                                  if (linkedFramesToShow.find(nextItem) == -1)
01139                                                         linkedFramesToShow.append(nextItem);
01140                                           }
01141                                           if ((Doc->appMode == modeEdit) && (currItem->isSelected()) && (currItem->itemType() == PageItem::TextFrame))
01142                                           {
01143                                                  //CB 230305 Stop redrawing the horizontal ruler if it hasnt changed when typing text!!!
01144                                                  if ((qRound(horizRuler->ItemPos*10000) != qRound((currItem->xPos())*10000)) || (qRound(horizRuler->ItemEndPos*10000) != qRound(((currItem->xPos()+currItem->width()) )*10000)))
01145                                                  {
01146                                                         horizRuler->setItem(currItem);
01147                                                         if (currItem->lineColor() != CommonStrings::None)
01148                                                                horizRuler->lineCorr = currItem->lineWidth() / 2.0;
01149                                                         else
01150                                                                horizRuler->lineCorr = 0;
01151                                                         horizRuler->ColGap = currItem->ColGap;
01152                                                         horizRuler->Cols = currItem->Cols;
01153                                                         horizRuler->Extra = currItem->textToFrameDistLeft();
01154                                                         horizRuler->RExtra = currItem->textToFrameDistRight();
01155                                                         horizRuler->First = currItem->currentStyle().firstIndent();
01156                                                         horizRuler->Indent = currItem->currentStyle().leftMargin();
01157                                                         double columnWidth = (currItem->width() - (currItem->columnGap() * (currItem->columns() - 1)) 
01158                                                                - currItem->textToFrameDistLeft() - currItem->textToFrameDistLeft() 
01159                                                                - 2*horizRuler->lineCorr) / currItem->columns();
01160                                                         horizRuler->RMargin = columnWidth - currItem->currentStyle().rightMargin();
01161                                                         if (currItem->imageFlippedH() || (currItem->reversed()))
01162                                                                horizRuler->Revers = true;
01163                                                         else
01164                                                                horizRuler->Revers = false;
01165                                                         horizRuler->ItemPosValid = true;
01166                                                         horizRuler->TabValues = currItem->currentStyle().tabValues();
01167                                                         horizRuler->repaint();
01168                                                  }
01169                                           }
01170                                    }
01171                                    if (groupStack.count() != 0)
01172                                    {
01173                                           while (currItem == groupStack.top())
01174                                           {
01175 #ifdef HAVE_CAIRO
01176                                                  painter->endLayer();
01177 #endif
01178                                                  painter->restore();
01179                                                  PageItem *cite = groupStack2.pop();
01180                                                  oldR = cite->getRedrawBounding(Scale);
01181                                                  if ((clip.intersects(oldR)) && (((Doc->guidesSettings.layerMarkersShown) && (Doc->layerCount() > 1)) || (cite->textFlowUsesContourLine())))
01182                                                         cite->DrawObj(painter, clip);
01183                                                  groupStack.pop();
01184                                           }
01185                                    }
01186                             }
01187                             QPtrListIterator<PageItem> docItem2(*Doc->Items);
01188                             while ( (currItem = docItem2.current()) != 0 )
01189                             {
01190                                    ++docItem2;
01191                                    if (currItem->LayerNr != ll.LNr)
01192                                           continue;
01193                                    if (!currItem->isTableItem)
01194                                           continue;
01195                                    if ((previewMode) && (!currItem->printEnabled()))
01196                                           continue;
01197                                    if ((viewAsPreview) && (!currItem->printEnabled()))
01198                                           continue;
01199                                    oldR = currItem->getRedrawBounding(Scale);
01200                                    if (clip.intersects(oldR))
01201                                    {
01202 #ifdef HAVE_CAIRO
01203                                           painter->save();
01204                                           painter->translate(currItem->xPos(), currItem->yPos());
01205 #else
01206                                           painter->setZoomFactor(Scale);
01207                                           painter->save();
01208                                           painter->translate(currItem->xPos()*Scale, currItem->yPos()*Scale);
01209 #endif
01210                                           painter->rotate(currItem->rotation());
01211                                           if ((currItem->lineColor() != CommonStrings::None) && (currItem->lineWidth() != 0.0))
01212                                           {
01213                                                  QColor tmp;
01214                                                  currItem->SetFarbe(&tmp, currItem->lineColor(), currItem->lineShade());
01215                                                  if ((currItem->TopLine) || (currItem->RightLine) || (currItem->BottomLine) || (currItem->LeftLine))
01216                                                  {
01217                                                         painter->setPen(tmp, currItem->lineWidth(), currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin);
01218                                                         if (currItem->TopLine)
01219                                                                painter->drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0));
01220                                                         if (currItem->RightLine)
01221                                                                painter->drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height()));
01222                                                         if (currItem->BottomLine)
01223                                                                painter->drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height()));
01224                                                         if (currItem->LeftLine)
01225                                                                painter->drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0));
01226                                                  }
01227                                           }
01228                                           painter->restore();
01229                                    }
01230                             }
01231 #ifdef HAVE_CAIRO
01232                             if ((layerCount > 1) || (ll.transparency != 1.0))
01233                                    painter->endLayer();
01234 #endif
01235                      }
01236                      Lnr++;
01237               }
01238        }
01239 #ifndef HAVE_CAIRO
01240        painter->setZoomFactor(z);
01241 #endif
01242 }
01243 
01244 void ScribusView::DrawPageMarks(ScPainter *p, Page *page, QRect clip)
01245 {
01246        p->save();
01247 #ifdef HAVE_CAIRO
01248        p->setAntialiasing(false);
01249        p->translate(page->xOffset(), page->yOffset());
01250        double lineWidth = 1.0 / Scale;
01251 #else
01252        double z = p->zoomFactor();
01253        p->setZoomFactor(Scale);
01254        p->translate(page->xOffset() * Scale, page->yOffset() * Scale);
01255        double lineWidth = 0.5 / Scale;
01256 #endif
01257        double pageHeight=page->height();
01258        double pageWidth=page->width();
01259        p->setFillMode(ScPainter::None);
01260        p->setPen(black, lineWidth, SolidLine, FlatCap, MiterJoin);
01261        p->drawRect(0, 0, pageWidth, pageHeight);
01262        //Draw the margins
01263        if (Doc->guidesSettings.marginsShown)
01264        {
01265               p->setPen(Doc->guidesSettings.margColor);
01266               if (Doc->marginColored)
01267               {
01268                      p->setBrush(Doc->guidesSettings.margColor);
01269                      p->drawRect(0, 0, pageWidth, page->Margins.Top);
01270                      p->drawRect(0, page->Margins.Top, page->Margins.Left, pageHeight - page->Margins.Top);
01271                      p->drawRect(page->Margins.Left, pageHeight - page->Margins.Bottom, pageWidth - page->Margins.Right - page->Margins.Left, page->Margins.Bottom);
01272                      p->drawRect(pageWidth - page->Margins.Right, page->Margins.Top, page->Margins.Right, pageHeight-page->Margins.Top);
01273               }
01274 //            p->setPen(Doc->guidesSettings.margColor);
01275               p->setFillMode(ScPainter::None);
01276               p->drawRect(page->Margins.Left, page->Margins.Top, pageWidth - page->Margins.Left - page->Margins.Right, pageHeight - page->Margins.Top - page->Margins.Bottom);
01277 //            p->drawLine(FPoint(0, page->Margins.Top), FPoint(pageWidth, page->Margins.Top));
01278 //            p->drawLine(FPoint(0, pageHeight - page->Margins.Bottom), FPoint(pageWidth, pageHeight - page->Margins.Bottom));
01279 //            p->drawLine(FPoint(page->Margins.Left, 0), FPoint(page->Margins.Left, pageHeight));
01280 //            p->drawLine(FPoint(pageWidth - page->Margins.Right, 0), FPoint(pageWidth - page->Margins.Right, pageHeight));
01281        }
01282        //Draw the baseline grid
01283        if (Doc->guidesSettings.baseShown)
01284        {
01285               p->setPen(Doc->guidesSettings.baseColor, lineWidth, SolidLine, FlatCap, MiterJoin);
01286               for (double yg = Doc->typographicSettings.offsetBaseGrid; yg < pageHeight; yg += Doc->typographicSettings.valueBaseGrid)
01287                      p->drawLine(FPoint(0, yg), FPoint(pageWidth, yg));
01288        }
01289        //Draw the grid lines
01290        if (Doc->guidesSettings.gridShown)
01291        {
01292               double lowerBx = QMAX(clip.x() / Scale + Doc->minCanvasCoordinate.x() - page->xOffset(), 0);
01293               double lowerBy = QMAX(clip.y() / Scale + Doc->minCanvasCoordinate.y() - page->yOffset(), 0);
01294               double highBx = QMIN(lowerBx + clip.width() / Scale, pageWidth);
01295               double highBy = QMIN(lowerBy + clip.height() / Scale, pageHeight);
01296               if (Scale > 0.49)
01297               {
01298                      double i,start;
01299                      i = Doc->guidesSettings.majorGrid;
01300                      p->setPen(Doc->guidesSettings.majorColor, lineWidth, SolidLine, FlatCap, MiterJoin);
01301                      start=floor(lowerBy/i);
01302                      start*=i;
01303                      for (double b = start; b <= highBy; b+=i)
01304                      {
01305                             p->drawLine(FPoint(QMAX(lowerBx, 0), b), FPoint(QMIN(pageWidth, highBx), b));
01306                      }
01307                      start=floor(lowerBx/i);
01308                      start*=i;
01309                      for (double b = start; b <= highBx; b+=i)
01310                      {
01311                             p->drawLine(FPoint(b, QMAX(lowerBy, 0)), FPoint(b, QMIN(pageHeight, highBy)));
01312                      }
01313                      i = Doc->guidesSettings.minorGrid;
01314                      p->setPen(Doc->guidesSettings.minorColor, lineWidth, DotLine, FlatCap, MiterJoin);
01315                      start=floor(lowerBy/i);
01316                      start*=i;
01317                      for (double b = start; b <= highBy; b+=i)
01318                      {
01319                             p->drawLine(FPoint(QMAX(lowerBx, 0), b), FPoint(QMIN(pageWidth, highBx), b));
01320                      }
01321                      start=floor(lowerBx/i);
01322                      start*=i;
01323                      for (double b = start; b <= highBx; b+=i)
01324                      {
01325                             p->drawLine(FPoint(b, QMAX(lowerBy, 0)), FPoint(b, QMIN(pageHeight, highBy)));
01326                      }
01327               }
01328        }
01329        //Draw the guides
01330        if (Doc->guidesSettings.guidesShown)
01331               page->guides.drawPage(p, Doc, lineWidth);
01332        if (Doc->currentPage() == page)
01333        {
01334 #ifdef HAVE_CAIRO
01335               p->setPen(Prefs->DPageBorderColor, 2 / Scale, SolidLine, FlatCap, MiterJoin);
01336 #else
01337               p->setPen(Prefs->DPageBorderColor, 2, SolidLine, FlatCap, MiterJoin);
01338 #endif
01339               p->drawRect(0, 0, pageWidth, pageHeight);
01340        }
01341 
01342 #ifdef HAVE_CAIRO
01343        p->setAntialiasing(true);
01344 #endif
01345 
01346        p->restore();
01347 #ifndef HAVE_CAIRO
01348        p->setZoomFactor(z);
01349 #endif
01350 }
01351 
01352 void ScribusView::enterEvent(QEvent *)
01353 {
01354        if (!m_MouseButtonPressed)
01355        {
01356               switch (Doc->appMode)
01357               {
01358                      case modeDrawShapes:
01359                             qApp->setOverrideCursor(QCursor(loadIcon("DrawFrame.xpm")), true);
01360                             break;
01361                      case modeDrawPicture:
01362                             qApp->setOverrideCursor(QCursor(loadIcon("DrawImageFrame.xpm")), true);
01363                             break;
01364                      case modeDrawText:
01365                             qApp->setOverrideCursor(QCursor(loadIcon("DrawTextFrame.xpm")), true);
01366                             break;
01367                      case modeDrawTable:
01368                             qApp->setOverrideCursor(QCursor(loadIcon("DrawTable.xpm")), true);
01369                             break;
01370                      case modeDrawRegularPolygon:
01371                             qApp->setOverrideCursor(QCursor(loadIcon("DrawPolylineFrame.xpm")), true);
01372                             break;
01373                      case modeDrawLine:
01374                      case modeDrawBezierLine:
01375                             qApp->setOverrideCursor(QCursor(crossCursor), true);
01376                             break;
01377                      case modeDrawFreehandLine:
01378                             qApp->setOverrideCursor(QCursor(loadIcon("DrawFreeLine.png"), 0, 32), true);
01379                             break;
01380                      case modeMagnifier:
01381                             if (Magnify)
01382                                    qApp->setOverrideCursor(QCursor(loadIcon("LupeZ.xpm")), true);
01383                             else
01384                                    qApp->setOverrideCursor(QCursor(loadIcon("LupeZm.xpm")), true);
01385                             break;
01386                      case modePanning:
01387                             qApp->setOverrideCursor(QCursor(loadIcon("HandC.xpm")), true);
01388                             break;
01389                      case modeMeasurementTool:
01390                      case modeEditGradientVectors:
01391                      case modeInsertPDFButton:
01392                      case modeInsertPDFTextfield:
01393                      case modeInsertPDFCheckbox:
01394                      case modeInsertPDFCombobox:
01395                      case modeInsertPDFListbox:
01396                      case modeInsertPDFTextAnnotation:
01397                      case modeInsertPDFLinkAnnotation:
01398                             qApp->setOverrideCursor(QCursor(CrossCursor), true);
01399                             break;
01400                      default:
01401                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
01402                      break;
01403               }
01404        }
01405 }
01406 
01407 void ScribusView::leaveEvent(QEvent *)
01408 {
01409 /*     if (BlockLeave)
01410               return; */
01411        if (!m_MouseButtonPressed)
01412               qApp->setOverrideCursor(QCursor(ArrowCursor), true);
01413 /*     else
01414        {
01415               if ((SelItem.count() != 0) && (m_MouseButtonPressed) && (!doku->DragP) && (doku->appMode == 1))
01416               {
01417                      PageItem *currItem = SelItem.at(0);
01418                      if ((b->Locked) || (b->Sizing))
01419                             return;
01420                      doku->DragP = true;
01421                      doku->leaveDrag = true;
01422                      doku->DraggedElem = b;
01423                      doku->DragElements.clear();
01424                      for (uint dre=0; dre<SelItem.count(); ++dre)
01425                             doku->DragElements.append(SelItem.at(dre)->ItemNr);
01426                      ScriXmlDoc *ss = new ScriXmlDoc();
01427                      QDragObject *dr = new QTextDrag(ss->WriteElem(&SelItem, doku), this);
01428                      dr->setPixmap(loadIcon("DragPix.xpm"));
01429                      dr->drag();
01430                      delete ss;
01431                      ss=NULL;
01432                      doku->DragP = false;
01433                      doku->leaveDrag = false;
01434                      m_MouseButtonPressed = false;
01435                      doku->DraggedElem = 0;
01436                      doku->DragElements.clear();
01437               }
01438        } */
01439 }
01440 
01441 void ScribusView::contentsDragEnterEvent(QDragEnterEvent *e)
01442 {
01443        QString text;
01444        e->accept(QTextDrag::canDecode(e));
01445        if (QTextDrag::decode(e, text))
01446        {
01447               double gx, gy, gw, gh;
01448               /*<< #3524
01449               setActiveWindow();
01450               raise();
01451               m_ScMW->newActWin(Doc->WinHan);
01452               updateContents();
01453               >>*/
01454 //            SeleItemPos(e->pos());
01455               QUrl ur(text);
01456               QFileInfo fi = QFileInfo(ur.path());
01457               ScriXmlDoc *ss = new ScriXmlDoc();
01458               if (fi.exists())
01459                      text = ur.path();
01460               if(ss->ReadElemHeader(text,fi.exists(), &gx, &gy, &gw, &gh))
01461               {
01462                      dragX = e->pos().x() / Scale;
01463                      dragY = e->pos().y() / Scale;
01464                      dragW = gw;
01465                      dragH = gh;
01466                      DraggedGroup = true;
01467                      DraggedGroupFirst = true;
01468                      //GroupSel = false;
01469                      QPainter p;
01470                      p.begin(viewport());
01471                      PaintSizeRect(&p, QRect());
01472                      emit ItemGeom(gw, gh);
01473 //                   QPoint pv = QPoint(qRound(gx), qRound(gy));
01474 //                   PaintSizeRect(&p, QRect(pv, QPoint(pv.x()+qRound(gw), pv.y()+qRound(gh))));
01475                      p.end();
01476               }
01477               delete ss;
01478               ss=NULL;
01479        }
01480 }
01481 
01482 void ScribusView::contentsDragMoveEvent(QDragMoveEvent *e)
01483 {
01484        QString text;
01485 //     PageItem *currItem;
01486 //     bool img;
01487        e->accept(QTextDrag::canDecode(e));
01488        if (QTextDrag::decode(e, text))
01489        {
01490               if (DraggedGroup)
01491               {
01492                      double gx, gy, gw, gh;
01493                      dragX = e->pos().x() / Scale;
01494                      dragY = e->pos().y() / Scale;
01495                      getDragRectScreen(&gx, &gy, &gw, &gh);
01496                      QPainter p;
01497                      p.begin(viewport());
01498                      gx += Doc->minCanvasCoordinate.x();
01499                      gy += Doc->minCanvasCoordinate.y();
01500                      QPoint pv = QPoint(qRound(gx), qRound(gy));
01501                      if (!DraggedGroupFirst)
01502                             PaintSizeRect(&p, QRect(pv, QPoint(pv.x()+qRound(gw), pv.y()+qRound(gh))));
01503                      DraggedGroupFirst = false;
01504                      p.end();
01505                      emit MousePos(dragX+Doc->minCanvasCoordinate.x(), dragY+Doc->minCanvasCoordinate.y());
01506                      horizRuler->Draw(e->pos().x());
01507                      vertRuler->Draw(e->pos().y());
01508                      return;
01509               }
01510 /*            QUrl ur(text);
01511               QFileInfo fi = QFileInfo(ur.path());
01512               QString ext = fi.extension(false).upper();
01513               QStrList imfo = QImageIO::inputFormats();
01514               if (ext == "JPG")
01515                      ext = "JPEG";
01516               img = ((imfo.contains(ext))||(ext=="PS")||(ext=="EPS")||(ext=="TIF"));
01517               if (!SeleItemPos(e->pos()))
01518               {
01519                      if (SelItem.count() != 0)
01520                             Deselect(true);
01521               }
01522               else
01523               {
01524                      b = SelItem.at(0);
01525                      if (img)
01526                      {
01527                             if (b->PType != 2)
01528                                    Deselect(true);
01529                      }
01530                      else
01531                      {
01532                             if (b->PType != 4)
01533                                    Deselect(true);
01534                      }
01535               } */
01536        }
01537 }
01538 
01539 void ScribusView::contentsDragLeaveEvent(QDragLeaveEvent *)
01540 {
01541        if (DraggedGroup)
01542        {
01543               updateContents();
01544               DraggedGroup = false;
01545               DraggedGroupFirst = false;
01546        }
01547 }
01548 
01549 void ScribusView::contentsDropEvent(QDropEvent *e)
01550 {
01551        QString text;
01552        PageItem *currItem;
01553        bool img = false;
01554 //     struct ScText *hg;
01555 //     uint a;
01556        int re = 0;
01557        e->accept(QTextDrag::canDecode(e));
01558        DraggedGroupFirst = false;
01559        int ex = qRound(e->pos().x()/Scale + Doc->minCanvasCoordinate.x());
01560        int ey = qRound(e->pos().y()/Scale + Doc->minCanvasCoordinate.y());
01561        if (QTextDrag::decode(e, text))
01562        {
01563               //<<#3524
01564               setActiveWindow();
01565               raise();
01566               m_ScMW->newActWin(Doc->WinHan);
01567               updateContents();
01568               //>>
01569               QUrl ur(text);
01570               QFileInfo fi = QFileInfo(ur.path());
01571               QString ext = fi.extension(false).upper();
01572               QStrList imfo = QImageIO::inputFormats();
01573               if (ext == "JPG")
01574                      ext = "JPEG";
01575               //CB Need to handle this ugly file extension list elsewhere... some capabilities class perhaps
01576               img = ((imfo.contains(ext))||(ext=="PS")||(ext=="EPS")||(ext=="PDF")||(ext=="TIF")||(ext=="TIFF")||(ext=="PSD"));
01577               bool selectedItemByDrag=false;
01578               int pscx=qRound(e->pos().x()/Scale), pscy=qRound(e->pos().y()/Scale);
01579               //Loop through all items and see which one(s) were under the drop point on the current layer
01580               //Should make a nice function for this.
01581               for (uint i=0; i<Doc->Items->count(); ++i)
01582               {
01583                      if (Doc->Items->at(i)->LayerNr==Doc->activeLayer())
01584                      {
01585                             if (Doc->Items->at(i)->pointWithinItem(pscx, pscy))
01586                             {
01587                                    Deselect(false);
01588                                    SelectItem(Doc->Items->at(i));
01589                                    selectedItemByDrag=true;
01590                                    break;
01591                             }
01592                      }
01593               }
01594               //CB When we drag an image to a page from outside
01595               //SeleItemPos is from 1.2.x. Needs reenabling for dragging *TO* a frame
01596               if ((fi.exists()) && (img) && !selectedItemByDrag)// && (!SeleItemPos(e->pos())))
01597               {
01598                      int z = Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, ex, ey, 1, 1, 1, Doc->toolSettings.dBrushPict, CommonStrings::None, true);
01599                      PageItem *b = Doc->Items->at(z);
01600                      Doc->LoadPict(ur.path(), b->ItemNr);
01601                      b->setWidth(static_cast<double>(b->OrigW * 72.0 / b->pixm.imgInfo.xres));
01602                      b->setHeight(static_cast<double>(b->OrigH * 72.0 / b->pixm.imgInfo.yres));
01603                      b->OldB2 = b->width();
01604                      b->OldH2 = b->height();
01605                      b->updateClip();
01606                      emit DocChanged();
01607                      update();
01608                      return;
01609               }
01610               //if ((SeleItemPos(e->pos())) && (!text.startsWith("<SCRIBUSELEM")))
01611               if (Doc->m_Selection->count()>0 && Doc->m_Selection->itemAt(0)->pointWithinItem(pscx, pscy) && (!text.startsWith("<SCRIBUSELEM")))
01612               {
01613                      PageItem *b = Doc->m_Selection->itemAt(0);
01614                      if (b->itemType() == PageItem::ImageFrame)
01615                      {
01616                             if ((fi.exists()) && (img))
01617                             {
01618                                    Doc->LoadPict(ur.path(), b->ItemNr);
01619                                    update();
01620                             }
01621                      }
01622                      /* CB leaving this out for now...
01623                      if (b->PType == 4)
01624                      {
01625                             if ((b->BackBox != 0) && (b->itemText.count() == 0))
01626                                    return;
01627                             if ((fi.exists()) && (!img) && (fi.size() < 500000))
01628                             {
01629                                    Serializer *ss = new Serializer(ur.path());
01630                                    if (ss->Read())
01631                                    {
01632                                           int st = doku->currentParaStyle;
01633                                           ss->GetText(b, st, doku->docParagraphStyles[st].Font, doku->docParagraphStyles[st].FontSize, true);
01634                                           emit DocChanged();
01635                                    }
01636                                    delete ss;
01637                                    ss=NULL;
01638                                    update();
01639                             }
01640                             else
01641                             {
01642                                    slotDoCurs(false);
01643                                    slotSetCurs(e->pos().x(), e->pos().y());
01644                                    if (text.startsWith("<SCRIBUSELEM"))
01645                                           return;
01646                                    for (a=0; a<text.length(); ++a)
01647                                    {
01648                                           hg = new ScText;
01649                                           hg->ch = text.at(a);
01650                                           if (hg->ch == QChar(10))
01651                                                  hg->ch = QChar(13);
01652                                           if (hg->ch == QChar(4))
01653                                                  hg->ch = QChar(9);
01654                                           if (hg->ch == QChar(5))
01655                                                  hg->ch = QChar(13);
01656                                           hg->cfont = b->IFont;
01657                                           hg->csize = b->ISize;
01658                                           hg->ccolor = b->TxtFill;
01659                                           hg->cshade = b->ShTxtFill;
01660                                           hg->cstroke = b->TxtStroke;
01661                                           hg->cshade2 = b->ShTxtStroke;
01662                                           hg->cselect = false;
01663                                           hg->cscale = b->TxtScale;
01664                                           hg->cextra = 0;
01665                                           hg->cstyle = 0;
01666                                           hg->cab = 0;
01667                                           hg->xp = 0;
01668                                           hg->yp = 0;
01669                                           hg->PRot = 0;
01670                                           hg->PtransX = 0;
01671                                           hg->PtransY = 0;
01672                                           b->itemText.insert(b->CPos, hg);
01673                                           b->CPos += 1;
01674                                    }
01675                                    emit DocChanged();
01676                                    update();
01677                             }
01678                      }*/
01679               }
01680               else
01681               {
01682                      for (uint as = 0; as < Doc->Items->count(); ++as)
01683                      {
01684                             Doc->Items->at(as)->setSelected(false);
01685                      }
01686                      uint oldDocItemCount = Doc->Items->count();
01687                      if ((!img) && (Doc->DraggedElem == 0))
01688                      {
01689                             undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::Create,"",Um::ICreate);
01690                             if ((fi.exists()) && (!img))
01691                             {
01692                                    QString data;
01693                                    if (fi.extension(true).lower() == "sml")
01694                                    {
01695                                           QString f = "";
01696                                           loadText(ur.path(), &f);
01697                                           StencilReader *pre = new StencilReader();
01698                                           data = pre->createObjects(f);
01699                                           delete pre;
01700                                           emit LoadElem(data, ex, ey, false, false, Doc, this);
01701                                    }
01702                                    else if (fi.extension(true).lower() == "shape")
01703                                    {
01704                                           QString f = "";
01705                                           loadText(ur.path(), &f);
01706                                           StencilReader *pre = new StencilReader();
01707                                           data = pre->createShape(f);
01708                                           delete pre;
01709                                           emit LoadElem(data, ex, ey, false, false, Doc, this);
01710                                    }
01711                                    else
01712                                           emit LoadElem(ur.path(), ex, ey, true, false, Doc, this);
01713                             }
01714                             else
01715                                    emit LoadElem(QString(text), ex, ey, false, false, Doc, this);
01716                             Doc->m_Selection->clear();
01717                             for (uint as = oldDocItemCount; as < Doc->Items->count(); ++as)
01718                             {
01719                                    currItem = Doc->Items->at(as);
01720                                    Doc->setRedrawBounding(currItem);
01721                                    Doc->m_Selection->addItem(currItem, true);
01722                                    if (currItem->isBookmark)
01723                                           emit AddBM(currItem);
01724                             }
01725                             undoManager->commit();
01726                      }
01727                      else
01728                      {
01729                             if (Doc->DraggedElem != 0)
01730                             {
01731                                    if (!Doc->leaveDrag)
01732                                    {
01733                                           QPopupMenu *pmen = new QPopupMenu();
01734                                           qApp->setOverrideCursor(QCursor(ArrowCursor), true);
01735                                           pmen->insertItem( tr("Copy Here"));
01736                                           int mov = pmen->insertItem( tr("Move Here"));
01737                                           pmen->insertItem( tr("Cancel"));
01738                                           for (uint dre=0; dre<Doc->DragElements.count(); ++dre)
01739                                           {
01740                                                  if (Doc->Items->at(Doc->DragElements[dre])->locked())
01741                                                  {
01742                                                         pmen->setItemEnabled(mov, false);
01743                                                         break;
01744                                                  }
01745                                           }
01746                                           re = pmen->indexOf(pmen->exec(QCursor::pos()));
01747                                           delete pmen;
01748                                           pmen=NULL;
01749                                    }
01750                                    else
01751                                           re = 1;
01752                                    if ((re == 2) || (re == -1))
01753                                    {
01754                                           updateContents();
01755                                           return;
01756                                    }
01757                                    if ((re == 1) || (Doc->leaveDrag))
01758                                    {
01759                                           QPtrList<PageItem> pasted;
01760                                           emit LoadElem(QString(text), ex, ey, false, false, Doc, this);
01761                                           for (uint as = oldDocItemCount; as < Doc->Items->count(); ++as)
01762                                           {
01763                                                  pasted.append(Doc->Items->at(as));
01764                                           }
01765                                           Doc->m_Selection->clear();
01766                                           for (uint dre=0; dre<Doc->DragElements.count(); ++dre)
01767                                           {
01768                                                  Doc->m_Selection->addItem(Doc->Items->at(Doc->DragElements[dre]), true);
01769                                           }
01770                                           PageItem* bb;
01771                                           int fin;
01772                                           for (uint dre=0; dre<Doc->DragElements.count(); ++dre)
01773                                           {
01774                                                  bb = pasted.at(dre);
01775                                                  currItem = Doc->m_Selection->itemAt(dre);
01776                                                  if ((currItem->asTextFrame()) && ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0)))
01777                                                  {
01778                                                         PageItem* before = currItem->prevInChain();
01779                                                         PageItem* after = currItem->nextInChain();
01780                                                         currItem->unlink();
01781                                                         if (before != 0)
01782                                                         {
01783                                                                fin = Doc->m_Selection->findItem(before);
01784                                                                if (fin != -1)
01785                                                                       before = pasted.at(fin);
01786                                                                before->unlink();
01787                                                                before->link(bb);
01788                                                         }
01789                                                         if (after != 0)
01790                                                         {
01791                                                                fin = Doc->m_Selection->findItem(after);
01792                                                                if (fin != -1)
01793                                                                       after = pasted.at(fin);                                                             
01794                                                                bb->link(after);
01795                                                         }
01796                                                  }
01797                                           }
01798 /*                                        for (uint dre=0; dre<Doc->DragElements.count(); ++dre)
01799                                           {
01800                                                  currItem = Doc->m_Selection->itemAt(dre);
01801                                                  currItem->NextBox = 0;
01802                                                  currItem->BackBox = 0;
01803                                           }
01804 */
01805                                           pasted.clear();
01806                                           Doc->itemSelection_DeleteItem();
01807                                    }
01808                             }
01809                             if ((!img) && ((re == 0)))
01810                                    emit LoadElem(QString(text), ex, ey, false, false, Doc, this);
01811                             Doc->DraggedElem = 0;
01812                             Doc->DragElements.clear();
01813                             Doc->m_Selection->clear();
01814                             for (uint as = oldDocItemCount; as < Doc->Items->count(); ++as)
01815                             {
01816                                    currItem = Doc->Items->at(as);
01817                                    Doc->setRedrawBounding(currItem);
01818                                    Doc->m_Selection->addItem(currItem, true);
01819                                    if (currItem->isBookmark)
01820                                           emit AddBM(currItem);
01821                             }
01822                      }
01823                      if (Doc->m_Selection->count() > 1)
01824                      {
01825                             Doc->m_Selection->connectItemToGUI();
01826                             Doc->m_Selection->setGroupRect();
01827                             double gx, gy, gh, gw;
01828                             Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
01829                             double nx = gx;
01830                             double ny = gy;
01831                             if (!Doc->ApplyGuides(&nx, &ny))
01832                             {
01833                                    FPoint npx;
01834                                    npx = Doc->ApplyGridF(FPoint(nx, ny));
01835                                    nx = npx.x();
01836                                    ny = npx.y();
01837                             }
01838                             moveGroup(nx-gx, ny-gy, false);
01839                             Doc->m_Selection->setGroupRect();
01840                             Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
01841                             nx = gx+gw;
01842                             ny = gy+gh;
01843                             Doc->ApplyGuides(&nx, &ny);
01844                             moveGroup(nx-(gx+gw), ny-(gy+gh), false);
01845                             Doc->m_Selection->setGroupRect();
01846                             Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
01847                             for (uint a = 0; a < Doc->m_Selection->count(); ++a)
01848                             {
01849                                    PageItem *currItem = Doc->m_Selection->itemAt(a);
01850                                    currItem->gXpos = currItem->xPos() - gx;
01851                                    currItem->gYpos = currItem->yPos() - gy;
01852                                    currItem->gWidth = gw;
01853                                    currItem->gHeight = gh;
01854                             }
01855                             emit ItemPos(gx, gy);
01856                             emit ItemGeom(gw, gh);
01857                      }
01858                      else
01859                      {
01860                             Doc->m_Selection->connectItemToGUI();
01861                             currItem = Doc->m_Selection->itemAt(0);
01862                             if (Doc->useRaster)
01863                             {
01864                                    double nx = currItem->xPos();
01865                                    double ny = currItem->yPos();
01866                                    if (!Doc->ApplyGuides(&nx, &ny))
01867                                    {
01868                                           FPoint npx;
01869                                           npx = Doc->ApplyGridF(FPoint(nx, ny));
01870                                           nx = npx.x();
01871                                           ny = npx.y();
01872                                    }
01873                                    Doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem);
01874                             }
01875                      }
01876                      updateContents();
01877               }
01878               if (!Doc->masterPageMode())
01879               {
01880                      uint docPagesCount=Doc->Pages->count();
01881                      uint docCurrPageNo=Doc->currentPageNumber();
01882                      for (uint i = 0; i < docPagesCount; ++i)
01883                      {
01884                             int x = static_cast<int>(Doc->Pages->at(i)->xOffset());
01885                             int y = static_cast<int>(Doc->Pages->at(i)->yOffset());
01886                             int w = static_cast<int>(Doc->Pages->at(i)->width());
01887                             int h = static_cast<int>(Doc->Pages->at(i)->height());
01888                             if (QRect(x, y, w, h).contains(ex, ey))
01889                             {
01890                                    if (docCurrPageNo != i)
01891                                    {
01892                                           Doc->setCurrentPage(Doc->Pages->at(i));
01893                                           setMenTxt(i);
01894                                           DrawNew();
01895                                    }
01896                                    break;
01897                             }
01898                      }
01899                      setRulerPos(contentsX(), contentsY());
01900               }
01901        }
01902 }
01903 
01904 void ScribusView::contentsMouseDoubleClickEvent(QMouseEvent *m)
01905 {
01906        m->accept();
01907        m_MouseButtonPressed = false;
01908        PageItem *currItem = 0;
01909        if (Doc->EditClip)
01910        {
01911               emit EndNodeEdit();
01912               return;
01913        }
01914        if ((Doc->m_Selection->isMultipleSelection()) || (Doc->appMode != modeNormal))
01915        {
01916               if ((Doc->m_Selection->isMultipleSelection()) && (Doc->appMode == modeNormal))
01917               {
01918                      if (GetItem(&currItem))
01919                      {
01920                             if (currItem->isTableItem)
01921                             {
01922                                    Deselect(false);
01923                                    Doc->m_Selection->addItem(currItem);
01924                                    currItem->isSingleSel = true;
01925                                    //CB FIXME dont call this if the added item is item 0
01926                                    if (!Doc->m_Selection->primarySelectionIs(currItem))
01927                                           currItem->emitAllToGUI();
01928                                    currItem->paintObj();
01929                             }
01930                      }
01931                      return;
01932               }
01933               else
01934               {
01935                      if (!(GetItem(&currItem) && (Doc->appMode == modeEdit) && currItem->asTextFrame()))
01936                      {
01937                             contentsMousePressEvent(m);
01938                             return;
01939                      }
01940               }
01941        }
01942        if (GetItem(&currItem))
01943        {
01944               if ((currItem->itemType() == PageItem::Polygon) || (currItem->itemType() == PageItem::PolyLine) || (currItem->itemType() == PageItem::ImageFrame) || (currItem->itemType() == PageItem::PathText))
01945               {
01946                      if ((currItem->locked()) || (!currItem->ScaleType))
01947                      {
01948                             contentsMousePressEvent(m);
01949                             return;
01950                      }
01951                      //If we double click on an image frame and theres no image assigned, open the
01952                      //load picture dialog, else put it into edit mode if the frame is set to show the image
01953                      if (currItem->itemType() == PageItem::ImageFrame)
01954                      {
01955                             if (currItem->Pfile.isEmpty())
01956                                    emit LoadPic();
01957                             else if (currItem->imageShown())
01958                                    emit Amode(modeEdit);
01959                      }
01960                      else
01961                             emit Amode(modeEdit);
01962               }
01963               else
01964                      if (currItem->itemType() == PageItem::TextFrame)
01965                      {
01966                             //CB old code
01967                             //emit currItem->isAnnotation() ? AnnotProps() : Amode(modeEdit);
01968                             //contentsMousePressEvent(m);
01969                             //CB if annotation, open the annotation dialog
01970                             if (currItem->isAnnotation())
01971                             {
01972                                    emit AnnotProps();
01973                                    contentsMousePressEvent(m);
01974                             }
01975                             //else if not in mode edit, set mode edit
01976                             else if (Doc->appMode != modeEdit)
01977                             {
01978                                    emit Amode(modeEdit);
01979                                    //CB ignore the double click and go with a single one
01980                                    //if we werent in mode edit before.
01981                                    //unsure if this is correct, but its ok given we had no
01982                                    //double click select until now.
01983                                    contentsMousePressEvent(m);
01984                             }
01985                             //otherwise, select between the whitespace
01986                             else
01987                             {      //Double click in a frame to select a word
01988                                    PageItem_TextFrame *cItem=currItem->asTextFrame();
01989                                    bool inText = slotSetCurs(m->x(), m->y());
01990                                    if (!inText)
01991                                    {
01992                                           Deselect(true);
01993                                           slotDoCurs(true);
01994                                           emit Amode(modeNormal);
01995                                           return;
01996                                    }
01997                                    int a=cItem->CPos;
01998                                    while(a>0)
01999                                    {
02000                                           if (cItem->itemText.text(a-1).isLetterOrNumber())
02001                                                  --a;
02002                                           else
02003                                                  break;
02004                                    }
02005                                    int b=cItem->CPos;
02006                                    while(b<cItem->itemText.length())
02007                                    {
02008                                           if (cItem->itemText.text(b).isLetterOrNumber())
02009                                                  ++b;
02010                                           else
02011                                                  break;
02012                                    }
02013                                    oldCp = a;
02014                                    cItem->CPos=b;
02015                                    cItem->ExpandSel(1, oldCp);
02016                                    slotDoCurs(true);
02017                             }
02018                      }
02019        }
02020 }
02021 
02022 void ScribusView::normalizeSelectionRect()
02023 {
02024        if(Mxp > SeRx)
02025        {
02026               int tmp = SeRx;
02027               SeRx = Mxp;
02028               Mxp = tmp;
02029        }
02030        if(Myp > SeRy)
02031        {
02032               int tmp = SeRy;
02033               SeRy = Myp;
02034               Myp = tmp;
02035        }
02036 }
02037 
02038 void ScribusView::contentsMouseReleaseEvent(QMouseEvent *m)
02039 {
02040        PageItem *currItem;
02041        m_MouseButtonPressed = false;
02042        if (Doc->appMode == modeNormal && Doc->guidesSettings.guidesShown)
02043        {
02044               bool foundGuide = false;
02045               double nx = translateToDoc(m->x(), m->y()).x();
02046               double ny = translateToDoc(m->x(), m->y()).y();
02047               double grabRadScale=Doc->guidesSettings.grabRad / Scale;
02048               if (Doc->currentPage()->guides.isMouseOnHorizontal(ny + grabRadScale, ny - grabRadScale, GuideManagerCore::Standard)
02049                      || Doc->currentPage()->guides.isMouseOnVertical(nx + grabRadScale, nx - grabRadScale, GuideManagerCore::Standard))
02050                      foundGuide = true;
02051               if ((foundGuide) && (m->button() == RightButton) && (!GetItem(&currItem)))
02052               {
02053                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
02054                      MoveGY = false;
02055                      MoveGX = false;
02056                      return;
02057               }
02058               if (MoveGY)
02059               {
02060                      SetYGuide(m, GyM);
02061                      MoveGY = false;
02062                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
02063                      updateContents();
02064                      GyM = -1;
02065                      return;
02066               }
02067               if (MoveGX)
02068               {
02069                      SetXGuide(m, GxM);
02070                      MoveGX = false;
02071                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
02072                      updateContents();
02073                      GxM = -1;
02074                      return;
02075               }
02076        }
02077        if (Doc->appMode == modeEditGradientVectors)
02078               return;
02079        if (Doc->appMode == modeCopyProperties)
02080               return;
02081        if (Doc->appMode == modeMeasurementTool)
02082        {
02083               QPainter p;
02084               p.begin(viewport());
02085               QPoint out = contentsToViewport(QPoint(0, 0));
02086               p.translate(out.x(), out.y());
02087               p.setRasterOp(XorROP);
02088               p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
02089               p.drawLine(Dxp, Dyp, Mxp, Myp);
02090               p.end();
02091               qApp->setOverrideCursor(QCursor(ArrowCursor), true);
02092               //emit PaintingDone();
02093               return;
02094        }
02095        if (Doc->appMode == modePanning)
02096        {
02097               if ((m->state() & Qt::RightButton) && (m->state() & Qt::ControlButton))
02098               {
02099                      m_ScMW->setAppMode(modeNormal);
02100               }
02101               return;
02102        }
02103        if (Doc->appMode == modeDrawTable)
02104        {
02105               if ((Doc->m_Selection->count() == 0) && (HaveSelRect) && (!MidButt))
02106               {
02107                      QRect AreaR = QRect(static_cast<int>(Mxp), static_cast<int>(Myp), static_cast<int>(SeRx-Mxp), static_cast<int>(SeRy-Myp));
02108                      QPainter p;
02109                      p.begin(viewport());
02110                      ToView(&p);
02111                      p.scale(Scale, Scale);
02112                      p.setRasterOp(XorROP);
02113                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
02114                      normalizeSelectionRect();
02115                      HaveSelRect = false;
02116                      double Tx, Ty, Tw, Th;
02117                      FPoint np2 = Doc->ApplyGrid(QPoint(Mxp, Myp));
02118                      Tx = np2.x();
02119                      Ty = np2.y();
02120                      Doc->ApplyGuides(&Tx, &Ty);
02121                      Mxp = qRound(Tx);
02122                      Myp = qRound(Ty);
02123                      np2 = Doc->ApplyGrid(QPoint(SeRx, SeRy));
02124                      Tw = np2.x();
02125                      Th = np2.y();
02126                      Doc->ApplyGuides(&Tw, &Th);
02127                      SeRx = qRound(Tw);
02128                      SeRy = qRound(Th);
02129                      Tw = Tw - Tx;
02130                      Th = Th - Ty;
02131                      int z;
02132                      int Cols, Rows;
02133                      double deltaX, deltaY, offX, offY;
02134                      if ((Th < 6) || (Tw < 6))
02135                      {
02136                             p.drawRect(AreaR);
02137                             p.end();
02138                             Doc->appMode = modeNormal;
02139                             emit PaintingDone();
02140                             return;
02141                      }
02142                      InsertTable *dia = new InsertTable(this, static_cast<int>(Th / 6), static_cast<int>(Tw / 6));
02143                      if (!dia->exec())
02144                      {
02145                             p.drawRect(AreaR);
02146                             p.end();
02147                             Doc->appMode = modeNormal;
02148                             emit PaintingDone();
02149                             delete dia;
02150                             dia=NULL;
02151                             return;
02152                      }
02153                      p.end();
02154                      Cols = dia->Cols->value();
02155                      Rows = dia->Rows->value();
02156                      delete dia;
02157                      dia=NULL;
02158                      deltaX = Tw / Cols;
02159                      deltaY = Th / Rows;
02160                      offX = 0.0;
02161                      offY = 0.0;
02162                      Doc->m_Selection->clear();
02163                      if (UndoManager::undoEnabled())
02164                             undoManager->beginTransaction(Doc->currentPage()->getUName(),
02165                                                                                Um::ITable, Um::CreateTable,
02166                                                                                QString(Um::RowsCols).arg(Rows).arg(Cols),
02167                                                                                Um::ICreate);
02168                      for (int rc = 0; rc < Rows; ++rc)
02169                      {
02170                             for (int cc = 0; cc < Cols; ++cc)
02171                             {
02172                                    //z = PaintText(Tx + offX, Ty + offY, deltaX, deltaY, Doc->toolSettings.dWidth, Doc->toolSettings.dPenText);
02173                                    z = Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, Tx + offX, Ty + offY, deltaX, deltaY, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenText, !m_MouseButtonPressed);
02174                                    currItem = Doc->Items->at(z);
02175                                    currItem->isTableItem = true;
02176                                    //currItem->setTextFlowsAroundFrame(true);
02177                                    //currItem->setTextFlowUsesBoundingBox(true);
02178                                    currItem->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
02179                                    Doc->m_Selection->addItem(currItem);
02180                                    offX += deltaX;
02181                             }
02182                             offY += deltaY;
02183                             offX = 0.0;
02184                      }
02185                      for (int rc = 0; rc < Rows; ++rc)
02186                      {
02187                             for (int cc = 0; cc < Cols; ++cc)
02188                             {
02189                                    currItem = Doc->m_Selection->itemAt((rc * Cols) + cc);
02190                                    if (rc == 0)
02191                                           currItem->TopLink = 0;
02192                                    else
02193                                           currItem->TopLink = Doc->m_Selection->itemAt(((rc-1)*Cols)+cc);
02194                                    if (rc == Rows-1)
02195                                           currItem->BottomLink = 0;
02196                                    else
02197                                           currItem->BottomLink = Doc->m_Selection->itemAt(((rc+1)*Cols)+cc);
02198                                    if (cc == 0)
02199                                           currItem->LeftLink = 0;
02200                                    else
02201                                           currItem->LeftLink = Doc->m_Selection->itemAt((rc*Cols)+cc-1);
02202                                    if (cc == Cols-1)
02203                                           currItem->RightLink = 0;
02204                                    else
02205                                           currItem->RightLink = Doc->m_Selection->itemAt((rc*Cols)+cc+1);
02206                             }
02207                      }
02208                      emit DoGroup();
02209                      if (UndoManager::undoEnabled())
02210                             undoManager->commit();
02211               }
02212               if (!Prefs->stickyTools)
02213               {
02214                      Doc->appMode = modeNormal;
02215                      emit PaintingDone();
02216               }
02217               else
02218                      emit Amode(Doc->appMode);
02219               emit DocChanged();
02220               updateContents();
02221               return;
02222        }
02223        if (Doc->appMode == modeDrawFreehandLine)
02224        {
02225               if (RecordP.size() > 1)
02226               {
02227                      uint z = Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Mxp, Myp, 1, 1, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenLine, !m_MouseButtonPressed);
02228                      currItem = Doc->Items->at(z);
02229                      currItem->PoLine.resize(0);
02230                      currItem->PoLine.addPoint(RecordP.point(0));
02231                      currItem->PoLine.addPoint(RecordP.point(0));
02232                      for (uint px = 1; px < RecordP.size()-1; ++px)
02233                      {
02234                             currItem->PoLine.addPoint(RecordP.point(px));
02235                             currItem->PoLine.addPoint(RecordP.point(px));
02236                             currItem->PoLine.addPoint(RecordP.point(px));
02237                             currItem->PoLine.addPoint(RecordP.point(px));
02238                      }
02239                      currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
02240                      currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
02241                      FPoint tp2(getMinClipF(&currItem->PoLine));
02242                      currItem->setXYPos(tp2.x(), tp2.y(), true);
02243                      currItem->PoLine.translate(-tp2.x(), -tp2.y());
02244                      FPoint tp(getMaxClipF(&currItem->PoLine));
02245                      Doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
02246 //                   currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
02247                      Doc->AdjustItemSize(currItem);
02248                      Doc->m_Selection->clear();
02249                      Doc->m_Selection->addItem(currItem);
02250                      currItem->ClipEdited = true;
02251                      currItem->FrameType = 3;
02252                      currItem->OwnPage = Doc->OnPage(currItem);
02253               }
02254               if (!Prefs->stickyTools)
02255               {
02256                      Doc->appMode = modeNormal;
02257                      emit PaintingDone();
02258               }
02259               else
02260                      emit Amode(Doc->appMode);
02261               emit DocChanged();
02262               updateContents();
02263               return;
02264        }
02265        if ((Doc->EditClip) && (ClRe == -1) && (HaveSelRect))
02266        {
02267               double sc = Scale;
02268               QPainter p;
02269               p.begin(viewport());
02270               ToView(&p);
02271               p.scale(Scale, Scale);
02272               p.setRasterOp(XorROP);
02273               p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
02274               p.drawRect(Mxp, Myp, SeRx-Mxp, SeRy-Myp);
02275               p.end();
02276               normalizeSelectionRect();
02277               currItem = Doc->m_Selection->itemAt(0);
02278               SelNode.clear();
02279               QRect Sele = QRect(static_cast<int>(Mxp*sc), static_cast<int>(Myp*sc), static_cast<int>((SeRx-Mxp)*sc), static_cast<int>((SeRy-Myp)*sc));
02280               FPointArray Clip;
02281               if (EditContour)
02282                      Clip = currItem->ContourLine;
02283               else
02284                      Clip = currItem->PoLine;
02285               for (uint a = 0; a < Clip.size(); ++a)
02286               {
02287                      if (Clip.point(a).x() > 900000)
02288                             continue;
02289                      p.begin(viewport());
02290                      Transform(currItem, &p);
02291                      QPoint npf = p.xForm(Clip.pointQ(a));
02292                      p.end();
02293                      if ((Sele.contains(npf)) && ((a == 0) || (((a-2) % 4) == 0)))
02294                      {
02295                             ClRe = a;
02296                             SelNode.append(a);
02297                             emit ClipPo(Clip.point(a).x(), Clip.point(a).y());
02298                      }
02299               }
02300               HaveSelRect = false;
02301               if (EditContour)
02302                      MarkClip(currItem, currItem->ContourLine, true);
02303               else
02304                      MarkClip(currItem, currItem->PoLine, true);
02305 
02306               if (oldClip) // is there the old clip stored for the undo action
02307               {
02308                      FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
02309                      if (*oldClip != newClip)
02310                      {
02311                             QString name = isContourLine ? Um::EditContour : Um::EditShape;
02312                             ItemState<QPair<FPointArray, FPointArray> > *state =
02313                                           new ItemState<QPair<FPointArray, FPointArray> >(name);
02314                             state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
02315                             state->set("IS_CONTOUR", isContourLine);
02316                             state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
02317                             state->set("OLD_X", oldItemX);
02318                             state->set("OLD_Y", oldItemY);
02319                             state->set("NEW_X", currItem->xPos());
02320                             state->set("NEW_Y", currItem->yPos());
02321                             undoManager->action(currItem, state);
02322                             undoManager->commit();
02323                      }
02324                      else
02325                             undoManager->cancelTransaction();
02326 
02327                      delete oldClip;
02328                      oldClip = 0;
02329               }
02330               m_SnapCounter = 0;
02331               return;
02332        }
02333 /*     if (moveTimerElapsed() && (Doc->EditClip) && (SegP1 == -1) && (SegP2 == -1))
02334        {
02335               currItem = Doc->m_Selection->itemAt(0);
02336               if (operItemMoving)
02337               {
02338                      currItem->OldB2 = currItem->width();
02339                      currItem->OldH2 = currItem->height();
02340                      double nx = m->x()/Scale + Doc->minCanvasCoordinate.x();
02341                      double ny = m->y()/Scale + Doc->minCanvasCoordinate.y();
02342                      if (!Doc->ApplyGuides(&nx, &ny))
02343                      {
02344                             FPoint npg(ApplyGridF(FPoint(nx, ny)));
02345                             nx = npg.x();
02346                             ny = npg.y();
02347                      }
02348                      FPoint np(nx, ny, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
02349                      MoveClipPoint(currItem, np);
02350               }
02351               Doc->AdjustItemSize(currItem);
02352               emit DocChanged();
02353               updateContents();
02354               operItemMoving = false;
02355               return;
02356        }
02357        if (moveTimerElapsed() && (Doc->EditClip) && (SegP1 != -1) && (SegP2 != -1)) */
02358        if (moveTimerElapsed() && (Doc->EditClip))
02359        {
02360               SegP1 = -1;
02361               SegP2 = -1;
02362               currItem = Doc->m_Selection->itemAt(0);
02363               operItemMoving = false;
02364 
02365               ItemState<QPair<FPointArray, FPointArray> > *state = NULL;
02366               if (oldClip) // is there the old clip stored for the undo action
02367               {
02368                      FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
02369                      if (*oldClip != newClip)
02370                      {
02371                             QString name = isContourLine ? Um::EditContour : Um::EditShape;
02372                             state = new ItemState<QPair<FPointArray, FPointArray> >(name);
02373                             state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
02374                             state->set("IS_CONTOUR", isContourLine);
02375                             state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
02376                             undoManager->setUndoEnabled(false);
02377                      }
02378                      else
02379                      {
02380                             delete oldClip;
02381                             oldClip = 0;
02382                             undoManager->cancelTransaction();
02383                      }
02384               }
02385               double xposOrig = currItem->xPos();
02386               double yposOrig = currItem->yPos();
02387               if (ClRe != -1)
02388               {
02389                      double newX = m->x();
02390                      double newY = m->y();
02391                      FPoint np(newX-Mxp, newY-Myp, 0, 0, currItem->rotation(), 1, 1, true);
02392                      currItem->OldB2 = currItem->width();
02393                      currItem->OldH2 = currItem->height();
02394                      FPointArray Clip;
02395                      if (EditContour)
02396                             Clip = currItem->ContourLine;
02397                      else
02398                             Clip = currItem->PoLine;
02399                      FPoint npf = FPoint(Clip.point(ClRe).x() + np.x() / Scale, Clip.point(ClRe).y() + np.y() / Scale);
02400                      double nx = npf.x();
02401                      double ny = npf.y();
02402                      nx += currItem->xPos();
02403                      ny += currItem->yPos();
02404                      if (!Doc->ApplyGuides(&nx, &ny))
02405                             npf = Doc->ApplyGridF(FPoint(nx, ny));
02406                      else
02407                             npf = FPoint(nx, ny);
02408                      npf = FPoint(npf.x() - currItem->xPos(), npf.y() - currItem->yPos());
02409                      MoveClipPoint(currItem, npf);
02410               }
02411 
02412               Doc->AdjustItemSize(currItem);
02413               if (!EditContour)
02414                      currItem->ContourLine.translate(xposOrig - currItem->xPos(), yposOrig - currItem->yPos());
02415               emit DocChanged();
02416               updateContents();
02417               if (oldClip)
02418               {
02419                      state->set("OLD_X", oldItemX);
02420                      state->set("OLD_Y", oldItemY);
02421                      state->set("NEW_X", currItem->xPos());
02422                      state->set("NEW_Y", currItem->yPos());
02423                      undoManager->setUndoEnabled(true);
02424                      undoManager->action(currItem, state);
02425                      undoManager->commit();
02426                      delete oldClip;
02427                      oldClip = 0;
02428               }
02429               m_SnapCounter = 0;
02430               return;
02431        }
02432        if ((!GetItem(&currItem)) && (m->button() == RightButton) && (!Doc->DragP) && (Doc->appMode == modeNormal))
02433        {
02434               QPopupMenu *pmen = new QPopupMenu();
02435               if ((m_ScMW->Buffer2.startsWith("<SCRIBUSELEM")) || (m_ScMW->Buffer2.contains("<SCRIBUSFRAGMENT")) || (m_ScMW->scrapbookPalette->tempBView->objectMap.count() > 0))
02436               {
02437                      Mxp = m->x();
02438                      Myp = m->y();
02439                      if ((m_ScMW->Buffer2.startsWith("<SCRIBUSELEM")) || (m_ScMW->Buffer2.contains("<SCRIBUSFRAGMENT")))
02440                             pmen->insertItem( tr("&Paste") , this, SLOT(PasteToPage()));
02441                      if (m_ScMW->scrapbookPalette->tempBView->objectMap.count() > 0)
02442                      {
02443                             pmen3 = new QPopupMenu();
02444                             QMap<QString,BibView::Elem>::Iterator it;
02445                             it = m_ScMW->scrapbookPalette->tempBView->objectMap.end();
02446                             it--;
02447                             for (uint m = 0; m < m_ScMW->scrapbookPalette->tempBView->objectMap.count(); ++m)
02448                             {
02449                                    QString strippedName = it.key();
02450                                    QPixmap pm = it.data().Preview;
02451                                    pmen3->insertItem(pm, strippedName);
02452                                    it--;
02453                             }
02454                             connect(pmen3, SIGNAL(activated(int)), this, SLOT(PasteRecentToPage(int)));
02455                             pmen->insertItem( tr("Paste Recent"), pmen3);
02456                      }
02457                      pmen->insertSeparator();
02458               }
02459               setObjectUndoMode();
02460               m_ScMW->scrActions["editUndoAction"]->addTo(pmen);
02461               m_ScMW->scrActions["editRedoAction"]->addTo(pmen);
02462               pmen->insertSeparator();
02463               m_ScMW->scrActions["viewShowMargins"]->addTo(pmen);
02464               m_ScMW->scrActions["viewShowFrames"]->addTo(pmen);
02465               m_ScMW->scrActions["viewShowLayerMarkers"]->addTo(pmen);
02466               m_ScMW->scrActions["viewShowImages"]->addTo(pmen);
02467               m_ScMW->scrActions["viewShowGrid"]->addTo(pmen);
02468               m_ScMW->scrActions["viewShowGuides"]->addTo(pmen);
02469               m_ScMW->scrActions["viewShowBaseline"]->addTo(pmen);
02470               m_ScMW->scrActions["viewShowTextChain"]->addTo(pmen);
02471               m_ScMW->scrActions["viewRulerMode"]->addTo(pmen);
02472               pmen->insertSeparator();
02473               m_ScMW->scrActions["viewSnapToGrid"]->addTo(pmen);
02474               m_ScMW->scrActions["viewSnapToGuides"]->addTo(pmen);
02475               int pgNum = -1;
02476               int docPageCount = static_cast<int>(Doc->Pages->count() - 1);
02477               double bleedRight = 0.0;
02478               double bleedLeft = 0.0;
02479               double bleedBottom = 0.0;
02480               double bleedTop = 0.0;
02481               bool drawBleed = false;
02482               int x2 = static_cast<int>(translateToDoc(m->x(), m->y()).x());
02483               int y2 = static_cast<int>(translateToDoc(m->x(), m->y()).y());
02484               if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
02485                      drawBleed = true;
02486               for (int a = docPageCount; a > -1; a--)
02487               {
02488                      if (drawBleed)
02489                             Doc->getBleeds(a, &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
02490                      int x = static_cast<int>(Doc->Pages->at(a)->xOffset() - bleedLeft);
02491                      int y = static_cast<int>(Doc->Pages->at(a)->yOffset() - bleedTop);
02492                      int w = static_cast<int>(Doc->Pages->at(a)->width() + bleedLeft + bleedRight);
02493                      int h = static_cast<int>(Doc->Pages->at(a)->height() + bleedBottom + bleedTop);
02494                      if (QRect(x, y, w, h).contains(x2, y2))
02495                      {
02496                             pgNum = static_cast<int>(a);
02497                             if (drawBleed)  // check again if its really on the correct page
02498                             {
02499                                    for (int a2 = docPageCount; a2 > -1; a2--)
02500                                    {
02501                                           int xn = static_cast<int>(Doc->Pages->at(a2)->xOffset());
02502                                           int yn = static_cast<int>(Doc->Pages->at(a2)->yOffset());
02503                                           int wn = static_cast<int>(Doc->Pages->at(a2)->width());
02504                                           int hn = static_cast<int>(Doc->Pages->at(a2)->height());
02505                                           if (QRect(xn, yn, wn, hn).contains(x2, y2))
02506                                           {
02507                                                  pgNum = static_cast<int>(a2);
02508                                                  break;
02509                                           }
02510                                    }
02511                             }
02512                             break;
02513                      }
02514               }
02515               if (pgNum != -1)
02516               {
02517                      pmen->insertSeparator();
02518                      m_ScMW->scrActions["pageApplyMasterPage"]->addTo(pmen);
02519                      m_ScMW->scrActions["pageManageGuides"]->addTo(pmen);
02520                      m_ScMW->scrActions["pageManageMargins"]->addTo(pmen);
02521                      pmen->insertSeparator();
02522                      m_ScMW->scrActions["pageDelete"]->addTo(pmen);
02523               }
02524               pmen->exec(QCursor::pos());
02525               setGlobalUndoMode();
02526               delete pmen;
02527               pmen=NULL;
02528               if (m_ScMW->scrapbookPalette->tempBView->objectMap.count() > 0)
02529               {
02530                      delete pmen3;
02531                      pmen3=NULL;
02532               }
02533               return;
02534        }
02535        if ((Doc->appMode != modeMagnifier) && (!Doc->EditClip) && (Doc->appMode != modeDrawBezierLine))
02536        {
02537               if ((GetItem(&currItem)) && (m->button() == RightButton) && (!Doc->DragP))
02538               {
02539                      QPopupMenu *pmen = new QPopupMenu();
02540                      QPopupMenu *pmen2 = new QPopupMenu();
02541                      pmen3 = new QPopupMenu();
02542                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
02543                      QPopupMenu *pmen4 = new QPopupMenu();
02544                      QPopupMenu *pmenEditContents = new QPopupMenu();
02545                      QPopupMenu *pmenLevel = new QPopupMenu();
02546                      QPopupMenu *pmenPDF = new QPopupMenu();
02547                      pmenResolution = new QPopupMenu();
02548                      setObjectUndoMode();
02549                      if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::ImageFrame) || (currItem->itemType() == PageItem::PathText))
02550                      {
02551                             QButtonGroup *InfoGroup = new QButtonGroup( this, "InfoGroup" );
02552                             InfoGroup->setFrameShape( QButtonGroup::NoFrame );
02553                             InfoGroup->setFrameShadow( QButtonGroup::Plain );
02554                             InfoGroup->setTitle("");
02555                             InfoGroup->setExclusive( true );
02556                             InfoGroup->setColumnLayout(0, Qt::Vertical );
02557                             InfoGroup->layout()->setSpacing( 0 );
02558                             InfoGroup->layout()->setMargin( 0 );
02559                             QGridLayout *InfoGroupLayout = new QGridLayout( InfoGroup->layout() );
02560                             InfoGroupLayout->setAlignment( Qt::AlignTop );
02561                             InfoGroupLayout->setSpacing( 2 );
02562                             InfoGroupLayout->setMargin( 0 );
02563                             QString txtC, txtC2;
02564                             QLabel *InfoT = new QLabel(InfoGroup, "ct");
02565                             QLabel *LinCT = new QLabel(InfoGroup, "lt");
02566                             QLabel *LinC = new QLabel(InfoGroup, "lc");
02567                             QLabel *ParCT = new QLabel(InfoGroup, "pt");
02568                             QLabel *ParC = new QLabel(InfoGroup, "pc");
02569                             QLabel *WordCT = new QLabel(InfoGroup, "wt");
02570                             QLabel *WordC = new QLabel(InfoGroup, "wc");
02571                             QLabel *CharCT = new QLabel(InfoGroup, "ct");
02572                             QLabel *CharC = new QLabel(InfoGroup, "cc");
02573                             QLabel *ColCT = new QLabel(InfoGroup, "ct");
02574                             QLabel *ColC = new QLabel(InfoGroup, "cc");
02575                             QLabel *PrintCT = new QLabel(InfoGroup, "nt"); // <a.l.e>
02576                             QLabel *PrintC = new QLabel(InfoGroup, "nc"); // </a.l.e>
02577                             if (currItem->itemType() == PageItem::ImageFrame)
02578                             {
02579                                    LinC->hide();
02580                                    LinCT->hide();
02581                                    if (currItem->PicAvail)
02582                                    {
02583                                           QFileInfo fi = QFileInfo(currItem->Pfile);
02584                                           InfoT->setText( tr("Picture"));
02585                                           InfoGroupLayout->addMultiCellWidget( InfoT, 0, 0, 0, 1, Qt::AlignHCenter );
02586                                           ParCT->setText( tr("File: "));
02587                                           InfoGroupLayout->addWidget( ParCT, 1, 0, Qt::AlignRight );
02588                                           ParC->setText(fi.fileName());
02589                                           InfoGroupLayout->addWidget( ParC, 1, 1 );
02590                                           WordCT->setText( tr("Original PPI: "));
02591                                           InfoGroupLayout->addWidget( WordCT, 2, 0, Qt::AlignRight );
02592                                           WordC->setText(txtC.setNum(qRound(currItem->pixm.imgInfo.xres))+" x "+txtC2.setNum(qRound(currItem->pixm.imgInfo.yres)));
02593                                           InfoGroupLayout->addWidget( WordC, 2, 1 );
02594                                           CharCT->setText( tr("Actual PPI: "));
02595                                           InfoGroupLayout->addWidget( CharCT, 3, 0, Qt::AlignRight );
02596                                           CharC->setText(txtC.setNum(qRound(72.0 / currItem->imageXScale()))+" x "+ txtC2.setNum(qRound(72.0 / currItem->imageYScale())));
02597                                           InfoGroupLayout->addWidget( CharC, 3, 1 );
02598                                           ColCT->setText( tr("Colorspace: "));
02599                                           InfoGroupLayout->addWidget( ColCT, 4, 0, Qt::AlignRight );
02600                                           QString cSpace;
02601                                           QString ext = fi.extension(false).lower();
02602                                           if (((ext == "pdf") || (ext == "eps") || (ext == "epsi") || (ext == "ps")) && (currItem->pixm.imgInfo.type != 7))
02603                                                  cSpace = tr("Unknown");
02604                                           else
02605                                           {
02606                                                  switch (currItem->pixm.imgInfo.colorspace)
02607                                                  {
02608                                                         case 0:
02609                                                                cSpace = tr("RGB");
02610                                                                break;
02611                                                         case 1:
02612                                                                cSpace = tr("CMYK");
02613                                                                break;
02614                                                         case 2:
02615                                                                cSpace = tr("Grayscale");
02616                                                                break;
02617                                                         case 3:
02618                                                                cSpace = tr("Duotone");
02619                                                                break;
02620                                                  }
02621                                           }
02622                                           ColC->setText(cSpace);
02623                                           InfoGroupLayout->addWidget( ColC, 4, 1 );
02624                                    }
02625                                    else
02626                                    {
02627                                           InfoT->setText( tr("Picture"));
02628                                           InfoGroupLayout->addMultiCellWidget( InfoT, 0, 0, 0, 1, Qt::AlignHCenter );
02629                                           ParCT->setText( tr("No Image Loaded"));
02630                                           InfoGroupLayout->addMultiCellWidget( ParCT, 1, 1, 0, 1, Qt::AlignHCenter );
02631                                           ParC->hide();
02632                                           WordCT->hide();
02633                                           WordC->hide();
02634                                           CharCT->hide();
02635                                           CharC->hide();
02636                                           ColCT->hide();
02637                                           ColC->hide();
02638                                    }
02639                             }
02640                             if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
02641                             {
02642                                    int Parag = 0;
02643                                    int Words = 0;
02644                                    int Chara = 0;
02645                                    int ParagN = 0;
02646                                    int WordsN = 0;
02647                                    int CharaN = 0;
02648                                    ColC->hide();
02649                                    ColCT->hide();
02650                                    if (currItem->itemType() == PageItem::TextFrame)
02651                                    {
02652                                           if ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0))
02653                                                  InfoT->setText( tr("Linked Text"));
02654                                           else
02655                                                  InfoT->setText( tr("Text Frame"));
02656                                    }
02657                                    else
02658                                           InfoT->setText( tr("Text on a Path"));
02659                                    InfoGroupLayout->addMultiCellWidget( InfoT, 0, 0, 0, 1, Qt::AlignCenter );
02660                                    WordAndPara(currItem, &Words, &Parag, &Chara, &WordsN, &ParagN, &CharaN);
02661                                    ParCT->setText( tr("Paragraphs: "));
02662                                    InfoGroupLayout->addWidget( ParCT, 1, 0, Qt::AlignRight );
02663                                    if (ParagN != 0)
02664                                           ParC->setText(txtC.setNum(Parag+ParagN)+" ("+txtC2.setNum(ParagN)+")");
02665                                    else
02666                                           ParC->setText(txtC.setNum(Parag));
02667                                    InfoGroupLayout->addWidget( ParC, 1, 1 );
02668                                    LinCT->setText( tr("Lines: "));
02669                                    InfoGroupLayout->addWidget( LinCT, 2, 0, Qt::AlignRight );
02670                                    LinC->setText(txtC.setNum(currItem->itemText.lines()));
02671                                    InfoGroupLayout->addWidget( LinC, 2, 1 );
02672                                    WordCT->setText( tr("Words: "));
02673                                    InfoGroupLayout->addWidget( WordCT, 3, 0, Qt::AlignRight );
02674                                    if (WordsN != 0)
02675                                           WordC->setText(txtC.setNum(Words+WordsN)+" ("+txtC2.setNum(WordsN)+")");
02676                                    else
02677                                           WordC->setText(txtC.setNum(Words));
02678                                    InfoGroupLayout->addWidget( WordC, 3, 1 );
02679                                    CharCT->setText( tr("Chars: "));
02680                                    InfoGroupLayout->addWidget( CharCT, 4, 0, Qt::AlignRight );
02681                                    if (CharaN != 0)
02682                                           CharC->setText(txtC.setNum(Chara+CharaN)+" ("+txtC2.setNum(CharaN)+")");
02683                                    else
02684                                           CharC->setText(txtC.setNum(Chara));
02685                                    InfoGroupLayout->addWidget( CharC, 4, 1 );
02686                             }
02687 
02688                             int row = InfoGroupLayout->numRows(); // <a.l.e>
02689 
02690                             PrintCT->setText( tr("Print: "));
02691                             InfoGroupLayout->addWidget( PrintCT, row, 0, Qt::AlignRight );
02692                             if (currItem->printEnabled())
02693                                    PrintC->setText( tr("Enabled"));
02694                             else
02695                                    PrintC->setText( tr("Disabled"));
02696                             InfoGroupLayout->addWidget( PrintC, row, 1 ); // </a.l.e>
02697 
02698                             pmen4->insertItem(InfoGroup);
02699                             if ((currItem->itemType() == PageItem::ImageFrame) && (currItem->pixm.imgInfo.exifDataValid))
02700                                    m_ScMW->scrActions["itemImageInfo"]->addTo(pmen4);
02701                             pmen->insertItem( tr("In&fo"), pmen4);
02702                      }
02703                      pmen->insertSeparator();
02704                      m_ScMW->scrActions["editUndoAction"]->addTo(pmen);
02705                      m_ScMW->scrActions["editRedoAction"]->addTo(pmen);
02706                      if (currItem->itemType() == PageItem::ImageFrame ||
02707                             currItem->itemType() == PageItem::TextFrame ||
02708                             currItem->itemType() == PageItem::PathText)
02709                      {
02710                             pmen->insertSeparator();
02711                             if (currItem->itemType() == PageItem::ImageFrame)
02712                             {
02713                                    m_ScMW->scrActions["fileImportImage"]->addTo(pmen);
02714                                    if (currItem->PicAvail)
02715                                    {
02716                                           if (!currItem->isTableItem)
02717                                                  m_ScMW->scrActions["itemAdjustFrameToImage"]->addTo(pmen);
02718                                           if (currItem->pixm.imgInfo.valid)
02719                                                  m_ScMW->scrActions["itemExtendedImageProperties"]->addTo(pmen);
02720                                           m_ScMW->scrActions["itemUpdateImage"]->addTo(pmen);
02721                                    }
02722                                    pmen->insertItem( tr("Preview Settings"), pmenResolution);
02723                                    m_ScMW->scrActions["itemImageIsVisible"]->addTo(pmenResolution);
02724                                    pmenResolution->insertSeparator();
02725                                    m_ScMW->scrActions["itemPreviewLow"]->addTo(pmenResolution);
02726                                    m_ScMW->scrActions["itemPreviewNormal"]->addTo(pmenResolution);
02727                                    m_ScMW->scrActions["itemPreviewFull"]->addTo(pmenResolution);
02728                                    if (currItem->PicAvail && currItem->isRaster)
02729                                    {
02730                                           m_ScMW->scrActions["styleImageEffects"]->addTo(pmen);
02731                                           m_ScMW->scrActions["editEditWithImageEditor"]->addTo(pmen);
02732                                    }
02733                             }
02734                             if (currItem->itemType() == PageItem::TextFrame)
02735                             {
02736                                    m_ScMW->scrActions["fileImportText"]->addTo(pmen);
02737                                    m_ScMW->scrActions["fileImportAppendText"]->addTo(pmen);
02738                                    m_ScMW->scrActions["toolsEditWithStoryEditor"]->addTo(pmen);
02739                                    m_ScMW->scrActions["insertSampleText"]->addTo(pmen);
02740                             }
02741                             if (currItem->itemType() == PageItem::PathText)
02742                                    m_ScMW->scrActions["toolsEditWithStoryEditor"]->addTo(pmen);
02743                      }
02744                      if (Doc->m_Selection->count() == 1)
02745                      {
02746                             pmen->insertSeparator();
02747                             m_ScMW->scrActions["itemAttributes"]->addTo(pmen);
02748                      }      
02749                      if (currItem->itemType() == PageItem::TextFrame)
02750                      {
02751                             if (Doc->currentPage()->pageName().isEmpty())
02752                             {
02753                                    m_ScMW->scrActions["itemPDFIsAnnotation"]->addTo(pmenPDF);
02754                                    m_ScMW->scrActions["itemPDFIsBookmark"]->addTo(pmenPDF);
02755                                    if (currItem->isAnnotation())
02756                                    {
02757                                           if ((currItem->annotation().Type() == 0) || (currItem->annotation().Type() == 1) || (currItem->annotation().Type() > 9))
02758                                                  m_ScMW->scrActions["itemPDFAnnotationProps"]->addTo(pmenPDF);
02759                                           else
02760                                                  m_ScMW->scrActions["itemPDFFieldProps"]->addTo(pmenPDF);
02761                                    }
02762                             }
02763                             pmen->insertItem( tr("&PDF Options"), pmenPDF);
02764                      }
02765                      pmen->insertSeparator();
02766                      m_ScMW->scrActions["itemLock"]->addTo(pmen);
02767                      m_ScMW->scrActions["itemLockSize"]->addTo(pmen);
02768                      if (!currItem->isSingleSel)
02769                      {
02770                             m_ScMW->scrActions["itemSendToScrapbook"]->addTo(pmen);
02771                             m_ScMW->scrActions["itemSendToPattern"]->addTo(pmen);
02772                             if (Doc->layerCount() > 1)
02773                             {
02774                                    QMap<int,int> layerMap;
02775                                    for (QValueList<Layer>::iterator it = Doc->Layers.begin(); it != Doc->Layers.end(); ++it)
02776                                           layerMap.insert((*it).Level, (*it).LNr);
02777                                    int i=layerMap.count()-1;
02778                                    while (i>=0)
02779                                    {
02780                                           if (Doc->layerLocked(layerMap[i]))
02781                                                  m_ScMW->scrLayersActions[QString::number(layerMap[i])]->setEnabled(false);
02782                                           else
02783                                                  m_ScMW->scrLayersActions[QString::number(layerMap[i])]->setEnabled(true);
02784                                           m_ScMW->scrLayersActions[QString::number(layerMap[i--])]->addTo(pmen3);
02785                                    }
02786 
02787                                    pmen->insertItem( tr("Send to La&yer"), pmen3);
02788                             }
02789                      }
02790                      if (Doc->m_Selection->count() > 1)
02791                      {
02792                             bool isGroup = true;
02793                             int firstElem = -1;
02794                             if (currItem->Groups.count() != 0)
02795                                    firstElem = currItem->Groups.top();
02796                             for (uint bx = 0; bx < Doc->m_Selection->count(); ++bx)
02797                             {
02798                                    if (Doc->m_Selection->itemAt(bx)->Groups.count() != 0)
02799                                    {
02800                                           if (Doc->m_Selection->itemAt(bx)->Groups.top() != firstElem)
02801                                                  isGroup = false;
02802                                    }
02803                                    else
02804                                           isGroup = false;
02805                             }
02806                             if (!isGroup)
02807                                    m_ScMW->scrActions["itemGroup"]->addTo(pmen);
02808                      }
02809                      if (currItem->Groups.count() != 0)
02810                             m_ScMW->scrActions["itemUngroup"]->addTo(pmen);
02811                      if (!currItem->locked())
02812                      {
02813                             if ((!currItem->isTableItem) && (!currItem->isSingleSel))
02814                             {
02815                                    pmen->insertItem( tr("Le&vel"), pmenLevel);
02816                                    m_ScMW->scrActions["itemRaiseToTop"]->addTo(pmenLevel);
02817                                    m_ScMW->scrActions["itemRaise"]->addTo(pmenLevel);
02818                                    m_ScMW->scrActions["itemLower"]->addTo(pmenLevel);
02819                                    m_ScMW->scrActions["itemLowerToBottom"]->addTo(pmenLevel);
02820                             }
02821                      }
02822                      if (Doc->appMode != modeEdit && (Doc->m_Selection->itemsAreSameType() || currItem->isSingleSel)) //Create convertTo Menu
02823                      {
02824                             bool insertConvertToMenu=false;
02825                             if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
02826                             {
02827                                    insertConvertToMenu=true;
02828                                    if (currItem->itemType() == PageItem::PathText)
02829                                           m_ScMW->scrActions["itemConvertToOutlines"]->addTo(pmen2);
02830                                    else
02831                                    {
02832                                           if (currItem->isTableItem)
02833                                           {
02834                                                  m_ScMW->scrActions["itemConvertToImageFrame"]->setEnabled(true);
02835                                                  m_ScMW->scrActions["itemConvertToImageFrame"]->addTo(pmen2);
02836                                           }
02837                                           if (!currItem->isTableItem)
02838                                           {
02839                                                  if ((currItem->prevInChain() == 0) && (currItem->nextInChain() == 0))
02840                                                         m_ScMW->scrActions["itemConvertToImageFrame"]->addTo(pmen2);
02841                                                  m_ScMW->scrActions["itemConvertToOutlines"]->addTo(pmen2);
02842                                                  if ((currItem->prevInChain() == 0) && (currItem->nextInChain() == 0))
02843                                                         m_ScMW->scrActions["itemConvertToPolygon"]->addTo(pmen2);
02844                                           }
02845                                    }
02846                             }
02847                             if (currItem->itemType() == PageItem::ImageFrame)
02848                             {
02849                                    insertConvertToMenu=true;
02850                                    m_ScMW->scrActions["itemConvertToTextFrame"]->setEnabled(true);
02851                                    m_ScMW->scrActions["itemConvertToTextFrame"]->addTo(pmen2);
02852                                    if (!currItem->isTableItem)
02853                                           m_ScMW->scrActions["itemConvertToPolygon"]->addTo(pmen2);
02854                             }
02855                             if (currItem->itemType() == PageItem::Polygon)
02856                             {
02857                                    insertConvertToMenu=true;
02858                                    m_ScMW->scrActions["itemConvertToBezierCurve"]->addTo(pmen2);
02859                                    m_ScMW->scrActions["itemConvertToImageFrame"]->addTo(pmen2);
02860                                    m_ScMW->scrActions["itemConvertToTextFrame"]->addTo(pmen2);
02861                             }
02862                             bool insertedMenusEnabled = false;
02863                             for (uint pc = 0; pc < pmen2->count(); pc++)
02864                             {
02865                                    if (pmen2->isItemEnabled(pmen2->idAt(pc)))
02866                                           insertedMenusEnabled = true;
02867                             }
02868                             if ((insertConvertToMenu) && (insertedMenusEnabled))
02869                                    pmen->insertItem( tr("Conve&rt to"), pmen2);
02870                      }
02871                      pmen->insertSeparator();
02872                      if (!currItem->locked() && !(currItem->isSingleSel))
02873                             m_ScMW->scrActions["editCut"]->addTo(pmen);
02874                      if (!(currItem->isSingleSel))
02875                             m_ScMW->scrActions["editCopy"]->addTo(pmen);
02876                      if ((Doc->appMode == modeEdit) && (m_ScMW->Buffer2.startsWith("<SCRIBUSTEXT")) && (currItem->itemType() == PageItem::TextFrame))
02877                             m_ScMW->scrActions["editPaste"]->addTo(pmen);
02878                      if (!currItem->locked() && (Doc->appMode != modeEdit) && (!(currItem->isSingleSel)))
02879                             pmen->insertItem( tr("&Delete"), Doc, SLOT(itemSelection_DeleteItem()));
02880                      if ((currItem->itemType() == PageItem::ImageFrame) || (currItem->itemType() == PageItem::TextFrame))
02881                      {
02882                             if (currItem->itemType() == PageItem::ImageFrame)
02883                             {
02884                                    if (currItem->PicAvail)
02885                                           m_ScMW->scrActions["editCopyContents"]->addTo(pmenEditContents);
02886                                    if (m_ScMW->contentsBuffer.sourceType==PageItem::ImageFrame)
02887                                    {
02888                                           m_ScMW->scrActions["editPasteContents"]->addTo(pmenEditContents);
02889                                           m_ScMW->scrActions["editPasteContentsAbs"]->addTo(pmenEditContents);
02890                                    }
02891                                    if (currItem->PicAvail)
02892                                           m_ScMW->scrActions["editClearContents"]->addTo(pmenEditContents);
02893                                    if ((currItem->PicAvail) || (m_ScMW->contentsBuffer.sourceType==PageItem::ImageFrame))
02894                                           pmen->insertItem( tr("Contents"), pmenEditContents);
02895                             }
02896                             else
02897                             {
02898                                    if (currItem->itemText.lines() != 0)
02899                                    {
02900                                           m_ScMW->scrActions["editClearContents"]->addTo(pmenEditContents);
02901                                           pmen->insertItem( tr("Contents"), pmenEditContents);
02902                                    }
02903                             }
02904                      }
02905                      pmen->insertSeparator();
02906                      m_ScMW->scrActions["toolsProperties"]->addTo(pmen);
02907 
02908                      pmen->exec(QCursor::pos());
02909                      setGlobalUndoMode();
02910                      delete pmen;
02911                      delete pmen2;
02912                      delete pmen3;
02913                      delete pmen4;
02914                      delete pmenEditContents;
02915                      delete pmenLevel;
02916                      delete pmenPDF;
02917                      delete pmenResolution;
02918                      pmen=NULL;
02919                      pmen2=NULL;
02920                      pmen3=NULL;
02921                      pmen4=NULL;
02922                      pmenEditContents=NULL;
02923                      pmenLevel=NULL;
02924                      pmenPDF=NULL;
02925                      pmenResolution=NULL;
02926               }
02927               if ((Doc->appMode == modeLinkFrames) || (Doc->appMode == modeUnlinkFrames))
02928               {
02929                      updateContents();
02930                      if (Doc->ElemToLink != 0)
02931                             return;
02932                      else
02933                      {
02934                             Doc->appMode = modeNormal;
02935                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
02936                             emit PaintingDone();
02937                             return;
02938                      }
02939               }
02940               if (inItemCreation)
02941               {
02942                      currItem = Doc->m_Selection->itemAt(0);
02943                      double itemX = 0.0;
02944                      double itemY = 0.0;
02945                      if (Doc->appMode == modeDrawLine)
02946                      {
02947                             QPainter p;
02948                             p.begin(viewport());
02949                             Transform(currItem, &p);
02950                             QPoint np = p.xFormDev(m->pos());
02951                             p.end();
02952                             np += QPoint(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
02953                             np = Doc->ApplyGrid(np);
02954                             itemX = sqrt(pow(np.x(),2.0)+pow(np.y(),2.0));
02955                             itemY = 1.0;
02956                      }
02957                      else if (Doc->appMode == modeDrawRegularPolygon)
02958                      {
02959                             FPoint np1(translateToDoc(m->x(), m->y()));
02960                             np1 = Doc->ApplyGridF(np1);
02961                             itemX = fabs(np1.x() - currItem->xPos());
02962                             itemY = fabs(np1.y() - currItem->yPos());
02963                      }
02964                      else
02965                      {
02966                             itemX = fabs(currItem->width());
02967                             itemY = fabs(currItem->height());
02968                      }
02969                      if ((!moveTimerElapsed()) || ((itemX < 2.0) && (itemY < 2.0)) || ((Doc->appMode == modeDrawLine) && (itemX < 2.0)))
02970                      {
02971                             int lmode = 0;
02972                             if (Doc->appMode == modeDrawLine)
02973                                    lmode = 1;
02974                             PrefsContext* sizes = PrefsManager::instance()->prefsFile->getContext("ObjectSize");
02975                             double xSize, ySize;
02976                             int originPoint;
02977                             if (lmode == 0)
02978                             {
02979                                    xSize = sizes->getDouble("defWidth", 100.0);
02980                                    ySize = sizes->getDouble("defHeight", 100.0);
02981                                    originPoint = sizes->getInt("Origin", 0);
02982                             }
02983                             else
02984                             {
02985                                    xSize = sizes->getDouble("defLength", 100.0);
02986                                    ySize = sizes->getDouble("defAngle", 0.0);
02987                                    originPoint = sizes->getInt("OriginL", 0);
02988                             }
02989                             bool doRemember = sizes->getBool("Remember", true);
02990                             bool doCreate = false;
02991                             if (m->state() & (ShiftButton | ControlButton))
02992                                    doCreate = true;
02993                             else
02994                             {
02995                                    OneClick *dia = new OneClick(this, tr("Enter Object Size"), Doc->unitIndex(), xSize, ySize, doRemember, originPoint, lmode);
02996                                    if (dia->exec())
02997                                    {
02998                                           doRemember = dia->checkRemember->isChecked();
02999                                           if (lmode == 0)
03000                                           {
03001                                                  xSize = dia->spinWidth->value() / unitGetRatioFromIndex(Doc->unitIndex());
03002                                                  ySize = dia->spinHeight->value() / unitGetRatioFromIndex(Doc->unitIndex());
03003                                                  originPoint = dia->RotationGroup->selectedId();
03004                                                  if (doRemember)
03005                                                  {
03006                                                         sizes->set("defWidth", xSize);
03007                                                         sizes->set("defHeight", ySize);
03008                                                         sizes->set("Origin", originPoint);
03009                                                  }
03010                                           }
03011                                           else
03012                                           {
03013                                                  xSize = dia->spinWidth->value() / unitGetRatioFromIndex(Doc->unitIndex());
03014                                                  ySize = dia->spinHeight->value();
03015                                                  originPoint = dia->RotationGroup->selectedId();
03016                                                  if (doRemember)
03017                                                  {
03018                                                         sizes->set("defLength", xSize);
03019                                                         sizes->set("defAngle", ySize);
03020                                                         sizes->set("OriginL", originPoint);
03021                                                  }
03022                                           }
03023                                           sizes->set("Remember", doRemember);
03024                                           doCreate = true;
03025                                    }
03026                                    else
03027                                    {
03028                                           Deselect(false);
03029                                           Doc->Items->remove(currItem->ItemNr);
03030                                    }
03031                                    delete dia;
03032                             }
03033                             if (doCreate)
03034                             {
03035                                    bool oldSnap = Doc->SnapGuides;
03036                                    Doc->SnapGuides = false;
03037                                    if (Doc->appMode == modeDrawLine)
03038                                    {
03039                                           currItem->setWidthHeight(xSize, 1);
03040                                           currItem->setRotation(-ySize);
03041                                           currItem->Sizing = false;
03042                                           currItem->updateClip();
03043                                    }
03044                                    else if (Doc->appMode == modeDrawRegularPolygon)
03045                                    {
03046                                           currItem->setWidthHeight(xSize, ySize);
03047                                           FPointArray cli = RegularPolygonF(currItem->width(), currItem->height(), Doc->toolSettings.polyC, Doc->toolSettings.polyS, Doc->toolSettings.polyF, Doc->toolSettings.polyR);
03048                                           FPoint np(cli.point(0));
03049                                           currItem->PoLine.resize(2);
03050                                           currItem->PoLine.setPoint(0, np);
03051                                           currItem->PoLine.setPoint(1, np);
03052                                           for (uint ax = 1; ax < cli.size(); ++ax)
03053                                           {
03054                                                  np = FPoint(cli.point(ax));
03055                                                  currItem->PoLine.putPoints(currItem->PoLine.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
03056                                           }
03057                                           np = FPoint(cli.point(0));
03058                                           currItem->PoLine.putPoints(currItem->PoLine.size(), 2, np.x(), np.y(), np.x(), np.y());
03059                                           FPoint tp2(getMinClipF(&currItem->PoLine));
03060                                           if ((tp2.x() > -1) || (tp2.y() > -1))
03061                                                  Doc->SizeItem(currItem->width() - tp2.x(), currItem->height() - tp2.y(), currItem->ItemNr, false, false, false);
03062                                           FPoint tp(getMaxClipF(&currItem->PoLine));
03063                                           Doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
03064 //                                        currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
03065                                           Doc->AdjustItemSize(currItem);
03066                                    }
03067                                    else
03068                                    {
03069                                           Doc->SizeItem(xSize, ySize, currItem->ItemNr, false, false, false);
03070                                           currItem->updateClip();
03071                                    }
03072                                    currItem->ContourLine = currItem->PoLine.copy();
03073                                    switch (originPoint)
03074                                    {
03075                                           case 0:
03076                                                  break;
03077                                           case 1:
03078                                                  if (lmode == 0)
03079                                                         Doc->MoveItem(-currItem->width(), 0.0, currItem, false);
03080                                                  else
03081                                                         Doc->MoveRotated(currItem, FPoint(-currItem->width() / 2.0, 0.0), false);
03082                                                  break;
03083                                           case 2:
03084                                                  if (lmode == 0)
03085                                                         Doc->MoveItem(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem, false);
03086                                                  else
03087                                                         Doc->MoveRotated(currItem, FPoint(-currItem->width(), 0.0), false);
03088                                                  break;
03089                                           case 3:
03090                                                  Doc->MoveItem(0.0, -currItem->height(), currItem, false);
03091                                                  break;
03092                                           case 4:
03093                                                  Doc->MoveItem(-currItem->width(), -currItem->height(), currItem, false);
03094                                                  break;
03095                                    }
03096                                    Doc->setRedrawBounding(currItem);
03097                                    currItem->OwnPage = Doc->OnPage(currItem);
03098                                    currItem->OldB2 = currItem->width();
03099                                    currItem->OldH2 = currItem->height();
03100                                    currItem->Sizing = false;
03101                                    Doc->SnapGuides = oldSnap;
03102                                    if (!Prefs->stickyTools)
03103                                    {
03104                                           Doc->SubMode = -1;
03105                                           Doc->appMode = modeNormal;
03106                                           emit PaintingDone();
03107                                    }
03108                                    else
03109                                    {
03110                                           if ((inItemCreation) && (Doc->appMode == modeNormal))
03111                                           {
03112                                                  currItem = Doc->m_Selection->itemAt(0);
03113                                                  if (currItem->asTextFrame())
03114                                                         Doc->appMode = modeDrawText;
03115                                                  else if (currItem->asImageFrame())
03116                                                         Doc->appMode = modeDrawPicture;
03117                                                  else if (Doc->SubMode != -1)
03118                                                         Doc->appMode = modeDrawShapes;
03119                                           }
03120                                           emit Amode(Doc->appMode);
03121                                    }
03122                                    emit DocChanged();
03123                             }
03124                             else
03125                             {
03126                                    Doc->SubMode = -1;
03127                                    Doc->appMode = modeNormal;
03128                                    emit PaintingDone();
03129                                    emit HaveSel(-1);
03130                             }
03131                             inItemCreation = false;
03132                             updateContents();
03133                             Doc->DragP = false;
03134                             Doc->leaveDrag = false;
03135                             operItemMoving = false;
03136                             operItemResizing = false;
03137                             MidButt = false;
03138                             shiftSelItems = false;
03139                             m_SnapCounter = 0;
03140                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
03141                      }
03142               }
03143               if ((Doc->appMode == modeDrawLine) && (inItemCreation))
03144               {
03145                      currItem = Doc->m_Selection->itemAt(0);
03146                      QPainter p;
03147                      p.begin(viewport());
03148                      Transform(currItem, &p);
03149                      QPoint np = p.xFormDev(m->pos());
03150                      p.end();
03151                      np += QPoint(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
03152                      np = Doc->ApplyGrid(np);
03153                      double newRot=xy2Deg(np.x(), np.y());
03154                      //Constrain rotation angle, when the mouse is released from drawing a line
03155                      if (m->state() & ControlButton)
03156                             newRot=constrainAngle(newRot, Doc->toolSettings.constrain);
03157                      currItem->setRotation(newRot);
03158                      currItem->setWidthHeight(sqrt(pow(np.x(),2.0)+pow(np.y(),2.0)), 1.0);
03159                      currItem->Sizing = false;
03160                      currItem->updateClip();
03161                      Doc->setRedrawBounding(currItem);
03162                      currItem->OwnPage = Doc->OnPage(currItem);
03163                      updateContents();
03164               }
03165               if ((Doc->appMode == modeDrawRegularPolygon) && (inItemCreation))
03166               {
03167                      currItem = Doc->m_Selection->itemAt(0);
03168                      FPoint np1(translateToDoc(m->x(), m->y()));
03169                      np1 = Doc->ApplyGridF(np1);
03170                      double w = np1.x() - currItem->xPos();
03171                      double h = np1.y()- currItem->yPos();
03172                      currItem->setWidthHeight(fabs(w), fabs(h));
03173                      if (w < 0.0)
03174                             currItem->setXPos(currItem->xPos() - fabs(w), true);
03175                      if (h < 0.0)
03176                             currItem->setYPos(currItem->yPos() - fabs(h), true);
03177                      FPointArray cli = RegularPolygonF(currItem->width(), currItem->height(), Doc->toolSettings.polyC, Doc->toolSettings.polyS, Doc->toolSettings.polyF, Doc->toolSettings.polyR);
03178                      FPoint np(cli.point(0));
03179                      currItem->PoLine.resize(2);
03180                      currItem->PoLine.setPoint(0, np);
03181                      currItem->PoLine.setPoint(1, np);
03182                      for (uint ax = 1; ax < cli.size(); ++ax)
03183                      {
03184                             np = FPoint(cli.point(ax));
03185                             currItem->PoLine.putPoints(currItem->PoLine.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
03186                      }
03187                      np = FPoint(cli.point(0));
03188                      currItem->PoLine.putPoints(currItem->PoLine.size(), 2, np.x(), np.y(), np.x(), np.y());
03189                      FPoint tp2(getMinClipF(&currItem->PoLine));
03190                      if ((tp2.x() > -1) || (tp2.y() > -1))
03191                      {
03192                             Doc->SizeItem(currItem->width() - tp2.x(), currItem->height() - tp2.y(), currItem->ItemNr, false, false, false);
03193                      }
03194                      FPoint tp(getMaxClipF(&currItem->PoLine));
03195                      Doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
03196 //                   currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
03197                      Doc->AdjustItemSize(currItem);
03198                      currItem->ContourLine = currItem->PoLine.copy();
03199                      Doc->setRedrawBounding(currItem);
03200                      currItem->OwnPage = Doc->OnPage(currItem);
03201                      currItem->OldB2 = currItem->width();
03202                      currItem->OldH2 = currItem->height();
03203                      updateContents();
03204               }
03205               if (moveTimerElapsed() && (GetItem(&currItem)))
03206               {
03207                      if (Doc->m_Selection->isMultipleSelection())
03208                      {
03209                             if (operItemResizing)
03210                             {
03211                                    double gx, gy, gh, gw, nx, ny, scx, scy;
03212                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
03213                                    double sc = Scale;
03214                                    scx = sc;
03215                                    scy = sc;
03216                                    QPoint np2;
03217                                    double newXF = translateToDoc(m->x(), m->y()).x();
03218                                    double newYF = translateToDoc(m->x(), m->y()).y();
03219                                    if (m->state() & ControlButton)
03220                                           np2 = QPoint(qRound(newXF), qRound(gy+(gh * ((newXF-gx) / gw))));
03221                                    else
03222                                           np2 = QPoint(qRound(newXF), qRound(newYF));
03223                                    nx = np2.x();
03224                                    ny = np2.y();
03225                                    if (!Doc->ApplyGuides(&nx, &ny))
03226                                    {
03227                                           np2 = Doc->ApplyGrid(np2);
03228                                           nx = np2.x();
03229                                           ny = np2.y();
03230                                    }
03231                                    switch (frameResizeHandle)
03232                                    {
03233                                           case 1:
03234                                                  scy = fabs(ny-gy) / gh;
03235                                                  scx = fabs(nx-gx) / gw;
03236                                                  break;
03237                                           case 2:
03238                                                  scx = fabs(nx-(gx+gw)) / gw;
03239                                                  scy = fabs(ny-(gy+gh)) / gh;
03240                                                  break;
03241                                           case 3:
03242                                                  scx = fabs(nx-gx) / gw;
03243                                                  scy = fabs(ny-(gy+gh)) / gh;
03244                                                  break;
03245                                           case 4:
03246                                                  scx = fabs(nx-(gx+gw)) / gw;
03247                                                  scy = fabs(ny-gy) / gh;
03248                                                  break;
03249                                           case 5:
03250                                                  scx = 1.0;
03251                                                  scy = fabs(ny-gy) / gh;
03252                                                  break;
03253                                           case 6:
03254                                                  scx = fabs(nx-gx) / gw;
03255                                                  scy = 1.0;
03256                                                  break;
03257                                           case 7:
03258                                                  scx = fabs(nx-(gx+gw)) / gw;
03259                                                  scy = 1.0;
03260                                                  break;
03261                                           case 8:
03262                                                  scx = 1.0;
03263                                                  scy = fabs(ny-(gy+gh)) / gh;
03264                                                  break;
03265                                    }
03266                                    RotMode = Doc->RotMode;
03267                                    Doc->RotMode = 0;
03268                                    //CB #3012 only scale text in a group if alt is pressed
03269                                    if ((currItem->itemType() == PageItem::TextFrame) && (m->state() & AltButton))
03270                                           scaleGroup(scx, scy, true);
03271                                    else
03272                                           scaleGroup(scx, scy, false);
03273                                    if ((frameResizeHandle == 3) || (frameResizeHandle == 8))
03274                                           moveGroup(0, ny-gy);
03275                                    if (frameResizeHandle == 2)
03276                                           moveGroup(nx-gx, ny-gy);
03277                                    if ((frameResizeHandle == 7) || (frameResizeHandle == 4))
03278                                           moveGroup(nx-gx, 0);
03279                                    Doc->RotMode = RotMode;
03280                                    evSpon = false;
03281                                    updateContents();
03282                                    emit DocChanged();
03283                             }
03284                      }
03285                      else
03286                      {
03287                             //Where a single frame resize stops when the mouse buttno is released
03288                             //FIXME: reduce code!
03289                             if (currItem->Sizing)
03290                             {
03291                                    FPoint npx;
03292                                    double nx = translateToDoc(m->x(), m->y()).x();
03293                                    double ny = translateToDoc(m->x(), m->y()).y();
03294                                    if (Doc->SnapGuides)
03295                                    {
03296                                           Doc->ApplyGuides(&nx, &ny);
03297                                           npx = FPoint(nx, ny, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
03298                                    }
03299                                    else
03300                                    {
03301                                           npx = Doc->ApplyGridF(FPoint(nx, ny));
03302                                           npx = FPoint(npx.x(), npx.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
03303                                    }
03304                                    if ((frameResizeHandle == 1) && !(currItem->asLine()) && (Doc->SnapGuides))
03305                                           Doc->SizeItem(npx.x(), npx.y(), currItem->ItemNr);
03306                                    bool sav = Doc->SnapGuides;
03307                                    Doc->SnapGuides = false;
03308                                    if (UndoManager::undoEnabled())
03309                                    {
03310                                           undoManager->beginTransaction(currItem->getUName(), currItem->getUPixmap(),
03311                                                  Um::Resize, QString(Um::ResizeFromTo).arg(currItem->width()).arg(currItem->height()).arg(currItem->width() - npx.x()).arg(currItem->height() - npx.y()), Um::IResize);
03312                                    }
03313                                    switch (frameResizeHandle)
03314                                    {
03315                                    case 1:
03316                                           if (!currItem->asLine())
03317                                           {
03318                                                  if (currItem->isTableItem)
03319                                                  {
03320                                                         double dist;
03321                                                         if (currItem->LeftLink != 0)
03322                                                                dist = npx.y() - currItem->LeftLink->height();
03323                                                         else if (currItem->RightLink != 0)
03324                                                                dist = npx.y() - currItem->RightLink->height();
03325                                                         else
03326                                                                dist = npx.y() - currItem->height();
03327                                                         PageItem* bb2;
03328                                                         PageItem* bb = currItem;
03329                                                         while (bb->LeftLink != 0)
03330                                                         {
03331                                                                bb = bb->LeftLink;
03332                                                         }
03333                                                         while (bb->RightLink != 0)
03334                                                         {
03335                                                                bb2 = bb;
03336                                                                while (bb2->BottomLink != 0)
03337                                                                {
03338                                                                       Doc->MoveRotated(bb2->BottomLink, FPoint(0, dist));
03339                                                                       bb2 = bb2->BottomLink;
03340                                                                }
03341                                                                if (bb != currItem)
03342                                                                       Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb->ItemNr);
03343                                                                bb = bb->RightLink;
03344                                                         }
03345                                                         bb2 = bb;
03346                                                         while (bb2->BottomLink != 0)
03347                                                         {
03348                                                                Doc->MoveRotated(bb2->BottomLink, FPoint(0, dist));
03349                                                                bb2 = bb2->BottomLink;
03350                                                         }
03351                                                         if (bb != currItem)
03352                                                                Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb->ItemNr);
03353                                                         bb = currItem;
03354                                                         if (currItem->TopLink != 0)
03355                                                                dist = npx.x() - currItem->TopLink->width();
03356                                                         else if (currItem->BottomLink != 0)
03357                                                                dist = npx.x() - currItem->BottomLink->width();
03358                                                         else
03359                                                                dist = npx.x() - currItem->width();
03360                                                         while (bb->TopLink != 0)
03361                                                         {
03362                                                                bb = bb->TopLink;
03363                                                         }
03364                                                         while (bb->BottomLink != 0)
03365                                                         {
03366                                                                bb2 = bb;
03367                                                                while (bb2->RightLink != 0)
03368                                                                {
03369                                                                       Doc->MoveRotated(bb2->RightLink, FPoint(dist, 0));
03370                                                                       bb2 = bb2->RightLink;
03371                                                                }
03372                                                                if (bb != currItem)
03373                                                                       Doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb->ItemNr);
03374                                                                bb = bb->BottomLink;
03375                                                         }
03376                                                         bb2 = bb;
03377                                                         while (bb2->RightLink != 0)
03378                                                         {
03379                                                                Doc->MoveRotated(bb2->RightLink, FPoint(dist, 0));
03380                                                                bb2 = bb2->RightLink;
03381                                                         }
03382                                                         if (bb != currItem)
03383                                                                Doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb->ItemNr);
03384                                                  }
03385                                                  //<<Swap location if width/height is <0
03386                                                  if (currItem->width()<0)
03387                                                  {
03388                                                         currItem->setWidth(-currItem->width());
03389                                                         currItem->setXPos(currItem->xPos()-currItem->width());
03390                                                  }
03391                                                  if (currItem->height()<0)
03392                                                  {
03393                                                         currItem->setHeight(-currItem->height());
03394                                                         currItem->setYPos(currItem->yPos()-currItem->height());
03395                                                  }
03396                                                  //>>
03397                                                  if (currItem->imageFlippedH())
03398                                                         currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03399                                                  if (currItem->imageFlippedV())
03400                                                         currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
03401                                           }
03402                                           else
03403                                           {
03404                                                  if (sav)
03405                                                  {
03406                                                         double nx = translateToDoc(m->x(), m->y()).x();
03407                                                         double ny = translateToDoc(m->x(), m->y()).y();
03408                                                         if (Doc->useRaster)
03409                                                         {
03410                                                                FPoint ra(Doc->ApplyGridF(FPoint(nx, ny)));
03411                                                                nx = ra.x();
03412                                                                ny = ra.y();
03413                                                         }
03414                                                         Doc->SnapGuides = sav;
03415                                                         Doc->ApplyGuides(&nx, &ny);
03416                                                         Doc->SnapGuides = false;
03417                                                         double r = atan2(ny - currItem->yPos(), nx - currItem->xPos())*(180.0/M_PI);
03418                                                         Doc->RotateItem(r, currItem->ItemNr);
03419                                                         double w = sqrt(pow(nx - currItem->xPos(), 2) + pow(ny - currItem->yPos(),2));
03420                                                         Doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
03421                                                  }
03422                                           }
03423                                           currItem->Sizing = false;
03424                                           break;
03425                                    case 2:
03426                                           if (!currItem->asLine())
03427                                           {
03428                                                  if (currItem->isTableItem)
03429                                                  {
03430                                                         PageItem* bb2;
03431                                                         PageItem* bb = currItem;
03432                                                         while (bb->TopLink != 0)
03433                                                         {
03434                                                                bb = bb->TopLink;
03435                                                         }
03436                                                         while (bb->BottomLink != 0)
03437                                                         {
03438                                                                bb2 = bb;
03439                                                                while (bb2->LeftLink != 0)
03440                                                                {
03441                                                                       Doc->MoveRotated(bb2->LeftLink, FPoint(npx.x(), 0));
03442                                                                       bb2 = bb2->LeftLink;
03443                                                                }
03444                                                                Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), bb->ItemNr);
03445                                                                bb = bb->BottomLink;
03446                                                         }
03447                                                         bb2 = bb;
03448                                                         while (bb2->LeftLink != 0)
03449                                                         {
03450                                                                Doc->MoveRotated(bb2->LeftLink, FPoint(npx.x(), 0));
03451                                                                bb2 = bb2->LeftLink;
03452                                                         }
03453                                                         Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), bb->ItemNr);
03454                                                         bb = currItem;
03455                                                         while (bb->LeftLink != 0)
03456                                                         {
03457                                                                bb = bb->LeftLink;
03458                                                         }
03459                                                         while (bb->RightLink != 0)
03460                                                         {
03461                                                                bb2 = bb;
03462                                                                while (bb2->TopLink != 0)
03463                                                                {
03464                                                                       Doc->MoveRotated(bb2->TopLink, FPoint(0, npx.y()));
03465                                                                       bb2 = bb2->TopLink;
03466                                                                }
03467                                                                Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), bb->ItemNr);
03468                                                                bb = bb->RightLink;
03469                                                         }
03470                                                         bb2 = bb;
03471                                                         while (bb2->TopLink != 0)
03472                                                         {
03473                                                                Doc->MoveRotated(bb2->TopLink, FPoint(0, npx.y()));
03474                                                                bb2 = bb2->TopLink;
03475                                                         }
03476                                                         Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), bb->ItemNr);
03477                                                  }
03478                                                  else
03479                                                         Doc->MoveSizeItem(npx, npx, currItem->ItemNr);
03480                                                         
03481                                                  //<<Swap location if width/height is <0
03482                                                  if (currItem->width()<0)
03483                                                  {
03484                                                         currItem->setWidth(-currItem->width());
03485                                                         currItem->setXPos(currItem->xPos()-currItem->width());
03486                                                  }
03487                                                  if (currItem->height()<0)
03488                                                  {
03489                                                         currItem->setHeight(-currItem->height());
03490                                                         currItem->setYPos(currItem->yPos()-currItem->height());
03491                                                  }
03492                                                  //>>
03493                                                         
03494                                                  currItem->Sizing = false;
03495                                                  if (!currItem->imageFlippedH())
03496                                                  {
03497                                                         currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03498                                                         updateContents(currItem->getRedrawBounding(Scale));
03499                                                  }
03500                                                  if (!currItem->imageFlippedV())
03501                                                  {
03502                                                         currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
03503                                                         updateContents(currItem->getRedrawBounding(Scale));
03504                                                  }
03505                                           }
03506                                           else
03507                                           {
03508                                                  if (sav)
03509                                                  {
03510                                                         double nx = translateToDoc(m->x(), m->y()).x();
03511                                                         double ny = translateToDoc(m->x(), m->y()).y();
03512                                                         if (Doc->useRaster)
03513                                                         {
03514                                                                FPoint ra(Doc->ApplyGridF(FPoint(nx, ny)));
03515                                                                nx = ra.x();
03516                                                                ny = ra.y();
03517                                                         }
03518                                                         Doc->SnapGuides = sav;
03519                                                         Doc->ApplyGuides(&nx, &ny);
03520                                                         Doc->SnapGuides = false;
03521                                                         QWMatrix ma;
03522                                                         ma.translate(currItem->xPos(), currItem->yPos());
03523                                                         ma.rotate(currItem->rotation());
03524                                                         double mx = ma.m11() * currItem->width() + ma.m21() * currItem->height() + ma.dx();
03525                                                         double my = ma.m22() * currItem->height() + ma.m12() * currItem->width() + ma.dy();
03526                                                         double r = atan2(my-ny,mx-nx)*(180.0/M_PI);
03527                                                         double w = sqrt(pow(mx-nx,2)+pow(my-ny,2));
03528                                                         Doc->MoveItem(nx - currItem->xPos(), ny - currItem->yPos(), currItem, true);
03529                                                         Doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
03530                                                         Doc->RotateItem(r, currItem->ItemNr);
03531                                                         currItem->Sizing = false;
03532                                                  }
03533                                           }
03534                                           break;
03535                                    case 3:
03536                                           if (currItem->isTableItem)
03537                                           {
03538                                                  double dist = npx.x() - currItem->width();
03539                                                  PageItem* bb2;
03540                                                  PageItem* bb = currItem;
03541                                                  while (bb->TopLink != 0)
03542                                                  {
03543                                                         bb = bb->TopLink;
03544                                                  }
03545                                                  while (bb->BottomLink != 0)
03546                                                  {
03547                                                         bb2 = bb;
03548                                                         while (bb2->RightLink != 0)
03549                                                         {
03550                                                                Doc->MoveRotated(bb2->RightLink, FPoint(dist, 0));
03551                                                                bb2 = bb2->RightLink;
03552                                                         }
03553                                                         Doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb->ItemNr);
03554                                                         bb = bb->BottomLink;
03555                                                  }
03556                                                  bb2 = bb;
03557                                                  while (bb2->RightLink != 0)
03558                                                  {
03559                                                         Doc->MoveRotated(bb2->RightLink, FPoint(dist, 0));
03560                                                         bb2 = bb2->RightLink;
03561                                                  }
03562                                                  Doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb->ItemNr);
03563                                                  bb = currItem;
03564                                                  while (bb->LeftLink != 0)
03565                                                  {
03566                                                         bb = bb->LeftLink;
03567                                                  }
03568                                                  while (bb->RightLink != 0)
03569                                                  {
03570                                                         bb2 = bb;
03571                                                         while (bb2->TopLink != 0)
03572                                                         {
03573                                                                Doc->MoveRotated(bb2->TopLink, FPoint(0, npx.y()));
03574                                                                bb2 = bb2->TopLink;
03575                                                         }
03576                                                         Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), bb->ItemNr);
03577                                                         bb = bb->RightLink;
03578                                                  }
03579                                                  bb2 = bb;
03580                                                  while (bb2->TopLink != 0)
03581                                                  {
03582                                                         Doc->MoveRotated(bb2->TopLink, FPoint(0, npx.y()));
03583                                                         bb2 = bb2->TopLink;
03584                                                  }
03585                                                  Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), bb->ItemNr);
03586                                           }
03587                                           else
03588                                                  Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(currItem->width() - npx.x(), npx.y()), currItem->ItemNr);
03589                                                  
03590                                           //<<Swap location if width/height is <0
03591                                           if (currItem->width()<0)
03592                                           {
03593                                                  currItem->setWidth(-currItem->width());
03594                                                  currItem->setXPos(currItem->xPos()-currItem->width());
03595                                           }
03596                                           if (currItem->height()<0)
03597                                           {
03598                                                  currItem->setHeight(-currItem->height());
03599                                                  currItem->setYPos(currItem->yPos()-currItem->height());
03600                                           }
03601                                           //>>
03602                                                  
03603                                           currItem->Sizing = false;
03604                                           if (currItem->imageFlippedH())
03605                                                  currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03606                                           if (!currItem->imageFlippedV())
03607                                                  currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
03608                                           break;
03609                                    case 4:
03610                                    
03611                                           if (currItem->isTableItem)
03612                                           {
03613                                                  double dist = npx.y() - currItem->height();
03614                                                  PageItem* bb2;
03615                                                  PageItem* bb = currItem;
03616                                                  while (bb->LeftLink != 0)
03617                                                  {
03618                                                         bb = bb->LeftLink;
03619                                                  }
03620                                                  while (bb->RightLink != 0)
03621                                                  {
03622                                                         bb2 = bb;
03623                                                         while (bb2->BottomLink != 0)
03624                                                         {
03625                                                                Doc->MoveRotated(bb2->BottomLink, FPoint(0, dist));
03626                                                                bb2 = bb2->BottomLink;
03627                                                         }
03628                                                         Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb->ItemNr);
03629                                                         bb = bb->RightLink;
03630                                                  }
03631                                                  bb2 = bb;
03632                                                  while (bb2->BottomLink != 0)
03633                                                  {
03634                                                         Doc->MoveRotated(bb2->BottomLink, FPoint(0, dist));
03635                                                         bb2 = bb2->BottomLink;
03636                                                  }
03637                                                  Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb->ItemNr);
03638                                                  bb = currItem;
03639                                                  while (bb->TopLink != 0)
03640                                                  {
03641                                                         bb = bb->TopLink;
03642                                                  }
03643                                                  while (bb->BottomLink != 0)
03644                                                  {
03645                                                         bb2 = bb;
03646                                                         while (bb2->LeftLink != 0)
03647                                                         {
03648                                                                Doc->MoveRotated(bb2->LeftLink, FPoint(npx.x(), 0));
03649                                                                bb2 = bb2->LeftLink;
03650                                                         }
03651                                                         Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), bb->ItemNr);
03652                                                         bb = bb->BottomLink;
03653                                                  }
03654                                                  bb2 = bb;
03655                                                  while (bb2->LeftLink != 0)
03656                                                  {
03657                                                         Doc->MoveRotated(bb2->LeftLink, FPoint(npx.x(), 0));
03658                                                         bb2 = bb2->LeftLink;
03659                                                  }
03660                                                  Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), bb->ItemNr);
03661                                           }
03662                                           else
03663                                                  Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), currItem->height() - npx.y()), currItem->ItemNr);
03664                                           
03665                                           //<<Swap location if width/height is <0
03666                                           if (currItem->width()<0)
03667                                           {
03668                                                  currItem->setWidth(-currItem->width());
03669                                                  currItem->setXPos(currItem->xPos()-currItem->width());
03670                                           }
03671                                           if (currItem->height()<0)
03672                                           {
03673                                                  currItem->setHeight(-currItem->height());
03674                                                  currItem->setYPos(currItem->yPos()-currItem->height());
03675                                           }
03676                                           //>>
03677                                                  
03678                                           currItem->Sizing = false;
03679                                           if (!currItem->imageFlippedH())
03680                                                  currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03681                                           if (currItem->imageFlippedV())
03682                                                  currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
03683                                           break;
03684                                    case 5:
03685                                           if (currItem->isTableItem)
03686                                           {
03687                                                  double dist = npx.y() - currItem->height();
03688                                                  PageItem* bb2;
03689                                                  PageItem* bb = currItem;
03690                                                  while (bb->LeftLink != 0)
03691                                                  {
03692                                                         bb = bb->LeftLink;
03693                                                  }
03694                                                  while (bb->RightLink != 0)
03695                                                  {
03696                                                         bb2 = bb;
03697                                                         while (bb2->BottomLink != 0)
03698                                                         {
03699                                                                Doc->MoveRotated(bb2->BottomLink, FPoint(0, dist));
03700                                                                bb2 = bb2->BottomLink;
03701                                                         }
03702                                                         Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb->ItemNr);
03703                                                         bb = bb->RightLink;
03704                                                  }
03705                                                  bb2 = bb;
03706                                                  while (bb2->BottomLink != 0)
03707                                                  {
03708                                                         Doc->MoveRotated(bb2->BottomLink, FPoint(0, dist));
03709                                                         bb2 = bb2->BottomLink;
03710                                                  }
03711                                                  Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb->ItemNr);
03712                                           }
03713                                           else
03714                                                  Doc->MoveSizeItem(FPoint(0, 0), FPoint(0, currItem->height() - npx.y()), currItem->ItemNr);
03715                                           if (currItem->imageFlippedV())
03716                                                  currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
03717                                           
03718                                           //<<Swap location if width/height is <0
03719                                           if (currItem->width()<0)
03720                                           {
03721                                                  currItem->setWidth(-currItem->width());
03722                                                  currItem->setXPos(currItem->xPos()-currItem->width());
03723                                           }
03724                                           if (currItem->height()<0)
03725                                           {
03726                                                  currItem->setHeight(-currItem->height());
03727                                                  currItem->setYPos(currItem->yPos()-currItem->height());
03728                                           }
03729                                           //>>
03730                                                  
03731                                           currItem->Sizing = false;
03732                                           break;
03733                                    case 6:
03734                                           if (currItem->isTableItem)
03735                                           {
03736                                                  double dist = npx.x() - currItem->width();
03737                                                  PageItem* bb2;
03738                                                  PageItem* bb = currItem;
03739                                                  while (bb->TopLink != 0)
03740                                                  {
03741                                                         bb = bb->TopLink;
03742                                                  }
03743                                                  while (bb->BottomLink != 0)
03744                                                  {
03745                                                         bb2 = bb;
03746                                                         while (bb2->RightLink != 0)
03747                                                         {
03748                                                                Doc->MoveRotated(bb2->RightLink, FPoint(dist, 0));
03749                                                                bb2 = bb2->RightLink;
03750                                                         }
03751                                                         Doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb->ItemNr);
03752                                                         bb = bb->BottomLink;
03753                                                  }
03754                                                  bb2 = bb;
03755                                                  while (bb2->RightLink != 0)
03756                                                  {
03757                                                         Doc->MoveRotated(bb2->RightLink, FPoint(dist, 0));
03758                                                         bb2 = bb2->RightLink;
03759                                                  }
03760                                                  Doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb->ItemNr);
03761                                           }
03762                                           else
03763                                                  Doc->MoveSizeItem(FPoint(0, 0), FPoint(currItem->width() - npx.x(), 0), currItem->ItemNr);
03764                                           if (currItem->imageFlippedH())
03765                                                  currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03766                                           
03767                                           //<<Swap location if width/height is <0
03768                                           if (currItem->width()<0)
03769                                           {
03770                                                  currItem->setWidth(-currItem->width());
03771                                                  currItem->setXPos(currItem->xPos()-currItem->width());
03772                                           }
03773                                           if (currItem->height()<0)
03774                                           {
03775                                                  currItem->setHeight(-currItem->height());
03776                                                  currItem->setYPos(currItem->yPos()-currItem->height());
03777                                           }
03778                                           //>>
03779                                           
03780                                           currItem->Sizing = false;
03781                                           break;
03782                                    case 7:
03783                                           if (currItem->isTableItem)
03784                                           {
03785                                                  PageItem* bb2;
03786                                                  PageItem* bb = currItem;
03787                                                  while (bb->TopLink != 0)
03788                                                  {
03789                                                         bb = bb->TopLink;
03790                                                  }
03791                                                  while (bb->BottomLink != 0)
03792                                                  {
03793                                                         bb2 = bb;
03794                                                         while (bb2->LeftLink != 0)
03795                                                         {
03796                                                                Doc->MoveRotated(bb2->LeftLink, FPoint(npx.x(), 0));
03797                                                                bb2 = bb2->LeftLink;
03798                                                         }
03799                                                         Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), bb->ItemNr);
03800                                                         bb = bb->BottomLink;
03801                                                  }
03802                                                  bb2 = bb;
03803                                                  while (bb2->LeftLink != 0)
03804                                                  {
03805                                                         Doc->MoveRotated(bb2->LeftLink, FPoint(npx.x(), 0));
03806                                                         bb2 = bb2->LeftLink;
03807                                                  }
03808                                                  Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), bb->ItemNr);
03809                                           }
03810                                           else
03811                                                  Doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), currItem->ItemNr);
03812                                           
03813                                           //<<Swap location if width/height is <0
03814                                           if (currItem->width()<0)
03815                                           {
03816                                                  currItem->setWidth(-currItem->width());
03817                                                  currItem->setXPos(currItem->xPos()-currItem->width());
03818                                           }
03819                                           if (currItem->height()<0)
03820                                           {
03821                                                  currItem->setHeight(-currItem->height());
03822                                                  currItem->setYPos(currItem->yPos()-currItem->height());
03823                                           }
03824                                           //>>
03825                                                  
03826                                           currItem->Sizing = false;
03827                                           if (!currItem->imageFlippedH())
03828                                                  currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03829                                           if (currItem->imageFlippedV())
03830                                                  currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
03831                                           break;
03832                                    case 8:
03833                                           if (currItem->isTableItem)
03834                                           {
03835                                                  PageItem* bb2;
03836                                                  PageItem* bb = currItem;
03837                                                  while (bb->LeftLink != 0)
03838                                                  {
03839                                                         bb = bb->LeftLink;
03840                                                  }
03841                                                  while (bb->RightLink != 0)
03842                                                  {
03843                                                         bb2 = bb;
03844                                                         while (bb2->TopLink != 0)
03845                                                         {
03846                                                                Doc->MoveRotated(bb2->TopLink, FPoint(0, npx.y()));
03847                                                                bb2 = bb2->TopLink;
03848                                                         }
03849                                                         Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), bb->ItemNr);
03850                                                         bb = bb->RightLink;
03851                                                  }
03852                                                  bb2 = bb;
03853                                                  while (bb2->TopLink != 0)
03854                                                  {
03855                                                         Doc->MoveRotated(bb2->TopLink, FPoint(0, npx.y()));
03856                                                         bb2 = bb2->TopLink;
03857                                                  }
03858                                                  Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), bb->ItemNr);
03859                                           }
03860                                           else
03861                                                  Doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), currItem->ItemNr);
03862                                                  
03863                                           //<<Swap location if width/height is <0
03864                                           if (currItem->width()<0)
03865                                           {
03866                                                  currItem->setWidth(-currItem->width());
03867                                                  currItem->setXPos(currItem->xPos()-currItem->width());
03868                                           }
03869                                           if (currItem->height()<0)
03870                                           {
03871                                                  currItem->setHeight(-currItem->height());
03872                                                  currItem->setYPos(currItem->yPos()-currItem->height());
03873                                           }
03874                                           //>>
03875                                                  
03876                                           currItem->Sizing = false;
03877                                           if (currItem->imageFlippedH())
03878                                                  currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
03879                                           if (!currItem->imageFlippedV())
03880                                                  currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
03881                                           break;
03882                                    }
03883 
03884                                    //TextFrame resize - Resize text with resize of frame
03885                                    //alt resize, free resize with text scaling
03886                                    //shift alt, square resize with text scaling
03887                                    //control alt, proportional resize with text scaling
03888                                    //if ((currItem->itemType() == PageItem::TextFrame) && (m->state() & ShiftButton) && (m->state() & ControlButton))
03889                                    //NOTE: this does not cover groups, strangely enough. Thats done in scaleGroup()
03890                                    if ((currItem->itemType() == PageItem::TextFrame) && (m->state() & AltButton))
03891                                    {
03892                                           double scx = currItem->width() / currItem->OldB2;
03893                                           double scy = currItem->height() / currItem->OldH2;
03894                                           scx = scx != scy ? scx / scy : 1.0;
03895                                           if (currItem->itemText.length() != 0)
03896                                           {
03897 //                                               currItem->setFontSize(QMAX(qRound(currItem->fontSize() * scy), 1));
03898 //                                               currItem->setLineSpacing(((currItem->fontSize() / 10.0)* static_cast<double>(Doc->typographicSettings.autoLineSpacing) / 100) + (currItem->fontSize() / 10.0));
03899 //                                               currItem->TxtScale = QMIN(QMAX(qRound(currItem->TxtScale * scx), 25), 400);
03900 /*                                               Doc->currTextScale = currItem->TxtScale;
03901                                                  Doc->CurrFontSize = currItem->fontSize();
03902                                                  Doc->CurrTextBase = currItem->TxtBase;
03903                                                  Doc->CurrTextShadowX = currItem->TxtShadowX;
03904                                                  Doc->CurrTextShadowY = currItem->TxtShadowY;
03905                                                  Doc->CurrTextOutline = currItem->TxtOutline;
03906                                                  Doc->CurrTextUnderPos = currItem->TxtUnderPos;
03907                                                  Doc->CurrTextUnderWidth = currItem->TxtUnderWidth;
03908                                                  Doc->CurrTextStrikePos = currItem->TxtStrikePos;
03909                                                  Doc->CurrTextStrikeWidth = currItem->TxtStrikeWidth;
03910                                                  emit ItemTextStrike(currItem->TxtStrikePos, currItem->TxtStrikeWidth);
03911                                                  emit ItemTextUnderline(currItem->TxtUnderPos, currItem->TxtUnderWidth);
03912                                                  emit ItemTextOutline(currItem->TxtOutline);
03913                                                  emit ItemTextShadow(currItem->TxtShadowX, currItem->TxtShadowY);
03914                                                  //emit ItemTextAttr(currItem->LineSp);
03915                                                  emit ItemTextCols(currItem->Cols, currItem->ColGap);
03916                                                  emit ItemTextSize(currItem->fontSize());
03917                                                  emit ItemTextSca(currItem->TxtScale);
03918                                                  emit ItemTextScaV(currItem->TxtScaleV);
03919                                                  emit ItemTextBase(currItem->TxtBase);
03920 */
03921 #ifndef NLS_PROTO
03922                                                  for (int aa = 0; aa < currItem->itemText.length(); ++aa)
03923                                                  {
03924                                                         currItem->itemText.item(aa)->setFontSize(QMAX(qRound(currItem->itemText.item(aa)->fontSize()*scy), 1));
03925                                                         currItem->itemText.item(aa)->setScaleH(QMAX(QMIN(qRound(currItem->itemText.item(aa)->scaleH()*scx), 4000), 100));
03926                                                  }
03927 #endif
03928                                           }
03929                                    }
03930                                    if (currItem->itemType() == PageItem::ImageFrame)
03931                                    {
03932                                           currItem->AdjustPictScale();
03933                                           /*Dont need this now adjustpictscale will emit for 1st selected item
03934                                           emit SetLocalValues(currItem->LocalScX, currItem->LocalScY, currItem->LocalX, currItem->LocalY );
03935                                           */
03936                                    }
03937                                    currItem->updateClip();
03938                                    emit ItemTextCols(currItem->Cols, currItem->ColGap);
03939                                    Doc->SnapGuides = sav;
03940                                    evSpon = false;
03941                                    updateContents();
03942                                    emit DocChanged();
03943                                    currItem->checkChanges();
03944                                    if (UndoManager::undoEnabled())
03945                                           undoManager->commit();
03946                             }
03947                             Doc->setRedrawBounding(currItem);
03948                             currItem->OwnPage = Doc->OnPage(currItem);
03949                      }
03950                      if (operItemMoving)
03951                      {
03952                             updatesOn(false);
03953                             evSpon = false;
03954                             if (Doc->m_Selection->isMultipleSelection())
03955                             {
03956                                    Doc->m_Selection->setGroupRect();
03957                                    double gx, gy, gh, gw;
03958                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
03959                                    double nx = gx;
03960                                    double ny = gy;
03961                                    if (!Doc->ApplyGuides(&nx, &ny))
03962                                    {
03963                                                  FPoint npx = Doc->ApplyGridF(FPoint(gx, gy));
03964                                                  FPoint npw = Doc->ApplyGridF(FPoint(gx+gw, gy+gh));
03965                                                  if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
03966                                                         nx = npw.x() - gw;
03967                                                  else
03968                                                         nx = npx.x();
03969                                                  if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
03970                                                         ny = npw.y() - gh;
03971                                                  else
03972                                                         ny = npx.y();
03973                                    }
03974                                    moveGroup(nx-gx, ny-gy, false);
03975                                    Doc->m_Selection->setGroupRect();
03976                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
03977                                    nx = gx+gw;
03978                                    ny = gy+gh;
03979                                    if (Doc->ApplyGuides(&nx, &ny))
03980                                           moveGroup(nx-(gx+gw), ny-(gy+gh), false);
03981                                    Doc->m_Selection->setGroupRect();
03982                             }
03983                             else
03984                             {
03985                                    currItem = Doc->m_Selection->itemAt(0);
03986 /*                                 if (!currItem->asLine())
03987                                    {
03988                                           if (fabs(currItem->width()) < 5)
03989                                                  currItem->setWidth(5.0);
03990                                           if (fabs(currItem->height()) < 5)
03991                                                  currItem->setHeight(5.0);
03992                                    } */
03993                                    if (Doc->useRaster)
03994                                    {
03995                                           double nx = currItem->xPos();
03996                                           double ny = currItem->yPos();
03997                                           if (!Doc->ApplyGuides(&nx, &ny))
03998                                           {
03999                                                  Doc->m_Selection->setGroupRect();
04000                                                  double gx, gy, gh, gw;
04001                                                  Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
04002                                                  FPoint npx = Doc->ApplyGridF(FPoint(gx, gy));
04003                                                  FPoint npw = Doc->ApplyGridF(FPoint(gx+gw, gy+gh));
04004                                                  if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
04005                                                         nx = npw.x() - gw;
04006                                                  else
04007                                                         nx = npx.x();
04008                                                  if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
04009                                                         ny = npw.y() - gh;
04010                                                  else
04011                                                         ny = npx.y();
04012                                           }
04013                                           Doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem);
04014                                    }
04015                                    else
04016                                           Doc->MoveItem(0, 0, currItem, false);
04017                             }
04018                             operItemMoving = false;
04019                             if (Doc->m_Selection->isMultipleSelection())
04020                             {
04021                                    double gx, gy, gh, gw;
04022                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
04023                                    FPoint maxSize(gx+gw+Doc->scratch.Right, gy+gh+Doc->scratch.Bottom);
04024                                    FPoint minSize(gx-Doc->scratch.Left, gy-Doc->scratch.Top);
04025                                    Doc->adjustCanvas(minSize, maxSize);
04026                             }
04027                             Doc->setRedrawBounding(currItem);
04028                             currItem->OwnPage = Doc->OnPage(currItem);
04029                             if (currItem->OwnPage != -1)
04030                             {
04031                                    Doc->setCurrentPage(Doc->Pages->at(currItem->OwnPage));
04032                                    setMenTxt(currItem->OwnPage);
04033                             }
04034                             //CB done with emitAllToGUI
04035                             //emit HaveSel(currItem->itemType());
04036                             //EmitValues(currItem);
04037                             //CB need this for? a moved item will send its new data with the new xpos/ypos emits
04038                             //CB TODO And what if we have dragged to a new page. Items X&Y are not updated anyway now
04039                             //currItem->emitAllToGUI();
04040                             updatesOn(true);
04041                             updateContents();
04042                             emit DocChanged();
04043                      }
04044               }
04045               //CB Drag selection performed here
04046               if (((Doc->m_Selection->count() == 0) && (HaveSelRect) && (!MidButt)) || ((shiftSelItems) && (HaveSelRect) && (!MidButt)))
04047               {
04048                      double sc = Scale;
04049                      QPainter p;
04050                      p.begin(viewport());
04051                      ToView(&p);
04052                      p.scale(Scale, Scale);
04053                      p.setRasterOp(XorROP);
04054                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04055                      p.drawRect(Mxp, Myp, SeRx-Mxp, SeRy-Myp);
04056                      p.end();
04057                      normalizeSelectionRect();
04058                      QRect Sele = QRect(static_cast<int>(Mxp*sc), static_cast<int>(Myp*sc), static_cast<int>((SeRx-Mxp)*sc), static_cast<int>((SeRy-Myp)*sc));
04059                      if (!Doc->masterPageMode())
04060                      {
04061                             uint docPagesCount=Doc->Pages->count();
04062                             uint docCurrPageNo=Doc->currentPageNumber();
04063                             for (uint i = 0; i < docPagesCount; ++i)
04064                             {
04065                                    int x = static_cast<int>(Doc->Pages->at(i)->xOffset() * Scale);
04066                                    int y = static_cast<int>(Doc->Pages->at(i)->yOffset() * Scale);
04067                                    int w = static_cast<int>(Doc->Pages->at(i)->width() * Scale);
04068                                    int h = static_cast<int>(Doc->Pages->at(i)->height() * Scale);
04069                                    if (QRect(x, y, w, h).intersects(Sele))
04070                                    {
04071                                           if (docCurrPageNo != i)
04072                                           {
04073                                                  Doc->setCurrentPage(Doc->Pages->at(i));
04074                                                  setMenTxt(i);
04075                                           }
04076                                           break;
04077                                    }
04078                             }
04079                             setRulerPos(contentsX(), contentsY());
04080                      }
04081                      uint docItemCount=Doc->Items->count();
04082                      if (docItemCount != 0)
04083                      {
04084                             Doc->m_Selection->setIsGUISelection(false);
04085                             for (uint a = 0; a < docItemCount; ++a)
04086                             {
04087                                    PageItem* docItem = Doc->Items->at(a);
04088                                    p.begin(viewport());
04089                                    Transform(docItem, &p);
04090                                    QRegion apr = QRegion(p.xForm(docItem->Clip));
04091                                    QRect apr2(docItem->getRedrawBounding(Scale));
04092                                    p.end();
04093                                    if ((Doc->masterPageMode()) && (docItem->OnMasterPage != Doc->currentPage()->pageName()))
04094                                           continue;
04095                                    //CB Finally Items are selected here
04096                                    if (((Sele.contains(apr.boundingRect())) || (Sele.contains(apr2))) && (docItem->LayerNr == Doc->activeLayer()) && (!Doc->layerLocked(docItem->LayerNr)))
04097                                    {
04098                                    //CB set draw to true to (dis)enable some actions via emit to HaveNewSel in scapp.
04099                                    //CB FIXME emit from selection when multiple selected instead
04100                                           //CB #3523 bool redrawSelection=(a==docItemCount-1);
04101                                           bool redrawSelection=false;
04102                                           SelectItemNr(a, redrawSelection);
04103                                    }
04104                             }
04105                             Doc->m_Selection->setIsGUISelection(true);
04106                             Doc->m_Selection->connectItemToGUI();
04107                             if (Doc->m_Selection->count() > 1)
04108                             {
04109                                    Doc->m_Selection->setGroupRect();
04110                                    paintGroupRect();
04111                                    double x, y, w, h;
04112                                    Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
04113                                    emit ItemPos(x, y);
04114                                    emit ItemGeom(w, h);
04115                                    emit HaveSel(Doc->m_Selection->itemAt(0)->itemType());
04116                             }
04117                      }
04118                      HaveSelRect = false;
04119                      shiftSelItems = false;
04120               }
04121               if (Doc->appMode != modeEdit)
04122               {
04123                      if (Doc->appMode == modeRotation)
04124                             Doc->RotMode = RotMode;
04125                      if (!Prefs->stickyTools)
04126                      {
04127                             Doc->appMode = modeNormal;
04128                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
04129                             emit PaintingDone();
04130                      }
04131                      else
04132                      {
04133                             if ((inItemCreation) && (Doc->appMode == modeNormal))
04134                             {
04135                                    currItem = Doc->m_Selection->itemAt(0);
04136                                    if (currItem->asTextFrame())
04137                                           Doc->appMode = modeDrawText;
04138                                    else if (currItem->asImageFrame())
04139                                           Doc->appMode = modeDrawPicture;
04140                                    else if (Doc->SubMode != -1)
04141                                           Doc->appMode = modeDrawShapes;
04142                             }
04143                             emit Amode(Doc->appMode);
04144                      }
04145               }
04146               if (GetItem(&currItem))
04147               {
04148                      if (Doc->m_Selection->count() > 1)
04149                      {
04150                             Doc->m_Selection->setGroupRect();
04151                             paintGroupRect();
04152                             //CB shouldnt need this i think
04153                             //emit HaveSel(currItem->itemType());
04154                             double x, y, w, h;
04155                             Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
04156                             emit ItemPos(x, y);
04157                             emit ItemGeom(w, h);
04158                      }
04159                      else
04160                             currItem->emitAllToGUI();
04161                             
04162                      /*else
04163                      {
04164                             //CB Dont think we need this here with the new selection code
04165                             //For a select, deselect operation, this will cause 2x emit
04166                             //emit HaveSel(currItem->itemType());
04167                             //EmitValues(currItem);
04168                             //currItem->emitAllToGUI();
04169                      }*/
04170               }
04171        }
04172        if ((Doc->appMode == modeEdit) && !operItemResizeInEditMode)
04173        {
04174               currItem = Doc->m_Selection->itemAt(0);
04175               if (currItem->asTextFrame())
04176               {
04177                      if (oldCp == currItem->CPos)
04178                      {
04179                             currItem->itemText.deselectAll();
04180                             currItem->HasSel = false;
04181                             emit HasNoTextSel();
04182                             RefreshItem(currItem);
04183                      }
04184               }
04185               else
04186                      emit DocChanged();
04187        }
04188        if (Doc->appMode == modeMagnifier)
04189        {
04190               double sc = Scale;
04191               if (HaveSelRect)
04192               {
04193                      QPainter p;
04194                      p.begin(viewport());
04195                      ToView(&p);
04196                      p.scale(Scale, Scale);
04197                      p.setRasterOp(XorROP);
04198                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04199                      p.drawRect(Mxp, Myp, SeRx-Mxp, SeRy-Myp);
04200                      p.end();
04201                      normalizeSelectionRect();
04202                      FPoint nx = translateToDoc(Mxp*sc, Myp*sc);
04203                      setScale(visibleWidth() / static_cast<double>(QMAX(abs(SeRx-Mxp), 1)));
04204                      slotDoZoom();
04205                      SetCPo(nx.x(), nx.y());
04206                      if (sc == Scale)
04207                      {
04208                             HaveSelRect = false;
04209                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
04210                             Doc->appMode = modeNormal;
04211                             emit PaintingDone();
04212                      }
04213               }
04214               else
04215               {
04216                      FPoint nx = translateToDoc(m->x(), m->y());
04217                      int mx = qRound(nx.x());
04218                      int my = qRound(nx.y());
04219                      Magnify ? slotZoomIn(mx,my) : slotZoomOut(mx,my);
04220                      if (sc == Scale)
04221                      {
04222                             HaveSelRect = false;
04223                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
04224                             Doc->appMode = modeNormal;
04225                             emit PaintingDone();
04226                      }
04227                      else
04228                      {
04229                             if (m->state() & ShiftButton)
04230                                    qApp->setOverrideCursor(QCursor(loadIcon("LupeZm.xpm")), true);
04231                             else
04232                                    qApp->setOverrideCursor(QCursor(loadIcon("LupeZ.xpm")), true);
04233                      }
04234               }
04235        }
04236        if ((Doc->appMode == modeDrawBezierLine) && (m->button() == LeftButton))
04237        {
04238               currItem = Doc->m_Selection->itemAt(0);
04239               currItem->ClipEdited = true;
04240               currItem->FrameType = 3;
04241               QPainter p;
04242               QPointArray Bez(4);
04243               p.begin(viewport());
04244               Transform(currItem, &p);
04245               FPoint npf(p.xFormDev(m->pos()));
04246               npf += FPoint(Doc->minCanvasCoordinate.x(), Doc->minCanvasCoordinate.y());
04247               npf = Doc->ApplyGridF(npf);
04248               currItem->PoLine.addPoint(npf);
04249               bool ssiz = currItem->Sizing;
04250               currItem->Sizing = true;
04251               if ((currItem->PoLine.size() % 4 == 0) && (currItem->PoLine.size() > 3))
04252               {
04253                      FPoint lxy(currItem->PoLine.point(currItem->PoLine.size()-2));
04254                      FPoint lk(currItem->PoLine.point(currItem->PoLine.size()-1));
04255                      double dx = lxy.x() - lk.x();
04256                      double dy = lxy.y() - lk.y();
04257                      lk.setX(lk.x() + dx*2);
04258                      lk.setY(lk.y() + dy*2);
04259                      currItem->PoLine.addPoint(lxy);
04260                      currItem->PoLine.addPoint(lk);
04261               }
04262               FPoint np2(getMinClipF(&currItem->PoLine));
04263               if (np2.x() < 0)
04264               {
04265                      currItem->PoLine.translate(-np2.x(), 0);
04266                      Doc->MoveItem(np2.x(), 0, currItem);
04267               }
04268               if (np2.y() < 0)
04269               {
04270                      currItem->PoLine.translate(0, -np2.y());
04271                      Doc->MoveItem(0, np2.y(), currItem);
04272               }
04273               if (FirstPoly)
04274               {
04275                      FirstPoly = false;
04276                      currItem->Sizing = ssiz;
04277               }
04278               else
04279               {
04280               Doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
04281 //            currItem->setPolyClip(qRound(QMAX(currItem->lineWidth() / 2, 1)));
04282               Doc->AdjustItemSize(currItem);
04283               currItem->Sizing = ssiz;
04284               currItem->ContourLine = currItem->PoLine.copy();
04285               RefreshItem(currItem);
04286               }
04287               p.end();
04288        }
04289        if ((Doc->appMode == modeDrawBezierLine) && (m->button() == RightButton))
04290        {
04291               currItem = Doc->m_Selection->itemAt(0);
04292               if (currItem!=0)
04293               {
04294                      currItem->PoLine.resize(currItem->PoLine.size()-2);
04295                      if (currItem->PoLine.size() < 4)
04296                      {
04297        //                   emit DelObj(Doc->currentPage->pageNr(), currItem->ItemNr);
04298                             Doc->Items->remove(currItem->ItemNr);
04299                             Doc->m_Selection->removeFirst();
04300                             emit HaveSel(-1);
04301                      }
04302                      else
04303                      {
04304                             Doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false);
04305 //                          currItem->setPolyClip(qRound(QMAX(currItem->lineWidth() / 2.0, 1)));
04306                             Doc->AdjustItemSize(currItem);
04307                             currItem->ContourLine = currItem->PoLine.copy();
04308                      }
04309               }
04310               if (!Prefs->stickyTools)
04311               {
04312                      Doc->appMode = modeNormal;
04313                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
04314                      emit PaintingDone();
04315               }
04316               else
04317                      emit Amode(Doc->appMode);
04318               emit DocChanged();
04319               FirstPoly = true;
04320               updateContents();
04321        }
04322        Doc->DragP = false;
04323        Doc->leaveDrag = false;
04324        operItemMoving = false;
04325        operItemResizing = false;
04326        MidButt = false;
04327        shiftSelItems = false;
04328        inItemCreation = false;
04329        m_SnapCounter = 0;
04330 //     Doc->SubMode = -1;
04331        if (_groupTransactionStarted)
04332        {
04333               for (uint i = 0; i < Doc->m_Selection->count(); ++i)
04334                      Doc->m_Selection->itemAt(i)->checkChanges(true);
04335               undoManager->commit();
04336               _groupTransactionStarted = false;
04337        }
04338 
04339        for (uint i = 0; i < Doc->m_Selection->count(); ++i)
04340               Doc->m_Selection->itemAt(i)->checkChanges(true);
04341 
04342        //Commit drag created items to undo manager.
04343        if (Doc->m_Selection->itemAt(0)!=NULL)
04344        {
04345               Doc->itemAddCommit(Doc->m_Selection->itemAt(0)->ItemNr);
04346        }
04347        //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
04348        zoomSpinBox->clearFocus();
04349        pageSelector->clearFocus();
04350        if (oldClip && Doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
04351        {
04352               currItem = Doc->m_Selection->itemAt(0);
04353               FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
04354               if (*oldClip != newClip)
04355               {
04356                      QString name = isContourLine ? Um::EditContour : Um::EditShape;
04357                      ItemState<QPair<FPointArray, FPointArray> > *state =
04358                                    new ItemState<QPair<FPointArray, FPointArray> >(name);
04359                      state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
04360                      state->set("IS_CONTOUR", isContourLine);
04361                      state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
04362                      state->set("OLD_X", oldItemX);
04363                      state->set("OLD_Y", oldItemY);
04364                      state->set("NEW_X", currItem->xPos());
04365                      state->set("NEW_Y", currItem->yPos());
04366                      undoManager->action(currItem, state);
04367                      undoManager->commit();
04368               }
04369               else
04370                      undoManager->cancelTransaction();
04371 
04372               delete oldClip;
04373               oldClip = 0;
04374        }
04375 
04376        delete oldClip;
04377        oldClip = 0;
04378 }
04379 
04380 void ScribusView::contentsMouseMoveEvent(QMouseEvent *m)
04381 {
04382        int newX, newY;
04383        double nx, ny;
04384        uint a;
04385        PageItem *currItem;
04386        QPoint np, np2, mop;
04387        FPoint npf, npf2;
04388        QPainter p;
04389        QRect tx;
04390        QPointArray Bez(4);
04391        bool erf = false;
04392        double sc = Scale;
04393        horizRuler->Draw(m->x());
04394        vertRuler->Draw(m->y());
04395        emit MousePos(m->x()/Scale + Doc->minCanvasCoordinate.x(), m->y()/Scale + Doc->minCanvasCoordinate.y());
04396        if (Doc->guidesSettings.guidesShown)
04397        {
04398               if (MoveGY)
04399               {
04400                      FromHRuler(m);
04401                      return;
04402               }
04403               if (MoveGX)
04404               {
04405                      FromVRuler(m);
04406                      return;
04407               }
04408        }
04409 /*     if ((!Doc->DragP) && (m_MouseButtonPressed) && (SelItem.count() != 0))
04410        {
04411               int cx = Anz->contentsX() - Anz->childX(doku->currentPage->parentWidget());
04412               int cy = Anz->contentsY() - Anz->childY(doku->currentPage->parentWidget());
04413               int cw = Anz->visibleWidth();
04414               int ch = Anz->visibleHeight();
04415               if ((m->y() < cy+10) || ((ch - (m->y() - cy)) - 10 < 0) || (m->x() < cx + 10) || ((cw - (m->x() - cx)) - 10 < 0))
04416               {
04417                      if (m->y() < cy+10)
04418                             Anz->scrollBy(0, m->y() - cy - 10);
04419                      else if ((ch - (m->y() - cy)) - 10 < 0)
04420                             Anz->scrollBy(0, m->y() - cy - ch +10);
04421                      else if (m->x() < cx + 10)
04422                             Anz->scrollBy(m->x() - cx - 10, 0);
04423                      else if ((cw - (m->x() - cx)) - 10 < 0)
04424                             Anz->scrollBy(m->x() - cx - cw + 10, 0);
04425                      BlockLeave = true;
04426                      update();
04427               }
04428        else
04429               BlockLeave = false;
04430        } */
04431 
04432        if (m_MouseButtonPressed && (Doc->appMode == modeEditGradientVectors))
04433        {
04434               PageItem *currItem = Doc->m_Selection->itemAt(0);
04435               newX = m->x();
04436               newY = m->y();
04437               double dx = abs(Mxp - newX) + 5;
04438               double dy = abs(Myp - newY) + 5;
04439               if (m->state() == LeftButton)
04440               {
04441                      currItem->GrStartX -= (Mxp - newX) / Scale;
04442                      currItem->GrStartY -= (Myp - newY) / Scale;
04443               }
04444               if (m->state() == RightButton)
04445               {
04446                      currItem->GrEndX -= (Mxp - newX) / Scale;
04447                      currItem->GrEndY -= (Myp - newY) / Scale;
04448               }
04449               Mxp = newX;
04450               Myp = newY;
04451               RefreshGradient(currItem, dx, dy);
04452               m_ScMW->propertiesPalette->updateColorSpecialGradient();
04453               return;
04454        }
04455        if (m_MouseButtonPressed && (Doc->appMode == modeMeasurementTool))
04456        {
04457               newX = m->x();
04458               newY = m->y();
04459               p.begin(viewport());
04460               QPoint out = contentsToViewport(QPoint(0, 0));
04461               p.translate(out.x(), out.y());
04462               p.setRasterOp(XorROP);
04463               p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04464               p.drawLine(Dxp, Dyp, Mxp, Myp);
04465               p.drawLine(Dxp, Dyp, newX, newY);
04466               p.end();
04467               Mxp = newX;
04468               Myp = newY;
04469               double dxp = Dxp / sc - Doc->currentPage()->xOffset()+ Doc->minCanvasCoordinate.x();
04470               double dyp = Dyp / sc - Doc->currentPage()->yOffset()+ Doc->minCanvasCoordinate.y();
04471               double nxp = newX / sc - Doc->currentPage()->xOffset()+ Doc->minCanvasCoordinate.x();
04472               double nyp = newY / sc - Doc->currentPage()->yOffset()+ Doc->minCanvasCoordinate.y();
04473               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)), Doc->unitIndex());
04474               return;
04475        }
04476        if (m_MouseButtonPressed && (m->state() & Qt::RightButton) && (m->state() & Qt::ControlButton))
04477        {
04478               m_ScMW->setAppMode(modePanning);
04479        }
04480        if (m_MouseButtonPressed && (Doc->appMode == modePanning))
04481        {
04482               int scroX = m->x() - qRound((Mxp * sc));
04483               int scroY = m->y() - qRound((Myp * sc));
04484               scrollBy(-scroX, -scroY);
04485               Mxp = static_cast<int>((m->x()-scroX)/sc);
04486               Myp = static_cast<int>((m->y()-scroY)/sc);
04487               return;
04488        }
04489        if (m_MouseButtonPressed && (Doc->appMode == modeDrawFreehandLine))
04490        {
04491               newX = m->x();
04492               newY = m->y();
04493               double newXF = translateToDoc(m->x(), m->y()).x();
04494               double newYF = translateToDoc(m->x(), m->y()).y();
04495               if (RecordP.size() > 0)
04496               {
04497                      if (FPoint(newXF, newYF) != RecordP.point(RecordP.size()-1))
04498                             RecordP.addPoint(FPoint(newXF, newYF));
04499               }
04500               else
04501                      RecordP.addPoint(FPoint(newXF, newYF));
04502               p.begin(viewport());
04503               ToView(&p);
04504               p.translate(qRound(Doc->minCanvasCoordinate.x()*Scale), qRound(Doc->minCanvasCoordinate.y()*Scale));
04505               if (RecordP.size() > 1)
04506               {
04507                      FPoint xp(RecordP.point(RecordP.size()-2));
04508                      p.drawLine(qRound((xp.x() - Doc->minCanvasCoordinate.x())*sc), qRound((xp.y() - Doc->minCanvasCoordinate.y())*sc), newX, newY);
04509               }
04510               else
04511                      p.drawPoint(m->x(), m->y());
04512               p.end();
04513               return;
04514        }
04515        if ((GetItem(&currItem)) && (!shiftSelItems))
04516        {
04517               newX = qRound(translateToDoc(m->x(), m->y()).x());
04518               newY = qRound(translateToDoc(m->x(), m->y()).y());
04519               if (moveTimerElapsed() && (m_MouseButtonPressed) && (m->state() == RightButton) && (!Doc->DragP) && (Doc->appMode == modeNormal) /* && (!currItem->locked()) */ && (!(currItem->isSingleSel)))
04520               {
04521                      if ((abs(Dxp - newX) > 10) || (abs(Dyp - newY) > 10))
04522                      {
04523                             Doc->DragP = true;
04524                             Doc->leaveDrag = false;
04525                             Doc->DraggedElem = currItem;
04526                             Doc->DragElements.clear();
04527                             for (uint dre=0; dre<Doc->m_Selection->count(); ++dre)
04528                                    Doc->DragElements.append(Doc->m_Selection->itemAt(dre)->ItemNr);
04529                             ScriXmlDoc *ss = new ScriXmlDoc();
04530                             QDragObject *dr = new QTextDrag(ss->WriteElem(Doc, this, Doc->m_Selection), this);
04531 //                          QImage drImg = currItem->DrawObj_toImage();
04532 //                          QPixmap pm;
04533 //                          pm.convertFromImage(drImg);
04534 //                          dr->setPixmap(pm);
04535                             dr->setPixmap(loadIcon("DragPix.xpm"));
04536                             dr->drag();
04537 //                          if (!dr->drag())
04538 //                                 qDebug("ScribusView::contentsMouseMoveEvent: couldn't start drag operation!");
04539 /* commented out the code above as the debug message is incorrect,
04540    see the Qt Reference: "The function returns TRUE if the caller should delete the original copy
04541     of the dragged data (but see target()); otherwise returns FALSE." */
04542                             delete ss;
04543                             ss=NULL;
04544                             Doc->DragP = false;
04545                             Doc->leaveDrag = false;
04546                             m_MouseButtonPressed = false;
04547                             Doc->DraggedElem = 0;
04548                             Doc->DragElements.clear();
04549                      }
04550                      return;
04551               }
04552               if (Doc->DragP)
04553                      return;
04554               if (moveTimerElapsed() && m_MouseButtonPressed && (Doc->appMode == modeRotation))
04555               {
04556                      double newW = xy2Deg(m->x()/sc - RCenter.x(), m->y()/sc - RCenter.y());
04557                      if (m->state() & ControlButton)
04558                      {
04559                             newW=constrainAngle(newW, Doc->toolSettings.constrain);
04560                             oldW=constrainAngle(oldW, Doc->toolSettings.constrain);
04561                             //RotateGroup uses MoveBy so its pretty hard to constrain the result
04562                             if (Doc->m_Selection->isMultipleSelection())
04563                                    RotateGroup(newW-oldW);
04564                             else
04565                                    Doc->RotateItem(newW, currItem->ItemNr);
04566                      }
04567                      else
04568                      {
04569                             if (Doc->m_Selection->isMultipleSelection())
04570                                    RotateGroup(newW - oldW);
04571                             else
04572                                    Doc->RotateItem(currItem->rotation() - (oldW - newW), currItem->ItemNr);
04573                      }
04574                      oldW = newW;
04575                      emit DocChanged();
04576               }
04577               if (Doc->appMode == modeDrawBezierLine)
04578               {
04579                      p.begin(viewport());
04580                      ToView(&p);
04581                      p.scale(Scale, Scale);
04582                      p.setRasterOp(XorROP);
04583                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04584                      if ((Doc->useRaster) && (Doc->OnPage(currItem) != -1))
04585                      {
04586                             newX = static_cast<int>(qRound(newX / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
04587                             newY = static_cast<int>(qRound(newY / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
04588                      }
04589                      if (!m_MouseButtonPressed)
04590                      {
04591                             QPoint a1 = currItem->PoLine.pointQ(currItem->PoLine.size()-2);
04592                             QPoint a2 = currItem->PoLine.pointQ(currItem->PoLine.size()-1);
04593                             a1 += QPoint(qRound(currItem->xPos()), qRound(currItem->yPos()));
04594                             a2 += QPoint(qRound(currItem->xPos()), qRound(currItem->yPos()));
04595                             BezierPoints(&Bez, a1, a2, QPoint(Mxp, Myp), QPoint(Mxp, Myp));
04596                             p.drawCubicBezier(Bez);
04597                             Bez.setPoint(2, QPoint(newX, newY));
04598                             Bez.setPoint(3, QPoint(newX, newY));
04599                             p.drawCubicBezier(Bez);
04600                      }
04601                      else
04602                      {
04603                             QPoint a2 = currItem->PoLine.pointQ(currItem->PoLine.size()-1);
04604                             a2 += QPoint(qRound(currItem->xPos()), qRound(currItem->yPos()));
04605                             if (currItem->PoLine.size() > 2)
04606                             {
04607                                    QPoint a1 = currItem->PoLine.pointQ(currItem->PoLine.size()-2);
04608                                    QPoint a3 = currItem->PoLine.pointQ(currItem->PoLine.size()-3);
04609                                    a1 += QPoint(qRound(currItem->xPos()), qRound(currItem->yPos()));
04610                                    a3 += QPoint(qRound(currItem->xPos()), qRound(currItem->yPos()));
04611                                    BezierPoints(&Bez, a3, a1, QPoint(Mxp, Myp), a2);
04612                                    p.drawCubicBezier(Bez);
04613                                    Bez.setPoint(2, QPoint(newX, newY));
04614                                    Bez.setPoint(3, a2);
04615                                    p.drawCubicBezier(Bez);
04616                             }
04617                             p.drawLine(a2, QPoint(Mxp, Myp));
04618                             p.drawLine(a2, QPoint(newX, newY));
04619                      }
04620                      p.end();
04621                      Mxp = newX;
04622                      Myp = newY;
04623               }
04624               if (m_MouseButtonPressed && (Doc->appMode == modeDrawRegularPolygon))
04625               {
04626                      p.begin(viewport());
04627                      ToView(&p);
04628                      p.setRasterOp(XorROP);
04629                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04630                      if (m->state() & ShiftButton)
04631                      {
04632                             mop = QPoint(m->x(), static_cast<int>((currItem->yPos() + (newX - currItem->xPos())) * sc));
04633                             QCursor::setPos(mapToGlobal(mop));
04634                             newY = static_cast<int>(mop.y()/sc);
04635                      }
04636                      if ((Doc->useRaster) && (Doc->OnPage(currItem) != -1))
04637                      {
04638                             newX = static_cast<int>(qRound(newX / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
04639                             newY = static_cast<int>(qRound(newY / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
04640                      }
04641                      p.drawRect(static_cast<int>(currItem->xPos()*sc), static_cast<int>(currItem->yPos()*sc),
04642                                 static_cast<int>(Mxp*sc-currItem->xPos()*sc), static_cast<int>(Myp*sc-currItem->yPos()*sc));
04643                      p.drawRect(static_cast<int>(currItem->xPos()*sc), static_cast<int>(currItem->yPos()*sc),
04644                                 static_cast<int>(newX*sc-currItem->xPos()*sc), static_cast<int>(newY*sc-currItem->yPos()*sc));
04645                      p.end();
04646                      emit ItemGeom(newX - currItem->xPos(), newY - currItem->yPos());
04647                      Mxp = newX;
04648                      Myp = newY;
04649               }
04650               if (m_MouseButtonPressed && (Doc->appMode == modeDrawLine))
04651               {
04652                      p.begin(viewport());
04653                      ToView(&p);
04654                      p.setRasterOp(XorROP);
04655                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04656                      if (Doc->useRaster)
04657                      {
04658                             newX = static_cast<int>(qRound(newX / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
04659                             newY = static_cast<int>(qRound(newY / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
04660                      }
04661                      double newRot=xy2Deg(newX - currItem->xPos(), newY - currItem->yPos());
04662                      //Constrain rotation angle, when the mouse is being dragged around for a new line
04663                      if (m->state() & ControlButton)
04664                      {
04665                             //Flip our angles around here
04666                             if (newRot<0.0)
04667                                    newRot=-newRot;
04668                             else
04669                                    newRot=360-newRot;
04670                             newRot=constrainAngle(newRot, Doc->toolSettings.constrain);
04671                             double hlen=sqrt(pow(newX - currItem->xPos(),2)+pow(newY - currItem->yPos(),2));
04672                             newX = qRound(currItem->xPos()+(hlen * cos(newRot/(180.0/M_PI))));
04673                             newY = qRound(currItem->yPos()-(hlen * sin(newRot/(180.0/M_PI))));
04674                      }
04675                      
04676                      p.drawLine(static_cast<int>(currItem->xPos()*sc), static_cast<int>(currItem->yPos()*sc), static_cast<int>(Mxp*sc), static_cast<int>(Myp*sc));
04677                      p.drawLine(static_cast<int>(currItem->xPos()*sc), static_cast<int>(currItem->yPos()*sc), static_cast<int>(newX*sc), static_cast<int>(newY*sc));
04678                      p.end();
04679                      emit SetAngle(newRot);
04680                      emit ItemGeom(sqrt(pow(newX - currItem->xPos(),2)+pow(newY - currItem->yPos(),2)), 0);
04681                      Mxp = newX;
04682                      Myp = newY;
04683               }
04684               if (m_MouseButtonPressed && (Doc->appMode == modeEdit) && (!operItemResizeInEditMode))
04685               {
04686                      if (currItem->asImageFrame())
04687                      {
04688                             QWMatrix ro;
04689                             ro.rotate(-currItem->rotation());
04690                             QPoint rota = ro.map(QPoint(newX-Mxp,newY-Myp));
04691                             currItem->moveImageInFrame(rota.x()/currItem->imageXScale(), rota.y()/currItem->imageYScale());
04692                             updateContents(currItem->getRedrawBounding(Scale));
04693                             Mxp = newX;
04694                             Myp = newY;
04695                      }
04696                      if (currItem->asTextFrame())
04697                      {
04698                             currItem->itemText.deselectAll();
04699                             currItem->HasSel = false;
04700                             slotSetCurs(m->x(), m->y());
04701                             //Make sure we dont go here if the old cursor position was not set
04702                             if (oldCp!=-1 && currItem->itemText.length() > 0)
04703                             {
04704                                    if (currItem->CPos < oldCp)
04705                                    {
04706                                           currItem->itemText.select(currItem->CPos, oldCp - currItem->CPos);
04707                                           currItem->HasSel = true;
04708                                    }
04709                                    if (currItem->CPos > oldCp)
04710                                    {
04711                                           currItem->itemText.select(oldCp, currItem->CPos - oldCp);
04712                                           currItem->HasSel = true;
04713                                    }
04714                             }
04715                             RefreshItem(currItem);
04716                             emit currItem->HasSel ? HasTextSel() : HasNoTextSel();
04717                      }
04718               }
04719               //Operations run here:
04720               //Item resize, esp after creating a new one
04721               if (moveTimerElapsed() && m_MouseButtonPressed && (m->state() & LeftButton) && ((Doc->appMode == modeNormal) || ((Doc->appMode == modeEdit) && operItemResizeInEditMode)) && (!currItem->locked()))
04722               {
04723                      if (Doc->EditClip)
04724                      {
04725                             if ((m_MouseButtonPressed) && (ClRe == -1) && (SegP1 == -1) && (SegP2 == -1))
04726                             {
04727                                    newX = qRound(translateToDoc(m->x(), m->y()).x());
04728                                    newY = qRound(translateToDoc(m->x(), m->y()).y());
04729                                    p.begin(viewport());
04730                                    ToView(&p);
04731                                    p.scale(Scale, Scale);
04732                                    p.setRasterOp(XorROP);
04733                                    p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04734                                    p.drawRect(Mxp, Myp, SeRx-Mxp, SeRy-Myp);
04735                                    p.drawRect(Mxp, Myp, newX-Mxp, newY-Myp);
04736                                    p.end();
04737                                    SeRx = newX;
04738                                    SeRy = newY;
04739                                    HaveSelRect = true;
04740                                    return;
04741                             }
04742                             newX = m->x();
04743                             newY = m->y();
04744                             FPoint np(newX-Mxp, newY-Myp, 0, 0, currItem->rotation(), 1, 1, true);
04745                             operItemMoving = true;
04746                             m_SnapCounter++;
04747                             if (m_SnapCounter > 3)
04748                                    m_SnapCounter = 0;
04749                             currItem = Doc->m_Selection->itemAt(0);
04750                             currItem->OldB2 = currItem->width();
04751                             currItem->OldH2 = currItem->height();
04752                             FPointArray Clip;
04753                             if (EditContour)
04754                                    Clip = currItem->ContourLine;
04755                             else
04756                                    Clip = currItem->PoLine;
04757                             npf.setX(Clip.point(ClRe).x() + np.x() / Scale);
04758                             npf.setY(Clip.point(ClRe).y() + np.y() / Scale);
04759                             if ((SegP1 != -1) && (SegP2 != -1))
04760                             {
04761                                    npf.setX(Clip.point(SegP2).x() + np.x() / Scale);
04762                                    npf.setY(Clip.point(SegP2).y() + np.y() / Scale);
04763                                    ClRe = SegP2;
04764                                    MoveClipPoint(currItem, npf);
04765                                    currItem->OldB2 = currItem->width();
04766                                    currItem->OldH2 = currItem->height();
04767                                    if (EditContour)
04768                                           Clip = currItem->ContourLine;
04769                                    else
04770                                           Clip = currItem->PoLine;
04771                                    ClRe = SegP1;
04772                                    npf2.setX(Clip.point(SegP1).x() + np.x() / Scale);
04773                                    npf2.setY(Clip.point(SegP1).y() + np.y() / Scale);
04774                                    MoveClipPoint(currItem, npf2);
04775                                    Mxp = newX;
04776                                    Myp = newY;
04777                             }
04778                             else
04779                             {
04780                                    if ((SelNode.count() != 0) && (EdPoints))
04781                                    {
04782                                           int storedClRe = ClRe;
04783                                           for (uint itm = 0; itm < SelNode.count(); ++itm)
04784                                           {
04785                                                  if (EditContour)
04786                                                         Clip = currItem->ContourLine;
04787                                                  else
04788                                                         Clip = currItem->PoLine;
04789                                                  npf.setX(Clip.point(*SelNode.at(itm)).x() + np.x() / Scale);
04790                                                  npf.setY(Clip.point(*SelNode.at(itm)).y() + np.y() / Scale);
04791                                                  ClRe = *SelNode.at(itm);
04792                                                  currItem->OldB2 = currItem->width();
04793                                                  currItem->OldH2 = currItem->height();
04794                                                  if (((ClRe != 0) && (SelNode.count() > 1)) || (SelNode.count() == 1))
04795                                                  {
04796                                                         if ((SelNode.count() == 1) && (m_SnapCounter > 2))
04797                                                         {
04798                                                                double nx = npf.x();
04799                                                                double ny = npf.y();
04800                                                                nx += currItem->xPos();
04801                                                                ny += currItem->yPos();
04802                                                                if (!Doc->ApplyGuides(&nx, &ny))
04803                                                                       npf = Doc->ApplyGridF(FPoint(nx, ny));
04804                                                                else
04805                                                                       npf = FPoint(nx, ny);
04806                                                                npf = FPoint(npf.x() - currItem->xPos(), npf.y() - currItem->yPos());
04807                                                                m_SnapCounter = 0;
04808                                                         }
04809                                                         MoveClipPoint(currItem, npf);
04810                                                  }
04811                                           }
04812                                           currItem->OldB2 = currItem->width();
04813                                           currItem->OldH2 = currItem->height();
04814                                           ClRe = storedClRe;
04815                                    }
04816                                    else
04817                                    {
04818                                           if (m_SnapCounter > 2)
04819                                           {
04820                                                  double nx = npf.x();
04821                                                  double ny = npf.y();
04822                                                  nx += currItem->xPos();
04823                                                  ny += currItem->yPos();
04824                                                  if (!Doc->ApplyGuides(&nx, &ny))
04825                                                         npf = Doc->ApplyGridF(FPoint(nx, ny));
04826                                                  else
04827                                                         npf = FPoint(nx, ny);
04828                                                  npf = FPoint(npf.x() - currItem->xPos(), npf.y() - currItem->yPos());
04829                                                  m_SnapCounter = 0;
04830                                           }
04831                                           MoveClipPoint(currItem, npf);
04832                                    }
04833                                    Mxp = newX;
04834                                    Myp = newY;
04835                             }
04836                             return;
04837                      }
04838                      if (operItemResizing)
04839                      {
04840                             newX = static_cast<int>(m->x()/sc);
04841                             newY = static_cast<int>(m->y()/sc);
04842                             operItemMoving = false;
04843                             if (Doc->m_Selection->isMultipleSelection())
04844                             {
04845                                    newX = qRound(translateToDoc(m->x(), m->y()).x());
04846                                    newY = qRound(translateToDoc(m->x(), m->y()).y());
04847                                    double gx, gy, gh, gw;
04848                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
04849                                    int ox1 = qRound(gx*sc);
04850                                    int oy1 = qRound(gy*sc);
04851                                    int ox2 = qRound((gx+gw)*sc);
04852                                    int oy2 = qRound((gy+gh)*sc);
04853                                    np2 = QPoint(newX, newY);
04854                                    np2 = Doc->ApplyGrid(np2);
04855                                    double nx = np2.x();
04856                                    double ny = np2.y();
04857                                    Doc->ApplyGuides(&nx, &ny);
04858                                    np2 = QPoint(qRound(nx*sc), qRound(ny*sc));
04859                                    p.begin(viewport());
04860                                    ToView(&p);
04861                                    switch (frameResizeHandle)
04862                                    {
04863                                    case 1:
04864                                           if (m->state() & ControlButton)
04865                                                  np2 = QPoint(qRound(newX), qRound(gy+(gh * ((newX-gx) / gw))));
04866                                           else
04867                                                  np2 = QPoint(qRound(newX), qRound(newY));
04868                                           np2 = Doc->ApplyGrid(np2);
04869                                           nx = np2.x();
04870                                           ny = np2.y();
04871                                           Doc->ApplyGuides(&nx, &ny);
04872                                           np2 = QPoint(qRound(nx*sc), qRound(ny*sc));
04873                                           PaintSizeRect(&p, QRect(QPoint(qRound(gx*sc), qRound(gy*sc)), np2));
04874                                           break;
04875                                    case 2:
04876                                           PaintSizeRect(&p, QRect(np2, QPoint(ox2,oy2)));
04877                                           break;
04878                                    case 3:
04879                                           PaintSizeRect(&p, QRect(np2, QPoint(ox1, oy2)));
04880                                           break;
04881                                    case 4:
04882                                           PaintSizeRect(&p, QRect(np2, QPoint(ox2, oy1)));
04883                                           break;
04884                                    case 5:
04885                                           PaintSizeRect(&p, QRect(QPoint(ox1, oy1), QPoint(ox2, np2.y())));
04886                                           break;
04887                                    case 6:
04888                                           PaintSizeRect(&p, QRect(QPoint(np2.x(), oy2), QPoint(ox1,oy1)));
04889                                           break;
04890                                    case 7:
04891                                           PaintSizeRect(&p, QRect(QPoint(np2.x(), oy1), QPoint(ox2, oy2)));
04892                                           break;
04893                                    case 8:
04894                                           PaintSizeRect(&p, QRect(QPoint(ox1, qRound(np2.y())), QPoint(ox2, oy2)));
04895                                           break;
04896                                    }
04897                                    Mxp = qRound(np2.x());
04898                                    Myp = qRound(np2.y());
04899                                    p.end();
04900                             }
04901                             else
04902                             {
04903                                    //qDebug(QString("frameResizeHandle %1").arg(frameResizeHandle));
04904                                    for (a = 0; a < Doc->m_Selection->count(); ++a)
04905                                    {
04906                                           currItem = Doc->m_Selection->itemAt(0);
04907                                           double nh = currItem->height();
04908                                           if ((frameResizeHandle == 1) || (frameResizeHandle == 2))
04909                                           {
04910                                                  switch (frameResizeHandle)
04911                                                  {
04912                                                  case 1:
04913                                                         p.begin(viewport());
04914                                                         Transform(currItem, &p);
04915                                                         p.translate(qRound(-Doc->minCanvasCoordinate.x()), qRound(-Doc->minCanvasCoordinate.y()));
04916                                                         //Shift proportional square resize
04917                                                         if ((m->state() & ShiftButton) && (!(m->state() & ControlButton)))
04918                                                         {
04919                                                                QWMatrix ma;
04920                                                                ma.translate(currItem->xPos(), currItem->yPos());
04921                                                                ma.rotate(currItem->rotation());
04922                                                                ma = ma.invert();
04923                                                                nh = ma.m11() * newX + ma.m21() * newY + ma.dx();
04924                                                                mop = QPoint(m->x(), m->y());
04925                                                         }
04926                                                         else
04927                                                         {
04928                                                                //Control proportional resize
04929                                                                if ((m->state() & ControlButton) && (!(m->state() & ShiftButton)))
04930                                                                {
04931                                                                       QWMatrix ma;
04932                                                                       ma.translate(currItem->xPos(), currItem->yPos());
04933                                                                       ma.rotate(currItem->rotation());
04934                                                                       ma = ma.invert();
04935                                                                       double nX = ma.m11() * newX + ma.m21() * newY + ma.dx();
04936                                                                       nh = nX / currItem->OldB2 * currItem->OldH2;
04937                                                                       mop = QPoint(m->x(), m->y());
04938                                                                }
04939                                                                else
04940                                                                       mop = QPoint(m->x(), m->y());
04941                                                         }
04942                                                         np = p.xFormDev(mop);
04943                                                         nx = np.x();
04944                                                         ny = np.y();
04945                                                         p.end();
04946                                                         if (!currItem->asLine())
04947                                                         {
04948                                                                if ((Doc->useRaster) && (Doc->OnPage(currItem) != -1))
04949                                                                {
04950                                                                       nx += currItem->xPos();
04951                                                                       ny += currItem->yPos();
04952                                                                       npf = Doc->ApplyGridF(FPoint(nx, ny));
04953                                                                       nx = npf.x() - currItem->xPos();
04954                                                                       ny = npf.y() - currItem->yPos();
04955                                                                }
04956                                                                if (Doc->SnapGuides)
04957                                                                {
04958                                                                       nx += currItem->xPos();
04959                                                                       ny += currItem->yPos();
04960                                                                       Doc->ApplyGuides(&nx, &ny);
04961                                                                       nx -= currItem->xPos();
04962                                                                       ny -= currItem->yPos();
04963                                                                }
04964                                                                if ((m->state() & ControlButton) || ((m->state() & ShiftButton)))
04965                                                                       erf = Doc->SizeItem(nx, nh, currItem->ItemNr);
04966                                                                else
04967                                                                erf = Doc->SizeItem(nx, ny, currItem->ItemNr);
04968                                                         }
04969                                                         else
04970                                                         {
04971                                                                p.begin(viewport());
04972                                                                double rba = currItem->rotation();
04973                                                                currItem->setRotation(0.0);
04974                                                                Transform(currItem, &p);
04975                                                                p.translate(qRound(-Doc->minCanvasCoordinate.x()), qRound(-Doc->minCanvasCoordinate.y()));
04976                                                                np = p.xFormDev(QPoint(m->x(), m->y()));
04977                                                                p.end();
04978                                                                double sizeItemX=np.x(), sizeItemY=np.y();
04979                                                                //Constrain rotation angle, when the mouse is moving the non-origin point of a line
04980                                                                if (m->state() & ControlButton)
04981                                                                {
04982                                                                       double newRot=xy2Deg(np.x(), np.y());
04983                                                                       rba=constrainAngle(newRot, Doc->toolSettings.constrain);
04984                                                                       double hlen=sqrt(pow(newX - currItem->xPos(),2)+pow(newY - currItem->yPos(),2));
04985                                                                       sizeItemX = hlen * cos(rba/(180.0/M_PI));
04986                                                                       sizeItemY = hlen * sin(rba/(180.0/M_PI));
04987                                                                }
04988                                                                currItem->setRotation(rba);
04989                                                                np = Doc->ApplyGrid(np);
04990                                                                erf = Doc->SizeItem(sizeItemX, sizeItemY, currItem->ItemNr);
04991                                                                if (Doc->SnapGuides)
04992                                                                {
04993                                                                       p.begin(viewport());
04994                                                                       currItem->Sizing = true;
04995                                                                       p.setRasterOp(XorROP);
04996                                                                       p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
04997                                                                       p.drawLine(static_cast<int>(currItem->xPos()*sc), static_cast<int>(currItem->yPos()*sc),
04998                                                                                     static_cast<int>(Mxp*sc), static_cast<int>(Myp*sc));
04999                                                                       p.drawLine(static_cast<int>(currItem->xPos()*sc), static_cast<int>(currItem->yPos()*sc),
05000                                                                                     static_cast<int>(newX*sc), static_cast<int>(newY*sc));
05001                                                                       p.end();
05002                                                                }
05003                                                         }
05004                                                         break;
05005                                                  case 2:
05006                                                         if (currItem->asLine())
05007                                                         {
05008                                                                double sav = Doc->SnapGuides;
05009                                                                npf2 = FPoint(newX-Mxp, newY-Myp);
05010                                                                //Constrain rotation on left point move, disabled for now in movesizeitem
05011                                                                erf = Doc->MoveSizeItem(npf2, FPoint(0, 0), currItem->ItemNr, false, (m->state() & ControlButton));
05012                                                                Doc->SnapGuides = sav;
05013                                                                if (sav)
05014                                                                       currItem->Sizing = true;
05015                                                         }
05016                                                         else
05017                                                         {
05018                                                                newX = qRound(translateToDoc(m->x(), m->y()).x());
05019                                                                newY = qRound(translateToDoc(m->x(), m->y()).y());
05020                                                                p.begin(viewport());
05021                                                                np2 = QPoint(newX, newY);
05022                                                                np2 = Doc->ApplyGrid(np2);
05023                                                                double nx = np2.x();
05024                                                                double ny = np2.y();
05025                                                                Doc->ApplyGuides(&nx, &ny);
05026                                                                p.translate(static_cast<int>(currItem->xPos()), static_cast<int>(currItem->yPos()));
05027                                                                p.rotate(currItem->rotation());
05028                                                                np2 = p.xFormDev(QPoint(qRound(nx), qRound(ny)));
05029                                                                p.end();
05030                                                                p.begin(viewport());
05031                                                                ToView(&p);
05032                                                                Transform(currItem, &p);
05033                                                                PaintSizeRect(&p, QRect(np2, QPoint(qRound(currItem->width()), qRound(currItem->height()))));
05034                                                                p.end();
05035                                                         }
05036                                                         break;
05037                                                  }
05038                                           }
05039                                           else
05040                                           {
05041                                                  p.begin(viewport());
05042                                                  np2 = QPoint(newX, newY);
05043                                                  np2 = Doc->ApplyGrid(np2);
05044                                                  double nx = np2.x();
05045                                                  double ny = np2.y();
05046                                                  Doc->ApplyGuides(&nx, &ny);
05047                                                  p.translate(static_cast<int>(currItem->xPos() - Doc->minCanvasCoordinate.x()), static_cast<int>(currItem->yPos() - Doc->minCanvasCoordinate.y()));
05048                                                  p.rotate(currItem->rotation());
05049                                                  np2 = p.xFormDev(QPoint(qRound(nx), qRound(ny)));
05050                                                  p.end();
05051                                                  p.begin(viewport());
05052                                                  ToView(&p);
05053                                                  Transform(currItem, &p);
05054                                                  switch (frameResizeHandle)
05055                                                  {
05056                                                  case 0:
05057                                                         break;
05058                                                  case 3:
05059                                                         PaintSizeRect(&p, QRect(np2, QPoint(0, qRound(currItem->height()))));
05060                                                         break;
05061                                                  case 4:
05062                                                         PaintSizeRect(&p, QRect(np2, QPoint(qRound(currItem->width()), 0)));
05063                                                         break;
05064                                                  case 5:
05065                                                         PaintSizeRect(&p, QRect(QPoint(0, 0), QPoint(qRound(currItem->width()), np2.y())));
05066                                                         break;
05067                                                  case 6:
05068                                                         PaintSizeRect(&p, QRect(QPoint(0, 0), QPoint(np2.x(), qRound(currItem->height()))));
05069                                                         break;
05070                                                  case 7:
05071                                                         PaintSizeRect(&p, QRect(QPoint(np2.x(), 0), QPoint(qRound(currItem->width()), qRound(currItem->height()))));
05072                                                         break;
05073                                                  case 8:
05074                                                         PaintSizeRect(&p, QRect(QPoint(0, np2.y()), QPoint(qRound(currItem->width()), qRound(currItem->height()))));
05075                                                         break;
05076                                                  }
05077                                                  p.end();
05078                                           }
05079                                    }
05080                             }
05081                             if ((erf) || (frameResizeHandle > 1))
05082                             {
05083                                    Mxp = newX;
05084                                    Myp = newY;
05085                             }
05086                      }
05087                      else
05088                      {
05089                             //Dragging an item (plus more?)
05090                             newX = static_cast<int>(m->x()/sc);
05091                             newY = static_cast<int>(m->y()/sc);
05092                             operItemMoving = true;
05093                             erf = false;
05094                             int dX=newX-Mxp, dY=newY-Myp;
05095                             if (!Doc->m_Selection->isMultipleSelection())
05096                             {
05097                                    erf=true;
05098                                    currItem = Doc->m_Selection->itemAt(0);
05099                                    //Control Alt drag image in frame without being in edit mode
05100                                    if ((currItem->asImageFrame()) && (m->state() & ControlButton) && (m->state() & AltButton))
05101                                    {
05102                                           currItem->moveImageInFrame(dX/currItem->imageXScale(),dY/currItem->imageYScale());
05103                                           updateContents(currItem->getRedrawBounding(Scale));
05104                                           
05105                                    }
05106                                    else
05107                                    {
05108                                           //Dragging orthogonally - Ctrl Drag
05109                                           if ((m->state() & ControlButton) && !(m->state() & ShiftButton) && !(m->state() & AltButton))
05110                                           {
05111                                                  if (abs(dX)>abs(dY))
05112                                                         dY=0;
05113                                                  else
05114                                                  if (abs(dY)>abs(dX))
05115                                                         dX=0;
05116                                                  erf=false;
05117                                                  dX+=qRound(dragConstrainInitPtX-currItem->xPos());
05118                                                  dY+=qRound(dragConstrainInitPtY-currItem->yPos());
05119                                           }
05120                                           if (!(currItem->isTableItem && currItem->isSingleSel))
05121                                           {
05122                                                  Doc->m_Selection->setGroupRect();
05123                                                  double gx, gy, gh, gw;
05124                                                  Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05125                                                  moveGroup(dX, dY, false);
05126                                                  if (Doc->SnapGuides)
05127                                                  {
05128                                                         double nx = gx;
05129                                                         double ny = gy;
05130                                                         Doc->ApplyGuides(&nx, &ny);
05131                                                         moveGroup(nx-gx, ny-gy, false);
05132                                                         Doc->m_Selection->setGroupRect();
05133                                                         Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05134                                                         nx = gx+gw;
05135                                                         ny = gy+gh;
05136                                                         Doc->ApplyGuides(&nx, &ny);
05137                                                         moveGroup(nx-(gx+gw), ny-(gy+gh), false);
05138                                                  }
05139                                                  if (Doc->useRaster)
05140                                                  {
05141                                                         Doc->m_Selection->setGroupRect();
05142                                                         double gx, gy, gh, gw, gxo, gyo;
05143                                                         Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05144                                                         gxo = gx;
05145                                                         gyo = gy;
05146                                                         FPoint npx = Doc->ApplyGridF(FPoint(gx, gy));
05147                                                         FPoint npw = Doc->ApplyGridF(FPoint(gx+gw, gy+gh));
05148                                                         if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
05149                                                                gx = npw.x() - gw;
05150                                                         else
05151                                                                gx = npx.x();
05152                                                         if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
05153                                                                gy = npw.y() - gh;
05154                                                         else
05155                                                                gy = npx.y();
05156                                                         if ((fabs(gx - gxo) < (Doc->guidesSettings.guideRad / 2.0) / Scale) && (fabs(gy - gyo) < (Doc->guidesSettings.guideRad / 2.0) / Scale))
05157                                                                moveGroup(gx-gxo, gy-gyo, false);
05158                                                  }
05159                                           }
05160                                    }
05161                             }
05162                             else
05163                             {
05164                                    Doc->m_Selection->setGroupRect();
05165                                    double gx, gy, gh, gw;
05166                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05167                                    int dX=newX-Mxp, dY=newY-Myp;
05168                                    erf = true;
05169                                    if (m->state() & ControlButton)
05170                                    {
05171                                           if (abs(dX)>abs(dY))
05172                                                  dY=0;
05173                                           else
05174                                           if (abs(dY)>abs(dX))
05175                                                  dX=0;
05176                                           erf=false;
05177                                           dX+=dragConstrainInitPtX-qRound(gx);
05178                                           dY+=dragConstrainInitPtY-qRound(gy);
05179                                    }
05180                                    moveGroup(dX, dY, false);
05181                                    if (Doc->SnapGuides)
05182                                    {
05183                                           double nx = gx;
05184                                           double ny = gy;
05185                                           Doc->ApplyGuides(&nx, &ny);
05186                                           moveGroup(nx-gx, ny-gy, false);
05187                                           Doc->m_Selection->setGroupRect();
05188                                           Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05189                                           nx = gx+gw;
05190                                           ny = gy+gh;
05191                                           Doc->ApplyGuides(&nx, &ny);
05192                                           moveGroup(nx-(gx+gw), ny-(gy+gh), false);
05193                                    }
05194                                    Doc->m_Selection->setGroupRect();
05195                                    if (Doc->useRaster)
05196                                    {
05197                                           Doc->m_Selection->setGroupRect();
05198                                           double gx, gy, gh, gw, gxo, gyo;
05199                                           Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05200                                           gxo = gx;
05201                                           gyo = gy;
05202                                           FPoint npx = Doc->ApplyGridF(FPoint(gx, gy));
05203                                           FPoint npw = Doc->ApplyGridF(FPoint(gx+gw, gy+gh));
05204                                           if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
05205                                                  gx = npw.x() - gw;
05206                                           else
05207                                                  gx = npx.x();
05208                                           if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
05209                                                  gy = npw.y() - gh;
05210                                           else
05211                                                  gy = npx.y();
05212                                           if ((fabs(gx - gxo) < (Doc->guidesSettings.guideRad / 2.0) / Scale) && (fabs(gy - gyo) < (Doc->guidesSettings.guideRad / 2.0) / Scale))
05213                                                  moveGroup(gx-gxo, gy-gyo, false);
05214                                           Doc->m_Selection->setGroupRect();
05215                                    }
05216                             }
05217                             if (erf)
05218                             {
05219                                    Mxp = newX;
05220                                    Myp = newY;
05221                             }
05222                      }
05223               }
05224               if ((!m_MouseButtonPressed) && (Doc->appMode != modeDrawBezierLine))
05225               {
05226                      if (Doc->m_Selection->isMultipleSelection())
05227                      {
05228                             QRect mpo = QRect(qRound(m->x()/Scale)-Doc->guidesSettings.grabRad, qRound(m->y()/Scale)-Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
05229                             mpo.moveBy(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
05230                             double gx, gy, gh, gw;
05231                             Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
05232                             if ((QRect(static_cast<int>(gx), static_cast<int>(gy), static_cast<int>(gw), static_cast<int>(gh)).intersects(mpo))
05233                                    && ((Doc->appMode == modeNormal) || (Doc->appMode == modeRotation)))
05234                             {
05235                                    int how = 0;
05236                                    gx -= Doc->minCanvasCoordinate.x();
05237                                    gy -= Doc->minCanvasCoordinate.y();
05238                                    QMap<double,int> distance;
05239                                    double d1 = sqrt(pow(((gx+gw) * Scale) - m->x(),2)+pow(((gy+gh) * Scale) - m->y(),2));
05240                                    if (d1 < Doc->guidesSettings.grabRad)
05241                                           distance.insert(d1, 1);
05242                                    double d2 = sqrt(pow((gx * Scale) - m->x(),2)+pow((gy * Scale) - m->y(),2));
05243                                    if (d2 < Doc->guidesSettings.grabRad)
05244                                           distance.insert(d2, 2);
05245                                    double d3 = sqrt(pow(((gx+gw) * Scale) - m->x(),2)+pow((gy * Scale) - m->y(),2));
05246                                    if (d3 < Doc->guidesSettings.grabRad)
05247                                           distance.insert(d3, 3);
05248                                    double d4 = sqrt(pow((gx * Scale) - m->x(),2)+pow(((gy+gh) * Scale) - m->y(),2));
05249                                    if (d4 < Doc->guidesSettings.grabRad)
05250                                           distance.insert(d4, 4);
05251                                    double d5 = sqrt(pow(((gx+gw/2) * Scale) - m->x(),2)+pow(((gy+gh) * Scale) - m->y(),2));
05252                                    if (d5 < Doc->guidesSettings.grabRad)
05253                                           distance.insert(d5, 5);
05254                                    double d6 = sqrt(pow(((gx+gw) * Scale) - m->x(),2)+pow(((gy+gh/2) * Scale) - m->y(),2));
05255                                    if (d6 < Doc->guidesSettings.grabRad)
05256                                           distance.insert(d6, 6);
05257                                    double d7 = sqrt(pow((gx * Scale) - m->x(),2)+pow(((gy+gh/2) * Scale) - m->y(),2));
05258                                    if (d7 < Doc->guidesSettings.grabRad)
05259                                           distance.insert(d7, 7);
05260                                    double d8 = sqrt(pow(((gx+gw/2) * Scale) - m->x(),2)+pow((gy * Scale) - m->y(),2));
05261                                    if (d8 < Doc->guidesSettings.grabRad)
05262                                           distance.insert(d8, 8);
05263                                    QValueList<int> result = distance.values();
05264                                    if (result.count() != 0)
05265                                    {
05266                                           how = result[0];
05267                                           switch (how)
05268                                           {
05269                                                  case 1:
05270                                                  case 2:
05271                                                         qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
05272                                                         break;
05273                                                  case 3:
05274                                                  case 4:
05275                                                         qApp->setOverrideCursor(QCursor(SizeBDiagCursor), true);
05276                                                         break;
05277                                                  case 5:
05278                                                  case 8:
05279                                                         qApp->setOverrideCursor(QCursor(SizeVerCursor), true);
05280                                                         break;
05281                                                  case 6:
05282                                                  case 7:
05283                                                         qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
05284                                                         break;
05285                                                  default:
05286                                                         qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
05287                                                         break;
05288                                           }
05289                                    }
05290                                    else
05291                                           qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
05292                                    if (Doc->appMode == modeRotation)
05293                                           qApp->setOverrideCursor(QCursor(loadIcon("Rotieren2.png")), true);
05294                             }
05295                             else
05296                             {
05297                                    switch (Doc->appMode)
05298                                    {
05299                                           case modeDrawShapes:
05300                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawFrame.xpm")), true);
05301                                                  break;
05302                                           case modeDrawPicture:
05303                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawImageFrame.xpm")), true);
05304                                                  break;
05305                                           case modeDrawText:
05306                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawTextFrame.xpm")), true);
05307                                                  break;
05308                                           case modeDrawTable:
05309                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawTable.xpm")), true);
05310                                                  break;
05311                                           case modeDrawRegularPolygon:
05312                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawPolylineFrame.xpm")), true);
05313                                                  break;
05314                                           case modeDrawLine:
05315                                           case modeDrawBezierLine:
05316                                                  qApp->setOverrideCursor(QCursor(crossCursor), true);
05317                                                  break;
05318                                           case modeDrawFreehandLine:
05319                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawFreeLine.png"), 0, 32), true);
05320                                                  break;
05321                                           default:
05322                                                  qApp->setOverrideCursor(QCursor(ArrowCursor), true);
05323                                           break;
05324                                    }
05325                             }
05326                             return;
05327                      }
05328                      for (a = 0; a < Doc->m_Selection->count(); ++a)
05329                      {
05330                             currItem = Doc->m_Selection->itemAt(a);
05331                             if (currItem->locked())
05332                                    break;
05333                             p.begin(viewport());
05334                             Transform(currItem, &p);
05335                             QRect mpo = QRect(m->x()-Doc->guidesSettings.grabRad, m->y()-Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
05336                             mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
05337                             if (Doc->EditClip)
05338                             {
05339                                    FPointArray Clip;
05340                                    QPointArray cli;
05341                                    ClRe2 = -1;
05342                                    SegP1 = -1;
05343                                    SegP2 = -1;
05344                                    if (EditContour)
05345                                           Clip = currItem->ContourLine;
05346                                    else
05347                                           Clip = currItem->PoLine;
05348                                    if ((Doc->EditClipMode == 2) || (Doc->EditClipMode == 0) || (Doc->EditClipMode == 3))
05349                                    {
05350                                           for (a=0; a<Clip.size(); ++a)
05351                                           {
05352                                                  if (((EdPoints) && (a % 2 != 0)) || ((!EdPoints) && (a % 2 == 0)))
05353                                                         continue;
05354                                                  np = p.xForm(Clip.pointQ(a));
05355                                                  tx = QRect(np.x()-3, np.y()-3, 6, 6);
05356                                                  if (tx.intersects(mpo))
05357                                                  {
05358                                                         if (Doc->EditClipMode == 0)
05359                                                                qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
05360                                                         if (Doc->EditClipMode == 2)
05361                                                                qApp->setOverrideCursor(QCursor(loadIcon("DelPoint.png"), 1, 1), true);
05362                                                         if (Doc->EditClipMode == 3)
05363                                                                qApp->setOverrideCursor(QCursor(loadIcon("Split.png"), 1, 1), true);
05364                                                         p.end();
05365                                                         return;
05366                                                  }
05367                                           }
05368                                           qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
05369                                    }
05370                                    if ((Doc->EditClipMode == 1) || (Doc->EditClipMode == 0) || (Doc->EditClipMode == 3) && (EdPoints))
05371                                    {
05372                                           for (uint poi=0; poi<Clip.size()-3; poi += 4)
05373                                           {
05374                                                  BezierPoints(&Bez, Clip.pointQ(poi), Clip.pointQ(poi+1), Clip.pointQ(poi+3), Clip.pointQ(poi+2));
05375                                                  cli = Bez.cubicBezier();
05376                                                  for (uint clp = 0; clp < cli.size()-1; ++clp)
05377                                                  {
05378                                                         if (PointOnLine(cli.point(clp), cli.point(clp+1), p.xFormDev(mpo)))
05379                                                         {
05380                                                                if (Doc->EditClipMode == 0)
05381                                                                       qApp->setOverrideCursor(QCursor(loadIcon("HandC.xpm")), true);
05382                                                                if (Doc->EditClipMode == 1)
05383                                                                       qApp->setOverrideCursor(QCursor(loadIcon("AddPoint.png"), 1, 1), true);
05384                                                                if (Doc->EditClipMode == 3)
05385                                                                       qApp->setOverrideCursor(QCursor(loadIcon("Split.png"), 1, 1), true);
05386                                                                ClRe2 = poi;
05387                                                                p.end();
05388                                                                return;
05389                                                         }
05390                                                  }
05391                                                  qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
05392                                           }
05393                                    }
05394                             }
05395                             if ((QRegion(p.xForm(QPointArray(QRect(-3, -3, static_cast<int>(currItem->width()+6), static_cast<int>(currItem->height()+6))))).contains(mpo))
05396                                    && ((Doc->appMode == modeNormal) || (Doc->appMode == modeRotation) || (Doc->appMode == modeEdit)))
05397                             {
05398                                    tx = p.xForm(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height())));
05399                                    if ((tx.intersects(mpo)) && (!currItem->locked()))
05400                                    {
05401                                           if (Doc->appMode == modeRotation)
05402                                                  qApp->setOverrideCursor(QCursor(loadIcon("Rotieren2.png")), true);
05403                                           else
05404                                           if (Doc->appMode == modeEdit)
05405                                           {
05406                                                  if (currItem->asTextFrame())
05407                                                         qApp->setOverrideCursor(QCursor(ibeamCursor), true);
05408                                                  if (currItem->asImageFrame())
05409                                                         qApp->setOverrideCursor(QCursor(loadIcon("HandC.xpm")), true);
05410                                           }
05411                                           else
05412                                                  qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
05413                                           if (!currItem->sizeLocked())
05414                                                  HandleCurs(&p, currItem, mpo);
05415                                    }
05416                             }
05417                             else
05418                             {
05419                                    switch (Doc->appMode)
05420                                    {
05421                                           case modeDrawShapes:
05422                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawFrame.xpm")), true);
05423                                                  break;
05424                                           case modeDrawPicture:
05425                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawImageFrame.xpm")), true);
05426                                                  break;
05427                                           case modeDrawText:
05428                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawTextFrame.xpm")), true);
05429                                                  break;
05430                                           case modeDrawTable:
05431                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawTable.xpm")), true);
05432                                                  break;
05433                                           case modeDrawRegularPolygon:
05434                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawPolylineFrame.xpm")), true);
05435                                                  break;
05436                                           case modeDrawLine:
05437                                           case modeDrawBezierLine:
05438                                                  qApp->setOverrideCursor(QCursor(crossCursor), true);
05439                                                  break;
05440                                           case modeDrawFreehandLine:
05441                                                  qApp->setOverrideCursor(QCursor(loadIcon("DrawFreeLine.png"), 0, 32), true);
05442                                                  break;
05443                                           default:
05444                                                  qApp->setOverrideCursor(QCursor(ArrowCursor), true);
05445                                           break;
05446                                    }
05447                             }
05448                             p.end();
05449                      }
05450               }
05451        }
05452        else
05453        {
05454               if ((m_MouseButtonPressed) && (m->state() & LeftButton) && (GyM == -1) && (GxM == -1))
05455               {
05456                      newX = qRound(translateToDoc(m->x(), m->y()).x());
05457                      if (Doc->appMode == modeMagnifier)
05458                             newY = qRound(Myp + ((SeRx - Mxp) * visibleHeight()) / visibleWidth());
05459                      else
05460                             newY = qRound(translateToDoc(m->x(), m->y()).y());
05461                      if (Doc->appMode == modeDrawTable)
05462                      {
05463                             FPoint np2 = Doc->ApplyGrid(QPoint(newX, newY));
05464                             double nx = np2.x();
05465                             double ny = np2.y();
05466                             Doc->ApplyGuides(&nx, &ny);
05467                             newX = qRound(nx);
05468                             newY = qRound(ny);
05469                             GyM = -1;
05470                             GxM = -1;
05471                      }
05472                      p.begin(viewport());
05473                      ToView(&p);
05474                      p.scale(Scale, Scale);
05475                      p.setRasterOp(XorROP);
05476                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
05477                      if (!((SeRx - Mxp == 0) && (SeRy - Myp == 0)))
05478                             p.drawRect(Mxp, Myp, SeRx-Mxp, SeRy-Myp);
05479                      p.drawRect(Mxp, Myp, newX-Mxp, newY-Myp);
05480                      p.end();
05481                      SeRx = newX;
05482                      SeRy = newY;
05483                      HaveSelRect = true;
05484                      return;
05485               }
05486               if ((Doc->guidesSettings.guidesShown) && (Doc->appMode == modeNormal) && (!Doc->GuideLock) && (Doc->OnPage(m->x()/sc, m->y()/sc) != -1) && (!GetItem(&currItem)))
05487               {
05488                      Guides::iterator it;
05489                      Guides tmpGuides = Doc->currentPage()->guides.horizontals(GuideManagerCore::Standard);
05490                      for (it = tmpGuides.begin(); it != tmpGuides.end(); ++it)
05491                      {
05492                             if (((*it)+Doc->currentPage()->yOffset()- Doc->minCanvasCoordinate.y() < ((m->y()+Doc->guidesSettings.grabRad) / sc)) &&
05493                                                            ((*it)+Doc->currentPage()->yOffset()- Doc->minCanvasCoordinate.y() > ((m->y()-Doc->guidesSettings.grabRad) / sc)))
05494                             {
05495                                    if ((m_MouseButtonPressed) && (GyM != -1))
05496                                           MoveGY = true;
05497                                    if (((m->x()/sc) < Doc->currentPage()->xOffset()- Doc->minCanvasCoordinate.x()) || ((m->x()/sc) >= Doc->currentPage()->width()-1+Doc->currentPage()->xOffset()- Doc->minCanvasCoordinate.x()))
05498                                           qApp->setOverrideCursor(QCursor(ArrowCursor), true);
05499                                    else
05500                                           qApp->setOverrideCursor(QCursor(SPLITHC), true);
05501                                    return;
05502                             }
05503                      }
05504 //                   qApp->setOverrideCursor(QCursor(ArrowCursor), true);
05505                      tmpGuides = Doc->currentPage()->guides.verticals(GuideManagerCore::Standard);
05506                      for (it = tmpGuides.begin(); it!= tmpGuides.end(); ++it)
05507                      {
05508                             if (((*it)+Doc->currentPage()->xOffset()- Doc->minCanvasCoordinate.x() < ((m->x()+Doc->guidesSettings.grabRad) / sc)) &&
05509                                                            ((*it)+Doc->currentPage()->xOffset()- Doc->minCanvasCoordinate.x() > ((m->x()-Doc->guidesSettings.grabRad) / sc)))
05510                             {
05511                                    if ((m_MouseButtonPressed) && (GxM != -1))
05512                                           MoveGX = true;
05513                                    if (((m->y()/sc) < Doc->currentPage()->yOffset()- Doc->minCanvasCoordinate.x()) || ((m->y()/sc) >= Doc->currentPage()->height()-1+Doc->currentPage()->yOffset()- Doc->minCanvasCoordinate.y()))
05514                                           qApp->setOverrideCursor(QCursor(ArrowCursor), true);
05515                                    else
05516                                           qApp->setOverrideCursor(QCursor(SPLITVC), true);
05517                                    return;
05518                             }
05519                      }
05520                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
05521               }
05522        }
05523 }
05524 
05525 void ScribusView::contentsMousePressEvent(QMouseEvent *m)
05526 {
05527        m_SnapCounter = 0;
05528        bool inText;
05529        uint a;
05530        int z;
05531        double Rxp = 0;
05532        double Ryp = 0;
05533        double Rxpd = 0;
05534        double Rypd = 0;
05535        PageItem *currItem;
05536        PageItem *bb;
05537        QPainter p;
05538        p.begin(viewport());
05539        PaintSizeRect(&p, QRect());
05540        p.end();
05541        FPoint npf, npf2;
05542        QPointArray Bez(4);
05543        QRect tx;
05544        m_MouseButtonPressed = true;
05545        operItemMoving = false;
05546        HaveSelRect = false;
05547        Doc->DragP = false;
05548        Doc->leaveDrag = false;
05549        inItemCreation = false;
05550        oldClip = 0;
05551        moveTimer.start();
05552        Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
05553        Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
05554        QRect mpo(m->x()-Doc->guidesSettings.grabRad, m->y()-Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
05555        mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
05556        if (Doc->appMode != modeEdit)
05557        {
05558               Rxp = Doc->ApplyGrid(QPoint(Mxp, Myp)).x();
05559               Rxpd = Mxp - Rxp;
05560               Mxp = qRound(Rxp);
05561               Ryp = Doc->ApplyGrid(QPoint(Mxp, Myp)).y();
05562               Rypd = Myp - Ryp;
05563               Myp = qRound(Ryp);
05564        }
05565        else
05566        {
05567               Ryp = Myp;
05568               Rxp = Mxp;
05569        }
05570        SeRx = Mxp;
05571        SeRy = Myp;
05572        if (m->button() == MidButton)
05573        {
05574               MidButt = true;
05575               DrawNew();
05576               return;
05577        }
05578        switch (Doc->appMode)
05579        {
05580               case modeNormal:
05581                      Mxp = qRound(m->x()/Scale);
05582                      Myp = qRound(m->y()/Scale);
05583                      SeRx = Mxp;
05584                      SeRy = Myp;
05585                      if ((Doc->EditClip) && (Doc->m_Selection->count() != 0))
05586                      {
05587                             currItem = Doc->m_Selection->itemAt(0);
05588                             FPointArray Clip;
05589                             bool edited = false;
05590                             bool pfound = false;
05591                             QString uAction;
05592                             if (EditContour)
05593                             {
05594                                    Clip = currItem->ContourLine;
05595                                    isContourLine = true;
05596                                    uAction = Um::EditContour;
05597                             }
05598                             else
05599                             {
05600                                    Clip = currItem->PoLine;
05601                                    isContourLine = false;
05602                                    uAction = Um::EditShape;
05603                             }
05604                             oldClip = new FPointArray(Clip);
05605                             oldItemX = currItem->xPos();
05606                             oldItemY = currItem->yPos();
05607                             undoManager->beginTransaction(currItem->getUName(), currItem->getUPixmap(), uAction);
05608                             p.begin(viewport());
05609                             p.translate(qRound(-Doc->minCanvasCoordinate.x()*Scale), qRound(-Doc->minCanvasCoordinate.y()*Scale));
05610                             Transform(currItem, &p);
05611                             npf2 = FPoint(p.xFormDev(m->pos()));
05612                             p.end();
05613                             p.begin(viewport());
05614                             Transform(currItem, &p);
05615                             ClRe = -1;
05616                             for (a=0; a<Clip.size(); ++a)
05617                             {
05618                                    if (((EdPoints) && (a % 2 != 0)) || ((!EdPoints) && (a % 2 == 0)))
05619                                           continue;
05620                                    npf = FPoint(p.xForm(Clip.pointQ(a)));
05621                                    tx = QRect(static_cast<int>(npf.x()-3), static_cast<int>(npf.y()-3), 6, 6);
05622                                    if (tx.intersects(mpo))
05623                                    {
05624                                           ClRe = a;
05625                                           if ((EdPoints) && (SelNode.contains(a) == 0))
05626                                           {
05627                                                  if (m->state() == ShiftButton)
05628                                                         SelNode.append(a);
05629                                                  else
05630                                                  {
05631                                                         SelNode.clear();
05632                                                         SelNode.append(a);
05633                                                  }
05634                                           }
05635                                           emit ClipPo(Clip.point(a).x(), Clip.point(a).y());
05636                                           pfound = true;
05637                                           break;
05638                                    }
05639                             }
05640                             if ((!pfound) || (!EdPoints))
05641                                    SelNode.clear();
05642                             p.end();
05643                             if ((Doc->EditClipMode == 0) && (ClRe2 != -1) && (ClRe == -1))
05644                             {
05645                                    SegP1 = ClRe2;
05646                                    SegP2 = ClRe2+2;
05647                                    ClRe = ClRe2;
05648                             }
05649                             FPointArray cli;
05650                             uint EndInd = Clip.size();
05651                             uint StartInd = 0;
05652                             for (uint n = ClRe; n < Clip.size(); ++n)
05653                             {
05654                                    if (Clip.point(n).x() > 900000)
05655                                    {
05656                                           EndInd = n;
05657                                           break;
05658                                    }
05659                             }
05660                             if (ClRe > 0)
05661                             {
05662                                    for (uint n2 = ClRe; n2 > 0; n2--)
05663                                    {
05664                                           if (n2 == 0)
05665                                                  break;
05666                                           if (Clip.point(n2).x() > 900000)
05667                                           {
05668                                                  StartInd = n2 + 1;
05669                                                  break;
05670                                           }
05671                                    }
05672                             }
05673                             if (Doc->EditClipMode == 3)
05674                             {
05675                                    if (!EdPoints)
05676                                           return;
05677                                    if (ClRe == -1)      // We don't have a Point, try to add one onto the current curve segment
05678                                    {
05679                                           bool foundP = false;
05680                                           QPointArray Bez(4);
05681                                           uint seg = 0;
05682                                           double absDist = 9999999999.9;
05683                                           FPoint point = FPoint(0, 0);
05684                                           FPoint normal = FPoint(0, 0);
05685                                           FPoint tangent = FPoint(0, 0);
05686                                           FPoint nearPoint = FPoint(0, 0);
05687                                           double nearT = 0.0;
05688                                           QRect mpo2(0, 0, Doc->guidesSettings.grabRad*3, Doc->guidesSettings.grabRad*3);
05689                                           mpo2.moveCenter(QPoint(qRound(npf2.x()), qRound(npf2.y())));
05690                                           for (uint poi=0; poi<Clip.size()-3; poi += 4)
05691                                           {
05692                                                  BezierPoints(&Bez, Clip.pointQ(poi), Clip.pointQ(poi+1), Clip.pointQ(poi+3), Clip.pointQ(poi+2));
05693                                                  QPointArray cli2 = Bez.cubicBezier();
05694                                                  for (uint clp = 0; clp < cli2.size()-1; ++clp)
05695                                                  {
05696                                                         if (PointOnLine(cli2.point(clp), cli2.point(clp+1), mpo2))
05697                                                         {
05698                                                                seg = poi;
05699                                                                double sp = 0.0;
05700                                                                double spadd = 1.0 / (Clip.lenPathSeg(seg) * Scale);
05701                                                                while (sp < 1.0)
05702                                                                {
05703                                                                       Clip.pointTangentNormalAt(seg, sp, &point, &tangent, &normal );
05704                                                                       double d1 = fabs(sqrt(pow(point.x() - npf2.x(), 2) + pow(point.y() - npf2.y() ,2)));
05705                                                                       if (d1 < absDist)
05706                                                                       {
05707                                                                              foundP = true;
05708                                                                              nearPoint = point;
05709                                                                              nearT = sp;
05710                                                                              absDist = d1;
05711                                                                       }
05712                                                                       sp += spadd;
05713                                                                }
05714                                                         }
05715                                                  }
05716                                           }
05717                                           cli.putPoints(0, ClRe2+2, Clip);
05718                                           if (foundP)
05719                                           {
05720                                                  npf2 = nearPoint;
05721                                                  FPoint base = cli.point(cli.size()-2);
05722                                                  FPoint c1 = cli.point(cli.size()-1);
05723                                                  FPoint base2 =  Clip.point(ClRe2+2);
05724                                                  FPoint c2 = Clip.point(ClRe2+3);
05725                                                  if ((base == c1) && (base2 == c2))
05726                                                  {
05727                                                         cli.resize(cli.size()+4);
05728                                                         cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y());
05729                                                         cli.putPoints(cli.size(), Clip.size()-(ClRe2 + 2), Clip, ClRe2+2);
05730                                                  }
05731                                                  else
05732                                                  {
05733                                                         FPoint cn1 = (1.0 - nearT) * base + nearT * c1;
05734                                                         FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2);
05735                                                         FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2);
05736                                                         FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2;
05737                                                         cli.setPoint(cli.size()-1, cn1);
05738                                                         cli.resize(cli.size()+4);
05739                                                         uint basind = cli.size()+1;
05740                                                         cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), cn2.x(), cn2.y(), npf2.x(), npf2.y(), cn3.x(), cn3.y());
05741                                                         cli.putPoints(cli.size(), Clip.size()-(ClRe2 + 2), Clip, ClRe2+2);
05742                                                         cli.setPoint(basind, cn4);
05743                                                  }
05744                                                  Clip = cli.copy();
05745                                                  cli.resize(0);
05746                                                  ClRe = ClRe2+2;
05747                                                  ClRe2 = -1;
05748                                                  EndInd = Clip.size();
05749                                                  StartInd = 0;
05750                                                  for (uint n = ClRe; n < Clip.size(); ++n)
05751                                                  {
05752                                                         if (Clip.point(n).x() > 900000)
05753                                                         {
05754                                                                EndInd = n;
05755                                                                break;
05756                                                         }
05757                                                  }
05758                                                  if (ClRe > 0)
05759                                                  {
05760                                                         for (uint n2 = ClRe; n2 > 0; n2--)
05761                                                         {
05762                                                                if (n2 == 0)
05763                                                                       break;
05764                                                                if (Clip.point(n2).x() > 900000)
05765                                                                {
05766                                                                       StartInd = n2 + 1;
05767                                                                       break;
05768                                                                }
05769                                                         }
05770                                                  }
05771                                           }
05772                                           else
05773                                                  ClRe = -1;
05774                                    }
05775                                    if (ClRe != -1)
05776                                    {
05777                                           if (currItem->asPolygon())
05778                                           {
05779                                                  if ((ClRe != 0) && (ClRe != static_cast<int>(EndInd-2)))
05780                                                  {
05781                                                         if (currItem->Segments.count() == 0)
05782                                                         {
05783                                                                cli.putPoints(0, EndInd-(ClRe+2), Clip, ClRe+2);
05784                                                                cli.putPoints(cli.size(), ClRe+2, Clip);
05785                                                         }
05786                                                         else
05787                                                         {
05788                                                                cli.putPoints(0, EndInd-StartInd, Clip, StartInd);
05789                                                                z = Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, currItem->xPos(), currItem->yPos(), currItem->width(), currItem->height(), currItem->lineWidth(), currItem->fillColor(), currItem->lineColor(), true);
05790                                                                bb = Doc->Items->at(z);
05791                                                                if (EditContour)
05792                                                                       bb->ContourLine.resize(0);
05793                                                                else
05794                                                                       bb->PoLine.resize(0);
05795                                                                if (StartInd != 0)
05796                                                                {
05797                                                                       if (EditContour)
05798                                                                       {
05799                                                                              bb->ContourLine.putPoints(0, StartInd - 4, Clip);
05800                                                                              bb->ContourLine.putPoints(bb->ContourLine.size(), Clip.size()-EndInd, Clip, EndInd);
05801                                                                       }
05802                                                                       else
05803                                                                       {
05804                                                                              bb->PoLine.putPoints(0, StartInd - 4, Clip);
05805                                                                              bb->PoLine.putPoints(bb->PoLine.size(), Clip.size()-EndInd, Clip, EndInd);
05806                                                                       }
05807                                                                }
05808                                                                else
05809                                                                {
05810                                                                       if (EditContour)
05811                                                                              bb->ContourLine.putPoints(0, Clip.size()-EndInd-4, Clip, EndInd+4);
05812                                                                       else
05813                                                                              bb->PoLine.putPoints(0, Clip.size()-EndInd-4, Clip, EndInd+4);
05814                                                                }
05815                                                                bb->setRotation(currItem->rotation());
05816                                                                Doc->AdjustItemSize(bb);
05817                                                                bb->ClipEdited = true;
05818                                                                PageItem *bx = Doc->Items->take(bb->ItemNr);
05819                                                                Doc->Items->insert(bb->ItemNr-1, bx);
05820                                                         }
05821                                                         currItem->PoLine = cli.copy();
05822                                                  }
05823                                                  ClRe = -1;
05824                                                  currItem->ClipEdited = true;
05825                                                  edited = true;
05826                                                  Doc->EditClipMode = 0;
05827                                                  PageItem* newItem=Doc->convertItemTo(currItem, PageItem::PolyLine);
05828                                                  currItem=newItem;
05829                                                  emit PolyOpen();
05830                                           }
05831                                           else
05832                                           {
05833                                                  if ((currItem->asPolyLine()) || (currItem->asPathText()))
05834                                                  {
05835                                                         if ((ClRe > 1) && (ClRe < static_cast<int>(Clip.size()-2)))
05836                                                         {
05837                                                                z = Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, currItem->xPos(), currItem->yPos(), currItem->width(), currItem->height(), currItem->lineWidth(), currItem->fillColor(), currItem->lineColor(), true);
05838                                                                bb = Doc->Items->at(z);
05839                                                                if (EditContour)
05840                                                                       bb->ContourLine.putPoints(0, Clip.size()-(ClRe+2), Clip, ClRe+2);
05841                                                                else
05842                                                                       bb->PoLine.putPoints(0, Clip.size()-(ClRe+2), Clip, ClRe+2);
05843                                                                bb->setRotation(currItem->rotation());
05844                                                                Doc->AdjustItemSize(bb);
05845                                                                bb->ClipEdited = true;
05846                                                                cli.resize(0);
05847                                                                cli.putPoints(0, ClRe+2, Clip);
05848                                                                currItem->PoLine = cli.copy();
05849                                                         }
05850                                                         ClRe = -1;
05851                                                         currItem->ClipEdited = true;
05852                                                         edited = true;
05853                                                         Doc->EditClipMode = 0;
05854                                                         currItem->setPolyClip(qRound(QMAX(currItem->lineWidth() / 2.0, 1)));
05855                                                         emit PolyOpen();
05856                                                  }
05857                                           }
05858                                    }
05859                             }
05860                             if ((Doc->EditClipMode == 2) && (ClRe != -1))
05861                             {
05862                                    if (!EdPoints)
05863                                           return;
05864                                    if ((currItem->asPolygon()) || (currItem->asTextFrame()) || (currItem->asImageFrame()))
05865                                    {
05866                                           if ((currItem->Segments.count() == 0) && (Clip.size() < 13))
05867                                                  return;
05868                                    }
05869                                    else
05870                                    {
05871                                           if (Clip.size() < 5)
05872                                                  return;
05873                                    }
05874                                    if ((currItem->Segments.count() != 0) && ((EndInd - StartInd) < 13))
05875                                    {
05876                                           if (StartInd != 0)
05877                                                  cli.putPoints(0, StartInd-4, Clip);
05878                                           cli.putPoints(cli.size(), Clip.size() - EndInd, Clip, EndInd);
05879                                    }
05880                                    else
05881                                    {
05882                                           if (ClRe == static_cast<int>(StartInd))
05883                                           {
05884                                                  if ((currItem->asPolygon()) || (currItem->asTextFrame()) || (currItem->asImageFrame()))
05885                                                  {
05886                                                         FPoint kp(Clip.point(EndInd-3));
05887                                                         cli.putPoints(0, StartInd, Clip);
05888                                                         cli.putPoints(cli.size(), EndInd - StartInd - 4, Clip, StartInd);
05889                                                         cli.setPoint(StartInd, cli.point(cli.size()-2));
05890                                                         cli.setPoint(StartInd + 1, kp);
05891                                                         cli.putPoints(cli.size(), Clip.size() - EndInd, Clip, EndInd);
05892                                                  }
05893                                                  else
05894                                                  {
05895                                                         cli.putPoints(0, StartInd, Clip);
05896                                                         cli.putPoints(cli.size(), EndInd - StartInd - 4, Clip, StartInd+4);
05897                                                         cli.putPoints(cli.size(), Clip.size() - EndInd, Clip, EndInd);
05898                                                  }
05899                                           }
05900                                           else
05901                                           {
05902                                                  if (ClRe != 0)
05903                                                         cli.putPoints(0, ClRe, Clip);
05904                                                  cli.putPoints(cli.size(), Clip.size()-(ClRe + 4), Clip, ClRe+4);
05905                                           }
05906                                    }
05907                                    if (EditContour)
05908                                           currItem->ContourLine = cli.copy();
05909                                    else
05910                                           currItem->PoLine = cli.copy();
05911                                    ClRe = -1;
05912                                    currItem->ClipEdited = true;
05913                                    edited = true;
05914                             }
05915                             if ((Doc->EditClipMode == 1) && (ClRe2 != -1))
05916                             {
05917                                    bool foundP = false;
05918                                    QPointArray Bez(4);
05919                                    uint seg = 0;
05920                                    double absDist = 9999999999.9;
05921                                    FPoint point = FPoint(0, 0);
05922                                    FPoint normal = FPoint(0, 0);
05923                                    FPoint tangent = FPoint(0, 0);
05924                                    FPoint nearPoint = FPoint(0, 0);
05925                                    double nearT = 0.0;
05926                                    QRect mpo2(0, 0, Doc->guidesSettings.grabRad*3, Doc->guidesSettings.grabRad*3);
05927                                    mpo2.moveCenter(QPoint(qRound(npf2.x()), qRound(npf2.y())));
05928                                    for (uint poi=0; poi<Clip.size()-3; poi += 4)
05929                                    {
05930                                           BezierPoints(&Bez, Clip.pointQ(poi), Clip.pointQ(poi+1), Clip.pointQ(poi+3), Clip.pointQ(poi+2));
05931                                           QPointArray cli2 = Bez.cubicBezier();
05932                                           for (uint clp = 0; clp < cli2.size()-1; ++clp)
05933                                           {
05934                                                  if (PointOnLine(cli2.point(clp), cli2.point(clp+1), mpo2))
05935                                                  {
05936                                                         seg = poi;
05937                                                         double sp = 0.0;
05938                                                         double spadd = 1.0 / (Clip.lenPathSeg(seg) * Scale);
05939                                                         while (sp < 1.0)
05940                                                         {
05941                                                                Clip.pointTangentNormalAt(seg, sp, &point, &tangent, &normal );
05942                                                                double d1 = fabs(sqrt(pow(point.x() - npf2.x(), 2) + pow(point.y() - npf2.y() ,2)));
05943                                                                if (d1 < absDist)
05944                                                                {
05945                                                                       foundP = true;
05946                                                                       nearPoint = point;
05947                                                                       nearT = sp;
05948                                                                       absDist = d1;
05949                                                                }
05950                                                                sp += spadd;
05951                                                         }
05952                                                  }
05953                                           }
05954                                    }
05955                                    cli.putPoints(0, ClRe2+2, Clip);
05956                                    if (foundP)
05957                                    {
05958                                           npf2 = nearPoint;
05959                                           FPoint base = cli.point(cli.size()-2);
05960                                           FPoint c1 = cli.point(cli.size()-1);
05961                                           FPoint base2 =  Clip.point(ClRe2+2);
05962                                           FPoint c2 = Clip.point(ClRe2+3);
05963                                           if ((base == c1) && (base2 == c2))
05964                                           {
05965                                                  cli.resize(cli.size()+4);
05966                                                  cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y());
05967                                                  cli.putPoints(cli.size(), Clip.size()-(ClRe2 + 2), Clip, ClRe2+2);
05968                                           }
05969                                           else
05970                                           {
05971                                                  FPoint cn1 = (1.0 - nearT) * base + nearT * c1;
05972                                                  FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2);
05973                                                  FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2);
05974                                                  FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2;
05975                                                  cli.setPoint(cli.size()-1, cn1);
05976                                                  cli.resize(cli.size()+4);
05977                                                  uint basind = cli.size()+1;
05978                                                  cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), cn2.x(), cn2.y(), npf2.x(), npf2.y(), cn3.x(), cn3.y());
05979                                                  cli.putPoints(cli.size(), Clip.size()-(ClRe2 + 2), Clip, ClRe2+2);
05980                                                  cli.setPoint(basind, cn4);
05981                                           }
05982                                    }
05983                                    else
05984                                    {
05985                                           cli.resize(cli.size()+4);
05986                                           cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y());
05987                                           cli.putPoints(cli.size(), Clip.size()-(ClRe2 + 2), Clip, ClRe2+2);
05988                                    }
05989                                    if (EditContour)
05990                                           currItem->ContourLine = cli.copy();
05991                                    else
05992                                           currItem->PoLine = cli.copy();
05993                                    ClRe2 = -1;
05994                                    currItem->ClipEdited = true;
05995                                    edited = true;
05996                             }
05997                             if (edited)
05998                             {
05999                                    currItem->FrameType = 3;
06000 //                                 if (!currItem->asPolyLine())
06001 //                                        currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
06002                                    Doc->AdjustItemSize(currItem);
06003                                    updateContents();
06004                                    if (EditContour)
06005                                           MarkClip(currItem, currItem->ContourLine, true);
06006                                    else
06007                                           MarkClip(currItem, currItem->PoLine, true);
06008                                    emit DocChanged();
06009                             }
06010                             if ((SelNode.count() != 0) || ((SegP1 != -1) && (SegP2 != -1)) || ((ClRe != -1) && (!EdPoints)))
06011                             {
06012                                    Mxp = m->x();
06013                                    Myp = m->y();
06014                             }
06015                             return;
06016                      }
06017                      if (GetItem(&currItem))
06018                      {
06019                             if (Doc->m_Selection->isMultipleSelection())
06020                             {
06021                                    p.begin(viewport());
06022                                    QRect ne = QRect();
06023                                    PaintSizeRect(&p, ne);
06024                                    p.end();
06025                                    double gx, gy, gh, gw;
06026                                    bool shiftSel = true;
06027                                    Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
06028                                    dragConstrainInitPtX = qRound(gx);
06029                                    dragConstrainInitPtY = qRound(gy);
06030                                    mpo = QRect(qRound(m->x() / Scale) - Doc->guidesSettings.grabRad, qRound(m->y() / Scale) - Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
06031                                    mpo.moveBy(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
06032                                    if ((QRect(static_cast<int>(gx), static_cast<int>(gy), static_cast<int>(gw), static_cast<int>(gh)).intersects(mpo))
06033                                          && (m->state() != (ControlButton | AltButton)) && (m->state() != ShiftButton))
06034                                    {
06035                                           frameResizeHandle = 0;
06036                                           QMap<double,int> distance;
06037                                           gx -= Doc->minCanvasCoordinate.x();
06038                                           gy -= Doc->minCanvasCoordinate.y();
06039                                           double d1 = sqrt(pow(((gx+gw) * Scale) - m->x(),2)+pow(((gy+gh) * Scale) - m->y(),2));
06040                                           if (d1 < Doc->guidesSettings.grabRad)
06041                                                  distance.insert(d1, 1);
06042                                           double d2 = sqrt(pow((gx * Scale) - m->x(),2)+pow((gy * Scale) - m->y(),2));
06043                                           if (d2 < Doc->guidesSettings.grabRad)
06044                                                  distance.insert(d2, 2);
06045                                           double d3 = sqrt(pow(((gx+gw) * Scale) - m->x(),2)+pow((gy * Scale) - m->y(),2));
06046                                           if (d3 < Doc->guidesSettings.grabRad)
06047                                                  distance.insert(d3, 3);
06048                                           double d4 = sqrt(pow((gx * Scale) - m->x(),2)+pow(((gy+gh) * Scale) - m->y(),2));
06049                                           if (d4 < Doc->guidesSettings.grabRad)
06050                                                  distance.insert(d4, 4);
06051                                           double d5 = sqrt(pow(((gx+gw/2) * Scale) - m->x(),2)+pow(((gy+gh) * Scale) - m->y(),2));
06052                                           if (d5 < Doc->guidesSettings.grabRad)
06053                                                  distance.insert(d5, 5);
06054                                           double d6 = sqrt(pow(((gx+gw) * Scale) - m->x(),2)+pow(((gy+gh/2) * Scale) - m->y(),2));
06055                                           if (d6 < Doc->guidesSettings.grabRad)
06056                                                  distance.insert(d6, 6);
06057                                           double d7 = sqrt(pow((gx * Scale) - m->x(),2)+pow(((gy+gh/2) * Scale) - m->y(),2));
06058                                           if (d7 < Doc->guidesSettings.grabRad)
06059                                                  distance.insert(d7, 7);
06060                                           double d8 = sqrt(pow(((gx+gw/2) * Scale) - m->x(),2)+pow((gy * Scale) - m->y(),2));
06061                                           if (d8 < Doc->guidesSettings.grabRad)
06062                                                  distance.insert(d8, 8);
06063                                           QValueList<int> result = distance.values();
06064                                           if (result.count() != 0)
06065                                           {
06066                                                  frameResizeHandle = result[0];
06067                                                  switch (frameResizeHandle)
06068                                                  {
06069                                                         case 1:
06070                                                         case 2:
06071                                                                qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
06072                                                                break;
06073                                                         case 3:
06074                                                         case 4:
06075                                                                qApp->setOverrideCursor(QCursor(SizeBDiagCursor), true);
06076                                                                break;
06077                                                         case 5:
06078                                                         case 8:
06079                                                                qApp->setOverrideCursor(QCursor(SizeVerCursor), true);
06080                                                                break;
06081                                                         case 6:
06082                                                         case 7:
06083                                                                qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
06084                                                                break;
06085                                                  }
06086                                           }
06087                                           if (currItem->sizeLocked())
06088                                           {
06089                                                  qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
06090                                                  frameResizeHandle = 0;
06091                                           }
06092                                           if (frameResizeHandle != 0)
06093                                                  operItemResizing = true;
06094                                    }
06095                                    else
06096                                           shiftSel = SeleItem(m);
06097                                    if (((Doc->m_Selection->count() == 0) || (!shiftSel)) && (m->state() == ShiftButton))
06098                                    {
06099                                           shiftSelItems = true;
06100                                           Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
06101                                           Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
06102                                           SeRx = Mxp;
06103                                           SeRy = Myp;
06104                                    }
06105                                    else
06106                                           shiftSelItems = false;
06107                             }
06108                             else
06109                             {
06110                                    dragConstrainInitPtX = qRound(currItem->xPos());
06111                                    dragConstrainInitPtY = qRound(currItem->yPos());
06112                                    SeleItem(m); //Where we send the mouse press event to select an item
06113                                    if (Doc->m_Selection->count() != 0)
06114                                    {
06115                                           currItem = Doc->m_Selection->itemAt(0);
06116                                           p.begin(viewport());
06117                                           Transform(currItem, &p);
06118                                           if (!currItem->locked())
06119                                           {
06120                                                  HandleSizer(&p, currItem, mpo, m);
06121                                                  if (frameResizeHandle != 0)
06122                                                  {
06123                                                         if (!currItem->asLine())
06124                                                                currItem->Sizing = true;
06125                                                         operItemResizing = true;
06126                                                  }
06127                                           }
06128                                           p.end();
06129                                    }
06130                                    else
06131                                    {
06132                                           Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
06133                                           Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
06134                                           SeRx = Mxp;
06135                                           SeRy = Myp;
06136                                    }
06137                             }
06138                      }
06139                      else
06140                      {
06141                             SeleItem(m);
06142                             if (Doc->m_Selection->count() == 0)
06143                             {
06144                                    Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
06145                                    Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
06146                                    SeRx = Mxp;
06147                                    SeRy = Myp;
06148                             }
06149                      }
06150 /*                   if (m->button() == MidButton)
06151                      {
06152                             MidButt = true;
06153                             if (Doc->m_Selection->count() != 0)
06154                                    Deselect(true);
06155                             DrawNew();
06156                      } */
06157                      if ((Doc->m_Selection->count() != 0) && (m->button() == RightButton))
06158                      {
06159                             m_MouseButtonPressed = true;
06160                             Dxp = Mxp;
06161                             Dyp = Myp;
06162                      }
06163                      break;
06164               case modeDrawShapes:
06165                      if (m->button() != LeftButton)
06166                             break;
06167                      selectPage(m);
06168                      switch (Doc->SubMode)
06169                      {
06170                      case 0:
06171                             if (m->state() == ShiftButton)
06172                             {
06173                                    z = Doc->itemAddArea(PageItem::Polygon, PageItem::Rectangle, Rxp, Ryp, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06174                                    Doc->Items->at(z)->FrameType = 0;
06175                                    SetupDrawNoResize(z);
06176                             }
06177                             else
06178                             {
06179                                    Doc->ApplyGuides(&Rxp, &Ryp);
06180                                    z = Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06181                                    Doc->Items->at(z)->FrameType = 0;
06182                                    SetupDraw(z);
06183                             }
06184                             break;
06185                      case 1:
06186                             if (m->state() == ShiftButton)
06187                             {
06188                                    z = Doc->itemAddArea(PageItem::Polygon, PageItem::Ellipse, Rxp, Ryp, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06189                                    Doc->Items->at(z)->FrameType = 1;
06190                                    SetupDrawNoResize(z);
06191                             }
06192                             else
06193                             {
06194                                    Doc->ApplyGuides(&Rxp, &Ryp);
06195                                    z = Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06196                                    Doc->Items->at(z)->FrameType = 1;
06197                                    SetupDraw(z);
06198                             }
06199                             break;
06200                      default:
06201                             if (m->state() == ShiftButton)
06202                             {
06203                                    z = Doc->itemAddArea(PageItem::Polygon, PageItem::Unspecified, Rxp, Ryp, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06204                                    Doc->Items->at(z)->SetFrameShape(Doc->ValCount, Doc->ShapeValues);
06205                                    Doc->setRedrawBounding(Doc->Items->at(z));
06206                                    Doc->Items->at(z)->FrameType = Doc->SubMode+2;
06207                                    SetupDrawNoResize(z);
06208                             }
06209                             else
06210                             {
06211                                    Doc->ApplyGuides(&Rxp, &Ryp);
06212                                    z = Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06213                                    Doc->Items->at(z)->SetFrameShape(Doc->ValCount, Doc->ShapeValues);
06214                                    Doc->setRedrawBounding(Doc->Items->at(z));
06215                                    Doc->Items->at(z)->FrameType = Doc->SubMode+2;
06216                                    SetupDraw(z);
06217                             }
06218                             break;
06219                      }
06220                      break;
06221               case modeDrawPicture:
06222                      if (m->button() != LeftButton)
06223                             break;
06224                      selectPage(m);
06225                      if (m->state() == ShiftButton)
06226                      {
06227                             z = Doc->itemAddArea(PageItem::ImageFrame, PageItem::Unspecified, Rxp, Ryp, 1, Doc->toolSettings.dBrushPict, CommonStrings::None, !m_MouseButtonPressed);
06228                             SetupDrawNoResize(z);
06229                      }
06230                      else
06231                      {
06232                             Doc->ApplyGuides(&Rxp, &Ryp);
06233                             z = Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, 1, Doc->toolSettings.dBrushPict, CommonStrings::None, !m_MouseButtonPressed);
06234                             SetupDraw(z);
06235                      }
06236                      break;
06237               case modeDrawText:
06238                      if (m->button() != LeftButton)
06239                             break;
06240                      selectPage(m);
06241                      if (m->state() == ShiftButton)
06242                      {
06243                             z = Doc->itemAddArea(PageItem::TextFrame, PageItem::Unspecified, Rxp, Ryp, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenText, !m_MouseButtonPressed);
06244                             SetupDrawNoResize(z);
06245                      }      
06246                      else
06247                      {
06248                             Doc->ApplyGuides(&Rxp, &Ryp);
06249                             z = Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenText, !m_MouseButtonPressed);
06250                             SetupDraw(z);
06251                      }
06252                      break;
06253               case modeMagnifier:
06254                      m_MouseButtonPressed = true;
06255                      if ((m->state() == ShiftButton) || (m->button() == RightButton))
06256                      {
06257                             Magnify = false;
06258                             qApp->setOverrideCursor(QCursor(loadIcon("LupeZm.xpm")), true);
06259                      }
06260                      else
06261                      {
06262                             Magnify = true;
06263                             qApp->setOverrideCursor(QCursor(loadIcon("LupeZ.xpm")), true);
06264                      }
06265                      Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
06266                      Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
06267                      SeRx = Mxp;
06268                      SeRy = Myp;
06269                      break;
06270               case modeEdit:
06271                      {
06272                             frameResizeHandle = 0;
06273                             operItemResizeInEditMode = false;
06274                             int oldP=0;
06275                             if (GetItem(&currItem))
06276                             {
06277                                    slotDoCurs(false);
06278                                    if (!currItem->locked())
06279                                    {
06280                                           p.begin(viewport());
06281                                           Transform(currItem, &p);
06282                                           HandleSizer(&p, currItem, mpo, m);
06283                                           tx = p.xForm(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height())));
06284                                           p.end();
06285                                           if (frameResizeHandle != 0)
06286                                           {
06287                                                  operItemResizeInEditMode = true;
06288                                                  slotDoCurs(true);
06289                                                  return;
06290                                           }
06291                                    }
06292                                    oldP = currItem->CPos;
06293                             }
06294                             //CB Where we set the cursor for a click in text frame
06295                             inText = slotSetCurs(m->x(), m->y());
06296                             //CB If we clicked outside a text frame to go out of edit mode and deselect the frame
06297                             if (!inText)
06298                             {
06299                                    //<<CB Redraw subsequent frames after being in edit mode
06300                                    //No intelligence, may slow things down when drawing unnecessarily
06301                                    PageItem *nextItem=currItem;
06302                                    while (nextItem != 0)
06303                                    {
06304                                           if (nextItem->nextInChain() != 0)
06305                                           {
06306                                                  nextItem = nextItem->nextInChain();
06307                                                  RefreshItem(nextItem);
06308                                           }
06309                                           else
06310                                                  break;
06311                                    }
06312                                    //>>
06313                                    Deselect(true);
06314                                    slotDoCurs(true);
06315                                    emit Amode(modeNormal);
06316                                    return;
06317                             }
06318                             //<<CB Add in shift select to text frames
06319                             if (m->state() & Qt::ShiftButton)
06320                             {
06321                                    int dir=1;
06322                                    if (oldCp>currItem->CPos)
06323                                           dir=-1;
06324                                    if (currItem->asTextFrame())
06325                                           currItem->asTextFrame()->ExpandSel(dir, oldP);
06326                                    oldCp = oldP;
06327                             }
06328                             else //>>CB
06329                                    oldCp = currItem->CPos;
06330                             currItem = Doc->m_Selection->itemAt(0);
06331                             slotDoCurs(true);
06332                             if ((!inText) && ((currItem->asTextFrame()) || (currItem->asImageFrame())))
06333                             {
06334                                    Deselect(true);
06335                                    if (SeleItem(m))
06336                                    {
06337                                           currItem = Doc->m_Selection->itemAt(0);
06338                                           if ((currItem->asTextFrame()) || (currItem->asImageFrame()))
06339                                                  emit Amode(modeEdit);
06340                                           else
06341                                           {
06342                                                  emit PaintingDone();
06343                                                  qApp->setOverrideCursor(QCursor(ArrowCursor), true);
06344                                           }
06345                                    }
06346                                    else
06347                                    {
06348                                           emit PaintingDone();
06349                                           qApp->setOverrideCursor(QCursor(ArrowCursor), true);
06350                                    }
06351                             }
06352                             else
06353                             {
06354                                    if ((m->button() == MidButton) && (currItem->asTextFrame()))
06355                                    {
06356                                           m_MouseButtonPressed = false;
06357                                           MidButt = false;
06358                                           QString cc;
06359                                           cc = QApplication::clipboard()->text(QClipboard::Selection);
06360                                           if (cc.isNull())
06361                                                  cc = QApplication::clipboard()->text(QClipboard::Clipboard);
06362                                           if (!cc.isNull())
06363                                           {
06364                                                  // K.I.S.S.:
06365                                                  currItem->itemText.insertChars(0, cc, true);
06366                                                  if (Doc->docHyphenator->AutoCheck)
06367                                                         Doc->docHyphenator->slotHyphenate(currItem);
06368                                                  emit ChBMText(currItem);
06369 //                                               m_ScMW->outlinePalette->BuildTree();
06370                                           }
06371                                           else
06372                                           {
06373                                                  if (m_ScMW->Buffer2.startsWith("<SCRIBUSTEXT"))
06374                                                         m_ScMW->slotEditPaste();
06375                                           }
06376                                           RefreshItem(currItem);
06377                                    }
06378                                    if (currItem->asImageFrame() && !tx.contains(m->x(), m->y()))
06379                                    {
06380                                           Deselect(true);
06381                                           if (SeleItem(m))
06382                                           {
06383                                                  currItem = Doc->m_Selection->itemAt(0);
06384                                                  if ((currItem->asTextFrame()) || (currItem->asImageFrame()))
06385                                                         emit Amode(modeEdit);
06386                                                  else
06387                                                  {
06388                                                         emit PaintingDone();
06389                                                         qApp->setOverrideCursor(QCursor(ArrowCursor), true);
06390                                                  }
06391                                           }
06392                                           else
06393                                           {
06394                                                  emit PaintingDone();
06395                                                  qApp->setOverrideCursor(QCursor(ArrowCursor), true);
06396                                           }
06397                                    }
06398                             }
06399                      }
06400                      break;
06401               case modeDrawLine:
06402                      if (m->button() != LeftButton)
06403                             break;
06404                      selectPage(m);
06405                      Doc->ApplyGuides(&Rxp, &Ryp);
06406                      z = Doc->itemAdd(PageItem::Line, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, Rypd, Doc->toolSettings.dWidthLine, CommonStrings::None, Doc->toolSettings.dPenLine, !m_MouseButtonPressed);
06407                      currItem = Doc->Items->at(z);
06408                      qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
06409                      Doc->m_Selection->clear();
06410                      Doc->m_Selection->addItem(currItem);
06411                      currItem->paintObj();
06412                      operItemMoving = true;
06413                      inItemCreation = true;
06414                      break;
06415               case modeRotation:
06416                      if (m->button() != LeftButton)
06417                             break;
06418                      if (GetItem(&currItem))
06419                      {
06420                             RotMode = Doc->RotMode;
06421                             if (Doc->m_Selection->isMultipleSelection())
06422                             {
06423                                    double gx, gy, gh, gw;
06424                                    double gxR, gyR, ghR, gwR;
06425                                    getGroupRectScreen(&gx, &gy, &gw, &gh);
06426                                    Doc->m_Selection->getGroupRect(&gxR, &gyR, &gwR, &ghR);
06427                                    if (QRect(static_cast<int>(gx), static_cast<int>(gy), static_cast<int>(gw), static_cast<int>(gh)).intersects(mpo))
06428                                    {
06429                                           Doc->RotMode = 2;
06430                                           RCenter = FPoint(gxR+gwR/2.0, gyR+ghR/2.0);
06431                                           if (QRect(static_cast<int>(gx+gw)-6, static_cast<int>(gy+gh)-6, 6, 6).intersects(mpo))
06432                                           {
06433                                                  RCenter = FPoint(gxR, gyR);
06434                                                  Doc->RotMode = 0;
06435                                           }
06436                                    }
06437                                    oldW = xy2Deg(m->x()/Scale - RCenter.x(), m->y()/Scale - RCenter.y());
06438                             }
06439                             else
06440                             {
06441                                    p.begin(viewport());
06442                                    Transform(currItem, &p);
06443                                    Doc->RotMode = 2;
06444 //                                 RCenter = FPoint(currItem->xPos()+currItem->width()/2, currItem->yPos()+currItem->height()/2, 0, 0, currItem->rotation(), 1, 1, true);
06445                                    RCenter = FPoint(currItem->width()/2, currItem->height()/2, 0, 0, currItem->rotation(), 1, 1, false);
06446 //                                 if (!currItem->asLine())
06447 //                                 {
06448                                           if (QRegion(p.xForm(QPointArray(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo))
06449                                           {
06450                                                  if (p.xForm(QRect(0, 0, 6, 6)).intersects(mpo))
06451                                                  {
06452 //                                                      RCenter = FPoint(currItem->xPos()+currItem->width(), currItem->yPos()+currItem->height(), 0, 0, currItem->rotation(), 1, 1, true);
06453                                                         RCenter = FPoint(currItem->width(), currItem->height(), 0, 0, currItem->rotation(), 1, 1, false);
06454                                                         Doc->RotMode = 4;
06455                                                  }
06456                                                  else if (p.xForm(QRect(static_cast<int>(currItem->width())-6, 0, 6, 6)).intersects(mpo))
06457                                                  {
06458 //                                                      RCenter = FPoint(currItem->xPos(), currItem->yPos()+currItem->height(), 0, 0, currItem->rotation(), 1, 1, true);
06459                                                         RCenter = FPoint(0, currItem->height(), 0, 0, currItem->rotation(), 1, 1, false);
06460                                                         Doc->RotMode = 3;
06461                                                  }
06462                                                  else if (p.xForm(QRect(static_cast<int>(currItem->width())-6, static_cast<int>(currItem->height())-6, 6, 6)).intersects(mpo))
06463                                                  {
06464 //                                                      RCenter = FPoint(currItem->xPos(), currItem->yPos());
06465                                                         RCenter = FPoint(0, 0);
06466                                                         Doc->RotMode = 0;
06467                                                  }
06468                                                  else if (p.xForm(QRect(0, static_cast<int>(currItem->height())-6, 6, 6)).intersects(mpo))
06469                                                  {
06470 //                                                      RCenter = FPoint(currItem->xPos()+currItem->width(), currItem->yPos(), 0, 0, currItem->rotation(), 1, 1, true);
06471                                                         RCenter = FPoint(currItem->width(), 0, 0, 0, currItem->rotation(), 1, 1, false);
06472                                                         Doc->RotMode = 1;
06473                                                  }
06474                                           }
06475 //                                 }
06476                                    RCenter = FPoint(currItem->xPos()+RCenter.x(), currItem->yPos()+ RCenter.y(), 0, 0, 0, 1, 1, true);
06477                                    oldW = xy2Deg(m->x()/Scale - RCenter.x(), m->y()/Scale - RCenter.y());
06478                                    p.end();
06479                             }
06480                      }
06481                      break;
06482               case modeLinkFrames:
06483                      if (m->button() != LeftButton)
06484                             break;
06485                      currItem = Doc->ElemToLink;
06486                      if (currItem==NULL)
06487                             break;
06488                      SeleItem(m);
06489                      if (GetItem(&bb) && (bb->asTextFrame()))
06490                      {
06491                             PageItem* bblast = bb;
06492                             while (bblast->nextInChain())
06493                                    bblast = bblast->nextInChain();
06494                             
06495                             if (currItem->nextInChain() == 0 && bb->prevInChain() == 0 && currItem != bblast)
06496                             {
06497                                    currItem->link(bb);
06498                                    // CB We need to do this because we draw in the order of the item list
06499                                    // Which is also item number list.. but #3488: we must also renumber the items
06500                                    if (bb->ItemNr < currItem->ItemNr)
06501                                    {
06502                                           Doc->Items->insert(currItem->ItemNr+1, bb);
06503                                           bb = Doc->Items->take(bb->ItemNr);
06504                                           Doc->renumberItemsInListOrder();
06505                                    }
06506                                    updateContents();
06507                                    emit DocChanged();
06508                                    Doc->ElemToLink = bb;
06509                             }
06510                             else if (currItem == bblast)
06511                             {
06512                                    //CB Mouse is released when this messagebox takes focus
06513                                    m_MouseButtonPressed = false;
06514                                    QMessageBox::warning(this, tr("Linking Text Frames"),
06515                                                                               "<qt>" + tr("You are trying to link a frame to itself.") + "</qt>");
06516                             }
06517                             else
06518                             {
06519                                    //CB Mouse is released when this messagebox takes focus
06520                                    m_MouseButtonPressed = false;
06521                                    QMessageBox::warning(this, tr("Linking Text Frames"),
06522                                                                        "<qt>" + tr("You are trying to link a frame which is already linked.") + "</qt>");
06523                             }
06524                      }
06525                      else
06526                             Doc->ElemToLink = NULL;
06527                      break;
06528               case modeUnlinkFrames:
06529                      if (m->button() != LeftButton)
06530                             break;
06531                      SeleItem(m);
06532                      if (GetItem(&currItem) && (currItem->asTextFrame()))
06533                      {
06534                             if (currItem->prevInChain() != 0)
06535                             {
06536                                    currItem->prevInChain()->unlink();
06537                             }
06538                             emit DocChanged();
06539                             updateContents();
06540                      }
06541                      break;
06542               case modeDrawRegularPolygon:
06543                      {
06544                             if (m->button() != LeftButton)
06545                                    break;
06546                             selectPage(m);
06547                             if (m->state() == ShiftButton)
06548                                    z = Doc->itemAddArea(PageItem::Polygon, PageItem::Unspecified, Rxp, Ryp, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06549                             else
06550                             {
06551                                    Doc->ApplyGuides(&Rxp, &Ryp);
06552                                    z = Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, Doc->toolSettings.dBrush, Doc->toolSettings.dPen, !m_MouseButtonPressed);
06553                             }
06554                             currItem = Doc->Items->at(z);
06555                             FPointArray cli = RegularPolygonF(currItem->width(), currItem->height(), Doc->toolSettings.polyC, Doc->toolSettings.polyS, Doc->toolSettings.polyF, Doc->toolSettings.polyR);
06556                             FPoint np(cli.point(0));
06557                             currItem->PoLine.resize(2);
06558                             currItem->PoLine.setPoint(0, np);
06559                             currItem->PoLine.setPoint(1, np);
06560                             for (uint ax = 1; ax < cli.size(); ++ax)
06561                             {
06562                                    np = FPoint(cli.point(ax));
06563                                    currItem->PoLine.putPoints(currItem->PoLine.size(), 4, np.x(), np.y(), np.x(), np.y(), np.x(), np.y(), np.x(), np.y());
06564                             }
06565                             np = FPoint(cli.point(0));
06566                             currItem->PoLine.putPoints(currItem->PoLine.size(), 2, np.x(), np.y(), np.x(), np.y());
06567                             currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
06568                             qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
06569                             Doc->m_Selection->clear();
06570                             Doc->m_Selection->addItem(currItem);
06571                             currItem->paintObj();
06572                             inItemCreation = true;
06573                             if (m->state() == ShiftButton)
06574                             {
06575                                    Doc->appMode = modeNormal;
06576                                    emit DocChanged();
06577                                    currItem->Sizing =  currItem->asLine() ? false : true;
06578                                    inItemCreation = false;
06579                                    updateContents();
06580                             }
06581                             else
06582                                    operItemMoving = true;
06583                             break;
06584                      }
06585               case modeDrawBezierLine:
06586                      if (m->button() == RightButton)
06587                             break;
06588                      if (FirstPoly)
06589                      {
06590                             selectPage(m);
06591                             z = Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenLine, !m_MouseButtonPressed);
06592                             currItem = Doc->Items->at(z);
06593                             Doc->m_Selection->clear();
06594                             Doc->m_Selection->addItem(currItem);
06595                             qApp->setOverrideCursor(QCursor(crossCursor), true);
06596                      }
06597                      currItem = Doc->m_Selection->itemAt(0);
06598                      p.begin(viewport());
06599                      Transform(currItem, &p);
06600                      npf = FPoint(p.xFormDev(m->pos()));
06601                      p.end();
06602                      npf += FPoint(Doc->minCanvasCoordinate.x(), Doc->minCanvasCoordinate.y());
06603                      npf = Doc->ApplyGridF(npf);
06604                      currItem->PoLine.addPoint(npf);
06605                      npf2 = getMinClipF(&currItem->PoLine);
06606                      if (npf2.x() < 0)
06607                      {
06608                             currItem->PoLine.translate(-npf2.x(), 0);
06609                             Doc->MoveItem(npf2.x(), 0, currItem);
06610                      }
06611                      if (npf2.y() < 0)
06612                      {
06613                             currItem->PoLine.translate(0, -npf2.y());
06614                             Doc->MoveItem(0, npf2.y(), currItem);
06615                      }
06616                      Doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
06617                      currItem->setPolyClip(qRound(QMAX(currItem->lineWidth() / 2, 1)));
06618                      currItem->paintObj();
06619                      break;
06620               case modeInsertPDFButton:
06621               case modeInsertPDFTextfield:
06622               case modeInsertPDFCheckbox:
06623               case modeInsertPDFCombobox:
06624               case modeInsertPDFListbox:
06625               case modeInsertPDFTextAnnotation:
06626               case modeInsertPDFLinkAnnotation:
06627                      if (m->button() != LeftButton)
06628                             break;
06629                      selectPage(m);
06630                      Doc->ApplyGuides(&Rxp, &Ryp);
06631                      z = Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenText, !m_MouseButtonPressed);
06632                      currItem = Doc->Items->at(z);
06633                      currItem->setIsAnnotation(true);
06634                      currItem->AutoName = false;
06635                      switch (Doc->appMode)
06636                      {
06637                      case modeInsertPDFButton:
06638                             currItem->annotation().setType(2);
06639                             currItem->annotation().setFlag(65536);
06640                             break;
06641                      case modeInsertPDFTextfield:
06642                             currItem->annotation().setType(3);
06643                             break;
06644                      case modeInsertPDFCheckbox:
06645                             currItem->annotation().setType(4);
06646                             break;
06647                      case modeInsertPDFCombobox:
06648                             currItem->annotation().setType(5);
06649                             currItem->annotation().setFlag(131072);
06650                             break;
06651                      case modeInsertPDFListbox:
06652                             currItem->annotation().setType(6);
06653                             break;
06654                      case modeInsertPDFTextAnnotation:
06655                             currItem->annotation().setType(10);
06656                             break;
06657                      case modeInsertPDFLinkAnnotation:
06658                             currItem->annotation().setType(11);
06659                             currItem->annotation().setZiel(Doc->currentPage()->pageNr());
06660                             currItem->annotation().setAction("0 0");
06661                             currItem->setTextFlowMode(PageItem::TextFlowDisabled);
06662                             break;
06663                      }
06664                      SetupDraw(z);
06665                      break;
06666               case modeDrawFreehandLine:
06667                      if (m->button() != LeftButton)
06668                             break;
06669                      RecordP.resize(0);
06670                      Deselect(false);
06671                      Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
06672                      Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
06673                      SeRx = Mxp;
06674                      SeRy = Myp;
06675                      break;
06676               case modeDrawTable:
06677                      if (m->button() != LeftButton)
06678                             break;
06679                      Deselect(false);
06680 //                   Mxp = qRound(m->x()/Scale + Doc->minCanvasCoordinate.x());
06681 //                   Myp = qRound(m->y()/Scale + Doc->minCanvasCoordinate.y());
06682                      Rxp = m->x()/Scale + Doc->minCanvasCoordinate.x();
06683                      Ryp = m->y()/Scale + Doc->minCanvasCoordinate.y();
06684                      npf = Doc->ApplyGridF(FPoint(Rxp, Ryp));
06685                      Rxp = npf.x();
06686                      Ryp = npf.y();
06687                      Doc->ApplyGuides(&Rxp, &Ryp);
06688                      GyM = -1;
06689                      GxM = -1;
06690                      Mxp = qRound(Rxp);
06691                      Myp = qRound(Ryp);
06692                      SeRx = Mxp;
06693                      SeRy = Myp;
06694                      break;
06695               case modePanning:
06696                      break;
06697               case modeMeasurementTool:
06698               case modeEditGradientVectors:
06699                      if (m->button() != LeftButton)
06700                             break;
06701                      m_MouseButtonPressed = true;
06702                      qApp->setOverrideCursor(QCursor(CrossCursor), true);
06703                      Dxp = m->x();
06704                      Dyp = m->y();
06705                      Mxp = m->x();
06706                      Myp = m->y();
06707                      break;
06708               case modeCopyProperties:
06709                      if (m->button() != LeftButton)
06710                             break;
06711                      SeleItem(m);
06712                      if (GetItem(&currItem))
06713                      {
06714                             currItem->ColGap = Doc->ElemToLink->ColGap;
06715                             currItem->Cols = Doc->ElemToLink->Cols;
06716                             currItem->BottomLine = Doc->ElemToLink->BottomLine;
06717                             currItem->TopLine = Doc->ElemToLink->TopLine;
06718                             currItem->LeftLine = Doc->ElemToLink->LeftLine;
06719                             currItem->RightLine = Doc->ElemToLink->RightLine;
06720                             currItem->setTextToFrameDist(Doc->ElemToLink->textToFrameDistLeft(), Doc->ElemToLink->textToFrameDistRight(), Doc->ElemToLink->textToFrameDistTop(), Doc->ElemToLink->textToFrameDistBottom());
06721                             currItem->setLineStyle(Doc->ElemToLink->lineStyle());
06722                             currItem->setLineWidth(Doc->ElemToLink->lineWidth());
06723                             currItem->setLineTransparency(Doc->ElemToLink->lineTransparency());
06724                             currItem->setLineShade(Doc->ElemToLink->lineShade());
06725                             currItem->setLineColor(Doc->ElemToLink->lineColor());
06726                             currItem->setLineEnd(Doc->ElemToLink->lineEnd());
06727                             currItem->setLineJoin(Doc->ElemToLink->lineJoin());
06728                             currItem->setCustomLineStyle(Doc->ElemToLink->customLineStyle());
06729                             currItem->setEndArrowIndex(Doc->ElemToLink->endArrowIndex());
06730                             currItem->setStartArrowIndex(Doc->ElemToLink->startArrowIndex());
06731                             currItem->setFillColor(Doc->ElemToLink->fillColor());
06732                             currItem->setFillShade(Doc->ElemToLink->fillShade());
06733                             currItem->setFillTransparency(Doc->ElemToLink->fillTransparency());
06734                             Doc->ElemToLink = currItem;
06735                             emit DocChanged();
06736                             updateContents();
06737                      }
06738                      else
06739                      {
06740                             Doc->ElemToLink = NULL;
06741                             Doc->appMode = modeNormal;
06742                             emit PaintingDone();
06743                      }
06744                      break;
06745        }
06746 }
06747 
06748 void ScribusView::getDragRectScreen(double *x, double *y, double *w, double *h)
06749 {
06750        QPoint in(qRound(dragX*Scale), qRound(dragY*Scale));
06751        in -= QPoint(qRound(Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
06752        QPoint out = contentsToViewport(in);
06753        *x = static_cast<double>(out.x());
06754        *y = static_cast<double>(out.y());
06755        *w = dragW*Scale;
06756        *h = dragH*Scale;
06757 }
06758 
06759 void ScribusView::getGroupRectScreen(double *x, double *y, double *w, double *h)
06760 {
06761        double gx, gy, gh, gw;
06762        Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
06763        QPoint in(qRound(gx*Scale), qRound(gy*Scale));
06764        in -= QPoint(qRound(Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
06765        QPoint out = contentsToViewport(in);
06766        *x = static_cast<double>(out.x());
06767        *y = static_cast<double>(out.y());
06768        *w = gw*Scale;
06769        *h = gh*Scale;
06770 }
06771 
06772 void ScribusView::paintGroupRect(bool norm)
06773 {
06774        double x, y, w, h;
06775        getGroupRectScreen(&x, &y, &w, &h);
06776        QPainter pgc;
06777        pgc.begin(viewport());
06778        pgc.setPen(QPen((norm ? red : black), 1, DotLine, FlatCap, MiterJoin));
06779        pgc.setBrush(NoBrush);
06780        pgc.drawRect(static_cast<int>(x), static_cast<int>(y), static_cast<int>(w), static_cast<int>(h));
06781        pgc.setBrush(red);
06782        if (norm)
06783        {
06784               pgc.setPen(QPen(red, 1, SolidLine, FlatCap, MiterJoin));
06785               pgc.drawRect(qRound(x+w-6), qRound(y+h-6), 6, 6);
06786               pgc.drawRect(qRound(x+w/2 - 3), qRound(y+h-6), 6, 6);
06787               pgc.drawRect(qRound(x+w/2 - 3), qRound(y), 6, 6);
06788               pgc.drawRect(qRound(x+w-6), qRound(y+h/2 - 3), 6, 6);
06789               pgc.drawRect(qRound(x+w-6), qRound(y), 6, 6);
06790               pgc.drawRect(qRound(x), qRound(y), 6, 6);
06791               pgc.drawRect(qRound(x), qRound(y+h/2 - 3), 6, 6);
06792               pgc.drawRect(qRound(x), qRound(y+h-6), 6, 6);
06793        }
06794        pgc.end();
06795 }
06796 
06797 void ScribusView::PaintSizeRect(QPainter *p, QRect newRect)
06798 {
06799        static QRect oldRect;
06800        if (!newRect.isNull())
06801        {
06802               QWMatrix ma(p->worldMatrix());
06803               ma.setTransformationMode ( QWMatrix::Areas );
06804               p->setWorldMatrix(ma);
06805               p->setRasterOp(XorROP);
06806               p->setBrush(NoBrush);
06807               p->setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
06808               if (!oldRect.isNull())
06809                      p->drawRect(oldRect);
06810               p->drawRect(newRect);
06811        }
06812        oldRect = newRect;
06813 }
06814 
06815 void ScribusView::ToView(QPainter *p)
06816 {
06817        QPoint out(contentsToViewport(QPoint(0, 0)));
06818        p->translate(qRound(-Doc->minCanvasCoordinate.x()*Scale), qRound(-Doc->minCanvasCoordinate.y()*Scale));
06819        p->translate(out.x(), out.y());
06820 }
06821 
06822 void ScribusView::ToView(QWMatrix& m)
06823 {
06824        QPoint out(contentsToViewport(QPoint(0, 0)));
06825        m.translate(qRound(-Doc->minCanvasCoordinate.x()*Scale), qRound(-Doc->minCanvasCoordinate.y()*Scale));
06826        m.translate(out.x(), out.y());
06827 }
06828 
06829 void ScribusView::RefreshItem(PageItem *currItem)
06830 {
06831        updateContents(currItem->getRedrawBounding(Scale));
06832 }
06833 
06834 void ScribusView::RefreshGradient(PageItem *currItem, double dx, double dy)
06835 {
06836        QWMatrix matrix;
06837        QRect rect = currItem->getRedrawBounding(Scale);
06838        Transform(currItem, matrix);
06839        FPointArray fpNew;
06840        fpNew.setPoints(2, currItem->GrStartX, currItem->GrStartY, currItem->GrEndX, currItem->GrEndY);
06841        fpNew.map(matrix);
06842        if (dx < 8.0) dx = 8.0;
06843        if (dy < 8.0) dy = 8.0;
06844        int grl = (int) floor( QMIN(fpNew.point(0).x(), fpNew.point(1).x()) - dx );
06845        int grr = (int) ceil ( QMAX(fpNew.point(0).x(), fpNew.point(1).x()) + dx );
06846        int grb = (int) ceil ( QMAX(fpNew.point(0).y(), fpNew.point(1).y()) + dy );
06847        int grt = (int) floor( QMIN(fpNew.point(0).y(), fpNew.point(1).y()) - dy );
06848        rect |= QRect(grl, grt, grr-grl, grb-grt);
06849        updateContents(rect);
06850 }
06851 
06852 // //CB-->Doc
06853 // bool ScribusView::MoveItem(double newX, double newY, PageItem* currItem, bool fromMP)
06854 // {
06855 //     if (currItem->locked())
06856 //            return false;
06857 //     bool retw = false;
06858 //     double oldx = currItem->xPos();
06859 //     double oldy = currItem->yPos();
06860 //     currItem->moveBy(newX, newY);
06861 //     if ((Doc->useRaster) && (!operItemMoving) && (!fromMP) && (static_cast<int>(Doc->currentPage()->pageNr()) == currItem->OwnPage))
06862 //     {
06863 //            currItem->setXYPos(qRound(currItem->xPos() / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid, qRound(currItem->yPos() / Doc->guidesSettings.minorGrid) * Doc->guidesSettings.minorGrid);
06864 //     }
06865 //     if ((Doc->SnapGuides) && (!operItemMoving) && (Doc->appMode == modeNormal) && (!Doc->EditClip) && (!fromMP))
06866 //            Doc->SnapToGuides(currItem);
06867 //     if ((currItem->xPos() != oldx) || (currItem->yPos() != oldy))
06868 //            retw = true;
06869 //     if (!fromMP)
06870 //     {
06871 // /*         if (GroupSel)
06872 //            {
06873 //                   double gx, gy, gh, gw;
06874 //                   setGroupRect();
06875 //                   getGroupRect(&gx, &gy, &gw, &gh);
06876 //                   emit ItemPos(gx, gy);
06877 //            }
06878 //            else */
06879 //            //CB if (!GroupSel)
06880 //            //CB   emit ItemPos(currItem->xPos(), currItem->yPos());
06881 //            //CB qDebug("if (!GroupSel)                      emit ItemPos(currItem->xPos(), currItem->yPos());");
06882 //     }
06883 // /*  if (!Doc->loading)
06884 //            emit UpdtObj(Doc->currentPage->pageNr(), b->ItemNr); */
06885 //     QRect oldR(currItem->getRedrawBounding(Scale));
06886 //     Doc->setRedrawBounding(currItem);
06887 //     QRect newR(currItem->getRedrawBounding(Scale));
06888 //     if ((!operItemMoving) && (!currItem->Sizing))
06889 //            updateContents(newR.unite(oldR));
06890 //     currItem->OwnPage = Doc->OnPage(currItem);
06891 //     return retw;
06892 // }
06893 
06894 void ScribusView::MarkClip(PageItem *currItem, FPointArray cli, bool once)
06895 {
06896        double x, y;
06897        QPainter p;
06898        QPointArray Bez(4);
06899        p.begin(viewport());
06900        ToView(&p);
06901        Transform(currItem, &p);
06902        p.scale(0.1, 0.1);
06903        if (once)
06904               p.setPen(QPen(blue, 1, SolidLine, FlatCap, MiterJoin));
06905        else
06906        {
06907               p.setRasterOp(XorROP);
06908               p.setPen(QPen(yellow, 1, SolidLine, FlatCap, MiterJoin));
06909        }
06910        p.setBrush(NoBrush);
06911        if ((EditContour) && (currItem->ContourLine.size() != 0))
06912               cli = currItem->ContourLine;
06913        else
06914               cli = currItem->PoLine;
06915        if (cli.size() > 3)
06916        {
06917               for (uint poi=0; poi<cli.size()-3; poi += 4)
06918               {
06919                      if (cli.point(poi).x() > 900000)
06920                             continue;
06921                      if (once)
06922                             p.setPen(QPen(blue, 1, SolidLine, FlatCap, MiterJoin));
06923                      else
06924                             p.setPen(QPen(yellow, 1, SolidLine, FlatCap, MiterJoin));
06925                      BezierPoints(&Bez,   QPoint(qRound(cli.point(poi).x()*10), qRound(cli.point(poi).y()*10)),
06926                                                                                     QPoint(qRound(cli.point(poi+1).x()*10), qRound(cli.point(poi+1).y()*10)),
06927                                                                                     QPoint(qRound(cli.point(poi+3).x()*10), qRound(cli.point(poi+3).y()*10)),
06928                                                                                     QPoint(qRound(cli.point(poi+2).x()*10), qRound(cli.point(poi+2).y()*10)));
06929                      p.drawCubicBezier(Bez);
06930                      if (once)
06931                             p.setPen(QPen(blue, 1, DotLine, FlatCap, MiterJoin));
06932                      else
06933                             p.setPen(QPen(yellow, 1, DotLine, FlatCap, MiterJoin));
06934                      p.drawLine(Bez.point(0), Bez.point(1));
06935                      p.drawLine(Bez.point(2), Bez.point(3));
06936               }
06937        }
06938        for (uint a=0; a<cli.size()-1; a += 2)
06939        {
06940               if (cli.point(a).x() > 900000)
06941                      continue;
06942               if (EdPoints)
06943               {
06944                      if (ClRe == static_cast<int>(a+1))
06945                      {
06946                             if (once)
06947                                    p.setPen(QPen(red, 8, SolidLine, RoundCap, MiterJoin));
06948                             else
06949                                    p.setPen(QPen(cyan, 8, SolidLine, RoundCap, MiterJoin));
06950                      }
06951                      else
06952                      {
06953                             if (once)
06954                                    p.setPen(QPen(magenta, 8, SolidLine, RoundCap, MiterJoin));
06955                             else
06956                                    p.setPen(QPen(green, 8, SolidLine, RoundCap, MiterJoin));
06957                      }
06958                      cli.point(a+1, &x, &y);
06959                      p.drawLine(qRound(x*10), qRound(y*10), qRound(x*10), qRound(y*10));
06960                      if (ClRe == static_cast<int>(a))
06961                      {
06962                             if (once)
06963                                    p.setPen(QPen(red, 8, SolidLine, RoundCap, MiterJoin));
06964                             else
06965                                    p.setPen(QPen(cyan, 8, SolidLine, RoundCap, MiterJoin));
06966                      }
06967                      else
06968                      {
06969                             if (once)
06970                                    p.setPen(QPen(blue, 8, SolidLine, RoundCap, MiterJoin));
06971                             else
06972                                    p.setPen(QPen(yellow, 8, SolidLine, RoundCap, MiterJoin));
06973                      }
06974                      cli.point(a, &x, &y);
06975                      p.drawLine(qRound(x*10), qRound(y*10), qRound(x*10), qRound(y*10));
06976               }
06977               else
06978               {
06979                      if (ClRe == static_cast<int>(a))
06980                      {
06981                             if (once)
06982                                    p.setPen(QPen(red, 8, SolidLine, RoundCap, MiterJoin));
06983                             else
06984                                    p.setPen(QPen(cyan, 8, SolidLine, RoundCap, MiterJoin));
06985                      }
06986                      else
06987                      {
06988                             if (once)
06989                                    p.setPen(QPen(blue, 8, SolidLine, RoundCap, MiterJoin));
06990                             else
06991                                    p.setPen(QPen(yellow, 8, SolidLine, RoundCap, MiterJoin));
06992                      }
06993                      cli.point(a, &x, &y);
06994                      p.drawLine(qRound(x*10), qRound(y*10), qRound(x*10), qRound(y*10));
06995                      if (ClRe == static_cast<int>(a+1))
06996                      {
06997                             if (once)
06998                                    p.setPen(QPen(red, 8, SolidLine, RoundCap, MiterJoin));
06999                             else
07000                                    p.setPen(QPen(cyan, 8, SolidLine, RoundCap, MiterJoin));
07001                      }
07002                      else
07003                      {
07004                             if (once)
07005                                    p.setPen(QPen(magenta, 8, SolidLine, RoundCap, MiterJoin));
07006                             else
07007                                    p.setPen(QPen(green, 8, SolidLine, RoundCap, MiterJoin));
07008                      }
07009                      cli.point(a+1, &x, &y);
07010                      p.drawLine(qRound(x*10), qRound(y*10), qRound(x*10), qRound(y*10));
07011               }
07012        }
07013        if (ClRe != -1)
07014        {
07015               if (once)
07016               {
07017                      p.setPen(QPen(red, 8, SolidLine, RoundCap, MiterJoin));
07018 //            else
07019 //                   p.setPen(QPen(cyan, 8, SolidLine, RoundCap, MiterJoin));
07020                      cli.point(ClRe, &x, &y);
07021                      p.drawLine(qRound(x*10), qRound(y*10), qRound(x*10), qRound(y*10));
07022                      QValueList<int>::Iterator itm;
07023                      for (itm = SelNode.begin(); itm != SelNode.end(); ++itm)
07024                      {
07025                             cli.point((*itm), &x, &y);
07026                             p.drawLine(qRound(x*10), qRound(y*10), qRound(x*10), qRound(y*10));
07027                      }
07028               }
07029               emit HavePoint(true, MoveSym);
07030        }
07031        else
07032               emit HavePoint(false, MoveSym);
07033        p.end();
07034 }
07035 
07036 //CB-->elsewhere, util, however, only used in the view for now
07037 bool ScribusView::PointOnLine(QPoint Start, QPoint End, QRect MArea)
07038 {
07039        QPoint an, en;
07040        if (Start.x() == End.x())
07041        {
07042               an = Start.y() > End.y() ? End : Start;
07043               en = an == End ? Start : End;
07044               for (int a=an.y(); a<en.y(); ++a)
07045               {
07046                      if (MArea.contains(an.x(), a))
07047                             return true;
07048               }
07049        }
07050        if (Start.y() == End.y())
07051        {
07052               an = Start.x() > End.x() ? End : Start;
07053               en = an == End ? Start : End;
07054               for (int a=an.x(); a<en.x(); ++a)
07055               {
07056                      if (MArea.contains(a, an.y()))
07057                             return true;
07058               }
07059        }
07060        if (abs(Start.x() - End.x()) > abs(Start.y() - End.y()))
07061        {
07062               an = Start.x() > End.x() ? End : Start;
07063               en = an == End ? Start : End;
07064               double stg = (en.y() - an.y()) / static_cast<double>((en.x() - an.x()));
07065               for (int a = an.x(); a < en.x(); ++a)
07066               {
07067                      if (MArea.contains(a, an.y()+qRound((a-an.x())*stg)))
07068                             return true;
07069               }
07070        }
07071        else
07072        {
07073               an = Start.y() > End.y() ? End : Start;
07074               en = an == End ? Start : End;
07075               double stg = (en.x() - an.x()) / static_cast<double>((en.y() - an.y()));
07076               for (int a = an.y(); a < en.y(); ++a)
07077               {
07078                      if (MArea.contains(an.x()+qRound((a-an.y())*stg), a))
07079                             return true;
07080               }
07081        }
07082        return false;
07083 }
07084 
07085 //CB-->Doc??
07086 void ScribusView::TransformPoly(int mode, int rot, double scaling)
07087 {
07088        PageItem *currItem = Doc->m_Selection->itemAt(0);
07089        currItem->ClipEdited = true;
07090        QWMatrix ma;
07091        if (EditContour)
07092        {
07093               FPoint tp2(getMinClipF(&currItem->ContourLine));
07094               FPoint tp(getMaxClipF(&currItem->ContourLine));
07095               currItem->ContourLine.translate(-qRound((tp.x() + tp2.x()) / 2.0), -qRound((tp.y() + tp2.y()) / 2.0));
07096               switch (mode)
07097               {
07098               case 0:
07099                      ma.rotate(-rot);
07100                      break;
07101               case 1:
07102                      ma.rotate(rot);
07103                      break;
07104               case 2:
07105                      ma.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0));
07106                      break;
07107               case 3:
07108                      ma.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0));
07109                      break;
07110               case 4:
07111                      ma.shear(0.017455, 0);
07112                      break;
07113               case 5:
07114                      ma.shear(-0.017455, 0);
07115                      break;
07116               case 6:
07117                      ma.shear(0, -0.017455);
07118                      break;
07119               case 7:
07120                      ma.shear(0, 0.017455);
07121                      break;
07122               case 8:
07123                      ma.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0));
07124                      break;
07125               case 9:
07126                      ma.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0));
07127                      break;
07128               //10-13 are for scaling the contour line in shape edit mode
07129               case 10:
07130                      {
07131                             double s=1.0 - (scaling/(tp2.x() - tp.x()));
07132                             ma.scale(s, 1);
07133                             ma.translate(-scaling/s/2,0);
07134                      }
07135                      break;
07136               case 11:
07137                      {
07138                             double s=1.0 - (scaling/(tp2.x() - tp.x()));
07139                             ma.scale(s, 1);
07140                             ma.translate(scaling/s/2,0);
07141                      }
07142                      break;
07143               case 12:
07144                      {
07145                             double s=1.0 - (scaling/(tp2.y() - tp.y()));
07146                             ma.scale(1, s);
07147                             ma.translate(0,-scaling/s/2);
07148                      }
07149                      break;
07150               case 13:
07151                      {
07152                             double s=1.0 - (scaling/(tp2.y() - tp.y()));
07153                             ma.scale(1, s);
07154                             ma.translate(0,scaling/s/2);
07155                      }
07156                      break;
07157               }
07158               currItem->ContourLine.map(ma);
07159               currItem->ContourLine.translate(qRound((tp.x() + tp2.x()) / 2.0), qRound((tp.y() + tp2.y()) / 2.0));
07160               updateContents();
07161 //            currItem->Tinput = true;
07162               currItem->FrameOnly = true;
07163               currItem->paintObj();
07164               MarkClip(currItem, currItem->ContourLine, true);
07165               if (UndoManager::undoEnabled())
07166               {
07167                      undoManager->setUndoEnabled(false);
07168                      currItem->checkChanges(true);
07169                      undoManager->setUndoEnabled(true);
07170                      SimpleState *ss = new SimpleState(Um::EditContourLine, "", Um::IBorder);
07171                      ss->set("EDIT_CONTOUR", "edit_contour");
07172                      ss->set("MODE", mode);
07173                      ss->set("ROT", rot);
07174                      ss->set("SCALING", scaling);
07175                      undoManager->action(currItem, ss);
07176               }
07177               emit DocChanged();
07178               return;
07179        }
07180        FPoint oldPos(currItem->xyPos());
07181        double offsX = currItem->width() / 2.0;
07182        double offsY = currItem->height() / 2.0;
07183        ma.translate(-offsX, -offsY);
07184        switch (mode)
07185        {
07186        case 0:
07187               ma.rotate(-rot);
07188               break;
07189        case 1:
07190               ma.rotate(rot);
07191               break;
07192        case 2:
07193               ma.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0));
07194               break;
07195        case 3:
07196               ma.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0));
07197               break;
07198        case 4:
07199               ma.shear(0.017455, 0);
07200               break;
07201        case 5:
07202               ma.shear(-0.017455, 0);
07203               break;
07204        case 6:
07205               ma.shear(0, -0.017455);
07206               break;
07207        case 7:
07208               ma.shear(0, 0.017455);
07209               break;
07210        case 8:
07211               ma.scale(1.0 - (scaling / currItem->width()),1.0 - (scaling / currItem->height()));
07212               break;
07213        case 9:
07214               ma.scale(1.0 + (scaling / currItem->width()),1.0 + (scaling / currItem->height()));
07215               break;
07216        }
07217        currItem->PoLine.map(ma);
07218        currItem->PoLine.translate(offsX, offsY);
07219        Doc->AdjustItemSize(currItem);
07220        QWMatrix ma2;
07221        ma2.translate(oldPos.x(), oldPos.y());
07222        ma2.scale(1, 1);
07223        ma2.translate(offsX, offsY);
07224        FPoint n(-offsX, -offsY);
07225        switch (mode)
07226        {
07227        case 0:
07228               ma2.rotate(-rot);
07229               break;
07230        case 1:
07231               ma2.rotate(rot);
07232               break;
07233        case 2:
07234               ma2.scale(1.0 - (scaling / 100.0), 1.0 - (scaling / 100.0));
07235               break;
07236        case 3:
07237               ma2.scale(1.0 + (scaling / 100.0), 1.0 + (scaling / 100.0));
07238               break;
07239        case 4:
07240               ma2.shear(0.017455, 0);
07241               break;
07242        case 5:
07243               ma2.shear(-0.017455, 0);
07244               break;
07245        case 6:
07246               ma2.shear(0, -0.017455);
07247               break;
07248        case 7:
07249               ma2.shear(0, 0.017455);
07250               break;
07251        case 8:
07252               ma2.scale(1.0 - (scaling / currItem->width()),1.0 - (scaling / currItem->height()));
07253               break;
07254        case 9:
07255               ma2.scale(1.0 + (scaling / currItem->width()),1.0 + (scaling / currItem->height()));
07256               break;
07257        }
07258        double x = ma2.m11() * n.x() + ma2.m21() * n.y() + ma2.dx();
07259        double y = ma2.m22() * n.y() + ma2.m12() * n.x() + ma2.dy();
07260        Doc->MoveItem(x-oldPos.x(), y-oldPos.y(), currItem);
07261        if (currItem->asPathText())
07262               currItem->updatePolyClip();
07263        Doc->setRedrawBounding(currItem);
07264        RefreshItem(currItem);
07265        MarkClip(currItem, currItem->PoLine, true);
07266        currItem->FrameType = 3;
07267        if (UndoManager::undoEnabled())
07268        {
07269               undoManager->setUndoEnabled(false);
07270               currItem->checkChanges(true);
07271               undoManager->setUndoEnabled(true);
07272               SimpleState *ss = new SimpleState(Um::EditShape, "", Um::IBorder);
07273               ss->set("EDIT_SHAPE", "edit_shape");
07274               ss->set("MODE", mode);
07275               ss->set("ROT", rot);
07276               ss->set("SCALING", scaling);
07277               undoManager->action(currItem, ss);
07278        }
07279        emit DocChanged();
07280 }
07281 
07282 void ScribusView::Reset1Control()
07283 {
07284        // do no record anything else but the core reset points action
07285        undoManager->setUndoEnabled(false);
07286 
07287        PageItem *currItem = Doc->m_Selection->itemAt(0);
07288 
07289        oldClip = new FPointArray(EditContour ? currItem->ContourLine.copy() : currItem->PoLine.copy());
07290        oldItemX = currItem->xPos();
07291        oldItemY = currItem->yPos();
07292        isContourLine = EditContour;
07293 
07294        currItem->ClipEdited = true;
07295        FPoint np;
07296        if (EditContour)
07297               np = currItem->ContourLine.point(ClRe-1);
07298        else
07299               np = currItem->PoLine.point(ClRe-1);
07300        currItem->OldB2 = currItem->width();
07301        currItem->OldH2 = currItem->height();
07302        if (EditContour)
07303        {
07304               currItem->ContourLine.setPoint(ClRe, np);
07305               updateContents();
07306 //            currItem->Tinput = true;
07307               currItem->FrameOnly = true;
07308               currItem->paintObj();
07309        }
07310        else
07311        {
07312               currItem->PoLine.setPoint(ClRe, np);
07313               Doc->AdjustItemSize(currItem);
07314        }
07315        FPointArray cli;
07316        if ((EditContour) && (currItem->ContourLine.size() != 0))
07317               cli = currItem->ContourLine;
07318        else
07319               cli = currItem->PoLine;
07320        MarkClip(currItem, cli, true);
07321        emit DocChanged();
07322 
07323        undoManager->setUndoEnabled(true);
07324        FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
07325        if (*oldClip != newClip)
07326        {
07327               ItemState<QPair<FPointArray, FPointArray> > *state =
07328                             new ItemState<QPair<FPointArray, FPointArray> >(Um::ResetControlPoint, "",
07329                                                                                                                 currItem->getUPixmap());
07330               state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
07331               state->set("IS_CONTOUR", EditContour);
07332               state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
07333               state->set("OLD_X", oldItemX);
07334               state->set("OLD_Y", oldItemY);
07335               state->set("NEW_X", currItem->xPos());
07336               state->set("NEW_Y", currItem->yPos());
07337               undoManager->action(currItem, state);
07338        }
07339        delete oldClip;
07340        oldClip = 0;
07341 }
07342 
07343 void ScribusView::ResetControl()
07344 {
07345        // do no record anything else but the core reset points action
07346        undoManager->setUndoEnabled(false);
07347 
07348        PageItem *currItem = Doc->m_Selection->itemAt(0);
07349        oldClip = new FPointArray(EditContour ? currItem->ContourLine.copy() : currItem->PoLine.copy());
07350        oldItemX = currItem->xPos();
07351        oldItemY = currItem->yPos();
07352        isContourLine = EditContour;
07353 
07354        currItem->ClipEdited = true;
07355        FPoint np;
07356        if (EditContour)
07357               np = currItem->ContourLine.point(ClRe);
07358        else
07359               np = currItem->PoLine.point(ClRe);
07360 
07361        currItem->OldB2 = currItem->width();
07362        currItem->OldH2 = currItem->height();
07363        if ((ClRe == 0) || (ClRe == static_cast<int>(currItem->PoLine.size()-2)))
07364        {
07365               if (EditContour)
07366                      currItem->ContourLine.setPoint(ClRe+1, np);
07367               else
07368                      currItem->PoLine.setPoint(ClRe+1, np);
07369        }
07370        else
07371        {
07372               if (EditContour)
07373               {
07374                      currItem->ContourLine.setPoint(ClRe+1, np);
07375                      currItem->ContourLine.setPoint((ClRe % 4 != 0 ? ClRe + 3 : ClRe - 1), np);
07376               }
07377               else
07378               {
07379                      currItem->PoLine.setPoint(ClRe+1, np);
07380                      currItem->PoLine.setPoint((ClRe % 4 != 0 ? ClRe + 3 : ClRe - 1), np);
07381               }
07382        }
07383        if (!EditContour)
07384               Doc->AdjustItemSize(currItem);
07385        else
07386        {
07387               updateContents();
07388 //            currItem->Tinput = true;
07389               currItem->FrameOnly = true;
07390               currItem->paintObj();
07391        }
07392        FPointArray cli;
07393        if ((EditContour) && (currItem->ContourLine.size() != 0))
07394               cli = currItem->ContourLine;
07395        else
07396               cli = currItem->PoLine;
07397        MarkClip(currItem, cli, true);
07398 
07399        emit DocChanged();
07400 
07401        undoManager->setUndoEnabled(true);
07402        FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
07403        if (*oldClip != newClip)
07404        {
07405               ItemState<QPair<FPointArray, FPointArray> > *state =
07406                             new ItemState<QPair<FPointArray, FPointArray> >(Um::ResetControlPoints, "",
07407                                                                                                                 currItem->getUPixmap());
07408               state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
07409               state->set("IS_CONTOUR", EditContour);
07410               state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
07411               state->set("OLD_X", oldItemX);
07412               state->set("OLD_Y", oldItemY);
07413               state->set("NEW_X", currItem->xPos());
07414               state->set("NEW_Y", currItem->yPos());
07415               undoManager->action(currItem, state);
07416        }
07417        delete oldClip;
07418        oldClip = 0;
07419 }
07420 
07421 //CB-->Doc
07422 void ScribusView::MoveClipPoint(PageItem *currItem, FPoint ip)
07423 {
07424        if (((EdPoints) && (ClRe % 2 != 0)) || ((!EdPoints) && (ClRe % 2 == 0)))
07425               return;
07426        double xposOrig = currItem->xPos();
07427        double yposOrig = currItem->yPos();
07428        currItem->ClipEdited = true;
07429        FPointArray Clip;
07430        if (EditContour)
07431        {
07432               MarkClip(currItem, currItem->ContourLine);
07433               Clip = currItem->ContourLine.copy();
07434        }
07435        else
07436        {
07437               MarkClip(currItem, currItem->PoLine);
07438               Clip = currItem->PoLine.copy();
07439        }
07440        currItem->FrameType = 3;
07441        uint EndInd = Clip.size();
07442        uint StartInd = 0;
07443        for (uint n = ClRe; n < Clip.size(); ++n)
07444        {
07445               if (Clip.point(n).x() > 900000)
07446               {
07447                      EndInd = n;
07448                      break;
07449               }
07450        }
07451        if (ClRe > 0)
07452        {
07453               for (uint n2 = ClRe; n2 > 0; n2--)
07454               {
07455                      if (n2 == 0)
07456                             break;
07457                      if (Clip.point(n2).x() > 900000)
07458                      {
07459                             StartInd = n2 + 1;
07460                             break;
07461                      }
07462               }
07463        }
07464        FPoint np(ip);
07465        if (ClRe != -1)
07466        {
07467               if ((np.x() < 0) && (!EditContour))
07468               {
07469                      Doc->SizeItem(currItem->width() - np.x(), currItem->height(), currItem->ItemNr, false, false, false);
07470                      if (currItem->rotation() != 0)
07471                      {
07472                             FPoint npv(np.x(), 0);
07473                             Doc->MoveRotated(currItem, npv);
07474                      }
07475                      else
07476                             Doc->MoveItem(np.x(), 0, currItem);
07477                      Clip.translate(-np.x(), 0);
07478                      if (!currItem->imageFlippedH())
07479                             currItem->moveImageInFrame(-np.x()/currItem->imageXScale(), 0);
07480                      np.setX(0);
07481               }
07482               if ((np.y() < 0) && (!EditContour))
07483               {
07484                      Doc->SizeItem(currItem->width(), currItem->height() - np.y(), currItem->ItemNr, false, false, false);
07485                      if (currItem->rotation() != 0)
07486                      {
07487                             FPoint npv(0, np.y());
07488                             Doc->MoveRotated(currItem, npv);
07489                      }
07490                      else
07491                             Doc->MoveItem(0, np.y(), currItem);
07492                      Clip.translate(0, -np.y());
07493                      if (!currItem->imageFlippedV())
07494                             currItem->moveImageInFrame(0, -np.y()/currItem->imageYScale());
07495                      np.setY(0);
07496               }
07497               emit ClipPo(np.x(), np.y());
07498               if ((ClRe+1 < static_cast<int>(EndInd)) && (ClRe % 2 == 0))
07499               {
07500                      FPoint ap(Clip.point(ClRe));
07501                      FPoint ap2(Clip.point(ClRe+1));
07502                      ap2.setX(ap2.x() - (ap.x() - np.x()));
07503                      ap2.setY(ap2.y() - (ap.y() - np.y()));
07504                      Clip.setPoint(ClRe+1, ap2);
07505               }
07506               Clip.setPoint(ClRe, np);
07507               if (((ClRe % 4 != 0) && (ClRe % 2 == 0)) && (ClRe+3 < static_cast<int>(EndInd)) && (ClRe != static_cast<int>(StartInd)))
07508               {
07509                      FPoint ap(Clip.point(ClRe+2));
07510                      FPoint ap2(Clip.point(ClRe+3));
07511                      ap2.setX(ap2.x() - (ap.x() - np.x()));
07512                      ap2.setY(ap2.y() - (ap.y() - np.y()));
07513                      Clip.setPoint(ClRe+3, ap2);
07514                      Clip.setPoint(ClRe+2, np);
07515               }
07516               if ((ClRe % 4 == 0) && (ClRe+3 < static_cast<int>(EndInd)) && (ClRe != static_cast<int>(StartInd)))
07517               {
07518                      FPoint ap(Clip.point(ClRe-2));
07519                      FPoint ap2(Clip.point(ClRe-1));
07520                      ap2.setX(ap2.x() - (ap.x() - np.x()));
07521                      ap2.setY(ap2.y() - (ap.y() - np.y()));
07522                      Clip.setPoint(ClRe-1, ap2);
07523                      Clip.setPoint(ClRe-2, np);
07524               }
07525               /*
07526               {
07527                      qDebug(QString("is a text %1").arg((currItem->asTextFrame()!=0)));
07528                      qDebug(QString("is a image %1").arg((currItem->asImageFrame()!=0)));
07529                      qDebug(QString("is a line %1").arg((currItem->asLine()!=0)));
07530                      qDebug(QString("is a pathtext %1").arg((currItem->asPathText()!=0)));
07531                      qDebug(QString("is a polygon %1").arg((currItem->asPolygon()!=0)));
07532                      qDebug(QString("is a polyline %1").arg((currItem->asPolyLine()!=0)));
07533 
07534                      qDebug(QString("item type is %1").arg(currItem->itemType()));
07535               }
07536               */
07537               if (((ClRe == static_cast<int>(StartInd)) || (ClRe == static_cast<int>(EndInd-2))) &&
07538 //                    ((currItem->asPolygon()) || (currItem->asTextFrame()) || (currItem->asImageFrame())))
07539        ((currItem->itemType() == PageItem::Polygon) || (currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::ImageFrame)))
07540               {
07541                      if (ClRe == static_cast<int>(StartInd))
07542                      {
07543                             FPoint ap(Clip.point(EndInd-2));
07544                             FPoint ap2(Clip.point(EndInd-1));
07545                             ap2.setX(ap2.x() - (ap.x() - np.x()));
07546                             ap2.setY(ap2.y() - (ap.y() - np.y()));
07547                             Clip.setPoint(EndInd-2, Clip.point(StartInd));
07548                             Clip.setPoint(EndInd-1, ap2);
07549                      }
07550                      else
07551                      {
07552                             FPoint ap(Clip.point(StartInd));
07553                             FPoint ap2(Clip.point(StartInd + 1));
07554                             ap2.setX(ap2.x() - (ap.x() - np.x()));
07555                             ap2.setY(ap2.y() - (ap.y() - np.y()));
07556                             Clip.setPoint(StartInd, Clip.point(EndInd-2));
07557                             Clip.setPoint(StartInd + 1, ap2);
07558                      }
07559               }
07560               if (((ClRe == static_cast<int>(StartInd+1)) || (ClRe == static_cast<int>(EndInd-1))) &&
07561 //                    ((currItem->asPolygon()) || (currItem->asTextFrame()) || (currItem->asImageFrame())) && (MoveSym))
07562 ((currItem->itemType() == PageItem::Polygon) || (currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::ImageFrame)) && (MoveSym))
07563               {
07564                      uint kon = 0;
07565                      if (ClRe == static_cast<int>(StartInd+1))
07566                             kon = EndInd-1;
07567                      else
07568                             kon = StartInd + 1;
07569                      FPoint lxy(Clip.point(ClRe-1));
07570                      FPoint lk(Clip.point(ClRe));
07571                      double dx = lxy.x() - lk.x();
07572                      double dy = lxy.y() - lk.y();
07573                      lk.setX(lk.x() + dx*2);
07574                      lk.setY(lk.y() + dy*2);
07575                      Clip.setPoint(kon, lk);
07576               }
07577               if ((ClRe % 2 != 0) && (MoveSym) && (ClRe != static_cast<int>(StartInd + 1)) && (ClRe != static_cast<int>(EndInd-1)))
07578               {
07579                      uint kon = 0;
07580                      if ((ClRe+1) % 4 == 0)
07581                             kon = ClRe + 2;
07582                      else
07583                             kon = ClRe - 2;
07584                      FPoint lxy(Clip.point(ClRe-1));
07585                      FPoint lk(Clip.point(ClRe));
07586                      double dx = lxy.x() - lk.x();
07587                      double dy = lxy.y() - lk.y();
07588                      lk.setX(lk.x() + dx*2);
07589                      lk.setY(lk.y() + dy*2);
07590                      Clip.setPoint(kon, lk);
07591               }
07592               if (EditContour)
07593                      currItem->ContourLine = Clip.copy();
07594               else
07595                      currItem->PoLine = Clip.copy();
07596               currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
07597               MarkClip(currItem, Clip);
07598        }
07599        if (!EditContour)
07600               currItem->ContourLine.translate(xposOrig - currItem->xPos(), yposOrig - currItem->yPos());
07601 }
07602 
07603 //CB-->Doc
07604 void ScribusView::moveGroup(double x, double y, bool fromMP, Selection* customSelection)
07605 {
07606        Selection* itemSelection = (customSelection!=0) ? customSelection : Doc->m_Selection;
07607        Q_ASSERT(itemSelection!=0);
07608        uint selectedItemCount=itemSelection->count();
07609        if (selectedItemCount == 0)
07610               return;
07611        
07612        if (!_groupTransactionStarted && selectedItemCount > 1)
07613        {
07614               QString tooltip = Um::ItemsInvolved + "\n";
07615               for (uint i = 0; i < selectedItemCount; ++i)
07616                      tooltip += "\t" + itemSelection->itemAt(i)->getUName() + "\n";
07617               undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup,
07618                                                                  Um::Move, tooltip, Um::IMove);
07619               _groupTransactionStarted = true;
07620        }
07621        PageItem* currItem;
07622        QPainter p;
07623        double gx, gy, gw, gh;
07624        double sc = Scale;
07625        for (uint a = 0; a < selectedItemCount; ++a)
07626        {
07627               currItem = itemSelection->itemAt(a);
07628               if ((!fromMP) && (selectedItemCount < moveWithBoxesOnlyThreshold))
07629               {
07630                      p.begin(viewport());
07631                      ToView(&p);
07632                      p.translate(qRound(currItem->xPos()*Scale), qRound(currItem->yPos()*sc));
07633                      p.scale(sc, sc);
07634                      p.rotate(currItem->rotation());
07635                      p.setRasterOp(XorROP);
07636                      p.setBrush(NoBrush);
07637                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
07638                      if (selectedItemCount < moveWithFullOutlinesThreshold)
07639                      {
07640                             if (!(currItem->asLine()) && (currItem->FrameType != 0) || (currItem->asPolyLine()))
07641                                    currItem->DrawPolyL(&p, currItem->Clip);
07642                             else
07643                             {
07644                                    if (currItem->asLine())
07645                                    {
07646                                           int lw2 = 1;
07647                                           int lw = 1;
07648                                           PenCapStyle le = FlatCap;
07649                                           if (currItem->NamedLStyle.isEmpty())
07650                                           {
07651                                                  lw2 = qRound(currItem->lineWidth()  / 2.0);
07652                                                  lw = qRound(QMAX(currItem->lineWidth(), 1.0));
07653                                                  le = currItem->PLineEnd;
07654                                           }
07655                                           else
07656                                           {
07657                                                  multiLine ml = Doc->MLineStyles[currItem->NamedLStyle];
07658                                                  lw2 = qRound(ml[ml.size()-1].Width  / 2.0);
07659                                                  lw = qRound(QMAX(ml[ml.size()-1].Width, 1.0));
07660                                                  le = static_cast<PenCapStyle>(ml[ml.size()-1].LineEnd);
07661                                           }
07662                                           if (le != FlatCap)
07663                                                  p.drawRect(-lw2, -lw2, qRound(currItem->width())+lw, lw);
07664                                           else
07665                                                  p.drawRect(-1, -lw2, qRound(currItem->width()), lw);
07666                                    }
07667                             }
07668                      }
07669                      else
07670                             p.drawRect(0, 0, static_cast<int>(currItem->width())+1, static_cast<int>(currItem->height())+1);
07671                      p.end();
07672               }
07673               Doc->MoveItem(x, y, currItem, fromMP);
07674               if ((!fromMP) && (itemSelection->count() < moveWithBoxesOnlyThreshold))
07675               {
07676                      p.begin(viewport());
07677                      ToView(&p);
07678                      p.translate(qRound(currItem->xPos()*sc), qRound(currItem->yPos()*sc));
07679                      p.scale(sc, sc);
07680                      p.rotate(currItem->rotation());
07681                      p.setRasterOp(XorROP);
07682                      p.setBrush(NoBrush);
07683                      p.setPen(QPen(white, 1, DotLine, FlatCap, MiterJoin));
07684                      if (itemSelection->count() < moveWithFullOutlinesThreshold)
07685                      {
07686                             if (!(currItem->asLine()) && (currItem->FrameType != 0) || (currItem->asPolyLine()))
07687                                    currItem->DrawPolyL(&p, currItem->Clip);
07688                             else
07689                             {
07690                                    if (currItem->asLine())
07691                                    {
07692                                           int lw2 = 1;
07693                                           int lw = 1;
07694                                           PenCapStyle le = FlatCap;
07695                                           if (currItem->NamedLStyle.isEmpty())
07696                                           {
07697                                                  lw2 = qRound(QMAX(currItem->lineWidth()  / 2.0, 1.0));
07698                                                  lw = qRound(QMAX(currItem->lineWidth(), 1.0));
07699                                                  le = currItem->PLineEnd;
07700                                           }
07701                                           else
07702                                           {
07703                                                  multiLine ml = Doc->MLineStyles[currItem->NamedLStyle];
07704                                                  lw2 = qRound(ml[ml.size()-1].Width  / 2.0);
07705                                                  lw = qRound(QMAX(ml[ml.size()-1].Width, 1.0));
07706                                                  le = static_cast<PenCapStyle>(ml[ml.size()-1].LineEnd);
07707                                           }
07708                                           if (le != FlatCap)
07709                                                  p.drawRect(-lw2, -lw2, qRound(currItem->width())+lw, lw);
07710                                           else
07711                                                  p.drawRect(-1, -lw2, qRound(currItem->width()), lw);
07712                                    }
07713                             }
07714                      }
07715                      else
07716                             p.drawRect(0, 0, static_cast<int>(currItem->width())+1, static_cast<int>(currItem->height())+1);
07717                      p.end();
07718               }
07719        }
07720        if (itemSelection->isMultipleSelection())
07721        {
07722               itemSelection->setGroupRect();
07723               itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
07724               emit ItemPos(gx, gy);
07725               currItem = itemSelection->itemAt(0);
07726               Doc->GroupOnPage(currItem);
07727               if (fromMP)
07728               {
07729                      gx -= Doc->minCanvasCoordinate.x();
07730                      gy -= Doc->minCanvasCoordinate.y();
07731                      updateContents(QRect(static_cast<int>(gx*sc-5), static_cast<int>(gy*sc-5), static_cast<int>(gw*sc+10), static_cast<int>(gh*sc+10)));
07732               }
07733 
07734               getGroupRectScreen(&gx, &gy, &gw, &gh);
07735               p.begin(viewport());
07736               PaintSizeRect(&p, QRect(qRound(gx), qRound(gy), qRound(gw), qRound(gh)));
07737               p.end();
07738        }
07739        else
07740        {
07741               //Paint the drag moved item, ie the black dashed line representing the frame
07742               currItem = itemSelection->itemAt(0);
07743               QRect oldR = QRect(qRound(currItem->BoundingX * Scale), qRound(currItem->BoundingY * Scale), qRound(currItem->BoundingW * Scale), qRound(currItem->BoundingH * Scale));
07744               //CB this breaks dragging an item when the canvas has been push resized
07745               //oldR.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
07746               if (!currItem->asLine())
07747               {
07748                      p.begin(viewport());
07749                      ToView(&p);
07750                      PaintSizeRect(&p, oldR);
07751                      p.end();
07752               }
07753        }
07754 }
07755 
07756 //CB-->Doc
07757 void ScribusView::RotateGroup(double win)
07758 {
07759        if (!_groupTransactionStarted && Doc->m_Selection->count() > 1)
07760        {
07761               QString tooltip = Um::ItemsInvolved + "\n";
07762               for (uint i = 0; i < Doc->m_Selection->count(); ++i)
07763                      tooltip += "\t" + Doc->m_Selection->itemAt(i)->getUName() + "\n";
07764               undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup,
07765                                                                  Um::Rotate, tooltip, Um::IRotate);
07766               _groupTransactionStarted = true;
07767        }
07768        double gxS, gyS, ghS, gwS;
07769        double sc = Scale;
07770        PageItem* currItem;
07771        Doc->m_Selection->getGroupRect(&gxS, &gyS, &gwS, &ghS);
07772        QWMatrix ma;
07773        ma.translate(RCenter.x(), RCenter.y());
07774        ma.scale(1, 1);
07775        ma.rotate(win);
07776        gxS -= Doc->minCanvasCoordinate.x();
07777        gyS -= Doc->minCanvasCoordinate.y();
07778        QRect oldR = QRect(static_cast<int>(gxS*sc-5), static_cast<int>(gyS*sc-5), static_cast<int>(gwS*sc+10), static_cast<int>(ghS*sc+10));
07779        FPoint n;
07780        for (uint a = 0; a < Doc->m_Selection->count(); ++a)
07781        {
07782               currItem = Doc->m_Selection->itemAt(a);
07783               n = FPoint(currItem->xPos() - RCenter.x(), currItem->yPos() - RCenter.y());
07784               currItem->setXYPos(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
07785               currItem->rotateBy(win);
07786               Doc->setRedrawBounding(currItem);
07787        }
07788        currItem = Doc->m_Selection->itemAt(0);
07789        Doc->GroupOnPage(currItem);
07790        Doc->m_Selection->setGroupRect();
07791        Doc->m_Selection->getGroupRect(&gxS, &gyS, &gwS, &ghS);
07792        gxS -= Doc->minCanvasCoordinate.x();
07793        gyS -= Doc->minCanvasCoordinate.y();
07794        updateContents(QRect(static_cast<int>(gxS*sc-5), static_cast<int>(gyS*sc-5), static_cast<int>(gwS*sc+10), static_cast<int>(ghS*sc+10)).unite(oldR));
07795 }
07796 
07797 //CB-->Doc
07798 void ScribusView::scaleGroup(double scx, double scy, bool scaleText, Selection* customSelection)
07799 {
07800        Selection* itemSelection = (customSelection!=0) ? customSelection : Doc->m_Selection;
07801        Q_ASSERT(itemSelection!=0);
07802        uint selectedItemCount=itemSelection->count();
07803        if (selectedItemCount == 0)
07804               return;
07805        
07806        if (!_groupTransactionStarted && selectedItemCount > 1)
07807        {
07808               QString tooltip = Um::ItemsInvolved + "\n";
07809               for (uint i = 0; i < selectedItemCount; ++i)
07810                      tooltip += "\t" + itemSelection->itemAt(i)->getUName() + "\n";
07811               undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup,
07812                                                                  Um::Resize, tooltip, Um::IResize);
07813               _groupTransactionStarted = true;
07814        }
07815        PageItem *bb;
07816        double gx, gy, gh, gw, x, y;
07817        int aa;
07818        double sc = Scale;
07819        int drm = Doc->RotMode;
07820        Doc->RotMode = 0;
07821        itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
07822        gx -= Doc->minCanvasCoordinate.x();
07823        gy -= Doc->minCanvasCoordinate.y();
07824        QRect oldR = QRect(static_cast<int>(gx*sc-5), static_cast<int>(gy*sc-5), static_cast<int>(gw*sc+10), static_cast<int>(gh*sc+10));
07825        itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
07826        double origGW = gw;
07827        double origGH = gh;
07828        updatesOn(false);
07829 
07830        for (uint a = 0; a < selectedItemCount; ++a)
07831        {
07832               bb = itemSelection->itemAt(a);
07833               if ((bb->locked()) || (bb->sizeLocked()))
07834                      continue;
07835               bb->OldB = bb->width();
07836               bb->OldH = bb->height();
07837               bb->OldB2 = bb->width();
07838               bb->OldH2 = bb->height();
07839               bb->Sizing = false;
07840               double oldRot, oldLocalX, oldLocalY;
07841               oldRot = bb->rotation();
07842               oldLocalX = bb->imageXOffset();
07843               oldLocalY = bb->imageYOffset();
07844               FPointArray gr;
07845               gr.addPoint(bb->GrStartX, bb->GrStartY);
07846               gr.addPoint(bb->GrEndX, bb->GrEndY);
07847               FPoint g(gx, gy);
07848               FPoint b(0, 0, bb->xPos(), bb->yPos(), bb->rotation(), 1, 1);
07849               b -= g;
07850               FPoint b1(b.x(), b.y(), 0, 0, 0, scx, scy);
07851               FPoint t(bb->width(), 0, bb->xPos(), bb->yPos(), bb->rotation(), 1, 1);
07852               t -= g;
07853               FPoint t1(t.x(), t.y(), 0, 0, 0, scx, scy);
07854               FPoint h(0, bb->height(), bb->xPos(), bb->yPos(), bb->rotation(), 1, 1);
07855               h -= g;
07856               FPoint h1(h.x(), h.y(), 0, 0, 0, scx, scy);
07857               if (bb->Groups.count() != 0)                            // change the LineWidth only when the item is within a real Group
07858                      bb->setLineWidth(QMAX(bb->lineWidth()*((scx+scy)/2), 0.01));
07859               if (bb->itemType() == PageItem::Line)
07860               {
07861                      bb->setRotation(atan2(t1.y()-b1.y(),t1.x()-b1.x())*(180.0/M_PI));
07862                      bb->setWidth(sqrt(pow(t1.x()-b1.x(),2)+pow(t1.y()-b1.y(),2)));
07863                      bb->setXYPos(b1.x()+gx, b1.y()+gy);
07864               }
07865               else
07866               {
07867                      FPoint oldPos(bb->xPos(), bb->yPos());
07868                      QWMatrix ma;
07869                      ma.rotate(bb->rotation());
07870                      bb->PoLine.map(ma);
07871                      QWMatrix ma2;
07872                      ma2.translate(gx-bb->xPos(), gy-bb->yPos());
07873                      ma2.scale(scx, scy);
07874                      bb->PoLine.map(ma2);
07875                      bb->setRotation(0.0);
07876                      bb->ClipEdited = true;
07877                      Doc->AdjustItemSize(bb);
07878                      QWMatrix ma3;
07879                      ma3.translate(gx, gy);
07880                      ma3.scale(scx, scy);
07881                      FPoint n(gx-oldPos.x(), gy-oldPos.y());
07882                      x = ma3.m11() * n.x() + ma3.m21() * n.y() + ma3.dx();
07883                      y = ma3.m22() * n.y() + ma3.m12() * n.x() + ma3.dy();
07884                      Doc->MoveItem(gx-x, gy-y, bb, true);
07885                      if (oldRot != 0)
07886                      {
07887                             bb->setRotation(atan2(t1.y()-b1.y(),t1.x()-b1.x())*(180.0/M_PI));
07888                             QWMatrix ma;
07889                             ma.rotate(-bb->rotation());
07890                             bb->PoLine.map(ma);
07891                             Doc->AdjustItemSize(bb);
07892                      }
07893               }
07894               if (scaleText)
07895               {
07896 #ifndef NLS_PROTO
07897 //                   bb->setFontSize(QMAX(qRound(bb->fontSize()*((scx+scy)/2)), 1));
07898                      if ((bb->itemText.length() != 0) && (!bb->isTableItem))
07899                      {
07900 //                          bb->setLineSpacing(((bb->fontSize() / 10.0) * static_cast<double>(Doc->typographicSettings.autoLineSpacing) / 100) + (bb->fontSize() / 10.0));
07901                             for (aa = 0; aa < bb->itemText.length(); ++aa)
07902                                    bb->itemText.item(aa)->setFontSize(QMAX(qRound(bb->itemText.item(aa)->fontSize()*((scx+scy)/2)), 1));
07903                             if (bb->asPathText())
07904                                    bb->updatePolyClip();
07905                      }
07906 #endif
07907               }
07908               bb->setImageXYOffset(oldLocalX, oldLocalY);
07909               bb->OldB2 = bb->width();
07910               bb->OldH2 = bb->height();
07911               QWMatrix ma4;
07912               ma4.rotate(oldRot);
07913               ma4.scale(scx, scy);
07914               gr.map(ma4);
07915               bb->ContourLine.map(ma4);
07916               bb->GrStartX = gr.point(0).x();
07917               bb->GrStartY = gr.point(0).y();
07918               bb->GrEndX = gr.point(1).x();
07919               bb->GrEndY = gr.point(1).y();
07920               bb->updateGradientVectors();
07921        }
07922        bb = itemSelection->itemAt(0);
07923        Doc->GroupOnPage(bb);
07924        itemSelection->setGroupRect();
07925        itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
07926        Doc->RotMode = drm;
07927        if ((Doc->RotMode != 0) && (!Doc->isLoading()))
07928        {
07929               switch (Doc->RotMode)
07930               {
07931               case 2:
07932                      moveGroup((origGW-gw) / 2.0, (origGH-gh) / 2.0, true);
07933                      break;
07934               case 4:
07935                      moveGroup(origGW-gw, origGH-gh, true);
07936                      break;
07937               case 3:
07938                      moveGroup(0.0, origGH-gh, true);
07939                      break;
07940               case 1:
07941                      moveGroup(origGW-gw, 0.0, true);
07942                      break;
07943               }
07944        }
07945        gx -= Doc->minCanvasCoordinate.x();
07946        gy -= Doc->minCanvasCoordinate.y();
07947        updatesOn(true);
07948        updateContents(QRect(static_cast<int>(gx*sc-5), static_cast<int>(gy*sc-5), static_cast<int>(gw*sc+10), static_cast<int>(gh*sc+10)).unite(oldR));
07949        itemSelection->setGroupRect();
07950        itemSelection->getGroupRect(&gx, &gy, &gw, &gh);
07951        for (uint a = 0; a < selectedItemCount; ++a)
07952        {
07953               PageItem *currItem = itemSelection->itemAt(a);
07954               currItem->gXpos = currItem->xPos() - gx;
07955               currItem->gYpos = currItem->yPos() - gy;
07956               currItem->gWidth = gw;
07957               currItem->gHeight = gh;
07958        }
07959        emit DocChanged();
07960 }
07961 
07962 
07963 bool ScribusView::slotSetCurs(int x, int y)
07964 {
07965        PageItem *currItemGeneric;
07966        if (GetItem(&currItemGeneric))
07967        {
07968               if (!((currItemGeneric->asTextFrame()) || (currItemGeneric->asImageFrame())))
07969                      return false;
07970               // unsed by gcc warning - PV
07971               //int xP = qRound(x/Scale + Doc->minCanvasCoordinate.x());
07972               //int yP = qRound(y/Scale + Doc->minCanvasCoordinate.y());
07973               QPainter p;
07974               p.begin(this);
07975               Transform(currItemGeneric, &p);
07976               p.translate(qRound(-Doc->minCanvasCoordinate.x()), qRound(-Doc->minCanvasCoordinate.y()));
07977               if (currItemGeneric->asImageFrame())
07978                      return true;
07979               PageItem_TextFrame *currItem=currItemGeneric->asTextFrame();
07980               if (currItem==0)
07981                      return false;
07982               QRect mpo(x - Doc->guidesSettings.grabRad, y - Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
07983               if ((QRegion(p.xForm(QPointArray(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo)) ||
07984                       (QRegion(p.xForm(currItem->Clip)).contains(mpo)))
07985               {
07986                      m_cursorVisible = true;
07987 #if 0
07988 //#ifndef NLS_PROTO
07989                      //Work out which column we are in
07990                      double colWidth=currItem->columnWidth();
07991                      double colGap=currItem->ColGap;
07992                      int currCol=0;
07993                      int cp=static_cast<int>(currItem->xPos()+currItem->textToFrameDistLeft()+qRound(colGap)+qRound(colWidth));
07994                      while (xP>cp)
07995                      {
07996                             ++currCol;
07997                             cp+=qRound(colGap);
07998                             cp+=qRound(colWidth);
07999                      };
08000                      int a, xp=0, yp=0, h;
08001                      bool breakAndReturn=false;
08002                      int currItemTextCount=currItem->itemText.length();
08003                      for (a = currItem->firstInFrame(); a <= currItem->lastInFrame(); ++a)
08004                      {
08005                             xp = static_cast<int>(currItem->itemText.item(a)->glyph.xoffset);
08006                             //If x pos of curr char is less than left position of current column, continue
08007                             if (xp+currItem->xPos()<cp-colWidth-colGap)
08008                                    continue;
08009                             yp = static_cast<int>(currItem->itemText.item(a)->glyph.yoffset);
08010                             h = static_cast<int>(currItem->itemText.paragraphStyle(a).lineSpacing());
08011 
08012                             if (a<currItemTextCount-1)
08013                             {
08014                                    if ((xp+currItem->xPos()+1>=xP) && (yp+currItem->yPos()>=yP))
08015                                    {
08016                                           //beginning of new paragraph or not
08017                                           if (((currItem->itemText.text(a) == SpecialChars::PARSEP) || (currItem->itemText.text(a) == SpecialChars::LINEBREAK)))
08018                                                  currItem->CPos = a+1;
08019                                           else
08020                                                  currItem->CPos = a;
08021                                           p.end();
08022                                           breakAndReturn=true;
08023                                           break;
08024                                    }
08025                                    if (yp-h+currItem->yPos()<=yP && yp+currItem->yPos()>=yP)
08026                                    {
08027                                           //click where next char is on next line in same or next column
08028                                           if (static_cast<int>(currItem->itemText.item(a+1)->glyph.yoffset)!=yp)
08029                                           {
08030                                                  if (((currItem->itemText.text(a+1) == SpecialChars::PARSEP) || (currItem->itemText.text(a+1) == SpecialChars::LINEBREAK)))
08031                                                         currItem->CPos = a+1;
08032                                                  else
08033                                                         currItem->CPos = a;
08034                                                  p.end();
08035                                                  breakAndReturn=true;
08036                                                  break;
08037                                           }
08038                                    }
08039                             }
08040 
08041                             /* CB old, rather complicated code...
08042                             chx = currItem->itemText.at(a)->ch;
08043                             if (chx == QChar(30))
08044                                    chx = currItem->ExpandToken(a);
08045                             if (chx == QChar(29))
08046                                    chx = " ";
08047                             chs = currItem->itemText.at(a)->csize;
08048                             currItem->SetZeichAttr(currItem->itemText.charStyle(a), &chs, &chx);
08049                             if ((chx == QChar(13)) || (chx == QChar(9)) || (chx == QChar(27)))
08050                                    w = 1;
08051                             else
08052                                    w = qRound(Cwidth(Doc, currItem->itemText.at(a)->cfont, chx, chs)*(currItem->itemText.at(a)->cscale / 1000.0));
08053                             h = static_cast<int>(Doc->docParagraphStyles[currItem->itemText.at(a)->cab].LineSpa);
08054                             //If we click within text
08055                             if (QRegion(p.xForm(QRect(xp-1, yp-h, w+1, h))).contains(QPoint(x, y)))
08056                             {
08057                                    currItem->CPos = a;
08058                                    p.end();
08059                                    breakAndReturn=true;
08060                                    break;
08061                             }
08062                             //If we are not at the end of the text and the next characters y position > current one
08063                             //IE, we are at the end of the line
08064                             else if ((a<currItemTextCount-1) && (static_cast<int>(currItem->itemText.at(a+1)->yp)>yp))
08065                             {
08066                                    //If one column only and we are within the width of the frame
08067                                    //Yes, some people want selection outside the frame to work too, this works ok for now
08068                                    if ((currItem->Cols==1) && (QRegion(p.xForm(QRect(xp-1, yp-h, static_cast<int>(currItem->width()-xp-1), h))).contains(QPoint(x, y))))
08069                                    {
08070                                           currItem->CPos = a;
08071                                           p.end();
08072                                           breakAndReturn=true;
08073                                           break;
08074                                    }
08075                                    //If columns>1, then work out what column we are in and place our cursor
08076                                    //TODO: Move this column placement code into PageItem_TextFrame.
08077                                    else if (currItem->Cols>1)
08078                                    {
08079                                           double colWidth=currItem->columnWidth();
08080                                           int currCol=0;
08081                                           int cp=static_cast<int>(currItem->xPos()+currItem->textToFrameDistLeft());
08082                                           do
08083                                           {
08084                                                  ++currCol;
08085                                                  cp+=qRound(currItem->ColGap);
08086                                                  if (currCol>1)
08087                                                         cp+=qRound(colWidth);
08088                                           } while (xp>cp);
08089                                           if (QRegion(p.xForm(QRect(xp-1, yp-h, static_cast<int>(cp-xp-1), h))).contains(QPoint(x, y)))
08090                                           {
08091                                                  currItem->CPos = a;
08092                                                  p.end();
08093                                                  breakAndReturn=true;
08094                                                  break;
08095                                           }
08096                                    }
08097                             }*/
08098                      }
08099                      if (breakAndReturn)
08100                      {
08101                             Doc->currentStyle.charStyle() = currItem->itemText.charStyle(a);
08102                             emit ItemTextStrike(currItem->itemText.charStyle(a).strikethruOffset(), currItem->itemText.charStyle(a).strikethruWidth());
08103                             emit ItemTextUnderline(currItem->itemText.charStyle(a).underlineOffset(), currItem->itemText.charStyle(a).underlineWidth());
08104                             emit ItemTextOutline(currItem->itemText.charStyle(a).outlineWidth());
08105                             emit ItemTextShadow(currItem->itemText.charStyle(a).shadowXOffset(), currItem->itemText.charStyle(a).shadowYOffset());
08106                             emit ItemTextBase(currItem->itemText.charStyle(a).baselineOffset());
08107                             emit ItemTextSca(currItem->itemText.charStyle(a).scaleH());
08108                             emit ItemTextScaV(currItem->itemText.charStyle(a).scaleV());
08109                             emit ItemTextFont(currItem->itemText.charStyle(a).font().scName());
08110                             emit ItemTextSize(currItem->itemText.charStyle(a).fontSize());
08111                             emit ItemTextUSval(currItem->itemText.charStyle(a).tracking());
08112                             emit ItemTextStil(currItem->itemText.charStyle(a).effects());
08113                             emit ItemTextAbs(currItem->itemText.paragraphStyle(a).alignment());
08114                             emit ItemTextFarben(currItem->itemText.charStyle(a).strokeColor(), currItem->itemText.charStyle(a).fillColor(), currItem->itemText.charStyle(a).strokeShade(), currItem->itemText.charStyle(a).fillShade());
08115                             return true;
08116                      }
08117 
08118                      /*currItemTextCount=currItem->itemText.count();
08119                      qDebug(QString("%1").arg(2));
08120                      for (a=0; a<currItemTextCount; ++a)
08121                      {
08122                             xp = static_cast<int>(currItem->itemText.at(a)->xp);
08123                             yp = static_cast<int>(currItem->itemText.at(a)->yp);
08124                             QPoint np = p.xForm(QPoint(xp, yp - static_cast<int>(Doc->docParagraphStyles[currItem->itemText.at(a)->cab].LineSpa)));
08125                             if (yP < np.y())
08126                             {
08127                                    currItem->CPos = a;
08128                                    p.end();
08129                                    uint i=a;
08130                                    if (a > 0)
08131                                           i--;
08132                                    Doc->CurrFont = currItem->itemText.at(i)->cfont->scName();
08133                                    Doc->CurrFontSize = currItem->itemText.at(i)->csize;
08134                                    Doc->CurrTextFill = currItem->itemText.at(i)->ccolor;
08135                                    Doc->CurrTextFillSh = currItem->itemText.at(i)->cshade;
08136                                    Doc->CurrTextStroke = currItem->itemText.at(i)->cstroke;
08137                                    Doc->CurrTextStrokeSh = currItem->itemText.at(i)->cshade2;
08138                                    Doc->CurrTextScale = currItem->itemText.at(i)->cscale;
08139                                    Doc->CurrTextScaleV = currItem->itemText.at(i)->cscalev;
08140                                    Doc->CurrTextBase = currItem->itemText.at(i)->cbase;
08141                                    Doc->CurrTextShadowX = currItem->itemText.at(i)->cshadowx;
08142                                    Doc->CurrTextShadowY = currItem->itemText.at(i)->cshadowy;
08143                                    Doc->CurrTextOutline = currItem->itemText.at(i)->coutline;
08144                                    Doc->CurrTextUnderPos = currItem->itemText.at(i)->cunderpos;
08145                                    Doc->CurrTextUnderWidth = currItem->itemText.at(i)->cunderwidth;
08146                                    Doc->CurrTextStrikePos = currItem->itemText.at(i)->cstrikepos;
08147                                    Doc->CurrTextStrikeWidth = currItem->itemText.at(i)->cstrikewidth;
08148                                    emit ItemTextStrike(currItem->itemText.at(i)->cstrikepos, currItem->itemText.at(i)->cstrikewidth);
08149                                    emit ItemTextUnderline(currItem->itemText.at(i)->cunderpos, currItem->itemText.at(i)->cunderwidth);
08150                                    emit ItemTextOutline(currItem->itemText.at(i)->coutline);
08151                                    emit ItemTextShadow(currItem->itemText.at(i)->cshadowx, currItem->itemText.at(i)->cshadowy);
08152                                    emit ItemTextSca(currItem->itemText.at(i)->cscale);
08153                                    emit ItemTextScaV(currItem->itemText.at(i)->cscalev);
08154                                    emit ItemTextFarben(currItem->itemText.at(i)->cstroke, currItem->itemText.at(i)->ccolor, currItem->itemText.at(i)->cshade2, currItem->itemText.at(i)->cshade);
08155                                    emit ItemTextFont(currItem->itemText.at(i)->cfont->scName());
08156                                    emit ItemTextSize(currItem->itemText.at(i)->csize);
08157                                    emit ItemTextUSval(currItem->itemText.at(i)->cextra);
08158                                    emit ItemTextStil(currItem->itemText.at(i)->cstyle);
08159                                    emit ItemTextAbs(currItem->itemText.at(i)->cab);
08160                                    emit ItemTextBase(currItem->itemText.at(i)->cbase);
08161                                    return true;
08162                             }
08163                      }
08164                      */
08165                      //End of text in frame
08166                      if (currItem->itemText.length() != 0)
08167                      {
08168                             a=currItem->lastInFrame();
08169                             int w = qRound(currItem->itemText.charStyle(a).font().charWidth(currItem->itemText.text(a), currItem->itemText.charStyle(a).fontSize())*(currItem->itemText.charStyle(a).scaleH() / 1000.0));
08170                             if (xp+currItem->xPos()+w<xP || yp+currItem->yPos()<yP)
08171                                    currItem->CPos = a+1;
08172                             else
08173                                    currItem->CPos = a;
08174                      }
08175                      else
08176                             currItem->CPos = 0;
08177                      p.end();
08178 
08179 #else
08180                      FPoint point((x + Doc->minCanvasCoordinate.x()) / Scale - currItem->xPos(), 
08181                                            (y + Doc->minCanvasCoordinate.x()) / Scale - currItem->yPos());
08182                      currItem->CPos = currItem->itemText.length() == 0 ? 0 :
08183                             currItem->itemText.screenToPosition(point);                    
08184 #endif
08185                      
08186                      if (currItem->itemText.length() > 0)
08187                      {
08188                             int b=currItem->CPos-1;
08189                             if (b<0)
08190                                    b=0;
08191                             Doc->currentStyle.charStyle() = currItem->itemText.charStyle(b);
08192                             emit ItemTextStrike(Doc->currentStyle.charStyle().strikethruOffset(), Doc->currentStyle.charStyle().strikethruWidth());
08193                             emit ItemTextUnderline(Doc->currentStyle.charStyle().underlineOffset(), Doc->currentStyle.charStyle().underlineWidth());
08194                             emit ItemTextOutline(Doc->currentStyle.charStyle().outlineWidth());
08195                             emit ItemTextShadow(Doc->currentStyle.charStyle().shadowXOffset(), Doc->currentStyle.charStyle().shadowYOffset());
08196                             emit ItemTextSca(Doc->currentStyle.charStyle().scaleH());
08197                             emit ItemTextScaV(Doc->currentStyle.charStyle().scaleV());
08198                             emit ItemTextFarben(Doc->currentStyle.charStyle().strokeColor(), Doc->currentStyle.charStyle().fillColor(), Doc->currentStyle.charStyle().strokeShade(), Doc->currentStyle.charStyle().fillShade());
08199                             emit ItemTextFont(Doc->currentStyle.charStyle().font().scName());
08200                             emit ItemTextSize(Doc->currentStyle.charStyle().fontSize());
08201                             emit ItemTextUSval(Doc->currentStyle.charStyle().tracking());
08202                             emit ItemTextStil(Doc->currentStyle.charStyle().effects());
08203                             emit ItemTextAbs(currItem->itemText.paragraphStyle(b).alignment());
08204                             emit ItemTextBase(Doc->currentStyle.charStyle().baselineOffset());
08205                             return true;
08206                      }
08207                      else
08208                      {
08209                             Doc->currentStyle.charStyle() = currItem->itemText.defaultStyle().charStyle();
08210                             emit ItemTextStrike(currItem->itemText.defaultStyle().charStyle().strikethruOffset(), currItem->itemText.defaultStyle().charStyle().strikethruWidth());
08211                             emit ItemTextUnderline(currItem->itemText.defaultStyle().charStyle().underlineOffset(), currItem->itemText.defaultStyle().charStyle().underlineWidth());
08212                             emit ItemTextOutline(currItem->itemText.defaultStyle().charStyle().outlineWidth());
08213                             emit ItemTextShadow(currItem->itemText.defaultStyle().charStyle().shadowXOffset(), currItem->itemText.defaultStyle().charStyle().shadowYOffset());
08214                             emit ItemTextSca(currItem->itemText.defaultStyle().charStyle().scaleH());
08215                             emit ItemTextScaV(currItem->itemText.defaultStyle().charStyle().scaleV());
08216                             emit ItemTextFarben(currItem->itemText.defaultStyle().charStyle().strokeColor(), currItem->itemText.defaultStyle().charStyle().fillColor(), currItem->itemText.defaultStyle().charStyle().strokeShade(), currItem->itemText.defaultStyle().charStyle().fillShade());
08217                             emit ItemTextFont(currItem->itemText.defaultStyle().charStyle().font().scName());
08218                             emit ItemTextSize(currItem->itemText.defaultStyle().charStyle().fontSize());
08219                             emit ItemTextUSval(currItem->itemText.defaultStyle().charStyle().tracking());
08220                             emit ItemTextStil(currItem->itemText.defaultStyle().charStyle().effects());
08221                             emit ItemTextAbs( 0 );
08222                             emit ItemTextBase(currItem->itemText.defaultStyle().charStyle().baselineOffset());
08223                             return true;
08224                      }
08225               }
08226        }
08227        return false;
08228 }
08229 
08230 void ScribusView::slotDoCurs(bool draw)
08231 {
08232        PageItem *currItem;
08233        if (GetItem(&currItem))
08234        {
08235               PageItem_TextFrame * textframe = currItem->asTextFrame();
08236               if ( !textframe )
08237                      return;
08238               
08239               // don't mess around with itemText when layout() is about to happen
08240               if (currItem->invalid)
08241                      return;
08242               
08243               //              textframe->lastTextItem = QMIN(textframe->lastTextItem, 
08244               //                                             signed(textframe->itemText.nrOfItems()) - 1);
08245               
08246               if (textframe->firstInFrame() >= 0 
08247                      && ((textframe->lastInFrame() >= textframe->firstInFrame()
08248                              && textframe->CPos >= textframe->itemText.startOfItem(textframe->firstInFrame())
08249                              && textframe->CPos <= textframe->itemText.endOfItem(textframe->lastInFrame())
08250                              ) 
08251                             || 
08252                             textframe->CPos >= textframe->itemText.length()
08253                             )
08254                      )
08255               {
08256                      QPainter p;
08257                      p.begin(viewport());
08258                      ToView(&p);
08259                      Transform(textframe, &p);
08260                      TransformM(textframe, &p);
08261                      
08262                      if (Doc->CurTimer != 0)
08263                             Doc->CurTimer->stop();
08264                      
08265                      int x, y, y1;
08266 #ifdef NLS_PROTO
08267                      if (textframe->CPos == textframe->itemText.endOfItem(textframe->lastInFrame()))
08268                      {
08269                             ScScriptItem * last = textframe->itemText.item(textframe->lastInFrame());
08270                             x = static_cast<int>(last->x + last->naturalWidth);
08271                             y = static_cast<int>(last->y);
08272                             y1 = static_cast<int>(last->y - 12);
08273                             qDebug(QString("cursor at end (%1,%2)").arg(x).arg(y));
08274                      }
08275                      else
08276                      {
08277                             glyph_metrics_t bbox = textframe->itemText.boundingBox(textframe->CPos);
08278                             x = static_cast<int>(bbox.x);
08279                             y = static_cast<int>(bbox.y);
08280                             y1 = static_cast<int>(bbox.y - bbox.height);
08281 //                          qDebug(QString("cursor at (%1,%2) + %3").arg(bbox.x).arg(bbox.y).arg(bbox.height));
08282                      }
08283 #else
08284                      if (textframe->CPos > textframe->itemText.length())
08285                      {
08286                             textframe->CPos = textframe->itemText.length();
08287                      }
08288                      if (textframe->lastInFrame() >= signed(textframe->itemText.nrOfItems()) 
08289                             || textframe->itemText.length() == 0)
08290                      {
08291                             x = 0;
08292                             y = 0;
08293                             y1 = static_cast<int>(textframe->itemText.defaultStyle().charStyle().fontSize() / 10);
08294                      }
08295                      else if ( textframe->CPos > textframe->itemText.endOfItem(textframe->lastInFrame())
08296                                      || (textframe->CPos >= textframe->itemText.length() && textframe->itemText.text(textframe->itemText.length()-1) != SpecialChars::PARSEP) )
08297                      {
08298                             FRect bbox = textframe->itemText.boundingBox(QMAX(0,QMIN(textframe->lastInFrame(), textframe->itemText.length()-1)));
08299                             x = static_cast<int>(bbox.x() + textframe->itemText.item(QMAX(0,QMIN(textframe->lastInFrame(), textframe->itemText.length()-1)))->glyph.wide());
08300                             y = static_cast<int>(bbox.y());
08301                             if (bbox.height() <= 2)
08302                                    y1 = static_cast<int>(bbox.y() + textframe->itemText.defaultStyle().charStyle().fontSize() / 30);
08303                             else
08304                                    y1 = static_cast<int>(bbox.y() + bbox.height());
08305                      }
08306                      else
08307                      {
08308                             FRect bbox = textframe->itemText.boundingBox(QMAX(0,QMIN(textframe->CPos, textframe->itemText.length())));
08309                             x = static_cast<int>(bbox.x());
08310                             y = static_cast<int>(bbox.y());
08311                             if (bbox.height() <= 2) 
08312                                    y1 = static_cast<int>(bbox.y() + textframe->itemText.charStyle(textframe->CPos).fontSize() / 30);
08313                             else
08314                                    y1 = static_cast<int>(bbox.y() + bbox.height());
08315                      }
08316 #endif
08317                      // avoid displaying the cursor on the frameborder
08318                      if (x < 1)
08319                             x = 1;
08320                      p.setPen(QPen(white, 2, SolidLine, FlatCap, MiterJoin));
08321                      p.setRasterOp(XorROP);
08322                      if (draw)
08323                      {
08324                             p.drawLine(x, QMIN(QMAX(y,0),static_cast<int>(currItem->height())), 
08325                                              x, QMIN(QMAX(y1,0),static_cast<int>(currItem->height())));
08326                             m_cursorVisible = !m_cursorVisible;
08327                             if (Doc->CurTimer != 0)
08328                             {
08329                                    if (!Doc->CurTimer->isActive())
08330                                           Doc->CurTimer->start(500);
08331                             }
08332                      }
08333                      else
08334                      {
08335                             if (Doc->CurTimer != 0)
08336                                    Doc->CurTimer->stop();
08337                             if (m_cursorVisible)
08338                                    p.drawLine(x, QMIN(QMAX(y,0),static_cast<int>(currItem->height())), 
08339                                                     x, QMIN(QMAX(y1,0),static_cast<int>(currItem->height())));
08340                             m_cursorVisible = false;
08341                      }
08342                      p.end();
08343               }
08344        }
08345 }
08346 
08347 void ScribusView::blinkCursor()
08348 {
08349        slotDoCurs(true);
08350 }
08351 
08352 void ScribusView::HandleCurs(QPainter *p, PageItem *currItem, QRect mpo)
08353 {
08354        QPoint tx, tx2;
08355        QWMatrix ma = p->worldMatrix();
08356        ma.setTransformationMode ( QWMatrix::Areas );
08357        p->setWorldMatrix(ma);
08358        tx = p->xForm(QPoint(static_cast<int>(currItem->width()), 0));
08359        tx2 = p->xForm(QPoint(0, static_cast<int>(currItem->height())));
08360        if (mpo.contains(tx) || mpo.contains(tx2))
08361        {
08362               if (Doc->appMode == modeRotation)
08363                      qApp->setOverrideCursor(QCursor(loadIcon("Rotieren2.png")), true);
08364               else
08365               {
08366                      double rr = fabs(currItem->rotation());
08367                      if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || ((rr >=315.0) && (rr <= 360.0)))
08368                             qApp->setOverrideCursor(QCursor(SizeBDiagCursor), true);
08369                      if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0)))
08370                             qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
08371               }
08372        }
08373        tx = p->xForm(QPoint(static_cast<int>(currItem->width()), static_cast<int>(currItem->height())/2));
08374        tx2 = p->xForm(QPoint(0, static_cast<int>(currItem->height())/2));
08375        if (mpo.contains(tx) || mpo.contains(tx2))
08376        {
08377               double rr = fabs(currItem->rotation());
08378               if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || ((rr >= 315.0) && (rr <= 360.0)))
08379                      qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
08380               if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0)))
08381                      qApp->setOverrideCursor(QCursor(SizeVerCursor), true);
08382        }
08383        tx = p->xForm(QPoint(static_cast<int>(currItem->width())/2, 0));
08384        tx2 = p->xForm(QPoint(static_cast<int>(currItem->width())/2, static_cast<int>(currItem->height())));
08385        if (mpo.contains(tx) || mpo.contains(tx2))
08386        {
08387               double rr = fabs(currItem->rotation());
08388               if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) || ((rr >= 315.0) && (rr <= 360.0)))
08389                      qApp->setOverrideCursor(QCursor(SizeVerCursor), true);
08390               if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0)))
08391                      qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
08392        }
08393        tx = p->xForm(QPoint(static_cast<int>(currItem->width()), static_cast<int>(currItem->height())));
08394        tx2 = p->xForm(QPoint(0, 0));
08395        if (mpo.contains(tx) || mpo.contains(tx2))
08396        {
08397               if (Doc->appMode == modeRotation)
08398                      qApp->setOverrideCursor(QCursor(loadIcon("Rotieren2.png")), true);
08399               else
08400               {
08401                      double rr = fabs(currItem->rotation());
08402                      if (((rr >= 0.0) && (rr < 45.0)) || ((rr >= 135.0) && (rr < 225.0)) ||
08403                              ((rr >= 315.0) && (rr <= 360.0)))
08404                             qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
08405                      if (((rr >= 45.0) && (rr < 135.0)) || ((rr >= 225.0) && (rr < 315.0)))
08406                             qApp->setOverrideCursor(QCursor(SizeBDiagCursor), true);
08407               }
08408        }
08409        if (Doc->EditClip)
08410               qApp->setOverrideCursor(QCursor(crossCursor), true);
08411 }
08412 
08413 void ScribusView::SelectItemNr(uint nr, bool draw, bool single)
08414 {
08415        if (nr < Doc->Items->count())
08416               SelectItem(Doc->Items->at(nr), draw, single);
08417 }
08418 
08419 //CB-->Doc/Fix
08420 void ScribusView::SelectItem(PageItem *currItem, bool draw, bool single)
08421 {
08422        if (!currItem->isSelected())
08423        {
08424               if (single)
08425               {
08426                      Doc->m_Selection->addItem(currItem);
08427                      currItem->isSingleSel = true;
08428                      currItem->paintObj();
08429               }
08430               else
08431               {
08432                      if (currItem->Groups.count() != 0)
08433                      {
08434                             if (Doc->m_Selection->count() != 0)
08435                             {
08436                                    if (Doc->m_Selection->findItem(currItem) == -1)
08437                                           Doc->m_Selection->addItem(currItem);
08438                             }
08439                             else
08440                                    Doc->m_Selection->addItem(currItem);
08441                             
08442                             for (uint ga=0; ga<Doc->Items->count(); ++ga)
08443                             {
08444                                    if (Doc->Items->at(ga)->Groups.count() != 0)
08445                                    {
08446                                           if (Doc->Items->at(ga)->Groups.top() == currItem->Groups.top())
08447                                           {
08448                                                  if (Doc->Items->at(ga)->ItemNr != currItem->ItemNr)
08449                                                  {
08450                                                         if (Doc->m_Selection->findItem(Doc->Items->at(ga)) == -1)
08451                                                                Doc->m_Selection->addItem(Doc->Items->at(ga));
08452                                                  }
08453                                                  Doc->Items->at(ga)->paintObj();
08454                                           }
08455                                    }
08456                             }
08457                      }
08458                      else
08459                      {
08460                             Doc->m_Selection->addItem(currItem);
08461                             currItem->paintObj();
08462                      }
08463                      //CB FIXME/TODO We are surely prepending here and we have turned off 
08464                      //emitting in prepend below so do it here.
08465                      //Doc->m_Selection->itemAt(0)->emitAllToGUI();
08466               }
08467        }
08468        else
08469        {
08470        //CB Prepend used to occur to enable level changes to work properly, however with 
08471        //current selection code we dont seem to need that anymore
08472        /*
08473               if (Doc->m_Selection->count() > 1)
08474               {
08475                      PageItem *bb = Doc->m_Selection->itemAt(0);
08476                      Doc->m_Selection->removeItem(currItem);
08477                      Doc->m_Selection->prependItem(currItem, false);
08478                      currItem->paintObj();
08479                      bb->paintObj();
08480               }*/
08481        }
08482        if (draw)
08483        {
08484               if (Doc->m_Selection->count() > 1)
08485               {
08486                      Doc->m_Selection->setGroupRect();
08487                      paintGroupRect();
08488                      double x, y, w, h;
08489                      Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
08490                      emit ItemPos(x, y);
08491                      emit ItemGeom(w, h);
08492                      //CB move in here as the emitAllToGUI will do it otherwise
08493                      emit HaveSel(currItem->itemType());
08494               }
08495               //CB done by addItem for single selection or the frame data is already there
08496               //else
08497                      //EmitValues(currItem);
08498                      //currItem->emitAllToGUI();
08499        }
08500 }
08501 
08502 void ScribusView::selectionChanged()
08503 {
08504        if (m_ScMW->isObjectSpecificUndo())
08505        {
08506               uint docSelectionCount=Doc->m_Selection->count();
08507               if (docSelectionCount == 1)
08508                      undoManager->showObject(Doc->m_Selection->itemAt(0)->getUId());
08509               else if (docSelectionCount == 0)
08510                      undoManager->showObject(Doc->currentPage()->getUId());
08511               else
08512                      undoManager->showObject(Um::NO_UNDO_STACK);
08513        }
08514 }
08515 
08516 void ScribusView::selectPage(QMouseEvent *m)
08517 {
08518        m_MouseButtonPressed = true;
08519        Mxp = static_cast<int>(m->x()/Scale);
08520        Myp = static_cast<int>(m->y()/Scale);
08521        QRect mpo(m->x()-Doc->guidesSettings.grabRad, m->y()-Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
08522        mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
08523        ClRe = -1;
08524        Deselect(false);
08525        if (!Doc->masterPageMode())
08526        {
08527               int i = Doc->OnPage(Mxp + Doc->minCanvasCoordinate.x(), Myp + Doc->minCanvasCoordinate.y());
08528               if (i!=-1)
08529               {
08530                      uint docCurrPageNo=Doc->currentPageNumber();
08531                      uint j=static_cast<uint>(i);
08532                      if (docCurrPageNo != j)
08533                      {
08534                             Doc->setCurrentPage(Doc->Pages->at(j));
08535                             setMenTxt(j);
08536                             DrawNew();
08537                      }
08538               }
08539 /*            uint docPagesCount=Doc->Pages->count();
08540               uint docCurrPageNo=Doc->currentPageNumber();
08541               for (uint i = 0; i < docPagesCount; ++i)
08542               {
08543                      int x = static_cast<int>(Doc->Pages->at(i)->xOffset() * Scale);
08544                      int y = static_cast<int>(Doc->Pages->at(i)->yOffset() * Scale);
08545                      int w = static_cast<int>(Doc->Pages->at(i)->width() * Scale);
08546                      int h = static_cast<int>(Doc->Pages->at(i)->height() * Scale);
08547                      if (QRect(x, y, w, h).intersects(mpo))
08548                      {
08549                             if (docCurrPageNo != i)
08550                             {
08551                                    Doc->setCurrentPage(Doc->Pages->at(i));
08552                                    setMenTxt(i);
08553                                    DrawNew();
08554                             }
08555                             break;
08556                      }
08557               } */
08558               setRulerPos(contentsX(), contentsY());
08559        }
08560 }
08561 
08562 //CB-->Doc/Fix
08563 bool ScribusView::SeleItem(QMouseEvent *m)
08564 {
08565        QPainter p;
08566        QRect tx, mpo;
08567        PageItem *currItem;
08568        m_MouseButtonPressed = true;
08569        Mxp = static_cast<int>(m->x()/Scale);
08570        Myp = static_cast<int>(m->y()/Scale);
08571        int MxpS = static_cast<int>(m->x()/Scale + Doc->minCanvasCoordinate.x());
08572        int MypS = static_cast<int>(m->y()/Scale + Doc->minCanvasCoordinate.y());
08573        mpo = QRect(m->x()-Doc->guidesSettings.grabRad, m->y()-Doc->guidesSettings.grabRad, Doc->guidesSettings.grabRad*2, Doc->guidesSettings.grabRad*2);
08574        mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
08575        ClRe = -1;
08576        if ((Doc->m_Selection->count() != 0) && (m->state() == ControlButton))
08577               currItem = Doc->m_Selection->itemAt(0);
08578        else
08579               currItem = Doc->Items->last();
08580        uint a;
08581        if (!Doc->masterPageMode())
08582        {
08583               int pgNum = -1;
08584               int docPageCount = static_cast<int>(Doc->Pages->count() - 1);
08585               double bleedRight = 0.0;
08586               double bleedLeft = 0.0;
08587               double bleedBottom = 0.0;
08588               double bleedTop = 0.0;
08589               bool drawBleed = false;
08590               if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
08591                      drawBleed = true;
08592               for (int a = docPageCount; a > -1; a--)
08593               {
08594                      if (drawBleed)
08595                             Doc->getBleeds(a, &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
08596                      int x = static_cast<int>(Doc->Pages->at(a)->xOffset() - bleedLeft);
08597                      int y = static_cast<int>(Doc->Pages->at(a)->yOffset() - bleedTop);
08598                      int w = static_cast<int>(Doc->Pages->at(a)->width() + bleedLeft + bleedRight);
08599                      int h = static_cast<int>(Doc->Pages->at(a)->height() + bleedBottom + bleedTop);
08600                      if (QRect(x, y, w, h).contains(MxpS, MypS))
08601                      {
08602                             pgNum = static_cast<int>(a);
08603                             if (drawBleed)  // check again if its really on the correct page
08604                             {
08605                                    for (int a2 = docPageCount; a2 > -1; a2--)
08606                                    {
08607                                           int xn = static_cast<int>(Doc->Pages->at(a2)->xOffset());
08608                                           int yn = static_cast<int>(Doc->Pages->at(a2)->yOffset());
08609                                           int wn = static_cast<int>(Doc->Pages->at(a2)->width());
08610                                           int hn = static_cast<int>(Doc->Pages->at(a2)->height());
08611                                           if (QRect(xn, yn, wn, hn).contains(MxpS, MypS))
08612                                           {
08613                                                  pgNum = static_cast<int>(a2);
08614                                                  break;
08615                                           }
08616                                    }
08617                             }
08618                             break;
08619                      }
08620               }
08621               if (pgNum!=-1)
08622               {
08623                      uint docCurrPageNo=Doc->currentPageNumber();
08624                      uint j=static_cast<uint>(pgNum);
08625                      if (docCurrPageNo != j)
08626                      {
08627                             Doc->setCurrentPage(Doc->Pages->at(j));
08628                             setMenTxt(j);
08629                             DrawNew();
08630                      }
08631               }
08632               setRulerPos(contentsX(), contentsY());
08633        }
08634        if (m->state() == (ControlButton | AltButton))
08635               Deselect(false);
08636 
08637        if ((m->state() == (ShiftButton | AltButton)) && (!Doc->masterPageMode()) && (Doc->currentPage()->FromMaster.count() != 0))
08638        {
08639               Page* Mp = Doc->MasterPages.at(Doc->MasterNames[Doc->currentPage()->MPageNam]);
08640               currItem = Doc->currentPage()->FromMaster.last();
08641               for (a = 0; a < Doc->currentPage()->FromMaster.count(); ++a)
08642               {
08643                      if ((currItem->LayerNr == Doc->activeLayer()) && (!Doc->layerLocked(currItem->LayerNr)))
08644                      {
08645                             p.begin(this);
08646                             double OldX = currItem->xPos();
08647                             double OldY = currItem->yPos();
08648                             if (!currItem->ChangedMasterItem)
08649                             {
08650                                    currItem->moveBy(-Mp->xOffset() + Doc->currentPage()->xOffset(), -Mp->yOffset() + Doc->currentPage()->yOffset());
08651                             }
08652                             Transform(currItem, &p);
08653                             if ((QRegion(p.xForm(QPointArray(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo)) ||
08654                                           (QRegion(p.xForm(currItem->Clip)).contains(mpo)))
08655                             {
08656                                    if (!currItem->isSelected())
08657                                    {
08658                                           if ((m->state() != ShiftButton) || (Doc->appMode == modeLinkFrames) || (Doc->appMode == modeUnlinkFrames))
08659                                                  Deselect(false);
08660                                           if (currItem->Groups.count() != 0)
08661                                           {
08662                                                  if (Doc->m_Selection->count() != 0)
08663                                                  {
08664                                                         if (Doc->m_Selection->findItem(currItem) == -1)
08665                                                                Doc->m_Selection->addItem(currItem, true);
08666                                                  }
08667                                                  else
08668                                                         Doc->m_Selection->addItem(currItem, true);
08669                                                  if (m->state() != (ControlButton | AltButton))
08670                                                  {
08671                                                         for (uint ga=0; ga<Doc->Items->count(); ++ga)
08672                                                         {
08673                                                                if (Doc->Items->at(ga)->Groups.count() != 0)
08674                                                                {
08675                                                                       if (Doc->Items->at(ga)->Groups.top() == currItem->Groups.top())
08676                                                                       {
08677                                                                              if (Doc->Items->at(ga)->ItemNr != currItem->ItemNr)
08678                                                                              {
08679                                                                                     if (Doc->m_Selection->findItem(Doc->Items->at(ga)) == -1)
08680                                                                                     {
08681                                                                                            Doc->m_Selection->addItem(Doc->Items->at(ga), true);
08682                                                                                     }
08683 
08684                                                                              }
08685                                                                              Doc->Items->at(ga)->isSingleSel = false;
08686                                                                       }
08687                                                                }
08688                                                         }
08689                                                  }
08690                                                  else
08691                                                  {
08692                                                         currItem->isSingleSel = true;
08693                                                         currItem->paintObj();
08694                                                  }
08695                                           }
08696                                           else
08697                                           {
08698                                                  Doc->m_Selection->addItem(currItem, true);
08699                                                  currItem->paintObj();
08700                                           }
08701                                    }
08702                                    else
08703                                    {
08704                                           if (Doc->m_Selection->count() > 1)
08705                                           {
08706                                                  PageItem *bb = Doc->m_Selection->itemAt(0);
08707                                                  Doc->m_Selection->removeItem(currItem);
08708                                                  Doc->m_Selection->prependItem(currItem);
08709                                                  currItem->paintObj();
08710                                                  bb->paintObj();
08711                                           }
08712                                    }
08713                                    if (Doc->m_Selection->count() > 1)
08714                                    {
08715                                           for (uint aa = 0; aa < Doc->m_Selection->count(); ++aa)
08716                                           {
08717                                                  PageItem *bb = Doc->m_Selection->itemAt(aa);
08718                                                  bb->paintObj();
08719                                           }
08720                                           Doc->m_Selection->connectItemToGUI();
08721                                           Doc->m_Selection->setGroupRect();
08722                                           paintGroupRect();
08723                                           double x, y, w, h;
08724                                           Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
08725                                           emit ItemPos(x, y);
08726                                           emit ItemGeom(w, h);
08727                                           emit HaveSel(currItem->itemType());
08728                                    }
08729                                    else
08730                                    {
08731                                           currItem->emitAllToGUI();
08732                                    }
08733                                    p.end();
08734                                    if (!currItem->ChangedMasterItem)
08735                                    {
08736                                           currItem->setXYPos(OldX, OldY);
08737                                    }
08738                                    return true;
08739                             }
08740                             p.end();
08741                             if (!currItem->ChangedMasterItem)
08742                             {
08743                                    currItem->setXYPos(OldX, OldY);
08744                             }
08745                      }
08746                      currItem = Doc->currentPage()->FromMaster.prev();
08747               }
08748        }
08749        if ((m->state() == (ControlButton | ShiftButton)) && (Doc->m_Selection->count() != 0))
08750        {
08751               for (a = 0; a < Doc->Items->count(); ++a)
08752               {
08753                      if (currItem->isSelected())
08754                      {
08755                             if (currItem->ItemNr == 0)
08756                             {
08757                                    currItem = Doc->Items->last();
08758                                    break;
08759                             }
08760                             currItem = Doc->Items->prev();
08761                             break;
08762                      }
08763                      currItem = Doc->Items->prev();
08764               }
08765        }
08766        //Where all basic selection occurs having found the click location and the current page
08767        for (a = 0; a < Doc->Items->count(); ++a)
08768        {
08769               if (currItem == NULL)
08770               {
08771                      Deselect(true);
08772                      //Doc->m_Selection->clear();
08773                      return false;
08774               }
08775               if ((Doc->masterPageMode())  && (!((currItem->OwnPage == -1) || (currItem->OwnPage == static_cast<int>(Doc->currentPage()->pageNr())))))
08776               {
08777                      currItem = Doc->Items->prev();
08778                      continue;
08779               }
08780               if ((currItem->LayerNr == Doc->activeLayer()) && (!Doc->layerLocked(currItem->LayerNr)))
08781               {
08782                      p.begin(this);
08783                      Transform(currItem, &p);
08784                      if ((QRegion(p.xForm(QPointArray(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo)) ||
08785                              (QRegion(p.xForm(currItem->Clip)).contains(mpo)))
08786                      {
08787                             //If the clicked on item is not tagged as selected
08788                             if (!currItem->isSelected())
08789                             {
08790                                    if ((m->state() != ShiftButton) || (Doc->appMode == modeLinkFrames) || (Doc->appMode == modeUnlinkFrames))
08791                                           Deselect(false);
08792                                    //If we are selecting an item that is part of a group...
08793                                    if (currItem->Groups.count() != 0)
08794                                    {
08795                                           if (Doc->m_Selection->count() != 0)
08796                                           {
08797                                                  if (Doc->m_Selection->findItem(currItem) == -1)
08798                                                         Doc->m_Selection->addItem(currItem, true);
08799                                           }
08800                                           else
08801                                                  Doc->m_Selection->addItem(currItem, true);
08802                                           //CB This is where we add the items of an unselected group
08803                                           if (m->state() != (ControlButton | AltButton))
08804                                           {
08805                                                  for (uint ga=0; ga<Doc->Items->count(); ++ga)
08806                                                  {
08807                                                         if (Doc->Items->at(ga)->Groups.count() != 0)
08808                                                         {
08809                                                                if (Doc->Items->at(ga)->Groups.top() == currItem->Groups.top())
08810                                                                {
08811                                                                       if (Doc->Items->at(ga)->ItemNr != currItem->ItemNr)
08812                                                                       {
08813                                                                              if (Doc->m_Selection->findItem(Doc->Items->at(ga)) == -1)
08814                                                                                     Doc->m_Selection->addItem(Doc->Items->at(ga), true);
08815                                                                       }
08816                                                                       Doc->Items->at(ga)->isSingleSel = false;
08817                                                                }
08818                                                         }
08819                                                  }
08820                                           }
08821                                           else
08822                                           {
08823                                                  currItem->isSingleSel = true;
08824                                                  currItem->paintObj();
08825                                           }
08826                                    }
08827                                    else
08828                                    //If we are just selecting one item
08829                                    {
08830                                           //CB 301206 We shouldnt be ignoring the GUI here...
08831                                           //Doc->m_Selection->addItem(currItem, true);
08832                                           Doc->m_Selection->addItem(currItem);
08833                                           currItem->paintObj();
08834                                    }
08835                             }
08836                             else //If the clicked on item is tagged as selected
08837                             {
08838                                    if (Doc->m_Selection->count() > 1)
08839                                    {
08840                                           PageItem *bb = Doc->m_Selection->itemAt(0);
08841                                           Doc->m_Selection->removeItem(currItem);
08842                                           Doc->m_Selection->prependItem(currItem);
08843                                           currItem->paintObj();
08844                                           //CB dont think we need to paint here when we paint below
08845                                           //CB With the change of 301206, perhaps we need to?
08846                                           bb->paintObj();
08847                                    }
08848                             }
08849                             if (Doc->m_Selection->count() > 1)
08850                             {
08851                                    for (uint aa = 0; aa < Doc->m_Selection->count(); ++aa)
08852                                    {
08853                                           PageItem *bb = Doc->m_Selection->itemAt(aa);
08854                                           bb->paintObj();
08855                                    }
08856                                    Doc->m_Selection->connectItemToGUI();
08857                                    Doc->m_Selection->setGroupRect();
08858                                    paintGroupRect();
08859                                    double x, y, w, h;
08860                                    Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
08861                                    emit ItemPos(x, y);
08862                                    emit ItemGeom(w, h);
08863                                    emit HaveSel(currItem->itemType());
08864                             }
08865 //CB 301206 Unsure why we need this if the above is no longer ignoring the GUI
08866 //                          else
08867 //                          {
08868 //                                 Doc->m_Selection->connectItemToGUI();
08869 //                                 //CB Dont need this as creating the 0th selection does this
08870 //                                 currItem->paintObj();
08871 //                          }
08872                             if (Doc->m_Selection->count() == 1)
08873                             {
08874                                    HandleSizer(&p, currItem, mpo, m);
08875                                    if ((frameResizeHandle == 0) && (!currItem->locked()))
08876                                           qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
08877                             }
08878                             else
08879                             {
08880                                    qApp->setOverrideCursor(QCursor(SizeAllCursor), true);
08881                                    operItemResizing = false;
08882                             }
08883                             p.end();
08884                             return true;
08885                      }
08886                      p.end();
08887               }
08888               currItem = Doc->Items->prev();
08889        }
08890        if ((Doc->guidesSettings.guidesShown) && (Doc->appMode == modeNormal) && (!Doc->GuideLock) && (Doc->OnPage(MxpS, MypS) != -1) && (Doc->m_Selection->count() == 0))
08891        {
08892               GxM = -1;
08893               GyM = -1;
08894               QMap<double, uint> tmpGuidesSel;
08895               Guides tmpGuides = Doc->currentPage()->guides.horizontals(GuideManagerCore::Standard);
08896               Guides::iterator it;
08897               uint yg = 0;
08898               uint xg = 0;
08899               double lowX = ((m->x() - Doc->guidesSettings.grabRad) / Scale) + Doc->minCanvasCoordinate.x();
08900               double highX = ((m->x() + Doc->guidesSettings.grabRad) / Scale) + Doc->minCanvasCoordinate.x();
08901               double lowY = ((m->y() - Doc->guidesSettings.grabRad) / Scale) + Doc->minCanvasCoordinate.y();
08902               double highY = ((m->y() + Doc->guidesSettings.grabRad) / Scale) + Doc->minCanvasCoordinate.y();
08903               for (it = tmpGuides.begin(); it != tmpGuides.end(); ++it, ++yg)
08904               {
08905                      if (((*it) + Doc->currentPage()->yOffset() < highY) && ((*it)+Doc->currentPage()->yOffset() > lowY))
08906                             tmpGuidesSel.insert(fabs(((*it)+Doc->currentPage()->yOffset()) - MypS), yg);
08907               }
08908               if (tmpGuidesSel.count() != 0)
08909               {
08910                      GyM = tmpGuidesSel.begin().data();
08911                      QPoint py = viewport()->mapFromGlobal(m->globalPos());
08912                      DrHY = py.y();
08913               }
08914               tmpGuidesSel.clear();
08915               tmpGuides = Doc->currentPage()->guides.verticals(GuideManagerCore::Standard);
08916               for (it = tmpGuides.begin(); it != tmpGuides.end(); ++it, ++xg)
08917               {
08918                      if (((*it) + Doc->currentPage()->xOffset() < highX) && ((*it)+Doc->currentPage()->xOffset() > lowX))
08919                             tmpGuidesSel.insert(fabs(((*it)+Doc->currentPage()->xOffset()) - MypS), xg);
08920               }
08921               if (tmpGuidesSel.count() != 0)
08922               {
08923                      GxM = tmpGuidesSel.begin().data();
08924                      QPoint py = viewport()->mapFromGlobal(m->globalPos());
08925                      DrVX = py.x();
08926               }
08927               if (GxM!=-1 || GyM!=-1)
08928               {
08929                      if (GxM==-1)
08930                      {
08931                             // Horizontal Guide
08932                             MoveGY = true;
08933                             emit signalGuideInformation(0, qRound(Doc->currentPage()->guides.horizontal(GyM, GuideManagerCore::Standard) * 10000.0) / 10000.0);
08934                      }
08935                      else
08936                      {
08937                             // Vertical Guide
08938                             MoveGX = true;
08939                             emit signalGuideInformation(1, qRound(Doc->currentPage()->guides.vertical(GxM, GuideManagerCore::Standard) * 10000.0) / 10000.0);
08940                      }
08941               }
08942        }
08943        if ((m->state() != ShiftButton) || (Doc->appMode == modeLinkFrames) || (Doc->appMode == modeUnlinkFrames))
08944               Deselect(true);
08945        return false;
08946 }
08947 
08948 //CB Fix item->old* stuff
08949 void ScribusView::HandleSizer(QPainter *p, PageItem *currItem, QRect mpo, QMouseEvent *m)
08950 {
08951        currItem->OldB = currItem->width();
08952        currItem->OldH = currItem->height();
08953        currItem->OldB2 = currItem->width();
08954        currItem->OldH2 = currItem->height();
08955        frameResizeHandle = 0;
08956        if (currItem->sizeLocked())
08957               return;
08958        QRect ne = QRect();
08959        PaintSizeRect(p, ne);
08960        double d1;
08961        QMap<double,int> distance;
08962        FPoint n1(currItem->width(), currItem->height(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08963        n1 -= QPoint(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
08964        d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08965        if (d1 < Doc->guidesSettings.grabRad)
08966               distance.insert(d1, 1);
08967        n1 = FPoint(0, 0, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08968        n1 -= QPoint(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
08969        d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08970        if (d1 < Doc->guidesSettings.grabRad)
08971               distance.insert(d1, 2);
08972        if (!currItem->asLine())
08973        {
08974               QPoint docMinCanvasCoordinate(qRound(Doc->minCanvasCoordinate.x()), qRound(Doc->minCanvasCoordinate.y()));
08975               n1 = FPoint(currItem->width(), 0, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08976               n1 -= docMinCanvasCoordinate;
08977               d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08978               if (d1 < Doc->guidesSettings.grabRad)
08979                      distance.insert(d1, 3);
08980               n1 = FPoint(0, currItem->height(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08981               n1 -= docMinCanvasCoordinate;
08982               d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08983               if (d1 < Doc->guidesSettings.grabRad)
08984                      distance.insert(d1, 4);
08985               n1 = FPoint(currItem->width()/2, currItem->height(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08986               n1 -= docMinCanvasCoordinate;
08987               d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08988               if (d1 < Doc->guidesSettings.grabRad)
08989                      distance.insert(d1, 5);
08990               n1 = FPoint(currItem->width(), currItem->height()/2, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08991               n1 -= docMinCanvasCoordinate;
08992               d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08993               if (d1 < Doc->guidesSettings.grabRad)
08994                      distance.insert(d1, 6);
08995               n1 = FPoint(0, currItem->height()/2, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
08996               n1 -= docMinCanvasCoordinate;
08997               d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
08998               if (d1 < Doc->guidesSettings.grabRad)
08999                      distance.insert(d1, 7);
09000               n1 = FPoint(currItem->width()/2, 0, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1);
09001               n1 -= docMinCanvasCoordinate;
09002               d1 = sqrt(pow(n1.x() * Scale - m->x(),2)+pow(n1.y() * Scale - m->y(),2));
09003               if (d1 < Doc->guidesSettings.grabRad)
09004                      distance.insert(d1, 8);
09005        }
09006        QValueList<int> result = distance.values();
09007        if (result.count() != 0)
09008               frameResizeHandle = result[0];
09009        mpo.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(Doc->minCanvasCoordinate.y() * Scale));
09010        HandleCurs(p, currItem, mpo);
09011        if (frameResizeHandle != 0)
09012        {
09013               if (!currItem->asLine())
09014                      currItem->Sizing = true;
09015               operItemResizing = true;
09016        }
09017 }
09018 
09019 bool ScribusView::GetItem(PageItem **currItem, int nr)
09020 {
09021        int n=nr;
09022        if (n == -1)
09023               n=0;
09024        *(currItem) = Doc->m_Selection->itemAt(n);
09025        return (*(currItem)!=NULL);
09026 }
09027 
09028 //CB Remove bookmark interaction here, item/doc should do it
09029 void ScribusView::Deselect(bool prop)
09030 {
09031        if (!Doc->m_Selection->isEmpty())
09032        {
09033               PageItem* currItem=NULL;
09034               for (uint a = 0; a < Doc->m_Selection->count(); ++a)
09035               {
09036                      currItem = Doc->m_Selection->itemAt(a);
09037                      if ((currItem->asTextFrame()) && (currItem->isBookmark))
09038                             emit ChBMText(currItem);
09039               }
09040               if (Doc->m_Selection->isMultipleSelection())
09041               {
09042                      double x, y, w, h;
09043                      Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
09044                      Doc->m_Selection->clear();
09045                      x -= Doc->minCanvasCoordinate.x();
09046                      y -= Doc->minCanvasCoordinate.y();
09047                      updateContents(static_cast<int>(x*Scale-5), static_cast<int>(y*Scale-5), static_cast<int>(w*Scale+10), static_cast<int>(h*Scale+10));
09048               }
09049               else
09050               {
09051                      currItem=Doc->m_Selection->itemAt(0);
09052                      Doc->m_Selection->clear();
09053                      if (currItem!=NULL)
09054                             updateContents(currItem->getRedrawBounding(Scale));
09055               }
09056        }
09057        if (prop)
09058               emit HaveSel(-1);
09059 }
09060 
09061 void ScribusView::SetupDraw(int nr)
09062 {
09063        PageItem* currItem = Doc->Items->at(nr);
09064 //     currItem->setFont(Doc->toolSettings.defFont);
09065 //     currItem->setFontSize(Doc->toolSettings.defSize);
09066        operItemResizing = true;
09067        frameResizeHandle = 1;
09068        qApp->setOverrideCursor(QCursor(SizeFDiagCursor), true);
09069        Doc->m_Selection->clear();
09070        Doc->m_Selection->addItem(currItem);
09071        currItem->paintObj();
09072        operItemMoving = true;
09073        Doc->appMode = modeNormal;
09074        emit DocChanged();
09075        currItem->Sizing =  currItem->asLine() ? false : true;
09076        inItemCreation = true;
09077 //     moveTimer = moveTimer.addSecs(1500);
09078 }
09079 
09080 void ScribusView::SetupDrawNoResize(int nr)
09081 {
09082        PageItem* currItem = Doc->Items->at(nr);
09083 //     currItem->setFont(Doc->toolSettings.defFont);
09084 //     currItem->setFontSize(Doc->toolSettings.defSize);
09085        Doc->m_Selection->clear();
09086        Doc->m_Selection->addItem(currItem);
09087        currItem->paintObj();
09088        if (!Prefs->stickyTools)
09089               Doc->appMode = modeNormal;
09090        emit DocChanged();
09091        currItem->Sizing =  currItem->asLine() ? false : true;
09092        inItemCreation = false;
09093        moveTimer = moveTimer.addSecs(1500);
09094 }
09095 
09096 //CB-->Doc/Fix
09097 void ScribusView::ToggleBookmark()
09098 {
09099        uint docSelectionCount=Doc->m_Selection->count();
09100        if (docSelectionCount != 0)
09101        {
09102               for (uint a = 0; a < docSelectionCount; ++a)
09103               {
09104                      PageItem* currItem = Doc->m_Selection->itemAt(a);
09105                      if (currItem->asTextFrame())
09106                      {
09107                             if (currItem->OwnPage != -1)
09108                             {
09109                                    bool old = currItem->isBookmark;
09110                                    currItem->isBookmark = !currItem->isBookmark;
09111                                    if (currItem->isBookmark)
09112                                    {
09113                                           currItem->setIsAnnotation(false);
09114                                           emit AddBM(currItem);
09115                                    }
09116                                    else
09117                                    {
09118                                           if (old)
09119                                                  emit DelBM(currItem);
09120                                    }
09121                             }
09122                      }
09123               }
09124               m_ScMW->actionManager->setPDFActions(this);
09125               emit DocChanged();
09126        }
09127 }
09128 
09129 //CB-->Doc/Fix
09130 void ScribusView::ToggleAnnotation()
09131 {
09132        if (Doc->m_Selection->count() != 0)
09133        {
09134               for (uint a = 0; a < Doc->m_Selection->count(); ++a)
09135               {
09136                      PageItem* currItem = Doc->m_Selection->itemAt(a);
09137                      if (currItem->asTextFrame())
09138                      {
09139                             bool old = currItem->isBookmark;
09140                             currItem->setIsAnnotation(!currItem->isAnnotation());
09141                             if (currItem->isAnnotation())
09142                             {
09143                                    currItem->AutoName = false;
09144                                    if (old)
09145                                           emit DelBM(currItem);
09146                                    currItem->isBookmark = false;
09147                             }
09148                      }
09149               }
09150               m_ScMW->actionManager->setPDFActions(this);
09151               emit DocChanged();
09152        }
09153 }
09154 
09155 //CB-->Doc/Fix
09156 void ScribusView::ToBack()
09157 {
09158        if (Doc->sendItemSelectionToBack())
09159        {
09160 //            m_ScMW->outlinePalette->BuildTree();
09161               emit LevelChanged(0);
09162               emit DocChanged();
09163               updateContents();
09164        }
09165 }
09166 
09167 //CB-->Doc/Fix
09168 void ScribusView::ToFront()
09169 {
09170        if (Doc->bringItemSelectionToFront())
09171        {
09172 //            m_ScMW->outlinePalette->BuildTree();
09173               emit LevelChanged(Doc->m_Selection->itemAt(0)->ItemNr);
09174               emit DocChanged();
09175               updateContents();
09176        }
09177 }
09178 
09179 //CB-->Doc/Fix
09180 void ScribusView::LowerItem()
09181 {
09182        uint low = Doc->Items->count();
09183        uint high = 0;
09184        int d;
09185        QMap<int, uint> ObjOrder;
09186        PageItem *currItem;
09187        PageItem *b2;
09188        uint docSelectionCount=Doc->m_Selection->count();
09189        if ((Doc->Items->count() > 1) && (docSelectionCount != 0))
09190        {
09191               for (uint c = 0; c < docSelectionCount; ++c)
09192               {
09193                      currItem = Doc->m_Selection->itemAt(c);
09194                      if (currItem->isTableItem && currItem->isSingleSel)
09195                             return;
09196                      low = QMIN(currItem->ItemNr, low);
09197                      high = QMAX(currItem->ItemNr, high);
09198               }
09199               if (low == 0)
09200                      return;
09201               bool wasGUISelection=Doc->m_Selection->isGUISelection();
09202               if (wasGUISelection)
09203               {
09204                      Doc->m_Selection->setIsGUISelection(false);
09205                      Doc->m_Selection->disconnectAllItemsFromGUI();
09206               }
09207               Selection tempSelection(*Doc->m_Selection);
09208               b2 = Doc->Items->at(high);
09209               Doc->m_Selection->clear();
09210               SelectItemNr(low-1, false);
09211               for (uint c = 0; c < Doc->m_Selection->count(); ++c)
09212               {
09213                      currItem = Doc->m_Selection->itemAt(c);
09214                      ObjOrder.insert(currItem->ItemNr, c);
09215                      d = Doc->Items->findRef(currItem);
09216                      Doc->Items->take(d);
09217               }
09218               d = Doc->Items->findRef(b2);
09219               QValueList<uint> Oindex = ObjOrder.values();
09220               for (int c = static_cast<int>(Oindex.count()-1); c > -1; c--)
09221               {
09222                      Doc->Items->insert(d+1, Doc->m_Selection->itemAt(Oindex[c]));
09223               }
09224               Doc->m_Selection->clear();
09225               Doc->renumberItemsInListOrder();
09226 //            m_ScMW->outlinePalette->BuildTree();
09227               if (wasGUISelection)
09228                      tempSelection.setIsGUISelection(true);
09229               *Doc->m_Selection=tempSelection;
09230               emit LevelChanged(Doc->m_Selection->itemAt(0)->ItemNr);
09231               emit DocChanged();
09232               updateContents();
09233        }
09234 }
09235 
09236 //CB-->Doc/Fix
09237 void ScribusView::RaiseItem()
09238 {
09239        uint low = Doc->Items->count();
09240        uint high = 0;
09241        int d;
09242        QMap<int, uint> ObjOrder;
09243        PageItem *currItem;
09244        PageItem *b2;
09245        uint docSelectionCount=Doc->m_Selection->count();
09246        if ((Doc->Items->count() > 1) && (docSelectionCount != 0))
09247        {
09248               for (uint c = 0; c < docSelectionCount; ++c)
09249               {
09250                      currItem = Doc->m_Selection->itemAt(c);
09251                      if (currItem->isTableItem && currItem->isSingleSel)
09252                             return;
09253                      low = QMIN(currItem->ItemNr, low);
09254                      high = QMAX(currItem->ItemNr, high);
09255               }
09256               if (high == Doc->Items->count()-1)
09257                      return;
09258               bool wasGUISelection=Doc->m_Selection->isGUISelection();
09259               if (wasGUISelection)
09260               {
09261                      Doc->m_Selection->setIsGUISelection(false);
09262                      Doc->m_Selection->disconnectAllItemsFromGUI();
09263               }
09264               Selection tempSelection(*Doc->m_Selection);
09265               b2 = Doc->Items->at(low);
09266               Doc->m_Selection->clear();
09267               SelectItemNr(high+1, false);
09268               for (uint c = 0; c < Doc->m_Selection->count(); ++c)
09269               {
09270                      currItem = Doc->m_Selection->itemAt(c);
09271                      ObjOrder.insert(currItem->ItemNr, c);
09272                      d = Doc->Items->findRef(currItem);
09273                      Doc->Items->take(d);
09274               }
09275               QValueList<uint> Oindex = ObjOrder.values();
09276               for (int c = 0; c <static_cast<int>(Oindex.count()); ++c)
09277               {
09278                      d = Doc->Items->findRef(b2);
09279                      if (d==-1)
09280                             d=0;
09281                      Doc->Items->insert(d, Doc->m_Selection->itemAt(Oindex[c]));
09282               }
09283               Doc->m_Selection->clear();
09284               Doc->renumberItemsInListOrder();
09285 //            m_ScMW->outlinePalette->BuildTree();
09286               if (wasGUISelection)
09287                      tempSelection.setIsGUISelection(true);
09288               *Doc->m_Selection=tempSelection;
09289               emit LevelChanged(Doc->m_Selection->itemAt(0)->ItemNr);
09290               emit DocChanged();
09291               updateContents();
09292        }
09293 }
09294 
09295 //CB Remove emit/start pasting objects
09296 void ScribusView::PasteToPage()
09297 {
09298        uint ac = Doc->Items->count();
09299        if (UndoManager::undoEnabled())
09300               undoManager->beginTransaction(Doc->currentPage()->getUName(), 0, Um::Paste, "", Um::IPaste);
09301        if (m_ScMW->Buffer2.contains("<SCRIBUSFRAGMENT"))
09302        {
09303               bool savedAlignGrid = Doc->useRaster;
09304               bool savedAlignGuides = Doc->SnapGuides;
09305               Selection pastedObjects = Serializer(*Doc).deserializeObjects(m_ScMW->Buffer2.utf8());
09306               Doc->useRaster = savedAlignGrid;
09307               Doc->SnapGuides = savedAlignGuides;
09308               pastedObjects.setGroupRect();
09309               double gx, gy, gh, gw;
09310               pastedObjects.getGroupRect(&gx, &gy, &gw, &gh);
09311               moveGroup(Mxp / Scale - gx, Myp / Scale - gy, false, &pastedObjects);
09312               Doc->m_Selection->clear();
09313        }
09314        else
09315               emit LoadElem(m_ScMW->Buffer2, Mxp / Scale, Myp / Scale, false, false, Doc, this);
09316        Doc->DraggedElem = 0;
09317        Doc->DragElements.clear();
09318        updateContents();
09319        Selection newObjects(this, false);
09320        for (uint as = ac; as < Doc->Items->count(); ++as)
09321        {
09322               PageItem* currItem = Doc->Items->at(as);
09323               if (currItem->isBookmark)
09324                      emit AddBM(currItem);
09325               newObjects.addItem(currItem);
09326        }
09327        if (newObjects.count() > 1)
09328        {
09329               newObjects.setGroupRect();
09330               double gx, gy, gh, gw;
09331               newObjects.getGroupRect(&gx, &gy, &gw, &gh);
09332               double nx = gx;
09333               double ny = gy;
09334               if (!Doc->ApplyGuides(&nx, &ny))
09335               {
09336                      FPoint npx;
09337                      npx = Doc->ApplyGridF(FPoint(nx, ny));
09338                      nx = npx.x();
09339                      ny = npx.y();
09340               }
09341               moveGroup(nx-gx, ny-gy, false, &newObjects);
09342               newObjects.setGroupRect();
09343               newObjects.getGroupRect(&gx, &gy, &gw, &gh);
09344               nx = gx+gw;
09345               ny = gy+gh;
09346               Doc->ApplyGuides(&nx, &ny);
09347               moveGroup(nx-(gx+gw), ny-(gy+gh), false, &newObjects);
09348               newObjects.setGroupRect();
09349               newObjects.getGroupRect(&gx, &gy, &gw, &gh);
09350               emit ItemPos(gx, gy);
09351               emit ItemGeom(gw, gh);
09352               emit HaveSel(newObjects.itemAt(0)->itemType());
09353        }
09354        else
09355        {
09356               Q_ASSERT(newObjects.count()==1);
09357               PageItem *currItem = newObjects.itemAt(0);
09358               if (Doc->useRaster)
09359               {
09360                      double nx = currItem->xPos();
09361                      double ny = currItem->yPos();
09362                      if (!Doc->ApplyGuides(&nx, &ny))
09363                      {
09364                             FPoint npx;
09365                             npx = Doc->ApplyGridF(FPoint(nx, ny));
09366                             nx = npx.x();
09367                             ny = npx.y();
09368                      }
09369                      Doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem);
09370               }
09371               currItem->emitAllToGUI();
09372        }
09373        Doc->m_Selection->copy(newObjects,false,true);
09374        if (UndoManager::undoEnabled())
09375               undoManager->commit();
09376 }
09377 
09378 void ScribusView::PasteRecentToPage(int id)
09379 {
09380        if (UndoManager::undoEnabled())
09381               undoManager->beginTransaction(Doc->currentPage()->getUName(), 0, Um::Paste, "", Um::IPaste);
09382        QString nam = pmen3->text(id);
09383        QString data = m_ScMW->scrapbookPalette->tempBView->objectMap[nam].Data;
09384        QFileInfo fi(data);
09385        if (fi.extension(true).lower() == "sml")
09386        {
09387               QString f = "";
09388               loadText(data, &f);
09389               StencilReader *pre = new StencilReader();
09390               data = pre->createObjects(f);
09391               delete pre;
09392        }
09393        else if (fi.extension(true).lower() == "shape")
09394        {
09395               QString f = "";
09396               loadText(data, &f);
09397               StencilReader *pre = new StencilReader();
09398               data = pre->createShape(f);
09399               delete pre;
09400        }
09401        else if (fi.extension(true).lower() == "sce")
09402        {
09403               QString f = "";
09404               loadText(data, &f);
09405               data = f;
09406        }
09407        uint ac = Doc->Items->count();
09408        emit LoadElem(data, Mxp / Scale, Myp / Scale, false, false, Doc, this);
09409        Doc->DraggedElem = 0;
09410        Doc->DragElements.clear();
09411        updateContents();
09412        for (uint as = ac; as < Doc->Items->count(); ++as)
09413        {
09414               PageItem* currItem = Doc->Items->at(as);
09415               if (currItem->isBookmark)
09416                      emit AddBM(currItem);
09417               Doc->m_Selection->addItem(currItem);
09418        }
09419        if (Doc->m_Selection->count() > 1)
09420        {
09421               Doc->m_Selection->setGroupRect();
09422               double gx, gy, gh, gw;
09423               Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
09424               double nx = gx;
09425               double ny = gy;
09426               if (!Doc->ApplyGuides(&nx, &ny))
09427               {
09428                      FPoint npx;
09429                      npx = Doc->ApplyGridF(FPoint(nx, ny));
09430                      nx = npx.x();
09431                      ny = npx.y();
09432               }
09433               moveGroup(nx-gx, ny-gy, false);
09434               Doc->m_Selection->setGroupRect();
09435               Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
09436               nx = gx+gw;
09437               ny = gy+gh;
09438               Doc->ApplyGuides(&nx, &ny);
09439               moveGroup(nx-(gx+gw), ny-(gy+gh), false);
09440               Doc->m_Selection->setGroupRect();
09441               Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
09442               emit ItemPos(gx, gy);
09443               emit ItemGeom(gw, gh);
09444               emit HaveSel(Doc->m_Selection->itemAt(0)->itemType());
09445        }
09446        else
09447        {
09448               PageItem *currItem = Doc->m_Selection->itemAt(0);
09449               if (Doc->useRaster)
09450               {
09451                      double nx = currItem->xPos();
09452                      double ny = currItem->yPos();
09453                      if (!Doc->ApplyGuides(&nx, &ny))
09454                      {
09455                             FPoint npx;
09456                             npx = Doc->ApplyGridF(FPoint(nx, ny));
09457                             nx = npx.x();
09458                             ny = npx.y();
09459                      }
09460                      Doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem);
09461               }
09462               currItem->emitAllToGUI();
09463        }
09464        if (UndoManager::undoEnabled())
09465               undoManager->commit();
09466 }
09467 
09469 void ScribusView::setHBarGeometry(QScrollBar &bar, int x, int y, int w, int h)
09470 {
09471        bar.setGeometry(x, y, w, h);
09472        if (Ready)
09473               horizRuler->setGeometry(m_vhRulerHW, 1, w-m_vhRulerHW-1, m_vhRulerHW);
09474 }
09475 
09477 void ScribusView::setVBarGeometry(QScrollBar &bar, int x, int y, int w, int h)
09478 {
09479        bar.setGeometry(x, y, w, h);
09480        if (Ready)
09481        {
09482               vertRuler->setGeometry(1, m_vhRulerHW, m_vhRulerHW, h-m_vhRulerHW-1);
09483               rulerMover->setGeometry(1, 1, m_vhRulerHW, m_vhRulerHW);
09484        }
09485 }
09486 
09487 bool ScribusView::mousePressed()
09488 {
09489        return m_MouseButtonPressed;
09490 }
09491 
09492 bool ScribusView::groupTransactionStarted()
09493 {
09494        return _groupTransactionStarted;
09495 }
09496 
09497 void ScribusView::setGroupTransactionStarted(bool isOn)
09498 {
09499        _groupTransactionStarted = isOn;
09500 }
09501 
09502 // jjsa 27-03-2004 add for better setting while zooming
09503 //CB find a new name
09504 void ScribusView::rememberOldZoomLocation(int mx, int my)
09505 {
09506        oldX = mx;
09507        oldY = my;
09508 }
09509 
09510 void ScribusView::setRulerPos(int x, int y)
09511 {
09512        if (m_ScMW->ScriptRunning)
09513               return;
09514        if (Doc->guidesSettings.rulerMode)
09515        {
09516               horizRuler->offs = x / Scale - Doc->currentPage()->xOffset();
09517               vertRuler->offs = y / Scale - Doc->currentPage()->yOffset();
09518        }
09519        else
09520        {
09521               horizRuler->offs = x / Scale;
09522               vertRuler->offs = y / Scale;
09523        }
09524 //     horizRuler->offs += qRound(Doc->minCanvasCoordinate.x() - 1 - Doc->rulerXoffset);
09525 //     vertRuler->offs += qRound(Doc->minCanvasCoordinate.y() - 1 - Doc->rulerYoffset);
09526        horizRuler->offs += Doc->minCanvasCoordinate.x()  - Doc->rulerXoffset;
09527        vertRuler->offs += Doc->minCanvasCoordinate.y()  - Doc->rulerYoffset;
09528        horizRuler->repaint();
09529        vertRuler->repaint();
09530        evSpon = true;
09531        QString newStatusBarText(" ");
09532        if ((verticalScrollBar()->draggingSlider()) || (horizontalScrollBar()->draggingSlider()))
09533        {
09534               QValueList<int> pag;
09535               pag.clear();
09536               uint docPageCount=Doc->Pages->count();
09537               for (uint a = 0; a < docPageCount; ++a)
09538               {
09539                      int xs = static_cast<int>(Doc->Pages->at(a)->xOffset() * Scale);
09540                      int ys = static_cast<int>(Doc->Pages->at(a)->yOffset() * Scale);
09541                      int ws = static_cast<int>(Doc->Pages->at(a)->width() * Scale);
09542                      int hs = static_cast<int>(Doc->Pages->at(a)->height() * Scale);
09543                      QRect drawRect = QRect(x, y, visibleWidth(), visibleHeight());
09544                      drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale));
09545                      if (drawRect.intersects(QRect(xs, ys, ws, hs)))
09546                             pag.append(a+1);
09547               }
09548               if (!pag.isEmpty())
09549                      newStatusBarText=( tr("Page %1 to %2").arg(pag.first()).arg(pag.last()));
09550        }
09551        m_ScMW->setStatusBarInfoText(newStatusBarText);
09552 }
09553 
09554 
09555 //CB This MUST now be called AFTER a call to doc->addPage or doc->addMasterPage as it
09556 //does NOT create a page anymore.
09557 Page* ScribusView::addPage(int nr, bool mov)
09558 {
09559        Page* fe=Doc->Pages->at(nr);
09560        Q_ASSERT(fe!=0);
09561        if (fe==0)
09562               return 0;
09563        //Note this picks up the new page or master page depending on the mode.
09564        reformPages(mov);
09565        setMenTxt(nr);
09566        m_MouseButtonPressed = false;
09567        Doc->DragP = false;
09568        Doc->leaveDrag = false;
09569        operItemMoving = false;
09570        MidButt = false;
09571        HaveSelRect = false;
09572        Magnify = false;
09573        FirstPoly = true;
09574        EdPoints = true;
09575        //GroupSel = false;
09576        DraggedGroup = false;
09577        MoveGY = false;
09578        MoveGX = false;
09579        EditContour = false;
09580        return fe;
09581 }
09582 
09583 void ScribusView::reformPages(bool moveObjects)
09584 {
09585        Doc->reformPages(moveObjects);
09586        if (!m_ScMW->ScriptRunning)
09587               setContentsPos(qRound((Doc->currentPage()->xOffset()-10 - Doc->minCanvasCoordinate.x()) * Scale), qRound((Doc->currentPage()->yOffset()-10 - Doc->minCanvasCoordinate.y()) * Scale));
09588        if (!Doc->isLoading())
09589        {
09590               setRulerPos(contentsX(), contentsY());
09591               setMenTxt(Doc->currentPage()->pageNr());
09592        }
09593 }
09594 
09595 void ScribusView::updatesOn(bool on)
09596 {
09597        updateOn = on;
09598        setUpdatesEnabled(on);
09599        viewport()->setUpdatesEnabled(on);
09600 }
09601 
09602 void ScribusView::adjustCanvas(double width, double height, double dX, double dY)
09603 {
09604        if (!operItemMoving)
09605        {
09606               bool updback = updateOn;
09607               updatesOn(false);
09608               disconnect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(setRulerPos(int, int)));
09609               int oldDX = contentsX();
09610               int oldDY = contentsY();
09611               int nw = QMAX(qRound(width * Scale), contentsWidth() + qRound(dX * Scale) * 2);
09612               int nh = QMAX(qRound(height * Scale), contentsHeight() + qRound(dY * Scale) * 2);
09613               resizeContents(QMAX(nw, visibleWidth() + qRound(dX * Scale) * 2), QMAX(nh, visibleHeight() + qRound(dY * Scale) * 2));
09614               setContentsPos(oldDX + qRound(dX * Scale), oldDY + qRound(dY * Scale));
09615               setRulerPos(contentsX(), contentsY());
09616               connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(setRulerPos(int, int)));
09617               updatesOn(updback);
09618        }
09619        evSpon = false;
09620 }
09621 
09622 void ScribusView::setMenTxt(int Seite)
09623 {
09624        if (m_ScMW->ScriptRunning)
09625               return;
09626        disconnect(pageSelector, SIGNAL(GotoPage(int)), this, SLOT(GotoPa(int)));
09627        pageSelector->setMaxValue(Doc->masterPageMode() ? 1 : Doc->Pages->count());
09628        if ((!Doc->isLoading()) && (!Doc->masterPageMode()))
09629               pageSelector->GotoPg(Seite);
09630        connect(pageSelector, SIGNAL(GotoPage(int)), this, SLOT(GotoPa(int)));
09631 }
09632 
09634 void ScribusView::slotDoZoom()
09635 {
09636        undoManager->setUndoEnabled(false);
09637        if (Scale > 32*Prefs->DisScale)
09638        {
09639               setScale(32*Prefs->DisScale);
09640               return;
09641        }
09642        updatesOn(false);
09643        int nw = QMAX(qRound((Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()) * Scale), visibleWidth());
09644        int nh = QMAX(qRound((Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()) * Scale), visibleHeight());
09645        resizeContents(nw, nh);
09646        if (Doc->m_Selection->count() != 0)
09647        {
09648               PageItem *currItem = Doc->m_Selection->itemAt(0);
09649               SetCCPo(currItem->xPos() + currItem->width() / 2.0, currItem->yPos() + currItem->height() / 2.0);
09650        }
09651        else
09652               SetCCPo(oldX, oldY);
09653        updatesOn(true);
09654        DrawNew();
09655        undoManager->setUndoEnabled(true);
09656 }
09657 
09658 void ScribusView::setZoom()
09659 {
09660        int x = qRound(QMAX(contentsX() / Scale, 0));
09661        int y = qRound(QMAX(contentsY() / Scale, 0));
09662        int w = qRound(QMIN(visibleWidth() / Scale, Doc->currentPage()->width()));
09663        int h = qRound(QMIN(visibleHeight() / Scale, Doc->currentPage()->height()));
09664        rememberOldZoomLocation(w / 2 + x,h / 2 + y);
09665        setScale(zoomSpinBox->value() / 100.0 * Prefs->DisScale);
09666        slotDoZoom();
09667        m_ScMW->setFocus();
09668 }
09669 
09670 void ScribusView::slotZoom100()
09671 {
09672        int x = qRound(QMAX(contentsX() / Scale, Doc->minCanvasCoordinate.x()));
09673        int y = qRound(QMAX(contentsY() / Scale, Doc->minCanvasCoordinate.y()));
09674        int w = qRound(QMIN(visibleWidth() / Scale, Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()));
09675        int h = qRound(QMIN(visibleHeight() / Scale, Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()));
09676        rememberOldZoomLocation(w / 2 + x,h / 2 + y);
09677        setScale(Prefs->DisScale);
09678 //     reformPages(false);
09679        slotDoZoom();
09680 }
09681 
09682 void ScribusView::slotZoomIn(int mx,int my)
09683 {
09684        if ((mx == 0) && (my == 0))
09685        {
09686               int x = qRound(QMAX(contentsX() / Scale, Doc->minCanvasCoordinate.x()));
09687               int y = qRound(QMAX(contentsY() / Scale, Doc->minCanvasCoordinate.y()));
09688               int w = qRound(QMIN(visibleWidth() / Scale, Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()));
09689               int h = qRound(QMIN(visibleHeight() / Scale, Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()));
09690               rememberOldZoomLocation(w/2+x, h/2+y);
09691        }
09692        else
09693               rememberOldZoomLocation(mx,my);
09694        setScale(Scale * static_cast<double>(Doc->toolSettings.magStep)/100.0);
09695        slotDoZoom();
09696 }
09697 
09699 void ScribusView::slotZoomOut(int mx,int my)
09700 {
09701        if ((mx == 0) && (my == 0))
09702        {
09703               int x = qRound(QMAX(contentsX() / Scale, Doc->minCanvasCoordinate.x()));
09704               int y = qRound(QMAX(contentsY() / Scale, Doc->minCanvasCoordinate.y()));
09705               int w = qRound(QMIN(visibleWidth() / Scale, Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()));
09706               int h = qRound(QMIN(visibleHeight() / Scale, Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()));
09707               rememberOldZoomLocation(w/2+x, h/2+y);
09708        }
09709        else
09710               rememberOldZoomLocation(mx,my);
09711        setScale(Scale / (static_cast<double>(Doc->toolSettings.magStep)/100.0));
09712        slotDoZoom();
09713 }
09714 
09715 FPoint ScribusView::translateToView(double x, double y)
09716 {
09717        return FPoint((x - Doc->minCanvasCoordinate.x()) * Scale, (y - Doc->minCanvasCoordinate.y())* Scale);
09718 }
09719 
09720 FPoint ScribusView::translateToView(FPoint in)
09721 {
09722        return translateToView(in.x(), in.y());
09723 }
09724 
09725 FPoint ScribusView::translateToDoc(double x, double y)
09726 {
09727        return FPoint(x / Scale + Doc->minCanvasCoordinate.x(), y / Scale + Doc->minCanvasCoordinate.y());
09728 }
09729 
09730 FPoint ScribusView::translateToDoc(FPoint in)
09731 {
09732        return translateToDoc(in.x(), in.y());
09733 }
09734 
09735 FPoint ScribusView::translateFromViewport(double x, double y)
09736 {
09737        return FPoint((x + contentsX()) / Scale + Doc->minCanvasCoordinate.x(), (y + contentsY()) / Scale + Doc->minCanvasCoordinate.y());
09738 }
09739 
09740 FPoint ScribusView::translateFromViewport(FPoint in)
09741 {
09742        return translateFromViewport(in.x(), in.y(