コード例 #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));
        }
    }
}
コード例 #2
0
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);
}
コード例 #3
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;
        }
    }
コード例 #4
0
ファイル: NCMenu.cpp プロジェクト: ronw23/prime-osx
void
shNCursesMenu::accumulateResults ()
{
    const int map_end = 64; /* column map ends */
    WINDOW *win, *helpwin = NULL;
    PANEL *panel, *helppanel = NULL;

    int helplines;
    free (prepareHelp (&helplines));

    /* Two additional lines besides all the choices are the menu title
       and --End-- or --More-- at the bottom. */
    mItemHeight = mini (mHeight - helplines, mChoices.count () + 2);
    int width = 10;
    int gap = 0; /* Used to position the menu. */
    for (int i = 0; i < mChoices.count (); ++i) {
        width = maxi (width, strlen (mChoices.get (i)->mText) + 1);
    }
    if (!(mFlags & kNoPick)) width += 10; /* Adjust for "( ) x - " prompts. */
    /* Main header might be still longer. */
    width = maxi (width, strlen (mPrompt) + 2);
    if (mFlags & kCategorizeObjects) { /* Do not center item lists. */
        /* Determine whether window can leave sidebar unobscured. */
        if (width <= map_end) { /* Yes! */
            width = map_end;
        } else {                /* No, so hide it whole. */
            width = mWidth;
        }
    } else {
        width = mini (mWidth, width);
        if (width > map_end) { /* Would obscure side bar window? */
            width = mWidth;    /* Then cover it whole. */
        } else { /* Place small gap between sidebar and menu if possible. */
            gap = mini (10, (map_end - width) / 2);
        }
    }

    win = newwin (mItemHeight, width, 0, maxi (0, map_end - width) - gap);
    if (!win) {
        debug.log ("Unable to create window (%d, %d, %d, %d)",
                  mItemHeight, width, 0, maxi (0, map_end - width));
        I->p ("Uh oh!  Couldn't create window!!");
        mDone = 1;
        return;
    }
    keypad (win, TRUE);
    panel = new_panel (win);
    if (helplines) {
        helpwin = newwin (helplines, 80, mHeight - helplines, 0);
        if (!helpwin) {
            debug.log ("Unable to create help window (%d, %d, %d, %d)",
                      helplines, 80, mHeight - helplines, 0);
            I->p ("Uh oh!  Couldn't create help window!!");
            mDone = 1;
            return;
        }
        helppanel = new_panel (helpwin);
        showHelp (helpwin);
    }

    /* -2 lines to make space for header and --End-- or similar. */
    mLast = mini (mOffset + mItemHeight - 2, mChoices.count ());
    while (1) { /* Menu loop. */
        /* Menu header: */
        wattrset (win, A_BOLD);
        mvwaddnstr (win, 0, 1, mPrompt, width);
        wclrtoeol (win);

        wattrset (win, A_NORMAL);
        int i;
        for (i = mOffset; i < mLast; ++i) {
            /* First, clear line. */
            wmove (win, 1 + i - mOffset, 0);
            wclrtoeol (win);
            /* Then draw. */
            char buf[100];
            shMenuChoice *item = mChoices.get (i);

            if (item->mLetter >= 0 and (shMenu::kCategorizeObjects & mFlags)
                and ((shObject *) item->mValue.mPtr)->isKnownRadioactive ())
            {
                wattrset (win, ColorMap[kGreen]);
            }
            if (-2 == item->mLetter) { /* This is a pretty delimiter. */
                int len = strlen (item->mText);
                int j = (width - len) / 2;
                char *spaces = GetBuf ();
                for (int i = 0; i < j; ++i) {
                    spaces[i] = ' ';
                }
                spaces[j] = '\0';
                snprintf (buf, 100, "%s%s%s", spaces, item->mText, spaces);
            } else if (-1 == item->mLetter) { /* This is a header entry. */
                if (kCategorizeObjects & mFlags and mFlags & kMultiPick) {
                    /* Get category header. */
                    char part[50];
                    snprintf (part, 50, " %s ", item->mText);
                    char *gap = strstr (part, "  "); /* Find gap. */
                    gap[1] = 0; /* Truncate. */
                    wattrset (win, A_REVERSE);
                    mvwaddnstr (win, 1 + i - mOffset, 1, part, width);
                    /* Get (toggle all with X) part. */
                    char *p2 = strstr (item->mText, "(t");
                    int len = strlen (p2);
                    snprintf (part, len-2, "%s", item->mText);
                    wattrset (win, ColorMap[kBlue]);
                    mvwaddnstr (win, 1 + i - mOffset, width-21, p2, width);
                    /* The toggle key should stand out. */
                    snprintf (buf, len - 1, "%c", p2[len - 2]);
                    mvwaddch (win, 1 + i - mOffset, width-21+len-2,
                              p2[len - 2] | ColorMap[kWhite]);
                    buf[0] = 0; /* Printing is done. */
                } else {
                    wattrset (win, A_REVERSE);
                    snprintf (buf, 100, " %s ", item->mText);
                }
            } else if (mFlags & kNoPick) {
                if (' ' == item->mLetter) {
                    snprintf (buf, 100, "%s", item->mText);
                } else {
                    snprintf (buf, 100, "%c - %s", item->mLetter, item->mText);
                }
            } else {
                if (' ' == item->mLetter) {
                    snprintf (buf, 100, "        %s", item->mText);
                } else if (mFlags & kShowCount) {
                    if (item->mSelected) {
                        snprintf (buf, 100, "(%d) %c - %s",
                            item->mSelected, item->mLetter, item->mText);
                    } else {
                        snprintf (buf, 100, "( ) %c - %s",
                            item->mLetter, item->mText);
                    }
                } else {
                    snprintf (buf, 100, "(%c) %c - %s",
                              0 == item->mSelected ? ' ' :
                              item->mCount == item->mSelected ? 'X' : '#',
                              item->mLetter, item->mText);
                }
            }
            mvwaddnstr (win, 1 + i - mOffset, 1, buf, width);
            wattrset (win, A_NORMAL);
        }
        mvwaddnstr (win, 1 + i - mOffset, 1, bottomLine (i), width);

        while (1) {
            if (helplines) {
                showHelp (helpwin);
                touchwin (helpwin);
            }
            update_panels ();
            doupdate();
            int key = I->getChar ();

            if (27 == key or 13 == key or ' ' == key) { /* done */
                mDone = 1; break;
            } else if (KEY_BACKSPACE == key) {
                interpretKey (0, shInterface::kDrop); break;
            } else if (KEY_HOME == key or KEY_A1 == key) {
                interpretKey (0, shInterface::kMoveNW); break;
            } else if (KEY_END == key or KEY_C1 == key) {
                interpretKey (0, shInterface::kMoveSW); break;
            } else if (KEY_UP == key) {
                interpretKey (0, shInterface::kMoveUp); break;
            } else if (KEY_DOWN == key) {
                interpretKey (0, shInterface::kMoveDown); break;
            } else if (KEY_PPAGE == key or KEY_LEFT == key or KEY_A3 == key) {
                interpretKey (0, shInterface::kMoveNE); break;
            } else if (KEY_NPAGE == key or KEY_RIGHT == key or KEY_C3 == key) {
                interpretKey (0, shInterface::kMoveSE); break;
            } else if ('\t' == key and mHelpFileName) { /* invoke help */
                interpretKey (0, shInterface::kHelp); break;
            } else if (mFlags & kNoPick) {
                continue;
            } else {
                if (interpretKey (key)) break;
            }
            if (mDone) break;
        }
        if (mDone) break;
    }
    /* Clean up. */
    hide_panel (panel);
    del_panel (panel);
    delwin (win);
    if (helplines) {
        hide_panel (helppanel);
        del_panel (helppanel);
        delwin (helpwin);
    }
    update_panels ();
    I->drawScreen ();
}
コード例 #5
0
ファイル: Triangle.cpp プロジェクト: sumboid/qt-problems
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);

}
コード例 #6
0
ファイル: characteranalysis.cpp プロジェクト: Witek-/openalpr
vector<bool> CharacterAnalysis::filterBetweenLines(Mat img, vector<vector<Point> > contours, vector<Vec4i> hierarchy, vector<Point> outerPolygon, vector<bool> goodIndices)
{
    static float MIN_AREA_PERCENT_WITHIN_LINES = 0.88;

    vector<bool> includedIndices(contours.size());
    for (int j = 0; j < contours.size(); j++)
        includedIndices[j] = false;


    if (outerPolygon.size() == 0)
        return includedIndices;

    vector<Point> validPoints;

    // Figure out the line height
    LineSegment topLine(outerPolygon[0].x, outerPolygon[0].y, outerPolygon[1].x, outerPolygon[1].y);
    LineSegment bottomLine(outerPolygon[3].x, outerPolygon[3].y, outerPolygon[2].x, outerPolygon[2].y);

    float x = ((float) img.cols) / 2;
    Point midpoint = Point(x, bottomLine.getPointAt(x));
    Point acrossFromMidpoint = topLine.closestPointOnSegmentTo(midpoint);
    float lineHeight = distanceBetweenPoints(midpoint, acrossFromMidpoint);

    // Create a white mask for the area inside the polygon
    Mat outerMask = Mat::zeros(img.size(), CV_8U);
    Mat innerArea = Mat::zeros(img.size(), CV_8U);
    fillConvexPoly(outerMask, outerPolygon.data(), outerPolygon.size(), Scalar(255,255,255));


    for (int i = 0; i < contours.size(); i++)
    {
        if (goodIndices[i] == false)
            continue;

        // get rid of the outline by drawing a 1 pixel width black line
        drawContours(innerArea, contours,
                     i, // draw this contour
                     cv::Scalar(255,255,255), // in
                     CV_FILLED,
                     8,
                     hierarchy,
                     0
                    );


        bitwise_and(innerArea, outerMask, innerArea);


        vector<vector<Point> > tempContours;
        findContours(innerArea, tempContours,
                     CV_RETR_EXTERNAL, // retrieve the external contours
                     CV_CHAIN_APPROX_SIMPLE ); // all pixels of each contours );

        double totalArea = contourArea(contours[i]);
        double areaBetweenLines = 0;

        for (int tempContourIdx = 0; tempContourIdx < tempContours.size(); tempContourIdx++)
        {
            areaBetweenLines += contourArea(tempContours[tempContourIdx]);

        }


        if (areaBetweenLines / totalArea >= MIN_AREA_PERCENT_WITHIN_LINES)
        {
            includedIndices[i] = true;
        }

        innerArea.setTo(Scalar(0,0,0));
    }

    return includedIndices;
}