Beispiel #1
0
void QPaintEnginePrivate::drawBoxTextItem(const QPointF &p, const QTextItemInt &ti)
{
    if (!ti.glyphs.numGlyphs)
        return;

    // any fixes here should probably also be done in QFontEngineBox::draw
    const int size = qRound(ti.fontEngine->ascent());
    QVarLengthArray<QFixedPoint> positions;
    QVarLengthArray<glyph_t> glyphs;
    QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - size);
    ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
    if (glyphs.size() == 0)
        return;

    QSize s(size - 3, size - 3);

    QPainter *painter = q_func()->state->painter();
    painter->save();
    painter->setBrush(Qt::NoBrush);
    QPen pen = painter->pen();
    pen.setWidthF(ti.fontEngine->lineThickness().toReal());
    painter->setPen(pen);
    for (int k = 0; k < positions.size(); k++)
        painter->drawRect(QRectF(positions[k].toPointF(), s));
    painter->restore();
}
void QNodeViewCanvas::drawBackground(QPainter* painter, const QRectF& rect)
{
    // GW-TODO: Expose this to QStyle
    painter->fillRect(rect, QBrush(QColor(50, 50, 50)));

    const qint32 gridInterval = 50;
    painter->setWorldMatrixEnabled(true);

    // GW-TODO: Expose this to QStyle
    QPen linePen(QColor(80, 80, 80), 1, Qt::DotLine, Qt::FlatCap, Qt::RoundJoin);
    linePen.setCosmetic(true); // Performance optimization
    painter->setPen(linePen);

    const qreal left = qint32(rect.left()) - (qint32(rect.left()) % gridInterval);
    const qreal top  = qint32(rect.top())  - (qint32(rect.top())  % gridInterval);

    QVarLengthArray<QLineF, 100> linesX;
    for (qreal x = left; x < rect.right(); x += gridInterval)
        linesX.append(QLineF(x, rect.top(), x, rect.bottom()));

    QVarLengthArray<QLineF, 100> linesY;
    for (qreal y = top; y < rect.bottom(); y += gridInterval)
        linesY.append(QLineF(rect.left(), y, rect.right(), y));

    painter->drawLines(linesX.data(), linesX.size());
    painter->drawLines(linesY.data(), linesY.size());
}
void QFontEngineQPF::draw(QPaintEngine *p, qreal _x, qreal _y, const QTextItemInt &si)
{
    QPaintEngineState *pState = p->state;
    QRasterPaintEngine *paintEngine = static_cast<QRasterPaintEngine*>(p);

    QTransform matrix = pState->transform();
    matrix.translate(_x, _y);
    QFixed x = QFixed::fromReal(matrix.dx());
    QFixed y = QFixed::fromReal(matrix.dy());

    QVarLengthArray<QFixedPoint> positions;
    QVarLengthArray<glyph_t> glyphs;
    getGlyphPositions(si.glyphs, si.num_glyphs, matrix, si.flags, glyphs, positions);
    if (glyphs.size() == 0)
        return;

    for(int i = 0; i < glyphs.size(); i++) {
        const Glyph *glyph = findGlyph(glyphs[i]);
        if (!glyph)
            continue;

        const bool mono = false; // ###

        paintEngine->alphaPenBlt(reinterpret_cast<const uchar *>(glyph) + sizeof(Glyph), glyph->bytesPerLine, mono,
                                     qRound(positions[i].x) + glyph->x,
                                     qRound(positions[i].y) + glyph->y,
                                     glyph->width, glyph->height);
    }
}
Beispiel #4
0
/*
    array = begin-array [ value *( value-separator value ) ] end-array
*/
bool Parser::parseArray()
{
    BEGIN << "parseArray";

    if (++nestingLevel > nestingLimit) {
        lastError = QJsonParseError::DeepNesting;
        return false;
    }

    int arrayOffset = reserveSpace(sizeof(QJsonPrivate::Array));

    QVarLengthArray<QJsonPrivate::Value, 64> values;

    if (!eatSpace()) {
        lastError = QJsonParseError::UnterminatedArray;
        return false;
    }
    if (*json == EndArray) {
        nextToken();
    } else {
        while (1) {
            QJsonPrivate::Value val;
            if (!parseValue(&val, arrayOffset))
                return false;
            values.append(val);
            char token = nextToken();
            if (token == EndArray)
                break;
            else if (token != ValueSeparator) {
                if (!eatSpace())
                    lastError = QJsonParseError::UnterminatedArray;
                else
                    lastError = QJsonParseError::MissingValueSeparator;
                return false;
            }
        }
    }

    DEBUG << "size =" << values.size();
    int table = arrayOffset;
    // finalize the object
    if (values.size()) {
        int tableSize = values.size()*sizeof(QJsonPrivate::Value);
        table = reserveSpace(tableSize);
        memcpy(data + table, values.constData(), tableSize);
    }

    QJsonPrivate::Array *a = (QJsonPrivate::Array *)(data + arrayOffset);
    a->tableOffset = table - arrayOffset;
    a->size = current - arrayOffset;
    a->is_object = false;
    a->length = values.size();

    DEBUG << "current=" << current;
    END;

    --nestingLevel;
    return true;
}
Beispiel #5
0
void QTriangulatingStroker::moveTo(const qreal *pts)
{
    m_cx = pts[0];
    m_cy = pts[1];

    float x2 = pts[2];
    float y2 = pts[3];
    normalVector(m_cx, m_cy, x2, y2, &m_nvx, &m_nvy);


    // To acheive jumps we insert zero-area tringles. This is done by
    // adding two identical points in both the end of previous strip
    // and beginning of next strip
    bool invisibleJump = m_vertices.size();

    switch (m_cap_style) {
    case Qt::FlatCap:
        if (invisibleJump) {
            m_vertices.add(m_cx + m_nvx);
            m_vertices.add(m_cy + m_nvy);
        }
        break;
    case Qt::SquareCap: {
        float sx = m_cx - m_nvy;
        float sy = m_cy + m_nvx;
        if (invisibleJump) {
            m_vertices.add(sx + m_nvx);
            m_vertices.add(sy + m_nvy);
        }
        emitLineSegment(sx, sy, m_nvx, m_nvy);
        break; }
    case Qt::RoundCap: {
        QVarLengthArray<float> points;
        arcPoints(m_cx, m_cy, m_cx + m_nvx, m_cy + m_nvy, m_cx - m_nvx, m_cy - m_nvy, points);
        m_vertices.resize(m_vertices.size() + points.size() + 2 * int(invisibleJump));
        int count = m_vertices.size();
        int front = 0;
        int end = points.size() / 2;
        while (front != end) {
            m_vertices.at(--count) = points[2 * end - 1];
            m_vertices.at(--count) = points[2 * end - 2];
            --end;
            if (front == end)
                break;
            m_vertices.at(--count) = points[2 * front + 1];
            m_vertices.at(--count) = points[2 * front + 0];
            ++front;
        }

        if (invisibleJump) {
            m_vertices.at(count - 1) = m_vertices.at(count + 1);
            m_vertices.at(count - 2) = m_vertices.at(count + 0);
        }
        break; }
    default: break; // ssssh gcc...
    }
    emitLineSegment(m_cx, m_cy, m_nvx, m_nvy);
}
void tst_QVarLengthArray::removeLast()
{
    {
        QVarLengthArray<char, 2> v;
        v.append(0);
        v.append(1);
        QCOMPARE(v.size(), 2);
        v.append(2);
        v.append(3);
        QCOMPARE(v.size(), 4);
        v.removeLast();
        QCOMPARE(v.size(), 3);
        v.removeLast();
        QCOMPARE(v.size(), 2);
    }

    {
        QVarLengthArray<QString, 2> v;
        v.append("0");
        v.append("1");
        QCOMPARE(v.size(), 2);
        v.append("2");
        v.append("3");
        QCOMPARE(v.size(), 4);
        v.removeLast();
        QCOMPARE(v.size(), 3);
        v.removeLast();
        QCOMPARE(v.size(), 2);
    }
}
Beispiel #7
0
void QFontEngineMac::draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight)
{
    QVarLengthArray<QFixedPoint> positions;
    QVarLengthArray<glyph_t> glyphs;
    QTransform matrix;
    matrix.translate(x, y);
    getGlyphPositions(ti.glyphs, ti.num_glyphs, matrix, ti.flags, glyphs, positions);
    if (glyphs.size() == 0)
        return;

    CGContextSetFontSize(ctx, fontDef.pixelSize);

    CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx);

    CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, -1, 0, -paintDeviceHeight);

    CGAffineTransformConcat(cgMatrix, oldTextMatrix);

    if (synthesisFlags & QFontEngine::SynthesizedItalic)
        cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0));

    cgMatrix = CGAffineTransformConcat(cgMatrix, multiEngine->transform);

    CGContextSetTextMatrix(ctx, cgMatrix);

    CGContextSetTextDrawingMode(ctx, kCGTextFill);


    QVarLengthArray<CGSize> advances(glyphs.size());
    QVarLengthArray<CGGlyph> cgGlyphs(glyphs.size());

    for (int i = 0; i < glyphs.size() - 1; ++i) {
        advances[i].width = (positions[i + 1].x - positions[i].x).toReal();
        advances[i].height = (positions[i + 1].y - positions[i].y).toReal();
        cgGlyphs[i] = glyphs[i];
    }
    advances[glyphs.size() - 1].width = 0;
    advances[glyphs.size() - 1].height = 0;
    cgGlyphs[glyphs.size() - 1] = glyphs[glyphs.size() - 1];

    CGContextSetFont(ctx, cgFont);

    CGContextSetTextPosition(ctx, positions[0].x.toReal(), positions[0].y.toReal());

    CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size());

    if (synthesisFlags & QFontEngine::SynthesizedBold) {
        CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(),
                                      positions[0].y.toReal());

        CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size());
    }

    CGContextSetTextMatrix(ctx, oldTextMatrix);
}
void tst_QVarLengthArray::count()
{
    // tests size(), count() and length(), since they're the same thing
    {
        const QVarLengthArray<int> list;
        QCOMPARE(list.length(), 0);
        QCOMPARE(list.count(), 0);
        QCOMPARE(list.size(), 0);
    }

    {
        QVarLengthArray<int> list;
        list.append(0);
        QCOMPARE(list.length(), 1);
        QCOMPARE(list.count(), 1);
        QCOMPARE(list.size(), 1);
    }

    {
        QVarLengthArray<int> list;
        list.append(0);
        list.append(1);
        QCOMPARE(list.length(), 2);
        QCOMPARE(list.count(), 2);
        QCOMPARE(list.size(), 2);
    }

    {
        QVarLengthArray<int> list;
        list.append(0);
        list.append(0);
        list.append(0);
        QCOMPARE(list.length(), 3);
        QCOMPARE(list.count(), 3);
        QCOMPARE(list.size(), 3);
    }

    // test removals too
    {
        QVarLengthArray<int> list;
        list.append(0);
        list.append(0);
        list.append(0);
        QCOMPARE(list.length(), 3);
        QCOMPARE(list.count(), 3);
        QCOMPARE(list.size(), 3);
        list.removeLast();
        QCOMPARE(list.length(), 2);
        QCOMPARE(list.count(), 2);
        QCOMPARE(list.size(), 2);
        list.removeLast();
        QCOMPARE(list.length(), 1);
        QCOMPARE(list.count(), 1);
        QCOMPARE(list.size(), 1);
        list.removeLast();
        QCOMPARE(list.length(), 0);
        QCOMPARE(list.count(), 0);
        QCOMPARE(list.size(), 0);
    }
}
Beispiel #9
0
void
dmz::QtCanvasScene::drawBackground (QPainter *painter, const QRectF &rect) {

   painter->drawRect (sceneRect ());
   
   if (_drawGrid) {

      painter->fillRect (sceneRect (), QBrush (QColor (230, 240, 255)));
      painter->setPen (QPen (Qt::lightGray, 1));
      painter->setOpacity(0.75f);

      const int gridSize = 100;

      qreal left = int(rect.left ()) - (int(rect.left ()) % gridSize);
      qreal top = int(rect.top ()) - (int(rect.top ()) % gridSize);

      QVarLengthArray<QLineF, 100> lines;

      for (qreal x = left; x < rect.right (); x += gridSize) {

         lines.append (QLineF (x, rect.top (), x, rect.bottom ()));
      }

      for (qreal y = top; y < rect.bottom (); y += gridSize) {

         lines.append (QLineF (rect.left (), y, rect.right (), y));
      }

//   qDebug () << lines.size ();
      painter->drawLines (lines.data (), lines.size ());

      QGraphicsScene::drawBackground (painter, rect);
   }
}
Beispiel #10
0
bool LosersBoard::vIsLegalMove(const Move& move)
{
	bool isCapture = (captureType(move) != Piece::NoPiece);
	if (m_captureKey != key()
	&&  !isCapture)
	{
		m_captureKey = key();
		m_canCapture = false;

		QVarLengthArray<Move> moves;
		generateMoves(moves);

		for (int i = 0; i < moves.size(); i++)
		{
			if (captureType(moves[i]) != Piece::NoPiece
			&&  WesternBoard::vIsLegalMove(moves[i]))
			{
				m_canCapture = true;
				break;
			}
		}
	}

	if (!isCapture && m_canCapture)
		return false;
	return WesternBoard::vIsLegalMove(move);
}
Beispiel #11
0
void tNDP2kEventManagerPrivate::CreateEventTableForStack()
{
    Assert(m_pStackEventTable == 0);

    // Create the event table for the stack
    m_pStackEventTable = new SystemData::tEventsMsgMap[ m_Events.size() ];

    // Initialise the event table
    int count;
    for(count = 0; count < m_Events.size(); count++)
    {
        m_pStackEventTable[count] = *(m_Events[count]->GetEventMsgMap());
    }

    Assert(count <= NDP2K_SIMNET_MAX_SYS_EVENTS); 
}
Beispiel #12
0
static float ratioFor(int step, int maxSteps) {
#if 1
    static QVarLengthArray<float> table;
    const int n = maxSteps + 1;
    if (table.size() != n) {
        table.resize(n);
        const float accel = 0.5f;
        const float factor = pow(0.5f, accel);
        for (int i = (n+1)/2; i < n; ++i) {
            float ratio = i/float(maxSteps);
            if (ratio == 0.5f)
                table[i] = 0.f;
            else
                table[i] = (pow(ratio - 0.5f, accel) + factor) / (2.0f*factor);
        }
        for (int i = 0; i <= n/2; ++i) {
            table[i] = 1.0f - table[maxSteps-i];
        }
    }

    return table.at(step);
#else
    return step/float(MAX_STEPS);
#endif
}
Beispiel #13
0
    void init(jclass declaringClass, jobjectArray javaArguments, QVarLengthArray<jvalue> convertedArgs, jintArray conversionScheme) {
        JNIEnv *env = qtjambi_current_environment();
        Q_ASSERT(env != 0);
        if (env != 0) {
            if (declaringClass != 0)
                m_declaring_class = reinterpret_cast<jclass>(env->NewGlobalRef(declaringClass));
            if (conversionScheme != 0)
                m_conversion_scheme = reinterpret_cast<jintArray>(env->NewGlobalRef(conversionScheme));

            if (javaArguments != 0) {
                // Convert all the arguments
                m_arguments = qtjambi_from_jobjectArray(env, javaArguments, m_conversion_scheme, true);
            } else {
                // Copy the converted arguments
                jint *a = m_conversion_scheme != 0 ? env->GetIntArrayElements(m_conversion_scheme, 0) : 0;
                for (int i=0; i<convertedArgs.size(); ++i) {
                    if (a != 0 && a[i] == 'L') {
                        jvalue val;
                        val.l = env->NewGlobalRef(convertedArgs[i].l);
                        m_arguments.append(val);
                    } else {
                        m_arguments.append(convertedArgs[i]);
                    }
                }
                env->ReleaseIntArrayElements(m_conversion_scheme, a, JNI_ABORT);
            }
        }
    }
Beispiel #14
0
/*!
    Creates an OpenCL program object from the list of \a binaries
    for \a devices.  The \a binaries and \a devices lists must have
    the same number of elements.

    \sa createProgramFromBinaryCode(), createProgramFromBinaryFile()
*/
QCLProgram QCLContext::createProgramFromBinaries
    (const QList<QCLDevice> &devices, const QList<QByteArray> &binaries)
{
    Q_D(QCLContext);
    if (devices.size() != binaries.size() || devices.isEmpty()) {
        reportError("QCLContext::createProgramFromBinaries:", CL_INVALID_VALUE);
        return QCLProgram();
    }
    QVarLengthArray<cl_device_id> devs;
    QVarLengthArray<const uchar *> bins;
    QVarLengthArray<size_t> lens;
    for (int index = 0; index < devices.size(); ++index) {
        devs.append(devices.at(index).deviceId());
        bins.append(reinterpret_cast<const uchar *>
            (binaries.at(index).constData()));
        lens.append(binaries.at(index).size());
    }
    cl_int error = CL_INVALID_CONTEXT;
    cl_program prog = clCreateProgramWithBinary
        (d->id, devs.size(), devs.data(), lens.data(), bins.data(), 0, &error);
    reportError("QCLContext::createProgramFromBinaries:", error);
    if (prog)
        return QCLProgram(this, prog);
    else
        return QCLProgram();
}
Beispiel #15
0
    void drawBackground(QPainter *painter, const QRectF &rect)
    {
        QGraphicsScene::drawBackground(painter, rect);
        const int gridSizeX = 1.0f;
        const int gridSizeY = 60.0f*KLineSize;

        qreal left = int(rect.left()) - (int(rect.left()) % gridSizeX);
        qreal top = int(rect.top()) - (int(rect.top()) % gridSizeY);

        QVarLengthArray<QLineF, 100> lines;

        for (qreal x = left; x < rect.right(); x += gridSizeX)
            lines.append(QLineF(x, rect.top(), x, rect.bottom()));
        for (qreal y = top; y < rect.bottom(); y += gridSizeY)
            lines.append(QLineF(rect.left(), y, rect.right(), y));


        painter->setPen(QPen(QBrush(Qt::darkGray),0,Qt::DashDotDotLine));

        painter->drawLines(lines.data(), lines.size());

        painter->setPen(QPen(QBrush(Qt::lightGray),0,Qt::DashLine));
        painter->drawLine(QLineF(16.66, rect.top(), 16.66, rect.bottom()));
        painter->drawLine(QLineF(33.33, rect.top(), 33.33, rect.bottom()));
    }
Beispiel #16
0
void QTriangulatingStroker::endCap(const qreal *)
{
    switch (m_cap_style) {
    case Qt::FlatCap:
        break;
    case Qt::SquareCap:
        emitLineSegment(m_cx + m_nvy, m_cy - m_nvx, m_nvx, m_nvy);
        break;
    case Qt::RoundCap: {
        QVarLengthArray<float> points;
        int count = m_vertices.size();
        arcPoints(m_cx, m_cy, m_vertices.at(count - 2), m_vertices.at(count - 1), m_vertices.at(count - 4), m_vertices.at(count - 3), points);
        int front = 0;
        int end = points.size() / 2;
        while (front != end) {
            m_vertices.add(points[2 * end - 2]);
            m_vertices.add(points[2 * end - 1]);
            --end;
            if (front == end)
                break;
            m_vertices.add(points[2 * front + 0]);
            m_vertices.add(points[2 * front + 1]);
            ++front;
        }
        break; }
    default: break; // to shut gcc up...
    }
}
Beispiel #17
0
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
{

	
    Q_UNUSED(rect);
	//return;

    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
	painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
	painter->fillRect(bottomShadow, Qt::darkGray);

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
	gradient.setColorAt(0, QColor(100,107,126));
	gradient.setColorAt(1, QColor(100,107,126));
    painter->fillRect(rect.intersect(sceneRect), gradient);
	//painter->setBrush(Qt::BrushStyle::DiagCrossPattern);
    painter->drawRect(sceneRect);

    // Text
    //QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
    //                sceneRect.width() - 4, sceneRect.height() - 4);
    //QString message(tr("Click and drag the nodes around, and zoom with the mouse "
    //                   "wheel or the '+' and '-' keys"));

    //QFont font = painter->font();
    //font.setBold(true);
    //font.setPointSize(14);
    //painter->setFont(font);
    //painter->setPen(Qt::lightGray);
    ////painter->drawText(textRect.translated(2, 2), message);
    //painter->setPen(Qt::black);

    //painter->drawText(textRect, message);
painter->setPen(QColor(135,142,157));
	const int gridSize = 25;

qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);

QVarLengthArray<QLineF, 100> lines;

for (qreal x = left; x < rect.right(); x += gridSize)
lines.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = top; y < rect.bottom(); y += gridSize)
lines.append(QLineF(rect.left(), y, rect.right(), y));

//qDebug() << lines.size();

painter->drawLines(lines.data(), lines.size());



}
Beispiel #18
0
/*!
 * \brief This calls the setValues JavaScript method in `lineSens`, to set the ON/OFF status of the LEDs on the strip.
 * \param leds is an array of boolean values to set the corresponding LEDs ON/OFF.
 */
void GuiHandler::setLedStrip(QVarLengthArray<bool> leds)
{
    QVariantList values;

    for(int i=0; i<leds.size(); i++)
        values << leds.at(i);
    QMetaObject::invokeMethod(this->lineSens->object, "setValues", Qt::DirectConnection, Q_ARG(QVariant, QVariant::fromValue(values)));
}
int countMoved(QVarLengthArray<T, PreAlloc> const &c)
{
    int result = 0;
    for (int i = 0; i < c.size(); ++i)
        if (c[i].hasMoved())
            ++result;

    return result;
}
void CrazyhouseBoard::restorePieces(Piece piece, const QVarLengthArray<int>& squares)
{
	if (!piece.isValid() || squares.isEmpty())
		return;

	Piece prom(piece.side(), promotedPieceType(piece.type()));
	for (int i = 0; i < squares.size(); i++)
		setSquare(squares[i], prom);
}
Beispiel #21
0
static QStringRef joinTokens(const QVarLengthArray<QStringRef>& tokens)
{
	Q_ASSERT(!tokens.isEmpty());

	const QStringRef& last = tokens[tokens.size() - 1];
	int start = tokens[0].position();
	int end = last.position() + last.size();

	return QStringRef(last.string(), start, end - start);
}
void MovementScene::drawForeground(QPainter *painter, const QRectF &rect){
    if(gridIsVisible){
        painter->setWorldMatrixEnabled(true);
        QVarLengthArray<QLineF, 100> linesX;
        QVarLengthArray<QLineF, 100> linesY;

        qreal left = int(rect.left()) - (int(rect.left()) % gridInterval );
        qreal top = int(rect.top()) - (int(rect.top()) % gridInterval );

        for (qreal x = left; x < rect.right(); x += gridInterval )
            linesX.append(QLineF(x, rect.top(), x, rect.bottom()));

        for (qreal y = top; y < rect.bottom(); y += gridInterval )
            linesY.append(QLineF(rect.left(), y, rect.right(), y));

        painter->setPen(QColor(196,220,255));
        painter->drawLines(linesX.data(), linesX.size());
        painter->drawLines(linesY.data(), linesY.size());
    }
}
Beispiel #23
0
 QVariant parseNumber()
 {
     QVarLengthArray<QChar> str;
     QChar c = next();
     if(c == '-')
     {
         str.append(c);
         c = nextNoSkip();
     }
     for(; c.isDigit(); c = nextNoSkip())
     {
         str.append(c);
     }
     bool hasDecimal = false;
     if(c == '.')
     {
         str.append(c);
         hasDecimal = true;
         c = nextNoSkip();
         for(; c.isDigit(); c = nextNoSkip())
         {
             str.append(c);
         }
     }
     if(c == 'e' || c == 'E')
     {
         // Exponent.
         str.append(c);
         c = nextNoSkip();
         if(c == '+' || c == '-')
         {
             str.append(c);
             c = nextNoSkip();
         }
         for(; c.isDigit(); c = nextNoSkip())
         {
             str.append(c);
         }
     }
     // Rewind one char (the loop was broken when a non-digit was read).
     pos--;
     skipWhite();
     double value = QString(str.constData(), str.size()).toDouble();
     if(hasDecimal)
     {
         return QVariant(value);
     }
     else
     {
         return QVariant(int(value));
     }
 }
Beispiel #24
0
unsigned char tNDP2kEventManagerPrivate::GetEventUserGroup(const unsigned short eventId)
{
    unsigned char userGroup = 1;

    if(eventId < m_Events.size())
    {
        tNDP2kEvent* pEvent = m_Events[eventId];
        userGroup = pEvent->GetUserGroup();
    }

    return userGroup;

}
void QQuickTextNodeEngine::BinaryTreeNode::inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree,
                                              QVarLengthArray<int> *sortedIndexes, int currentIndex)
{
    Q_ASSERT(currentIndex < binaryTree.size());

    const BinaryTreeNode *node = binaryTree.data() + currentIndex;
    if (node->leftChildIndex >= 0)
        inOrder(binaryTree, sortedIndexes, node->leftChildIndex);

    sortedIndexes->append(currentIndex);

    if (node->rightChildIndex >= 0)
        inOrder(binaryTree, sortedIndexes, node->rightChildIndex);
}
Beispiel #26
0
void QtBasicGraph::paintEvent(QPaintEvent *e)
{
    QPainter p(this);

    if (m_render_hints)
        p.setRenderHints(m_render_hints);

    p.fillRect(e->rect(), palette().background());

    if (m_values.size() < 2)
        return;

    p.setPen(palette().color(QPalette::Text));

    qreal scalex = qreal(width()) / m_xrange;
    qreal scaley = qreal(height()) / (m_ymax - m_ymin);

    qreal dx = qreal(3) / scalex;
    qreal dy = qreal(3) / scaley;

    QRectF bound(e->rect().x() / scalex, m_ymin + e->rect().y() / scaley, e->rect().width() / scalex, e->rect().height() / scaley);

    QPointF last = m_values.last();

    qreal tx = m_xrange - last.x();
    qreal ty = m_ymin;


    p.scale(scalex, -scaley);
    p.translate(tx, ty);

    QVarLengthArray<QLineF> lines;
    
    for (int i = m_values.size() - 1; i >= 0; --i) {
        QPointF pt = m_values[i];
        QRectF linerect(last, pt);
        linerect = linerect.normalized().translated(tx, 0);
        linerect.adjust(-dx, -dy, dx, dy);

        if (bound.intersects(linerect))
            lines.append(QLineF(last, pt));
        last = pt;
    }

//    if (lines.size() < (m_values.size()-1))
//        qWarning("skipped %d lines", (m_values.size()-1) -lines.size());

    p.drawLines(lines.constData(), lines.size());
}
void QQuickTextNodeEngine::addTextDecorations(const QVarLengthArray<TextDecoration> &textDecorations,
                                              qreal offset, qreal thickness)
{
    for (int i=0; i<textDecorations.size(); ++i) {
        TextDecoration textDecoration = textDecorations.at(i);

        {
            QRectF &rect = textDecoration.rect;
            rect.setY(qRound(rect.y() + m_currentLine.ascent() + offset));
            rect.setHeight(thickness);
        }

        m_lines.append(textDecoration);
    }
}
Beispiel #28
0
void tNDP2kEventManagerPrivate::Initialize()
{
    tQMutexLocker locker( m_NDP2k.StackLocker() );

    SystemData::RegisterRxEventObserver(cRxEvent);
    SystemData::RegisterRxEventReplyObserver(cRxEventReply);
    SystemData::RegisterGetEventUserGroupFunction(cGetEventUserGroup);

    SystemData::RegisterWatchEventObserver(cRxWatchEvent);

    CreateEventTableForStack();

    Assert(m_pStackEventTable);

    SystemData::InitialiseEventTable(m_pStackEventTable, static_cast<unsigned char>(m_Events.size()));
}
Beispiel #29
0
 QVariant parseString()
 {
     QVarLengthArray<QChar, 1024> result;
     QChar c = next();
     DENG2_ASSERT(c == '\"');
     forever
     {
         c = nextNoSkip();
         if(c == '\\')
         {
             // Escape.
             c = nextNoSkip();
             if(c == '\"' || c == '\\' || c == '/')
                 result.append(c);
             else if(c == 'b')
                 result.append('\b');
             else if(c == 'f')
                 result.append('\f');
             else if(c == 'n')
                 result.append('\n');
             else if(c == 'r')
                 result.append('\r');
             else if(c == 't')
                 result.append('\t');
             else if(c == 'u')
             {
                 QString code = source.mid(pos, 4);
                 pos += 4;
                 result.append(QChar(ushort(code.toLong(0, 16))));
             }
             else error("unknown escape sequence in string");
         }
         else if(c == '\"')
         {
             // End of string.
             break;
         }
         else
         {
             result.append(c);
         }
     }
     return QString(result.constData(), result.size());
 }
void QQuickTextNodeEngine::addGlyphsForRanges(const QVarLengthArray<QTextLayout::FormatRange> &ranges,
                                              int start, int end,
                                              int selectionStart, int selectionEnd)
{
    int currentPosition = start;
    int remainingLength = end - start;
    for (int j=0; j<ranges.size(); ++j) {
        const QTextLayout::FormatRange &range = ranges.at(j);
        if (range.start + range.length >= currentPosition
                && range.start < currentPosition + remainingLength) {

            if (range.start > currentPosition) {
                addGlyphsInRange(currentPosition, range.start - currentPosition,
                                 QColor(), QColor(), selectionStart, selectionEnd);
            }
            int rangeEnd = qMin(range.start + range.length, currentPosition + remainingLength);
            QColor rangeColor;
            if (range.format.hasProperty(QTextFormat::ForegroundBrush))
                rangeColor = range.format.foreground().color();
            else if (range.format.isAnchor())
                rangeColor = m_anchorColor;
            QColor rangeBackgroundColor = range.format.hasProperty(QTextFormat::BackgroundBrush)
                    ? range.format.background().color()
                    : QColor();

            addGlyphsInRange(range.start, rangeEnd - range.start,
                             rangeColor, rangeBackgroundColor,
                             selectionStart, selectionEnd);

            currentPosition = range.start + range.length;
            remainingLength = end - currentPosition;

        } else if (range.start > currentPosition + remainingLength || remainingLength <= 0) {
            break;
        }
    }

    if (remainingLength > 0) {
        addGlyphsInRange(currentPosition, remainingLength, QColor(), QColor(),
                         selectionStart, selectionEnd);
    }

}