void KarbonView::dropEvent( QDropEvent *e ) { debugView("KarbonView::dropEvent()"); //Accepts QColor - from Color Manager's KColorPatch QColor color = KColorMimeData::fromMimeData( e->mimeData() ); if ( color.isValid() ) { KoSelection * selection = d->canvas->shapeManager()->selection(); if( ! selection ) return; if( ! part() ) return; if( d->canvas->resourceProvider()->intResource( Karbon::ActiveStyle ) == Karbon::Foreground ) { QList<KoShapeBorderModel*> borders; QList<KoShape*> selectedShapes = selection->selectedShapes(); foreach( KoShape * shape, selectedShapes ) { KoLineBorder * border = dynamic_cast<KoLineBorder*>( shape->border() ); KoLineBorder * newBorder = 0; if( border ) { newBorder = new KoLineBorder( *border ); newBorder->setColor( color ); } else { newBorder = new KoLineBorder( 1.0, color ); } borders.append( newBorder ); }
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); }
void KPrView::createAnimation() { static int animationcount = 0; KoSelection * selection = kopaCanvas()->shapeManager()->selection(); QList<KoShape*> selectedShapes = selection->selectedShapes(); foreach( KoShape * shape, selectedShapes ) { Q_UNUSED(shape); /*KPrShapeAnimationOld * animation = new KPrAnimationMoveAppear( shape, animationcount ); KPrDocument * doc = static_cast<KPrDocument *>( kopaDocument() ); KPrAnimationCreateCommand * command = new KPrAnimationCreateCommand( doc, animation ); kopaCanvas()->addCommand( command );*/ }
ShapeMoveStrategy::ShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked) : KoInteractionStrategy(tool, canvas) , m_start(clicked) { QList<KoShape*> selectedShapes = canvas->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection); QRectF boundingRect; foreach(KoShape *shape, selectedShapes) { if( ! shape->isEditable() ) continue; m_selectedShapes << shape; m_previousPositions << shape->position(); m_newPositions << shape->position(); boundingRect = boundingRect.unite( shape->boundingRect() ); } KoSelection * selection = m_canvas->shapeManager()->selection(); m_initialOffset = selection->absolutePosition( SelectionDecorator::hotPosition() ) - m_start; m_initialSelectionPosition = selection->position(); m_canvas->snapGuide()->setIgnoredShapes( selection->selectedShapes( KoFlake::FullSelection ) ); tool->setStatusText( i18n("Press ALT to hold x- or y-position.") ); }
void StrokeDocker::applyChanges() { KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController(); KoSelection *selection = canvasController->canvas()->shapeManager()->selection(); canvasController->canvas()->resourceProvider()->setActiveBorder( d->border ); if( ! selection || ! selection->count() ) return; KoLineBorder * newBorder = new KoLineBorder(d->border); KoLineBorder * oldBorder = dynamic_cast<KoLineBorder*>( selection->firstSelectedShape()->border() ); if( oldBorder ) { newBorder->setColor( oldBorder->color() ); newBorder->setLineBrush( oldBorder->lineBrush() ); } KoShapeBorderCommand *cmd = new KoShapeBorderCommand( selection->selectedShapes(), newBorder ); canvasController->canvas()->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; }
ShapeShearStrategy::ShapeShearStrategy( KoToolBase *tool, const QPointF &clicked, KoFlake::SelectionHandle direction ) : KoInteractionStrategy(tool) , m_start(clicked) { KoSelection *sel = tool->canvas()->shapeManager()->selection(); QList<KoShape*> selectedShapes = sel->selectedShapes(KoFlake::StrippedSelection); foreach(KoShape *shape, selectedShapes) { if( ! shape->isEditable() ) continue; m_selectedShapes << shape; m_oldTransforms << shape->transformation(); } m_initialSelectionMatrix = sel->transformation(); // Eventhoug we aren't currently activated by the corner handles we might as well code like it switch(direction) { case KoFlake::TopMiddleHandle: m_top = true; m_bottom = false; m_left = false; m_right = false; break; case KoFlake::TopRightHandle: m_top = true; m_bottom = false; m_left = false; m_right = true; break; case KoFlake::RightMiddleHandle: m_top = false; m_bottom = false; m_left = false; m_right = true; break; case KoFlake::BottomRightHandle: m_top = false; m_bottom = true; m_left = false; m_right = true; break; case KoFlake::BottomMiddleHandle: m_top = false; m_bottom = true; m_left = false; m_right = false; break; case KoFlake::BottomLeftHandle: m_top = false; m_bottom = true; m_left = true; m_right = false; break; case KoFlake::LeftMiddleHandle: m_top = false; m_bottom = false; m_left = true; m_right = false; break; case KoFlake::TopLeftHandle: m_top = true; m_bottom = false; m_left = true; m_right = false; break; default: ;// throw exception ? TODO } m_initialSize = sel->size(); m_solidPoint = QPointF( m_initialSize.width() / 2, m_initialSize.height() / 2); if(m_top) m_solidPoint += QPointF(0, m_initialSize.height() / 2); else if(m_bottom) m_solidPoint -= QPointF(0, m_initialSize.height() / 2); if(m_left) m_solidPoint += QPointF(m_initialSize.width() / 2, 0); else if(m_right) m_solidPoint -= QPointF(m_initialSize.width() / 2, 0); QPointF edge; qreal angle = 0.0; if( m_top ) { edge = sel->absolutePosition( KoFlake::BottomLeftCorner ) - sel->absolutePosition( KoFlake::BottomRightCorner ); angle = 180.0; } else if( m_bottom ) { edge = sel->absolutePosition( KoFlake::TopRightCorner ) - sel->absolutePosition( KoFlake::TopLeftCorner ); angle = 0.0; } else if( m_left ) { edge = sel->absolutePosition( KoFlake::BottomLeftCorner ) - sel->absolutePosition( KoFlake::TopLeftCorner ); angle = 90.0; } else if( m_right ) { edge = sel->absolutePosition( KoFlake::TopRightCorner ) - sel->absolutePosition( KoFlake::BottomRightCorner ); angle = 270.0; } qreal currentAngle = atan2( edge.y(), edge.x() ) / M_PI * 180; m_initialSelectionAngle = currentAngle - angle; kDebug(30006) <<" PREsol.x=" << m_solidPoint.x() <<" sol.y=" << m_solidPoint.y(); m_solidPoint = tool->canvas()->shapeManager()->selection()->absoluteTransformation(0).map( m_solidPoint ); // use crossproduct of top edge and left edge of selection bounding rect // to determine if the selection is mirrored QPointF top = sel->absolutePosition( KoFlake::TopRightCorner ) - sel->absolutePosition( KoFlake::TopLeftCorner ); QPointF left = sel->absolutePosition( KoFlake::BottomLeftCorner ) - sel->absolutePosition( KoFlake::TopLeftCorner ); m_isMirrored = (top.x()*left.y() - top.y()*left.x() ) < 0.0; }