void CanvasMode_EditArc::applyValues(double start, double end, double height, double width) { PageItem *currItem = m_doc->m_Selection->itemAt(0); PageItem_Arc *item = currItem->asArc(); QPointF mPoint = item->PoLine.pointQF(0); QRectF upRect = QRectF(QPointF(0, 0), QPointF(currItem->width(), currItem->height())).normalized(); QRectF upRect2 = QRectF(mPoint.x() - item->arcWidth / 2.0, mPoint.y() - item->arcHeight / 2.0, item->arcWidth, item->arcHeight); upRect = upRect2.united(upRect); upRect.translate(currItem->xPos(), currItem->yPos()); QTransform bb; bb.scale(height / width, 1.0); QLineF inp = QLineF(QPointF(width / 2.0, height / 2.0), QPointF(width, height / 2.0)); inp.setAngle(start); QLineF res = bb.map(inp); inp.setAngle(end); QLineF ena = bb.map(inp); startAngle = res.angle(); endAngle = ena.angle(); double nSweep = endAngle - startAngle; if (nSweep < 0) nSweep += 360; QPainterPath pp; pp.moveTo(mPoint); pp.arcTo(QRectF(mPoint.x() - width / 2.0, mPoint.y() - height / 2.0, width, height), startAngle, nSweep); pp.closeSubpath(); currItem->PoLine.fromQPainterPath(pp); m_doc->AdjustItemSize(currItem); if(UndoManager::undoEnabled()) { ScItemState<QPair<FPointArray, FPointArray> > *ss = new ScItemState<QPair<FPointArray, FPointArray> >(Um::EditArc,"",Um::IPolygon); FPointArray old = item->PoLine; ss->set("ARC","arc"); ss->set("OLD_WIDTH",item->arcWidth); ss->set("NEW_WIDTH",width); ss->set("OLD_XPOS",item->xPos()); ss->set("OLD_YPOS",item->yPos()); ss->set("OLD_HEIGHT",item->arcHeight); ss->set("NEW_HEIGHT",height); ss->set("OLD_START",item->arcStartAngle); ss->set("NEW_START",startAngle); ss->set("OLD_SWEEP",item->arcSweepAngle); ss->set("NEW_SWEEP",nSweep); ss->setItem(qMakePair(old,item->PoLine)); ss->set("NEW_XPOS",item->xPos()); ss->set("NEW_YPOS",item->yPos()); undoManager->action(currItem,ss); } item->arcStartAngle = startAngle; item->arcSweepAngle = nSweep; item->arcWidth = width; item->arcHeight = height; startPoint = currItem->PoLine.pointQF(2); endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 4); centerPoint = currItem->PoLine.pointQF(0); widthPoint = QPointF(centerPoint.x() - item->arcWidth / 2.0, centerPoint.y()); heightPoint = QPointF(centerPoint.x(), centerPoint.y() - item->arcHeight / 2.0); 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())); }
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; }
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 CanvasMode_EditArc::applyValues(double start, double end, double height, double width) { PageItem *currItem = m_doc->m_Selection->itemAt(0); QRectF oldR = currItem->getBoundingRect().adjusted(-5, -5, 10, 10); PageItem_Arc *item = currItem->asArc(); QTransform bb; bb.scale(height / width, 1.0); QLineF inp = QLineF(QPointF(width / 2.0, height / 2.0), QPointF(width, height / 2.0)); inp.setAngle(start); QLineF res = bb.map(inp); inp.setAngle(end); QLineF ena = bb.map(inp); m_startAngle = res.angle(); m_endAngle = ena.angle(); double nSweep = m_endAngle - m_startAngle; if (nSweep < 0) nSweep += 360; double oldX = currItem->xPos(); double oldY = currItem->yPos(); double newX = oldX + m_centerPoint.x() - (width / 2.0); double newY = oldY + m_centerPoint.y() - (height / 2.0); item->setXYPos(newX, newY, true); FPointArray old = item->PoLine; QPainterPath pp; pp.moveTo(width / 2.0, height / 2.0); pp.arcTo(QRectF(0, 0, width, height), m_startAngle, nSweep); pp.closeSubpath(); currItem->PoLine.fromQPainterPath(pp, true); FPoint wh = getMaxClipF(&currItem->PoLine); currItem->setWidthHeight(wh.x(),wh.y()); m_doc->adjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); if (UndoManager::undoEnabled()) { ScItemState<QPair<FPointArray, FPointArray> > *ss = new ScItemState<QPair<FPointArray, FPointArray> >(Um::EditArc,"",Um::IPolygon); ss->set("ARC"); ss->set("OLD_WIDTH",item->arcWidth); ss->set("NEW_WIDTH",width); ss->set("OLD_XPOS",oldX); ss->set("OLD_YPOS",oldY); ss->set("OLD_HEIGHT",item->arcHeight); ss->set("NEW_HEIGHT",height); ss->set("OLD_START",item->arcStartAngle); ss->set("NEW_START",m_startAngle); ss->set("OLD_SWEEP",item->arcSweepAngle); ss->set("NEW_SWEEP",nSweep); ss->setItem(qMakePair(old,item->PoLine)); ss->set("NEW_XPOS",item->xPos()); ss->set("NEW_YPOS",item->yPos()); undoManager->action(currItem,ss); } item->arcStartAngle = m_startAngle; item->arcSweepAngle = nSweep; item->arcWidth = width; item->arcHeight = height; m_startPoint = currItem->PoLine.pointQF(2); m_endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 4); m_centerPoint = currItem->PoLine.pointQF(0); m_widthPoint = QPointF(m_centerPoint.x() - item->arcWidth / 2.0, m_centerPoint.y()); m_heightPoint = QPointF(m_centerPoint.x(), m_centerPoint.y() - item->arcHeight / 2.0); m_doc->setRedrawBounding(currItem); QRectF newR(currItem->getBoundingRect()); m_doc->regionsChanged()->update(newR.united(oldR)); // 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())); }