Example #1
0
SEXP
scene_addText(SEXP scene, SEXP x, SEXP y, SEXP labels, SEXP html)
{
    QGraphicsScene* s = unwrapQObject(scene, QGraphicsScene);
    int nlab = length(labels);
    int i, n = length(x);
    for (i = 0; i < n; i++) {
	QGraphicsTextItem *ti = s->addText(QString());
	ti->setFont(QFont("Arial"));
	if (LOGICAL(html)[0]) {
	    ti->setHtml(QString::fromLocal8Bit(CHAR(asChar(STRING_ELT(labels, i % nlab)))));
	    ti->setOpenExternalLinks(true);
	    ti->setToolTip("I am HTML!");
	}
	else {
	    ti->setPlainText(QString::fromLocal8Bit(CHAR(asChar(STRING_ELT(labels, i % nlab)))));
	}
	ti->setPos(REAL(x)[i], REAL(y)[i]);
	ti->setFlags(QGraphicsItem::ItemIsMovable | 
		     QGraphicsItem::ItemIsSelectable | 
		     QGraphicsItem::ItemIsFocusable | 
		     QGraphicsItem::ItemIgnoresTransformations);
    }
    return R_NilValue;
}