// ###################################################################### void ScorbotConsole::updatePlots() { itsGraphicsView->setBackgroundBrush(QBrush(Qt::darkGray)); //Clear all previous plots QList<QGraphicsItem*> items = itsGraphicsScene->items(); for(int i=0; i<items.size(); i++) { itsGraphicsScene->removeItem(items[i]); delete items[i]; } int textPos = -5000; int textOffset=500; QMap<QString, bool>::iterator dataCheckIt = plotDataCheck.begin(); for(; dataCheckIt != plotDataCheck.end(); ++dataCheckIt) { if (dataCheckIt.value() && plotData.contains(dataCheckIt.key())) { PixRGB<byte> color = plotDataColor[dataCheckIt.key()]; QGraphicsTextItem *text = itsGraphicsScene->addText(dataCheckIt.key()); text->setDefaultTextColor(QColor(color.red(), color.green(), color.blue())); text->setPos(1, textPos); text->setFlags(QGraphicsItem::ItemIgnoresTransformations); textPos+=textOffset; plotLine(plotData[dataCheckIt.key()], color); } } itsGraphicsScene->addLine(QLineF(0, -5000, 0, 5000), QPen(QColor(128, 0, 0))); itsGraphicsScene->addLine(QLineF(0, 0, itsMaxPlotLength, 0), QPen(QColor(128, 0, 0))); itsGraphicsView->fitInView(itsGraphicsScene->itemsBoundingRect()); itsGraphicsView->ensureVisible(itsGraphicsScene->itemsBoundingRect()); itsGraphicsView->centerOn(itsMaxPlotLength/2, 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; }
QtTextPositionWidget::QtTextPositionWidget(const std::vector<std::string>& items) { QGraphicsScene * const scene = new QGraphicsScene(this); this->setScene(scene); std::for_each(items.begin(),items.end(), [this,scene](const std::string& s) { QGraphicsTextItem * item = new QGraphicsTextItem; item->setPlainText(s.c_str()); item->setFlags(QGraphicsItem::ItemIsMovable); item->setPos(this->width() / 2.0, this->height() / 2.0); scene->addItem(item); } ); }
void PSV_ChartItem::updateForDouble() { QMapIterator<QString,PSV_CurveInfo> iter(m_curveDataMap); qreal posY = m_staStartPoint.y(); qreal posX = m_staStartPoint.x(); while(iter.hasNext()) { iter.next(); PSV_CurveInfo curveInfo = iter.value(); updateAxisRange(curveInfo.m_axisType); addCurveItem(curveInfo); addEllipseItem(curveInfo); if(!isStaHidden()) { QGraphicsTextItem *textItem = new QGraphicsTextItem(this); textItem->setData(E_ITEM_TYPE,PSV::staLabelItem); textItem->setData(E_CURVE_NAME,curveInfo.m_curveName); textItem->setFlags(QGraphicsItem::ItemIsSelectable); textItem->installSceneEventFilter(this); textItem->setDefaultTextColor(getDefaultColor()); textItem->setFont(staFont()); textItem->setHtml(curveInfo.m_staHtmText); double textHeight = textItem->boundingRect().height(); int staMaxHeight = (int)textHeight* 6 / 10; textItem->setPos(posX + textItem->boundingRect().height(),posY); QPixmap pixmap(staMaxHeight,staMaxHeight); pixmap.fill(); QPen pen(curveInfo.m_lineColor); pen.setWidth(3); QPainter painter(&pixmap); painter.setPen(pen); if(!curveInfo.m_isHidden) { QBrush brush(curveInfo.m_lineColor); painter.setBrush(brush); } painter.drawRect(0, 0, pixmap.height(), pixmap.height()); QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(pixmap,this); pixmapItem->setPixmap(pixmap); pixmapItem->setPos(posX,posY + textHeight * 2 / 10); pixmapItem->setData(E_ITEM_TYPE,PSV::staLabelItem); pixmapItem->setData(E_CURVE_NAME,curveInfo.m_curveName); pixmapItem->setFlags(QGraphicsItem::ItemIsSelectable); pixmapItem->installSceneEventFilter(this); if(posX + 2 * m_staMaxWidth > m_chartRect.right()) { posX = m_staStartPoint.x(); posY += textItem->boundingRect().height() + getData(PSV::margin,3).toInt(); } else { posX += m_staMaxWidth; } } } //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT // QGraphicsRectItem *item = new QGraphicsRectItem(m_rect,this);//TTTTTTTTTTTTTTT // item->setPen(QPen(QColor(Qt::red)));//TTTTTTTTTTTTTTT //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT }