Exemplo n.º 1
0
void BindingIndicator::setItems(const QList<FormEditorItem *> &itemList)
{
    clear();

    if (itemList.count() == 1) {
        m_formEditorItem = itemList.first();
        QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode();

        if (qmlItemNode.hasBindingProperty("x")) {
            m_indicatorTopShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
            m_indicatorTopShape->updateBindingIndicator(leftLine(qmlItemNode));
        }

        if (qmlItemNode.hasBindingProperty("y")) {
            m_indicatorLeftShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
            m_indicatorLeftShape->updateBindingIndicator(topLine(qmlItemNode));
        }

        if (qmlItemNode.hasBindingProperty("width")) {
            m_indicatorRightShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
            m_indicatorRightShape->updateBindingIndicator(rightLine(qmlItemNode));
        }

        if (qmlItemNode.hasBindingProperty("height")) {
            m_indicatorBottomShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
            m_indicatorBottomShape->updateBindingIndicator(bottomLine(qmlItemNode));
        }
    }
}
void Snake::drawBorders()
{
    QPen myPen = QPen(Qt::black);
    QLineF topLine(0, 0, cellSize*nbCells, 0);
    QLineF leftLine(0, 0, 0, cellSize*nbCells);
    QLineF rightLine(cellSize*nbCells, 0, cellSize*nbCells, cellSize*nbCells);
    QLineF bottomLine(0, cellSize*nbCells, cellSize*nbCells, cellSize*nbCells);
    scene->addLine(topLine, myPen);
    scene->addLine(leftLine, myPen);
    scene->addLine(rightLine, myPen);
    scene-> addLine(bottomLine, myPen);
}
void UBGraphicsDelegateFrame::initializeTransform()
{
    QTransform itemTransform = delegated()->sceneTransform();
    QRectF itemRect = delegated()->boundingRect();
    QPointF topLeft = itemTransform.map(itemRect.topLeft());
    QPointF topRight = itemTransform.map(itemRect.topRight());
    QPointF  bottomLeft = itemTransform.map(itemRect.bottomLeft());

    qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1;
    mMirrorX = horizontalFlip < 0 ;
    if(horizontalFlip < 0) {
        // why this is because of the way of calculating the translations that checks which side is the most is the
        // nearest instead of checking which one is the left side.
        QPointF tmp = topLeft;
        topLeft = topRight;
        topRight = tmp;

        // because of the calculation of the height is done by lenght and not deltaY
        bottomLeft = itemTransform.map(itemRect.bottomRight());
    }

    qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1;
    // not sure that is usefull
    mMirrorY = verticalFlip < 0;
    if(verticalFlip < 0 && !mMirrorX) {
        topLeft = itemTransform.map(itemRect.bottomLeft());
        topRight = itemTransform.map(itemRect.bottomRight());
        bottomLeft = itemTransform.map(itemRect.topLeft());
    }

    QLineF topLine(topLeft, topRight);
    QLineF leftLine(topLeft, bottomLeft);
    qreal width = topLine.length();
    qreal height = leftLine.length();

    mAngle = topLine.angle();

    // the fact the the length is used we loose the horizontalFlip information
    // a better way to do this is using DeltaX that preserve the direction information.
    mTotalScaleX = (width / itemRect.width()) * horizontalFlip;
    mTotalScaleY = height / itemRect.height() * verticalFlip;

    QTransform tr;
    QPointF center = delegated()->boundingRect().center();
    tr.translate(center.x() * mTotalScaleX, center.y() * mTotalScaleY);
    tr.rotate(-mAngle);
    tr.translate(-center.x() * mTotalScaleX, -center.y() * mTotalScaleY);
    tr.scale(mTotalScaleX, mTotalScaleY);

    mTotalTranslateX = delegated()->transform().dx() - tr.dx();
    mTotalTranslateY = delegated()->transform().dy() - tr.dy();
}
Exemplo n.º 4
0
    foreach (FormEditorItem *formEditorItem, itemList) {
        if (formEditorItem == m_formEditorItem) {
            QmlItemNode qmlItemNode = m_formEditorItem->qmlItemNode();

            if (qmlItemNode.hasBindingProperty("x")) {
                if (m_indicatorTopShape.isNull())
                    m_indicatorTopShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
                m_indicatorTopShape->updateBindingIndicator(leftLine(qmlItemNode));
            } else {
                delete m_indicatorTopShape;
            }

            if (qmlItemNode.hasBindingProperty("y")) {
                if (m_indicatorLeftShape.isNull())
                    m_indicatorLeftShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
                m_indicatorLeftShape->updateBindingIndicator(topLine(qmlItemNode));
            } else {
                delete m_indicatorLeftShape;
            }

            if (qmlItemNode.hasBindingProperty("width")) {
                if (m_indicatorRightShape.isNull())
                    m_indicatorRightShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
                m_indicatorRightShape->updateBindingIndicator(rightLine(qmlItemNode));
            } else {
                delete m_indicatorRightShape;
            }

            if (qmlItemNode.hasBindingProperty("height")) {
                if (m_indicatorBottomShape.isNull())
                    m_indicatorBottomShape = new BindingIndicatorGraphicsItem(m_layerItem.data());
                m_indicatorBottomShape->updateBindingIndicator(bottomLine(qmlItemNode));
            } else {
                delete m_indicatorBottomShape;
            }

            return;
        }
    }
Exemplo n.º 5
0
void UBGraphicsTriangle::updateResizeCursor()
{
    QPixmap pix(":/images/cursors/resize.png");
    QTransform itemTransform = sceneTransform();
    QRectF itemRect = boundingRect();

    QPointF topLeft = itemTransform.map(itemRect.topLeft());
    QPointF topRight = itemTransform.map(itemRect.topRight());
    QPointF bottomLeft = itemTransform.map(itemRect.bottomLeft());

    QLineF topLine(topLeft, topRight);
    QLineF leftLine(topLeft, bottomLeft);

    qreal angle = topLine.angle();
    QTransform tr1;
    tr1.rotate(- angle);
    mResizeCursor1  = QCursor(pix.transformed(tr1, Qt::SmoothTransformation), pix.width() / 2,  pix.height() / 2);

    angle = leftLine.angle();
    QTransform tr2;
    tr2.rotate(- angle);
    mResizeCursor2  = QCursor(pix.transformed(tr2, Qt::SmoothTransformation), pix.width() / 2,  pix.height() / 2);
}
Exemplo n.º 6
0
void DataStorePrivate::insertStringAtIndex(const char* inString, uint index)
{
    uint inStringLength = strlen(inString);
    uint lineNumber;
    uint indexInLine;
    if (!GetPositionInStorageForIndex(_dataStorage, lineNumber, indexInLine, index))
    {
        return;
    }
    _stringLength += inStringLength;

    if (_dataStorage[lineNumber]->size() + inStringLength <= kMaxCharactersPerLineConteiner)
    {
        SubBaseTypePtr currentLine = _dataStorage[lineNumber];
        currentLine->insert(currentLine->begin() + indexInLine, inString, inString + inStringLength);
    }
    else if (0 == indexInLine)
    {
        uint lastCharCount = inStringLength % kMaxCharactersPerLineConteiner;
        uint sectorCount = inStringLength / kMaxCharactersPerLineConteiner;
        SubBaseTypePtr line;
        for (int i = 0; i < sectorCount; i++)
        {
            line = new SubBaseType(inString, inString + kMaxCharactersPerLineConteiner);
            _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
            lineNumber++;
            inString += kMaxCharactersPerLineConteiner;
        }

        if (lastCharCount)
        {
            line = new SubBaseType(inString, inString + lastCharCount);
            _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
        }
    }
    else
    {
        SubBaseTypePtr currentLine = _dataStorage[lineNumber];
        SubBaseType leftLine(currentLine->begin() + indexInLine, currentLine->end());

        currentLine->erase(currentLine->begin() + indexInLine, currentLine->end());

        uint needAddToComplete = kMaxCharactersPerLineConteiner - currentLine->size();
        if (inStringLength < needAddToComplete)
        {
            needAddToComplete = inStringLength;
        }
        currentLine->insert(currentLine->end(), inString, inString + needAddToComplete);
        inString += needAddToComplete;
        inStringLength -= needAddToComplete;
        lineNumber++;

        uint lastCharCount = inStringLength % kMaxCharactersPerLineConteiner;
        uint sectorCount = inStringLength / kMaxCharactersPerLineConteiner;
        SubBaseTypePtr line;
        for (int i = 0; i < sectorCount; i++)
        {
            line = new SubBaseType(inString, inString + kMaxCharactersPerLineConteiner);
            _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
            lineNumber++;
            inString += kMaxCharactersPerLineConteiner;
        }

        bool isLastCharactersAdded = false;
        if (lastCharCount)
        {
            line = new SubBaseType(inString, inString + lastCharCount);
            if (lastCharCount + leftLine.size() <= kMaxCharactersPerLineConteiner)
            {
                line->insert(line->end(), leftLine.begin(), leftLine.end());
                isLastCharactersAdded = true;
            }
            else
            {
                _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
                lineNumber++;
            }
        }
        if (!isLastCharactersAdded)
        {
            line = new SubBaseType(leftLine.begin(), leftLine.end());
        }

        _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
    }
}
Exemplo n.º 7
0
void DataStorePrivate::insertStringAtIndex(const DataStorePrivate& inDataStorePrivate, uint index)
{
    uint inStringLength = inDataStorePrivate.getStringLength();
    uint lineNumber;
    uint indexInLine;
    if (!GetPositionInStorageForIndex(_dataStorage, lineNumber, indexInLine, index))
    {
        return;
    }
    _stringLength += inStringLength;

    if (_dataStorage[lineNumber]->size() + inStringLength <= kMaxCharactersPerLineConteiner)
    {
        SubBaseTypePtr currentLine = _dataStorage[lineNumber];
        currentLine->insert(currentLine->begin() + indexInLine, inDataStorePrivate.begin(),
                            inDataStorePrivate.begin() + inStringLength);
    }
    else if (0 == indexInLine)
    {
        uint lastCharCount = inStringLength % kMaxCharactersPerLineConteiner;
        uint sectorCount = inStringLength / kMaxCharactersPerLineConteiner;
        SubBaseTypePtr line;
        uint offset = 0;
        for (int i = 0; i < sectorCount; i++)
        {
            line = new SubBaseType(inDataStorePrivate.begin() + offset,
                                   inDataStorePrivate.iteratorFromIndex(kMaxCharactersPerLineConteiner + offset));
            _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
            lineNumber++;
            offset += kMaxCharactersPerLineConteiner;
        }

        if (lastCharCount)
        {
            line = new SubBaseType(inDataStorePrivate.begin() + offset,
                                   inDataStorePrivate.iteratorFromIndex(offset + lastCharCount));
            _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
        }
    }
    else
    {
        SubBaseTypePtr currentLine = _dataStorage[lineNumber];
        SubBaseType leftLine(currentLine->begin() + indexInLine, currentLine->end());

        currentLine->erase(currentLine->begin() + indexInLine, currentLine->end());

        uint offset = kMaxCharactersPerLineConteiner - currentLine->size();
        if (inStringLength < offset)
        {
            offset = inStringLength;
        }
        currentLine->insert(currentLine->end(), inDataStorePrivate.begin(),
                            inDataStorePrivate.begin() + offset);
        inStringLength -= offset;
        lineNumber++;

        uint lastCharCount = inStringLength % kMaxCharactersPerLineConteiner;
        uint sectorCount = inStringLength / kMaxCharactersPerLineConteiner;
        SubBaseTypePtr line;
        for (int i = 0; i < sectorCount; i++)
        {
            line = new SubBaseType(inDataStorePrivate.begin() + offset,
                                   inDataStorePrivate.iteratorFromIndex(offset + kMaxCharactersPerLineConteiner));
            _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
            lineNumber++;
            offset += kMaxCharactersPerLineConteiner;
        }

        bool isLastCharactersAdded = false;
        if (lastCharCount)
        {
            line = new SubBaseType(inDataStorePrivate.begin() + offset,
                                   inDataStorePrivate.iteratorFromIndex(offset + lastCharCount));
            if (lastCharCount + leftLine.size() <= kMaxCharactersPerLineConteiner)
            {
                line->insert(line->end(), leftLine.begin(), leftLine.end());
                isLastCharactersAdded = true;
            }
            else
            {
                _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
                lineNumber++;
            }
        }
        if (!isLastCharactersAdded)
        {
            line = new SubBaseType(leftLine.begin(), leftLine.end());
        }

        _dataStorage.insert(_dataStorage.begin() + lineNumber, line);
    }
}
Exemplo n.º 8
0
void Triangle::draw(const Point& x, const double _angle)
{
    allPixels = 0;
    transparentPixels = 0;
    borderPixels = 0;
    setPoints(x, _angle);
    //Search point with max(y)
    enum Position {TOP = 0, MIDDLE = 1, BOTTOM = 2};

    Point sortPoints[3] = {points[0], points[1], points[2]};
    std::sort(sortPoints, sortPoints + 3, ycomp);
    Position left, right;

    if(sortPoints[MIDDLE].first > sortPoints[BOTTOM].first)
    {
        left = BOTTOM;
        right = MIDDLE;
    }
    else
    {
        left = MIDDLE;
        right = BOTTOM;
    }

    int lineNumber = sortPoints[TOP].second;

    Point leftBorder = sortPoints[TOP], rightBorder = sortPoints[TOP];
    Point bottomBorder = sortPoints[MIDDLE];

    Line leftLine(sortPoints[TOP], sortPoints[left]);
    Line rightLine(sortPoints[TOP], sortPoints[right]);
    Line bottomLine(sortPoints[MIDDLE], sortPoints[BOTTOM]);

    while(!EQUAL(sortPoints[BOTTOM], leftBorder))
    {
        if(leftBorder.first + 1 < rightBorder.first)
        {
            for(int i = leftBorder.first + 1; i < rightBorder.first; i++)
            {
                view->setPixel(i, lineNumber, getColor(Point(i, lineNumber)));
                allPixels++;
            }
        }
        else
        {
            for(int i = rightBorder.first + 1; i < leftBorder.first; i++)
            {
                allPixels++;
                view->setPixel(i, lineNumber, getColor(Point(i, lineNumber)));
            }
        }

        while(rightBorder.second == lineNumber)
        {
            if(EQUAL(rightBorder, sortPoints[MIDDLE]))
            {
                rightBorder = bottomBorder;
                rightLine = bottomLine;
            }
            if(EQUAL(rightBorder, sortPoints[BOTTOM]))
            {
                break;
            }
            rightBorder = rightLine.next();
        }
        while(leftBorder.second == lineNumber)
        {
            if(EQUAL(leftBorder, sortPoints[BOTTOM]))
            {
                break;
            }
            if(EQUAL(leftBorder, sortPoints[MIDDLE]))
            {
                leftBorder = bottomBorder;
                leftLine = bottomLine;
            }
            leftBorder = leftLine.next();
        }
        lineNumber++;
    }

    leftBorder = sortPoints[TOP];
    rightBorder = sortPoints[TOP];
    bottomBorder = sortPoints[MIDDLE];

    leftLine = Line(sortPoints[TOP], sortPoints[left]);
    rightLine = Line(sortPoints[TOP], sortPoints[right]);
    bottomLine = Line(sortPoints[MIDDLE], sortPoints[BOTTOM]);

    while(leftBorder != sortPoints[left])
    {
        view->setPixel(leftBorder.first, leftBorder.second, 0x0);
        leftBorder = leftLine.next();
        allPixels++;
        borderPixels++;
    }
    while(rightBorder != sortPoints[right])
    {
        view->setPixel(rightBorder.first, rightBorder.second, 0x0);
        rightBorder = rightLine.next();
        allPixels++;
        borderPixels++;
    }
    while(bottomBorder != sortPoints[BOTTOM])
    {
        view->setPixel(bottomBorder.first, bottomBorder.second, 0x0);
        bottomBorder = bottomLine.next();
        allPixels++;
        borderPixels++;
    }

    allPixels++;
    borderPixels++;
    view->setPixel(sortPoints[BOTTOM].first, sortPoints[BOTTOM].second, 0x0);

}