コード例 #1
0
UBEditableGraphicsLineItem::UBEditableGraphicsLineItem(QGraphicsItem* parent)
    : UBEditableGraphicsPolygonItem(parent)
{
    // Line has Stroke and Fill capabilities :
    Delegate()->setCanReturnInCreationMode(false);
    initializeStrokeProperty();
    initializeFillingProperty();

    UBFreeHandle *startHandle = new UBFreeHandle;
    UBFreeHandle *endHandle = new UBFreeHandle;

    endHandle->setId(1);

    startHandle->setParentItem(this);
    endHandle->setParentItem(this);

    startHandle->setEditableObject(this);
    endHandle->setEditableObject(this);

    startHandle->hide();
    endHandle->hide();

    mHandles.push_back(startHandle);
    mHandles.push_back(endHandle);

    mIsMagnetic = true;
}
コード例 #2
0
ファイル: UBFreeHandle.cpp プロジェクト: KubaO/Sankore-3.1
void UBFreeHandle::copyItemParameters(UBItem *copy) const
{
    UBFreeHandle *cp = dynamic_cast<UBFreeHandle*>(copy);
    if (cp)
    {
        cp->setTransform(this->transform());
        cp->setFlag(QGraphicsItem::ItemIsMovable, true);
        cp->setFlag(QGraphicsItem::ItemIsSelectable, true);
        cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType));
        cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked));

        cp->setPos(pos());
        cp->setEditableObject(cp->editableObject());
    }
}
コード例 #3
0
void UBEditableGraphicsPolygonItem::copyItemParameters(UBItem *copy) const
{
    UBAbstractEditableGraphicsPathItem::copyItemParameters(copy);

    UBEditableGraphicsPolygonItem *cp = dynamic_cast<UBEditableGraphicsPolygonItem*>(copy);

    if(cp){
        for(int i = 0; i < mHandles.size(); i++){
            UBFreeHandle *handle = new UBFreeHandle();

            handle->setParentItem(cp);
            handle->setEditableObject(cp);
            handle->setPos(mHandles.at(i)->pos());
            handle->setId(mHandles.at(i)->getId());
            handle->hide();

            cp->mHandles.push_back(handle);
        }

        cp->mIsInCreationMode = mIsInCreationMode;
        cp->mClosed = mClosed;
        cp->mStartEndPoint[0] = mStartEndPoint[0];
        cp->mStartEndPoint[1] = mStartEndPoint[1];
    }
}
コード例 #4
0
void UBEditableGraphicsPolygonItem::addPoint(const QPointF & point)
{
    QPainterPath painterPath = path();

    if (painterPath.elementCount() == 0)
    {
        painterPath.moveTo(point); // For the first point added, we must use moveTo().
        setPath(painterPath);

        mStartEndPoint[0] = point;
    }
    else
    {
        // If clic on first point, close the polygon
        // TODO à terme : utiliser la surface de la première poignée.
        QPointF pointDepart(painterPath.elementAt(0).x, painterPath.elementAt(0).y);
        QPointF pointFin(painterPath.elementAt(painterPath.elementCount()-1).x, painterPath.elementAt(painterPath.elementCount()-1).y);


        QGraphicsEllipseItem poigneeDepart(pointDepart.x()-10, pointDepart.y()-10, 20, 20);
        QGraphicsEllipseItem poigneeFin(pointFin.x()-10, pointFin.y()-10, 20, 20);

        if (poigneeDepart.contains(point))
        {
            setClosed(true);
        }
        else
        {
            if(poigneeFin.contains(point)){
                mIsInCreationMode = false;
                mOpened = true;
            }else{
                painterPath.lineTo(point);
                setPath(painterPath);
            }
        }

        mStartEndPoint[1] = point;
    }

    if(!mClosed && !mOpened){
        UBFreeHandle *handle = new UBFreeHandle();

        addHandle(handle);

        handle->setParentItem(this);
        handle->setEditableObject(this);
        handle->setPos(point);
        handle->setId(path().elementCount()-1);
        handle->hide();
    }
}
コード例 #5
0
void UBGraphicsPathItem::copyItemParameters(UBItem *copy) const
{
    UBGraphicsPathItem *cp = dynamic_cast<UBGraphicsPathItem*>(copy);
    if (cp)
    {
        cp->setPath(QPainterPath(this->path()));

        cp->setTransform(this->transform());
        cp->setTransformOriginPoint(this->transformOriginPoint());

        cp->setFlag(QGraphicsItem::ItemIsMovable, true);
        cp->setFlag(QGraphicsItem::ItemIsSelectable, true);
        cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType));
        cp->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked));
        cp->setFlag(QGraphicsItem::ItemIsFocusable, true);

        if(Delegate()->action()){
            if(Delegate()->action()->linkType() == eLinkToAudio){
                UBGraphicsItemPlayAudioAction* audioAction = dynamic_cast<UBGraphicsItemPlayAudioAction*>(Delegate()->action());
                UBGraphicsItemPlayAudioAction* action = new UBGraphicsItemPlayAudioAction(audioAction->fullPath());
                cp->Delegate()->setAction(action);
            }
            else
                cp->Delegate()->setAction(Delegate()->action());
        }

        if (hasFillingProperty())
            cp->mFillingProperty = new UBFillProperty(*fillingProperty());

        if (hasStrokeProperty())
            cp->mStrokeProperty = new UBStrokeProperty(*strokeProperty());

        cp->mClosed = this->mClosed;

        for(int i = 0; i < mHandles.size(); i++){
            UBFreeHandle *handle = new UBFreeHandle();

            handle->setParentItem(cp);
            handle->setEditableObject(cp);
            handle->setPos(mHandles.at(i)->pos());
            handle->setId(mHandles.at(i)->getId());
            handle->hide();

            cp->mHandles.push_back(handle);
        }
    }
}