void TestSelection::testSize() { KoSelection selection; MockShape shape1; shape1.setSize( QSizeF( 100, 100 ) ); shape1.setPosition( QPointF( 0, 0 ) ); selection.select( &shape1 ); QCOMPARE(selection.size(), QSizeF( 100, 100 )); MockShape shape2; shape2.setSize( QSizeF( 100, 100 ) ); shape2.setPosition( QPointF( 100, 100 ) ); selection.select( &shape2 ); QCOMPARE(selection.size(), QSizeF( 200, 200 )); MockShape shape3; shape3.setSize( QSizeF( 100, 100 ) ); shape3.setPosition( QPointF( 200, 200 ) ); selection.select( &shape3 ); QCOMPARE(selection.size(), QSizeF( 300, 300 )); selection.deselect( &shape3 ); QCOMPARE(selection.size(), QSizeF( 200, 200 )); selection.deselect( &shape2 ); QCOMPARE(selection.size(), QSizeF( 100, 100 )); }
void KoCreatePathTool::addPathShape(KoPathShape *pathShape) { Q_D(KoCreatePathTool); KoPathShape *startShape = 0; KoPathShape *endShape = 0; pathShape->normalize(); // check if existing start/end points are still valid d->existingStartPoint.validate(canvas()); d->existingEndPoint.validate(canvas()); pathShape->setStroke(createStroke()); if (d->connectPaths(pathShape, d->existingStartPoint, d->existingEndPoint)) { if (d->existingStartPoint.isValid()) startShape = d->existingStartPoint.path; if (d->existingEndPoint.isValid() && d->existingEndPoint != d->existingStartPoint) endShape = d->existingEndPoint.path; } KUndo2Command *cmd = canvas()->shapeController()->addShape(pathShape); if (cmd) { KoSelection *selection = canvas()->shapeManager()->selection(); selection->deselectAll(); selection->select(pathShape); if (startShape) canvas()->shapeController()->removeShape(startShape, cmd); if (endShape && startShape != endShape) canvas()->shapeController()->removeShape(endShape, cmd); canvas()->addCommand(cmd); } else { canvas()->updateCanvas(pathShape->boundingRect()); delete pathShape; } }
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 KPrViewModeNotes::updateActivePage( KoPAPageBase *page ) { if ( m_view->activePage() != page ) { m_view->setActivePage( page ); } KPrPage *prPage = dynamic_cast<KPrPage *>( page ); if ( !prPage ) return; KPrNotes *notes = prPage->pageNotes(); notes->updatePageThumbnail(); KoShapeLayer* layer = dynamic_cast<KoShapeLayer*>( notes->childShapes().last() ); KoPageLayout &layout = notes->pageLayout(); QSize size(layout.width, layout.height); m_view->horizontalRuler()->setRulerLength(layout.width); m_view->verticalRuler()->setRulerLength(layout.height); m_view->horizontalRuler()->setActiveRange(layout.left, layout.width - layout.right); m_view->verticalRuler()->setActiveRange(layout.top, layout.height - layout.bottom); m_view->zoomController()->setPageSize(size); m_view->zoomController()->setDocumentSize(size); m_canvas->update(); m_canvas->shapeManager()->setShapes( layer->childShapes() ); m_canvas->masterShapeManager()->setShapes(QList<KoShape*>()); KoSelection *selection = m_canvas->shapeManager()->selection(); selection->select(notes->textShape()); selection->setActiveLayer( layer ); QString tool = KoToolManager::instance()->preferredToolForSelection(selection->selectedShapes()); KoToolManager::instance()->switchToolRequested(tool); }
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; }
void KarbonCalligraphyTool::deactivate() { if (m_lastShape && canvas()->shapeManager()->shapes().contains(m_lastShape)) { KoSelection *selection = canvas()->shapeManager()->selection(); selection->deselectAll(); selection->select(m_lastShape); } }
bool KisNodeManager::Private::activateNodeImpl(KisNodeSP node) { Q_ASSERT(view); Q_ASSERT(view->canvasBase()); Q_ASSERT(view->canvasBase()->globalShapeManager()); Q_ASSERT(imageView); if (node && node == q->activeNode()) { return false; } // Set the selection on the shape manager to the active layer // and set call KoSelection::setActiveLayer( KoShapeLayer* layer ) // with the parent of the active layer. KoSelection *selection = view->canvasBase()->globalShapeManager()->selection(); Q_ASSERT(selection); selection->deselectAll(); if (!node) { selection->setActiveLayer(0); imageView->setCurrentNode(0); maskManager.activateMask(0); layerManager.activateLayer(0); } else { KoShape * shape = view->document()->shapeForNode(node); Q_ASSERT(shape); selection->select(shape); KoShapeLayer * shapeLayer = dynamic_cast<KoShapeLayer*>(shape); Q_ASSERT(shapeLayer); // shapeLayer->setGeometryProtected(node->userLocked()); // shapeLayer->setVisible(node->visible()); selection->setActiveLayer(shapeLayer); imageView->setCurrentNode(node); if (KisLayerSP layer = dynamic_cast<KisLayer*>(node.data())) { maskManager.activateMask(0); layerManager.activateLayer(layer); } else if (KisMaskSP mask = dynamic_cast<KisMask*>(node.data())) { maskManager.activateMask(mask); // XXX_NODE: for now, masks cannot be nested. layerManager.activateLayer(static_cast<KisLayer*>(node->parent().data())); } } return true; }
void KoPAView::editSelectAll() { KoSelection* selection = kopaCanvas()->shapeManager()->selection(); if( !selection ) return; QList<KoShape*> shapes = activePage()->shapes(); foreach( KoShape *shape, shapes ) { KoShapeLayer *layer = dynamic_cast<KoShapeLayer *>( shape ); if ( layer ) { QList<KoShape*> layerShapes( layer->shapes() ); foreach( KoShape *layerShape, layerShapes ) { selection->select( layerShape ); layerShape->update(); } }
void KoPAView::addImages(const QList<QImage> &imageList, const QPoint &insertAt) { // get position from event and convert to document coordinates QPointF pos = zoomHandler()->viewToDocument(insertAt) + kopaCanvas()->documentOffset() - kopaCanvas()->documentOrigin(); // create a factory KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value("PictureShape"); if (!factory) { kWarning(30003) << "No picture shape found, cannot drop images."; return; } foreach(const QImage &image, imageList) { KoProperties params; QVariant v; v.setValue<QImage>(image); params.setProperty("qimage", v); KoShape *shape = factory->createShape(¶ms, d->doc->resourceManager()); if (!shape) { kWarning(30003) << "Could not create a shape from the image"; return; } shape->setPosition(pos); pos += QPointF(25,25); // increase the position for each shape we insert so the // user can see them all. KUndo2Command *cmd = kopaCanvas()->shapeController()->addShapeDirect(shape); if (cmd) { KoSelection *selection = kopaCanvas()->shapeManager()->selection(); selection->deselectAll(); selection->select(shape); } kopaCanvas()->addCommand(cmd); }
void TestSelection::testSelectedShapes() { KoSelection selection; MockShape *shape1 = new MockShape(); MockShape *shape2 = new MockShape(); MockShape *shape3 = new MockShape(); QCOMPARE(selection.count(), 0); QCOMPARE(selection.selectedShapes().count(), 0); selection.select(shape1); QCOMPARE(selection.count(), 1); QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 1); QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 1); QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 1); selection.select(shape1); // same one. QCOMPARE(selection.count(), 1); QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 1); QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 1); QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 1); selection.select(shape2); selection.select(shape3); QCOMPARE(selection.count(), 3); QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 3); QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 3); QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 3); MockGroup *group1 = new MockGroup(); group1->addShape(shape1); group1->addShape(shape2); selection.select(group1); QCOMPARE(selection.count(), 3); // don't return the grouping shape. // Stripped returns no groups, so simply all 3 shapes QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 3); // stripped returns no groups; so simply all shapes. QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 3); // toplevel returns shape3 and group1 QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 2); MockGroup *group2 = new MockGroup(); group2->addShape(shape3); group2->addShape(group1); selection.select(group2); QCOMPARE(selection.count(), 3); // thats 5 minus 2 grouping shapes. // Stripped returns no groups, so simply all 3 shapes QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 3); // Stripped returns no groups, so simply all 3 shapes QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 3); // toplevel returns only group2 QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 1); group1->removeShape(shape1); group1->removeShape(shape2); MockContainer *container = new MockContainer(); container->addShape(shape1); container->addShape(shape2); selection.select(container); QCOMPARE(selection.count(), 4); // thats 6 minus 2 grouping shapes. // Stripped returns no groups, so simply all 3 shapes + container QCOMPARE(selection.selectedShapes(KoFlake::FullSelection).count(), 4); // Stripped returns no groups, and no children of a container. So; container + shape3 QCOMPARE(selection.selectedShapes(KoFlake::StrippedSelection).count(), 2); // toplevel returns only group2 + container QCOMPARE(selection.selectedShapes(KoFlake::TopLevelSelection).count(), 2); delete group2; delete container; }