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; }
QGraphicsTextItem * GraphicsButton::decorateKey(const QRectF & cell,int group,int level) { QString text = m_keydef->getDecoration(group,level); QGraphicsTextItem * item = new QGraphicsTextItem(this); int scriptCount = 0; /// Get the script for the text and use it as CSS selector /// selectors are case insensitive /// QString script; if (text.size() == 1) { script = UcdScripts::getScript(text.at(0).unicode()); if ( ! script.isEmpty()) { scriptCount = 1; } } else { script = UcdScripts::getScript(text,&scriptCount); if (scriptCount != 1) { script = "default"; } } script = script.toCaseFolded(); if (! m_css.isEmpty()) item->document()->setDefaultStyleSheet(m_css); /// this stops Arabic being moved to the right QTextOption topt; topt.setTextDirection(Qt::LeftToRight); item->document()->setDefaultTextOption(topt); QString sep("<br/>"); QString html; QStringList w = text.toHtmlEscaped().split(QChar(' '),QString::SkipEmptyParts); // QFont f("Amiri",30); // item->setFont(f); // html = QString("<html><body><span class=\"%1\">%2</span></body></html>").arg(script).arg(text); html = QString("<span class=\"%1\">%2</span>").arg(script).arg(w.join("<br/>")); item->setHtml(html);//Html(html); QRectF wr = item->boundingRect(); /// align the text centrally in its bounding rect qreal dx = cell.width() - wr.width(); qreal dy = cell.height() - wr.height(); if (m_keydef->centerText(group,level)) { dy = dy/2; } else { int vpos = m_keydef->getVerticalAdjust(group,level); dy += vpos; } item->setPos(cell.topLeft() + QPointF(dx/2,dy));//dy/2)); item->setDefaultTextColor(m_textColor); this->setBrush(QBrush(m_backgroundUpColor)); this->setPen(QPen(m_textColor)); return item; }
SEXP qt_qsetText_QGraphicsItem(SEXP item, SEXP label) { QGraphicsItem *i = unwrapQGraphicsItem(item, QGraphicsItem); QGraphicsTextItem *textitem = qgraphicsitem_cast<QGraphicsTextItem *>(i); if (textitem) textitem->setHtml(sexp2qstring(label)); return R_NilValue; }
void ChartsView::drawText(QString text, qint16 x, qint16 y, QString style) { QGraphicsTextItem *textItem = new QGraphicsTextItem(text); textItem->setPos(x,y); textItem->setTransform(QTransform::fromScale(1,-1)); if(style.size())textItem->setHtml("<span style='"+style+"'>"+text+"</span>"); sceneCharts->addItem(textItem); }
int main(int argc, char **argv) { Q_INIT_RESOURCE(stickman); QApplication app(argc, argv); StickMan *stickMan = new StickMan; stickMan->setDrawSticks(false); QGraphicsTextItem *textItem = new QGraphicsTextItem(); textItem->setHtml("<font color=\"white\"><b>Stickman</b>" "<p>" "Tell the stickman what to do!" "</p>" "<p><i>" "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>" "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>" "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>" "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>" "</i></p>" "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again." "</p></font>"); qreal w = textItem->boundingRect().width(); QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect(); textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0); QGraphicsScene scene; scene.addItem(stickMan); scene.addItem(textItem); scene.setBackgroundBrush(Qt::black); GraphicsView view; view.setRenderHints(QPainter::Antialiasing); view.setTransformationAnchor(QGraphicsView::NoAnchor); view.setScene(&scene); QRectF sceneRect = scene.sceneRect(); // making enough room in the scene for stickman to jump and die view.resize(sceneRect.width() + 100, sceneRect.height() + 100); view.setSceneRect(sceneRect); view.show(); view.setFocus(); LifeCycle cycle(stickMan, &view); cycle.setDeathAnimation(":/animations/dead.bin"); cycle.addActivity(":/animations/jumping.bin", Qt::Key_J); cycle.addActivity(":/animations/dancing.bin", Qt::Key_D); cycle.addActivity(":/animations/chilling.bin", Qt::Key_C); cycle.start(); return app.exec(); }
void AprsPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { event->setAccepted(true); QGraphicsScene *scene = this->scene(); QGraphicsTextItem * message = new QGraphicsTextItem; message->setPos(_pos - QPoint(0,16)); message->setHtml("<div style=\"background:white;color:blue;font-height:15px;\"><b>"+ _callsign+"</b></div><div style=\"background:white;color:black;\"><br/>"+_message+"<br/><b>Via:</b>"+_via+"</span>"); scene->addItem(message); _item_text = message; }
void Update(int64 amount) { referenced = true; if (amount == nAmount) return; // If only the amount changed, update text nAmount = amount; text->setHtml( "<center>" + QString::fromStdString(FormatMoney(nAmount)) + "</center>" ); }
void NodeBackDropPrivate::setNameInternal(const QString& n) { { QMutexLocker l(&nameStringMutex); nameString = n; } QString textLabel = n; textLabel.prepend("<div align=\"center\"><font size = 6>"); textLabel.append("</font></div>"); name->setHtml(textLabel); name->adjustSize(); QRectF bbox = _publicInterface->boundingRect(); _publicInterface->resize(bbox.width(), bbox.height()); }
HelpItem::HelpItem(QGraphicsItem * parent) : AbstractDisposeable(true, parent) , m_frame(FrameFactory::createFrame(0x1001 /*HARDCODED*/)) { QString introduction = tr( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" "<html><!--head><meta name=\"qrichtext\" content=\"1\" /></head-->\n" "<body style=\"font-family:'Sans Serif';\">\n" " <span style='font-size: 26px; font-weight: normal; color: #FF0000;'>\n" " <img src=':/data/action-remove.png'>\n" " Welcome\n" " <img src=':/data/action-remove.png'>\n" " </span>\n" " <br />\n" " <div style='font-size: 16px; font-weight: normal;'>\n" " <b>Playing</b> with <b>Fotowall</b> is easy\n" " </div>\n" " <ul>\n" " <li><img src=':/data/action-add.png'><b> add contents</b> using the <i><span style='background-color: rgb(255, 226, 0);'>ADD NEW</span></i> buttons or <i><span style='background-color: rgb(255, 226, 0);'>drop them</span></i></li>\n" " <li><img src=':/data/action-move.png'><b> move contents around </b> and <b><img src=':/data/action-rotate.png'> rotate them</b> <span style='background-color: rgb(255, 226, 0);'>by <i>dragging the corners</i></span></li>\n" " <li><img src=':/data/action-configure.png'><i> <span style='background-color: rgb(255, 226, 0);'>right click on the objects</span></i> or <i><span style='background-color: rgb(255, 226, 0);'>use the top bar</span></i> to <b>modify properties</b></li>\n" " <li><span style='background-color: rgb(255, 226, 0);'><i>double click any content</i></span> to <b>open the editor</b> or set it as <b>background</b></li>\n" " <li>...and we'll let you discover the rest!</li>\n" " </ul>\n" " <div><font color='#2B2B2B'><b>\n" " Please make sure to share your best work with your friends ;-)\n" " </b></font></div>\n" " <br/>\n" " <div><font color='#616161' style='font-size: 11px; font-weight: normal;'>\n" " Fotowall is LGPL, by Enrico Ros <*****@*****.**>, 2009\n" " </font></div>\n" "</body>\n" "</html>" ); #if defined(USE_QTWEBKIT) // show fancy help in internal browser #error WebKit was completely disabled, to only have 1 version of the HTML to translate... //BrowserItem * bi = new BrowserItem(this); //bi->setGeometry(...); //bi->write(introduction); //bi->setReadOnly(true); #else // create an item to display it QGraphicsTextItem * ti = new QGraphicsTextItem(this); ti->setHtml(introduction); ti->setPos(boundingRect().adjusted(12, 12, -12, -12).topLeft()); ti->setTextInteractionFlags(Qt::NoTextInteraction); #endif }
void TXaxis::setAnswersForBarChart(QList<TgroupedQAunit>& listOfLists) { setLength(m_qWidth * (listOfLists.size() + 1)); update(boundingRect()); m_ticTips.clear(); for (int i = 0; i < listOfLists.size(); i++) { QGraphicsTextItem *ticTip = new QGraphicsTextItem(); ticTip->setHtml(listOfLists[i].description()); TgraphicsTextTip::alignCenter(ticTip); if ((ticTip->boundingRect().width() * scale()) > m_qWidth) ticTip->setScale(((qreal)m_qWidth * scale()) / ticTip->boundingRect().width()); scene()->addItem(ticTip); ticTip->setPos(pos().x() + mapValue(i + 1) - (ticTip->boundingRect().width() * ticTip->scale()) / 2 , pos().y() + 15); m_ticTips << ticTip; } }
void DataVisualizer::draw(SceneType scene, qreal& lastXPos, Element::Ptr e, int propertyIndex) { if (e.isNull()) return; // see if item should be drawn Element::Property p(Element::getProperty(propertyIndex)); Element::PropertyType type(Element::propertyType(p)); Element::PropertyVariant var(e->propertyConst(p)); if (p == Element::NUCLEONS_PROPERTY && !e->isIsotope()) return; if (!Element::isValidVariant(var)) return; // build the text item QGraphicsItem * item(0); QGraphicsTextItem * text = new QGraphicsTextItem(); text->setHtml( getLinkText(*e) + "<br>" + mMainWindow->toString(var)); text->setTextInteractionFlags(Qt::TextBrowserInteraction); text->setToolTip(tr("formattedFormulaToolTip")); connect(text, SIGNAL(linkActivated(const QString&)), this, SLOT(emitElementLinkActivated(const QString&))); item = text; // build the encapsulating box item QGraphicsRectItem * rect = new QGraphicsRectItem( item->boundingRect() ); rect->setBrush(QBrush(QColor(196, 255, 196))); // combine both and add them to the scene item->setParentItem(rect); scene->addItem(rect); QPointF pos(boost::apply_visitor(DrawingPositionFromPropertyVariant(), var)); if (type == Element::COMPLEX_TYPE || type == Element::STRING_TYPE) { // no stacking for 2D drawing // item positions are stretched in X direction if (lastXPos > pos.x()) { pos.setX(lastXPos); } rect->setPos(pos); // update drawing position for the next item lastXPos = pos.x() + rect->boundingRect().width() + itemMargin; } else { setItemPos(rect, pos); } }
void Create(QGraphicsScene *scene, const GameGraphicsObjects *grobjs, int x, int y, int64 amount) { nAmount = amount; referenced = true; coin = scene->addPixmap(grobjs->coin_sprite); coin->setOffset(x, y); coin->setZValue(0.1); text = new QGraphicsTextItem(coin); text->setHtml( "<center>" + QString::fromStdString(FormatMoney(nAmount)) + "</center>" ); text->setPos(x, y + 13); text->setTextWidth(TILE_SIZE); }
void LegendItem::addId(int i) { QGraphicsTextItem* id = new QGraphicsTextItem(this); id->setHtml(QString("[%1]").arg(i)); id->setFont(getFont()); int idXPos = 0; int idYPos = _currHeight + _space; if (id->boundingRect().width() > rect().width()) { idXPos = (int)(0 - id->boundingRect().width() / 2); } else { idXPos = (int)((rect().width() - id->boundingRect().width()) / 2); } id->setPos(idXPos, idYPos); _currHeight += _space + (int)(id->boundingRect().height()); }
void addBoxedItem(QGraphicsItem* item, QString title) { QGraphicsRectItem* box = createBox(); item->setParentItem(box); QString htmlTitle = QString("<center>%1</center>").arg(title); QGraphicsTextItem *textItem = new QGraphicsTextItem(); textItem->setDefaultTextColor(Qt::blue); QFont font; font.setPixelSize(10); textItem->setFont(font); textItem->setHtml(htmlTitle); textItem->setTextWidth(WIDTH); textItem->setParentItem(box); textItem->moveBy(0, 110); nextPosition(); }
void LegendItem::addName(const QString& n) { QGraphicsTextItem* name = new QGraphicsTextItem(this); QString html = n; html.replace(QString(" "), QString("<br/>")); name->setHtml(QString("<p align=\"center\">%1</p>").arg(html)); name->setFont(getFont()); int nameXPos = 0; int nameYPos = (int)(rect().height() - _space - name->boundingRect().height()); if (name->boundingRect().width() > rect().width()) { nameXPos = (int)(0 - name->boundingRect().width() / 2); } else { nameXPos = (int)((rect().width() - name->boundingRect().width()) / 2); } name->setPos(nameXPos, nameYPos); _currHeight = (int)(_space + name->boundingRect().height()); }
void NodeBackDropPrivate::refreshLabelText(const QString &text) { QString textLabel = text; textLabel.replace("\n", "<br>"); textLabel.prepend("<div align=\"left\">"); textLabel.append("</div>"); QFont f; String_KnobGui::parseFont(textLabel, f); label->setFont(f); label->setHtml(textLabel); QRectF labelBbox = label->boundingRect(); QRectF nameBbox = name->boundingRect(); QRectF bbox = _publicInterface->boundingRect(); int w = std::max(std::max(bbox.width(), labelBbox.width()),nameBbox.width()); int h = std::max(labelBbox.height() + nameBbox.height() * 1.5 + 10, bbox.height()); _publicInterface->resize(w, h); _publicInterface->update(); }
QGraphicsTextItem* GraphicsWorkflow::addInfoGraphText(const QMap<QString,QPair<QPointF,QString> >& ids, const QString& title, QGraphicsTextItem*& titleitem) { QPointF infopos(0,0); QPointF titlepos(0,0); qreal leftx = 0, rightx = 0; for (int i=0; i< ids.keys().count(); i++ ) { QString key = ids.keys().at(i); if ( ids[key].first.x() < infopos.x() ) { infopos.setX(ids[key].first.x()); leftx = ids[key].first.x(); } if ( ids[key].first.x() > rightx ) { rightx = ids[key].first.x(); } if ( ids[key].first.y() < infopos.y() ) { infopos.setY(ids[key].first.y()); } } qDebug("right: %0.2f",rightx); qDebug("leftx: %0.2f",leftx); titlepos.setX((rightx-leftx)/2.0); QGraphicsTextItem *infotitle = NULL; infotitle = new QGraphicsTextItem(); infotitle->setHtml(title); infopos.setY(infopos.y()-15); if ( infotitle) { scene()->addItem(infotitle); } bool ok; qreal size = SafetYAWL::getConf()["GeneralOptions/currentflowtitle.separation"].toDouble(&ok); QString fontname = SafetYAWL::getConf()["GeneralOptions/currentflowtitle.font"]; int fontsize = SafetYAWL::getConf()["GeneralOptions/currentflowtitle.size"].toInt(&ok); QFont myfont; ok = false; if ( !fontname.isEmpty()) { myfont.setFamily(fontname); ok = true; } if ( fontsize > 1 ) { myfont.setPixelSize(fontsize); ok = true; } if ( infotitle) { int titlesize = fontsize+3; myfont.setPixelSize(titlesize); infotitle->setFont(myfont); } infopos.setY(infopos.y()-size); // Colocando posicion del titulo titlepos.setX(titlepos.x()); titlepos.setY(infopos.y()-size*2.5); if (infotitle) { infotitle->setPos(titlepos); titleitem = infotitle; } //qDebug("...infotext %p", infotext); return infotitle; }
QGraphicsTextItem* GraphicsWorkflow::addInfoGraphDateText(const QMap<QString,QPair<QPointF,QString> >& ids) { QPointF infopos(0,0); qreal leftx = 0, rightx = 0; for (int i=0; i< ids.keys().count(); i++ ) { QString key = ids.keys().at(i); if ( ids[key].first.x() < infopos.x() ) { infopos.setX(ids[key].first.x()); leftx = ids[key].first.x(); } if ( ids[key].first.x() > rightx ) { rightx = ids[key].first.x(); } if ( ids[key].first.y() < infopos.y() ) { infopos.setY(ids[key].first.y()); } } qDebug("right: %0.2f",rightx); qDebug("leftx: %0.2f",leftx); QGraphicsTextItem *infotext = new QGraphicsTextItem(); QString msg = SafetYAWL::getConf()["Graphs/infotext.format"]; QDateTime now = QDateTime::currentDateTime(); QString date = now.toString("dd MMM yyyy"); QString time = now.toString("h:mm:ssap"); QString datetime = now.toString("dd MMM yyyy hh:mm:ssap"); msg.replace("%time",time); msg.replace("%datetime",datetime); msg.replace("%date",date); scene()->addItem(infotext); qDebug("...addInfoGraphText...SafetYAWL::lastinfodate:|%s|", qPrintable(SafetYAWL::lastinfodate)); if ( !SafetYAWL::lastinfodate.isEmpty() ) { infotext->setHtml(SafetYAWL::lastinfodate); } else { infotext->setHtml(msg); } SafetYAWL::lastinfodate = msg; bool ok; qreal size = SafetYAWL::getConf()["Graphs/infotext.separation"].toDouble(&ok); qDebug("......separation:|%0.2f|",size); QString fontname = SafetYAWL::getConf()["Graphs/infotext.font"]; int fontsize = SafetYAWL::getConf()["Graphs/infotext.size"].toInt(&ok); QFont myfont; ok = false; if ( !fontname.isEmpty()) { myfont.setFamily(fontname); ok = true; } qDebug(".....(1).........."); if ( fontsize > 1 ) { myfont.setPixelSize(fontsize); ok = true; } if ( ok ) { infotext->setFont(myfont); } infopos.setY(infopos.y()-int(size)); infotext->setPos(infopos); return infotext; }
int main(int argc, char **argv) { Q_INIT_RESOURCE(stickman); QApplication app(argc, argv); StickMan *stickMan = new StickMan; stickMan->setDrawSticks(false); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) RectButton *buttonJump = new RectButton("Jump"); buttonJump->setPos(100, 125); RectButton *buttonDance = new RectButton("Dance"); buttonDance->setPos(100, 200); RectButton *buttonChill = new RectButton("Chill"); buttonChill->setPos(100, 275); #else QGraphicsTextItem *textItem = new QGraphicsTextItem(); textItem->setHtml("<font color=\"white\"><b>Stickman</b>" "<p>" "Tell the stickman what to do!" "</p>" "<p><i>" "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>" "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>" "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>" "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>" "</i></p>" "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again." "</p></font>"); qreal w = textItem->boundingRect().width(); QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect(); textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0); #endif QGraphicsScene scene; scene.addItem(stickMan); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) scene.addItem(buttonJump); scene.addItem(buttonDance); scene.addItem(buttonChill); #else scene.addItem(textItem); #endif scene.setBackgroundBrush(Qt::black); GraphicsView view; view.setRenderHints(QPainter::Antialiasing); view.setTransformationAnchor(QGraphicsView::NoAnchor); view.setScene(&scene); QRectF sceneRect = scene.sceneRect(); // making enough room in the scene for stickman to jump and die view.resize(sceneRect.width() + 100, sceneRect.height() + 100); view.setSceneRect(sceneRect); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.showMaximized(); view.fitInView(scene.sceneRect(), Qt::KeepAspectRatio); #else view.show(); view.setFocus(); #endif LifeCycle cycle(stickMan, &view); cycle.setDeathAnimation(":/animations/dead"); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) cycle.addActivity(":/animations/jumping", Qt::Key_J, buttonJump, SIGNAL(clicked())); cycle.addActivity(":/animations/dancing", Qt::Key_D, buttonDance, SIGNAL(clicked())); cycle.addActivity(":/animations/chilling", Qt::Key_C, buttonChill, SIGNAL(clicked())); #else cycle.addActivity(":/animations/jumping", Qt::Key_J); cycle.addActivity(":/animations/dancing", Qt::Key_D); cycle.addActivity(":/animations/chilling", Qt::Key_C); #endif cycle.start(); return app.exec(); }
TlinearChart::TlinearChart(Texam* exam, Tchart::Tsettings& settings, QWidget* parent) : TmainChart(exam, settings, parent) { // Determine y value type and its maximal value to prepare Y axis switch (settings.yValue) { case TmainLine::e_prepareTime: { quint32 prepTime = 0; for(int i = 0; i < exam->count(); i++) prepTime = qMax(prepTime, exam->question(i)->attempt(0)->prepareTime()); yAxis->setMaxValue((qreal)prepTime / 10.0); yAxis->setUnit(TYaxis::e_prepareTime); break; } case TmainLine::e_attemptsCount: { int attemptsNr = 0; for(int i = 0; i < exam->count(); i++) attemptsNr = qMax(attemptsNr, exam->question(i)->attemptsCount()); yAxis->setMaxValue(attemptsNr, false); yAxis->setUnit(TYaxis::e_attemptsCount); break; } case TmainLine::e_playedCount: { int playedNr = 0; for(int i = 0; i < exam->count(); i++) playedNr = qMax(playedNr, exam->question(i)->totalPlayBacks()); yAxis->setMaxValue(playedNr, false); yAxis->setUnit(TYaxis::e_playedCount); break; } case TmainLine::e_effectiveness: { yAxis->setMaxValue(100.0); // 100% looks good for this kind yAxis->setUnit(TYaxis::e_effectiveness); break; } default: { quint16 maxTime = 0; for(int i = 0; i < exam->count(); i++) maxTime = qMax(maxTime, exam->question(i)->time); yAxis->setMaxValue((qreal)maxTime / 10.0); break; } } if (settings.order == e_byNumber) { xAxis->setAnswersList(currExam->answList(), currExam->level()); prepareChart(currExam->count()); m_mainLine = new TmainLine(currExam->answList(), this, settings.yValue); if (settings.yValue == TmainLine::e_questionTime) { qreal aTime = 0 , prev = 0; int firstCorrect = 0, okCount = 0; for(int i = 0; i < exam->count(); i++) { // looking for first correct answer if (!exam->question(i)->isWrong() || (!exam->question(i)->isWrong() && settings.inclWrongAnsw)) { firstCorrect = i; prev = exam->question(i)->time; okCount++; aTime = prev; break; } } int prevX = firstCorrect + 1; for(int i = firstCorrect + 1; i < exam->count(); i++) { if (exam->question(i)->isWrong()) continue; // skip wrong answers in aver time else aTime = (aTime * okCount + (exam->question(i)->time)) / (okCount + 1); okCount++; TgraphicsLine *averProgress = new TgraphicsLine(); scene->addItem(averProgress); averProgress->setPen(QPen(averColor.darker(120), 3, Qt::DotLine)); averProgress->setLine(xAxis->mapValue(prevX) + xAxis->pos().x(), yAxis->mapValue(prev / 10.0), xAxis->mapValue(i + 1) + xAxis->pos().x(), yAxis->mapValue(aTime / 10.0)); prevX = i + 1; averProgress->setZValue(20); prev = aTime; } if (exam->averageReactonTime() > 0) { TgraphicsLine *averLine = new TgraphicsLine(0, "<p>" + TexTrans::averAnsverTimeTxt() + QString("<br><big><b>%1</b></big></p>").arg(Texam::formatReactTime(exam->averageReactonTime(), true)) ); scene->addItem(averLine); averLine->setZValue(15); averLine->setPen(QPen(averColor, 2)); averLine->setLine(xAxis->mapValue(1) + xAxis->pos().x(), yAxis->mapValue(exam->averageReactonTime() / 10.0), xAxis->mapValue(exam->count()) + xAxis->pos().x(), yAxis->mapValue(exam->averageReactonTime() / 10.0)); } // rest of cases are available only for melodies } } if (settings.order == e_byNote || settings.order == e_byFret || settings.order == e_byKey || settings.order == e_byAccid || settings.order == e_byQuestAndAnsw || settings.order == e_byMistake) { sort(); xAxis->setAnswersLists(sortedLists, exam->level()); int ln = 0; for (int i = 0; i < sortedLists.size(); i++) ln += sortedLists[i].size(); prepareChart(ln); m_mainLine = new TmainLine(sortedLists, this, settings.yValue); int goodOffset = 0; // 0 when not unrelated question list inside if (hasListUnrelated) goodOffset = -1; // do not perform a last loop int cnt = 1; if (settings.yValue != TmainLine::e_questionTime) { QTimer::singleShot(10, this, SLOT(ajustChartHeight())); return; } // paint lines with average time of all the same notes/frets for (int i = 0; i < goodSize + goodOffset; i++) { // skip wrong answers if separated if (sortedLists[i].size() > 1) { TgraphicsLine *averTimeLine = new TgraphicsLine(&sortedLists[i]); averTimeLine->setText(sortedLists[i].fullDescription()); scene->addItem(averTimeLine); averTimeLine->setZValue(46); averTimeLine->setPen(QPen(averColor, 3)); // sea blue averTimeLine->setLine(xAxis->mapValue(cnt - 0.4) + xAxis->pos().x(), yAxis->mapValue(sortedLists[i].averTime() / 10.0), xAxis->mapValue(cnt + sortedLists[i].size() -0.6) + xAxis->pos().x(), yAxis->mapValue(sortedLists[i].averTime() / 10.0)); } cnt += sortedLists[i].size(); } cnt = 1; // paint highlights under grouped items for (int i = 0; i < sortedLists.size(); i++) { QGraphicsRectItem *groupBg = new QGraphicsRectItem(); scene->addItem(groupBg); QColor hiCol = palette().highlight().color(); hiCol.setAlpha(60); if (i%2) { groupBg->setBrush(QBrush(hiCol)); groupBg->setPen(Qt::NoPen); groupBg->setRect(xAxis->mapValue(cnt), 0, sortedLists[i].size() * xAxis->questWidth(), yAxis->boundingRect().height()); groupBg->setZValue(-1); } cnt += sortedLists[i].size(); } // fret number over the chart if (settings.order == e_byFret) { cnt = 1; for (int i = 0; i < goodSize; i++) { QGraphicsTextItem *fretText = getTextItem(30); QString hintText = "<b>"; if (goodOffset && (i == goodSize -1)) hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type"); else hintText += QString("%1").arg(TfingerPos::romanFret(sortedLists[i].first()->qa.pos.fret())); hintText += "</b>"; fretText->setHtml(hintText); TgraphicsTextTip::alignCenter(fretText); qreal sc = 1.0; if (sortedLists[i].size() * xAxis->questWidth() < fretText->boundingRect().width()) { sc = (sortedLists[i].size() * xAxis->questWidth()) / fretText->boundingRect().width(); fretText->setScale(sc); } fretText->setPos(xAxis->mapValue(cnt) + (sortedLists[i].size() * xAxis->questWidth() - fretText->boundingRect().width() * sc) / 2, yAxis->mapValue(yAxis->maxValue())); cnt += sortedLists[i].size(); } } // key signature names over the chart if (settings.order == e_byKey) { cnt = 1; QColor tc = palette().text().color(); for (int i = 0; i < goodSize; i++) { QGraphicsTextItem *keyText = getTextItem(16); QString hintText = "<b>"; if (goodOffset && (i == goodSize -1)) hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type"); else { hintText += QString("%1").arg(sortedLists[i].first()->key.getName()); hintText += "<br>" + getWasInAnswOrQuest(TQAtype::e_asNote, sortedLists[i].operator[](0).qaPtr); } hintText += "</b>"; keyText->setHtml(hintText); TgraphicsTextTip::alignCenter(keyText); qreal sc = 1.0; if (sortedLists[i].size() * xAxis->questWidth() < keyText->boundingRect().width()) { sc = (sortedLists[i].size() * xAxis->questWidth()) / keyText->boundingRect().width(); keyText->setScale(sc); } keyText->setPos(xAxis->mapValue(cnt) + (sortedLists[i].size() * xAxis->questWidth() - keyText->boundingRect().width() * sc) / 2, yAxis->mapValue(yAxis->maxValue())); cnt += sortedLists[i].size(); } } // accidentals over the chart if (settings.order == e_byAccid) { cnt = 1; for (int i = 0; i < goodSize; i++) { QGraphicsTextItem *accidentalText = getTextItem(30); QString hintText; if (goodOffset && (i == goodSize -1)) hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type") + "</span>"; else if (kindOfAccids[i]) hintText += QString("%1").arg(accidToNotka(kindOfAccids[i], 40)); else hintText += QApplication::translate("TlinearChart", "without accidentals"); accidentalText->setHtml(hintText); TgraphicsTextTip::alignCenter(accidentalText); accidentalText->setPos(xAxis->mapValue(cnt) + (sortedLists[i].size() * xAxis->questWidth() - accidentalText->boundingRect().width()) / 2, yAxis->mapValue(yAxis->maxValue())); cnt += sortedLists[i].size(); } } // question/answer type over the chart if (settings.order == e_byQuestAndAnsw) { cnt = 1; for (int i = 0; i < goodSize; i++) { QGraphicsTextItem *qaText = getTextItem(30); int nootFontSize = fontMetrics().boundingRect("A").height() * 2; QString hintText; if (exam->melodies()) { if (sortedLists[i].first()->questionAs == TQAtype::e_asNote) hintText = TexTrans::playMelodyTxt(); else hintText = TexTrans::writeMelodyTxt(); } else hintText = TnooFont::span(TquestionAsWdg::qaTypeSymbol(sortedLists[i].first()->questionAs) + "?", nootFontSize) + "<br>" + TnooFont::span(TquestionAsWdg::qaTypeSymbol(sortedLists[i].first()->answerAs) + "!", nootFontSize); qaText->setHtml(hintText); TgraphicsTextTip::alignCenter(qaText); qreal sc = 1.0; if (sortedLists[i].size() * xAxis->questWidth() < qaText->boundingRect().width()) { sc = (sortedLists[i].size() * xAxis->questWidth()) / qaText->boundingRect().width(); qaText->setScale(sc); } qaText->setPos(xAxis->mapValue(cnt) + (sortedLists[i].size() * xAxis->questWidth() - qaText->boundingRect().width() * sc) / 2, yAxis->mapValue(0) - yAxis->length()); cnt += sortedLists[i].size(); } } } QTimer::singleShot(10, this, SLOT(ajustChartHeight())); }
Window::Window(const QString &title, const QSizeF &size) :title(title), size(size), keep_when_disappear(false) { setFlags(ItemIsMovable); QPixmap *bg; bg = size.width()>size.height() ? new QPixmap("image/system/tip.png") : new QPixmap("image/system/about.png"); QImage bgimg = bg->toImage(); outimg = new QImage(size.toSize(),QImage::Format_ARGB32); qreal pad = 10; int w = bgimg.width(); int h = bgimg.height(); int tw = outimg->width(); int th =outimg->height(); qreal xc = (w - 2*pad)/(tw - 2*pad); qreal yc = (h - 2*pad)/(th - 2*pad); for(int i=0;i<tw;i++) for(int j=0;j<th;j++) { int x = i; int y = j; if( x>=pad && x<=(tw - pad) ) x = pad + (x - pad)*xc; else if(x>=(tw-pad))x = w - (tw - x); if( y>=pad && y<=(th - pad) ) y = pad + (y - pad)*yc; else if(y>=(th-pad))y = h - (th - y); QRgb rgb = bgimg.pixel(x,y); outimg->setPixel(i,j,rgb); } scaleTransform = new QGraphicsScale(this); scaleTransform->setXScale(1.05); scaleTransform->setYScale(0.95); scaleTransform->setOrigin(QVector3D( this->boundingRect().width()/2, this->boundingRect().height()/2, 0 )); QList<QGraphicsTransform *> transforms; transforms << scaleTransform; setTransformations(transforms); this->setOpacity(0.0); QGraphicsTextItem * titleItem = new QGraphicsTextItem(this); QString style; style.append("font-size:18pt; "); style.append("color:#77c379; "); style.append(QString("font-family: %1").arg(Config.SmallFont.family())); QString content; content.append(QString("<h style=\"%1\">%2</h>") .arg(style).arg(title)); titleItem->setHtml(content); titleItem->moveBy(size.width()/2 - titleItem->boundingRect().width()/2,10); }
bool PSV_ChartItem::adjusetMargin() { // qreal m_margin = getData(PSV::margin).toDouble(); // PSV_Public::printMes(m_margin,"margin"); int m_margin = getData(PSV::margin,3).toInt(); qreal margin_up = m_margin_up+m_margin; qreal margin_down = m_margin_down+m_margin; qreal margin_left = m_margin_left+m_margin; qreal margin_right = m_margin_right+m_margin; if(m_axisParam_left.m_isShow) { createLeftAxisi(m_axisParam_left); margin_left += m_leftAxisItem->validRect().width(); } if(m_axisParam_right.m_isShow) { createRightAxisi(m_axisParam_right); margin_right += m_rightAxisItem->validRect().width(); } if(m_axisParam_up.m_isShow) { createUpAxisi(m_axisParam_up); margin_up += m_upAxisItem->validRect().height(); } if(m_axisParam_down.m_isShow) { createDownAxisi(m_axisParam_down); margin_down += m_downAxisItem->validRect().height(); } QString m_titleText = getData(PSV::titleText,"").toString(); if(!m_titleText.isEmpty()) { createTitle(m_titleText); margin_up += m_titleItem->boundingRect().height(); } if(!isStaHidden() && m_curveDataMap.count() > 0) { qreal height_max = 0; qreal width_max = 0; QGraphicsTextItem *textItem = new QGraphicsTextItem(this); textItem->setDefaultTextColor(getDefaultColor()); textItem->setFont(staFont()); QMapIterator<QString,PSV_CurveInfo> iter(m_curveDataMap); while(iter.hasNext()) { iter.next(); PSV_CurveInfo curveInfo = iter.value(); textItem->setHtml(curveInfo.m_staHtmText); qreal tempWidth = textItem->boundingRect().width(); qreal tempHeight = textItem->boundingRect().height(); if(width_max < tempWidth) { width_max = tempWidth; } if(height_max < tempHeight) { height_max = tempHeight; } } width_max += height_max; height_max += getData(PSV::margin,3).toInt(); qreal width = getBoundingRect().width() - margin_left - margin_right; if(width_max >= width) { margin_down += m_curveDataMap.count() * height_max; } else { int count_row = (int)(width / width_max); int dataCount = m_curveDataMap.count(); if(dataCount % count_row != 0) { dataCount += count_row; } int count = dataCount / count_row; margin_down += count * height_max; } m_staMaxWidth = width_max; } m_margin_total_up = margin_up; m_margin_total_down = margin_down; m_margin_total_left = margin_left; m_margin_total_right = margin_right; updateChartRect(); return clearAll(); }
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 }