Rev 9646 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
scribusview.cpp - description
-------------------
begin : Fre Apr 6 21:47:55 CEST 2001
copyright : (C) 2001 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "scribusview.h"
//#include "scribusview.moc"
#include "scconfig.h"
#include <qcolor.h>
#include <qfont.h>
#include <qfontmetrics.h>
#include <qpixmap.h>
#include <q3pointarray.h>
#include <qstringlist.h>
#include <q3dragobject.h>
#include <qimage.h>
#include <q3cstring.h>
#include <qfileinfo.h>
#include <qfile.h>
#include <q3ptrstack.h>
//Added by qt3to4:
#include <QWheelEvent>
#include <Q3PtrList>
#include <QPaintEvent>
#include <QDragMoveEvent>
#include <QDragLeaveEvent>
#include <Q3StrList>
#include <QLabel>
#include <QDropEvent>
#include <Q3PopupMenu>
#include <QMenu>
#include <QDragEnterEvent>
#include <Q3ValueList>
#include <QMouseEvent>
#include <Q3GridLayout>
#include <QImageReader>
#include <QWidgetAction>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <q3url.h>
#include <qdir.h>
#include <qevent.h>
#include <qsizegrip.h>
#if QT_VERSION > 0x030102
#define SPLITVC Qt::SplitHCursor
#define SPLITHC Qt::SplitVCursor
#else
#define SPLITVC Qt::SplitVCursor
#define SPLITHC Qt::SplitHCursor
#endif
#include "scribus.h"
//#include "tree.h"
#include "mpalette.h"
#include "scribusXml.h"
#include "selection.h"
#include "serializer.h"
#include "insertTable.h"
#include "hruler.h"
#include "vruler.h"
#include "filewatcher.h"
#include "undomanager.h"
#include "units.h"
#include "extimageprops.h"
#include "page.h"
#include "pageitemattributes.h"
#include "pageitem_imageframe.h"
#include "pageitem_line.h"
#include "pageitem_pathtext.h"
#include "pageitem_polygon.h"
#include "pageitem_polyline.h"
#include "pageitem_textframe.h"
#include "pageselector.h"
#include "scpaths.h"
#include "actionmanager.h"
#include <tiffio.h>
#include CMS_INC
#include "scmessagebox.h"
#include "util.h"
#include "story.h"
#include "prefsmanager.h"
#include "prefscontext.h"
#include "prefsfile.h"
#include "rulermover.h"
#include "hyphenator.h"
#include "commonstrings.h"
#include "guidemanager.h"
#include "oneclick.h"
#include "text/nlsconfig.h"
#include "scrap.h"
#include "stencilreader.h"
using namespace std;
ScribusView::ScribusView(QWidget* win, ScribusMainWindow* mw, ScribusDoc *doc) :
Q3ScrollView(win, "s", Qt::WNoAutoErase | Qt::WStaticContents),
Doc(doc),
Prefs(&(PrefsManager::instance()->appPrefs)),
undoManager(UndoManager::instance()),
OldScale(0),
dragX(0), dragY(0), dragW(0), dragH(0),
oldW(-1), oldCp(-1),
Mxp(-1), Myp(-1), Dxp(-1), Dyp(-1),
frameResizeHandle(-1),
SeRx(-1), SeRy(-1), GyM(-1), GxM(-1),
ClRe(-1), ClRe2(-1),
SegP1(-1), SegP2(-1),
RotMode(0),
DrHY(-1), DrVX(-1),
EdPoints(true),
m_MouseButtonPressed(false),
operItemMoving(false),
MoveGY(false), MoveGX(false),
HaveSelRect(false),
operItemResizing(false),
EditContour(false),
//GroupSel(false),
DraggedGroup(false),
DraggedGroupFirst(false),
operItemResizeInEditMode(false),
MidButt(false),
updateOn(true),
FirstPoly(true),
Magnify(false),
MoveSym(false),
previewMode(false),
RCenter(-1,-1),
RecordP(),
Ready(false),
oldX(0), oldY(0),
_groupTransactionStarted(false),
_isGlobalMode(true),
evSpon(false),
forceRedraw(false),
Scale(Prefs->DisScale),
oldClip(0),
m_vhRulerHW(17),
m_cursorVisible(false),
m_ScMW(mw)
{
setHScrollBarMode(Q3ScrollView::AlwaysOn);
setVScrollBarMode(Q3ScrollView::AlwaysOn);
setMargins(m_vhRulerHW, m_vhRulerHW, 0, 0);
setResizePolicy(Manual);
viewport()->setBackgroundMode(Qt::PaletteBackground);
QFont fo = QFont(font());
int posi = fo.pointSize()-2;
fo.setPointSize(posi);
unitSwitcher = new QComboBox( false, this, "unitSwitcher" );
unitSwitcher->setFocusPolicy(Qt::NoFocus);
unitSwitcher->setFont(fo);
int maxUindex = unitGetMaxIndex() - 2;
for (int i = 0; i <= maxUindex; ++i)
unitSwitcher->insertItem(unitGetStrFromIndex(i));
zoomSpinBox = new ScrSpinBox( 10, 3200, this, 6 );
zoomSpinBox->setTabAdvance(false);
zoomSpinBox->setFont(fo);
zoomSpinBox->setValue( 100 );
zoomSpinBox->setLineStepM(10);
zoomSpinBox->setFocusPolicy(Qt::ClickFocus);
zoomSpinBox->setSuffix( tr( " %" ) );
#if OPTION_USE_QTOOLBUTTON
zoomOutToolbarButton = new QToolButton(this);
zoomDefaultToolbarButton = new QToolButton(this);
zoomInToolbarButton = new QToolButton(this);
cmsToolbarButton = new QToolButton(this);
previewToolbarButton = new QToolButton(this);
zoomDefaultToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
zoomOutToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
zoomInToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
cmsToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
cmsToolbarButton->setToggleButton(true);
QIcon ic2;
ic2.addPixmap(loadIcon("cmsOff.png"), QIcon::Normal, QIcon::Off);
ic2.addPixmap(loadIcon("cmsOn.png"), QIcon::Normal, QIcon::On);
cmsToolbarButton->setIcon(ic2);
previewToolbarButton->setAutoRaise(OPTION_FLAT_BUTTON);
previewToolbarButton->setToggleButton(true);
QIcon ic;
ic.addPixmap(loadIcon("previewOff.png"), QIcon::Normal, QIcon::Off);
ic.addPixmap(loadIcon("previewOn.png"), QIcon::Normal, QIcon::On);
previewToolbarButton->setIcon(ic);
#else
zoomDefaultToolbarButton = new QPushButton(this);
zoomDefaultToolbarButton->setFocusPolicy(Qt::NoFocus);
zoomDefaultToolbarButton->setDefault( false );
zoomDefaultToolbarButton->setAutoDefault( false );
zoomDefaultToolbarButton->setFlat(OPTION_FLAT_BUTTON);
zoomOutToolbarButton = new QPushButton(this);
zoomOutToolbarButton->setFocusPolicy(Qt::NoFocus);
zoomOutToolbarButton->setDefault( false );
zoomOutToolbarButton->setAutoDefault( false );
zoomOutToolbarButton->setFlat(OPTION_FLAT_BUTTON);
zoomInToolbarButton = new QPushButton(this);
zoomInToolbarButton->setFocusPolicy(Qt::NoFocus);
zoomInToolbarButton->setDefault( false );
zoomInToolbarButton->setAutoDefault( false );
zoomInToolbarButton->setFlat(OPTION_FLAT_BUTTON);
previewToolbarButton = new QPushButton(this);
cmsToolbarButton->setFocusPolicy(Qt::NoFocus);
cmsToolbarButton->setDefault( false );
cmsToolbarButton->setAutoDefault( false );
cmsToolbarButton->setFlat(OPTION_FLAT_BUTTON);
cmsToolbarButton->setPixmap(loadIcon("cmsOn.png"));
previewToolbarButton = new QPushButton(this);
previewToolbarButton->setFocusPolicy(Qt::NoFocus);
previewToolbarButton->setDefault( false );
previewToolbarButton->setAutoDefault( false );
previewToolbarButton->setFlat(OPTION_FLAT_BUTTON);
previewToolbarButton->setPixmap(loadIcon("previewOn.png"));
#endif
//zoomDefaultToolbarButton->setText("1:1");
zoomDefaultToolbarButton->setPixmap(loadIcon("16/zoom-original.png"));
zoomOutToolbarButton->setPixmap(loadIcon("16/zoom-out.png"));
zoomInToolbarButton->setPixmap(loadIcon("16/zoom-in.png"));
pageSelector = new PageSelector(this, Doc->Pages->count());
pageSelector->setFont(fo);
pageSelector->setFocusPolicy(Qt::ClickFocus);
layerMenu = new QComboBox( true, this, "LY" );
layerMenu->setEditable(false);
layerMenu->setFont(fo);
layerMenu->setFocusPolicy(Qt::NoFocus);
visualMenu = new QComboBox( false, this, "visualMenu" );
visualMenu->setFocusPolicy(Qt::NoFocus);
visualMenu->setFont(fo);
visualMenu->setEnabled(false);
horizRuler = new Hruler(this, Doc);
vertRuler = new Vruler(this, Doc);
rulerMover = new RulerMover(this);
rulerMover->setFocusPolicy(Qt::NoFocus);
Ready = true;
viewport()->setMouseTracking(true);
setAcceptDrops(true);
viewport()->setAcceptDrops(true);
setDragAutoScroll(false);
Doc->DragP = false;
Doc->leaveDrag = false;
Doc->SubMode = -1;
storedFramesShown = Doc->guidesSettings.framesShown;
storedShowControls = Doc->guidesSettings.showControls;
viewAsPreview = false;
previewVisual = 0;
shiftSelItems = false;
inItemCreation = false;
redrawMode = 0;
redrawCount = 0;
redrawMarker = new QRubberBand(QRubberBand::Rectangle);
redrawMarker->hide();
redrawPolygon.clear();
specialRendering = false;
firstSpecial = false;
m_buffer = QPixmap();
m_ScMW->scrActions["viewFitPreview"]->setOn(viewAsPreview);
m_SnapCounter = 0;
connect(zoomOutToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
connect(zoomInToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
connect(zoomDefaultToolbarButton, SIGNAL(clicked()), this, SLOT(slotZoom100()));
connect(zoomSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setZoom()));
connect(pageSelector, SIGNAL(GotoPage(int)), this, SLOT(GotoPa(int)));
connect(layerMenu, SIGNAL(activated(int)), this, SLOT(GotoLa(int)));
connect(unitSwitcher, SIGNAL(activated(int)), this, SLOT(ChgUnit(int)));
connect(previewToolbarButton, SIGNAL(clicked()), this, SLOT(togglePreview()));
connect(cmsToolbarButton, SIGNAL(clicked()), this, SLOT(toggleCMS()));
connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int)));
connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(setRulerPos(int, int)));
connect(this, SIGNAL(HaveSel(int)), this, SLOT(selectionChanged()));
languageChange();
dragTimer = new QTimer(this);
connect(dragTimer, SIGNAL(timeout()), this, SLOT(dragTimerTimeOut()));
dragTimer->stop();
dragTimerFired = false;
}
void ScribusView::languageChange()
{
QToolTip::remove(cmsToolbarButton);
QToolTip::remove(previewToolbarButton);
QToolTip::remove(visualMenu);
QToolTip::add(cmsToolbarButton, tr("Switches Color Management on or off"));
QToolTip::add(previewToolbarButton, tr("Enables the Preview Mode"));
QToolTip::add(visualMenu, tr("Here you can select the visual appearance of the display\nYou can choose between normal and several color blindness forms"));
disconnect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int)));
visualMenu->clear();
visualMenu->insertItem(CommonStrings::trVisionNormal);
visualMenu->insertItem(CommonStrings::trVisionProtanopia);
visualMenu->insertItem(CommonStrings::trVisionDeuteranopia);
visualMenu->insertItem(CommonStrings::trVisionTritanopia);
visualMenu->insertItem(CommonStrings::trVisionFullColorBlind);
visualMenu->setCurrentItem(previewVisual);
connect(visualMenu, SIGNAL(activated(int)), this, SLOT(switchPreviewVisual(int)));
}
void ScribusView::toggleCMS()
{
Doc->enableCMS(!Doc->HasCMS);
updateContents();
}
void ScribusView::switchPreviewVisual(int vis)
{
previewVisual = vis;
Doc->recalculateColors();
Doc->recalcPicturesRes();
updateContents();
}
void ScribusView::togglePreview()
{
viewAsPreview = !viewAsPreview;
if (viewAsPreview)
{
storedFramesShown = Doc->guidesSettings.framesShown;
Doc->guidesSettings.framesShown = false;
storedShowControls = Doc->guidesSettings.showControls;
Doc->guidesSettings.showControls = false;
// warning popping up in case colour management and out-of-gamut-display are active
// as from #4346: Add a preview for daltonian - PV
if (Doc->HasCMS && Doc->Gamut)
QMessageBox::information(m_ScMW, tr("Preview Mode"),
"<qt>" + tr("CMS is active. Therefore the color display may not match the perception by visually impaired") + "</qt>",
QMessageBox::Ok);
}
else
{
Doc->guidesSettings.framesShown = storedFramesShown;
Doc->guidesSettings.showControls = storedShowControls;
}
m_ScMW->scrActions["viewFitPreview"]->setOn(viewAsPreview);
m_ScMW->scrActions["viewShowMargins"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowFrames"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowLayerMarkers"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowGrid"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowGuides"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowColumnBorders"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowBaseline"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowTextChain"]->setEnabled(!viewAsPreview);
m_ScMW->scrActions["viewShowTextControls"]->setEnabled(!viewAsPreview);
#if OPTION_USE_QTOOLBUTTON
previewToolbarButton->setOn(viewAsPreview);
#endif
visualMenu->setEnabled(viewAsPreview);
Doc->recalculateColors();
Doc->recalcPicturesRes();
updateContents();
}
void ScribusView::viewportPaintEvent ( QPaintEvent * p )
{
#ifndef _WIN32
if (p->spontaneous())
evSpon = true;
#endif
Q3ScrollView::viewportPaintEvent(p);
}
void ScribusView::drawContents(QPainter *psx, int clipx, int clipy, int clipw, int cliph)
{
if (Doc->isLoading())
return;
if (!updateOn)
return;
// QTime tim;
// tim.start();
if ((clipw > 0) && (cliph > 0))
{
if ((specialRendering) || (Doc->EditClip && specialRendering))
{
if (firstSpecial)
{
m_buffer = QPixmap::grabWindow(viewport()->winId(), 0, 0);
firstSpecial = false;
}
QPainter pp;
QPixmap ppx = m_buffer;
pp.begin(&ppx);
pp.setRenderHint(QPainter::Antialiasing, true);
if (redrawMode == 1)
{
pp.resetMatrix();
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(Qt::black, 1.0, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
QPoint nXY = redrawPolygon.point(0);
pp.drawLine(0, nXY.y(), viewport()->width(), nXY.y());
pp.drawLine(nXY.x(), 0, nXY.x(), viewport()->height());
redrawPolygon.clear();
}
if ((Doc->appMode == modeDrawBezierLine) && (!redrawPolygon.isEmpty()) && (Doc->m_Selection->count() != 0))
{
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(Qt::black, 1.0 / Scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
PageItem *currItem = Doc->m_Selection->itemAt(0);
Transform(currItem, &pp);
Q3PointArray Bez(4);
if (currItem->PoLine.size() > 1)
{
QPoint nXY = redrawPolygon.point(0);
if (!m_MouseButtonPressed)
{
QPoint a1 = currItem->PoLine.pointQ(currItem->PoLine.size()-2);
QPoint a2 = currItem->PoLine.pointQ(currItem->PoLine.size()-1);
BezierPoints(&Bez, a1, a2, nXY, nXY);
pp.drawCubicBezier(Bez);
}
else
{
QPoint a2 = currItem->PoLine.pointQ(currItem->PoLine.size()-1);
if (currItem->PoLine.size() > 2)
{
QPoint a1 = currItem->PoLine.pointQ(currItem->PoLine.size()-2);
QPoint a3 = currItem->PoLine.pointQ(currItem->PoLine.size()-3);
BezierPoints(&Bez, a3, a1, nXY, a2);
pp.drawCubicBezier(Bez);
}
pp.drawLine(a2, nXY);
}
}
else
{
QPoint a2 = currItem->PoLine.pointQ(currItem->PoLine.size()-1);
QPoint nXY = redrawPolygon.point(0);
pp.drawLine(a2, nXY);
}
redrawPolygon.clear();
}
if (m_MouseButtonPressed && (Doc->appMode == modeMeasurementTool))
{
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(Qt::black, 1.0, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
pp.drawPolyline(redrawPolygon);
redrawPolygon.clear();
}
if (m_MouseButtonPressed && (Doc->appMode == modeDrawLine))
{
QPoint out = contentsToViewport(QPoint(0, 0));
pp.resetMatrix();
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
pp.scale(Scale, Scale);
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(Qt::black, 1.0 / Scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
pp.drawPolyline(redrawPolygon);
redrawPolygon.clear();
}
if (operItemMoving || operItemResizing)
{
if (operItemResizing)
{
if (!redrawPolygon.isEmpty())
{
if (m_MouseButtonPressed && (Doc->appMode == modeDrawFreehandLine))
{
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
pp.scale(Scale, Scale);
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(Qt::black, 1.0 / Scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
pp.drawPolyline(redrawPolygon);
redrawPolygon.clear();
}
else
{
QColor drawColor = qApp->palette().color(QPalette::Active, QColorGroup::Highlight);
pp.setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
drawColor.setAlpha(64);
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
// pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
pp.setBrush(drawColor);
pp.drawPolygon(redrawPolygon);
redrawPolygon.clear();
}
}
}
else
{
if (Doc->m_Selection->count() != 0)
{
uint selectedItemCount = Doc->m_Selection->count();
PageItem *currItem = Doc->m_Selection->itemAt(0);
if (selectedItemCount < moveWithBoxesOnlyThreshold)
{
for (uint cu = 0; cu < selectedItemCount; cu++)
{
currItem = Doc->m_Selection->itemAt(cu);
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
Transform(currItem, &pp);
pp.setBrush(Qt::NoBrush);
pp.setPen(QPen(Qt::black, 1.0 / Scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
if (selectedItemCount < moveWithFullOutlinesThreshold)
{
if (!(currItem->asLine()))
currItem->DrawPolyL(&pp, currItem->Clip);
else
{
if (currItem->asLine())
{
int lw2 = 1;
int lw = 1;
Qt::PenCapStyle le = Qt::FlatCap;
if (currItem->NamedLStyle.isEmpty())
{
lw2 = qRound(currItem->lineWidth() / 2.0);
lw = qRound(qMax(currItem->lineWidth(), 1.0));
le = currItem->PLineEnd;
}
else
{
multiLine ml = Doc->MLineStyles[currItem->NamedLStyle];
lw2 = qRound(ml[ml.size()-1].Width / 2.0);
lw = qRound(qMax(ml[ml.size()-1].Width, 1.0));
le = static_cast<Qt::PenCapStyle>(ml[ml.size()-1].LineEnd);
}
if (le != Qt::FlatCap)
pp.drawRect(-lw2, -lw2, qRound(currItem->width())+lw, lw);
else
pp.drawRect(-1, -lw2, qRound(currItem->width()), lw);
}
}
}
else
pp.drawRect(0, 0, static_cast<int>(currItem->width())+1, static_cast<int>(currItem->height())+1);
}
}
else
{
double gx, gy, gw, gh;
Doc->m_Selection->setGroupRect();
Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
QPoint out = contentsToViewport(QPoint(0, 0));
pp.resetMatrix();
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
pp.scale(Scale, Scale);
pp.translate(qRound(gx), qRound(gy));
pp.drawRect(QRect(0, 0, qRound(gw), qRound(gh)));
}
}
}
}
else
{
if ((Doc->m_Selection->count() != 0) && (Doc->appMode != modeDrawBezierLine))
{
PageItem *currItem = Doc->m_Selection->itemAt(0);
if ((Doc->EditClip) && (currItem->isSelected()))
{
if (EditContour)
MarkClip(&pp, currItem, currItem->ContourLine, true);
else
MarkClip(&pp, currItem, currItem->PoLine, true);
}
else
{
if (Doc->m_Selection->isMultipleSelection())
{
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
double x, y, w, h;
Doc->m_Selection->setGroupRect();
Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
x *= Scale;
y *= Scale;
w *= Scale;
h *= Scale;
pp.setPen(QPen(Qt::red, 1, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
pp.setBrush(Qt::NoBrush);
pp.drawRect(QRectF(x, y, w, h));
pp.setBrush(Qt::red);
pp.setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
pp.drawRect(QRectF(x+w-6, y+h-6, 6, 6));
pp.drawRect(QRectF(x+w/2 - 3, y+h-6, 6, 6));
pp.drawRect(QRectF(x+w/2 - 3, y, 6, 6));
pp.drawRect(QRectF(x+w-6, y+h/2 - 3, 6, 6));
pp.drawRect(QRectF(x+w-6, y, 6, 6));
pp.drawRect(QRectF(x, y, 6, 6));
pp.drawRect(QRectF(x, y+h/2 - 3, 6, 6));
pp.drawRect(QRectF(x, y+h-6, 6, 6));
}
else
{
pp.resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
pp.translate(out.x(), out.y());
pp.translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
Transform(currItem, &pp);
currItem->paintObj(&pp);
}
}
}
}
pp.end();
psx->resetMatrix();
psx->drawPixmap(0, 0, ppx);
return;
}
QPoint vr = contentsToViewport(QPoint(clipx, clipy));
ScPainter *painter=0;
QImage img = QImage(clipw, cliph, QImage::Format_ARGB32);
painter = new ScPainter(&img, img.width(), img.height(), 1.0, 0);
painter->clear(paletteBackgroundColor());
painter->newPath();
painter->moveTo(0, 0);
painter->lineTo(clipw, 0);
painter->lineTo(clipw, cliph);
painter->lineTo(0, cliph);
painter->closePath();
painter->setClipPath();
painter->translate(-clipx, -clipy);
painter->setZoomFactor(Scale);
painter->translate(-Doc->minCanvasCoordinate.x(), -Doc->minCanvasCoordinate.y());
painter->setLineWidth(1);
painter->setFillMode(ScPainter::Solid);
/* Draw Page Outlines */
if (!Doc->masterPageMode())
{
uint docPagesCount=Doc->Pages->count();
if (!viewAsPreview)
{
painter->setBrush(QColor(128,128,128));
painter->setAntialiasing(false);
painter->beginLayer(1.0, 0);
painter->setPen(Qt::black, 1.0 / Scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
Page *actPg;
for (int a = 0; a < static_cast<int>(docPagesCount); ++a)
{
actPg = Doc->Pages->at(a);
double bleedRight = 0.0;
double bleedLeft = 0.0;
double bleedBottom = 0.0;
double bleedTop = 0.0;
Doc->getBleeds(actPg, &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
double blx = (actPg->xOffset() - bleedLeft) * Scale;
double bly = (actPg->yOffset() - bleedTop) * Scale;
double blw = (actPg->width() + bleedLeft + bleedRight) * Scale;
double blh = (actPg->height() + bleedBottom + bleedTop) * Scale;
QRectF drawRect = QRectF(blx-1, bly-1, blw+6, blh+6);
drawRect.translate(-Doc->minCanvasCoordinate.x() * Scale, -Doc->minCanvasCoordinate.y() * Scale);
if (drawRect.intersects(QRectF(clipx, clipy, clipw, cliph)))
{
painter->setFillMode(ScPainter::Solid);
double blx2 = actPg->xOffset();
double bly2 = actPg->yOffset();
double blw2 = actPg->width();
double blh2 = actPg->height();
if (Doc->guidesSettings.showBleed)
{
blx2 -= bleedLeft;
bly2 -= bleedTop;
blw2 += bleedLeft + bleedRight;
blh2 += bleedBottom + bleedTop;
}
painter->drawRect(blx2 + 5 / Scale, bly2 + 5 / Scale, blw2, blh2);
if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
{
painter->setFillMode(ScPainter::None);
painter->setPen(Qt::black, 1.0 / Scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
painter->drawRect(blx2, bly2 - 1 / Scale, blw2 + 1 / Scale, blh2 + 2 / Scale);
}
}
}
painter->endLayer();
painter->setAntialiasing(true);
}
painter->setFillMode(ScPainter::Solid);
Page *actPg;
for (int a = 0; a < static_cast<int>(docPagesCount); ++a)
{
actPg = Doc->Pages->at(a);
double x = actPg->xOffset();
double y = actPg->yOffset();
double w = actPg->width();
double h = actPg->height();
double bleedRight = 0.0;
double bleedLeft = 0.0;
double bleedBottom = 0.0;
double bleedTop = 0.0;
bool drawBleed = false;
if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
{
drawBleed = true;
Doc->getBleeds(a, &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
}
double blx = (actPg->xOffset() - bleedLeft) * Scale;
double bly = (actPg->yOffset() - bleedTop) * Scale;
double blw = (actPg->width() + bleedLeft + bleedRight) * Scale;
double blh = (actPg->height() + bleedBottom + bleedTop) * Scale;
QRectF drawRect = QRectF(blx, bly, blw+5, blh+5);
drawRect.translate(-Doc->minCanvasCoordinate.x() * Scale, -Doc->minCanvasCoordinate.y() * Scale);
if (drawRect.intersects(QRectF(clipx, clipy, clipw, cliph)))
{
painter->setFillMode(ScPainter::Solid);
painter->setPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
painter->setAntialiasing(false);
painter->beginLayer(1.0, 0);
painter->setLineWidth(0.0);
painter->setBrush(Doc->papColor);
if (!viewAsPreview)
{
double blx2 = actPg->xOffset() - bleedLeft;
double bly2 = actPg->yOffset() - bleedTop;
double blw2 = actPg->width() + bleedLeft + bleedRight;
double blh2 = actPg->height() + bleedBottom + bleedTop;
painter->drawRect(blx2, bly2, blw2, blh2);
if (drawBleed)
painter->drawRect(x, y, w, h);
}
else
painter->drawRect(x, y, w, h);
painter->endLayer();
painter->setAntialiasing(true);
}
}
if (viewAsPreview)
{
FPointArray PoLine;
bool first = true;
Page *actPg;
for (int a = 0; a < static_cast<int>(docPagesCount); ++a)
{
if (!first)
PoLine.setMarker();
first = false;
actPg = Doc->Pages->at(a);
double x = actPg->xOffset();
double y = actPg->yOffset();
double w = actPg->width();
double h = actPg->height();
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,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0};
for (int a = 0; a < 29; a += 4)
{
PoLine.addPoint(x + w * rect[a], y + h * rect[a+1]);
PoLine.addPoint(x + w * rect[a+2], y + h * rect[a+3]);
}
}
painter->beginLayer(1.0, 0, &PoLine);
}
else
painter->beginLayer(1.0, 0);
if ((Doc->guidesSettings.before) && (!viewAsPreview))
{
Page *actPg;
for (uint a = 0; a < docPagesCount; ++a)
{
actPg = Doc->Pages->at(a);
double x = actPg->xOffset() * Scale;
double y = actPg->yOffset() * Scale;
double w = actPg->width() * Scale;
double h = actPg->height() * Scale;
QRectF drawRect = QRectF(x, y, w+5, h+5);
drawRect.translate(-Doc->minCanvasCoordinate.x() * Scale, -Doc->minCanvasCoordinate.y() * Scale);
if (drawRect.intersects(QRectF(clipx, clipy, clipw, cliph)))
DrawPageMarks(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph));
}
}
for (uint a = 0; a < docPagesCount; ++a)
{
DrawMasterItems(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph));
}
DrawPageItems(painter, QRect(clipx, clipy, clipw, cliph));
painter->endLayer();
if ((!Doc->guidesSettings.before) && (!viewAsPreview))
{
Page *actPg;
for (uint a = 0; a < docPagesCount; ++a)
{
actPg = Doc->Pages->at(a);
double x = actPg->xOffset() * Scale;
double y = actPg->yOffset() * Scale;
double w = actPg->width() * Scale;
double h = actPg->height() * Scale;
QRectF drawRect = QRectF(x, y, w+5, h+5);
drawRect.translate(-Doc->minCanvasCoordinate.x() * Scale, -Doc->minCanvasCoordinate.y() * Scale);
if (drawRect.intersects(QRectF(clipx, clipy, clipw, cliph)))
DrawPageMarks(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph));
}
}
}
else
{
double x = Doc->scratch.Left * Scale;
double y = Doc->scratch.Top * Scale;
double w = Doc->currentPage()->width() * Scale;
double h = Doc->currentPage()->height() * Scale;
QRectF drawRect = QRectF(x, y, w+5, h+5);
drawRect.translate(-Doc->minCanvasCoordinate.x() * Scale, -Doc->minCanvasCoordinate.y() * Scale);
if (drawRect.intersects(QRectF(clipx, clipy, clipw, cliph)))
{
painter->setFillMode(ScPainter::Solid);
painter->setBrush(QColor(128,128,128));
double bleedRight = 0.0;
double bleedLeft = 0.0;
double bleedBottom = 0.0;
double bleedTop = 0.0;
Doc->getBleeds(Doc->currentPage(), &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
painter->beginLayer(1.0, 0);
painter->setAntialiasing(false);
painter->setPen(Qt::black, 1 / Scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
{
painter->drawRect(Doc->scratch.Left - bleedLeft+5 / Scale, Doc->scratch.Top - bleedTop+5 / Scale, Doc->currentPage()->width() + bleedLeft + bleedRight, Doc->currentPage()->height() + bleedBottom + bleedTop);
painter->setBrush(Doc->papColor);
painter->drawRect(Doc->scratch.Left - bleedLeft, Doc->scratch.Top - bleedTop, Doc->currentPage()->width() + bleedLeft + bleedRight, Doc->currentPage()->height() + bleedBottom + bleedTop);
}
else
{
painter->drawRect(Doc->scratch.Left+5 / Scale, Doc->scratch.Top+5 / Scale, Doc->currentPage()->width(), Doc->currentPage()->height());
painter->setBrush(Doc->papColor);
painter->drawRect(Doc->scratch.Left, Doc->scratch.Top, Doc->currentPage()->width(), Doc->currentPage()->height());
}
painter->setAntialiasing(true);
if (Doc->guidesSettings.before)
DrawPageMarks(painter, Doc->currentPage(), QRect(clipx, clipy, clipw, cliph));
painter->endLayer();
}
painter->beginLayer(1.0, 0);
DrawPageItems(painter, QRect(clipx, clipy, clipw, cliph));
painter->endLayer();
if ((!Doc->guidesSettings.before) && (drawRect.intersects(QRect(clipx, clipy, clipw, cliph))))
DrawPageMarks(painter, Doc->currentPage(), QRect(clipx, clipy, clipw, cliph));
}
if (((Doc->m_Selection->count() != 0) || (linkedFramesToShow.count() != 0)) && (!viewAsPreview))
{
painter->save();
PageItem *currItem;
if ((Doc->guidesSettings.linkShown) && (linkedFramesToShow.count() != 0))
currItem = linkedFramesToShow.at(0);
else
{
if (linkedFramesToShow.count() != 0)
currItem = linkedFramesToShow.at(0);
else
currItem = Doc->m_Selection->itemAt(0);
}
//Draw the frame links
if ((((Doc->appMode == modeLinkFrames) || (Doc->appMode == modeUnlinkFrames))
&& (currItem->itemType() == PageItem::TextFrame)) || (Doc->guidesSettings.linkShown))
{
PageItem *nextItem = currItem;
if (Doc->guidesSettings.linkShown)
{
for (uint lks = 0; lks < linkedFramesToShow.count(); ++lks)
{
nextItem = linkedFramesToShow.at(lks);
while (nextItem != 0)
{
//Calculate the link points of the frames
double x11 = nextItem->xPos();
double y11 = nextItem->yPos();
double x12 = x11+nextItem->width();
double y12 = y11+nextItem->height();
double x1mid = x11+(x12-x11)/2;
double y1mid = y11+(y12-y11)/2;
if (nextItem->rotation()!=0.000)
{
FPoint tempPoint(0,0, x11, y11, nextItem->rotation(), 1, 1);
x11=tempPoint.x();
y11=tempPoint.y();
FPoint tempPoint2(0,0, x12, y12, nextItem->rotation(), 1, 1);
x12=tempPoint2.x();
y12=tempPoint2.y();
FPoint tempPoint3(0,0, x1mid, y1mid, nextItem->rotation(), 1, 1);
x1mid=tempPoint3.x();
y1mid=tempPoint3.y();
}
double a1, b1, a2, b2;
a1 = a2 = b1 = b2 = 0;
if (nextItem->nextInChain() != NULL)
{
double x21 = nextItem->nextInChain()->xPos();
double y21 = nextItem->nextInChain()->yPos();
double x22 = x21+nextItem->nextInChain()->width();
double y22 = y21+nextItem->nextInChain()->height();
double x2mid = x21 + nextItem->nextInChain()->width()/2;
double y2mid = y21 + nextItem->nextInChain()->height()/2;
//x2mid = x21+(x22-x21)/2;
//y2mid = y21+(y22-y21)/2;
if (nextItem->nextInChain()->rotation()!=0.000)
{
FPoint tempPoint(0,0, x21, y21, nextItem->nextInChain()->rotation(), 1, 1);
x21=tempPoint.x();
y21=tempPoint.y();
FPoint tempPoint2(0,0, x22, y22, nextItem->nextInChain()->rotation(), 1, 1);
x22=tempPoint2.x();
y22=tempPoint2.y();
FPoint tempPoint3(0,0, x2mid, y2mid, nextItem->nextInChain()->rotation(), 1, 1);
x2mid=tempPoint3.x();
y2mid=tempPoint3.y();
}
if (x22<x11) { a1 = x11; a2 = x22; }
if (x21>x12) { a1 = x12; a2 = x21; }
if (y22<y11) { b1 = y11; b2 = y22; }
if (y21>y12) { b1 = y12; b2 = y21; }
if (x21<x12 && x21>x11) { a1 = x1mid; a2 = x2mid; }
if (x21<x11 && x22>x11) { a1 = x1mid; a2 = x2mid; }
if (y21<y12 && y21>y11) { b1 = y1mid; b2 = y2mid; }
if (y21<y11 && y22>y11) { b1 = y1mid; b2 = y2mid; }
}
//Draw the link frame lines
FPoint Start(a1-nextItem->xPos(), b1-nextItem->yPos(), nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
//FPoint Start = transformPoint(FPoint(nextItem->Width/2, nextItem->Height), nextItem->xPos(), nextItem->yPos(), nextItem->Rot, 1, 1);
nextItem = nextItem->nextInChain();
if (nextItem != NULL)
{
FPoint End(a2-nextItem->xPos(), b2-nextItem->yPos(), nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
drawLinkFrameLine(painter, Start, End);
}
}
}
}
else
{
while (nextItem != 0)
{
if (nextItem->prevInChain() != 0)
nextItem = nextItem->prevInChain();
else
break;
}
while (nextItem != 0)
{
FPoint Start(nextItem->width()/2, nextItem->height(), nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
nextItem = nextItem->nextInChain();
//Draw the link frame indicator for a new link
//CB unsure if we need to do this
if (nextItem != 0)
{
FPoint End(nextItem->width()/2, 0, nextItem->xPos(), nextItem->yPos(), nextItem->rotation(), 1, 1);
drawLinkFrameLine(painter, Start, End);
}
}
}
}
painter->setLineWidth(1);
painter->setPenOpacity(1.0);
painter->restore();
}
painter->end();
psx->drawImage(clipx, clipy, img);
delete painter;
painter=NULL;
}
/* psx->setRenderHint(QPainter::Antialiasing, true);
if (operItemMoving || operItemResizing)
{
if (operItemResizing)
{
if (!redrawPolygon.isEmpty())
{
if (m_MouseButtonPressed && (Doc->appMode == modeDrawFreehandLine))
{
psx->resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
psx->translate(out.x(), out.y());
psx->translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
psx->scale(Scale, Scale);
psx->setBrush(Qt::NoBrush);
psx->setPen(QPen(Qt::black, 1.0 / Scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
psx->drawPolyline(redrawPolygon);
redrawPolygon.clear();
}
else
{
QColor drawColor = qApp->palette().color(QPalette::Active, QColorGroup::Highlight);
psx->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
drawColor.setAlpha(64);
psx->setBrush(drawColor);
psx->drawPolygon(redrawPolygon);
redrawPolygon.clear();
}
}
}
else
{
if (Doc->m_Selection->count() != 0)
{
uint selectedItemCount = Doc->m_Selection->count();
PageItem *currItem = Doc->m_Selection->itemAt(0);
if (selectedItemCount < moveWithBoxesOnlyThreshold)
{
for (uint cu = 0; cu < selectedItemCount; cu++)
{
currItem = Doc->m_Selection->itemAt(cu);
psx->resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
psx->translate(out.x(), out.y());
psx->translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
Transform(currItem, psx);
psx->setBrush(Qt::NoBrush);
psx->setPen(QPen(Qt::black, 1.0 / Scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
if (selectedItemCount < moveWithFullOutlinesThreshold)
{
if (!(currItem->asLine()))
currItem->DrawPolyL(psx, currItem->Clip);
else
{
if (currItem->asLine())
{
int lw2 = 1;
int lw = 1;
Qt::PenCapStyle le = Qt::FlatCap;
if (currItem->NamedLStyle.isEmpty())
{
lw2 = qRound(currItem->lineWidth() / 2.0);
lw = qRound(qMax(currItem->lineWidth(), 1.0));
le = currItem->PLineEnd;
}
else
{
multiLine ml = Doc->MLineStyles[currItem->NamedLStyle];
lw2 = qRound(ml[ml.size()-1].Width / 2.0);
lw = qRound(qMax(ml[ml.size()-1].Width, 1.0));
le = static_cast<Qt::PenCapStyle>(ml[ml.size()-1].LineEnd);
}
if (le != Qt::FlatCap)
psx->drawRect(-lw2, -lw2, qRound(currItem->width())+lw, lw);
else
psx->drawRect(-1, -lw2, qRound(currItem->width()), lw);
}
}
}
else
psx->drawRect(0, 0, static_cast<int>(currItem->width())+1, static_cast<int>(currItem->height())+1);
}
}
else
{
double gx, gy, gw, gh;
Doc->m_Selection->setGroupRect();
getGroupRectScreen(&gx, &gy, &gw, &gh);
QPoint out = contentsToViewport(QPoint(0, 0));
psx->resetMatrix();
psx->translate(-out.x(), -out.y());
psx->translate(qRound(gx), qRound(gy));
psx->scale(Scale, Scale);
psx->drawRect(QRect(0, 0, qRound(gw), qRound(gh)));
}
}
}
}
else
{ */
if ((Doc->m_Selection->count() != 0) && !(operItemMoving || operItemResizing) && (Doc->appMode != modeDrawBezierLine))
{
PageItem *currItem = Doc->m_Selection->itemAt(0);
if ((Doc->EditClip) && (currItem->isSelected()) && (!specialRendering))
{
if (EditContour)
MarkClip(psx, currItem, currItem->ContourLine, true);
else
MarkClip(psx, currItem, currItem->PoLine, true);
}
else
{
if (Doc->m_Selection->isMultipleSelection())
{
psx->resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
psx->translate(out.x(), out.y());
psx->translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
if (Doc->m_Selection->count() != 0)
{
uint docSelectionCount = Doc->m_Selection->count();
PageItem *currItem;
for (uint a=0; a<docSelectionCount; ++a)
{
currItem = Doc->m_Selection->itemAt(a);
psx->save();
Transform(currItem, psx);
currItem->paintObj(psx);
psx->restore();
}
}
psx->resetMatrix();
psx->translate(out.x(), out.y());
psx->translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
double x, y, w, h;
Doc->m_Selection->setGroupRect();
Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
x *= Scale;
y *= Scale;
w *= Scale;
h *= Scale;
psx->setPen(QPen(Qt::red, 1, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin));
psx->setBrush(Qt::NoBrush);
psx->drawRect(QRectF(x, y, w, h));
psx->setBrush(Qt::red);
psx->setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
psx->drawRect(QRectF(x+w-6, y+h-6, 6, 6));
psx->drawRect(QRectF(x+w/2 - 3, y+h-6, 6, 6));
psx->drawRect(QRectF(x+w/2 - 3, y, 6, 6));
psx->drawRect(QRectF(x+w-6, y+h/2 - 3, 6, 6));
psx->drawRect(QRectF(x+w-6, y, 6, 6));
psx->drawRect(QRectF(x, y, 6, 6));
psx->drawRect(QRectF(x, y+h/2 - 3, 6, 6));
psx->drawRect(QRectF(x, y+h-6, 6, 6));
}
else
{
psx->resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
psx->translate(out.x(), out.y());
psx->translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
Transform(currItem, psx);
currItem->paintObj(psx);
}
}
}
/* } */
if (Doc->appMode == modeEdit)
slotDoCurs(true);
if (Doc->appMode == modeEditGradientVectors)
{
PageItem *currItem = Doc->m_Selection->itemAt(0);
psx->resetMatrix();
QPoint out = contentsToViewport(QPoint(0, 0));
psx->translate(out.x(), out.y());
psx->translate(-qRound(Doc->minCanvasCoordinate.x()*Scale), -qRound(Doc->minCanvasCoordinate.y()*Scale));
Transform(currItem, psx);
psx->setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
psx->setBrush(Qt::NoBrush);
psx->drawLine(QPointF(currItem->GrStartX, currItem->GrStartY), QPointF(currItem->GrEndX, currItem->GrEndY));
psx->setPen(QPen(Qt::magenta, 8, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
psx->drawPoint(QPointF(currItem->GrStartX, currItem->GrStartY));
psx->drawPoint(QPointF(currItem->GrEndX, currItem->GrEndY));
}
evSpon = false;
forceRedraw = false;
// qDebug( "Time elapsed: %d ms", tim.elapsed() );
}
void ScribusView::DrawMasterItems(ScPainter *painter, Page *page, QRect clip)
{
QRect oldR;
Q3PtrStack<PageItem> groupStack;
Q3PtrStack<PageItem> groupStack2;
if (!page->MPageNam.isEmpty())
{
Page* Mp = Doc->MasterPages.at(Doc->MasterNames[page->MPageNam]);
if (page->FromMaster.count() != 0)
{
int Lnr;
struct Layer ll;
PageItem *currItem;
ll.isViewable = false;
ll.LNr = 0;
Lnr = 0;
uint layerCount=Doc->layerCount();
for (uint la = 0; la < layerCount; ++la)
{
Level2Layer(Doc, &ll, Lnr);
bool pr = true;
if ((previewMode) && (!ll.isPrintable))
pr = false;
if ((viewAsPreview) && (!ll.isPrintable))
pr = false;
if ((ll.isViewable) && (pr))
{
if ((layerCount > 1) || (ll.transparency != 1.0))
painter->beginLayer(ll.transparency, ll.blendMode);
uint pageFromMasterCount=page->FromMaster.count();
for (uint a = 0; a < pageFromMasterCount; ++a)
{
currItem = page->FromMaster.at(a);
if (currItem->LayerNr != ll.LNr)
continue;
if ((currItem->OwnPage != -1) && (currItem->OwnPage != static_cast<int>(Mp->pageNr())))
continue;
if ((previewMode) && (!currItem->printEnabled()))
continue;
if ((viewAsPreview) && (!currItem->printEnabled()))
continue;
double OldX = currItem->xPos();
double OldY = currItem->yPos();
double OldBX = currItem->BoundingX;
double OldBY = currItem->BoundingY;
if (!currItem->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
currItem->moveBy(-Mp->xOffset() + page->xOffset(), -Mp->yOffset() + page->yOffset(), true);
currItem->BoundingX = OldBX - Mp->xOffset() + page->xOffset();
currItem->BoundingY = OldBY - Mp->yOffset() + page->yOffset();
}
oldR = currItem->getRedrawBounding(Scale);
if (currItem->isGroupControl)
{
painter->save();
currItem->savedOwnPage = currItem->OwnPage;
currItem->OwnPage = page->pageNr();
if ((clip.intersects(oldR)) && (Doc->guidesSettings.layerMarkersShown) && (Doc->layerCount() > 1))
currItem->DrawObj(painter, clip);
FPointArray cl = currItem->PoLine.copy();
QMatrix mm;
mm.translate(currItem->xPos(), currItem->yPos());
mm.rotate(currItem->rotation());
cl.map( mm );
painter->beginLayer(1.0 - currItem->fillTransparency(), currItem->fillBlendmode(), &cl);
groupStack.push(currItem->groupsLastItem);
groupStack2.push(currItem);
currItem->OwnPage = currItem->savedOwnPage;
if (!currItem->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
currItem->setXYPos(OldX, OldY, true);
currItem->BoundingX = OldBX;
currItem->BoundingY = OldBY;
}
continue;
}
currItem->savedOwnPage = currItem->OwnPage;
currItem->OwnPage = page->pageNr();
if (!evSpon || forceRedraw)
currItem->invalid = true;
if (clip.intersects(oldR))
{
if (!((operItemMoving || operItemResizeInEditMode) && (currItem->isSelected())))
currItem->DrawObj(painter, clip);
}
currItem->OwnPage = currItem->savedOwnPage;
if (!currItem->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
currItem->setXYPos(OldX, OldY, true);
currItem->BoundingX = OldBX;
currItem->BoundingY = OldBY;
}
if (groupStack.count() != 0)
{
while (currItem == groupStack.top())
{
painter->endLayer();
painter->restore();
PageItem *cite = groupStack2.pop();
double OldX = cite->xPos();
double OldY = cite->yPos();
double OldBX = cite->BoundingX;
double OldBY = cite->BoundingY;
if (!cite->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
cite->moveBy(-Mp->xOffset() + page->xOffset(), -Mp->yOffset() + page->yOffset(), true);
cite->BoundingX = OldBX - Mp->xOffset() + page->xOffset();
cite->BoundingY = OldBY - Mp->yOffset() + page->yOffset();
}
oldR = cite->getRedrawBounding(Scale);
if ((clip.intersects(oldR)) && (Doc->guidesSettings.layerMarkersShown) && (Doc->layerCount() > 1))
cite->DrawObj(painter, clip);
cite->OwnPage = cite->savedOwnPage;
if (!currItem->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
cite->setXYPos(OldX, OldY, true);
cite->BoundingX = OldBX;
cite->BoundingY = OldBY;
}
groupStack.pop();
}
}
}
for (uint a = 0; a < pageFromMasterCount; ++a)
{
currItem = page->FromMaster.at(a);
if (currItem->LayerNr != ll.LNr)
continue;
if (!currItem->isTableItem)
continue;
if ((previewMode) && (!currItem->printEnabled()))
continue;
if ((viewAsPreview) && (!currItem->printEnabled()))
continue;
if ((currItem->OwnPage != -1) && (currItem->OwnPage != static_cast<int>(Mp->pageNr())))
continue;
if (currItem->isGroupControl)
continue;
double OldX = currItem->xPos();
double OldY = currItem->yPos();
double OldBX = currItem->BoundingX;
double OldBY = currItem->BoundingY;
if (!currItem->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
currItem->setXYPos(OldX - Mp->xOffset() + page->xOffset(), OldY - Mp->yOffset() + page->yOffset(), true);
currItem->BoundingX = OldBX - Mp->xOffset() + page->xOffset();
currItem->BoundingY = OldBY - Mp->yOffset() + page->yOffset();
}
oldR = currItem->getRedrawBounding(Scale);
if (clip.intersects(oldR))
{
painter->save();
painter->translate(currItem->xPos(), currItem->yPos());
painter->rotate(currItem->rotation());
if ((currItem->lineColor() != CommonStrings::None) && (currItem->lineWidth() != 0.0))
{
QColor tmp;
currItem->SetFarbe(&tmp, currItem->lineColor(), currItem->lineShade());
if ((currItem->TopLine) || (currItem->RightLine) || (currItem->BottomLine) || (currItem->LeftLine))
{
painter->setPen(tmp, currItem->lineWidth(), currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin);
if (currItem->TopLine)
painter->drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0));
if (currItem->RightLine)
painter->drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height()));
if (currItem->BottomLine)
painter->drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height()));
if (currItem->LeftLine)
painter->drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0));
}
}
painter->restore();
}
if (!currItem->ChangedMasterItem)
{
//Hack to not check for undo changes, indicate drawing only
currItem->setXYPos(OldX, OldY, true);
currItem->BoundingX = OldBX;
currItem->BoundingY = OldBY;
}
}
if ((layerCount > 1) || (ll.transparency != 1.0))
painter->endLayer();
}
Lnr++;
}
}
}
}
void ScribusView::DrawPageItems(ScPainter *painter, QRect clip)
{
linkedFramesToShow.clear();
QRect oldR;
Q3PtrStack<PageItem> groupStack;
Q3PtrStack<PageItem> groupStack2;
if (Doc->Items->count() != 0)
{
int Lnr=0;
struct Layer ll;
PageItem *currItem;
ll.isViewable = false;
ll.LNr = 0;
uint layerCount=Doc->layerCount();
int docCurrPageNo=static_cast<int>(Doc->currentPageNumber());
for (uint la2 = 0; la2 < layerCount; ++la2)
{
Level2Layer(Doc, &ll, Lnr);
bool pr = true;
if ((previewMode) && (!ll.isPrintable))
pr = false;
if ((viewAsPreview) && (!ll.isPrintable))
pr = false;
if ((ll.isViewable) && (pr))
{
if ((layerCount > 1) || (ll.transparency != 1.0))
painter->beginLayer(ll.transparency, ll.blendMode);
Q3PtrListIterator<PageItem> docItem(*Doc->Items);
while ( (currItem = docItem.current()) != 0)
{
++docItem;
if (currItem->LayerNr != ll.LNr)
continue;
if ((previewMode) && (!currItem->printEnabled()))
continue;
if ((viewAsPreview) && (!currItem->printEnabled()))
continue;
if ((Doc->masterPageMode()) && ((currItem->OwnPage != -1) && (currItem->OwnPage != docCurrPageNo)))
continue;
if (!Doc->masterPageMode() && !currItem->OnMasterPage.isEmpty())
{
if (currItem->OnMasterPage != Doc->currentPage()->pageName())
continue;
}
oldR = currItem->getRedrawBounding(Scale);
if (currItem->isGroupControl)
{
painter->save();
FPointArray cl = currItem->PoLine.copy();
QMatrix mm;
mm.translate(currItem->xPos(), currItem->yPos());
mm.rotate(currItem->rotation());
cl.map( mm );
painter->beginLayer(1.0 - currItem->fillTransparency(), currItem->fillBlendmode(), &cl);
groupStack.push(currItem->groupsLastItem);
groupStack2.push(currItem);
continue;
}
if (clip.intersects(oldR))
{
if (!evSpon || forceRedraw)
currItem->invalid = true;
// if ((!m_MouseButtonPressed) || (Doc->EditClip))
if (!((operItemMoving || operItemResizeInEditMode) && (currItem->isSelected())))
currItem->DrawObj(painter, clip);
// currItem->Redrawn = true;
if ((currItem->asTextFrame()) && ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0)))
{
PageItem *nextItem = currItem;
while (nextItem != 0)
{
if (nextItem->prevInChain() != 0)
nextItem = nextItem->prevInChain();
else
break;
}
if (linkedFramesToShow.find(nextItem) == -1)
linkedFramesToShow.append(nextItem);
}
if ((Doc->appMode == modeEdit) && (currItem->isSelected()) && (currItem->itemType() == PageItem::TextFrame))
{
//CB 230305 Stop redrawing the horizontal ruler if it hasnt changed when typing text!!!
if ((qRound(horizRuler->ItemPos*10000) != qRound((currItem->xPos())*10000)) || (qRound(horizRuler->ItemEndPos*10000) != qRound(((currItem->xPos()+currItem->width()) )*10000)))
{
horizRuler->setItem(currItem);
if (currItem->lineColor() != CommonStrings::None)
horizRuler->lineCorr = currItem->lineWidth() / 2.0;
else
horizRuler->lineCorr = 0;
horizRuler->ColGap = currItem->ColGap;
horizRuler->Cols = currItem->Cols;
horizRuler->Extra = currItem->textToFrameDistLeft();
horizRuler->RExtra = currItem->textToFrameDistRight();
horizRuler->First = currItem->currentStyle().firstIndent();
horizRuler->Indent = currItem->currentStyle().leftMargin();
double columnWidth = (currItem->width() - (currItem->columnGap() * (currItem->columns() - 1))
- currItem->textToFrameDistLeft() - currItem->textToFrameDistLeft()
- 2*horizRuler->lineCorr) / currItem->columns();
horizRuler->RMargin = columnWidth - currItem->currentStyle().rightMargin();
if (currItem->imageFlippedH() || (currItem->reversed()))
horizRuler->Revers = true;
else
horizRuler->Revers = false;
horizRuler->ItemPosValid = true;
horizRuler->TabValues = currItem->currentStyle().tabValues();
horizRuler->update();
}
}
}
if (groupStack.count() != 0)
{
while (currItem == groupStack.top())
{
painter->endLayer();
painter->restore();
PageItem *cite = groupStack2.pop();
oldR = cite->getRedrawBounding(Scale);
if ((clip.intersects(oldR)) && (((Doc->guidesSettings.layerMarkersShown) && (Doc->layerCount() > 1)) || (cite->textFlowUsesContourLine())))
cite->DrawObj(painter, clip);
groupStack.pop();
}
}
}
Q3PtrListIterator<PageItem> docItem2(*Doc->Items);
while ( (currItem = docItem2.current()) != 0 )
{
++docItem2;
if (currItem->LayerNr != ll.LNr)
continue;
if (!currItem->isTableItem)
continue;
if ((previewMode) && (!currItem->printEnabled()))
continue;
if ((viewAsPreview) && (!currItem->printEnabled()))
continue;
oldR = currItem->getRedrawBounding(Scale);
if (clip.intersects(oldR))
{
painter->save();
painter->translate(currItem->xPos(), currItem->yPos());
painter->rotate(currItem->rotation());
if ((currItem->lineColor() != CommonStrings::None) && (currItem->lineWidth() != 0.0))
{
QColor tmp;
currItem->SetFarbe(&tmp, currItem->lineColor(), currItem->lineShade());
if ((currItem->TopLine) || (currItem->RightLine) || (currItem->BottomLine) || (currItem->LeftLine))
{
painter->setPen(tmp, currItem->lineWidth(), currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin);
if (currItem->TopLine)
painter->drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0));
if (currItem->RightLine)
painter->drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height()));
if (currItem->BottomLine)
painter->drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height()));
if (currItem->LeftLine)
painter->drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0));
}
}
painter->restore();
}
}
if ((layerCount > 1) || (ll.transparency != 1.0))
painter->endLayer();
}
Lnr++;
}
}
}
void ScribusView::DrawPageMarks(ScPainter *p, Page *page, QRect clip)
{
p->save();
p->setAntialiasing(false);
p->translate(page->xOffset(), page->yOffset());
double lineWidth = 1.0 / Scale;
double pageHeight=page->height();
double pageWidth=page->width();
p->setFillMode(ScPainter::None);
p->setPen(Qt::black, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->drawRect(0, 0, pageWidth, pageHeight);
//Draw the margins
if (Doc->guidesSettings.marginsShown)
{
p->setPen(Doc->guidesSettings.margColor);
if (Doc->marginColored)
{
p->setBrush(Doc->guidesSettings.margColor);
p->drawRect(0, 0, pageWidth, page->Margins.Top);
p->drawRect(0, page->Margins.Top, page->Margins.Left, pageHeight - page->Margins.Top);
p->drawRect(page->Margins.Left, pageHeight - page->Margins.Bottom, pageWidth - page->Margins.Right - page->Margins.Left, page->Margins.Bottom);
p->drawRect(pageWidth - page->Margins.Right, page->Margins.Top, page->Margins.Right, pageHeight-page->Margins.Top);
}
// p->setPen(Doc->guidesSettings.margColor);
p->setFillMode(ScPainter::None);
p->drawRect(page->Margins.Left, page->Margins.Top, pageWidth - page->Margins.Left - page->Margins.Right, pageHeight - page->Margins.Top - page->Margins.Bottom);
// p->drawLine(FPoint(0, page->Margins.Top), FPoint(pageWidth, page->Margins.Top));
// p->drawLine(FPoint(0, pageHeight - page->Margins.Bottom), FPoint(pageWidth, pageHeight - page->Margins.Bottom));
// p->drawLine(FPoint(page->Margins.Left, 0), FPoint(page->Margins.Left, pageHeight));
// p->drawLine(FPoint(pageWidth - page->Margins.Right, 0), FPoint(pageWidth - page->Margins.Right, pageHeight));
}
//Draw the baseline grid
if (Doc->guidesSettings.baseShown)
{
p->setPen(Doc->guidesSettings.baseColor, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
for (double yg = Doc->typographicSettings.offsetBaseGrid; yg < pageHeight; yg += Doc->typographicSettings.valueBaseGrid)
p->drawLine(FPoint(0, yg), FPoint(pageWidth, yg));
}
//Draw the grid lines
if (Doc->guidesSettings.gridShown)
{
double lowerBx = qMax(clip.x() / Scale + Doc->minCanvasCoordinate.x() - page->xOffset(), 0.0);
double lowerBy = qMax(clip.y() / Scale + Doc->minCanvasCoordinate.y() - page->yOffset(), 0.0);
double highBx = qMin(lowerBx + clip.width() / Scale, pageWidth);
double highBy = qMin(lowerBy + clip.height() / Scale, pageHeight);
if (Scale > 0.49)
{
double i,start;
i = Doc->guidesSettings.majorGrid;
p->setPen(Doc->guidesSettings.majorColor, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
start=floor(lowerBy/i);
start*=i;
for (double b = start; b <= highBy; b+=i)
{
p->drawLine(FPoint(qMax(lowerBx, 0.0), b), FPoint(qMin(pageWidth, highBx), b));
}
start=floor(lowerBx/i);
start*=i;
for (double b = start; b <= highBx; b+=i)
{
p->drawLine(FPoint(b, qMax(lowerBy, 0.0)), FPoint(b, qMin(pageHeight, highBy)));
}
i = Doc->guidesSettings.minorGrid;
p->setPen(Doc->guidesSettings.minorColor, lineWidth, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
start=floor(lowerBy/i);
start*=i;
for (double b = start; b <= highBy; b+=i)
{
p->drawLine(FPoint(qMax(lowerBx, 0.0), b), FPoint(qMin(pageWidth, highBx), b));
}
start=floor(lowerBx/i);
start*=i;
for (double b = start; b <= highBx; b+=i)
{
p->drawLine(FPoint(b, qMax(lowerBy, 0.0)), FPoint(b, qMin(pageHeight, highBy)));
}
}
}
//Draw the guides
if (Doc->guidesSettings.guidesShown)
page->guides.drawPage(p, Doc, lineWidth);
if (Doc->currentPage() == page)
{
p->setPen(Prefs->DPageBorderColor, 2 / Scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
p->drawRect(0, 0, pageWidth, pageHeight);
}
p->setAntialiasing(true);
p->restore();
}
void ScribusView::enterEvent(QEvent *)
{
if (!m_MouseButtonPressed)
{
switch (Doc->appMode)
{
case modeDrawShapes:
qApp->changeOverrideCursor(QCursor(loadIcon("DrawFrame.xpm")));
break;
case modeDrawPicture:
qApp->changeOverrideCursor(QCursor(loadIcon("DrawImageFrame.xpm")));
break;
case modeDrawText:
qApp->changeOverrideCursor(QCursor(loadIcon("DrawTextFrame.xpm")));
break;
case modeDrawTable:
qApp->changeOverrideCursor(QCursor(loadIcon("DrawTable.xpm")));
break;
case modeDrawRegularPolygon:
qApp->changeOverrideCursor(QCursor(loadIcon("DrawPolylineFrame.xpm")));
break;
case modeDrawLine:
case modeDrawBezierLine:
qApp->changeOverrideCursor(QCursor(Qt::CrossCursor));
break;
case modeDrawFreehandLine:
qApp->changeOverrideCursor(QCursor(loadIcon("DrawFreeLine.png"), 0, 32));
break;
case modeMagnifier:
if (Magnify)
qApp->changeOverrideCursor(QCursor(loadIcon("LupeZ.xpm")));
else
qApp->changeOverrideCursor(QCursor(loadIcon("LupeZm.xpm")));
break;
case modePanning:
qApp->changeOverrideCursor(QCursor(loadIcon("HandC.xpm")));
break;
case modeMeasurementTool:
case modeEditGradientVectors:
case modeInsertPDFButton:
case modeInsertPDFTextfield:
case modeInsertPDFCheckbox:
case modeInsertPDFCombobox:
case modeInsertPDFListbox:
case modeInsertPDFTextAnnotation:
case modeInsertPDFLinkAnnotation:
qApp->changeOverrideCursor(QCursor(Qt::CrossCursor));
break;
default:
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
break;
}
}
}
void ScribusView::leaveEvent(QEvent *)
{
/* if (BlockLeave)
return; */
if (!m_MouseButtonPressed)
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
/* else
{
if ((SelItem.count() != 0) && (m_MouseButtonPressed) && (!doku->DragP) && (doku->appMode == 1))
{
PageItem *currItem = SelItem.at(0);
if ((b->Locked) || (b->Sizing))
return;
doku->DragP = true;
doku->leaveDrag = true;
doku->DraggedElem = b;
doku->DragElements.clear();
for (uint dre=0; dre<SelItem.count(); ++dre)
doku->DragElements.append(SelItem.at(dre)->ItemNr);
ScriXmlDoc *ss = new ScriXmlDoc();
QDragObject *dr = new QTextDrag(ss->WriteElem(&SelItem, doku), this);
dr->setPixmap(loadIcon("DragPix.xpm"));
dr->drag();
delete ss;
ss=NULL;
doku->DragP = false;
doku->leaveDrag = false;
m_MouseButtonPressed = false;
doku->DraggedElem = 0;
doku->DragElements.clear();
}
} */
}
void ScribusView::contentsDragEnterEvent(QDragEnterEvent *e)
{
QString text;
e->accept(Q3TextDrag::canDecode(e));
if (Q3TextDrag::decode(e, text))
{
double gx, gy, gw, gh;
/*<< #3524
setActiveWindow();
raise();
m_ScMW->newActWin(Doc->WinHan);
updateContents();
>>*/
// SeleItemPos(e->pos());
Q3Url ur(text);
QFileInfo fi = QFileInfo(ur.path());
ScriXmlDoc *ss = new ScriXmlDoc();
if (fi.exists())
text = ur.path();
if(ss->ReadElemHeader(text,fi.exists(), &gx, &gy, &gw, &gh))
{
dragX = e->pos().x() / Scale;
dragY = e->pos().y() / Scale;
dragW = gw;
dragH = gh;
DraggedGroup = true;
DraggedGroupFirst = true;
//GroupSel = false;
PaintSizeRect(QRect());
emit ItemGeom(gw, gh);
QPoint pv = QPoint(qRound(gx), qRound(gy));
PaintSizeRect(QRect(pv, QPoint(pv.x()+qRound(gw), pv.y()+qRound(gh))));
}
delete ss;
ss=NULL;
}
}
void ScribusView::contentsDragMoveEvent(QDragMoveEvent *e)
{
QString text;
// PageItem *currItem;
// bool img;
e->accept(Q3TextDrag::canDecode(e));
if (Q3TextDrag::decode(e, text))
{
if (DraggedGroup)
{
double gx, gy, gw, gh;
dragX = e->pos().x() / Scale;
dragY = e->pos().y() / Scale;
getDragRectScreen(&gx, &gy, &gw, &gh);
gx += Doc->minCanvasCoordinate.x();
gy += Doc->minCanvasCoordinate.y();
QPoint pv = QPoint(qRound(gx), qRound(gy));
if (!DraggedGroupFirst)
PaintSizeRect(QRect(pv, QPoint(pv.x()+qRound(gw), pv.y()+qRound(gh))));
DraggedGroupFirst = false;
emit MousePos(dragX+Doc->minCanvasCoordinate.x(), dragY+Doc->minCanvasCoordinate.y());
horizRuler->Draw(e->pos().x());
vertRuler->Draw(e->pos().y());
return;
}
/* QUrl ur(text);
QFileInfo fi = QFileInfo(ur.path());
QString ext = fi.extension(false).upper();
QStrList imfo = QImageIO::inputFormats();
if (ext == "JPG")
ext = "JPEG";
img = ((imfo.contains(ext))||(ext=="PS")||(ext=="EPS")||(ext=="TIF"));
if (!SeleItemPos(e->pos()))
{
if (SelItem.count() != 0)
Deselect(true);
}
else
{
b = SelItem.at(0);
if (img)
{
if (b->PType != 2)
Deselect(true);
}
else
{
if (b->PType != 4)
Deselect(true);
}
} */
}
}
void ScribusView::contentsDragLeaveEvent(QDragLeaveEvent *)
{
if (DraggedGroup)
{
updateContents();
DraggedGroup = false;
DraggedGroupFirst = false;
}
}
void ScribusView::contentsDropEvent(QDropEvent *e)
{
QString text;
PageItem *currItem;
bool img = false;
specialRendering = false;
firstSpecial = false;
// struct ScText *hg;
// uint a;
int re = 0;
e->accept(Q3TextDrag::canDecode(e));
DraggedGroupFirst = false;
int ex = qRound(e->pos().x()/Scale + Doc->minCanvasCoordinate.x());
int ey = qRound(e->pos().y()/Scale + Doc->minCanvasCoordinate.y());
if (Q3TextDrag::decode(e, text))
{
//<<#3524
setActiveWindow();
raise();
m_ScMW->newActWin(Doc->WinHan);
updateContents();
//>>
Q3Url ur(text);
QFileInfo fi = QFileInfo(ur.path());
QString ext = fi.extension(false).upper();
QStringList imfo;
QList<QByteArray> imgs = QImageReader::supportedImageFormats();
for (int i = 0; i < imgs.count(); ++i )
{
imfo.append(QString(imgs.at(i)));
}
if (ext == "JPG")
ext = "JPEG";
//CB Need to handle this ugly file extension list elsewhere... some capabilities class perhaps
img = ((imfo.contains(ext))||(ext=="PS")||(ext=="EPS")||(ext=="PDF")||(ext=="TIF")||(ext=="TIFF")||(ext=="PSD"));
bool selectedItemByDrag=false;
int pscx=qRound(e->pos().x()/Scale), pscy=qRound(e->pos().y()/Scale);
//Loop through all items and see which one(s) were under the drop point on the current layer
//Should make a nice function for this.
for (uint i=0; i<Doc->Items->count(); ++i)
{
if (Doc->Items->at(i)->LayerNr==Doc->activeLayer())
{
if (Doc->Items->at(i)->pointWithinItem(pscx, pscy))
{
Deselect(false);
SelectItem(Doc->Items->at(i));
selectedItemByDrag=true;
break;
}
}
}
//CB When we drag an image to a page from outside
//SeleItemPos is from 1.2.x. Needs reenabling for dragging *TO* a frame
if ((fi.exists()) && (img) && !selectedItemByDrag)// && (!SeleItemPos(e->pos())))
{
int z = Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, ex, ey, 1, 1, 1, Doc->toolSettings.dBrushPict, CommonStrings::None, true);
PageItem *b = Doc->Items->at(z);
Doc->LoadPict(ur.path(), b->ItemNr);
b->setWidth(static_cast<double>(b->OrigW * 72.0 / b->pixm.imgInfo.xres));
b->setHeight(static_cast<double>(b->OrigH * 72.0 / b->pixm.imgInfo.yres));
b->OldB2 = b->width();
b->OldH2 = b->height();
b->updateClip();
emit DocChanged();
update();
return;
}
//if ((SeleItemPos(e->pos())) && (!text.startsWith("<SCRIBUSELEM")))
if (Doc->m_Selection->count()>0 && Doc->m_Selection->itemAt(0)->pointWithinItem(pscx, pscy) && (!text.startsWith("<SCRIBUSELEM")))
{
PageItem *b = Doc->m_Selection->itemAt(0);
if (b->itemType() == PageItem::ImageFrame)
{
if ((fi.exists()) && (img))
{
Doc->LoadPict(ur.path(), b->ItemNr);
update();
}
}
/* CB leaving this out for now...
if (b->PType == 4)
{
if ((b->BackBox != 0) && (b->itemText.count() == 0))
return;
if ((fi.exists()) && (!img) && (fi.size() < 500000))
{
Serializer *ss = new Serializer(ur.path());
if (ss->Read())
{
int st = doku->currentParaStyle;
ss->GetText(b, st, doku->docParagraphStyles[st].Font, doku->docParagraphStyles[st].FontSize, true);
emit DocChanged();
}
delete ss;
ss=NULL;
update();
}
else
{
slotDoCurs(false);
slotSetCurs(e->pos().x(), e->pos().y());
if (text.startsWith("<SCRIBUSELEM"))
return;
for (a=0; a<text.length(); ++a)
{
hg = new ScText;
hg->ch = text.at(a);
if (hg->ch == QChar(10))
hg->ch = QChar(13);
if (hg->ch == QChar(4))
hg->ch = QChar(9);
if (hg->ch == QChar(5))
hg->ch = QChar(13);
hg->cfont = b->IFont;
hg->csize = b->ISize;
hg->ccolor = b->TxtFill;
hg->cshade = b->ShTxtFill;
hg->cstroke = b->TxtStroke;
hg->cshade2 = b->ShTxtStroke;
hg->cselect = false;
hg->cscale = b->TxtScale;
hg->cextra = 0;
hg->cstyle = 0;
hg->cab = 0;
hg->xp = 0;
hg->yp = 0;
hg->PRot = 0;
hg->PtransX = 0;
hg->PtransY = 0;
b->itemText.insert(b->CPos, hg);
b->CPos += 1;
}
emit DocChanged();
update();
}
}*/
}
else
{
for (uint as = 0; as < Doc->Items->count(); ++as)
{
Doc->Items->at(as)->setSelected(false);
}
uint oldDocItemCount = Doc->Items->count();
if ((!img) && (Doc->DraggedElem == 0))
{
undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::Create,"",Um::ICreate);
if ((fi.exists()) && (!img))
{
QString data;
if (fi.extension(true).lower() == "sml")
{
QString f = "";
loadText(ur.path(), &f);
StencilReader *pre = new StencilReader();
data = pre->createObjects(f);
delete pre;
emit LoadElem(data, ex, ey, false, false, Doc, this);
}
else if (fi.extension(true).lower() == "shape")
{
QString f = "";
loadText(ur.path(), &f);
StencilReader *pre = new StencilReader();
data = pre->createShape(f);
delete pre;
emit LoadElem(data, ex, ey, false, false, Doc, this);
}
else
emit LoadElem(ur.path(), ex, ey, true, false, Doc, this);
}
else
emit LoadElem(QString(text), ex, ey, false, false, Doc, this);
Doc->m_Selection->clear();
for (uint as = oldDocItemCount; as < Doc->Items->count(); ++as)
{
currItem = Doc->Items->at(as);
Doc->setRedrawBounding(currItem);
Doc->m_Selection->addItem(currItem, true);
if (currItem->isBookmark)
emit AddBM(currItem);
}
undoManager->commit();
}
else
{
if (Doc->DraggedElem != 0)
{
if (!Doc->leaveDrag)
{
Q3PopupMenu *pmen = new Q3PopupMenu();
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
pmen->insertItem( tr("Copy Here"));
int mov = pmen->insertItem( tr("Move Here"));
pmen->insertItem( tr("Cancel"));
for (int dre=0; dre<Doc->DragElements.count(); ++dre)
{
if (Doc->Items->at(Doc->DragElements[dre])->locked())
{
pmen->setItemEnabled(mov, false);
break;
}
}
re = pmen->indexOf(pmen->exec(QCursor::pos()));
delete pmen;
pmen=NULL;
}
else
re = 1;
if ((re == 2) || (re == -1))
{
updateContents();
return;
}
if ((re == 1) || (Doc->leaveDrag))
{
Q3PtrList<PageItem> pasted;
emit LoadElem(QString(text), ex, ey, false, false, Doc, this);
for (uint as = oldDocItemCount; as < Doc->Items->count(); ++as)
{
pasted.append(Doc->Items->at(as));
}
Doc->m_Selection->clear();
for (int dre=0; dre<Doc->DragElements.count(); ++dre)
{
Doc->m_Selection->addItem(Doc->Items->at(Doc->DragElements[dre]), true);
}
PageItem* bb;
int fin;
for (int dre=0; dre<Doc->DragElements.count(); ++dre)
{
bb = pasted.at(dre);
currItem = Doc->m_Selection->itemAt(dre);
if ((currItem->asTextFrame()) && ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0)))
{
PageItem* before = currItem->prevInChain();
PageItem* after = currItem->nextInChain();
currItem->unlink();
if (before != 0)
{
fin = Doc->m_Selection->findItem(before);
if (fin != -1)
before = pasted.at(fin);
before->unlink();
before->link(bb);
}
if (after != 0)
{
fin = Doc->m_Selection->findItem(after);
if (fin != -1)
after = pasted.at(fin);
bb->link(after);
}
}
}
/* for (uint dre=0; dre<Doc->DragElements.count(); ++dre)
{
currItem = Doc->m_Selection->itemAt(dre);
currItem->NextBox = 0;
currItem->BackBox = 0;
}
*/
pasted.clear();
Doc->itemSelection_DeleteItem();
}
}
if ((!img) && ((re == 0)))
emit LoadElem(QString(text), ex, ey, false, false, Doc, this);
Doc->DraggedElem = 0;
Doc->DragElements.clear();
Doc->m_Selection->clear();
for (uint as = oldDocItemCount; as < Doc->Items->count(); ++as)
{
currItem = Doc->Items->at(as);
Doc->setRedrawBounding(currItem);
Doc->m_Selection->addItem(currItem, true);
if (currItem->isBookmark)
emit AddBM(currItem);
}
}
if (Doc->m_Selection->count() > 1)
{
Doc->m_Selection->connectItemToGUI();
Doc->m_Selection->setGroupRect();
double gx, gy, gh, gw;
Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
double nx = gx;
double ny = gy;
if (!Doc->ApplyGuides(&nx, &ny))
{
FPoint npx;
npx = Doc->ApplyGridF(FPoint(nx, ny));
nx = npx.x();
ny = npx.y();
}
moveGroup(nx-gx, ny-gy, false);
Doc->m_Selection->setGroupRect();
Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
nx = gx+gw;
ny = gy+gh;
Doc->ApplyGuides(&nx, &ny);
moveGroup(nx-(gx+gw), ny-(gy+gh), false);
Doc->m_Selection->setGroupRect();
Doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
for (uint a = 0; a < Doc->m_Selection->count(); ++a)
{
PageItem *currItem = Doc->m_Selection->itemAt(a);
currItem->gXpos = currItem->xPos() - gx;
currItem->gYpos = currItem->yPos() - gy;
currItem->gWidth = gw;
currItem->gHeight = gh;
}
emit ItemPos(gx, gy);
emit ItemGeom(gw, gh);
}
else
{
Doc->m_Selection->connectItemToGUI();
currItem = Doc->m_Selection->itemAt(0);
if (Doc->useRaster)
{
double nx = currItem->xPos();
double ny = currItem->yPos();
if (!Doc->ApplyGuides(&nx, &ny))
{
FPoint npx;
npx = Doc->ApplyGridF(FPoint(nx, ny));
nx = npx.x();
ny = npx.y();
}
Doc->MoveItem(nx-currItem->xPos(), ny-currItem->yPos(), currItem);
}
}
updateContents();
}
if (!Doc->masterPageMode())
{
uint docPagesCount=Doc->Pages->count();
uint docCurrPageNo=Doc->currentPageNumber();
for (uint i = 0; i < docPagesCount; ++i)
{
int x = static_cast<int>(Doc->Pages->at(i)->xOffset());
int y = static_cast<int>(Doc->Pages->at(i)->yOffset());
int w = static_cast<int>(Doc->Pages->at(i)->width());
int h = static_cast<int>(Doc->Pages->at(i)->height());
if (QRect(x, y, w, h).contains(ex, ey))
{
if (docCurrPageNo != i)
{
Doc->setCurrentPage(Doc->Pages->at(i));
setMenTxt(i);
DrawNew();
}
break;
}
}
setRulerPos(contentsX(), contentsY());
}
}
}
void ScribusView::contentsMouseDoubleClickEvent(QMouseEvent *m)
{
m->accept();
m_MouseButtonPressed = false;
PageItem *currItem = 0;
if (Doc->EditClip)
{
emit EndNodeEdit();
return;
}
if ((Doc->m_Selection->isMultipleSelection()) || (Doc->appMode != modeNormal))
{
if ((Doc->m_Selection->isMultipleSelection()) && (Doc->appMode == modeNormal))
{
if (GetItem(&currItem))
{
if (currItem->isTableItem)
{
Deselect(false);
Doc->m_Selection->addItem(currItem);
currItem->isSingleSel = true;
//CB FIXME dont call this if the added item is item 0
if (!Doc->m_Selection->primarySelectionIs(currItem))
currItem->emitAllToGUI();
updateContents(currItem->getRedrawBounding(Scale));
}
}
return;
}
else
{
if (!(GetItem(&currItem) && (Doc->appMode == modeEdit) && currItem->asTextFrame()))
{
contentsMousePressEvent(m);
return;
}
}
}
if (GetItem(&currItem))
{
if ((currItem->itemType() == PageItem::Polygon) || (currItem->itemType() == PageItem::PolyLine) || (currItem->itemType() == PageItem::ImageFrame) || (currItem->itemType() == PageItem::PathText))
{
if ((currItem->locked()) || (!currItem->ScaleType))
{
contentsMousePressEvent(m);
return;
}
//If we double click on an image frame and theres no image assigned, open the
//load picture dialog, else put it into edit mode if the frame is set to show the image
if (currItem->itemType() == PageItem::ImageFrame)
{
if (currItem->Pfile.isEmpty())
emit LoadPic();
else if (currItem->imageShown())
emit Amode(modeEdit);
}
else
emit Amode(modeEdit);
}
else
if (currItem->itemType() == PageItem::TextFrame)
{
//CB old code
//emit currItem->isAnnotation() ? AnnotProps() : Amode(modeEdit);
//contentsMousePressEvent(m);
//CB if annotation, open the annotation dialog
if (currItem->isAnnotation())
{
emit AnnotProps();
contentsMousePressEvent(m);
}
//else if not in mode edit, set mode edit
else if (Doc->appMode != modeEdit)
{
emit Amode(modeEdit);
//CB ignore the double click and go with a single one
//if we werent in mode edit before.
//unsure if this is correct, but its ok given we had no
//double click select until now.
contentsMousePressEvent(m);
}
//otherwise, select between the whitespace
else
{ //Double click in a frame to select a word
PageItem_TextFrame *cItem=currItem->asTextFrame();
bool inText = slotSetCurs(m->x(), m->y());
if (!inText)
{
Deselect(true);
slotDoCurs(true);
emit Amode(modeNormal);
return;
}
int a=cItem->CPos;
while(a>0)
{
if (cItem->itemText.text(a-1).isLetterOrNumber())
--a;
else
break;
}
int b=cItem->CPos;
while(b<cItem->itemText.length())
{
if (cItem->itemText.text(b).isLetterOrNumber())
++b;
else
break;
}
oldCp = a;
cItem->CPos=b;
cItem->ExpandSel(1, oldCp);
slotDoCurs(true);
}
}
}
}
void ScribusView::normalizeSelectionRect()
{
if(Mxp > SeRx)
{
int tmp = SeRx;
SeRx = Mxp;
Mxp = tmp;
}
if(Myp > SeRy)
{
int tmp = SeRy;
SeRy = Myp;
Myp = tmp;
}
}
void ScribusView::contentsMouseReleaseEvent(QMouseEvent *m)
{
PageItem *currItem;
m_MouseButtonPressed = false;
specialRendering = false;
firstSpecial = false;
m->accept();
dragTimer->stop();
if (Doc->appMode == modeNormal && Doc->guidesSettings.guidesShown)
{
bool foundGuide = false;
double nx = translateToDoc(m->x(), m->y()).x();
double ny = translateToDoc(m->x(), m->y()).y();
double grabRadScale=Doc->guidesSettings.grabRad / Scale;
if (Doc->currentPage()->guides.isMouseOnHorizontal(ny + grabRadScale, ny - grabRadScale, GuideManagerCore::Standard)
|| Doc->currentPage()->guides.isMouseOnVertical(nx + grabRadScale, nx - grabRadScale, GuideManagerCore::Standard))
foundGuide = true;
if ((foundGuide) && (m->button() == Qt::RightButton) && (!GetItem(&currItem)))
{
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
MoveGY = false;
MoveGX = false;
return;
}
if (MoveGY)
{
SetYGuide(m, GyM);
MoveGY = false;
redrawMarker->hide();
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
updateContents();
GyM = -1;
return;
}
if (MoveGX)
{
SetXGuide(m, GxM);
MoveGX = false;
redrawMarker->hide();
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
updateContents();
GxM = -1;
return;
}
}
if (Doc->appMode == modeEditGradientVectors)
return;
if (Doc->appMode == modeCopyProperties)
return;
if (Doc->appMode == modeMeasurementTool)
{
redrawPolygon.clear();
updateContents(QRect(QPoint(Dxp, Dyp), QPoint(Mxp, Mxp)).normalized().adjusted(-10, -10, 20, 20));
// qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
//emit PaintingDone();
return;
}
if (Doc->appMode == modePanning)
{
if ((m->state() & Qt::RightButton) && (m->state() & Qt::ControlButton))
{
m_ScMW->setAppMode(modeNormal);
}
return;
}
if (Doc->appMode == modeDrawTable)
{
if ((Doc->m_Selection->count() == 0) && (HaveSelRect) && (!MidButt))
{
QRect AreaR = QRect(static_cast<int>(Mxp), static_cast<int>(Myp), static_cast<int>(SeRx-Mxp), static_cast<int>(SeRy-Myp)).normalized();
HaveSelRect = false;
double Tx, Ty, Tw, Th;
FPoint np2 = Doc->ApplyGrid(QPoint(Mxp, Myp));
Tx = np2.x();
Ty = np2.y();
Doc->ApplyGuides(&Tx, &Ty);
Mxp = qRound(Tx);
Myp = qRound(Ty);
np2 = Doc->ApplyGrid(QPoint(SeRx, SeRy));
Tw = np2.x();
Th = np2.y();
Doc->ApplyGuides(&Tw, &Th);
SeRx = qRound(Tw);
SeRy = qRound(Th);
Tw = Tw - Tx;
Th = Th - Ty;
int z;
int Cols, Rows;
double deltaX, deltaY, offX, offY;
if ((Th < 6) || (Tw < 6))
{
redrawMarker->hide();
Doc->appMode = modeNormal;
emit PaintingDone();
return;
}
InsertTable *dia = new InsertTable(this, static_cast<int>(Th / 6), static_cast<int>(Tw / 6));
if (!dia->exec())
{
redrawMarker->hide();
Doc->appMode = modeNormal;
emit PaintingDone();
delete dia;
dia=NULL;
return;
}
redrawMarker->hide();
Cols = dia->Cols->value();
Rows = dia->Rows->value();
delete dia;
dia=NULL;
deltaX = Tw / Cols;
deltaY = Th / Rows;
offX = 0.0;
offY = 0.0;
Doc->m_Selection->clear();
if (UndoManager::undoEnabled())
undoManager->beginTransaction(Doc->currentPage()->getUName(),
Um::ITable, Um::CreateTable,
QString(Um::RowsCols).arg(Rows).arg(Cols),
Um::ICreate);
for (int rc = 0; rc < Rows; ++rc)
{
for (int cc = 0; cc < Cols; ++cc)
{
//z = PaintText(Tx + offX, Ty + offY, deltaX, deltaY, Doc->toolSettings.dWidth, Doc->toolSettings.dPenText);
z = Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, Tx + offX, Ty + offY, deltaX, deltaY, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenText, !m_MouseButtonPressed);
currItem = Doc->Items->at(z);
currItem->isTableItem = true;
//currItem->setTextFlowsAroundFrame(true);
//currItem->setTextFlowUsesBoundingBox(true);
currItem->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
Doc->m_Selection->addItem(currItem);
offX += deltaX;
}
offY += deltaY;
offX = 0.0;
}
for (int rc = 0; rc < Rows; ++rc)
{
for (int cc = 0; cc < Cols; ++cc)
{
currItem = Doc->m_Selection->itemAt((rc * Cols) + cc);
if (rc == 0)
currItem->TopLink = 0;
else
currItem->TopLink = Doc->m_Selection->itemAt(((rc-1)*Cols)+cc);
if (rc == Rows-1)
currItem->BottomLink = 0;
else
currItem->BottomLink = Doc->m_Selection->itemAt(((rc+1)*Cols)+cc);
if (cc == 0)
currItem->LeftLink = 0;
else
currItem->LeftLink = Doc->m_Selection->itemAt((rc*Cols)+cc-1);
if (cc == Cols-1)
currItem->RightLink = 0;
else
currItem->RightLink = Doc->m_Selection->itemAt((rc*Cols)+cc+1);
}
}
emit DoGroup();
if (UndoManager::undoEnabled())
undoManager->commit();
}
if (!Prefs->stickyTools)
{
Doc->appMode = modeNormal;
emit PaintingDone();
}
else
emit Amode(Doc->appMode);
emit DocChanged();
updateContents();
return;
}
if (Doc->appMode == modeDrawFreehandLine)
{
if (RecordP.size() > 1)
{
uint z = Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Mxp, Myp, 1, 1, Doc->toolSettings.dWidth, CommonStrings::None, Doc->toolSettings.dPenLine, !m_MouseButtonPressed);
currItem = Doc->Items->at(z);
currItem->PoLine.resize(0);
currItem->PoLine.addPoint(RecordP.point(0));
currItem->PoLine.addPoint(RecordP.point(0));
for (uint px = 1; px < RecordP.size()-1; ++px)
{
currItem->PoLine.addPoint(RecordP.point(px));
currItem->PoLine.addPoint(RecordP.point(px));
currItem->PoLine.addPoint(RecordP.point(px));
currItem->PoLine.addPoint(RecordP.point(px));
}
currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
FPoint tp2(getMinClipF(&currItem->PoLine));
currItem->setXYPos(tp2.x(), tp2.y(), true);
currItem->PoLine.translate(-tp2.x(), -tp2.y());
FPoint tp(getMaxClipF(&currItem->PoLine));
Doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
Doc->AdjustItemSize(currItem);
Doc->m_Selection->clear();
Doc->m_Selection->addItem(currItem);
currItem->ClipEdited = true;
currItem->FrameType = 3;
currItem->OwnPage = Doc->OnPage(currItem);
operItemMoving = false;
operItemResizing = false;
inItemCreation = false;
updateContents(currItem->getRedrawBounding(Scale).adjusted(-10, -10, 20, 20));
}
if (!Prefs->stickyTools)
{
Doc->appMode = modeNormal;
emit PaintingDone();
}
else
emit Amode(Doc->appMode);
emit DocChanged();
return;
}
if ((Doc->EditClip) && (ClRe == -1) && (HaveSelRect))
{
double sc = Scale;
currItem = Doc->m_Selection->itemAt(0);
SelNode.clear();
QRect Sele = QRect(Dxp, Dyp, SeRx-Dxp, SeRy-Dyp).normalized();
FPointArray Clip;
Scale = 1.0;
if (EditContour)
Clip = currItem->ContourLine;
else
Clip = currItem->PoLine;
for (uint a = 0; a < Clip.size(); ++a)
{
if (Clip.point(a).x() > 900000)
continue;
FPoint np = Clip.point(a);
FPoint npf2 = np.transformPoint(currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0, false);
QPoint npf = QPoint(qRound(npf2.x()), qRound(npf2.y()));
if ((Sele.contains(npf)) && ((a == 0) || (((a-2) % 4) == 0)))
{
ClRe = a;
SelNode.append(a);
emit ClipPo(Clip.point(a).x(), Clip.point(a).y());
}
}
Scale = sc;
HaveSelRect = false;
redrawMarker->hide();
RefreshItem(currItem);
if (oldClip) // is there the old clip stored for the undo action
{
FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
if (*oldClip != newClip)
{
QString name = isContourLine ? Um::EditContour : Um::EditShape;
ItemState<QPair<FPointArray, FPointArray> > *state =
new ItemState<QPair<FPointArray, FPointArray> >(name);
state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
state->set("IS_CONTOUR", isContourLine);
state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
state->set("OLD_X", oldItemX);
state->set("OLD_Y", oldItemY);
state->set("NEW_X", currItem->xPos());
state->set("NEW_Y", currItem->yPos());
undoManager->action(currItem, state);
undoManager->commit();
}
else
undoManager->cancelTransaction();
delete oldClip;
oldClip = 0;
}
m_SnapCounter = 0;
return;
}
/* if (moveTimerElapsed() && (Doc->EditClip) && (SegP1 == -1) && (SegP2 == -1))
{
currItem = Doc->m_Selection->itemAt(0);
if (operItemMoving)
{
currItem->OldB2 = currItem->width();
currItem->OldH2 = currItem->height();
double nx = m->x()/Scale + Doc->minCanvasCoordinate.x();
double ny = m->y()/Scale + Doc->minCanvasCoordinate.y();
if (!Doc->ApplyGuides(&nx, &ny))
{
FPoint npg(ApplyGridF(FPoint(nx, ny)));
nx = npg.x();
ny = npg.y();
}
FPoint np(nx, ny, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
MoveClipPoint(currItem, np);
}
Doc->AdjustItemSize(currItem);
emit DocChanged();
updateContents();
operItemMoving = false;
return;
}
if (moveTimerElapsed() && (Doc->EditClip) && (SegP1 != -1) && (SegP2 != -1)) */
if (moveTimerElapsed() && (Doc->EditClip))
{
dragTimer->stop();
SegP1 = -1;
SegP2 = -1;
currItem = Doc->m_Selection->itemAt(0);
operItemMoving = false;
double xposOrig = currItem->xPos();
double yposOrig = currItem->yPos();
ItemState<QPair<FPointArray, FPointArray> > *state = NULL;
if (oldClip) // is there the old clip stored for the undo action
{
FPointArray newClip(isContourLine ? currItem->ContourLine : currItem->PoLine);
if (*oldClip != newClip)
{
QString name = isContourLine ? Um::EditContour : Um::EditShape;
state = new ItemState<QPair<FPointArray, FPointArray> >(name);
state->set("EDIT_SHAPE_OR_CONTOUR", "edit_shape_or_contour");
state->set("IS_CONTOUR", isContourLine);
state->setItem(QPair<FPointArray, FPointArray>(*oldClip, newClip));
undoManager->setUndoEnabled(false);
}
else
{
delete oldClip;
oldClip = 0;
undoManager->cancelTransaction();
}
}
xposOrig = currItem->xPos();
yposOrig = currItem->yPos();
if (ClRe != -1)
{
double newX = m->x();
double newY = m->y();
FPoint np(newX-Mxp, newY-Myp, 0, 0, currItem->rotation(), 1, 1, true);
currItem->OldB2 = currItem->width();
currItem->OldH2 = currItem->height();
FPointArray Clip;
if (EditContour)
Clip = currItem->ContourLine;
else
Clip = currItem->PoLine;
FPoint npf = FPoint(Clip.point(ClRe).x() + np.x() / Scale, Clip.point(ClRe).y() + np.y() / Scale);
double nx = npf.x();
double ny = npf.y();
nx += currItem->xPos();
ny += currItem->yPos();
if (!Doc->ApplyGuides(&nx, &ny))
npf = Doc->ApplyGridF(FPoint(nx, ny));
else
npf = FPoint(nx, ny);
npf = FPoint(npf.x() - currItem->xPos(), npf.y() - currItem->yPos());
MoveClipPoint(currItem, npf);
}
Doc->AdjustItemSize(currItem);
if (!EditContour)
currItem->ContourLine.translate(xposOrig - currItem->xPos(),yposOrig - currItem->yPos());
emit DocChanged();
updateContents();
if (oldClip)
{
state->set("OLD_X", oldItemX);
state->set("OLD_Y", oldItemY);
state->set("NEW_X", currItem->xPos());
state->set("NEW_Y", currItem->yPos());
undoManager->setUndoEnabled(true);
undoManager->action(currItem, state);
undoManager->commit();
delete oldClip;
oldClip = 0;
}
m_SnapCounter = 0;
return;
}
if ((!GetItem(&currItem)) && (m->button() == Qt::RightButton) && (!Doc->DragP) && (Doc->appMode == modeNormal))
{
Q3PopupMenu *pmen = new Q3PopupMenu();
if ((m_ScMW->Buffer2.startsWith("<SCRIBUSELEM")) || (m_ScMW->Buffer2.contains("<SCRIBUSFRAGMENT")) || (m_ScMW->scrapbookPalette->tempBView->objectMap.count() > 0))
{
Mxp = m->x();
Myp = m->y();
if ((m_ScMW->Buffer2.startsWith("<SCRIBUSELEM")) || (m_ScMW->Buffer2.contains("<SCRIBUSFRAGMENT")))
pmen->insertItem( tr("&Paste") , this, SLOT(PasteToPage()));
if (m_ScMW->scrapbookPalette->tempBView->objectMap.count() > 0)
{
pmen3 = new Q3PopupMenu();
QMap<QString,BibView::Elem>::Iterator it;
it = m_ScMW->scrapbookPalette->tempBView->objectMap.end();
it--;
for (int m = 0; m < m_ScMW->scrapbookPalette->tempBView->objectMap.count(); ++m)
{
QString strippedName = it.key();
QPixmap pm = it.data().Preview;
// Qt4 pmen3->insertItem(pm, strippedName);
pmen3->addAction(pm, strippedName);
it--;
}
connect(pmen3, SIGNAL(activated(int)), this, SLOT(PasteRecentToPage(int)));
pmen->insertItem( tr("Paste Recent"), pmen3);
}
pmen->insertSeparator();
}
setObjectUndoMode();
m_ScMW->scrActions["editUndoAction"]->addTo(pmen);
m_ScMW->scrActions["editRedoAction"]->addTo(pmen);
pmen->insertSeparator();
m_ScMW->scrActions["viewShowMargins"]->addTo(pmen);
m_ScMW->scrActions["viewShowFrames"]->addTo(pmen);
m_ScMW->scrActions["viewShowLayerMarkers"]->addTo(pmen);
m_ScMW->scrActions["viewShowImages"]->addTo(pmen);
m_ScMW->scrActions["viewShowGrid"]->addTo(pmen);
m_ScMW->scrActions["viewShowGuides"]->addTo(pmen);
m_ScMW->scrActions["viewShowBaseline"]->addTo(pmen);
m_ScMW->scrActions["viewShowTextChain"]->addTo(pmen);
m_ScMW->scrActions["viewRulerMode"]->addTo(pmen);
pmen->insertSeparator();
m_ScMW->scrActions["viewSnapToGrid"]->addTo(pmen);
m_ScMW->scrActions["viewSnapToGuides"]->addTo(pmen);
int pgNum = -1;
int docPageCount = static_cast<int>(Doc->Pages->count() - 1);
double bleedRight = 0.0;
double bleedLeft = 0.0;
double bleedBottom = 0.0;
double bleedTop = 0.0;
bool drawBleed = false;
int x2 = static_cast<int>(translateToDoc(m->x(), m->y()).x());
int y2 = static_cast<int>(translateToDoc(m->x(), m->y()).y());
if (((Doc->bleeds.Bottom != 0.0) || (Doc->bleeds.Top != 0.0) || (Doc->bleeds.Left != 0.0) || (Doc->bleeds.Right != 0.0)) && (Doc->guidesSettings.showBleed))
drawBleed = true;
for (int a = docPageCount; a > -1; a--)
{
if (drawBleed)
Doc->getBleeds(a, &bleedTop, &bleedBottom, &bleedLeft, &bleedRight);
int x = static_cast<int>(Doc->Pages->at(a)->xOffset() - bleedLeft);
int y = static_cast<int>(Doc->Pages->at(a)->yOffset() - bleedTop);
int w = static_cast<int>(Doc->Pages->at(a)->width() + bleedLeft + bleedRight);
int h = static_cast<int>(Doc->Pages->at(a)->height() + bleedBottom + bleedTop);
if (QRect(x, y, w, h).contains(x2, y2))
{
pgNum = static_cast<int>(a);
if (drawBleed) // check again if its really on the correct page
{
for (int a2 = docPageCount; a2 > -1; a2--)
{
int xn = static_cast<int>(Doc->Pages->at(a2)->xOffset());
int yn = static_cast<int>(Doc->Pages->at(a2)->yOffset());
int wn = static_cast<int>(Doc->Pages->at(a2)->width());
int hn = static_cast<int>(Doc->Pages->at(a2)->height());
if (QRect(xn, yn, wn, hn).contains(x2, y2))
{
pgNum = static_cast<int>(a2);
break;
}
}
}
break;
}
}
if (pgNum != -1)
{
pmen->insertSeparator();
m_ScMW->scrActions["pageApplyMasterPage"]->addTo(pmen);
m_ScMW->scrActions["pageManageGuides"]->addTo(pmen);
m_ScMW->scrActions["pageManageMargins"]->addTo(pmen);
pmen->insertSeparator();
m_ScMW->scrActions["pageDelete"]->addTo(pmen);
}
pmen->exec(QCursor::pos());
setGlobalUndoMode();
delete pmen;
pmen=NULL;
if (m_ScMW->scrapbookPalette->tempBView->objectMap.count() > 0)
{
delete pmen3;
pmen3=NULL;
}
return;
}
if ((Doc->appMode != modeMagnifier) && (!Doc->EditClip) && (Doc->appMode != modeDrawBezierLine))
{
if ((GetItem(&currItem)) && (m->button() == Qt::RightButton) && (!Doc->DragP))
{
Q3PopupMenu *pmen = new Q3PopupMenu();
Q3PopupMenu *pmen2 = new Q3PopupMenu();
pmen3 = new Q3PopupMenu();
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
QMenu *pmen4 = new QMenu();
Q3PopupMenu *pmenEditContents = new Q3PopupMenu();
Q3PopupMenu *pmenLevel = new Q3PopupMenu();
Q3PopupMenu *pmenPDF = new Q3PopupMenu();
pmenResolution = new Q3PopupMenu();
setObjectUndoMode();
if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::ImageFrame) || (currItem->itemType() == PageItem::PathText))
{
Q3ButtonGroup *InfoGroup = new Q3ButtonGroup( this, "InfoGroup" );
InfoGroup->setFrameShape( Q3ButtonGroup::NoFrame );
InfoGroup->setFrameShadow( Q3ButtonGroup::Plain );
InfoGroup->setTitle("");
InfoGroup->setExclusive( true );
InfoGroup->setColumnLayout(0, Qt::Vertical );
InfoGroup->layout()->setSpacing( 0 );
InfoGroup->layout()->setMargin( 0 );
Q3GridLayout *InfoGroupLayout = new Q3GridLayout( InfoGroup->layout() );
InfoGroupLayout->setAlignment( Qt::AlignTop );
InfoGroupLayout->setSpacing( 2 );
InfoGroupLayout->setMargin( 0 );
QString txtC, txtC2;
QLabel *InfoT = new QLabel(InfoGroup, "ct");
QLabel *LinCT = new QLabel(InfoGroup, "lt");
QLabel *LinC = new QLabel(InfoGroup, "lc");
QLabel *ParCT = new QLabel(InfoGroup, "pt");
QLabel *ParC = new QLabel(InfoGroup, "pc");
QLabel *WordCT = new QLabel(InfoGroup, "wt");
QLabel *WordC = new QLabel(InfoGroup, "wc");
QLabel *CharCT = new QLabel(InfoGroup, "ct");
QLabel *CharC = new QLabel(InfoGroup, "cc");
QLabel *ColCT = new QLabel(InfoGroup, "ct");
QLabel *ColC = new QLabel(InfoGroup, "cc");
QLabel *PrintCT = new QLabel(InfoGroup, "nt"); // <a.l.e>
QLabel *PrintC = new QLabel(InfoGroup, "nc"); // </a.l.e>
if (currItem->itemType() == PageItem::ImageFrame)
{
LinC->hide();
LinCT->hide();
if (currItem->PicAvail)
{
QFileInfo fi = QFileInfo(currItem->Pfile);
InfoT->setText( tr("Picture"));
InfoGroupLayout->addMultiCellWidget( InfoT, 0, 0, 0, 1, Qt::AlignHCenter );
ParCT->setText( tr("File: "));
InfoGroupLayout->addWidget( ParCT, 1, 0, Qt::AlignRight );
ParC->setText(fi.fileName());
InfoGroupLayout->addWidget( ParC, 1, 1 );
WordCT->setText( tr("Original PPI: "));
InfoGroupLayout->addWidget( WordCT, 2, 0, Qt::AlignRight );
WordC->setText(txtC.setNum(qRound(currItem->pixm.imgInfo.xres))+" x "+txtC2.setNum(qRound(currItem->pixm.imgInfo.yres)));
InfoGroupLayout->addWidget( WordC, 2, 1 );
CharCT->setText( tr("Actual PPI: "));
InfoGroupLayout->addWidget( CharCT, 3, 0, Qt::AlignRight );
CharC->setText(txtC.setNum(qRound(72.0 / currItem->imageXScale()))+" x "+ txtC2.setNum(qRound(72.0 / currItem->imageYScale())));
InfoGroupLayout->addWidget( CharC, 3, 1 );
ColCT->setText( tr("Colorspace: "));
InfoGroupLayout->addWidget( ColCT, 4, 0, Qt::AlignRight );
QString cSpace;
QString ext = fi.extension(false).lower();
if (((ext == "pdf") || (ext == "eps") || (ext == "epsi") || (ext == "ps")) && (currItem->pixm.imgInfo.type != 7))
cSpace = tr("Unknown");
else
{
switch (currItem->pixm.imgInfo.colorspace)
{
case 0:
cSpace = tr("RGB");
break;
case 1:
cSpace = tr("CMYK");
break;
case 2:
cSpace = tr("Grayscale");
break;
case 3:
cSpace = tr("Duotone");
break;
}
}
ColC->setText(cSpace);
InfoGroupLayout->addWidget( ColC, 4, 1 );
}
else
{
InfoT->setText( tr("Picture"));
InfoGroupLayout->addMultiCellWidget( InfoT, 0, 0, 0, 1, Qt::AlignHCenter );
ParCT->setText( tr("No Image Loaded"));
InfoGroupLayout->addMultiCellWidget( ParCT, 1, 1, 0, 1, Qt::AlignHCenter );
ParC->hide();
WordCT->hide();
WordC->hide();
CharCT->hide();
CharC->hide();
ColCT->hide();
ColC->hide();
}
}
if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
{
int Parag = 0;
int Words = 0;
int Chara = 0;
int ParagN = 0;
int WordsN = 0;
int CharaN = 0;
ColC->hide();
ColCT->hide();
if (currItem->itemType() == PageItem::TextFrame)
{
if ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0))
InfoT->setText( tr("Linked Text"));
else
InfoT->setText( tr("Text Frame"));
}
else
InfoT->setText( tr("Text on a Path"));
InfoGroupLayout->addMultiCellWidget( InfoT, 0, 0, 0, 1, Qt::AlignCenter );
WordAndPara(currItem, &Words, &Parag, &Chara, &WordsN, &ParagN, &CharaN);
ParCT->setText( tr("Paragraphs: "));
InfoGroupLayout->addWidget( ParCT, 1, 0, Qt::AlignRight );
if (ParagN != 0)
ParC->setText(txtC.setNum(Parag+ParagN)+" ("+txtC2.setNum(ParagN)+")");
else
ParC->setText(txtC.setNum(Parag));
InfoGroupLayout->addWidget( ParC, 1, 1 );
LinCT->setText( tr("Lines: "));
InfoGroupLayout->addWidget( LinCT, 2, 0, Qt::AlignRight );
LinC->setText(txtC.setNum(currItem->itemText.lines()));
InfoGroupLayout->addWidget( LinC, 2, 1 );
WordCT->setText( tr("Words: "));
InfoGroupLayout->addWidget( WordCT, 3, 0, Qt::AlignRight );
if (WordsN != 0)
WordC->setText(txtC.setNum(Words+WordsN)+" ("+txtC2.setNum(WordsN)+")");
else
WordC->setText(txtC.setNum(Words));