KUndo2Command* KoCreateShapeStrategy::createCommand() { Q_D(KoShapeRubberSelectStrategy); KoCreateShapesTool *parent = static_cast<KoCreateShapesTool*>(d_ptr->tool); KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value(parent->shapeId()); if (! factory) { warnFlake << "Application requested a shape that is not registered" << parent->shapeId(); return 0; } const KoProperties *props = parent->shapeProperties(); KoShape *shape; if (props) shape = factory->createShape(props, parent->canvas()->shapeController()->resourceManager()); else shape = factory->createDefaultShape(parent->canvas()->shapeController()->resourceManager()); if (shape->shapeId().isEmpty()) shape->setShapeId(factory->id()); QRectF rect = d->selectedRect(); shape->setPosition(rect.topLeft()); QSizeF newSize = rect.size(); // if the user has dragged when creating the shape, // resize the shape to the dragged size if (newSize.width() > 1.0 && newSize.height() > 1.0) shape->setSize(newSize); KUndo2Command * cmd = parent->canvas()->shapeController()->addShape(shape); if (cmd) { KoSelection *selection = parent->canvas()->shapeManager()->selection(); selection->deselectAll(); selection->select(shape); } return cmd; }
KWOutlineShape::KWOutlineShape(KWFrame *frame) : m_paintOutline(false) { setShapeId(KoPathShapeId); setApplicationData(frame); class MyGroup : public KoShapeGroup { public: ~MyGroup() { setApplicationData(0); // make sure deleting this will not delete the parent frame. } }; KoShapeGroup *group = new MyGroup(); group->setSize(QSize(1, 1)); group->setApplicationData(frame); KoShape *child = frame->shape(); group->setTransformation(child->absoluteTransformation(0)); QMatrix matrix; child->setTransformation(matrix); const QSizeF s = child->size(); // init with a simple rect as the outline of the original. moveTo(QPointF(0, 0)); lineTo(QPointF(s.width(), 0)); lineTo(QPointF(s.width(), s.height())); lineTo(QPointF(0, s.height())); close(); group->setZIndex(child->zIndex()); group->addChild(this); group->addChild(child); }
void KisSelectionToVectorActionFactory::run(KisView2 *view) { KisSelectionSP selection = view->selection(); if (selection->hasShapeSelection() || !selection->outlineCacheValid()) { return; } QPainterPath selectionOutline = selection->outlineCache(); QTransform transform = view->canvasBase()->coordinatesConverter()->imageToDocumentTransform(); KoShape *shape = KoPathShape::createShapeFromPainterPath(transform.map(selectionOutline)); shape->setShapeId(KoPathShapeId); /** * Mark a shape that it belongs to a shape selection */ if(!shape->userData()) { shape->setUserData(new KisShapeSelectionMarker); } KisProcessingApplicator *ap = beginAction(view, i18n("Convert to Vector Selection")); ap->applyCommand(view->canvasBase()->shapeController()->addShape(shape), KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE); endAction(ap, KisOperationConfiguration(id()).toXML()); }
void KoTosContainer::setTextAlignment(Qt::Alignment alignment) { Q_D(KoTosContainer); KoShape *textShape = this->textShape(); if (textShape == 0) { warnFlake << "No text shape present in KoTosContainer"; return; } // vertical KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData()); shapeData->setVerticalAlignment(alignment); // horizontal Q_ASSERT(shapeData->document()); QTextBlockFormat bf; bf.setAlignment(alignment & Qt::AlignHorizontal_Mask); QTextCursor cursor(shapeData->document()); cursor.setPosition(QTextCursor::End, QTextCursor::KeepAnchor); cursor.mergeBlockFormat(bf); d->alignment = alignment; }
bool KoTosContainer::loadText(const KoXmlElement &element, KoShapeLoadingContext &context) { Q_D(const KoTosContainer); KoXmlElement child; forEachElement(child, element) { // only recreate the text shape if there's something to be loaded if (child.localName() == "p" || child.localName() == "list") { KoShape *textShape = createTextShape(context.documentResourceManager()); if (!textShape) { return false; } //apply the style properties to the loaded text setTextAlignment(d->alignment); // In the case of text on shape, we cannot ask the text shape to load // the odf, since it expects a complete document with style info and // everything, so we have to use the KoTextShapeData object instead. KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData()); Q_ASSERT(shapeData); shapeData->loadStyle(element, context); bool loadOdf = shapeData->loadOdf(element, context); return loadOdf; } } return true; }
KWFrameDialog::KWFrameDialog(const QList<KoShape *> &shapes, KWDocument *document, KWCanvas *canvas) : KPageDialog(canvas) , m_frameConnectSelector(0) , m_canvas(canvas) { m_state = new FrameConfigSharedState(document); setFaceType(Tabbed); m_anchoringProperties = new KWAnchoringProperties(m_state); if (m_anchoringProperties->open(shapes)) addPage(m_anchoringProperties, i18n("Smart Positioning")); m_runAroundProperties = new KWRunAroundProperties(m_state); if (m_runAroundProperties->open(shapes)) addPage(m_runAroundProperties, i18n("Text Run Around")); if (shapes.count() == 1) { m_frameConnectSelector = new KWFrameConnectSelector(m_state); KoShape *shape = shapes.first(); m_state->setKeepAspectRatio(shape->keepAspectRatio()); if (m_frameConnectSelector->canOpen(shape)) { m_frameConnectSelector->open(shape); addPage(m_frameConnectSelector, i18n("Connect Text Frames")); } else { delete m_frameConnectSelector; m_frameConnectSelector = 0; } } connect(this, SIGNAL(accepted()), this, SLOT(okClicked())); connect(this, SIGNAL(rejected()), this, SLOT(cancelClicked())); }
QUndoCommand* KoCreateShapeStrategy::createCommand() { KoCreateShapesTool *parent = static_cast<KoCreateShapesTool*>(m_parent); KoShapeFactory *factory = KoShapeRegistry::instance()->value(parent->shapeId()); if (! factory) { kWarning(30006) << "Application requested a shape that is not registered" << parent->shapeId(); return 0; } const KoProperties *props = parent->shapeProperties(); KoShape *shape; if (props) shape = factory->createShapeAndInit(props, parent->m_canvas->shapeController()->dataCenterMap()); else shape = factory->createDefaultShapeAndInit(parent->m_canvas->shapeController()->dataCenterMap()); if (shape->shapeId().isEmpty()) shape->setShapeId(factory->id()); QRectF rect = selectRect(); shape->setPosition(rect.topLeft()); QSizeF newSize = rect.size(); // if the user has dragged when creating the shape, // resize the shape to the dragged size if (newSize.width() > 1.0 && newSize.height() > 1.0) shape->setSize(newSize); QUndoCommand * cmd = parent->m_canvas->shapeController()->addShape(shape); if (cmd) { KoSelection *selection = parent->m_canvas->shapeManager()->selection(); selection->deselectAll(); selection->select(shape); } return cmd; }
void AbstractSelectionStrategy::handleMouseMove(const QPointF& documentPos, Qt::KeyboardModifiers modifiers) { Q_UNUSED(modifiers) const KoShape* shape = m_canvas->shapeManager()->selection()->firstSelectedShape(); const QPointF position = documentPos - (shape ? shape->position() : QPointF(0.0, 0.0)); // In which cell did the user click? double xpos; double ypos; int col = d->selection->activeSheet()->leftColumn(position.x(), xpos); int row = d->selection->activeSheet()->topRow(position.y(), ypos); // Check boundaries. if (col > KS_colMax || row > KS_rowMax) { kDebug(36005) << "col or row is out of range:" << "col:" << col << " row:" << row; return; } // Test whether mouse is over the Selection.handle const QRectF selectionHandle = d->selection->selectionHandleArea(m_canvas->viewConverter()); if (selectionHandle.contains(position)) { // If the cursor is over the handle, than it might be already on the next cell. // Recalculate the cell position! col = d->selection->activeSheet()->leftColumn(position.x() - m_canvas->viewConverter()->viewToDocumentX(2.0), xpos); row = d->selection->activeSheet()->topRow(position.y() - m_canvas->viewConverter()->viewToDocumentY(2.0), ypos); } // Update the selection. d->selection->update(QPoint(col, row)); m_parent->repaintDecorations(); }
KoShape *KPrPlaceholderPictureStrategy::createShape(KoDocumentResourceManager *rm) { KoShape * shape = 0; KUrl url = KFileDialog::getOpenUrl(); if ( !url.isEmpty() ) { shape = KPrPlaceholderStrategy::createShape(rm); KoImageCollection *collection = rm->imageCollection(); Q_ASSERT(collection); QString tmpFile; if (KIO::NetAccess::download(url, tmpFile, 0)) { QImage image(tmpFile); if (!image.isNull()) { //setSuffix(url.prettyUrl()); KoImageData *data = collection->createImageData(image); if (data->isValid()) { shape->setUserData( data ); // TODO the pic should be fit into the space provided shape->setSize( data->imageSize() ); } } } else { kWarning() << "open image " << url.prettyUrl() << "failed"; } } return shape; }
KoShape* StencilShapeFactory:: createDefaultShape(KoDocumentResourceManager* documentResources) const { KoShape* shape = 0; KoStore* store = 0; QIODevice* in = 0; QString ext = id().mid(id().lastIndexOf('.')).toLower(); if (ext == ".odg") { store = KoStore::createStore(id(), KoStore::Read); if (!store->bad()) { shape = createFromOdf(store, documentResources); } delete store; } else if (ext == ".svg") { in = KFilterDev::deviceForFile(id(), "text/plain"); shape = createFromSvg(in, documentResources); delete in; } else if (ext == ".svgz") { in = KFilterDev::deviceForFile(id(), "application/x-gzip"); shape = createFromSvg(in, documentResources); delete in; } else { qDebug() << "stencil format" << ext << "unsupported"; } if (shape) { if (m_properties->intProperty("keepAspectRatio") == 1) shape->setKeepAspectRatio(true); } return shape; }
void KPrAttributeHeight::updateCache(KPrAnimationCache *cache, KPrShapeAnimation *shapeAnimation, qreal value) { qreal tx = 0.0, ty = 0.0; KoShape * shape = shapeAnimation->shape(); KoTextBlockData * textBlockData = shapeAnimation->textBlockData(); QTransform transform; if (textBlockData) { if (KoTextShapeData *textShapeData = dynamic_cast<KoTextShapeData*>(shape->userData())) { QTextDocument *textDocument = textShapeData->document(); for (int i = 0; i < textDocument->blockCount(); i++) { QTextBlock textBlock = textDocument->findBlockByNumber(i); if (textBlock.userData() == textBlockData) { QTextLayout *layout = textBlock.layout(); value = value * cache->pageSize().height() / layout->boundingRect().height(); tx = layout->minimumWidth() * cache->zoom() / 2; ty = layout->boundingRect().height() * cache->zoom() / 2; } } } } else { value = value * cache->pageSize().height() / shape->size().height(); tx = shape->size().width() * cache->zoom() / 2; ty = shape->size().height() * cache->zoom() / 2; } transform.translate(tx, ty).scale(1, value).translate(-tx, -ty); cache->update(shape, shapeAnimation->textBlockData(), "transform", transform); }
void TestKoShapeFactory::testOdfElement() { KoShapeFactoryBase * factory = new KoPathShapeFactory(QStringList()); QVERIFY(factory->odfElements().front().second.contains("path")); QVERIFY(factory->odfElements().front().second.contains("line")); QVERIFY(factory->odfElements().front().second.contains("polyline")); QVERIFY(factory->odfElements().front().second.contains("polygon")); QVERIFY(factory->odfElements().front().first == KoXmlNS::draw); QBuffer xmldevice; xmldevice.open(QIODevice::WriteOnly); QTextStream xmlstream(&xmldevice); xmlstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; xmlstream << "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:koffice=\"http://www.koffice.org/2005/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">"; xmlstream << "<office:body>"; xmlstream << "<office:text>"; xmlstream << "<text:p text:style-name=\"P1\"><?opendocument cursor-position?></text:p>"; xmlstream << "<draw:path svg:d=\"M10,10L100,100\"></draw:path>"; xmlstream << "</office:text>"; xmlstream << "</office:body>"; xmlstream << "</office:document-content>"; xmldevice.close(); KoXmlDocument doc; QString errorMsg; int errorLine = 0; int errorColumn = 0; QCOMPARE(doc.setContent(&xmldevice, true, &errorMsg, &errorLine, &errorColumn), true); QCOMPARE(errorMsg.isEmpty(), true); QCOMPARE(errorLine, 0); QCOMPARE(errorColumn, 0); KoXmlElement contentElement = doc.documentElement(); KoXmlElement bodyElement = contentElement.firstChild().toElement(); // XXX: When loading is implemented, these no doubt have to be // sensibly filled. KoOdfStylesReader stylesReader; KoOdfLoadingContext odfContext(stylesReader, 0); KoShapeLoadingContext shapeContext(odfContext, 0); KoXmlElement textElement = bodyElement.firstChild().firstChild().toElement(); QVERIFY(textElement.tagName() == "p"); QCOMPARE(factory->supports(textElement, shapeContext), false); KoXmlElement pathElement = bodyElement.firstChild().lastChild().toElement(); QVERIFY(pathElement.tagName() == "path"); QCOMPARE(factory->supports(pathElement, shapeContext), true); KoShape *shape = factory->createDefaultShape(); QVERIFY(shape); QVERIFY(shape->loadOdf(pathElement, shapeContext)); delete shape; delete factory; }
void KoTosContainer::setRunThrough(short int runThrough) { KoShape::setRunThrough(runThrough); KoShape *textShape = this->textShape(); if (textShape) { textShape->setRunThrough(runThrough); } }
void StrokeDocker::selectionChanged() { KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController(); KoSelection *selection = canvasController->canvas()->shapeManager()->selection(); KoShape * shape = selection->firstSelectedShape(); if( shape ) setStroke( shape->border() ); }
void KPrAttributeY::initCache(KPrAnimationCache *animationCache, int step, KPrShapeAnimation * shapeAnimation, qreal startValue, qreal endValue) { KoShape * shape = shapeAnimation->shape(); qreal v1 = (startValue * animationCache->pageSize().height() - shape->position().y()) * animationCache->zoom(); qreal v2 = (endValue * animationCache->pageSize().height() - shape->position().y()) * animationCache->zoom(); animationCache->init(step, shape, shapeAnimation->textBlockUserData(), "transform", QTransform().translate(0, v1)); animationCache->init(step + 1, shape, shapeAnimation->textBlockUserData(), "transform", QTransform().translate(0, v2)); }
void ConnectionTool::paint(QPainter &painter, const KoViewConverter &converter) { // get the correctly sized rect for painting handles QRectF handleRect = handlePaintRect(QPointF()); painter.setRenderHint(QPainter::Antialiasing, true); if (m_currentStrategy) { painter.save(); m_currentStrategy->paint(painter, converter); painter.restore(); } QList<KoShape*> shapes = canvas()->shapeManager()->shapes(); for (QList<KoShape*>::const_iterator end = shapes.constBegin(); end != shapes.constEnd(); ++end) { KoShape* shape = *end; if (!dynamic_cast<KoConnectionShape*>(shape)) { // only paint connection points of textShapes not inside a tos container and other shapes if (shape->shapeId() == TextShape_SHAPEID && dynamic_cast<KoTosContainer*>(shape->parent())) continue; painter.save(); painter.setPen(Qt::black); QTransform transform = shape->absoluteTransformation(0); KoShape::applyConversion(painter, converter); // Draw all the connection points of the shape KoConnectionPoints connectionPoints = shape->connectionPoints(); KoConnectionPoints::const_iterator cp = connectionPoints.constBegin(); KoConnectionPoints::const_iterator lastCp = connectionPoints.constEnd(); for(; cp != lastCp; ++cp) { if (shape == findNonConnectionShapeAtPosition(transform.map(cp.value().position)) ) { handleRect.moveCenter(transform.map(cp.value().position)); painter.setBrush(cp.key() == m_activeHandle && shape == m_currentShape ? Qt::red : Qt::white); painter.drawRect(handleRect); } } painter.restore(); } } // paint connection points or connection handles depending // on the shape the mouse is currently if (m_currentShape && m_editMode == EditConnection) { KoConnectionShape *connectionShape = dynamic_cast<KoConnectionShape*>(m_currentShape); if (connectionShape) { int radius = handleRadius()+1; int handleCount = connectionShape->handleCount(); for(int i = 0; i < handleCount; ++i) { painter.save(); painter.setPen(Qt::blue); painter.setBrush(i == m_activeHandle ? Qt::red : Qt::white); painter.setTransform(connectionShape->absoluteTransformation(&converter) * painter.transform()); connectionShape->paintHandle(painter, converter, i, radius); painter.restore(); } } } }
void KPrAttributeY::updateCache(KPrAnimationCache *cache, KPrShapeAnimation *shapeAnimation, qreal value) { KoShape *shape = shapeAnimation->shape(); QTransform transform; value = value * cache->pageSize().height(); value = value - shape->position().y(); value = value * cache->zoom(); transform.translate(0, value); cache->update(shape, shapeAnimation->textBlockUserData(), "transform", transform); }
KUndo2Command* paint() { /** * Mark a shape that it belongs to a shape selection */ if(!m_shape->userData()) { m_shape->setUserData(new KisShapeSelectionMarker); } return m_view->canvasBase()->shapeController()->addShape(m_shape); }
void KoTosContainer::setPlainText(const QString &text) { KoShape *textShape = this->textShape(); if (textShape == 0) { warnFlake << "No text shape present in KoTosContainer"; return; } KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData()); Q_ASSERT(shapeData->document()); shapeData->document()->setPlainText(text); }
void KWCreateOutlineCommand::undo() { QUndoCommand::undo(); Q_ASSERT(m_container); KoShape *child = m_frame->shape(); child->setTransformation(m_container->absoluteTransformation(0)); m_container->removeShape(m_frame->shape()); m_container->setApplicationData(0); m_controller->removeShape(m_container); m_frame->setOutlineShape(0); m_deleteOnExit = true; }
void KoShapeTransformCommand::undo() { KUndo2Command::undo(); const int shapeCount = d->shapes.count(); for (int i = 0; i < shapeCount; ++i) { KoShape * shape = d->shapes[i]; shape->update(); shape->setTransformation(d->oldState[i]); shape->update(); } }
void KoTosContainer::setPreferredTextRect(const QRectF &rect) { Q_D(KoTosContainer); d->preferredTextRect = rect; KoShape *textShape = this->textShape(); //debugFlake << rect << textShape << d->resizeBehavior; if (d->resizeBehavior == TextFollowsPreferredTextRect && textShape) { //debugFlake << rect; textShape->setPosition(rect.topLeft()); textShape->setSize(rect.size()); } }
// static KoShapeGroupCommand * KoShapeGroupCommand::createCommand(KoShapeGroup *container, const QList<KoShape *> &shapes, KUndo2Command *parent) { QList<KoShape*> orderedShapes(shapes); qSort(orderedShapes.begin(), orderedShapes.end(), KoShape::compareShapeZIndex); if (!orderedShapes.isEmpty()) { KoShape * top = orderedShapes.last(); container->setParent(top->parent()); container->setZIndex(top->zIndex()); } return new KoShapeGroupCommand(container, orderedShapes, parent); }
void ConnectionTool::repaintDecorations() { const qreal radius = handleRadius(); QRectF repaintRect; if (m_currentShape) { repaintRect = m_currentShape->boundingRect(); canvas()->updateCanvas(repaintRect.adjusted(-radius, -radius, radius, radius)); KoConnectionShape * connectionShape = dynamic_cast<KoConnectionShape*>(m_currentShape); if (!m_resetPaint && m_currentShape->isVisible(true) && !connectionShape) { // only paint connection points of textShapes not inside a tos container and other shapes if ( !(m_currentShape->shapeId() == TextShape_SHAPEID && dynamic_cast<KoTosContainer*>(m_currentShape->parent())) ) { KoConnectionPoints connectionPoints = m_currentShape->connectionPoints(); KoConnectionPoints::const_iterator cp = connectionPoints.constBegin(); KoConnectionPoints::const_iterator lastCp = connectionPoints.constEnd(); for(; cp != lastCp; ++cp) { repaintRect = handleGrabRect(m_currentShape->shapeToDocument(cp.value().position)); canvas()->updateCanvas(repaintRect.adjusted(-radius, -radius, radius, radius)); } } } if (m_editMode == EditConnection) { if (connectionShape) { QPointF handlePos = connectionShape->handlePosition(m_activeHandle); handlePos = connectionShape->shapeToDocument(handlePos); repaintRect = handlePaintRect(handlePos); canvas()->updateCanvas(repaintRect.adjusted(-radius, -radius, radius, radius)); } } } if (m_resetPaint) { QList<KoShape*> shapes = canvas()->shapeManager()->shapes(); for (QList<KoShape*>::const_iterator end = shapes.constBegin(); end != shapes.constEnd(); ++end) { KoShape* shape = *end; if (!dynamic_cast<KoConnectionShape*>(shape)) { // only paint connection points of textShapes not inside a tos container and other shapes if (shape->shapeId() == TextShape_SHAPEID && dynamic_cast<KoTosContainer*>(shape->parent())) continue; KoConnectionPoints connectionPoints = shape->connectionPoints(); KoConnectionPoints::const_iterator cp = connectionPoints.constBegin(); KoConnectionPoints::const_iterator lastCp = connectionPoints.constEnd(); for(; cp != lastCp; ++cp) { repaintRect = handleGrabRect(shape->shapeToDocument(cp.value().position)); canvas()->updateCanvas(repaintRect.adjusted(-radius, -radius, radius, radius)); } } } } m_resetPaint = false; }
void KoTosContainer::saveText(KoShapeSavingContext &context) const { KoShape *textShape = this->textShape(); if (!textShape) { return; } // In the case of text on shape, we cannot ask the text shape to save // the odf, since it would save all the frame information as well, which // is wrong. // Only save the text shape if it has content. KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData()); if (shapeData && !shapeData->document()->isEmpty()) { shapeData->saveOdf(context); } }
void KPrViewModeNotes::removeShape( KoShape *shape ) { KoShape *parent = shape; KPrNotes *notes = 0; while ( !notes && ( parent = parent->parent() ) ) { notes = dynamic_cast<KPrNotes *>( parent ); } if ( notes ) { KPrPage *activePage = static_cast<KPrPage *>( m_view->activePage() ); if ( notes == activePage->pageNotes() ) { m_view->kopaCanvas()->shapeManager()->remove( shape ); } } }
KoShape * ConnectionTool::findNonConnectionShapeAtPosition(const QPointF &position) const { QList<KoShape*> shapes = canvas()->shapeManager()->shapesAt(handleGrabRect(position)); if (!shapes.isEmpty()) { qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex); for (QList<KoShape*>::const_iterator end = shapes.constEnd()-1; end >= shapes.constBegin(); --end) { KoShape* shape = *end; if (!dynamic_cast<KoConnectionShape*>(shape) && shape->shapeId() != TextShape_SHAPEID) { return shape; } } } return 0; }
void KPrViewModeNotes::addShape( KoShape *shape ) { KoShape *parent = shape; KPrNotes *notes = 0; // similar to KoPADocument::pageByShape() while ( !notes && ( parent = parent->parent() ) ) { notes = dynamic_cast<KPrNotes *>( parent ); } if ( notes ) { KPrPage *activePage = static_cast<KPrPage *>( m_view->activePage() ); if ( notes == activePage->pageNotes() ) { m_view->kopaCanvas()->shapeManager()->addShape( shape ); } } }
void KPrPicturesImport::pictureImported(KJob *job) { KoShape *shape = m_factory->createDefaultShape(); if (shape) { KIO::StoredTransferJob *transferJob = qobject_cast<KIO::StoredTransferJob*>(job); Q_ASSERT(transferJob); KoImageData *imageData = m_doc->resourceManager()->imageCollection()->createImageData(transferJob->data()); if (imageData->isValid()) { shape->setUserData(imageData); // make sure the picture fits on the page QSizeF imageSize = imageData->imageSize(); QSizeF pageSize = m_masterPage->size(); qreal zoom = 1; if (imageSize.width() > pageSize.width() || imageSize.height() > pageSize.height()) { zoom = pageSize.width() / imageSize.width(); zoom = qMin(zoom, pageSize.height() / imageSize.height()); } imageSize *= zoom; shape->setSize(imageSize); // center the picture on the page QPointF pos( pageSize.width() / 2- imageSize.width() / 2, pageSize.height() / 2 - imageSize.height() / 2 ); shape->setPosition(pos); KoPAPageBase *page = m_doc->newPage(m_masterPage); KoShapeLayer *layer = dynamic_cast<KoShapeLayer *>(page->shapes().first()); if (layer) { layer->addShape(shape); new KoPAPageInsertCommand(m_doc, page, m_currentPage, m_cmd); m_currentPage = page; } else { delete page; delete shape; } } else { kWarning(33001) << "imageData not valid"; delete shape; } } else { kWarning(33001) << "shape not created"; } import(); }
void KoTextOnShapeContainerModel::containerChanged(KoShapeContainer *container, KoShape::ChangeType type) { #ifdef QT_NO_DEBUG Q_UNUSED(container); #endif if (lock || type != KoShape::SizeChanged) { return; } lock = true; Q_ASSERT(container == q); containerData->content->setSize(q->size()); KoShape *text = containerData->textShape; if (text && q->resizeBehavior() != KoTextOnShapeContainer::TextFollowsPreferredTextRect) { text->setSize(q->size()); } lock = false; }