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()));
    }
Exemple #2
0
static void stringToWCharArray(QVarLengthArray<wchar_t> &ret, const QString &string)
{
    ret.resize(string.length());
    int len = string.toWCharArray(ret.data());
    ret.resize(len+1);
    ret[len] = 0;
}
Exemple #3
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
}
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);
    }
}
Exemple #5
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();
}
Exemple #6
0
QStringRef UciEngine::parseUciTokens(const QStringRef& first,
				     const QString* types,
				     int typeCount,
				     QVarLengthArray<QStringRef>& tokens,
				     int& type)
{
	QStringRef token(first);
	type = -1;
	tokens.clear();

	do
	{
		bool newType = false;
		for (int i = 0; i < typeCount; i++)
		{
			if (token == types[i])
			{
				if (type != -1)
					return token;
				type = i;
				newType = true;
				break;
			}
		}
		if (!newType && type != -1)
			tokens.append(token);
	}
	while (!(token = nextToken(token)).isNull());

	return token;
}
Exemple #7
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...
    }
}
Exemple #8
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);
   }
}
Exemple #9
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);
}
// Read a UTF-16 string value.
static QString read_string( QIODevice *dev, int length )
{
    QVarLengthArray<ushort> buf;
    buf.reserve( length );
    dev->read( (char *)(buf.data()), length * 2 );
    return QString::fromUtf16( buf.data(), length );
}
Exemple #11
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();
}
Exemple #12
0
void Parser::ParsedObject::insert(uint offset) {
    const QJsonPrivate::Entry *newEntry = reinterpret_cast<const QJsonPrivate::Entry *>(parser->data + objectPosition + offset);
    int min = 0;
    int n = offsets.size();
    while (n > 0) {
        int half = n >> 1;
        int middle = min + half;
        if (*entryAt(middle) >= *newEntry) {
            n = half;
        } else {
            min = middle + 1;
            n -= half + 1;
        }
    }
    if (min < offsets.size() && *entryAt(min) == *newEntry) {
        offsets[min] = offset;
    } else {
#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0)
        QVarLengthArray<uint, 64> offsetsN;
        for (int i=0, n=offsets.size() ; i<n ; ++i) {
            if (i == min)
                offsetsN.append(offsets[i]);
            offsetsN.append(offsets[i]);
        }
        offsets = offsetsN;
#else
        offsets.insert(min, offset);
#endif
    }
}
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());



}
void LosAlamosBoard::addPromotions(int sourceSquare,
				int targetSquare,
				QVarLengthArray<Move>& moves) const
{
	moves.append(Move(sourceSquare, targetSquare, Knight));
	moves.append(Move(sourceSquare, targetSquare, Rook));
	moves.append(Move(sourceSquare, targetSquare, Queen));
}
void tst_QVarLengthArray::append()
{
    QVarLengthArray<QString> v;
    v.append(QString("hello"));

    QVarLengthArray<int> v2; // rocket!
    v2.append(5);
}
Exemple #16
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)));
}
Exemple #17
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 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);
}
Exemple #19
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 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);
}
static inline QString qSystemDirectory()
{
    QVarLengthArray<wchar_t, MAX_PATH> fullPath;

    UINT retLen = ::GetSystemDirectory(fullPath.data(), MAX_PATH);
    if (retLen > MAX_PATH) {
        fullPath.resize(retLen);
        retLen = ::GetSystemDirectory(fullPath.data(), retLen);
    }
    // in some rare cases retLen might be 0
    return QString::fromWCharArray(fullPath.constData(), int(retLen));
}
Exemple #22
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));
     }
 }
QCollatorSortKey QCollator::sortKey(const QString &string) const
{
    QVarLengthArray<wchar_t> original;
    stringToWCharArray(original, string);
    QVector<wchar_t> result(string.size());
    size_t size = std::wcsxfrm(result.data(), original.constData(), string.size());
    if (size > uint(result.size())) {
        result.resize(size+1);
        size = std::wcsxfrm(result.data(), original.constData(), string.size());
    }
    result.resize(size+1);
    result[size] = 0;
    return QCollatorSortKey(new QCollatorSortKeyPrivate(result));
}
Exemple #24
0
/*!
 * \brief This sets the angle of the `AccelY` `GyroIndicator` QML element on the GUI, based on the parameters acquired from V-REP.
 * \param wheels is an array that stores the speed of individual wheels.
 * \param accelY is the horizontal acceleration of the robot.
 */
void GuiHandler::setCarAccelY(QVarLengthArray<float> wheels, float accelY)
{
    float v, R, angle;
    float dt=10;

    v=(wheels.at(0)+wheels.at(1))/2.0;
    R=(v*v)/(accelY);
    if(R==0 || R!=R)
        angle=0;
    else
        angle=v*dt/R;

    QMetaObject::invokeMethod(this->carAccelY->object, "setAngle", Qt::DirectConnection, Q_ARG(QVariant, angle));
}
Exemple #25
0
/*!
 * \brief This sets the angle of the `wheels` `GyroIndicator` QML element on the GUI, based on the wheel parameters acquired from V-REP.
 * \param wheels is an array that stores the speed of individual wheels.
 * \param D is the distance of wheels.
 */
void GuiHandler::setWheels(QVarLengthArray<float> wheels, float D)
{
    float v, R, angle;
    float dt=10;

    v=(wheels.at(0)+wheels.at(1))/2.0;
    R=v*D/(wheels.at(1)-wheels.at(0));
    if(R==0 || R!=R)
        angle=0;
    else
        angle=-v*dt/R;

    QMetaObject::invokeMethod(this->wheels->object, "setAngle", Qt::DirectConnection, Q_ARG(QVariant, angle));
}
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);
}
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());
}
Exemple #28
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);
    }
}
Exemple #30
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);
            }
        }
    }