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; }