Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
KoCreateShapeStrategy::KoCreateShapeStrategy(KoCreateShapesTool *tool, const QPointF &clicked)
        : KoShapeRubberSelectStrategy(tool, clicked, tool->canvas()->snapToGrid())
{
    KoCreateShapesTool *parent = static_cast<KoCreateShapesTool*>(d_ptr->tool);
    KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value(parent->shapeId());
    if (factory) {
        const KoProperties *props = parent->shapeProperties();
        KoShape *shape;
        if (props) {
            shape = factory->createShape(props);
        } else {
            shape = factory->createDefaultShape();
        }

        m_outline = shape->outline();
        m_outlineBoundingRect = m_outline.boundingRect();
        delete shape;
    }
}
Esempio n. 4
0
KoCreateShapeStrategy::KoCreateShapeStrategy(KoCreateShapesTool *tool, KoCanvasBase *canvas, const QPointF &clicked)
        : KoShapeRubberSelectStrategy(tool, canvas, clicked, canvas->snapToGrid())
{
    KoCreateShapesTool *parent = static_cast<KoCreateShapesTool*>(m_parent);
    KoShapeFactory *factory = KoShapeRegistry::instance()->value(parent->shapeId());
    if (factory) {
        QMap<QString, KoDataCenter *> dataCenterMap;
        const KoProperties *props = parent->shapeProperties();
        KoShape *shape;
        if (props) {
            // it is ok that the data center map is empty as the shape is never added to the document
            shape = factory->createShapeAndInit(props, dataCenterMap);
        } else {
            // it is ok that the data center map is empty as the shape is never added to the document
            shape = factory->createDefaultShapeAndInit(dataCenterMap);
        }

        m_outline = shape->outline();
        m_outlineBoundingRect = m_outline.boundingRect();
        delete shape;
    }
}