Example #1
0
Selection Serializer::importCollection()
{
	Collection* coll = lookup<Collection>("<collection>");
	Selection result( &m_Doc, false);
//	qDebug() << QString("deserialize: collection %1 doc %2").arg((ulong)coll).arg((ulong)&m_Doc);
	if (coll == NULL)
		qDebug() << "deserialize: no objects collected";
	else
	{
		QMap<QString,QString> newNames;

		//TODO: fonts

		do {
			newNames.clear();
			for (int i = 0; i < coll->cstyles.count(); ++i)
			{
				QString oldName = coll->cstyles[i].name();
				int oldIndex = m_Doc.charStyles().find(oldName);
				if (oldIndex >= 0 && m_Doc.charStyle(oldName) == coll->cstyles[i])
					continue;
				QString newName = oldName;
				if (oldIndex >= 0 && !newNames.contains(oldName))
				{
					int counter = 0;
					while (m_Doc.charStyles().find(newName) >= 0)
						newName = (QObject::tr("Copy of %1 (%2)")).arg(oldName).arg(++counter);
					newNames[oldName] = newName;
				}
			}
			
			coll->cstyles.rename(newNames);
		}
		while (newNames.count() > 0);
		m_Doc.redefineCharStyles(coll->cstyles, false);		

		do {
			newNames.clear();
			for (int i = 0; i < coll->pstyles.count(); ++i)  // FIXME:  QValueList<QString> StyleSet::names()
			{
				QString oldName = coll->pstyles[i].name();
				int oldIndex = m_Doc.paragraphStyles().find(oldName);
//				qDebug() << QString("comparing %1 (old %2 new %3): parent '%4'='%5' cstyle %6 equiv %7").arg(oldName).arg(oldIndex).arg(i)
//					   .arg(oldIndex>=0? m_Doc.paragraphStyle(oldName).parent() : "?").arg(coll->pstyles[i].parent())
//					   .arg(oldIndex>=0? m_Doc.paragraphStyle(oldName).charStyle() == coll->pstyles[i].charStyle() : false)
//					   .arg(oldIndex>=0? m_Doc.paragraphStyle(oldName).equiv(coll->pstyles[i]) : false);
			
				if (oldIndex >= 0 && coll->pstyles[i] == m_Doc.paragraphStyle(oldName) )
					continue;
				QString newName = oldName;
				if (oldIndex >= 0 && !newNames.contains(oldName))
				{
					int counter = 0;
					while (m_Doc.paragraphStyles().find(newName) >= 0)
						newName = (QObject::tr("Copy of %1 (%2)")).arg(oldName).arg(++counter);
					newNames[oldName] = newName;
				}
			}
			coll->pstyles.rename(newNames);
		}
		while(newNames.count() > 0);
		
		m_Doc.redefineStyles(coll->pstyles, false);		

		//TODO: linestyles : this is temporary code until MultiLine is replaced by LineStyle
		QMap<QString,multiLine>::Iterator mlit;
		for (mlit = coll->lstyles.begin(); mlit != coll->lstyles.end(); ++mlit)
		{
			multiLine& ml = mlit.value();
			QString    oldName = mlit.key();
			QString    newName = mlit.key();
			QMap<QString,multiLine>::ConstIterator mlitd = m_Doc.MLineStyles.find(oldName);
			if (mlitd != m_Doc.MLineStyles.end() && ml != mlitd.value())
			{
				int counter = 0;
				while (m_Doc.MLineStyles.contains(newName))
					newName = (QObject::tr("Copy of %1 (%2)")).arg(oldName).arg(++counter);
			}
			m_Doc.MLineStyles.insert(newName, ml);
		}

		//TODO: patterns
		
		QList<PageItem*>* objects = &(coll->items);
		m_Doc.PageColors = backUpColors;
		m_Doc.PageColors.addColors(coll->colors, false);
		int maxG = m_Doc.GroupCounter;
		for (int i=0; i < objects->count(); ++i)
		{
			PageItem* currItem = objects->at(i);
			currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
			currItem->setFillQColor();
			currItem->setLineQColor();
			result.addItem(currItem);
			if (currItem->Groups.count() != 0)
			{
				QStack<int> groups;
				for (int i=0; i < currItem->groups().count(); ++i)
				{
					int newGroup = m_Doc.GroupCounter + currItem->groups()[i] - 1;
					groups.append(newGroup);
				}
				currItem->setGroups(groups);
				maxG = qMax(maxG, currItem->Groups.top()+1);
			}
		}
		m_Doc.GroupCounter = maxG;
		updateGradientColors(coll->colors);
		delete coll;
	}
	return result;
}
Example #2
0
void BezierMode::mousePressEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	
	int z;
	double Rxp = 0;
	double Ryp = 0;
	double Rxpd = 0;
	double Rypd = 0;
	PageItem *currItem;
//	m_canvas->PaintSizeRect(QRect());
	FPoint npf, npf2;
	QRect tx;
	QTransform pm;
	m_MouseButtonPressed = true;
	m_view->HaveSelRect = false;
	m_doc->DragP = false;
	m_doc->leaveDrag = false;
	MoveGX = MoveGY = false;
//	inItemCreation = false;
//	oldClip = 0;
	m->accept();
	m_view->registerMousePress(m->globalPos());
	Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
	Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
	QRect mpo(m->x()-m_doc->guidesPrefs().grabRadius, m->y()-m_doc->guidesPrefs().grabRadius, m_doc->guidesPrefs().grabRadius*2, m_doc->guidesPrefs().grabRadius*2);
//	mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
	Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
	Rxpd = Mxp - Rxp;
	Mxp = qRound(Rxp);
	Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
	Rypd = Myp - Ryp;
	Myp = qRound(Ryp);
	SeRx = Mxp;
	SeRy = Myp;
	if (m->button() == Qt::MidButton)
	{
		m_view->MidButt = true;
		if (m->modifiers() & Qt::ControlModifier)
			m_view->DrawNew();
		return;
	}
	if (m->button() == Qt::RightButton)
	{
		m_view->stopGesture();
		return;
	}
	if (FirstPoly)
	{
		selectPage(m);
		m_createTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction());
		z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, m_doc->itemToolPrefs().lineWidth, CommonStrings::None, m_doc->itemToolPrefs().lineColor, true);
		currItem = m_doc->Items->at(z);
		m_doc->m_Selection->clear();
		m_doc->m_Selection->addItem(currItem);
		qApp->changeOverrideCursor(QCursor(Qt::CrossCursor));
		m_canvas->setRenderModeFillBuffer();
		inItemCreation = true;
	}
	currItem = m_doc->m_Selection->itemAt(0);
	//			pm.translate(-m_doc->minCanvasCoordinate.x()*m_canvas->scale(), -m_doc->minCanvasCoordinate.y()*m_canvas->scale());
	pm = currItem->getTransform();
	npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true);
	currItem->PoLine.addPoint(npf);
	npf2 = getMinClipF(&currItem->PoLine);
	if (npf2.x() < 0)
	{
		currItem->PoLine.translate(-npf2.x(), 0);
		m_doc->MoveItem(npf2.x(), 0, currItem);
	}
	if (npf2.y() < 0)
	{
		currItem->PoLine.translate(0, -npf2.y());
		m_doc->MoveItem(0, npf2.y(), currItem);
	}
	m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
	currItem->setPolyClip(qRound(qMax(currItem->lineWidth() / 2, 1.0)));
	m_canvas->newRedrawPolygon();
}
Example #3
0
void gtAction::write(const QString& text, gtStyle *style)
{
	if (isFirstWrite)
	{
		if (!doAppend)
		{
			if (it->nextInChain() != 0)
			{
				PageItem *nextItem = it->nextInChain();
				while (nextItem != 0)
				{
					nextItem->itemText.clear();
					nextItem = nextItem->nextInChain();
				}
			}
			it->itemText.clear();
		}
	}
	int paragraphStyle = -1;
	if (style->target() == "paragraph")
	{
		gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style);
		assert(pstyle != NULL);
		paragraphStyle = applyParagraphStyle(pstyle);
		if (isFirstWrite)
			inPara = true;
	}
	else if (style->target() == "frame")
	{
		gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style);
		assert(fstyle != NULL);
		applyFrameStyle(fstyle);
	}

	if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1))
		paragraphStyle = lastParagraphStyle;

	if (paragraphStyle == -1)
		paragraphStyle = 0; //::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle);

	const ParagraphStyle& paraStyle = textFrame->doc()->paragraphStyles()[paragraphStyle];

	gtFont* font = style->getFont();
	QString fontName = validateFont(font).scName();
	CharStyle lastStyle, newStyle;
	int lastStyleStart = 0;
	
	if ((inPara) && (!overridePStyleFont))
	{
		if (paraStyle.charStyle().font().isNone())
		{
			gtFont font2(*font);
			font2.setName(paraStyle.charStyle().font().scName());
			QString fontName2 = validateFont(&font2).scName();
			newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]);
		}
	}
	else
	{
		setCharStyleAttributes(font, newStyle);
	}
	/*newStyle.eraseCharStyle(paraStyle.charStyle());*/

	lastStyle = newStyle;
	lastStyleStart = it->itemText.length();

	QChar ch0(0), ch5(5), ch10(10), ch13(13);
	for (int a = 0; a < text.length(); ++a)
	{
		if ((text.at(a) == ch0) || (text.at(a) == ch13))
			continue;
		QChar ch = text.at(a);
		if ((ch == ch10) || (ch == ch5))
			ch = ch13;
		else if (ch.unicode() == 0x2028)
			ch = SpecialChars::LINEBREAK;
		else if (ch.unicode() == 0x2029)
			ch = SpecialChars::PARSEP;
		
		int pos = it->itemText.length();
		it->itemText.insertChars(pos, QString(ch));
		if (ch == SpecialChars::PARSEP) 
		{
			if (paraStyle.hasName())
			{
				ParagraphStyle pstyle;
				pstyle.setParent(paraStyle.name());
				it->itemText.applyStyle(pos, pstyle);
			}
			else
				it->itemText.applyStyle(pos, paraStyle);
		}
	}
	it->itemText.applyCharStyle(lastStyleStart, it->itemText.length()-lastStyleStart, lastStyle);
	if (paraStyle.hasName())
	{
		ParagraphStyle pStyle;
		pStyle.setParent(paraStyle.name());
		it->itemText.applyStyle(qMax(0,it->itemText.length()-1), pStyle);
	}
	else
		it->itemText.applyStyle(qMax(0,it->itemText.length()-1), paraStyle);
	
	lastCharWasLineChange = text.right(1) == "\n";
	inPara = style->target() == "paragraph";
	lastParagraphStyle = paragraphStyle;
	if (isFirstWrite)
		isFirstWrite = false;
}
Example #4
0
//CB-->Doc/Fix
bool CanvasMode_CopyProperties::SeleItem(QMouseEvent *m)
{
    const unsigned SELECT_IN_GROUP = Qt::AltModifier;
    const unsigned SELECT_MULTIPLE = Qt::ShiftModifier;
    const unsigned SELECT_BENEATH = Qt::ControlModifier;
    PageItem *currItem;
    m_canvas->m_viewMode.m_MouseButtonPressed = true;
    FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
    Mxp = mousePointDoc.x(); //m->x()/m_canvas->scale());
    Myp = mousePointDoc.y(); //m->y()/m_canvas->scale());
    int MxpS = static_cast<int>(mousePointDoc.x()); //m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
    int MypS = static_cast<int>(mousePointDoc.y()); //m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
    m_doc->nodeEdit.deselect();
    if (!m_doc->masterPageMode())
    {
        int pgNum = -1;
        int docPageCount = static_cast<int>(m_doc->Pages->count() - 1);
        MarginStruct pageBleeds;
        bool drawBleed = false;
        if (m_doc->bleeds()->hasNonZeroValue() && m_doc->guidesPrefs().showBleed)
            drawBleed = true;
        for (int a = docPageCount; a > -1; a--)
        {
            if (drawBleed)
                m_doc->getBleeds(a, pageBleeds);
            int x = static_cast<int>(m_doc->Pages->at(a)->xOffset() - pageBleeds.Left);
            int y = static_cast<int>(m_doc->Pages->at(a)->yOffset() - pageBleeds.Top);
            int w = static_cast<int>(m_doc->Pages->at(a)->width() + pageBleeds.Left + pageBleeds.Right);
            int h = static_cast<int>(m_doc->Pages->at(a)->height() + pageBleeds.Bottom + pageBleeds.Top);
            if (QRect(x, y, w, h).contains(MxpS, MypS))
            {
                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>(m_doc->Pages->at(a2)->xOffset());
                        int yn = static_cast<int>(m_doc->Pages->at(a2)->yOffset());
                        int wn = static_cast<int>(m_doc->Pages->at(a2)->width());
                        int hn = static_cast<int>(m_doc->Pages->at(a2)->height());
                        if (QRect(xn, yn, wn, hn).contains(MxpS, MypS))
                        {
                            pgNum = static_cast<int>(a2);
                            break;
                        }
                    }
                }
                break;
            }
        }
        if (pgNum >= 0)
        {
            if (m_doc->currentPageNumber() != pgNum)
            {
                m_doc->setCurrentPage(m_doc->Pages->at(unsigned(pgNum)));
                m_view->setMenTxt(unsigned(pgNum));
                m_view->DrawNew();
            }
        }
        m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
    }
    currItem = NULL;
    if ((m->modifiers() & SELECT_BENEATH) != 0)
    {
        for (int i=0; i < m_doc->m_Selection->count(); ++i)
        {
            if (m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), m_doc->m_Selection->itemAt(i)) >= 0)
            {
                currItem = m_doc->m_Selection->itemAt(i);
                m_doc->m_Selection->removeItem(currItem);
                break;
            }
        }
    }
    else if ( (m->modifiers() & SELECT_MULTIPLE) == Qt::NoModifier || (m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames) )
    {
        m_view->Deselect(false);
    }
    currItem = m_canvas->itemUnderCursor(m->globalPos(), currItem, (m->modifiers() & SELECT_IN_GROUP));
    if (currItem)
    {
        m_doc->m_Selection->delaySignalsOn();
        if (m_doc->m_Selection->containsItem(currItem))
        {
            m_doc->m_Selection->removeItem(currItem);
        }
        else
        {
            //CB: If we have a selection but the user clicks with control on another item that is not below the current
            //then clear and select the new item
            if ((m->modifiers() == SELECT_BENEATH) && m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem) >= 0)
                m_doc->m_Selection->clear();
            m_doc->m_Selection->addItem(currItem);
            if ( (m->modifiers() & SELECT_IN_GROUP) && (!currItem->isGroup()))
            {
                currItem->isSingleSel = true;
            }
        }

        currItem->update();
        m_doc->m_Selection->delaySignalsOff();
        if (m_doc->m_Selection->count() > 1)
        {
            for (int aa = 0; aa < m_doc->m_Selection->count(); ++aa)
            {
                PageItem *bb = m_doc->m_Selection->itemAt(aa);
                bb->update();
            }
            m_doc->m_Selection->setGroupRect();
            double x, y, w, h;
            m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
            m_view->getGroupRectScreen(&x, &y, &w, &h);
        }
        if (m_doc->m_Selection->count() == 1)
        {
            frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem);
            if ((frameResizeHandle == Canvas::INSIDE) && (!currItem->locked()))
                qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
        }
        else
        {
            qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
            m_canvas->m_viewMode.operItemResizing = false;
        }
        return true;
    }
    m_doc->m_Selection->connectItemToGUI();
    if ( !(m->modifiers() & SELECT_MULTIPLE) || (m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames))
        m_view->Deselect(true);
    return false;
}
void CalligraphicMode::mouseReleaseEvent(QMouseEvent *m)
{
	undoManager->setUndoEnabled(true);
	PageItem *currItem;
	m_MouseButtonPressed = false;
	m_canvas->resetRenderMode();
	m->accept();
	
	if (m_doc->appMode == modeDrawCalligraphicLine)
	{
		if (RecordP.size() > 1)
		{
			UndoTransaction createTransaction;
			if (UndoManager::undoEnabled())
				createTransaction = UndoManager::instance()->beginTransaction();
			uint z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->itemToolPrefs().calligraphicPenLineWidth, m_doc->itemToolPrefs().calligraphicPenFillColor, m_doc->itemToolPrefs().calligraphicPenLineColor);
			currItem = m_doc->Items->at(z);
			currItem->PoLine.resize(0);
			QList<QPointF> clipU;
			QList<QPointF> clipL;
			double mx = sin(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0);
			double my = cos(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0);
			for (int px = 0; px < RecordP.size()-1; ++px)
			{
				FPoint clp = RecordP.point(px);
				clipU.append(QPointF(clp.x() - mx, clp.y() - my));
				clipL.prepend(QPointF(clp.x() + mx, clp.y() + my));
			}
			QPainterPath ppU = bezierFit(clipU, 5.0);
			QPainterPath ppL = bezierFit(clipL, 5.0);
			QPainterPath pp;
			pp.addPath(ppU);
			pp.connectPath(ppL);
			pp.closeSubpath();
			currItem->PoLine.fromQPainterPath(pp);
			FPoint tp2(getMinClipF(&currItem->PoLine));
			currItem->setXYPos(tp2.x(), tp2.y(), true);
			currItem->PoLine.translate(-tp2.x(), -tp2.y());
			FPoint tp(getMaxClipF(&currItem->PoLine));
			m_doc->sizeItem(tp.x(), tp.y(), currItem, false, false, false);
			m_doc->adjustItemSize(currItem);
			m_doc->m_Selection->clear();
			m_doc->m_Selection->addItem(currItem);
			currItem->ClipEdited = true;
			currItem->FrameType = 3;
			currItem->OwnPage = m_doc->OnPage(currItem);
			currItem->PLineArt = Qt::PenStyle(m_doc->itemToolPrefs().calligraphicPenStyle);
			currItem->setFillShade(m_doc->itemToolPrefs().calligraphicPenFillColorShade);
			currItem->setLineShade(m_doc->itemToolPrefs().calligraphicPenLineColorShade);
			currItem->setFillEvenOdd(true);
			m_view->resetMousePressed();
			currItem->checkChanges();
			QString targetName = Um::ScratchSpace;
			if (currItem->OwnPage > -1)
				targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
			if (createTransaction)
				createTransaction.commit(targetName, currItem->getUPixmap(), Um::Create + " " + currItem->getUName(),  "", Um::ICreate);
			//FIXME	
			m_canvas->m_viewMode.operItemResizing = false;
			m_doc->changed();
		}
		if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools)
		{
			m_view->requestMode(modeNormal);
		}
		else
			m_view->requestMode(m_doc->appMode);
		return;
	}

	m_canvas->setRenderModeUseBuffer(false);
	
	m_doc->DragP = false;
	m_doc->leaveDrag = false;
	m_view->MidButt = false;
	if (m_view->groupTransactionStarted())
	{
		for (int i = 0; i < m_doc->m_Selection->count(); ++i)
			m_doc->m_Selection->itemAt(i)->checkChanges(true);
		m_view->endGroupTransaction();
	}

	for (int i = 0; i < m_doc->m_Selection->count(); ++i)
		m_doc->m_Selection->itemAt(i)->checkChanges(true);

	//Commit drag created items to undo manager.
	if (m_doc->m_Selection->itemAt(0)!=NULL)
	{
		m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0));
	}
	//Make sure the Zoom spinbox and page selector don't have focus if we click on the canvas
	m_view->m_ScMW->zoomSpinBox->clearFocus();
	m_view->m_ScMW->pageSelector->clearFocus();
	if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
	{
		currItem = m_doc->m_Selection->itemAt(0);
		m_doc->nodeEdit.finishTransaction(currItem);
	}
}
bool SubdividePlugin::run(ScribusDoc* doc, QString)
{
	ScribusDoc* currDoc = doc;
	if (currDoc == 0)
		currDoc = ScCore->primaryMainWindow()->doc;
	double nearT = 0.5;
	uint docSelectionCount = currDoc->m_Selection->count();
	if (docSelectionCount != 0)
	{
		for (uint aa = 0; aa < docSelectionCount; ++aa)
		{
			FPointArray points;
			PageItem *currItem = currDoc->m_Selection->itemAt(aa);
			if (currDoc->nodeEdit.isContourLine)
			{
				uint psize = currItem->ContourLine.size();
				for (uint a = 0; a < psize-3; a += 4)
				{
					if (currItem->ContourLine.point(a).x() > 900000)
					{
						points.setMarker();
						continue;
					}
					FPoint base = currItem->ContourLine.point(a);
					FPoint c1 = currItem->ContourLine.point(a+1);
					FPoint base2 =  currItem->ContourLine.point(a+2);
					FPoint c2 = currItem->ContourLine.point(a+3);
					FPoint cn1 = (1.0 - nearT) * base + nearT * c1;
					FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2);
					FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2);
					FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2;
					FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3;
					if ((base == c1) && (base2 == c2))
					{
						points.addPoint(base);
						points.addPoint(c1);
						points.addPoint(bp1);
						points.addPoint(bp1);
						points.addPoint(bp1);
						points.addPoint(bp1);
						points.addPoint(base2);
						points.addPoint(c2);
					}
					else
					{
						points.addPoint(base);
						points.addPoint(cn1);
						points.addPoint(bp1);
						points.addPoint(cn2);
						points.addPoint(bp1);
						points.addPoint(cn3);
						points.addPoint(base2);
						points.addPoint(cn4);
					}
				}
				currItem->ContourLine = points;
			}
			else
			{
				uint psize = currItem->PoLine.size();
				for (uint a = 0; a < psize-3; a += 4)
				{
					if (currItem->PoLine.point(a).x() > 900000)
					{
						points.setMarker();
						continue;
					}
					FPoint base = currItem->PoLine.point(a);
					FPoint c1 = currItem->PoLine.point(a+1);
					FPoint base2 =  currItem->PoLine.point(a+2);
					FPoint c2 = currItem->PoLine.point(a+3);
					FPoint cn1 = (1.0 - nearT) * base + nearT * c1;
					FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2);
					FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2);
					FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2;
					FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3;
					if ((base == c1) && (base2 == c2))
					{
						points.addPoint(base);
						points.addPoint(c1);
						points.addPoint(bp1);
						points.addPoint(bp1);
						points.addPoint(bp1);
						points.addPoint(bp1);
						points.addPoint(base2);
						points.addPoint(c2);
					}
					else
					{
						points.addPoint(base);
						points.addPoint(cn1);
						points.addPoint(bp1);
						points.addPoint(cn2);
						points.addPoint(bp1);
						points.addPoint(cn3);
						points.addPoint(base2);
						points.addPoint(cn4);
					}
				}
				currItem->PoLine = points;
				currItem->Frame = false;
				currItem->ClipEdited = true;
				currItem->FrameType = 3;
				currDoc->AdjustItemSize(currItem);
				currItem->OldB2 = currItem->width();
				currItem->OldH2 = currItem->height();
				currItem->updateClip();
			}
		}
		currDoc->regionsChanged()->update(QRectF());
		currDoc->changed();
	}
	return true;
}
Example #7
0
LensDialog::LensDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent)
{
	setupUi(this);
	buttonRemove->setEnabled(false);
	setModal(true);
	buttonZoomOut->setIcon(QIcon(loadIcon("16/zoom-out.png")));
	buttonZoomI->setIcon(QIcon(loadIcon("16/zoom-in.png")));

	PageItem *currItem;
	double gx, gy, gh, gw;
	doc->m_Selection->setGroupRect();
	doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
	uint selectedItemCount = doc->m_Selection->count();
	QStack<PageItem*> groupStack;
	QStack<QGraphicsPathItem*> groupStack2;
	QStack<PageItem*> groupStack3;
	groupStack2.push(0);
	for (uint i = 0; i < selectedItemCount; ++i)
	{
		currItem = doc->m_Selection->itemAt(i);
		FPointArray path = currItem->PoLine;
		QPainterPath pp;
		if (currItem->itemType() == PageItem::PolyLine)
			pp = path.toQPainterPath(false);
		else
			pp = path.toQPainterPath(true);
		origPath.append(pp);
		QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, groupStack2.top());
		if (groupStack2.top() == 0)
		{
			scene.addItem(pItem);
			pItem->setPos(currItem->xPos() - gx, currItem->yPos() - gy);
			pItem->rotate(currItem->rotation());
		}
		else
		{
			PageItem* parent = groupStack3.top();
			QMatrix mm;
			mm.rotate(-parent->rotation());
			mm.translate(-parent->xPos(), -parent->yPos());
			pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos())));
		}
		pItem->setZValue(i);
		origPathItem.append(pItem);
		if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->controlsGroup()))
			pItem->setBrush(Qt::NoBrush);
		else
		{
			if (currItem->GrType != 0)
			{
				if (currItem->GrType != 8)
				{
					QGradient pat;
					double x1 = currItem->GrStartX;
					double y1 = currItem->GrStartY;
					double x2 = currItem->GrEndX;
					double y2 = currItem->GrEndY;
					switch (currItem->GrType)
					{
						case 1:
						case 2:
						case 3:
						case 4:
						case 6:
							pat = QLinearGradient(x1, y1,  x2, y2);
							break;
						case 5:
						case 7:
							pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1);
							break;
					}
					QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops();
					QColor qStopColor;
					for( int offset = 0 ; offset < colorStops.count() ; offset++ )
					{
						qStopColor = colorStops[ offset ]->color;
						int h, s, v, sneu, vneu;
						int shad = colorStops[offset]->shade;
						qStopColor.getHsv(&h, &s, &v);
						sneu = s * shad / 100;
						vneu = 255 - ((255 - v) * shad / 100);
						qStopColor.setHsv(h, sneu, vneu);
						qStopColor.setAlphaF(colorStops[offset]->opacity);
						pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor);
					}
					pItem->setBrush(pat);
				}
				else if ((currItem->GrType == 8) && (!currItem->pattern().isEmpty()) && (doc->docPatterns.contains(currItem->pattern())))
				{
					double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
					currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
					QMatrix qmatrix;
					qmatrix.translate(patternOffsetX, patternOffsetY);
					qmatrix.rotate(patternRotation);
					qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0);
					QImage pat = *doc->docPatterns[currItem->pattern()].getPattern();
					QBrush brush = QBrush(pat);
					brush.setMatrix(qmatrix);
					pItem->setBrush(brush);
				}
			}
			else
			{
				QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->fillColor()], doc, currItem->fillShade());
				paint.setAlphaF(1.0 - currItem->fillTransparency());
				pItem->setBrush(paint);
			}
		}
		if ((currItem->lineColor() == CommonStrings::None) || (currItem->controlsGroup()))
			pItem->setPen(Qt::NoPen);
		else
		{
			QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade());
			paint.setAlphaF(1.0 - currItem->lineTransparency());
			pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin()));
		}
		if (currItem->controlsGroup())
		{
			groupStack.push(currItem->groupsLastItem);
			groupStack2.push(pItem);
			groupStack3.push(currItem);
			pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
		}
		if (groupStack.count() != 0)
		{
			while (currItem == groupStack.top())
			{
				groupStack3.pop();
				groupStack2.pop();
				groupStack.pop();
				if (groupStack.count() == 0)
					break;
			}
		}
	}

	previewWidget->setRenderHint(QPainter::Antialiasing);
	previewWidget->setScene(&scene);
	isFirst = true;
	addLens();
	connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
	connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
	connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
	connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
	connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addLens()));
	connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeLens()));
	connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
	connect(buttonZoomI, SIGNAL(clicked()), this, SLOT(doZoomIn()));
	connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut()));
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	connect(&scene, SIGNAL(selectionChanged()), this, SLOT(selectionHasChanged()));
}
bool PathFinderPlugin::run(ScribusDoc* doc, QString)
{
	ScribusDoc* currDoc = doc;
	if (currDoc == 0)
		currDoc = ScCore->primaryMainWindow()->doc;
	if (currDoc->m_Selection->count() <= 1)
		return true;
	
	//<<#9046
	UndoTransaction* activeTransaction = NULL;
	UndoManager* undoManager = UndoManager::instance();
	if (UndoManager::undoEnabled())
		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IDocument, Um::PathOperation, "", Um::IPolygon));
	//>>#9046
	
	PageItem *Item1 = currDoc->m_Selection->itemAt(0);
	PageItem *Item2 = currDoc->m_Selection->itemAt(1);
	PathFinderDialog *dia = new PathFinderDialog(currDoc->scMW(), currDoc, Item1, Item2);
	if (dia->exec())
	{
		int opMode=dia->opMode;
		if (dia->keepItem1)
		{
			PageItem *newItem;
			if (dia->swapped)
			{
				newItem = new PageItem_Polygon(*Item2);
				newItem->setSelected(false);
				currDoc->Items->insert(currDoc->Items->indexOf(Item2), newItem);
			}
			else
			{
				newItem = new PageItem_Polygon(*Item1);
				newItem->setSelected(false);
				currDoc->Items->insert(currDoc->Items->indexOf(Item1), newItem);
			}
			if (UndoManager::undoEnabled())
			{
				ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem");
				is->set("CREATE_ITEM", "create_item");
				is->setItem(newItem);
				UndoObject *target = currDoc->Pages->at(Item1->OwnPage);
				undoManager->action(target, is);
			}
		}
		if (dia->keepItem2)
		{
			PageItem *newItem;
			if (dia->swapped)
			{
				newItem = new PageItem_Polygon(*Item1);
				newItem->setSelected(false);
				currDoc->Items->insert(currDoc->Items->indexOf(Item1), newItem);
			}
			else
			{
				newItem = new PageItem_Polygon(*Item2);
				newItem->setSelected(false);
				currDoc->Items->insert(currDoc->Items->indexOf(Item2), newItem);
			}
			if (UndoManager::undoEnabled())
			{
				ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem");
				is->set("CREATE_ITEM", "create_item");
				is->setItem(newItem);
				UndoObject *target = currDoc->Pages->at(Item1->OwnPage);
				undoManager->action(target, is);
			}
		}
		if (opMode != 4)
		{
			PageItem *currItem;
			QPainterPath path;
			FPointArray points;
			if (dia->targetColor == 0)
			{
				currItem = Item1;
				if (dia->swapped)
				{
					currItem = Item2;
					currItem->setXYPos(Item1->xPos(), Item1->yPos());
					currItem->setRotation(0.0);
				}
			}
			else
			{
				if (dia->swapped)
					currItem = Item1;
				else
				{
					currItem = Item2;
					currItem->setXYPos(Item1->xPos(), Item1->yPos());
					currItem->setRotation(0.0);
				}
			}
			path = dia->result;
			points.fromQPainterPath(path);
			
			//<<#9046
			FPointArray oldPOLine=currItem->PoLine;
			FPointArray oldContourLine=currItem->ContourLine;
			ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL;
			if (UndoManager::undoEnabled())
			{
				state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation);
				state->set("PATH_OPERATION", "path_operation");
				state->set("PATH_OP_OLD_FRAME", currItem->Frame);
				state->set("PATH_OP_OLD_CLIPEDITED", currItem->ClipEdited);
				state->set("PATH_OP_OLD_FRAMETYPE", currItem->FrameType);
				state->set("PATH_OP_OLD_OLDB2", currItem->OldB2);
				state->set("PATH_OP_OLD_OLDH2", currItem->OldH2);
				state->set("PATH_OP_NEW_FRAME", false);
				state->set("PATH_OP_NEW_CLIPEDITED", true);
				state->set("PATH_OP_NEW_FRAMETYPE", 3);
			}
			//>>#9046
			
			currItem->PoLine = points;
			currItem->Frame = false;
			currItem->ClipEdited = true;
			currItem->FrameType = 3;
			currDoc->AdjustItemSize(currItem);
			currItem->OldB2 = currItem->width();
			currItem->OldH2 = currItem->height();
			currItem->updateClip();
			currItem->ContourLine = currItem->PoLine.copy();
			
			//<<#9046
			if (UndoManager::undoEnabled())
			{
				state->set("PATH_OP_NEW_OLDB2", currItem->OldB2);
				state->set("PATH_OP_NEW_OLDH2", currItem->OldH2);
				state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(points, currItem->ContourLine)));
				undoManager->action(currItem, state);
			}
			//>>#9046
			
			currDoc->m_Selection->removeItem(currItem);
			currDoc->itemSelection_DeleteItem();
		}
		else
		{
			QPainterPath path;
			FPointArray points;
			PageItem *newItem;
			double i1x = Item1->xPos();
			double i1y = Item1->yPos();
			path = dia->result;
			if (!path.isEmpty())
			{
				points.fromQPainterPath(path);
				//<<#9046
				FPointArray oldPOLine=Item1->PoLine;
				FPointArray oldContourLine=Item1->ContourLine;
				ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL;
				if (UndoManager::undoEnabled())
				{
					state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation);
					state->set("PATH_OPERATION", "path_operation");
					state->set("PATH_OP_OLD_FRAME", Item1->Frame);
					state->set("PATH_OP_OLD_CLIPEDITED", Item1->ClipEdited);
					state->set("PATH_OP_OLD_FRAMETYPE", Item1->FrameType);
					state->set("PATH_OP_OLD_OLDB2", Item1->OldB2);
					state->set("PATH_OP_OLD_OLDH2", Item1->OldH2);
					state->set("PATH_OP_NEW_FRAME", false);
					state->set("PATH_OP_NEW_CLIPEDITED", true);
					state->set("PATH_OP_NEW_FRAMETYPE", 3);
				}
				//>>#9046
				Item1->PoLine = points;
				Item1->Frame = false;
				Item1->ClipEdited = true;
				Item1->FrameType = 3;
				currDoc->AdjustItemSize(Item1);
				Item1->OldB2 = Item1->width();
				Item1->OldH2 = Item1->height();
				Item1->updateClip();
				Item1->ContourLine = Item1->PoLine.copy();
				//<<#9046
				if (UndoManager::undoEnabled())
				{
					state->set("PATH_OP_NEW_OLDB2", Item1->OldB2);
					state->set("PATH_OP_NEW_OLDH2", Item1->OldH2);
					state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(Item1->PoLine, Item1->ContourLine)));
					undoManager->action(Item1, state);
				}
				//>>#9046
			}

			path = QPainterPath();
			path = dia->result1;
			if (!path.isEmpty())
			{
				points.fromQPainterPath(path);
				//<<#9046
				FPointArray oldPOLine=Item2->PoLine;
				FPointArray oldContourLine=Item2->ContourLine;
				ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL;
				if (UndoManager::undoEnabled())
				{
					state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation);
					state->set("PATH_OPERATION", "path_operation");
					state->set("PATH_OP_OLD_FRAME", Item2->Frame);
					state->set("PATH_OP_OLD_CLIPEDITED", Item2->ClipEdited);
					state->set("PATH_OP_OLD_FRAMETYPE", Item2->FrameType);
					state->set("PATH_OP_OLD_OLDB2", Item2->OldB2);
					state->set("PATH_OP_OLD_OLDH2", Item2->OldH2);
					state->set("PATH_OP_NEW_FRAME", false);
					state->set("PATH_OP_NEW_CLIPEDITED", true);
					state->set("PATH_OP_NEW_FRAMETYPE", 3);
				}
				//>>#9046
				Item2->setXYPos(i1x, i1y);
				Item2->setRotation(0.0);
				Item2->PoLine = points;
				Item2->Frame = false;
				Item2->ClipEdited = true;
				Item2->FrameType = 3;
				currDoc->AdjustItemSize(Item2);
				Item2->OldB2 = Item2->width();
				Item2->OldH2 = Item2->height();
				Item2->updateClip();
				Item2->ContourLine = Item2->PoLine.copy();
				//<<#9046
				if (UndoManager::undoEnabled())
				{
					state->set("PATH_OP_NEW_OLDB2", Item2->OldB2);
					state->set("PATH_OP_NEW_OLDH2", Item2->OldH2);
					state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(Item2->PoLine, Item2->ContourLine)));
					undoManager->action(Item2, state);
				}
				//>>#9046
			}
			
			path = QPainterPath();
			path = dia->result2;
			if (!path.isEmpty())
			{
				if (dia->targetColor == 0)
				{
					newItem = new PageItem_Polygon(*Item1);
					newItem->setXYPos(i1x, i1y);
				}
				else
				{
					newItem = new PageItem_Polygon(*Item2);
					newItem->setXYPos(i1x, i1y);
					newItem->setRotation(0.0);
				}
				currDoc->Items->append(newItem);
				newItem->setSelected(false);
				points.fromQPainterPath(path);
				newItem->PoLine = points;
				newItem->Frame = false;
				newItem->ClipEdited = true;
				newItem->FrameType = 3;
				currDoc->AdjustItemSize(newItem);
				newItem->OldB2 = newItem->width();
				newItem->OldH2 = newItem->height();
				newItem->updateClip();
				newItem->ContourLine = newItem->PoLine.copy();
				if (dia->targetColor == 2)
				{
					QString fill = dia->getOtherFillColor();
					if (fill == CommonStrings::tr_NoneColor)
						fill = CommonStrings::None;
					newItem->setFillColor(fill);
					QString stroke = dia->getOtherLineColor();
					if (stroke == CommonStrings::tr_NoneColor)
						stroke = CommonStrings::None;
					newItem->setLineColor(stroke);
				}
			}
			currDoc->m_Selection->clear();
			currDoc->view()->Deselect(true);
		}
		currDoc->changed();
		currDoc->view()->DrawNew();
	}
	delete dia;
	
	//<<#9046
	if (activeTransaction)
	{
		activeTransaction->commit();
		delete activeTransaction;
		activeTransaction = NULL;
	}
	//>>#9046
	
	return true;
}
Example #9
0
void WordAndPara(PageItem* currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN)
{
    QChar Dat = QChar(32);
    int para = 0;
    int ww = 0;
    int cc = 0;
    int paraN = 0;
    int wwN = 0;
    int ccN = 0;
    bool first = true;
    PageItem *nextItem = currItem;
    PageItem *nbl = currItem;
    while (nextItem != 0)
    {
        if (nextItem->prevInChain() != 0)
            nextItem = nextItem->prevInChain();
        else
            break;
    }
    while (nextItem != 0)
    {
        for (int a = qMax(nextItem->firstInFrame(),0); a <= nextItem->lastInFrame() && a < nextItem->itemText.length(); ++a)
        {
            QChar b = nextItem->itemText.text(a);
            if (b == SpecialChars::PARSEP)
            {
                para++;
            }
            if ((!b.isLetterOrNumber()) && (Dat.isLetterOrNumber()) && (!first))
            {
                ww++;
            }
            cc++;
            Dat = b;
            first = false;
        }
        nbl = nextItem;
        nextItem = nextItem->nextInChain();
    }
    if (nbl->frameOverflows()) {
        paraN++;
        for (int a = nbl->lastInFrame()+1; a < nbl->itemText.length(); ++a)
        {
            QChar b = nbl->itemText.text(a);
            if (b == SpecialChars::PARSEP)
            {
                paraN++;
            }
            if ((!b.isLetterOrNumber()) && (Dat.isLetterOrNumber()) && (!first))
            {
                wwN++;
            }
            ccN++;
            Dat = b;
            first = false;
        }
    }
    else {
        para++;
    }
    if (Dat.isLetterOrNumber())
    {
        if (nbl->frameOverflows())
            wwN++;
        else
            ww++;
    }
    *w = ww;
    *p = para;
    *c = cc;
    *wN = wwN;
    *pN = paraN;
    *cN = ccN;
}
void CanvasMode_EditMeshGradient::mousePressEvent(QMouseEvent *m)
{
    const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());

    m_canvas->PaintSizeRect(QRect());
    m_canvas->m_viewMode.m_MouseButtonPressed = true;
    m_canvas->m_viewMode.operItemMoving = false;
    m_view->HaveSelRect = false;
    m_doc->DragP = false;
    m_doc->leaveDrag = false;
    m->accept();
    m_view->registerMousePress(m->globalPos());
    m_Mxp = mousePointDoc.x(); //m->x();
    m_Myp = mousePointDoc.y(); //m->y();
    if (m->button() == Qt::MidButton)
    {
        m_view->MidButt = true;
        if (m->modifiers() & Qt::ControlModifier)
            m_view->DrawNew();
        return;
    }
    PageItem *currItem = m_doc->m_Selection->itemAt(0);
    QTransform itemMatrix = currItem->getTransform();
    bool found = false;
    QPair<int, int> selPoint;
    if (m_view->editStrokeGradient == 5)
    {
        m_gradientPoint = noPointDefined;
        for (int grow = 0; grow < currItem->meshGradientArray.count(); grow++)
        {
            for (int gcol = 0; gcol < currItem->meshGradientArray[grow].count(); gcol++)
            {
                meshPoint mp = currItem->meshGradientArray[grow][gcol];
                QPointF gradientPoint = QPointF(mp.gridPoint.x(), mp.gridPoint.y());
                gradientPoint = itemMatrix.map(gradientPoint);
                if (m_canvas->hitsCanvasPoint(mousePointDoc, gradientPoint))
                {
                    selPoint.first = grow;
                    selPoint.second = gcol;
                    found = true;
                    *m_old_mesh = mp;
                    break;
                }
            }
            if (found)
                break;
        }
    }
    else if (m_view->editStrokeGradient == 6)
    {
        m_gradientPoint = noPointDefined;
        m_selectedMeshPoints.clear();
        for (int grow = 0; grow < currItem->meshGradientArray.count(); grow++)
        {
            for (int gcol = 0; gcol < currItem->meshGradientArray[grow].count(); gcol++)
            {
                meshPoint mp = currItem->meshGradientArray[grow][gcol];
                QPointF gradientPoint = QPointF(mp.gridPoint.x(), mp.gridPoint.y());
                gradientPoint = itemMatrix.map(gradientPoint);
                QPointF gradientColorPoint = QPointF(mp.controlColor.x(), mp.controlColor.y());
                gradientColorPoint = itemMatrix.map(gradientColorPoint);
                if (m_canvas->hitsCanvasPoint(mousePointDoc, gradientPoint) || m_canvas->hitsCanvasPoint(mousePointDoc, gradientColorPoint))
                {
                    selPoint.first = grow;
                    selPoint.second = gcol;
                    currItem->selectedMeshPointX = grow;
                    currItem->selectedMeshPointY = gcol;
                    *m_old_mesh = mp;
                    found = true;
                    break;
                }
            }
            if (found)
                break;
        }
    }
    else if (m_view->editStrokeGradient == 7)
    {
        for (int grow = 0; grow < currItem->meshGradientArray.count(); grow++)
        {
            for (int gcol = 0; gcol < currItem->meshGradientArray[grow].count(); gcol++)
            {
                meshPoint mp1 = currItem->meshGradientArray[grow][gcol];
                QPointF gradientPoint;
                if (grow == 0)
                {
                    if (gcol == 0)
                    {
                        gradientPoint = QPointF(mp1.controlRight.x(), mp1.controlRight.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlR;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlBottom.x(), mp1.controlBottom.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlB;
                            found = true;
                        }
                    }
                    else if (gcol == currItem->meshGradientArray[grow].count()-1)
                    {
                        gradientPoint = QPointF(mp1.controlLeft.x(), mp1.controlLeft.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlL;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlBottom.x(), mp1.controlBottom.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlB;
                            found = true;
                        }
                    }
                    else
                    {
                        gradientPoint = QPointF(mp1.controlLeft.x(), mp1.controlLeft.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlL;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlRight.x(), mp1.controlRight.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlR;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlBottom.x(), mp1.controlBottom.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlB;
                            found = true;
                        }
                    }
                }
                else if (grow == currItem->meshGradientArray.count()-1)
                {
                    if (gcol == 0)
                    {
                        gradientPoint = QPointF(mp1.controlRight.x(), mp1.controlRight.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlR;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlTop.x(), mp1.controlTop.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlT;
                            found = true;
                        }
                    }
                    else if (gcol == currItem->meshGradientArray[grow].count()-1)
                    {
                        gradientPoint = QPointF(mp1.controlTop.x(), mp1.controlTop.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlT;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlLeft.x(), mp1.controlLeft.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlL;
                            found = true;
                        }
                    }
                    else
                    {
                        gradientPoint = QPointF(mp1.controlTop.x(), mp1.controlTop.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlT;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlLeft.x(), mp1.controlLeft.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlL;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlRight.x(), mp1.controlRight.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlR;
                            found = true;
                        }
                    }
                }
                else
                {
                    if (gcol == 0)
                    {
                        gradientPoint = QPointF(mp1.controlBottom.x(), mp1.controlBottom.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlB;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlTop.x(), mp1.controlTop.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlT;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlRight.x(), mp1.controlRight.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlR;
                            found = true;
                        }
                    }
                    else if (gcol == currItem->meshGradientArray[grow].count()-1)
                    {
                        gradientPoint = QPointF(mp1.controlBottom.x(), mp1.controlBottom.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlB;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlTop.x(), mp1.controlTop.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlT;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlLeft.x(), mp1.controlLeft.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlL;
                            found = true;
                        }
                    }
                    else
                    {
                        gradientPoint = QPointF(mp1.controlBottom.x(), mp1.controlBottom.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlB;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlTop.x(), mp1.controlTop.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlT;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlLeft.x(), mp1.controlLeft.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlL;
                            found = true;
                        }
                        gradientPoint = QPointF(mp1.controlRight.x(), mp1.controlRight.y());
                        if (m_canvas->hitsCanvasPoint(mousePointDoc, itemMatrix.map(gradientPoint)))
                        {
                            m_gradientPoint = useControlR;
                            found = true;
                        }
                    }
                }
                if (found)
                {
                    selPoint.first = grow;
                    selPoint.second = gcol;
                    *m_old_mesh = mp1;
                    break;
                }
            }
            if (found)
                break;
        }
        if (!found)
        {
            for (int grow = 0; grow < currItem->meshGradientArray.count(); grow++)
            {
                for (int gcol = 0; gcol < currItem->meshGradientArray[grow].count(); gcol++)
                {
                    meshPoint mp = currItem->meshGradientArray[grow][gcol];
                    QPointF gradientPoint = QPointF(mp.gridPoint.x(), mp.gridPoint.y());
                    gradientPoint = itemMatrix.map(gradientPoint);
                    if (m_canvas->hitsCanvasPoint(mousePointDoc, gradientPoint))
                    {
                        selPoint.first = grow;
                        selPoint.second = gcol;
                        m_gradientPoint = noPointDefined;
                        found = true;
                        break;
                    }
                }
                if (found)
                    break;
            }
        }
    }
    if (!found)
    {
        if (!(m->modifiers() & Qt::ShiftModifier))
        {
            m_gradientPoint = noPointDefined;
            m_selectedMeshPoints.clear();
            currItem->selectedMeshPointX = -1;
            currItem->selectedMeshPointY = -1;
            currItem->selectedMeshControlPoint = static_cast<int>(m_gradientPoint);
        }
    }
    else
    {
        bool isSelected = false;
        for (int se = 0; se < m_selectedMeshPoints.count(); se++)
        {
            if ((selPoint.first == m_selectedMeshPoints[se].first) && (selPoint.second == m_selectedMeshPoints[se].second))
            {
                isSelected = true;
                break;
            }
        }
        if ((!(m->modifiers() & Qt::ShiftModifier)) && (!isSelected))
            m_selectedMeshPoints.clear();
        if (!isSelected)
            m_selectedMeshPoints.append(selPoint);
        currItem->selectedMeshPointX = m_selectedMeshPoints[0].first;
        currItem->selectedMeshPointY = m_selectedMeshPoints[0].second;
        currItem->selectedMeshControlPoint = static_cast<int>(m_gradientPoint);
    }
    m_canvas->m_viewMode.m_MouseButtonPressed = true;
    m_ScMW->propertiesPalette->updateColorSpecialGradient();
    m_view->setCursor(QCursor(Qt::CrossCursor));
    m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem->width(), currItem->height()));
}
void PageItem_Group::DrawObj_Item(ScPainter *p, QRectF /*e*/)
{
	if (m_Doc->RePos)
		return;

	if (groupItemList.isEmpty())
	{
		if (m_Doc->guidesPrefs().framesShown)
		{
			p->save();
			p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
			p->drawLine(FPoint(0, 0), FPoint(Width, Height));
			p->drawLine(FPoint(0, Height), FPoint(Width, 0));
			p->setFont(QApplication::font());
			p->drawLine(FPoint(0, 0), FPoint(Width, 0));
			p->drawLine(FPoint(Width, 0), FPoint(Width, Height));
			p->drawLine(FPoint(Width, Height), FPoint(0, Height));
			p->drawLine(FPoint(0, Height), FPoint(0, 0));
			p->setBrush(QColor(255, 255, 255));
			p->setBrushOpacity(0.0);
			p->drawText(QRectF(0.0, 0.0, Width, Height), "Empty Group");
			p->restore();
		}
		return;
	}

	p->save();
	if (imageFlippedH())
	{
		p->translate(Width, 0);
		p->scale(-1, 1);
	}
	if (imageFlippedV())
	{
		p->translate(0, Height);
		p->scale(1, -1);
	}
	if ((maskType() == 1) || (maskType() == 2) || (maskType() == 4) || (maskType() == 5))
	{
		if ((maskType() == 1) || (maskType() == 2))
			p->setMaskMode(1);
		else
			p->setMaskMode(3);
		if ((!gradientMask().isEmpty()) && (!m_Doc->docGradients.contains(gradientMask())))
			gradientMaskVal = "";
		if (!(gradientMask().isEmpty()) && (m_Doc->docGradients.contains(gradientMask())))
			mask_gradient = m_Doc->docGradients[gradientMask()];
		p->mask_gradient = mask_gradient;
		if ((maskType() == 1) || (maskType() == 4))
			p->setGradientMask(VGradient::linear, FPoint(GrMaskStartX, GrMaskStartY), FPoint(GrMaskEndX, GrMaskEndY), FPoint(GrMaskStartX, GrMaskStartY), GrMaskScale, GrMaskSkew);
		else
			p->setGradientMask(VGradient::radial, FPoint(GrMaskStartX, GrMaskStartY), FPoint(GrMaskEndX, GrMaskEndY), FPoint(GrMaskFocalX, GrMaskFocalY), GrMaskScale, GrMaskSkew);
	}
	else if ((maskType() == 3) || (maskType() == 6) || (maskType() == 7) || (maskType() == 8))
	{
		if ((patternMask().isEmpty()) || (!m_Doc->docPatterns.contains(patternMask())))
			p->setMaskMode(0);
		else
		{
			double scw = Width / groupWidth;
			double sch = Height / groupHeight;
			p->setPatternMask(&m_Doc->docPatterns[patternMask()], patternMaskScaleX * scw, patternMaskScaleY * sch, patternMaskOffsetX, patternMaskOffsetY, patternMaskRotation, patternMaskSkewX, patternMaskSkewY, patternMaskMirrorX, patternMaskMirrorY);
			if (maskType() == 3)
				p->setMaskMode(2);
			else if (maskType() == 6)
				p->setMaskMode(4);
			else if (maskType() == 7)
				p->setMaskMode(5);
			else
				p->setMaskMode(6);
		}
	}
	else
		p->setMaskMode(0);
	p->setFillRule(fillRule);
	p->beginLayer(1.0 - fillTransparency(), fillBlendmode(), &PoLine);
	p->setMaskMode(0);
	p->scale(Width / groupWidth, Height / groupHeight);
	for (int em = 0; em < groupItemList.count(); ++em)
	{
		PageItem* embedded = groupItemList.at(em);
		p->save();
		p->translate(embedded->gXpos, embedded->gYpos);
		embedded->isEmbedded = true;
		embedded->invalidateLayout();
		embedded->DrawObj(p, QRectF());
		embedded->isEmbedded = false;
		p->restore();
		if (m_Doc->guidesPrefs().framesShown)
		{
			p->save();
			double x = embedded->xPos();
			double y = embedded->yPos();
			embedded->setXYPos(embedded->gXpos, embedded->gYpos, true);
			embedded->DrawObj_Decoration(p);
			embedded->setXYPos(x, y, true);
			p->restore();
		}
		if (m_Doc->layerOutline(LayerID))
		{
			p->save();
			p->setPen(m_Doc->layerMarker(LayerID), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
			p->setFillMode(ScPainter::None);
			p->setBrushOpacity(1.0);
			p->setPenOpacity(1.0);
			p->setupPolygon(&PoLine);
			p->strokePath();
			p->restore();
		}
	}
	p->endLayer();
	p->restore();
}
void CanvasMode_EditMeshGradient::mouseMoveEvent(QMouseEvent *m)
{
    const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
    m->accept();
    if (m_selectedMeshPoints.count() == 0)
        return;
    if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed())
    {
        FPoint npfN;
        double nx = mousePointDoc.x();
        double ny = mousePointDoc.y();
        if (!m_doc->ApplyGuides(&nx, &ny) && !m_doc->ApplyGuides(&nx, &ny,true))
            npfN = m_doc->ApplyGridF(FPoint(nx, ny));
        else
            npfN = FPoint(nx, ny);
        PageItem *currItem = m_doc->m_Selection->itemAt(0);
        QTransform pp = currItem->getTransform();
        FPoint npf = npfN.transformPoint(pp, true);
        if (m_view->editStrokeGradient == 6)
        {
            if (m_selectedMeshPoints.count() > 0)
            {
                QPair<int, int> selP = m_selectedMeshPoints[0];
                FPoint cP = currItem->meshGradientArray[selP.first][selP.second].controlColor;
                FPoint gP = currItem->meshGradientArray[selP.first][selP.second].gridPoint;
                m_canvas->displayXYHUD(m->globalPos(), cP.x() - gP.x(), cP.y() - gP.y());
            }
        }
        else
            m_canvas->displayXYHUD(m->globalPos(), npf.x(), npf.y());
        FPoint npx(m_Mxp - npfN.x(), m_Myp - npfN.y(), 0, 0, currItem->rotation(), 1, 1, true);
        if (m_selectedMeshPoints.count() > 0)
        {
            if (m_view->editStrokeGradient == 5)
            {
                for (int mo = 0; mo < m_selectedMeshPoints.count(); mo++)
                {
                    QPair<int, int> selP = m_selectedMeshPoints[mo];
                    currItem->meshGradientArray[selP.first][selP.second].moveRel(-npx.x(), -npx.y());
                }
            }
            else if (m_view->editStrokeGradient == 6)
            {
                QPair<int, int> selP = m_selectedMeshPoints[0];
                currItem->meshGradientArray[selP.first][selP.second].controlColor -= npx;
            }
            else if (m_view->editStrokeGradient == 7)
            {
                QPair<int, int> selP = m_selectedMeshPoints[0];
                if (m_gradientPoint == useControlT)
                    currItem->meshGradientArray[selP.first][selP.second].controlTop -= npx;
                else if (m_gradientPoint == useControlB)
                    currItem->meshGradientArray[selP.first][selP.second].controlBottom -= npx;
                else if (m_gradientPoint == useControlL)
                    currItem->meshGradientArray[selP.first][selP.second].controlLeft -= npx;
                else if (m_gradientPoint == useControlR)
                    currItem->meshGradientArray[selP.first][selP.second].controlRight -= npx;
            }
            currItem->update();
            QTransform itemMatrix = currItem->getTransform();
            m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem->width(), currItem->height()));
        }
        m_Mxp = npfN.x();
        m_Myp = npfN.y();
    }
}
void CanvasMode_EditMeshGradient::keyPressEvent(QKeyEvent *e)
{
    if (m_selectedMeshPoints.count() == 0)
        return;
    int kk = e->key();
    if (m_keyRepeat)
        return;
    m_keyRepeat = true;
    e->accept();
    Qt::KeyboardModifiers buttonModifiers = e->modifiers();
    if ((!m_view->m_ScMW->zoomSpinBox->hasFocus()) && (!m_view->m_ScMW->pageSelector->hasFocus()))
    {
        if (m_doc->m_Selection->count() != 0)
        {
            double moveBy = 1.0;
            double moveX = 0.0;
            double moveY = 0.0;
            bool isMoving = false;
            bool doUpdate = false;
            if ((buttonModifiers & Qt::ShiftModifier) && !(buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
                moveBy=0.1;
            else if (!(buttonModifiers & Qt::ShiftModifier) && (buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
                moveBy=10.0;
            else if ((buttonModifiers & Qt::ShiftModifier) && (buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
                moveBy=0.01;
            moveBy/=m_doc->unitRatio();//Lets allow movement by the current doc ratio, not only points
            moveBy /= m_canvas->m_viewMode.scale;
            PageItem *currItem = m_doc->m_Selection->itemAt(0);
            switch (kk)
            {
            case Qt::Key_7:
                moveX = -moveBy;
                moveY = -moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_9:
                moveX = moveBy;
                moveY = -moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_3:
                moveX = moveBy;
                moveY = moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_1:
                moveX = -moveBy;
                moveY = moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_Left:
            case Qt::Key_4:
                moveX = -moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_Right:
            case Qt::Key_6:
                moveX = moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_Up:
            case Qt::Key_8:
                moveY = -moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_Down:
            case Qt::Key_2:
                moveY = moveBy;
                isMoving = true;
                doUpdate = true;
                break;
            case Qt::Key_5:
                if (m_view->editStrokeGradient == 6)
                {
                    QPair<int, int> selP = m_selectedMeshPoints[0];
                    currItem->meshGradientArray[selP.first][selP.second].controlColor = currItem->meshGradientArray[selP.first][selP.second].gridPoint;
                    doUpdate = true;
                }
                else if (m_view->editStrokeGradient == 7)
                {
                    QPair<int, int> selP = m_selectedMeshPoints[0];
                    if (m_gradientPoint == useControlT)
                        currItem->meshGradientArray[selP.first][selP.second].controlTop = currItem->meshGradientArray[selP.first][selP.second].gridPoint;
                    else if (m_gradientPoint == useControlB)
                        currItem->meshGradientArray[selP.first][selP.second].controlBottom = currItem->meshGradientArray[selP.first][selP.second].gridPoint;
                    else if (m_gradientPoint == useControlL)
                        currItem->meshGradientArray[selP.first][selP.second].controlLeft = currItem->meshGradientArray[selP.first][selP.second].gridPoint;
                    else if (m_gradientPoint == useControlR)
                        currItem->meshGradientArray[selP.first][selP.second].controlRight = currItem->meshGradientArray[selP.first][selP.second].gridPoint;
                    doUpdate = true;
                }
                break;
            }
            if (isMoving)
            {
                if (m_view->editStrokeGradient == 5)
                {
                    for (int mo = 0; mo < m_selectedMeshPoints.count(); mo++)
                    {
                        QPair<int, int> selP = m_selectedMeshPoints[mo];
                        currItem->meshGradientArray[selP.first][selP.second].moveRel(moveX, moveY);
                    }
                }
                else if (m_view->editStrokeGradient == 6)
                {
                    QPair<int, int> selP = m_selectedMeshPoints[0];
                    currItem->meshGradientArray[selP.first][selP.second].controlColor += FPoint(moveX, moveY);
                }
                else if (m_view->editStrokeGradient == 7)
                {
                    QPair<int, int> selP = m_selectedMeshPoints[0];
                    if (m_gradientPoint == useControlT)
                        currItem->meshGradientArray[selP.first][selP.second].controlTop += FPoint(moveX, moveY);
                    else if (m_gradientPoint == useControlB)
                        currItem->meshGradientArray[selP.first][selP.second].controlBottom += FPoint(moveX, moveY);
                    else if (m_gradientPoint == useControlL)
                        currItem->meshGradientArray[selP.first][selP.second].controlLeft += FPoint(moveX, moveY);
                    else if (m_gradientPoint == useControlR)
                        currItem->meshGradientArray[selP.first][selP.second].controlRight += FPoint(moveX, moveY);
                }
            }
            if (doUpdate)
            {
                currItem->update();
                QRectF upRect;
                upRect = QRectF(QPointF(0, 0), QPointF(currItem->width(), currItem->height())).normalized();
                upRect.translate(currItem->xPos(), currItem->yPos());
                m_doc->regionsChanged()->update(upRect.adjusted(-10.0 - currItem->width() / 2.0, -10.0 - currItem->height() / 2.0, 10.0 + currItem->width() / 2.0, 10.0 + currItem->height() / 2.0));
            }
        }
    }
    m_keyRepeat = false;
}
Example #14
0
void ShapePlug::parseGroup(QDomNode &DOC)
{
    QString tmp = "";
    QString FillCol = "White";
    QString StrokeCol = "Black";
    QString defFillCol = "White";
    QString defStrokeCol = "Black";
    QColor stroke = Qt::black;
    QColor fill = Qt::white;
//	Qt::PenStyle Dash = Qt::SolidLine;
    Qt::PenCapStyle LineEnd = Qt::FlatCap;
    Qt::PenJoinStyle LineJoin = Qt::MiterJoin;
//	int fillStyle = 1;
    double strokewidth = 0.1;
//	bool poly = false;
    while(!DOC.isNull())
    {
        double x1, y1, x2, y2;
        StrokeCol = defStrokeCol;
        FillCol = defFillCol;
        stroke = Qt::black;
        fill = Qt::white;
        //	fillStyle = 1;
        strokewidth = 1.0;
        //	Dash = Qt::SolidLine;
        LineEnd = Qt::FlatCap;
        LineJoin = Qt::MiterJoin;
        FPointArray PoLine;
        PoLine.resize(0);
        QDomElement pg = DOC.toElement();
        QString STag = pg.tagName();
        QString style = pg.attribute( "style", "" ).simplified();
        if (style.isEmpty())
            style = pg.attribute( "svg:style", "" ).simplified();
        QStringList substyles = style.split(';', QString::SkipEmptyParts);
        for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it )
        {
            QStringList substyle = (*it).split(':', QString::SkipEmptyParts);
            QString command(substyle[0].trimmed());
            QString params(substyle[1].trimmed());
            if (command == "fill")
            {
                if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default") || (params == "inverse")))
                {
                    if (params == "nofill")
                        FillCol = CommonStrings::None;
                    else
                    {
                        fill.setNamedColor( params );
                        FillCol = "FromDia"+fill.name();
                        ScColor tmp;
                        tmp.fromQColor(fill);
                        tmp.setSpotColor(false);
                        tmp.setRegistrationColor(false);
                        QString fNam = m_Doc->PageColors.tryAddColor(FillCol, tmp);
                        if (fNam == FillCol)
                            importedColors.append(FillCol);
                        FillCol = fNam;
                    }
                }
            }
            else if (command == "stroke")
            {
                if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default")) || (params == "inverse"))
                {
                    stroke.setNamedColor( params );
                    StrokeCol = "FromDia"+stroke.name();
                    ScColor tmp;
                    tmp.fromQColor(stroke);
                    tmp.setSpotColor(false);
                    tmp.setRegistrationColor(false);
                    QString fNam = m_Doc->PageColors.tryAddColor(StrokeCol, tmp);
                    if (fNam == StrokeCol)
                        importedColors.append(StrokeCol);
                    StrokeCol = fNam;
                }
            }
            else if (command == "stroke-width")
                strokewidth = ScCLocale::toDoubleC(params);
            else if( command == "stroke-linejoin" )
            {
                if( params == "miter" )
                    LineJoin = Qt::MiterJoin;
                else if( params == "round" )
                    LineJoin = Qt::RoundJoin;
                else if( params == "bevel" )
                    LineJoin = Qt::BevelJoin;
            }
            else if( command == "stroke-linecap" )
            {
                if( params == "butt" )
                    LineEnd = Qt::FlatCap;
                else if( params == "round" )
                    LineEnd = Qt::RoundCap;
                else if( params == "square" )
                    LineEnd = Qt::SquareCap;
            }
        }
        if (STag == "svg:line")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion;
            y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion;
            PoLine.addPoint(x1, y1);
            PoLine.addPoint(x1, y1);
            PoLine.addPoint(x2, y2);
            PoLine.addPoint(x2, y2);
            int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, CommonStrings::None, StrokeCol);
            m_Doc->Items->at(z)->PoLine = PoLine.copy();
            finishItem(m_Doc->Items->at(z));
        }
        else if (STag == "svg:rect")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion;
            y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion;
            int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX + x1, baseY + y1, x2, y2, strokewidth, FillCol, StrokeCol);
            m_Doc->Items->at(z)->setLineJoin(LineJoin);
            m_Doc->Items->at(z)->setLineEnd(LineEnd);
            finishItem(m_Doc->Items->at(z));
        }
        else if ((STag == "svg:polygon") || (STag == "svg:polyline"))
        {
            bool bFirst = true;
            double x = 0.0;
            double y = 0.0;
            QString points = pg.attribute( "points" ).simplified().replace(',', " ");
            QStringList pointList = points.split(' ', QString::SkipEmptyParts);
            FirstM = true;
            for( QStringList::Iterator it = pointList.begin(); it != pointList.end(); it++ )
            {
                x = ScCLocale::toDoubleC(*(it++));
                y = ScCLocale::toDoubleC(*it);
                if( bFirst )
                {
                    svgMoveTo(x * Conversion, y * Conversion);
                    bFirst = false;
                    WasM = true;
                }
                else
                {
                    svgLineTo(&PoLine, x * Conversion, y * Conversion);
                }
            }
            if (STag == "svg:polygon")
                svgClosePath(&PoLine);
            if (PoLine.size() < 4)
            {
                DOC = DOC.nextSibling();
                continue;
            }
            int z;
            if (STag == "svg:polygon")
                z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, FillCol, StrokeCol);
            else
                z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, CommonStrings::None, StrokeCol);
            m_Doc->Items->at(z)->PoLine = PoLine.copy();
            finishItem(m_Doc->Items->at(z));
        }
        else if ((STag == "svg:circle") || (STag == "svg:ellipse"))
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1;
            y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1;
            x1 *= 2.0;
            y1 *= 2.0;
            int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x1, baseY + y1, x2, y2, strokewidth, FillCol, StrokeCol);
            m_Doc->Items->at(z)->setLineJoin(LineJoin);
            m_Doc->Items->at(z)->setLineEnd(LineEnd);
            finishItem(m_Doc->Items->at(z));
        }
        else if (STag == "svg:path")
        {
            //	poly =
            parseSVG( pg.attribute( "d" ), &PoLine );
            if (PoLine.size() < 4)
            {
                DOC = DOC.nextSibling();
                continue;
            }
            int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, FillCol, StrokeCol);
            m_Doc->Items->at(z)->PoLine = PoLine.copy();
            finishItem(m_Doc->Items->at(z));
        }
        else if (STag == "svg:g")
        {
            int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseX, 1, 1, 0, CommonStrings::None, CommonStrings::None);
            PageItem *neu = m_Doc->Items->at(z);
            Elements.append(neu);
            if (groupStack.count() > 0)
                groupStack.top().append(neu);
            QList<PageItem*> gElements;
            groupStack.push(gElements);
            QDomNode child = DOC.firstChild();
            parseGroup(child);
            if (gElements.count() == 0)
            {
                groupStack.pop();
                Elements.removeAll(neu);
                groupStack.top().removeAll(neu);
                Selection tmpSelection(m_Doc, false);
                tmpSelection.addItem(neu);
                m_Doc->itemSelection_DeleteItem(&tmpSelection);
            }
            else
            {
                QList<PageItem*> gElem = groupStack.pop();
                double minx =  std::numeric_limits<double>::max();
                double miny =  std::numeric_limits<double>::max();
                double maxx = -std::numeric_limits<double>::max();
                double maxy = -std::numeric_limits<double>::max();
                for (int gr = 0; gr < gElements.count(); ++gr)
                {
                    PageItem* currItem = gElem.at(gr);
                    double x1, x2, y1, y2;
                    currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
                    minx = qMin(minx, x1);
                    miny = qMin(miny, y1);
                    maxx = qMax(maxx, x2);
                    maxy = qMax(maxy, y2);
                }
                double gx = minx;
                double gy = miny;
                double gw = maxx - minx;
                double gh = maxy - miny;
                neu->setXYPos(gx, gy, true);
                neu->setWidthHeight(gw, gh, true);
                neu->SetRectFrame();
                neu->Clip = FlattenPath(neu->PoLine, neu->Segments);
                neu->setItemName( tr("Group%1").arg(m_Doc->GroupCounter));
                neu->AutoName = false;
                neu->gXpos = neu->xPos() - gx;
                neu->gYpos = neu->yPos() - gy;
                neu->groupWidth = gw;
                neu->groupHeight = gh;
                for (int gr = 0; gr < gElem.count(); ++gr)
                {
                    PageItem* currItem = gElem.at(gr);
                    currItem->gXpos = currItem->xPos() - gx;
                    currItem->gYpos = currItem->yPos() - gy;
                    currItem->gWidth = gw;
                    currItem->gHeight = gh;
                    currItem->Parent = neu;
                    neu->groupItemList.append(currItem);
                    m_Doc->Items->removeAll(currItem);
                    Elements.removeAll(currItem);
                }
                neu->setRedrawBounding();
                neu->setTextFlowMode(PageItem::TextFlowDisabled);
                m_Doc->GroupCounter++;
            }
        }
        DOC = DOC.nextSibling();
    }
}
void CanvasMode_EditWeldPoint::keyPressEvent(QKeyEvent *e)
{
	if (m_selectedPoint < 0)
		return;
	int kk = e->key();
	if (m_keyRepeat)
		return;
	m_keyRepeat = true;
	e->accept();

	if (e->key() == Qt::Key_Escape)
	{
		// Go back to normal mode.
		m_view->requestMode(modeNormal);
		return;
	}

	Qt::KeyboardModifiers buttonModifiers = e->modifiers();
	if ((!m_view->m_ScMW->zoomSpinBox->hasFocus()) && (!m_view->m_ScMW->pageSelector->hasFocus()))
	{
		if (m_doc->m_Selection->count() != 0)
		{
			double moveBy = 1.0;
			double moveX = 0.0;
			double moveY = 0.0;
			bool isMoving = false;
			bool doUpdate = false;
			if (m_doc->unitIndex()!=SC_INCHES)
			{
				if ((buttonModifiers & Qt::ShiftModifier) && !(buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
					moveBy=0.1;
				else if (!(buttonModifiers & Qt::ShiftModifier) && (buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
					moveBy=10.0;
				else if ((buttonModifiers & Qt::ShiftModifier) && (buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
					moveBy=0.01;
				moveBy/=m_doc->unitRatio();//Lets allow movement by the current doc ratio, not only points
			}
			else
			{
				if ((buttonModifiers & Qt::ShiftModifier) && !(buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
					moveBy=0.1/m_doc->unitRatio();
				else if (!(buttonModifiers & Qt::ShiftModifier) && (buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
					moveBy=1.0/m_doc->unitRatio();
				else if ((buttonModifiers & Qt::ShiftModifier) && (buttonModifiers & Qt::ControlModifier) && !(buttonModifiers & Qt::AltModifier))
					moveBy=0.01/m_doc->unitRatio();
			}
			moveBy /= m_canvas->m_viewMode.scale;
			PageItem *currItem = m_doc->m_Selection->itemAt(0);
			switch (kk)
			{
				case Qt::Key_7:
					moveX = -moveBy;
					moveY = -moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_9:
					moveX = moveBy;
					moveY = -moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_3:
					moveX = moveBy;
					moveY = moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_1:
					moveX = -moveBy;
					moveY = moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_Left:
				case Qt::Key_4:
					moveX = -moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_Right:
				case Qt::Key_6:
					moveX = moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_Up:
				case Qt::Key_8:
					moveY = -moveBy;
					isMoving = true;
					doUpdate = true;
					break;
				case Qt::Key_Down:
				case Qt::Key_2:
					moveY = moveBy;
					isMoving = true;
					doUpdate = true;
					break;
			}
			if (isMoving)
			{
				if (m_editWeldMode)
				{
					currItem->weldList[m_selectedPoint].weldPoint += FPoint(moveX, moveY);
				}
				else
				{
					currItem->setXYPos(currItem->xPos() + moveX, currItem->yPos() + moveY, true);
					currItem->setRedrawBounding();
					currItem->OwnPage = m_doc->OnPage(currItem);
				}
			}
			if (doUpdate)
			{
				currItem->update();
				m_doc->regionsChanged()->update(getUpdateRect());
			}
		}
	}
	m_keyRepeat = false;
}
Example #16
0
PyObject *scribus_polygon(PyObject* /* self */, PyObject* args)
{
	char *Name = const_cast<char*>("");
	PyObject *il;
	// FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
	if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
		return NULL;
	if(!checkHaveDocument())
		return NULL;
	int len = PyList_Size(il);
	if (len < 6)
	{
		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error").toLocal8Bit().constData());
		return NULL;
	}
	if ((len % 2) != 0)
	{
		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error").toLocal8Bit().constData());
		return NULL;
	}
//	if (ItemExists(QString::fromUtf8(Name)))
//	{
//		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData());
//		return NULL;
//	}
	double x, y, w, h;
	int i = 0;
	x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, 1, 1,	ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor);
	PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
	it->PoLine.resize(2);
	it->PoLine.setPoint(0, 0, 0);
	it->PoLine.setPoint(1, 0, 0);
	int pp = 6;
	for (i = 2; i < len - 2; i += 2)
	{
		w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
		h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
		it->PoLine.resize(pp);
		it->PoLine.setPoint(pp-4, w-x, h-y);
		it->PoLine.setPoint(pp-3, w-x, h-y);
		it->PoLine.setPoint(pp-2, w-x, h-y);
		it->PoLine.setPoint(pp-1, w-x, h-y);
		pp += 4;
	}
	w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
	h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
	it->PoLine.resize(pp);
	it->PoLine.setPoint(pp-4, w-x, h-y);
	it->PoLine.setPoint(pp-3, w-x, h-y);
	it->PoLine.setPoint(pp-2, w-x, h-y);
	it->PoLine.setPoint(pp-1, w-x, h-y);
	pp += 2;
	it->PoLine.resize(pp);
	it->PoLine.setPoint(pp-2, 0, 0);
	it->PoLine.setPoint(pp-1, 0, 0);
	FPoint np2 = getMinClipF(&it->PoLine);
	if (np2.x() < 0)
	{
		it->PoLine.translate(-np2.x(), 0);
		ScCore->primaryMainWindow()->doc->moveItem(np2.x(), 0, it);
	}
	if (np2.y() < 0)
	{
		it->PoLine.translate(0, -np2.y());
		ScCore->primaryMainWindow()->doc->moveItem(0, np2.y(), it);
	}
	ScCore->primaryMainWindow()->doc->sizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), it, false, false, false);
	ScCore->primaryMainWindow()->doc->adjustItemSize(it);
	if (strlen(Name) > 0)
	{
		QString objName = QString::fromUtf8(Name);
		if (!ItemExists(objName))
			ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
	}
	return PyString_FromString(it->itemName().toUtf8());
}
Example #17
0
void XfigPlug::processArrows(int forward_arrow, QString fArrowData, int backward_arrow, QString bArrowData, int depth, PageItem *ite)
{
	int		arrow_typeAF;			// (enumeration type)
	int		arrow_styleAF;			// (enumeration type)
	float	arrow_thicknessAF;		// (1/80 inch)
	float	arrow_widthAF;			// (Fig units)
	float	arrow_heightAF;			// (Fig units)
	int		arrow_typeAB;			// (enumeration type)
	int		arrow_styleAB;			// (enumeration type)
	float	arrow_thicknessAB;		// (1/80 inch)
	float	arrow_widthAB;			// (Fig units)
	float	arrow_heightAB;			// (Fig units)
	FPointArray arrow;
	int z = -1;
	PageItem::ItemType iteType;
	if (forward_arrow == 1)
	{
		arrow.resize(0);
		ScTextStream CodeAF(&fArrowData, QIODevice::ReadOnly);
		CodeAF >> arrow_typeAF >> arrow_styleAF >> arrow_thicknessAF >> arrow_widthAF >> arrow_heightAF;
		arrow_widthAF = fig2Pts(arrow_widthAF);
		arrow_heightAF = fig2Pts(arrow_heightAF);
		arrow_thicknessAF = arrow_thicknessAF / 80.0 * 72.0;
		FPoint End = ite->PoLine.point(ite->PoLine.size()-2);
		for (uint xx = ite->PoLine.size()-1; xx > 0; xx -= 2)
		{
			FPoint Vector = ite->PoLine.point(xx);
			if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
			{
				double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
				QTransform arrowTrans;
				if (arrow_typeAF == 0)
					arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5");
				else if (arrow_typeAF == 1)
					arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 z");
				else if (arrow_typeAF == 2)
					arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 L -0.7 0 z");
				else if (arrow_typeAF == 3)
					arrow.parseSVG("M -0.7, -0.5 L 0, 0 L -0.7, 0.5 L -1 0 z");
				arrowTrans.translate(End.x(), End.y());
				arrowTrans.rotate(r);
				arrowTrans.scale(arrow_heightAF, arrow_widthAF);
				arrow.map(arrowTrans);
				break;
			}
		}
		QString fillC = "White";
		if (arrow_styleAF == 1)
			fillC = CurrColorStroke;
		if (arrow_typeAF == 0)
		{
			fillC = CommonStrings::None;
			iteType = PageItem::PolyLine;
		}
		else
			iteType = PageItem::Polygon;
		z = m_Doc->itemAdd(iteType, PageItem::Unspecified, ite->xPos(), ite->yPos(), 10, 10, arrow_thicknessAF, fillC, CurrColorStroke);
		if (z >= 0)
		{
			PageItem *item = m_Doc->Items->at(z);
			item->PoLine = arrow.copy();
			item->ClipEdited = true;
			item->FrameType = 3;
			item->setFillShade(CurrFillShade);
			item->setLineShade(CurrStrokeShade);
			FPoint wh = getMaxClipF(&item->PoLine);
			item->setWidthHeight(wh.x(),wh.y());
			item->setTextFlowMode(PageItem::TextFlowDisabled);
			m_Doc->adjustItemSize(item);
			item->setWidthHeight(qMax(item->width(), 1.0), qMax(item->height(), 1.0));
			depthMap.insert(999 - depth, currentItemNr);
			currentItemNr++;
		}
	}
Example #18
0
/*
 * Craig Ringer, 2004-09-09
 * Apply the named style to the currently selected object.
 * pv, 2004-09-13, optionaly param objectName + "check the page" stuff
 */
PyObject *scribus_setstyle(PyObject* /* self */, PyObject* args)
{
	char *style = const_cast<char*>("");
	char *name = const_cast<char*>("");
	if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
		return NULL;
	if(!checkHaveDocument())
		return NULL;
	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
	if (item == NULL)
		return NULL;
	if ((item->itemType() == PageItem::TextFrame) || (item->itemType() == PageItem::PathText))
	{
		// First, find the style number associated with the requested style
		// by scanning through the styles looking for the name. If
		// we can't find it, raise PyExc_Exception.
		// FIXME: Should use a more specific exception.
		bool found = false;
		uint styleid = 0;
		// We start at zero here because it's OK to match an internal name
		int docParagraphStylesCount=ScCore->primaryMainWindow()->doc->paragraphStyles().count();
		for (int i=0; i < docParagraphStylesCount; ++i)
		{
			if (ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name() == QString::fromUtf8(style)) {
				found = true;
				styleid = i;
				break;
			}
		}
		if (!found) {
			// whoops, the user specified an invalid style, complain loudly.
			PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error").toLocal8Bit().constData());
			return NULL;
		}
		// for current item only
		if (ScCore->primaryMainWindow()->doc->m_Selection->count() == 0 || (strlen(name) > 0))
		{
			// quick hack to always apply on the right frame - pv
			ScCore->primaryMainWindow()->view->Deselect(true);
			//CB I dont think we need to draw here. Its faster if we dont.
			ScCore->primaryMainWindow()->view->SelectItem(item, false);
			// Now apply the style.
			int mode = ScCore->primaryMainWindow()->doc->appMode;
			ScCore->primaryMainWindow()->doc->appMode = modeEdit;
			ScCore->primaryMainWindow()->setNewParStyle(QString::fromUtf8(style));
			ScCore->primaryMainWindow()->doc->appMode = mode;
		}
		else // for multiple selection
		{
			int mode = ScCore->primaryMainWindow()->doc->appMode;
			ScCore->primaryMainWindow()->doc->appMode = modeNormal;
			ScCore->primaryMainWindow()->doc->itemSelection_ApplyParagraphStyle(ScCore->primaryMainWindow()->doc->paragraphStyles()[styleid]);
			ScCore->primaryMainWindow()->doc->appMode = mode;
		}
	}
	else
	{
		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.","python error").toLocal8Bit().constData());
		return NULL;
	}
//	Py_INCREF(Py_None);
//	return Py_None;
	Py_RETURN_NONE;
}
Example #19
0
void PageItem_Symbol::DrawObj_Item(ScPainter *p, QRectF /*e*/)
{
	if (!m_Doc->RePos)
	{
		if ((!patternVal.isEmpty()) && (m_Doc->docPatterns.contains(patternVal)))
		{
			p->save();
			if (imageFlippedH())
			{
				p->translate(Width, 0);
				p->scale(-1, 1);
			}
			if (imageFlippedV())
			{
				p->translate(0, Height);
				p->scale(1, -1);
			}
			if ((maskType() == 1) || (maskType() == 2) || (maskType() == 4) || (maskType() == 5))
			{
				if ((maskType() == 1) || (maskType() == 2))
					p->setMaskMode(1);
				else
					p->setMaskMode(3);
				if ((!gradientMask().isEmpty()) && (!m_Doc->docGradients.contains(gradientMask())))
					gradientMaskVal = "";
				if (!(gradientMask().isEmpty()) && (m_Doc->docGradients.contains(gradientMask())))
					mask_gradient = m_Doc->docGradients[gradientMask()];
				p->mask_gradient = mask_gradient;
				if ((maskType() == 1) || (maskType() == 4))
					p->setGradientMask(VGradient::linear, FPoint(GrMaskStartX, GrMaskStartY), FPoint(GrMaskEndX, GrMaskEndY), FPoint(GrMaskStartX, GrMaskStartY), GrMaskScale, GrMaskSkew);
				else
					p->setGradientMask(VGradient::radial, FPoint(GrMaskStartX, GrMaskStartY), FPoint(GrMaskEndX, GrMaskEndY), FPoint(GrMaskFocalX, GrMaskFocalY), GrMaskScale, GrMaskSkew);
			}
			else if ((maskType() == 3) || (maskType() == 6))
			{
				if ((patternMask().isEmpty()) || (!m_Doc->docPatterns.contains(patternMask())))
					p->setMaskMode(0);
				else
				{
					p->setPatternMask(&m_Doc->docPatterns[patternMask()], patternMaskScaleX, patternMaskScaleY, patternMaskOffsetX + xPos(), patternMaskOffsetY + yPos(), patternMaskRotation, patternMaskSkewX, patternMaskSkewY, patternMaskMirrorX, patternMaskMirrorY);
					if (maskType() == 3)
						p->setMaskMode(2);
					else
						p->setMaskMode(4);
				}
			}
			else
				p->setMaskMode(0);
			p->beginLayer(1.0 - fillTransparency(), fillBlendmode(), &PoLine);
			p->setMaskMode(0);
			ScPattern pat = m_Doc->docPatterns[patternVal];
			p->scale(Width / pat.width, Height / pat.height);
			p->translate(pat.items.at(0)->gXpos, pat.items.at(0)->gYpos);
			for (int em = 0; em < pat.items.count(); ++em)
			{
				PageItem* embedded = pat.items.at(em);
				p->save();
				p->translate(embedded->gXpos, embedded->gYpos);
				embedded->isEmbedded = true;
				embedded->invalid = true;
				embedded->DrawObj(p, QRectF());
				embedded->isEmbedded = false;
				p->restore();
			}
			for (int em = 0; em < pat.items.count(); ++em)
			{
				PageItem* embedded = pat.items.at(em);
				if (!embedded->isTableItem)
					continue;
				p->save();
				p->translate(embedded->gXpos, embedded->gYpos);
				p->rotate(embedded->rotation());
				embedded->isEmbedded = true;
				embedded->invalid = true;
				if ((embedded->lineColor() != CommonStrings::None) && (embedded->lineWidth() != 0.0))
				{
					QColor tmp;
					embedded->SetQColor(&tmp, embedded->lineColor(), embedded->lineShade());
					if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine))
					{
						p->setPen(tmp, embedded->lineWidth(), embedded->PLineArt, Qt::SquareCap, embedded->PLineJoin);
						if (embedded->TopLine)
							p->drawLine(FPoint(0.0, 0.0), FPoint(embedded->width(), 0.0));
						if (embedded->RightLine)
							p->drawLine(FPoint(embedded->width(), 0.0), FPoint(embedded->width(), embedded->height()));
						if (embedded->BottomLine)
							p->drawLine(FPoint(embedded->width(), embedded->height()), FPoint(0.0, embedded->height()));
						if (embedded->LeftLine)
							p->drawLine(FPoint(0.0, embedded->height()), FPoint(0.0, 0.0));
					}
				}
				embedded->isEmbedded = false;
				p->restore();
			}
			p->endLayer();
			p->restore();
		}
		else
		{
			if (m_Doc->guidesPrefs().framesShown)
			{
				p->save();
				p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
				p->drawLine(FPoint(0, 0), FPoint(Width, Height));
				p->drawLine(FPoint(0, Height), FPoint(Width, 0));
				p->setFont(QApplication::font());
				p->drawLine(FPoint(0, 0), FPoint(Width, 0));
				p->drawLine(FPoint(Width, 0), FPoint(Width, Height));
				p->drawLine(FPoint(Width, Height), FPoint(0, Height));
				p->drawLine(FPoint(0, Height), FPoint(0, 0));
				p->setBrush(QColor(255, 255, 255));
				p->setBrushOpacity(0.0);
				p->drawText(QRectF(0.0, 0.0, Width, Height), "Empty Symbol");
				p->restore();
			}
		}
	}
}
Example #20
0
void PropertiesPalette_XYZ::handleSelectionChanged()
{
	if (!m_haveDoc || !m_ScMW || m_ScMW->scriptIsRunning())
		return;

	nameEdit->setEnabled(m_doc->m_Selection->count() == 1);

	PageItem* currItem = currentItemFromSelection();
	if (m_doc->m_Selection->count() > 1)
	{
		m_oldRotation = 0;
		double gx, gy, gh, gw;
		m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
		int bp = basePointWidget->checkedId();
		if (bp == 0)
			m_ScMW->view->RCenter = FPoint(gx, gy);
		else if (bp == 1)
			m_ScMW->view->RCenter = FPoint(gx + gw, gy);
		else if (bp == 2)
			m_ScMW->view->RCenter = FPoint(gx + gw / 2.0, gy + gh / 2.0);
		else if (bp == 3)
			m_ScMW->view->RCenter = FPoint(gx, gy + gh);
		else if (bp == 0)
			m_ScMW->view->RCenter = FPoint(gx + gw, gy + gh);
		xposLabel->setText( tr( "&X-Pos:" ) );
		widthLabel->setText( tr( "&Width:" ) );
		yposLabel->setText( tr( "&Y-Pos:" ) );
		heightLabel->setText( tr( "&Height:" ) );

		xposSpin->showValue(gx);
		yposSpin->showValue(gy);
		widthSpin->showValue(gw);
		heightSpin->showValue(gh);
		rotationSpin->showValue(0);

		xposSpin->setEnabled(true);
		yposSpin->setEnabled(true);
		widthSpin->setEnabled(true);
		heightSpin->setEnabled(true);
		rotationSpin->setEnabled(true);

		nameEdit->setEnabled(false);
		flipH->setCheckable( false );
		flipV->setCheckable( false );
		flipH->setChecked(false);
		flipV->setChecked(false);

		flipH->setEnabled(true);
		flipV->setEnabled(true);

		setEnabled(true);
	}
	else
	{
		int itemType = currItem ? (int) currItem->itemType() : -1;
		
		m_haveItem = (itemType!=-1);
		if (itemType == -1)
		{
			doGroup->setEnabled(false);
			doUnGroup->setEnabled(false);
		}
		nameEdit->setEnabled(true);
		basePointWidget->setEnabled(true);

		setEnabled(true);

		//CB If Toggle is not possible, then we need to enable it so we can turn it off
		//It then gets reset below for items where its valid
		flipH->setCheckable(true);
		flipV->setCheckable(true);
		if ((itemType == 2) || (itemType == 4) || ((itemType >= 9) && (itemType <= 12)) || (itemType == 15))
		{
			flipH->setCheckable(true);
			flipV->setCheckable(true);
		}
		else
		{
			flipH->setCheckable(false);
			flipV->setCheckable(false);
			flipH->setChecked(false);
			flipV->setChecked(false);
		}
		
		//CB Why cant we do this for lines?
//		flipH->setEnabled((itemType !=-1) && (itemType !=5));
//		flipV->setEnabled((itemType !=-1) && (itemType !=5));
		flipH->setEnabled(itemType !=-1);
		flipV->setEnabled(itemType !=-1);
		switch (itemType)
		{
		case -1:
			xposLabel->setText( tr( "&X-Pos:" ) );
			widthLabel->setText( tr( "&Width:" ) );
			yposLabel->setText( tr( "&Y-Pos:" ) );
			heightLabel->setText( tr( "&Height:" ) );

			xposSpin->showValue(0);
			yposSpin->showValue(0);
			widthSpin->showValue(0);
			heightSpin->showValue(0);
			rotationSpin->showValue(0);
			levelLabel->setText("  ");
			setEnabled(false);
			break;
		case PageItem::ImageFrame:
		case PageItem::LatexFrame:
		case PageItem::OSGFrame:
#ifdef HAVE_OSG
			if (currItem->asOSGFrame())
			{
				setEnabled(true);
				rotationSpin->setEnabled(false);
			}
#endif
			break;
		case PageItem::Line:
			basePointWidget->setEnabled(false);
			break;
		}
	}
	if (currItem)
	{
		setCurrentItem(currItem);
	}
	updateGeometry();
	repaint();
}
Example #21
0
void CanvasMode_CopyProperties::mousePressEvent(QMouseEvent *m)
{
// 	const double mouseX = m->globalX();
// 	const double mouseY = m->globalY();
    const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());

    double Rxp = 0, Ryp = 0;
    PageItem *currItem;
    m_canvas->PaintSizeRect(QRect());
    m_canvas->m_viewMode.m_MouseButtonPressed = true;
    m_canvas->m_viewMode.operItemMoving = false;
    m_view->HaveSelRect = false;
    m_doc->DragP = false;
    m_doc->leaveDrag = false;
    m->accept();
    m_view->registerMousePress(m->globalPos());
    Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
    Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
    Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
    Mxp = qRound(Rxp);
    Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
    Myp = qRound(Ryp);
    if (m->button() == Qt::MidButton)
    {
        m_view->MidButt = true;
        if (m->modifiers() & Qt::ControlModifier)
            m_view->DrawNew();
        return;
    }
    if (m->button() != Qt::LeftButton)
        return;
    SeleItem(m);
    if (GetItem(&currItem))
    {
        double sx, sy, ex, ey, r, skx, sky, fx, fy, ss, sk, sp;
        currItem->ColGap = m_doc->ElemToLink->ColGap;
        currItem->Cols = m_doc->ElemToLink->Cols;
        currItem->BottomLine = m_doc->ElemToLink->BottomLine;
        currItem->TopLine = m_doc->ElemToLink->TopLine;
        currItem->LeftLine = m_doc->ElemToLink->LeftLine;
        currItem->RightLine = m_doc->ElemToLink->RightLine;
        currItem->setTextToFrameDist(m_doc->ElemToLink->textToFrameDistLeft(), m_doc->ElemToLink->textToFrameDistRight(), m_doc->ElemToLink->textToFrameDistTop(), m_doc->ElemToLink->textToFrameDistBottom());
        // Stroke Properties
        currItem->setLineStyle(m_doc->ElemToLink->lineStyle());
        currItem->setLineWidth(m_doc->ElemToLink->lineWidth());
        currItem->setLineTransparency(m_doc->ElemToLink->lineTransparency());
        currItem->setLineShade(m_doc->ElemToLink->lineShade());
        currItem->setLineColor(m_doc->ElemToLink->lineColor());
        currItem->setLineEnd(m_doc->ElemToLink->lineEnd());
        currItem->setLineJoin(m_doc->ElemToLink->lineJoin());
        currItem->setCustomLineStyle(m_doc->ElemToLink->customLineStyle());
        currItem->setEndArrowIndex(m_doc->ElemToLink->endArrowIndex());
        currItem->setStartArrowIndex(m_doc->ElemToLink->startArrowIndex());
        currItem->setEndArrowScale(m_doc->ElemToLink->endArrowScale());
        currItem->setStartArrowScale(m_doc->ElemToLink->startArrowScale());
        // Fill Properties
        currItem->setFillColor(m_doc->ElemToLink->fillColor());
        currItem->setFillShade(m_doc->ElemToLink->fillShade());
        currItem->setFillTransparency(m_doc->ElemToLink->fillTransparency());
        // Gradient Properties
        currItem->fill_gradient = m_doc->ElemToLink->fill_gradient;
        currItem->setGradient(m_doc->ElemToLink->gradient());
        m_doc->ElemToLink->gradientVector(sx, sy, ex, ey, fx, fy, ss, sk);
        currItem->setGradientVector(sx, sy, ex, ey, fx, fy, ss, sk);
        // Pattern Properties
        currItem->setPattern(m_doc->ElemToLink->pattern());
        m_doc->ElemToLink->patternTransform(sx, sy, ex, ey, r, skx, sky);
        currItem->setPatternTransform(sx, sy, ex, ey, r, skx, sky);
        currItem->setStrokePattern(m_doc->ElemToLink->strokePattern());
        m_doc->ElemToLink->strokePatternTransform(sx, sy, ex, ey, r, skx, sky, sp);
        currItem->setStrokePatternTransform(sx, sy, ex, ey, r, skx, sky, sp);
        currItem->setStrokePatternToPath(m_doc->ElemToLink->isStrokePatternToPath());
        // Set Gradient type after all properties
        currItem->setGradientType(m_doc->ElemToLink->gradientType());

        currItem->stroke_gradient = m_doc->ElemToLink->stroke_gradient;
        currItem->setStrokeGradient(m_doc->ElemToLink->strokeGradient());
        m_doc->ElemToLink->strokeGradientVector(sx, sy, ex, ey, fx, fy, ss, sk);
        currItem->setStrokeGradientVector(sx, sy, ex, ey, fx, fy, ss, sk);
        currItem->setStrokeGradientType(m_doc->ElemToLink->strokeGradientType());
        // Update Item
        m_doc->ElemToLink = currItem;
        currItem->update();
//		emit DocChanged();
//		m_view->updateContents();
    }
    else
    {
        m_doc->ElemToLink = NULL;
        m_view->requestMode(submodePaintingDone);
    }
}
Example #22
0
bool PathFinderPlugin::run(ScribusDoc* doc, QString)
{
	QString vers = QString(qVersion()).left(5);
	if (vers < "4.3.3")
	{
		QMessageBox::information(doc->scMW(), tr("Qt Version too old"), tr("This plugin requires at least version 4.3.3 of the Qt library"));
		return true;
	}
	ScribusDoc* currDoc = doc;
	if (currDoc == 0)
		currDoc = ScCore->primaryMainWindow()->doc;
	if (currDoc->m_Selection->count() > 1)
	{
		PageItem *Item1 = currDoc->m_Selection->itemAt(0);
		PageItem *Item2 = currDoc->m_Selection->itemAt(1);
		PathFinderDialog *dia = new PathFinderDialog(currDoc->scMW(), currDoc, Item1, Item2);
		if (dia->exec())
		{
			if (dia->keepItem1)
			{
				PageItem *newItem;
				if (dia->swapped)
				{
					newItem = new PageItem_Polygon(*Item2);
					newItem->setSelected(false);
					currDoc->Items->insert(Item2->ItemNr, newItem);
				}
				else
				{
					newItem = new PageItem_Polygon(*Item1);
					newItem->setSelected(false);
					currDoc->Items->insert(Item1->ItemNr, newItem);
				}
			}
			if (dia->keepItem2)
			{
				PageItem *newItem;
				if (dia->swapped)
				{
					newItem = new PageItem_Polygon(*Item1);
					newItem->setSelected(false);
					currDoc->Items->insert(Item1->ItemNr, newItem);
				}
				else
				{
					newItem = new PageItem_Polygon(*Item2);
					newItem->setSelected(false);
					currDoc->Items->insert(Item2->ItemNr, newItem);
				}
			}
			if (dia->keepItem1 || dia->keepItem2)
				currDoc->renumberItemsInListOrder();
			if (dia->opMode != 4)
			{
				PageItem *currItem;
				QPainterPath path;
				FPointArray points;
				if (dia->targetColor == 0)
				{
					currItem = Item1;
					if (dia->swapped)
					{
						currItem = Item2;
						currItem->setXYPos(Item1->xPos(), Item1->yPos());
						currItem->setRotation(0.0);
					}
				}
				else
				{
					if (dia->swapped)
						currItem = Item1;
					else
					{
						currItem = Item2;
						currItem->setXYPos(Item1->xPos(), Item1->yPos());
						currItem->setRotation(0.0);
					}
				}
				path = dia->result;
				points.fromQPainterPath(path);
				currItem->PoLine = points;
				currItem->Frame = false;
				currItem->ClipEdited = true;
				currItem->FrameType = 3;
				currDoc->AdjustItemSize(currItem);
				currItem->OldB2 = currItem->width();
				currItem->OldH2 = currItem->height();
				currItem->updateClip();
				currItem->ContourLine = currItem->PoLine.copy();
				currDoc->m_Selection->removeItem(currItem);
				currDoc->itemSelection_DeleteItem();
			}
			else
			{
				QPainterPath path;
				FPointArray points;
				PageItem *newItem;
				double i1x = Item1->xPos();
				double i1y = Item1->yPos();
				path = dia->result;
				if (!path.isEmpty())
				{
					points.fromQPainterPath(path);
					Item1->PoLine = points;
					Item1->Frame = false;
					Item1->ClipEdited = true;
					Item1->FrameType = 3;
					currDoc->AdjustItemSize(Item1);
					Item1->OldB2 = Item1->width();
					Item1->OldH2 = Item1->height();
					Item1->updateClip();
					Item1->ContourLine = Item1->PoLine.copy();
				}

				path = QPainterPath();
				path = dia->result1;
				if (!path.isEmpty())
				{
					points.fromQPainterPath(path);
					Item2->setXYPos(i1x, i1y);
					Item2->setRotation(0.0);
					Item2->PoLine = points;
					Item2->Frame = false;
					Item2->ClipEdited = true;
					Item2->FrameType = 3;
					currDoc->AdjustItemSize(Item2);
					Item2->OldB2 = Item2->width();
					Item2->OldH2 = Item2->height();
					Item2->updateClip();
					Item2->ContourLine = Item2->PoLine.copy();
				}
				
				path = QPainterPath();
				path = dia->result2;
				if (!path.isEmpty())
				{
					if (dia->targetColor == 0)
					{
						newItem = new PageItem_Polygon(*Item1);
						newItem->setXYPos(i1x, i1y);
					}
					else
					{
						newItem = new PageItem_Polygon(*Item2);
						newItem->setXYPos(i1x, i1y);
						newItem->setRotation(0.0);
					}
					currDoc->Items->append(newItem);
					newItem->ItemNr = currDoc->Items->count()-1;
					newItem->setSelected(false);
					points.fromQPainterPath(path);
					newItem->PoLine = points;
					newItem->Frame = false;
					newItem->ClipEdited = true;
					newItem->FrameType = 3;
					currDoc->AdjustItemSize(newItem);
					newItem->OldB2 = newItem->width();
					newItem->OldH2 = newItem->height();
					newItem->updateClip();
					newItem->ContourLine = newItem->PoLine.copy();
					if (dia->targetColor == 2)
					{
						QString fill = dia->getOtherFillColor();
						if (fill == CommonStrings::tr_NoneColor)
							fill = CommonStrings::None;
						newItem->setFillColor(fill);
						QString stroke = dia->getOtherLineColor();
						if (stroke == CommonStrings::tr_NoneColor)
							stroke = CommonStrings::None;
						newItem->setLineColor(stroke);
					}
				}
				currDoc->m_Selection->clear();
				currDoc->view()->Deselect(true);
			}
			currDoc->changed();
			currDoc->view()->DrawNew();
		}
		delete dia;
	}
	return true;
}
void CalligraphicMode::mouseMoveEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	
	double newX, newY;
	PageItem *currItem;
	QPoint np, np2, mop;
	FPoint npf, npf2;
	QRect tx;
	m->accept();
	m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());

	if (commonMouseMove(m))
		return;
	
	if (m_MouseButtonPressed && (m_doc->appMode == modeDrawCalligraphicLine))
	{
		double newXF = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
		double newYF = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
		if (RecordP.size() > 0)
		{
			if (FPoint(newXF, newYF) != RecordP.point(RecordP.size()-1))
				RecordP.addPoint(FPoint(newXF, newYF));
		}
		else
			RecordP.addPoint(FPoint(newXF, newYF));
		QPolygon& redrawPolygon(m_canvas->newRedrawPolygon());
		double mx = sin(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0);
		double my = cos(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0);
		for (int px = 0; px < RecordP.size()-1; ++px)
		{
			FPoint clp = RecordP.point(px);
			redrawPolygon.append(QPoint(qRound(clp.x() - mx), qRound(clp.y() - my)));
			redrawPolygon.prepend(QPoint(qRound(clp.x() + mx), qRound(clp.y() + my)));
		}
		redrawPolygon.append(QPoint(qRound(RecordP.point(RecordP.size()-1).x() + mx), qRound(RecordP.point(RecordP.size()-1).y() + my)));
//FIXME		
		m_canvas->m_viewMode.operItemResizing = true;
		QRect bRect = m_canvas->redrawPolygon().boundingRect();
		m_view->updateCanvas(bRect);
		return;
	}
	
	if (GetItem(&currItem))
	{
		newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
		newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
		
		if (m_doc->DragP)
			return;
				
		if ((!m_MouseButtonPressed) && (m_doc->appMode != modeDrawBezierLine))
		{
			if (m_doc->m_Selection->isMultipleSelection())
			{
				setModeCursor();
				return;
			}
			for (int a = 0; a < m_doc->m_Selection->count(); ++a)
			{
				currItem = m_doc->m_Selection->itemAt(a);
				if (currItem->locked())
					break;
				setModeCursor();
			}
		}
	}
	else
	{
		if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
		{
			newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
			newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
			SeRx = newX;
			SeRy = newY;
			QPoint startP = m_canvas->canvasToGlobal(m_doc->appMode == modeDrawTable2 ? QPointF(Dxp, Dyp) : QPointF(Mxp, Myp));
			m_view->redrawMarker->setGeometry(QRect(m_view->mapFromGlobal(startP), m_view->mapFromGlobal(m->globalPos())).normalized());
			m_view->setRedrawMarkerShown(true);
			m_view->HaveSelRect = true;
			return;
		}
	}
}
Example #24
0
void ReplaceColor(QString col, QString rep)
{
	QColor tmpc;
	for (int c = 0; c < ScCore->primaryMainWindow()->doc->Items->count(); c++)
	{
		PageItem *ite = ScCore->primaryMainWindow()->doc->Items->at(c);
		if (ite->itemType() == PageItem::TextFrame)
		{
			for (int d = 0; d < ite->itemText.length(); d++)
			{
				//FIXME:NLS  that should work on runs
				if (col == ite->itemText.charStyle(d).fillColor())
					ite->itemText.item(d)->setFillColor(rep);
				if (col == ite->itemText.charStyle(d).strokeColor())
					ite->itemText.item(d)->setStrokeColor(rep);
			}
		}
		if (col == ite->fillColor())
			ite->setFillColor(rep);
		if (col == ite->lineColor())
			ite->setLineColor(rep);
		QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
		for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
		{
			if (col == cstops.at(cst)->name)
			{
				ite->SetQColor(&tmpc, rep, cstops.at(cst)->shade);
				cstops.at(cst)->color = tmpc;
				cstops.at(cst)->name = rep;
			}
		}
	}
	for (int c = 0; c < ScCore->primaryMainWindow()->doc->MasterItems.count(); c++)
	{
		PageItem *ite = ScCore->primaryMainWindow()->doc->MasterItems.at(c);
		if (ite->itemType() == PageItem::TextFrame)
		{
			for (int d = 0; d < ite->itemText.length(); d++)
			{
				//FIXME: NLS this should work on runs
				if (col == ite->itemText.charStyle(d).fillColor())
					ite->itemText.item(d)->setFillColor(rep);
				if (col == ite->itemText.charStyle(d).strokeColor())
					ite->itemText.item(d)->setStrokeColor(rep);
			}
		}
		if (col == ite->fillColor())
			ite->setFillColor(rep);
		if (col == ite->lineColor())
			ite->setLineColor(rep);
		QList<VColorStop*> cstops = ite->fill_gradient.colorStops();
		for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
		{
			if (col == cstops.at(cst)->name)
			{
				ite->SetQColor(&tmpc, rep, cstops.at(cst)->shade);
				cstops.at(cst)->color = tmpc;
				cstops.at(cst)->name = rep;
			}
		}
	}
}
Example #25
0
void BezierMode::mouseMoveEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	
	double newX, newY;
	PageItem *currItem;
	QPoint np, np2, mop;
	FPoint npf, npf2;
	QRect tx;
	m->accept();
	m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
//	qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
//	emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(), 
//				  m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
/*	if (m_doc->guidesPrefs().guidesShown)
	{
		if (MoveGY)
		{
			m_view->FromHRuler(m);
			return;
		}
		if (MoveGX)
		{
			m_view->FromVRuler(m);
			return;
		}
	}
*/
	
	if (commonMouseMove(m))
		return;
	
	if (inItemCreation)
	{
		if ((GetItem(&currItem)) && (!shiftSelItems))
		{
			newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
			newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
			
			if (m_doc->DragP)
				return;
			
			if (m_doc->appMode == modeDrawBezierLine)
			{
				if ((m_doc->useRaster) && (m_doc->OnPage(currItem) != -1))
				{
					newX = qRound(newX / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
					newY = qRound(newY / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
				}
				m_canvas->newRedrawPolygon() << QPoint(qRound(newX - currItem->xPos()), qRound(newY - currItem->yPos()));
				m_view->updateCanvas();
				Mxp = newX;
				Myp = newY;
			}
			
		}
		else
		{
			if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1))
			{
				newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
				newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
				SeRx = newX;
				SeRy = newY;
				/*
				if (m_doc->appMode == modeDrawTable)
					m_view->redrawMarker->setGeometry(QRect(Dxp, Dyp, m->globalPos().x() - Dxp, m->globalPos().y() - Dyp).normalized());
				else
					m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
				*/
				QPoint startP = m_canvas->canvasToGlobal(QPointF(Mxp, Myp));
				m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
				if (!m_view->redrawMarker->isVisible())
					m_view->redrawMarker->show();
				m_view->HaveSelRect = true;
				return;
			}
		}
	}
}
Example #26
0
void Imposition::booklet4p(QList<int>* pages)
{
	/*
	
	4 page imposition looks like this:
	       front:                     back:
	 --------------------       --------------------
	|         |          |     |         |          |
	|         |          |     |         |          |
	|         |          |     |         |          |
	|    4    |    1     |     |    2    |    3     |
	|         |          |     |         |          |
	|         |          |     |         |          |
	|         |          |     |         |          |
         --------------------       --------------------
	
	*/
	
	//fill the pages, so that it could be divided by for
	while ( (pages->count() % 4) != 0)
	{
		pages->append(0);
	}
	
	//create pages
	int targetSheets = (int)ceil(pages->count() / 4.0); //how many sheets do we have
	int targetPages = targetSheets * 2; //how many pages do we have
	
	targetDoc->createNewDocPages(targetPages);
	
	targetDoc->changeLayerName(0,srcDoc->layerName(0));
	for (int i = 1; i < srcDoc->layerCount(); i++)
	{
		targetDoc->addLayer(srcDoc->layerName(i));
	}
	
	//make guides
	for (int i = 0; i < targetDoc->Pages->count(); i++)
	{
		Page* p = targetDoc->Pages->at(i);
		
		//count the left guide:
		double guide_x = (p->width() - 2 * srcDoc->pageWidth)/2;
		p->guides.addVertical(guide_x, p->guides.Standard);
		
		//middle guide:
		guide_x += srcDoc->pageWidth;
		p->guides.addVertical(guide_x, p->guides.Standard);
		
		//and the right one:
		guide_x += srcDoc->pageWidth;
		p->guides.addVertical(guide_x, p->guides.Standard);
		
		//now, the top guide:
		double guide_y = (p->height() - srcDoc->pageHeight)/2;
		p->guides.addHorizontal(guide_y, p->guides.Standard);
		
		//and the bottom one:
		guide_y += srcDoc->pageHeight;
		p->guides.addHorizontal(guide_y, p->guides.Standard);
	}
	
	//start copying
	ScribusMainWindow* scMW = ScCore->primaryMainWindow();
	scMW->slotSelect();
	Selection* s = new Selection(scMW);
	
	//first, do the frontsides
	for (int i = 0; i < targetDoc->Pages->count(); i = i + 2)
	{
		targetDoc->setCurrentPage(targetDoc->Pages->at(i));
		
		//copy the page to the clipboard
		//right side
		//make selections
		for (int j = 0; j < srcDoc->Items->count(); j++)
		{
			if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1))
			{
				s->addItem(srcDoc->Items->at(j),false);
			}
			
		}
		
		if (s->count() > 0)
		{
			std::ostringstream xmlString;
			SaxXML xmlStream(xmlString);
			Serializer::serializeObjects(*s, xmlStream);
			std::string xml(xmlString.str());
			QByteArray ba(QByteArray(xml.c_str(), xml.length()));
			
			//paste page from clipboard
			
			Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba);
			
			targetDoc->moveGroup(
					targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard),
					false,
					&pastedObjects
				);
			
			
			s->clear();
			
			for (int j = 0; j < targetDoc->layerCount(); j++)
			{
				//create group out of all the items in the layer
				Selection* gs = new Selection(scMW);
				
				for (int k = 0; k < pastedObjects.count(); k++)
				{
					if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k));
				}
				
				if (gs->count() > 0)
				{
					//create group
					targetDoc->itemSelection_GroupObjects(false, false, gs);
					
					//get group control
					signed int groupid = gs->itemAt(0)->Groups.at(0);
					
					PageItem* groupcontrol = NULL;
					for (int k = 0; k < targetDoc->Items->count(); k++)
					{
						if (
							targetDoc->Items->at(k)->Groups.count() > 0 &&
							targetDoc->Items->at(k)->Groups.at(0) == groupid &&
							targetDoc->Items->at(k)->isGroupControl
						   )
						{
							groupcontrol = targetDoc->Items->at(k);
							break;
						}
					}
					groupcontrol->SetRectFrame();
					
					double points[32] = {
					//left upper corner - left lower corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					
					//left lower corner - right lower corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
							
					100,
     					100,
	  				100,
       					100,

					//right lower corner - right upper corner
					100,
					100,
					100,
					100,
							
					0,
     					100,
	  				0,
       					100,
	    
					//right upper corner - left upper corner
					0,
					100,
					0,
					100,
					
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					};
					
					double groupX = groupcontrol->xPos();
					double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset();
					
					double groupWidth = groupcontrol->width();
					double groupHeight = groupcontrol->height();
					
					qDebug() << groupX << groupY << groupWidth << groupHeight;
					
					for (int k = 0; k < 12; k += 2)
					{
						if  (points[k] < groupX)
						{
							points[k] = 0;
						}
						else if (points[k] - groupX > 100)
						{
							points[k] = 100;
						}
						else
						{
							points[k] = 100* (points[k] - groupX) / groupWidth;
						}
						
						if (points[k+1] < groupY)
						{
							points[k+1] = 0;
						}
						else if (points[k+1] - groupY > 100)
						{
							points[k+1] = 100;
						}
						else
						{
							points[k+1] = 100* (points[k+1] - groupY) / groupHeight;
						}
						
						qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n";
						qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n";
					}
					
					for (int k = 28; k < 32; k += 2)
					{
						if  (points[k] < groupX)
						{
							points[k] = 0;
						}
						else if (points[k] - groupX > 100)
						{
							points[k] = 100;
						}
						else
						{
							points[k] = 100* (points[k] - groupX) / groupWidth;
						}
						
						if (points[k+1] < groupY)
						{
							points[k+1] = 0;
						}
						else if (points[k+1] - groupY > 100)
						{
							points[k+1] = 100;
						}
						else
						{
							points[k+1] = 100* (points[k+1] - groupY) / groupHeight;
						}
						
						qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n";
						qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n";
					}

					groupcontrol->SetFrameShape(32,points);					
				}
			}
		
		}
		
		//left side
		for (int j = 0; j < srcDoc->Items->count(); j++)
		{
			if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1))
			{
				s->addItem(srcDoc->Items->at(j),false);
			}
		
		}
		
		if (s->count() > 0)
		{
			std::ostringstream xmlString;
			SaxXML xmlStream(xmlString);
			Serializer::serializeObjects(*s, xmlStream);
			std::string xml(xmlString.str());
			QByteArray ba(QByteArray(xml.c_str(), xml.length()));
			
			//paste page from clipboard
			
			Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba);
			
			targetDoc->moveGroup(
					targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard),
					false,
					&pastedObjects
				       );
			s->clear();
			
			//clipping layerwise
			for (int j = 0; j < targetDoc->layerCount(); j++)
			{
				//create group out of all the items in the layer
				Selection* gs = new Selection(scMW);
				
				for (int k = 0; k < pastedObjects.count(); k++)
				{
					if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k));
				}
				
				if (gs->count() > 0)
				{
					//create group
					targetDoc->itemSelection_GroupObjects(false, false, gs);
					
					//get group control
					signed int groupid = gs->itemAt(0)->Groups.at(0);
					
					PageItem* groupcontrol = NULL;
					for (int k = 0; k < targetDoc->Items->count(); k++)
					{
						if (
							targetDoc->Items->at(k)->Groups.count() > 0 &&
							targetDoc->Items->at(k)->Groups.at(0) == groupid &&
							targetDoc->Items->at(k)->isGroupControl
						   )
						{
							groupcontrol = targetDoc->Items->at(k);
							break;
						}
					}
					groupcontrol->SetRectFrame();
					
					double points[32] = {
					//left upper corner - left lower corner
					0,
					0,
					0,
					0,
					
					0,
					100,
					0,
					100,
					
					//left lower corner - right lower corner
					0,
					100,
					0,
					100,
							
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),

					//right lower corner - right upper corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
							
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),

					//right upper corner - left upper corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					
					0,
					0,
					0,
					0
					};
					
					double groupX = groupcontrol->xPos();
					double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset();
					
					double groupWidth = groupcontrol->width();
					double groupHeight = groupcontrol->height();
					
					qDebug() << groupX << groupY << groupWidth << groupHeight;
					
					for (int k = 13; k < 28; k += 2)
					{
						if  (points[k] < groupX)
						{
							points[k] = 0;
						}
						else if (points[k] - groupX > 100)
						{
							points[k] = 100;
						}
						else
						{
							points[k] = 100* (points[k] - groupX) / groupWidth;
						}
						
						if (points[k+1] < groupY)
						{
							points[k+1] = 0;
						}
						else if (points[k+1] - groupY > 100)
						{
							points[k+1] = 100;
						}
						else
						{
							points[k+1] = 100* (points[k+1] - groupY) / groupHeight;
						}
						
						qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n";
						qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n";
					}
					
					groupcontrol->SetFrameShape(32,points);					
				}
			}
		}
	}
	
	//backsides
	for (int i = 1; i < targetDoc->Pages->count(); i = i + 2)
	{
		targetDoc->setCurrentPage(targetDoc->Pages->at(i));
		
		//copy the page to the clipboard
		//left side
		//make selections
		for (int j = 0; j < srcDoc->Items->count(); j++)
		{
			if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(i)-1))
			{
				s->addItem(srcDoc->Items->at(j),false);
			}
			
		}
		
		if (s->count() > 0)
		{
			std::ostringstream xmlString;
			SaxXML xmlStream(xmlString);
			Serializer::serializeObjects(*s, xmlStream);
			std::string xml(xmlString.str());
			QByteArray ba(QByteArray(xml.c_str(), xml.length()));
			
			//paste page from clipboard
			
			Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba);
			
			targetDoc->moveGroup(
					targetDoc->Pages->at(i)->guides.vertical(0, targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard),
					false,
				       &pastedObjects
				       );
			s->clear();
			
			//clipping layerwise
			for (int j = 0; j < targetDoc->layerCount(); j++)
			{
				//create group out of all the items in the layer
				Selection* gs = new Selection(scMW);
				
				for (int k = 0; k < pastedObjects.count(); k++)
				{
					if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k));
				}
				
				if (gs->count() > 0)
				{
					//create group
					targetDoc->itemSelection_GroupObjects(false, false, gs);
					
					//get group control
					signed int groupid = gs->itemAt(0)->Groups.at(0);
					
					PageItem* groupcontrol = NULL;
					for (int k = 0; k < targetDoc->Items->count(); k++)
					{
						if (
							targetDoc->Items->at(k)->Groups.count() > 0 &&
							targetDoc->Items->at(k)->Groups.at(0) == groupid &&
							targetDoc->Items->at(k)->isGroupControl
						   )
						{
							groupcontrol = targetDoc->Items->at(k);
							break;
						}
					}
					groupcontrol->SetRectFrame();
					
					double points[32] = {
					//left upper corner - left lower corner
					0,
					0,
					0,
					0,
					
					0,
					100,
					0,
					100,
					
					//left lower corner - right lower corner
					0,
					100,
					0,
					100,
							
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),

					//right lower corner - right upper corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
							
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),

					//right upper corner - left upper corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					
					0,
					0,
					0,
					0
					};
					
					double groupX = groupcontrol->xPos();
					double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset();
					
					double groupWidth = groupcontrol->width();
					double groupHeight = groupcontrol->height();
					
					qDebug() << groupX << groupY << groupWidth << groupHeight;
					
					for (int k = 13; k < 28; k += 2)
					{
						if  (points[k] < groupX)
						{
							points[k] = 0;
						}
						else if (points[k] - groupX > 100)
						{
							points[k] = 100;
						}
						else
						{
							points[k] = 100* (points[k] - groupX) / groupWidth;
						}
						
						if (points[k+1] < groupY)
						{
							points[k+1] = 0;
						}
						else if (points[k+1] - groupY > 100)
						{
							points[k+1] = 100;
						}
						else
						{
							points[k+1] = 100* (points[k+1] - groupY) / groupHeight;
						}
						
						qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n";
						qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n";
					}
					
					groupcontrol->SetFrameShape(32,points);					
				}
			}
		}
		
		//right side
		for (int j = 0; j < srcDoc->Items->count(); j++)
		{
			if (srcDoc->OnPage(srcDoc->Items->at(j)) == (pages->at(pages->count()-i-1)-1))
			{
				s->addItem(srcDoc->Items->at(j),false);
			}
		
		}
		
		if (s->count() > 0)
		{
			std::ostringstream xmlString;
			SaxXML xmlStream(xmlString);
			Serializer::serializeObjects(*s, xmlStream);
			std::string xml(xmlString.str());
			QByteArray ba(QByteArray(xml.c_str(), xml.length()));
			
			//paste page from clipboard
			
			Selection pastedObjects = Serializer(*targetDoc).deserializeObjects(ba);
			
			targetDoc->moveGroup(
					targetDoc->Pages->at(i)->guides.vertical(1, targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(i)->guides.horizontal(0, targetDoc->Pages->at(i)->guides.Standard),
					false,
					&pastedObjects
				       );
			s->clear();
			
			for (int j = 0; j < targetDoc->layerCount(); j++)
			{
				//create group out of all the items in the layer
				Selection* gs = new Selection(scMW);
				
				for (int k = 0; k < pastedObjects.count(); k++)
				{
					if (pastedObjects.itemAt(k)->LayerNr == j) gs->addItem(pastedObjects.itemAt(k));
				}
				
				if (gs->count() > 0)
				{
					//create group
					targetDoc->itemSelection_GroupObjects(false, false, gs);
					
					//get group control
					signed int groupid = gs->itemAt(0)->Groups.at(0);
					
					PageItem* groupcontrol = NULL;
					for (int k = 0; k < targetDoc->Items->count(); k++)
					{
						if (
							targetDoc->Items->at(k)->Groups.count() > 0 &&
							targetDoc->Items->at(k)->Groups.at(0) == groupid &&
							targetDoc->Items->at(k)->isGroupControl
						   )
						{
							groupcontrol = targetDoc->Items->at(k);
							break;
						}
					}
					groupcontrol->SetRectFrame();
					
					double points[32] = {
					//left upper corner - left lower corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					
					//left lower corner - right lower corner
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(1,targetDoc->Pages->at(i)->guides.Standard),
							
					100,
     					100,
	  				100,
       					100,

					//right lower corner - right upper corner
					100,
					100,
					100,
					100,
							
					0,
     					100,
	  				0,
       					100,
	    
					//right upper corner - left upper corner
					0,
					100,
					0,
					100,
					
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					targetDoc->Pages->at(0)->guides.vertical(1,targetDoc->Pages->at(0)->guides.Standard),
					targetDoc->Pages->at(0)->guides.horizontal(0,targetDoc->Pages->at(i)->guides.Standard),
					};
					
					double groupX = groupcontrol->xPos();
					double groupY = groupcontrol->yPos() - targetDoc->Pages->at(i)->yOffset();
					
					double groupWidth = groupcontrol->width();
					double groupHeight = groupcontrol->height();
					
					qDebug() << groupX << groupY << groupWidth << groupHeight;
					
					for (int k = 0; k < 12; k += 2)
					{
						if  (points[k] < groupX)
						{
							points[k] = 0;
						}
						else if (points[k] - groupX > 100)
						{
							points[k] = 100;
						}
						else
						{
							points[k] = 100* (points[k] - groupX) / groupWidth;
						}
						
						if (points[k+1] < groupY)
						{
							points[k+1] = 0;
						}
						else if (points[k+1] - groupY > 100)
						{
							points[k+1] = 100;
						}
						else
						{
							points[k+1] = 100* (points[k+1] - groupY) / groupHeight;
						}
						
						qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n";
						qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n";
					}
					
					for (int k = 28; k < 32; k += 2)
					{
						if  (points[k] < groupX)
						{
							points[k] = 0;
						}
						else if (points[k] - groupX > 100)
						{
							points[k] = 100;
						}
						else
						{
							points[k] = 100* (points[k] - groupX) / groupWidth;
						}
						
						if (points[k+1] < groupY)
						{
							points[k+1] = 0;
						}
						else if (points[k+1] - groupY > 100)
						{
							points[k+1] = 100;
						}
						else
						{
							points[k+1] = 100* (points[k+1] - groupY) / groupHeight;
						}
						
						qDebug() << "IMPOSITION: points[" << k << "] " << points[i] << "\n";
						qDebug() << "IMPOSITION: points[" << k+1 << "] " << points[i+1] << "\n";
					}

					groupcontrol->SetFrameShape(32,points);					
				}
			}

		}
		
	}

}
Example #27
0
void BezierMode::mouseReleaseEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	

	PageItem *currItem;
	m_MouseButtonPressed = false;
	m_canvas->resetRenderMode();
	m->accept();
//	m_view->stopDragTimer();
	
	m_canvas->setRenderModeUseBuffer(false);
	if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::LeftButton))
	{
		m_canvas->setRenderModeUseBuffer(true);
		currItem = m_doc->m_Selection->itemAt(0);
		currItem->ClipEdited = true;
		currItem->FrameType = 3;
		QTransform pm = currItem->getTransform();
		FPoint npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true);
		currItem->PoLine.addPoint(npf);
		bool ssiz = currItem->Sizing;
		currItem->Sizing = true;
		if ((currItem->PoLine.size() % 4 == 0) && (currItem->PoLine.size() > 3))
		{
			FPoint lxy(currItem->PoLine.point(currItem->PoLine.size()-2));
			FPoint lk(currItem->PoLine.point(currItem->PoLine.size()-1));
			double dx = lxy.x() - lk.x();
			double dy = lxy.y() - lk.y();
			lk.setX(lk.x() + dx*2);
			lk.setY(lk.y() + dy*2);
			currItem->PoLine.addPoint(lxy);
			currItem->PoLine.addPoint(lk);
		}
		FPoint np2(getMinClipF(&currItem->PoLine));
		if (np2.x() < 0)
		{
			currItem->PoLine.translate(-np2.x(), 0);
			m_doc->MoveItem(np2.x(), 0, currItem);
		}
		if (np2.y() < 0)
		{
			currItem->PoLine.translate(0, -np2.y());
			m_doc->MoveItem(0, np2.y(), currItem);
		}
		if (FirstPoly)
		{
			FirstPoly = false;
			currItem->Sizing = ssiz;
		}
		else
		{
			m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
			m_doc->AdjustItemSize(currItem);
			currItem->Sizing = ssiz;
			currItem->ContourLine = currItem->PoLine.copy();
			m_canvas->setRenderModeUseBuffer(false);
			currItem->update();
		}
		m_canvas->setRenderModeFillBuffer();
		int newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
		int newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
		m_canvas->newRedrawPolygon() << QPoint(newX - qRound(currItem->xPos()), newY - qRound(currItem->yPos()));
		m_view->updateCanvas();
	}
	if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::RightButton))
	{
		currItem = m_doc->m_Selection->itemAt(0);
		if (currItem!=0)
		{
			finalizeItem(currItem);
		}
		
		if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools)
		{
//			qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
			m_view->requestMode(modeNormal);
//			m_view->requestMode(submodePaintingDone);
		}
		else
			m_view->requestMode(m_doc->appMode);
		m_doc->changed();
//		emit DocChanged();
		FirstPoly = true;
		inItemCreation = false;
		m_canvas->setRenderModeUseBuffer(false);
//		m_view->updateContents();
	}
	m_doc->DragP = false;
	m_doc->leaveDrag = false;
//	m_canvas->m_viewMode.operItemResizing = false;
	m_view->MidButt = false;
	shiftSelItems = false;
//	m_doc->SubMode = -1;
	if (m_view->groupTransactionStarted())
	{
		for (int i = 0; i < m_doc->m_Selection->count(); ++i)
			m_doc->m_Selection->itemAt(i)->checkChanges(true);
		m_view->endGroupTransaction();
	}

//???	for (int i = 0; i < m_doc->m_Selection->count(); ++i)
//???		m_doc->m_Selection->itemAt(i)->checkChanges(true);

//	//Commit drag created items to undo manager.
//	if (m_doc->m_Selection->itemAt(0)!=NULL)
//	{
//		m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr);
//	}
	//Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
	m_view->zoomSpinBox->clearFocus();
	m_view->pageSelector->clearFocus();
	if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
	{
		currItem = m_doc->m_Selection->itemAt(0);
		m_doc->nodeEdit.finishTransaction(currItem);
	}
	else
	{
		//delete oldClip;
		//oldClip = 0;
	}
}
Example #28
0
void ContextMenu::createMenuItems_Selection()
{
	//CB TODO clean
	int selectedItemCount=m_Sel.count();
	if (selectedItemCount==0)
		return;
	bool itemsAreSameType=m_Sel.itemsAreSameType();
	//Find our doc from first item in selection if we have an item
	PageItem *currItem = m_Sel.itemAt(0);
	assert(m_doc!=0 && currItem!=0);
	
	QMenu *menuConvertTo = new QMenu(this);
	QMenu *menuEditContent = new QMenu(this);
	QMenu *menuInfo = new QMenu(this);
	QMenu *menuLayer = new QMenu(this);
	QMenu *menuLevel = new QMenu(this);
	QMenu *menuPDF = new QMenu(this);
	QMenu *menuMark = new QMenu(this);
	QMenu *menuResolution = new QMenu(this);
	QMenu *menuLocking = new QMenu(this);
	QMenu *menuSendTo = new QMenu(this);
	QMenu *menuScrapbook = new QMenu(this);
	QMenu *menuEdit = new QMenu(this);
	QMenu *menuImage = new QMenu(this);
//	QMenu *menuWeld = new QMenu(this);

	//<-- Add Info
	//Test new method with image frames first
	if (selectedItemCount==1 && currItem->asImageFrame())
	{
		QAction *act = addMenu(menuInfo);
		act->setText( tr("In&fo"));
		if (currItem->asImageFrame())
		{
			QLabel* menuLabel = new QLabel("<html>" + currItem->infoDescription() + "</html>", this);
			menuLabel->setFrameShape(QFrame::NoFrame);
			QWidgetAction* menuTextWidget = new QWidgetAction(this);
			menuTextWidget->setDefaultWidget(menuLabel);
			menuInfo->addAction(menuTextWidget);
		}
	}
	else
	{
		QFrame *infoGroup = new QFrame( m_doc->view() );
		infoGroup->setFrameShape( QFrame::NoFrame );
		QGridLayout *infoGroupLayout = new QGridLayout( infoGroup );
		infoGroupLayout->setAlignment( Qt::AlignTop );
		infoGroupLayout->setSpacing( 2 );
		infoGroupLayout->setMargin( 0 );
		if (currItem->createInfoGroup(infoGroup, infoGroupLayout)) 
		{
			int row = infoGroupLayout->rowCount(); // <a.l.e>
	
			QLabel *printCT = new QLabel(infoGroup);
			QLabel *printT = new QLabel(infoGroup);
			printCT->setText( tr("Print: "));
			infoGroupLayout->addWidget( printCT, row, 0, Qt::AlignRight );
			if (currItem->printEnabled())
				printT->setText( tr("Enabled"));
			else
				printT->setText( tr("Disabled"));
			infoGroupLayout->addWidget( printT, row, 1 ); // </a.l.e>
					
			QWidgetAction* MenAct = new QWidgetAction(this);
			MenAct->setDefaultWidget(infoGroup);
			menuInfo->addAction(MenAct);
	
	// Qt4				menuInfo->insertItem(infoGroup);
//			currItem->createContextMenu(menuInfo, 5);
			QAction *act = addMenu(menuInfo);
			act->setText( tr("In&fo"));
		}
		else
		{
			delete infoGroupLayout;
			delete infoGroup;
		}
	}
	//-->

	//<-- Add Contents Actions
	if (m_actionList.contains("fileImportText"))
	{
		addSeparator();
		menuEditContent->addAction(m_ScMW->scrActions["fileImportText"]);
		menuEditContent->addAction(m_ScMW->scrActions["fileImportAppendText"]);
		menuEditContent->addAction(m_ScMW->scrActions["toolsEditWithStoryEditor"]);
		menuEditContent->addAction(m_ScMW->scrActions["insertSampleText"]);
		menuEditContent->addSeparator();
	}
	else //enable this for, eg, text on a path
		if (m_actionList.contains("toolsEditWithStoryEditor"))
		{
			addSeparator();
			menuEditContent->addAction(m_ScMW->scrActions["toolsEditWithStoryEditor"]);
		}
	if (m_actionList.contains("fileImportImage"))
		menuEditContent->addAction(m_ScMW->scrActions["fileImportImage"]);
	if (selectedItemCount==1 && currItem->asImageFrame())
	{
		if (QApplication::clipboard()->mimeData()->hasImage())
			menuEditContent->addAction(m_ScMW->scrActions["editPasteImageFromClipboard"]);
	}
	if (itemsAreSameType)
	{
		if (m_actionList.contains("editCopyContents"))
			menuEditContent->addAction(m_ScMW->scrActions["editCopyContents"]);
		if (m_actionList.contains("editPasteContents"))
			menuEditContent->addAction(m_ScMW->scrActions["editPasteContents"]);
		if (currItem->asImageFrame() && m_actionList.contains("editPasteContentsAbs"))
			menuEditContent->addAction(m_ScMW->scrActions["editPasteContentsAbs"]);
	}
	if (m_actionList.contains("editClearContents"))
		menuEditContent->addAction(m_ScMW->scrActions["editClearContents"]);
	if (m_actionList.contains("editTruncateContents"))
		menuEditContent->addAction(m_ScMW->scrActions["editTruncateContents"]);
	if (menuEditContent->actions().count()>0)
	{
		QAction *act = addMenu(menuEditContent);
		act->setText( tr("Content"));
	}
	//-->

	//<-- Item specific actions
	if (itemsAreSameType)
	{
		if (m_actionList.contains("editEditRenderSource"))
		{
			addSeparator();
#ifdef HAVE_OSG
			if (currItem->isOSGFrame())
			{
				QAction *act = addAction( tr("Edit 3D Annotation..."));
				connect(act, SIGNAL(triggered()), m_ScMW, SLOT(callImageEditor()));
			}
			else
				addAction(m_ScMW->scrActions["editEditRenderSource"]);
#else
			addAction(m_ScMW->scrActions["editEditRenderSource"]);
#endif
		}
		if (m_doc->appMode == modeEdit)
		{
			//add actions for marks in edit mode
			addSeparator();
			QAction *act2 = addMenu(menuMark);
			act2->setText( tr("Insert Mark"));
			menuMark->addAction(m_ScMW->scrActions["insertMarkVariableText"]);
			if (m_actionList.contains("insertMarkAnchor"))
			{
				menuMark->addAction(m_ScMW->scrActions["insertMarkAnchor"]);
				menuMark->addAction(m_ScMW->scrActions["insertMarkItem"]);
				menuMark->addAction(m_ScMW->scrActions["insertMark2Mark"]);
				if (!currItem->isNoteFrame())
					menuMark->addAction(m_ScMW->scrActions["insertMarkNote"]);
				//	menuMark->addAction(m_AP->scrActions["insertMarkIndex"]);
			}
			if (currItem->itemText.cursorPosition() < currItem->itemText.length())
			{
				if (currItem->itemText.hasMark(currItem->itemText.cursorPosition()))
					addAction(m_ScMW->scrActions["editMark"]);
			}
		}
		if (!m_doc->marksList().isEmpty())
		{
			addSeparator();
			addAction(m_ScMW->scrActions["itemUpdateMarks"]);
		}





		addSeparator();



		if (m_actionList.contains("tableInsertRows"))
			addAction(m_ScMW->scrActions["tableInsertRows"]);
		if (m_actionList.contains("tableInsertColumns"))
			addAction(m_ScMW->scrActions["tableInsertColumns"]);
		if (m_actionList.contains("tableDeleteRows"))
			addAction(m_ScMW->scrActions["tableDeleteRows"]);
		if (m_actionList.contains("tableDeleteColumns"))
			addAction(m_ScMW->scrActions["tableDeleteColumns"]);
		if (m_actionList.contains("tableMergeCells"))
			addAction(m_ScMW->scrActions["tableMergeCells"]);
		if (m_actionList.contains("tableSplitCells"))
			addAction(m_ScMW->scrActions["tableSplitCells"]);
		if (m_actionList.contains("tableSetRowHeights"))
			addAction(m_ScMW->scrActions["tableSetRowHeights"]);
		if (m_actionList.contains("tableSetColumnWidths"))
			addAction(m_ScMW->scrActions["tableSetColumnWidths"]);
		if (m_actionList.contains("tableDistributeRowsEvenly"))
			addAction(m_ScMW->scrActions["tableDistributeRowsEvenly"]);
		if (m_actionList.contains("tableDistributeColumnsEvenly"))
			addAction(m_ScMW->scrActions["tableDistributeColumnsEvenly"]);
		if (m_actionList.contains("tableAdjustFrameToTable"))
			addAction(m_ScMW->scrActions["tableAdjustFrameToTable"]);
		if (m_actionList.contains("tableAdjustTableToFrame"))
			addAction(m_ScMW->scrActions["tableAdjustTableToFrame"]);
		if (m_actionList.contains("itemAdjustFrameHeightToText"))
			addAction(m_ScMW->scrActions["itemAdjustFrameHeightToText"]);

		
		if (m_actionList.contains("itemPreviewLow"))
		{
			if (m_actionList.contains("itemImageIsVisible"))
				menuResolution->addAction(m_ScMW->scrActions["itemImageIsVisible"]);
			menuResolution->addSeparator();
			if (m_actionList.contains("itemPreviewFull"))
				menuResolution->addAction(m_ScMW->scrActions["itemPreviewFull"]);
			if (m_actionList.contains("itemPreviewNormal"))
				menuResolution->addAction(m_ScMW->scrActions["itemPreviewNormal"]);
			if (m_actionList.contains("itemPreviewLow"))
				menuResolution->addAction(m_ScMW->scrActions["itemPreviewLow"]);
			if (menuResolution->actions().count()>0)
			{
				QAction *act = addMenu(menuResolution);
				act->setText( tr("Preview Settings"));
			}
		}
		
		if (m_actionList.contains("styleImageEffects"))
			menuImage->addAction(m_ScMW->scrActions["styleImageEffects"]);
		if (m_actionList.contains("editEditWithImageEditor"))
			menuImage->addAction(m_ScMW->scrActions["editEditWithImageEditor"]);
		if (selectedItemCount==1 && currItem->asImageFrame())
		{
			if (currItem->imageIsAvailable)
			{
				if (m_actionList.contains("itemExtendedImageProperties"))
					menuImage->addAction(m_ScMW->scrActions["itemExtendedImageProperties"]);
				if (m_actionList.contains("itemAdjustFrameToImage"))
				{
					if (currItem->imageIsAvailable)
						menuImage->addAction(m_ScMW->scrActions["itemToggleInlineImage"]);
				}
				if (m_actionList.contains("itemImageInfo"))
					menuImage->addAction(m_ScMW->scrActions["itemImageInfo"]);
				if (m_actionList.contains("itemUpdateImage"))
					menuImage->addAction(m_ScMW->scrActions["itemUpdateImage"]);
				if (m_actionList.contains("itemAdjustFrameToImage"))
					menuImage->addAction(m_ScMW->scrActions["itemAdjustFrameToImage"]);
				if (m_actionList.contains("itemAdjustImageToFrame"))
					menuImage->addAction(m_ScMW->scrActions["itemAdjustImageToFrame"]);
				m_ScMW->scrActions["itemAdjustFrameToImage"]->setEnabled(true);
				m_ScMW->scrActions["itemAdjustImageToFrame"]->setEnabled(true);
				if (currItem->pixm.imgInfo.valid)
					m_ScMW->scrActions["itemExtendedImageProperties"]->setEnabled(true);
				if (currItem->pixm.imgInfo.exifDataValid)
					m_ScMW->scrActions["itemImageInfo"]->setEnabled(true);
				m_ScMW->scrActions["itemUpdateImage"]->setEnabled(true);
				if (currItem->isRaster)
				{
					m_ScMW->scrActions["styleImageEffects"]->setEnabled(true);
					m_ScMW->scrActions["editEditWithImageEditor"]->setEnabled(true);
				}


				if (menuImage->actions().count()>0)
				{
					QAction *act = addMenu(menuImage);
					act->setText( tr("Image"));
				}
			}
		}
		
		if ((selectedItemCount==1) && currItem->asTextFrame())
		{
			if (currItem->itemText.length() > 0)
				m_ScMW->scrActions["itemAdjustFrameHeightToText"]->setEnabled(true);
		}
	}
	//-->




	addSeparator();

	
	if (selectedItemCount>0)
	{
		//<-- Item Locking
		menuLocking->addAction(m_ScMW->scrActions["itemLock"]);
		menuLocking->addAction(m_ScMW->scrActions["itemLockSize"]);
		QAction *actL = addMenu(menuLocking);
		actL->setText( tr("Locking"));
		//-->

		//<-- Send To
		QAction *actST = addMenu(menuSendTo);
		actST->setText( tr("Send to"));
		QAction *actScr = menuSendTo->addMenu(menuScrapbook);
		actScr->setText( tr("Scrapbook"));
		menuSendTo->addAction(m_ScMW->scrActions["itemSendToPattern"]);
		menuSendTo->addAction(m_ScMW->scrActions["itemSendToInline"]);

		QStringList scrapNames = m_ScMW->scrapbookNames();
		scrapNames.removeAt(1);
		for (int i = 0; i < scrapNames.count(); i++)
		{
			ScrAction *act = new ScrAction( ScrAction::DataInt, QPixmap(), QPixmap(), scrapNames[i], QKeySequence(), this, i);
			menuScrapbook->addAction(act);
			connect(act, SIGNAL(triggeredData(int)), m_ScMW, SLOT(PutScrap(int)));
		}

		if (m_doc->layerCount() > 1)
		{
			QMap<int,int> layerMap;
			for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)
				layerMap.insert((*it).Level, (*it).ID);
			int i=layerMap.count()-1;
			while (i>=0)
			{
				if (m_doc->layerLocked(layerMap[i]))
					m_ScMW->scrLayersActions[QString::number(layerMap[i])]->setEnabled(false);
				else
					m_ScMW->scrLayersActions[QString::number(layerMap[i])]->setEnabled(true);
				QPixmap pm(20,15);
				pm.fill(m_doc->layerMarker(layerMap[i]));
				m_ScMW->scrLayersActions[QString::number(layerMap[i])]->setIcon(pm);
				menuLayer->addAction(m_ScMW->scrLayersActions[QString::number(layerMap[i--])]);
			}
			QAction *act = addMenu(menuLayer);
			act->setText( tr("Send to La&yer"));
		}
		//-->
	}


	//<-- Add Groups Items
	if (selectedItemCount > 1)
	{
		if (m_Sel.objectsLayer() != -1)
			addAction(m_ScMW->scrActions["itemGroup"]);
	}
	else
	{
		if (currItem->isGroup())
		{
			addAction(m_ScMW->scrActions["itemUngroup"]);
			addAction(m_ScMW->scrActions["itemGroupAdjust"]);
		}
	}
	//-->

	//<-- Add Level Items
	if (!currItem->locked())
	{
		menuLevel->addAction(m_ScMW->scrActions["itemRaise"]);
		menuLevel->addAction(m_ScMW->scrActions["itemLower"]);
		menuLevel->addAction(m_ScMW->scrActions["itemRaiseToTop"]);
		menuLevel->addAction(m_ScMW->scrActions["itemLowerToBottom"]);
		if (menuLevel->actions().count()>0)
		{
			QAction *act = addMenu(menuLevel);
			act->setText( tr("Le&vel"));
		}
	}
	//-->
	
	//<-- Add Convert To Items
	if (m_doc->appMode != modeEdit && (itemsAreSameType || currItem->isSingleSel)) //Create convertTo Menu
	{
		if (m_ScMW->scrActions["itemConvertToBezierCurve"]->isEnabled() && m_actionList.contains("itemConvertToBezierCurve"))
			menuConvertTo->addAction(m_ScMW->scrActions["itemConvertToBezierCurve"]);
		if (m_ScMW->scrActions["itemConvertToImageFrame"]->isEnabled() && m_actionList.contains("itemConvertToImageFrame"))
			menuConvertTo->addAction(m_ScMW->scrActions["itemConvertToImageFrame"]);
		if (m_ScMW->scrActions["itemConvertToOutlines"]->isEnabled() && m_actionList.contains("itemConvertToOutlines"))
			menuConvertTo->addAction(m_ScMW->scrActions["itemConvertToOutlines"]);
		if (m_ScMW->scrActions["itemConvertToPolygon"]->isEnabled() && m_actionList.contains("itemConvertToPolygon"))
			menuConvertTo->addAction(m_ScMW->scrActions["itemConvertToPolygon"]);
		if (m_ScMW->scrActions["itemConvertToTextFrame"]->isEnabled() && m_actionList.contains("itemConvertToTextFrame"))
			menuConvertTo->addAction(m_ScMW->scrActions["itemConvertToTextFrame"]);
		if (m_ScMW->scrActions["itemConvertToSymbolFrame"]->isEnabled() && !currItem->isSymbol())
			menuConvertTo->addAction(m_ScMW->scrActions["itemConvertToSymbolFrame"]);
		if (menuConvertTo->actions().count()>0)
		{
			QAction *act = addMenu(menuConvertTo);
			act->setText( tr("Conve&rt to"));
		}
	}
	//-->
	//<-- Item Attributes
	if (selectedItemCount == 1)
	{
		addSeparator();
		addAction(m_ScMW->scrActions["itemAttributes"]);
	}
	//-->

	//<-- Item PDF Options
	if (currItem->itemType() == PageItem::TextFrame)
	{
		QAction *act = addMenu(menuPDF);
		act->setText( tr("&PDF Options"));
		menuPDF->addAction(m_ScMW->scrActions["itemPDFIsAnnotation"]);
		if (!m_doc->masterPageMode())
			menuPDF->addAction(m_ScMW->scrActions["itemPDFIsBookmark"]);
		if (selectedItemCount == 1)
		{
			menuPDF->addSeparator();
			if (m_actionList.contains("itemPDFAnnotationProps"))
				menuPDF->addAction(m_ScMW->scrActions["itemPDFAnnotationProps"]);
			if (m_actionList.contains("itemPDFFieldProps"))
				menuPDF->addAction(m_ScMW->scrActions["itemPDFFieldProps"]);
		}
	}
	//-->
	//<<-- Edit Menu
	addSeparator();
	//<-- Add Copy/Paste Actions
	if (!currItem->locked() && !(currItem->isSingleSel))
		menuEdit->addAction(m_ScMW->scrActions["editCut"]);
	if (!(currItem->isSingleSel))
		menuEdit->addAction(m_ScMW->scrActions["editCopy"]);
	if (((m_doc->appMode == modeEdit && currItem->itemType() == PageItem::TextFrame) || (m_doc->appMode == modeEditTable && currItem->itemType() == PageItem::Table)) && (ScMimeData::clipboardHasScribusText()||ScMimeData::clipboardHasPlainText()) )
		menuEdit->addAction(m_ScMW->scrActions["editPaste"]);
	if (!currItem->locked() && (m_doc->appMode != modeEdit)  && (m_doc->appMode != modeEditTable) && (!(currItem->isSingleSel)))
		menuEdit->addAction(m_ScMW->scrActions["itemDelete"]);
	//-->
	//<-- Add undo
	UndoManager * const undoManager(UndoManager::instance());
	if (undoManager->hasUndoActions())
		menuEdit->addAction(m_ScMW->scrActions["editUndoAction"]);
	if (undoManager->hasRedoActions())
		menuEdit->addAction(m_ScMW->scrActions["editRedoAction"]);
	QAction *actEdit = addMenu(menuEdit);
	actEdit->setText( tr("Edit"));
	//-->
	//-->
	
	//<-- Add Welding Menu
	addSeparator();
	if (selectedItemCount > 0 && m_doc->appMode != modeEdit)
	{
		PageItem *currItem;
		for (int a = 0; a < m_Sel.count(); ++a)
		{
			currItem = m_Sel.itemAt(a);
			if (currItem->isWelded())
			{
				addAction(m_ScMW->scrActions["itemsUnWeld"]);
				break;
			}
		}
	}
	if (selectedItemCount == 2 && m_doc->appMode != modeEdit)
		addAction(m_ScMW->scrActions["itemWeld"]);
//	{
//		menuWeld->addAction(m_AP->scrActions["itemWeld17"]);
//		menuWeld->addAction(m_AP->scrActions["itemWeld71"]);
//		menuWeld->addAction(m_AP->scrActions["itemWeld13"]);
//		menuWeld->addAction(m_AP->scrActions["itemWeld31"]);
//		QAction *act = addMenu(menuWeld);
//		act->setText( tr("Weld to last..."));
//	}
	//-->
	
	//<-- Add Properties
	addSeparator();
	addAction(m_ScMW->scrActions["toolsProperties"]);
	//-->

}
Example #29
0
PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
{
	char *Name = const_cast<char*>("");
	PyObject *il;
	// FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
	if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
		return NULL;
	if(!checkHaveDocument())
		return NULL;
	int len = PyList_Size(il);
	if (len < 8)
	{
		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error").toLocal8Bit().constData());
		return NULL;
	}
	if ((len % 6) != 0)
	{
		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error").toLocal8Bit().constData());
		return NULL;
	}
//	if (ItemExists(QString::fromUtf8(Name)))
//	{
//		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData());
//		return NULL;
//	}
	double x, y, w, h, kx, ky, kx2, ky2;
	int i = 0;
	x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
	i++;
	//int ic = ScCore->primaryMainWindow()->view->PaintPolyLine(x, y, 1, 1,	ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen);
	int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,	ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor, true);
	PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
	it->PoLine.resize(2);
	it->PoLine.setPoint(0, 0, 0);
	it->PoLine.setPoint(1, kx-x, ky-y);
	int pp = 6;
	for (i = 6; i < len - 6; i += 6)
	{
		w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
		h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
		kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
		ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
		kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
		ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
		it->PoLine.resize(pp);
		it->PoLine.setPoint(pp-4, w-x, h-y);
		it->PoLine.setPoint(pp-3, kx-x, ky-y);
		it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
		it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
		pp += 4;
	}
	pp -= 2;
	w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
	h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
	kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
	ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
	it->PoLine.resize(pp);
	it->PoLine.setPoint(pp-2, w-x, h-y);
	it->PoLine.setPoint(pp-1, kx-x, ky-y);
	FPoint np2 = getMinClipF(&it->PoLine);
	if (np2.x() < 0)
	{
		it->PoLine.translate(-np2.x(), 0);
		ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
	}
	if (np2.y() < 0)
	{
		it->PoLine.translate(0, -np2.y());
		ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
	}
	ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
	ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
	if (Name != EMPTY_STRING)
	{
		QString objName = QString::fromUtf8(Name);
		if (!ItemExists(objName))
			ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
	}
	return PyString_FromString(it->itemName().toUtf8());
}
void CollapsedTablePainter::paintTable(ScPainter* p)
{
	p->save();
	p->translate(table()->gridOffset());

	// Paint table fill.
	paintTableFill(p);

	/*
	 * We paint the table in five passes:
	 *
	 * 1) Cell fills.
	 * 2) Vertical borders.
	 * 3) Horizontal borders
	 * 4) Decorative grid lines.
	 * 5) Cell content.
	 */

	// Pass 1: Paint cell fills.
	for (int row = 0; row < table()->rows(); ++row)
	{
		int colSpan = 0;
		for (int col = 0; col < table()->columns(); col += colSpan)
		{
			TableCell cell = table()->cellAt(row, col);
			if (row == cell.row())
				paintCellFill(cell, p);
			colSpan = cell.columnSpan();
		}
	}

	// Pass 2: Paint vertical borders.
	for (int row = 0; row < table()->rows(); ++row)
	{
		int colSpan = 0;
		for (int col = 0; col < table()->columns(); col += colSpan)
		{
			TableCell cell = table()->cellAt(row, col);
			if (row == cell.row())
			{
				paintCellRightBorders(cell, p);
				if (col == 0)
					paintCellLeftBorders(cell, p);
			}
			colSpan = cell.columnSpan();
		}
	}

	// Pass 3: Paint horizontal borders.
	for (int row = 0; row < table()->rows(); ++row)
	{
		int colSpan = 0;
		for (int col = 0; col < table()->columns(); col += colSpan)
		{
			TableCell cell = table()->cellAt(row, col);
			if (row == cell.row())
			{
				paintCellBottomBorders(cell, p);
				if (row == 0)
					paintCellTopBorders(cell, p);
			}
			colSpan = cell.columnSpan();
		}
	}

	// Pass 4: Paint grid lines.
	if (table()->m_Doc->guidesPrefs().framesShown)
	{
		for (int row = 0; row < table()->rows(); ++row)
		{
			int colSpan = 0;
			for (int col = 0; col < table()->columns(); col += colSpan)
			{
				TableCell cell = table()->cellAt(row, col);
				if (row == cell.row())
				{
					int endCol = col + cell.columnSpan() - 1;
					int endRow = row + cell.rowSpan() - 1;
					qreal left = table()->columnPosition(col);
					qreal right = table()->columnPosition(endCol) + table()->columnWidth(endCol);
					qreal top = table()->rowPosition(row);
					qreal bottom = table()->rowPosition(endRow) + table()->rowHeight(endRow);
					// Paint right and bottom grid line.
					paintGridLine(QPointF(right, top), QPointF(right, bottom), p);
					paintGridLine(QPointF(left, bottom), QPointF(right, bottom), p);
					// Paint left and top grid line.
					if (col == 0)
						paintGridLine(QPointF(left, top), QPointF(left, bottom), p);
					if (row == 0)
						paintGridLine(QPointF(left, top), QPointF(right, top), p);
				}
				colSpan = cell.columnSpan();
			}
		}
	}

	// Pass 5: Paint cell content.
	for (int row = 0; row < table()->rows(); ++row)
	{
		for (int col = 0; col < table()->columns(); col ++)
		{
			TableCell cell = table()->cellAt(row, col);
			if (cell.row() == row && cell.column() == col)
			{
				PageItem* textFrame = cell.textFrame();
				textFrame->DrawObj(p, QRectF());
				textFrame->DrawObj_Decoration(p);
			}
		}
	}

	p->restore();
}