Ejemplo n.º 1
0
void CanvasMode_EditSpiral::mouseMoveEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	m->accept();
	double newX = mousePointDoc.x();
	double newY = mousePointDoc.y();
	if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed() && (m_arcPoint != noPointDefined))
	{
		PageItem *currItem = m_doc->m_Selection->itemAt(0);
		QTransform itemMatrix = currItem->getTransform();
		PageItem_Spiral *item = currItem->asSpiral();
		QPointF sPoint;
		if (m_arcPoint == useControlStart)
			sPoint = getSegment(m_startAngle);
		else if (m_arcPoint == useControlEnd)
			sPoint = getSegment(m_endAngle);
		QPointF smPoint = itemMatrix.map(sPoint);
		QLineF stLinA = QLineF(smPoint, QPointF(m_Mxp, m_Myp));
		QLineF stLinM = QLineF(smPoint, QPointF(newX, newY));
		double deltaAngle = stLinM.angle() - stLinA.angle();
		if (deltaAngle < -180)
			deltaAngle = deltaAngle + 360;
		else if (deltaAngle > 180)
			deltaAngle = deltaAngle - 360;
		if (currItem->imageFlippedV())
			deltaAngle *= -1.0;
		if (currItem->imageFlippedH())
			deltaAngle *= -1.0;
		if (m_arcPoint == useControlStart)
		{
			if (m_startAngle + deltaAngle >= 0)
			{
				m_startAngle += deltaAngle;
				applyValues(m_startAngle,m_endAngle,item->spiralFactor);
				item->recalcPath();
				m_startPoint = currItem->PoLine.pointQF(0);
				m_canvas->displayRealRotHUD(m->globalPos(), m_startAngle);
			}
			m_VectorDialog->setValues(computeRealAngle(m_startAngle, false), computeRealAngle(m_endAngle, false), item->spiralFactor);
		}
		else if (m_arcPoint == useControlEnd)
		{
			if (m_endAngle + deltaAngle > m_startAngle)
			{
				m_endAngle += deltaAngle;
				applyValues(m_startAngle,m_endAngle,item->spiralFactor);
				item->recalcPath();
				m_endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 2);
				m_canvas->displayRealRotHUD(m->globalPos(), m_endAngle);
			}
			m_VectorDialog->setValues(computeRealAngle(m_startAngle, false), computeRealAngle(m_endAngle, false), item->spiralFactor);
		}
		currItem->update();
		m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-5, -5, 10, 10));
	}
	m_Mxp = newX;
	m_Myp = newY;
}
Ejemplo n.º 2
0
QPointF CanvasMode_EditSpiral::getSegment(double angle)
{
	PageItem *currItem = m_doc->m_Selection->itemAt(0);
	PageItem_Spiral *item = currItem->asSpiral();
	double ww = item->width();
	double wws = 0.0;
	double wwn = ww;
	double hh = item->height() - (item->height() / (item->spiralFactor + 1.0));
	double segStart = 0.0;
	double segEnd = 180;
	bool segPart = true;
	QPointF ret = QPointF(item->width() / 2.0, item->height() / 2.0);
	if (angle < 0)
		return ret;
	while (true)
	{
		QLineF lin = QLineF(QPointF(wws, hh), QPointF(wwn, hh));
		if ((angle <= segEnd) && (angle >= segStart))
		{
			ret = lin.pointAt(0.5);
			break;
		}
		ww /= item->spiralFactor;
		wws = wwn;
		if (segPart)
			wwn -= ww;
		else
			wwn += ww;
		segPart = !segPart;
		segStart += 180.0;
		segEnd += 180.0;
	}
	return ret;
}
Ejemplo n.º 3
0
void CanvasMode_EditSpiral::applyValues(double start, double end, double factor)
{
	PageItem *currItem = m_doc->m_Selection->itemAt(0);
	PageItem_Spiral *item = currItem->asSpiral();
	SimpleState *ss = new SimpleState(Um::EditSpiral, "", Um::IPolygon);
	ss->set("SPIRAL","spiral");
	ss->set("OLD_START",item->spiralStartAngle);
	ss->set("OLD_END",item->spiralEndAngle);
	ss->set("OLD_FACTOR",item->spiralFactor);
	item->spiralStartAngle = computeRealAngle(start, true);
	item->spiralEndAngle = computeRealAngle(end, true);
	item->spiralFactor = factor;
	ss->set("NEW_START",item->spiralStartAngle);
	ss->set("NEW_END",item->spiralEndAngle);
	ss->set("NEW_FACTOR",item->spiralFactor);
	undoManager->action(item,ss);
	item->recalcPath();
	m_startPoint = currItem->PoLine.pointQF(0);
	m_endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 2);
	m_startAngle = item->spiralStartAngle;
	m_endAngle = item->spiralEndAngle;
	QTransform itemMatrix = currItem->getTransform();
	m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-5, -5, 10, 10));
}
Ejemplo n.º 4
0
void PropertiesPalette_XYZ::handleNewH()
{
	if (!m_ScMW || m_ScMW->scriptIsRunning())
		return;
	if ((m_haveDoc) && (m_haveItem))
	{
		double x,y,w,h, gx, gy, gh, gw;
		x = xposSpin->value() / m_unitRatio;
		y = yposSpin->value() / m_unitRatio;
		w = widthSpin->value() / m_unitRatio;
		h = heightSpin->value() / m_unitRatio;
		double oldW = (m_item->width()  != 0.0) ? m_item->width()  : 1.0;
		double oldH = (m_item->height() != 0.0) ? m_item->height() : 1.0;
		if (m_doc->m_Selection->isMultipleSelection())
		{
			if (!_userActionOn)
				m_ScMW->view->startGroupTransaction();
			m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
			if (keepFrameWHRatioButton->isChecked())
			{
				m_doc->scaleGroup(h / gh, h / gh, false);
				displayWH((h / gh) * gw, h);
			}
			else
			{
				m_doc->scaleGroup(1.0, h / gh, false);
				m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
				displayWH(gw, gh);
			}
			if (!_userActionOn)
			{
				m_ScMW->view->endGroupTransaction();
			}
		}
		else
		{
			bool oldS = m_item->Sizing;
			m_item->Sizing = false;
			m_item->OldB2 = m_item->width();
			m_item->OldH2 = m_item->height();
			if (m_item->asLine())
			{
				if (m_lineMode)
				{
					double r = atan2(h-y,w-x)*(180.0/M_PI);
					m_item->setRotation(r, true);
					w = sqrt(pow(w-x,2)+pow(h-y,2));
				}
				m_doc->SizeItem(w, m_item->height(), m_item, true, true, false);
			}
			else
			{
				if (m_item->isTableItem)
				{
					int rmo = m_doc->RotMode();
					m_doc->RotMode ( 0 );
					double dist = h - m_item->height();
					PageItem* bb2;
					PageItem* bb = m_item;
					while (bb->LeftLink != 0)
					{
						bb = bb->LeftLink;
					}
					while (bb->RightLink != 0)
					{
						bb2 = bb;
						while (bb2->BottomLink != 0)
						{
							m_doc->MoveRotated(bb2->BottomLink, FPoint(0, dist), true);
							bb2 = bb2->BottomLink;
						}
						m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb, true);
						bb = bb->RightLink;
					}
					bb2 = bb;
					while (bb2->BottomLink != 0)
					{
						m_doc->MoveRotated(bb2->BottomLink, FPoint(0, dist), true);
						bb2 = bb2->BottomLink;
					}
					m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb, true);
					m_doc->RotMode ( rmo );
					if (keepFrameWHRatioButton->isChecked())
					{
						keepFrameWHRatioButton->setChecked(false);
						displayWH((h / oldH) * m_item->width(), h);
						handleNewW();
						keepFrameWHRatioButton->setChecked(true);
					}
				}
				else
				{
					if (keepFrameWHRatioButton->isChecked())
					{
						displayWH((h / oldH) * m_item->width(), h);
						m_doc->SizeItem((h / oldH) * m_item->width(), h, m_item, true, true, false);
					}
					else
						m_doc->SizeItem(m_item->width(), h, m_item, true, true, false);
				}
			}
			if (m_item->isArc())
			{
				double dw = w - oldW;
				double dh = h - oldH;
				PageItem_Arc* item = m_item->asArc();
				double dsch = item->arcHeight / oldH;
				double dscw = item->arcWidth / oldW;
				item->arcWidth += dw * dscw;
				item->arcHeight += dh * dsch;
				item->recalcPath();
				FPoint tp2(getMinClipF(&m_item->PoLine));
				m_item->PoLine.translate(-tp2.x(), -tp2.y());
				m_doc->AdjustItemSize(m_item);
			}
			if (m_item->isSpiral())
			{
				PageItem_Spiral* item = m_item->asSpiral();
				item->recalcPath();
			}
			m_item->Sizing = oldS;
		}
		//emit DocChanged();
		m_doc->changed();
		m_doc->regionsChanged()->update(QRect());
	}
}
void ResizeGesture::doResize(bool scaleContent)
{
	PageItem* currItem = m_doc->m_Selection->itemAt(0);
	QString targetName = Um::SelectionGroup;
	QPixmap* targetIcon = Um::IGroup;
	if (!m_doc->m_Selection->isMultipleSelection())
	{
		targetName = currItem->getUName();
		targetIcon = currItem->getUPixmap();
	}
	if (!m_transactionStarted)
	{
		m_transactionStarted = new UndoTransaction(Um::instance()->beginTransaction(targetName, targetIcon,
																					Um::Resize, "", Um::IResize));
//		qDebug() << "ResizeGesture::doResize: begin transaction" << m_transactionStarted;
	}
	QRectF newBounds = m_bounds.normalized();
	double dw = (newBounds.width() - m_extraWidth) - currItem->width();
	double dh = (newBounds.height() - m_extraHeight) - currItem->height();
	double dsch = 1.0;
	double dscw = 1.0;
	if (currItem->isArc())
	{
		PageItem_Arc* item = currItem->asArc();
		if (currItem->height() != 0.0)
			dsch = item->arcHeight / currItem->height();
		if (currItem->width() != 0.0)
			dscw = item->arcWidth / currItem->width();
	}
	if (m_doc->m_Selection->isMultipleSelection())
	{
		int RotModeBack = m_doc->RotMode();
		m_doc->RotMode ( 0 );
		double gx, gy, gh, gw;
		m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
		QRectF oldBounds(gx, gy, gw, gh);
		double scx = oldBounds.width() == 0? 1.0 : (newBounds.width() - m_extraWidth) / oldBounds.width();
		double scy = oldBounds.height() == 0? 1.0 : (newBounds.height() - m_extraHeight) / oldBounds.height();
		//CB #3012 only scale text in a group if alt is pressed
		if ((currItem->itemType() == PageItem::TextFrame) && scaleContent)
			m_doc->scaleGroup(scx, scy, true);
		else
			m_doc->scaleGroup(scx, scy, false);
		double dx = newBounds.x() - oldBounds.x();
		double dy = newBounds.y() - oldBounds.y();
		if (dx != 0 || dy != 0)
			m_doc->moveGroup(dx + m_extraX, dy + m_extraY);
		m_doc->RotMode ( RotModeBack );
	}
	else
	{
		if (currItem->itemType() == PageItem::ImageFrame && scaleContent)
		{
			double divX = (currItem->width() != 0) ? currItem->width() : 1.0;
			double divY = (currItem->height() != 0) ? currItem->height() : 1.0;
			double imgScX = (newBounds.width() - m_extraWidth) / divX * currItem->imageXScale();
			double imgScY = (newBounds.height() - m_extraHeight) / divY * currItem->imageYScale();
			// The aspect ratio has been fixed, so make the modification in the direction of the larger movement.
			if (currItem->keepAspectRatio() && currItem->fitImageToFrame()) 
			{
				if (qAbs((newBounds.width() - m_extraWidth) - currItem->width()) > qAbs((newBounds.height() - m_extraHeight) - currItem->height()))
					imgScY = imgScX;
				else
					imgScX = imgScY;
			}
			currItem->setImageXYScale(imgScX, imgScY);
		}
		else if (currItem->itemType() == PageItem::ImageFrame && currItem->PictureIsAvailable)
		{
			double dx = ((newBounds.x() + m_extraX) - currItem->xPos());
			double dy = ((newBounds.y() + m_extraY) - currItem->yPos());
			double cosa = cos(currItem->rotation() * M_PI / 180.0);
			double sina = sin(currItem->rotation() * M_PI / 180.0);
			double xoff = -(cosa*dx + sina*dy);
			if (currItem->imageFlippedH())
				xoff += (currItem->width() - (newBounds.width() - m_extraWidth));
			double yoff = -(cosa*dy - sina*dx);
			if (currItem->imageFlippedV())
				yoff += (currItem->height() - (newBounds.height() - m_extraHeight));
			if (xoff != 0.0 || yoff != 0.0)
			{
				currItem->moveImageInFrame(xoff / currItem->imageXScale(), yoff / currItem->imageYScale());
			}
		}
		// We do not want to scale the text of a linked frame
		// as it would alter text in other frames of the string
		else if((currItem->itemType() == PageItem::TextFrame) 
				       && (currItem->nextInChain() == 0) 
				       && (currItem->prevInChain() == 0) 
				       && scaleContent)
		{
			double divX = (currItem->width() != 0) ? currItem->width() : 1.0;
			double divY = (currItem->height() != 0) ? currItem->height() : 1.0;
			double txtScX = (newBounds.width() - m_extraWidth) / divX;
			double txtScY = (newBounds.height() - m_extraHeight) / divY;
			if (currItem->itemText.length() != 0)
			{
				for (int aa = 0; aa < currItem->itemText.length(); ++aa)
				{
#if 0 // hard to decide if it’s batter to scale or to change font size
					currItem->itemText.item(aa)->setScaleV(
							qMax(qMin(qRound(currItem->itemText.item(aa)->scaleV()*txtScY), 4000), 100));
					currItem->itemText.item(aa)->setScaleH(
							qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX), 4000), 100));
#else
					currItem->itemText.item(aa)->setFontSize(
							qMax(qMin(currItem->itemText.item(aa)->fontSize() * txtScY, 4000.0), 1.0));
					currItem->itemText.item(aa)->setScaleH(
							qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX / txtScY), 4000), 100));
#endif

					// We need to scale the linespacing _only once_ per paragraph.
					if((aa == 0) 
						|| ( SpecialChars::isBreak(currItem->itemText.itemText(aa - 1).at(0))))
					{
						ParagraphStyle ps(currItem->itemText.paragraphStyle(aa));
						double oldLS(currItem->itemText.paragraphStyle(aa).lineSpacing());
						ps.setLineSpacing(qMax(qRound(oldLS * txtScY), 1));
						currItem->itemText.setStyle(aa,ps);
					}
				}
			}
		}
		currItem->setXYPos(newBounds.x() + m_extraX, newBounds.y() + m_extraY);
		currItem->setWidth(newBounds.width() - m_extraWidth);
		currItem->setHeight(newBounds.height() - m_extraHeight);
		currItem->updateClip();
		if (currItem->isArc())
		{
			PageItem_Arc* item = currItem->asArc();
			item->arcWidth += dw * dscw;
			item->arcHeight += dh * dsch;
			item->recalcPath();
			FPoint tp2(getMinClipF(&currItem->PoLine));
			currItem->PoLine.translate(-tp2.x(), -tp2.y());
			m_doc->AdjustItemSize(currItem);
		}
		if (currItem->isSpiral())
		{
			PageItem_Spiral* item = currItem->asSpiral();
			item->recalcPath();
		}
		// rotation does not change
	}
	m_origBounds = m_bounds;
}