void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText ) { scene->clear(); mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); QDomDocument doc; QString data = QString::fromUtf8(templateXml); QString replacementText = QString::fromUtf8(templateText); doc.setContent(data); QDomElement title = doc.documentElement(); // Check for invalid title if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return; // Check title locale if ( title.hasAttribute( "LC_NUMERIC" ) ) { QString locale = title.attribute( "LC_NUMERIC" ); QLocale::setDefault( locale ); } int originalWidth; int originalHeight; if ( title.hasAttribute("width") ) { originalWidth = title.attribute("width").toInt(); originalHeight = title.attribute("height").toInt(); scene->setSceneRect(0, 0, originalWidth, originalHeight); } else { originalWidth = scene->sceneRect().width(); originalHeight = scene->sceneRect().height(); } if ( title.hasAttribute( "out" ) ) { mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() ); } else { mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) ); } mlt_properties_set_int( producer_props, "_original_width", originalWidth ); mlt_properties_set_int( producer_props, "_original_height", originalHeight ); QDomNode node; QDomNodeList items = title.elementsByTagName("item"); for ( int i = 0; i < items.count(); i++ ) { QGraphicsItem *gitem = NULL; node = items.item( i ); QDomNamedNodeMap nodeAttributes = node.attributes(); int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt(); if ( zValue > -1000 ) { if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" ) { QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes(); QFont font( txtProperties.namedItem( "font" ).nodeValue() ); QDomNode propsNode = txtProperties.namedItem( "font-bold" ); if ( !propsNode.isNull() ) { // Old: Bold/Not bold. font.setBold( propsNode.nodeValue().toInt() ); } else { // New: Font weight (QFont::) font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() ); } font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() ); font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() ); // Older Kdenlive version did not store pixel size but point size if ( txtProperties.namedItem( "font-pixel-size" ).isNull() ) { QFont f2; f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() ); font.setPixelSize( QFontInfo( f2 ).pixelSize() ); } else font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() ); QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) ); QString text = node.namedItem( "content" ).firstChild().nodeValue(); if ( !replacementText.isEmpty() ) { text = text.replace( "%s", replacementText ); } QGraphicsTextItem *txt = scene->addText(text, font); if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){ QTextDocument *doc = txt->document(); // Make sure some that the text item does not request refresh by itself doc->blockSignals(true); QTextCursor cursor(doc); cursor.select(QTextCursor::Document); QTextCharFormat format; format.setTextOutline( QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ), txtProperties.namedItem("font-outline").nodeValue().toDouble(), Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin) ); format.setForeground(QBrush(col)); cursor.mergeCharFormat(format); } else { txt->setDefaultTextColor( col ); } // Effects if (!txtProperties.namedItem( "typewriter" ).isNull()) { // typewriter effect mlt_properties_set_int( producer_props, "_animated", 1 ); QStringList effetData = QStringList() << "typewriter" << text << txtProperties.namedItem( "typewriter" ).nodeValue(); txt->setData(0, effetData); if ( !txtProperties.namedItem( "textwidth" ).isNull() ) txt->setData( 1, txtProperties.namedItem( "textwidth" ).nodeValue() ); } if ( txtProperties.namedItem( "alignment" ).isNull() == false ) { txt->setTextWidth( txt->boundingRect().width() ); QTextOption opt = txt->document()->defaultTextOption (); opt.setAlignment(( Qt::Alignment ) txtProperties.namedItem( "alignment" ).nodeValue().toInt() ); txt->document()->setDefaultTextOption (opt); } if ( !txtProperties.namedItem( "kdenlive-axis-x-inverted" ).isNull() ) { //txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt()); } if ( !txtProperties.namedItem( "kdenlive-axis-y-inverted" ).isNull() ) { //txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt()); } gitem = txt; } else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsRectItem" ) { QString rect = node.namedItem( "content" ).attributes().namedItem( "rect" ).nodeValue(); QString br_str = node.namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue(); QString pen_str = node.namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue(); double penwidth = node.namedItem( "content" ).attributes().namedItem( "penwidth") .nodeValue().toDouble(); QGraphicsRectItem *rec = scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ), QBrush( stringToColor( br_str ) ) ); gitem = rec; } else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" ) { const QString url = node.namedItem( "content" ).attributes().namedItem( "url" ).nodeValue(); const QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue(); QImage img; if (base64.isEmpty()){ img.load(url); }else{ img.loadFromData(QByteArray::fromBase64(base64.toAscii())); } ImageItem *rec = new ImageItem(img); scene->addItem( rec ); gitem = rec; } else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsSvgItem" ) { QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue(); QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue(); QGraphicsSvgItem *rec = NULL; if (base64.isEmpty()){ rec = new QGraphicsSvgItem(url); }else{ rec = new QGraphicsSvgItem(); QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec ); rec->setSharedRenderer(renderer); } if (rec){ scene->addItem(rec); gitem = rec; } } } //pos and transform if ( gitem ) { QPointF p( node.namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(), node.namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() ); gitem->setPos( p ); gitem->setTransform( stringToTransform( node.namedItem( "position" ).firstChild().firstChild().nodeValue() ) ); int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt(); gitem->setZValue( zValue ); #if QT_VERSION >= 0x040600 // effects QDomNode eff = items.item(i).namedItem("effect"); if (!eff.isNull()) { QDomElement e = eff.toElement(); if (e.attribute("type") == "blur") { QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(); blur->setBlurRadius(e.attribute("blurradius").toInt()); gitem->setGraphicsEffect(blur); } else if (e.attribute("type") == "shadow") { QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(); shadow->setBlurRadius(e.attribute("blurradius").toInt()); shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt()); gitem->setGraphicsEffect(shadow); } } #endif } } QDomNode n = title.firstChildElement("background"); if (!n.isNull()) { QColor color = QColor( stringToColor( n.attributes().namedItem( "color" ).nodeValue() ) ); if (color.alpha() > 0) { QGraphicsRectItem *rec = scene->addRect(0, 0, scene->width(), scene->height() , QPen( Qt::NoPen ), QBrush( color ) ); rec->setZValue(-1100); } } QString startRect; n = title.firstChildElement( "startviewport" ); // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport if (!n.isNull() && !n.toElement().hasAttribute("x")) { startRect = n.attributes().namedItem( "rect" ).nodeValue(); } n = title.firstChildElement( "endviewport" ); // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport if (!n.isNull() && !n.toElement().hasAttribute("x")) { QString rect = n.attributes().namedItem( "rect" ).nodeValue(); if (startRect != rect) mlt_properties_set( producer_props, "_endrect", rect.toUtf8().data() ); } if (!startRect.isEmpty()) { mlt_properties_set( producer_props, "_startrect", startRect.toUtf8().data() ); } return; }
void smithDialog::smithDrawReact(double react, bool doLabel) { QPen pen(smithLineColor,1); if (react == 0) { QPainterPath path; path.moveTo(smithLeftX, smithCenterY); path.lineTo(smithRightX, smithCenterY); scene->addPath(path, pen); QString text = "0"; QGraphicsTextItem *txt = scene->addText(text); QFontMetrics fm(scene->font()); txt->setDefaultTextColor(smithLineColor); QRectF rect = fm.tightBoundingRect(text); float x, y; x = smithLeftX - rect.width() *2; y = rect.top(); txt->setPos(x,y*2); return; } double angle; double arcRadius=(fabs(smithR0/react)*smithRadius) * 2; int startAngle = 270; angle = smithRadius / arcRadius * 2; angle = atan(angle) * 180 / PI; angle = angle * 2; QGraphicsArcItem* item; if (react < 0) { startAngle = 90; item = new QGraphicsArcItem(smithRightX - arcRadius/2, 0, arcRadius, arcRadius); item->setStartAngle(startAngle * 16); item->setSpanAngle(angle * 16); } else { item = new QGraphicsArcItem(smithRightX - arcRadius/2, 0 - arcRadius, arcRadius, arcRadius); item->setStartAngle(startAngle * 16); item->setSpanAngle(-angle * 16); } item->setPen(smithLineColor); scene->addItem(item); QString text = QString::number(react); QGraphicsTextItem *txt = scene->addText(text); txt->setDefaultTextColor(smithLineColor); QFontMetrics fm(scene->font()); QRectF rect = fm.tightBoundingRect(text); float x, y; x = smithRightX - arcRadius * sin((angle) / 180.0 * PI) / 2; y = arcRadius * sin((90.0-angle) / 180.0 * PI)/2 - arcRadius/2; if (fabs(react) == 50) { x = -rect.width() / 2; y=y-5; } else if (x < 0) { x = x - rect.width() - 10; } if (react < 0) { y = -y - rect.height(); } else { y = y - rect.height() * 2; } txt->setPos(x,y); }
void BC_DITL::addEvent(BC_Event* event, bool refresh) { // Write the event's data to the event file event->write(eventFile); // Initialize Times static bool init = true; if(init||refresh) { initTimes(event->time); init = false; } // Declare the reference event offset (in the graph->rows struct vector unsigned short REFEVNT_OFF=0; // Create an event object to hold the current event's information from the event database EventDatabase::Event currEvent; // Grab info from database if(!db.getEvent(event->code, currEvent)) qDebug() << "Could not reference event ID (" << event->code << ")\n\n"; // Create an origin object for the same reason EventDatabase::Origin currOrig; // Grab info from database if(!db.getOrigin(event->origin, currOrig)) qDebug() << "Could not reference origin ID (" << event->origin << ")\n\n"; // Send status message ui->DITL_statusBar->showMessage(QString("Creating event for ID: ").append(QString::fromStdString(currEvent.name)).append(" (").append(QString::number(event->code)).append(")")); for(unsigned short j(0);j<graph->rows.size();++j) // Find the matching event in the vertical event list { if(currEvent.name == graph->rows[j].name) // Set the reference event offset { REFEVNT_OFF=j; break; } } // ===== PAINT ===== // if(event->getUTC() > graph->lastTime) // Time Expansion and Current Unfinished Rectangle Repaint { // Coordinate variable double x = graph->gridLineX.back(); //for(unsigned short i(0); i<slotcount; ++i) while(event->getUTC() > graph->lastTime) // Loop until past the event { // Draw the timestamp bounding rectangle timeScene->addRect(x,1,TIMESLOT_WIDTH,(0.94)*ui->DITL_graphicsView_BOTT->height(),*outlinePen); // Grab time as a string and format it a bit std::string timestamp = graph->lastTime.toString(Qt::ISODate).toStdString(); for(unsigned char i(0); i<timestamp.size();++i){ if(timestamp[i]=='T') { timestamp[i]='\n'; break; } } if(timestamp.back()=='Z') timestamp.pop_back(); // Add text to the rectangle QGraphicsTextItem *text; text = timeScene->addText(QString::fromStdString(timestamp), *timeFont); text->setDefaultTextColor(QColor(205,201,201)); text->setPos(x,1); // Add tooltip text containing several time formats QString tt = "UTC: "; tt.append(graph->lastTime.toString()); tt.append("\nLocal: ").append(graph->lastTime.toLocalTime().toString(Qt::SystemLocaleShortDate)); text->setToolTip(tt); // Add Another Grid Line graph->gridLineX.push_back(x); graphScene->addRect(x,graph->gridLineY.front()-2,0,graph->gridLineY.back()-graph->gridLineY.front(),*linePen)->setZValue(0); // Progress the graph->lastTime graph->lastTime = graph->lastTime.addSecs(graph->timeStep); // Progress x coord x += TIMESLOT_WIDTH; } // Draw last vertical line graph->gridLineX.push_back(graph->gridLineX.back()+TIMESLOT_WIDTH); graphScene->addRect(x,graph->gridLineY.front()-2,0,graph->gridLineY.back()-graph->gridLineY.front(),*linePen)->setZValue(0); // Draw cube at end of timescene to make room for main scene's vertical scrollbar if(ui->DITL_graphicsView->verticalScrollBar()->isVisible()) { // Instantiate buffer cube static QGraphicsRectItem* bufferCube = new QGraphicsRectItem; if(!refresh) delete bufferCube; bufferCube = timeScene->addRect(graph->gridLineX.back(),1,16,(0.94)*ui->DITL_graphicsView_BOTT->height(),QPen(QColor(0,0,0,0))); } // Horizontal Line Repaint for(unsigned int i(0);i<graph->gridLineY.size();++i) graphScene->addRect(0,graph->gridLineY[i]-2,graph->gridLineX.back(),0,*linePen)->setZValue(0); for(unsigned int i(0); i<graph->events.size(); ++i) // Stretch out all of the unfinished rectangles { if(graph->events[i]->type == Graph::EventItem::RectType::Unfinished) // For every unfinished rectangle { // Clear old rectangle for(unsigned char j(0); j<graph->events[i]->graphicsItems.size(); ++j) graphScene->removeItem(graph->events[i]->graphicsItems[j]); graph->events[i]->graphicsItems.clear(); // Declare the reference event offset (in the graph->rows struct vector unsigned short REFEVNT_OFF=0; // Create an event object to hold the current event's information from the event database EventDatabase::Event currEvent; // Grab info from database if(!db.getEvent(graph->events[i]->event->code, currEvent)) qDebug() << "Could not reference event ID (" << graph->events[i]->event->code << ")\n\n"; // Create an origin object for the same reason EventDatabase::Origin currOrig; // Grab info from database if(!db.getOrigin(graph->events[i]->event->origin, currOrig)) qDebug() << "Could not reference origin ID (" << graph->events[i]->event->origin << ")\n\n"; for(unsigned short j(0);j<graph->rows.size();++j) // Find the matching event in the vertical event list { if(currEvent.name == graph->rows[j].name) // Set the reference event offset { REFEVNT_OFF=j; break; } } // Vectors holds references to all graphics items std::vector<QGraphicsRectItem*> rectangles; // "cursor" is the horizontal location of event in 'timeslots' double cursor = (double)(graph->events[i]->event->time-graph->low)/graph->timeStep; // Which is then multiplied by the width of a timeslot double x = cursor*TIMESLOT_WIDTH; // Set color (grabbed by event name) QBrush color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); if(graph->events[i]->event->severity==BC_Event::Severity::CAUTION) // Red dotted foreground if CAUTION { // Draw original rectangle // NOTE: width parameter = (total scene width)-(starting position) // Since it is an "unfinished" event, it goes until the end of the scene rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); // Set color to red warning color = colorDB.colorFromString("WARN"); color.setStyle(Qt::Dense7Pattern); // Draw dotted foreground over original rectangle rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); } if(graph->events[i]->event->severity==BC_Event::Severity::WARNING) // Draw crossed red foreground and outline if WARNING { // Change color to non-opaque color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); // Draw original rectangle rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); // Change color to red warning color = colorDB.colorFromString("WARN"); color.setStyle(Qt::DiagCrossPattern); // Draw red crossed and outlined rectangle over original rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*warningPen,color)); } else // Draw original if ADVISORY rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); // Grab time as string and convert to UTC QDateTime temp = QDateTime::fromTime_t(graph->events[i]->event->time); temp.setTimeZone(QTimeZone::utc()); temp.setTimeSpec(Qt::UTC); // Define tooltip QString tooltip = QString::fromStdString(graph->rows[REFEVNT_OFF].name ).append(" from: (" ).append(temp.toString() ).append(")" ).append(" -> (UNFINISHED)" ).append("\nSev: " ).append(sevToQString(graph->events[i]->event->severity) ).append("\tMsg: \"" ).append(QString::fromStdString(graph->events[i]->event->message) ).append("\"\nSource: " ).append(" ").append(QString::fromStdString(currOrig.name) ).append(" from " ).append(QString::fromStdString(graph->events[i]->event->filename) ).append(" on line " ).append(QString::number(graph->events[i]->event->lineNumber)); // Set event's tooltip rectangles.back()->setToolTip(tooltip); for(QGraphicsRectItem* r:rectangles) r->setZValue(1); // Delete old unbounded arrow delete graph->events[i]->unboundedEventArrow; // Reassign the event graph->events[i] = new Graph::EventItem(rectangles, Graph::EventItem::Unfinished, graph->events[i]->event); // Add this item to the event tree // TODO: REPLACE OLD ONE SOMEHOW graph->events[i]->treeItem = new BC_DITL_SEVTREE_ITEM(graph->events[i]->event->severity, graph->rows[REFEVNT_OFF].name, tooltip.toStdString(), x, graph->gridLineY[REFEVNT_OFF], graph->gridLineX.back()-x, eventHeight, false); // Add new unbounded arrow graph->events[i]->unboundedEventArrow = graphScene->addPixmap(*unboundedArrowRight); graph->events[i]->unboundedEventArrow->setPos(graph->gridLineX.back()-45,graph->gridLineY[REFEVNT_OFF]-1); graph->events[i]->unboundedEventArrow->setZValue(2); } } } if(event->eventType==BC_Event::EventType::POINT) // Paint a point event { // Vectors holds references to all graphics items std::vector<QGraphicsEllipseItem*> ellipses; // "cursor" is the horizontal location of event in 'timeslots' double cursor = ((double)(event->time-graph->low))/graph->timeStep; // Which is then multiplied by the width of a timeslot and shifted to the left double x = (cursor*TIMESLOT_WIDTH)-eventHeight/2; // The y coordinate is grabbed from the graph information singleton double y = graph->rows[REFEVNT_OFF].y; // Grab color from the origin color reference file (based on event) QBrush color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); if(event->severity==BC_Event::Severity::CAUTION) // Paint a red-dotted foreground over the event { // Draw original Ellipse ellipses.push_back(graphScene->addEllipse(x,y,eventHeight,eventHeight,*outlinePen,color)); // Change color params to red color = colorDB.colorFromString("WARN"); color.setStyle(Qt::Dense7Pattern); // Draw dotted foreground over original ellipses.push_back(graphScene->addEllipse(x,y,eventHeight,eventHeight,*outlinePen,color)); } else if(event->severity==BC_Event::Severity::WARNING) // Paint a red-crossed foreground and outline in red { // Set original color to non-opaque color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); // Draw original ellipse ellipses.push_back(graphScene->addEllipse(x,y,eventHeight,eventHeight,*outlinePen,color)); // Change color to red color = colorDB.colorFromString("WARN"); color.setStyle(Qt::DiagCrossPattern); // Draw outline and crossed foreground ellipses.push_back(graphScene->addEllipse(x,y,eventHeight,eventHeight,*warningPen,color)); } else // Draws the original ellipse only ellipses.push_back(graphScene->addEllipse(x,y,eventHeight,eventHeight,*outlinePen,color)); // Define tooltip string QString tooltip = QString::fromStdString( currEvent.name + " @ (" ).append(event->getUTC().toString() ).append(")\nSev: " ).append(sevToQString(event->severity) ).append("\tMsg: \"" ).append(QString::fromStdString(event->message) ).append("\"\nSource: " ).append(" ").append(QString::fromStdString(currOrig.name) ).append(" from " ).append(QString::fromStdString(event->filename) ).append(" on line " ).append(QString::number(event->lineNumber)); // Set the event's tooltip ellipses.back()->setToolTip(tooltip); for(QGraphicsEllipseItem* e:ellipses) e->setZValue(1); // Push back the graphics item reference vector graph->events.push_back(new Graph::EventItem(ellipses, event)); // Add this item to the event tree graph->addTreeItem(new BC_DITL_SEVTREE_ITEM(event->severity, graph->rows[REFEVNT_OFF].name, tooltip.toStdString(), x, y, eventHeight, eventHeight, true), graph->events.back()); } else if(event->eventType==BC_Event::EventType::END) // Paints an unstarted event or completes an unfinished event { // Paired flag to throw unstarted error bool paired = false; for(unsigned short i(0); i<graph->events.size(); ++i) // Check if there's an unfinished event waiting for this { if(event->code==graph->events[i]->event->code && graph->events[i]->type == Graph::EventItem::RectType::Unfinished) // If it finds a match { //Set paired flag to avoid throwing unstarted error paired = true; // Clear old rectangle for(unsigned char j(0); j<graph->events[i]->graphicsItems.size(); ++j) graphScene->removeItem(graph->events[i]->graphicsItems[j]); graph->events[i]->graphicsItems.clear(); // Vectors holds references to all graphics items std::vector<QGraphicsRectItem*> rectangles; // Similar procedure here, but we mark cursors for the beginning and end times double start = ((double)(graph->events[i]->event->time-graph->low)/graph->timeStep)*TIMESLOT_WIDTH; double end = ((double)(event->time-graph->low)/graph->timeStep)*TIMESLOT_WIDTH; // Initialize the color (grabs by event name) QBrush color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); if(event->severity==BC_Event::Severity::CAUTION) // Paints a dotted red foreground if CAUTION { // Original rectangle rectangles.push_back(graphScene->addRect(start,graph->gridLineY[REFEVNT_OFF],end-start,eventHeight,*outlinePen,color)); // Change color to red warning color = colorDB.colorFromString("WARN"); color.setStyle(Qt::Dense7Pattern); // Draw dotted foreground over original rectangle rectangles.push_back(graphScene->addRect(start,graph->gridLineY[REFEVNT_OFF],end-start,eventHeight,*outlinePen,color)); } else if(event->severity==BC_Event::Severity::WARNING) // Draws a crossed foreground and red outline if WARNING { // Change color to non-opaque color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); // Draw original rectangle rectangles.push_back(graphScene->addRect(start,graph->gridLineY[REFEVNT_OFF],end-start,eventHeight,*outlinePen,color)); // Change color to red warning color = colorDB.colorFromString("WARN"); color.setStyle(Qt::DiagCrossPattern); // Draw red outline and crossed patterned rectangle over original rectangle rectangles.push_back(graphScene->addRect(start,graph->gridLineY[REFEVNT_OFF],end-start,eventHeight,*warningPen,color)); } else // Draw the original rectangle if ADVISORY rectangles.push_back(graphScene->addRect(start,graph->gridLineY[REFEVNT_OFF],end-start,eventHeight,*outlinePen,color)); // Grab event time as string and convert to UTC QDateTime temp = QDateTime::fromTime_t(graph->events[i]->event->time); temp.setTimeZone(QTimeZone::utc()); temp.setTimeSpec(Qt::UTC); // Define tooltip QString tooltip = QString::fromStdString(graph->rows[REFEVNT_OFF].name ).append(" from: (" ).append(temp.toString() ).append(") -> (" ).append(event->getUTC().toString() ).append(")\nSev: " ).append(sevToQString(event->severity) ).append("\tMsg: \"" ).append(QString::fromStdString(event->message) ).append("\"\nSource: " ).append(" ").append(QString::fromStdString(currOrig.name) ).append(" from " ).append(QString::fromStdString(event->filename) ).append(" on line " ).append(QString::number(event->lineNumber)); // Set event's tooltip rectangles.back()->setToolTip(tooltip); for(QGraphicsRectItem* r:rectangles) r->setZValue(1); // Grab a by-value copy of the event to store in the "paired" event object BC_Event tempEventItem = *graph->events[i]->event; // Delete the graph item to remove it from tree delete graph->events[i]; // Push back the event item reference vector graph->events[i] = new Graph::EventItem(rectangles, Graph::EventItem::Paired, tempEventItem, event); // Push back the tree item vector with relevant params for later graph->addTreeItem(new BC_DITL_SEVTREE_ITEM(event->severity, graph->rows[REFEVNT_OFF].name, tooltip.toStdString(), start, graph->gridLineY[REFEVNT_OFF], end-start, eventHeight, false), graph->events[i]); } } if(!paired) { // Vectors holds references to all graphics items std::vector<QGraphicsRectItem*> rectangles; // "cursor" is the horizontal location of the END of the event in 'timeslots' double cursor = (double)(event->time-graph->low)/graph->timeStep; //Rectangle width is equal to the distance from the beginining of time to the end event double width = cursor*TIMESLOT_WIDTH; // Grab color from the origin color reference file (based on event) QBrush color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); if(event->severity==BC_Event::Severity::CAUTION) // Paints a red-dotted foreground over the event { // Draw original rectangle rectangles.push_back(graphScene->addRect(graph->gridLineX.front()+2,graph->gridLineY[REFEVNT_OFF],width,eventHeight,*outlinePen,color)); // Change colors to red color = colorDB.colorFromString("WARN"); color.setStyle(Qt::Dense7Pattern); // Draw dotted rectangle over original rectangles.push_back(graphScene->addRect(graph->gridLineX.front()+2,graph->gridLineY[REFEVNT_OFF],width,eventHeight,*outlinePen,color)); } else if(event->severity==BC_Event::Severity::WARNING) // Draws red outline and crossed foreground over event { // Set color to non-opaque color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); // Draw original non-opaque rectangle rectangles.push_back(graphScene->addRect(graph->gridLineX.front()+2,graph->gridLineY[REFEVNT_OFF],width,eventHeight,*outlinePen,color)); // Change colors to red color = colorDB.colorFromString("WARN"); color.setStyle(Qt::DiagCrossPattern); // Overlay crossed and outlined rectangle over original rectangles.push_back(graphScene->addRect(graph->gridLineX.front()+2,graph->gridLineY[REFEVNT_OFF],width,eventHeight,*warningPen,color)); } else // Draw original rectangle rectangles.push_back(graphScene->addRect(graph->gridLineX.front()+2,graph->gridLineY[REFEVNT_OFF],width,eventHeight,*outlinePen,color)); // Define tooltip text QString tooltip = QString::fromStdString( graph->rows[REFEVNT_OFF].name ).append(" from: (PREVIOUS LOG) -> (" ).append(event->getUTC().toString() ).append(")\nSev: " ).append(sevToQString(event->severity) ).append("\tMsg: \"" ).append(QString::fromStdString(event->message) ).append("\"\nSource: " ).append(" ").append(QString::fromStdString(currOrig.name) ).append(" from " ).append(QString::fromStdString(event->filename) ).append(" on line " ).append(QString::number(event->lineNumber)); // Set event tooltip rectangles.back()->setToolTip(tooltip); for(QGraphicsRectItem* r:rectangles) r->setZValue(1); // Push back the graphics item reference vector graph->events.push_back(new Graph::EventItem(rectangles, Graph::EventItem::RectType::Unstarted, event)); // Push back treeitems vector with relevant parameters for later graph->addTreeItem(new BC_DITL_SEVTREE_ITEM(event->severity, graph->rows[REFEVNT_OFF].name, tooltip.toStdString(), graph->gridLineX.front()+2, graph->gridLineY[REFEVNT_OFF], width, eventHeight, false), graph->events.back()); // Add unbounded arrow graph->events.back()->unboundedEventArrow = graphScene->addPixmap(*unboundedArrowRight); graph->events.back()->unboundedEventArrow->setPos(graph->gridLineX.front()+47,graph->gridLineY[REFEVNT_OFF]+44); graph->events.back()->unboundedEventArrow->setZValue(2); // Rotate to face left graph->events.back()->unboundedEventArrow->setRotation(180); } } else if(event->eventType==BC_Event::EventType::START) { // Vectors holds references to all graphics items std::vector<QGraphicsRectItem*> rectangles; // "cursor" is the horizontal location of event in 'timeslots' double cursor = (double)(event->time-graph->low)/graph->timeStep; // Which is then multiplied by the width of a timeslot double x = cursor*TIMESLOT_WIDTH; // Set color (grabbed by event name) QBrush color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); if(event->severity==BC_Event::Severity::CAUTION) // Red dotted foreground if CAUTION { // Draw original rectangle // NOTE: width parameter = (total scene width)-(starting position) // Since it is an "unfinished" event, it goes until the end of the scene rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); // Set color to red warning color = colorDB.colorFromString("WARN"); color.setStyle(Qt::Dense7Pattern); // Draw dotted foreground over original rectangle rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); } if(event->severity==BC_Event::Severity::WARNING) // Draw crossed red foreground and outline if WARNING { // Change color to non-opaque color = colorDB.colorFromEvent(graph->rows[REFEVNT_OFF].name); // Draw original rectangle rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); // Change color to red warning color = colorDB.colorFromString("WARN"); color.setStyle(Qt::DiagCrossPattern); // Draw red crossed and outlined rectangle over original rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*warningPen,color)); } else // Draw original if ADVISORY rectangles.push_back(graphScene->addRect(x,graph->gridLineY[REFEVNT_OFF],graph->gridLineX.back()-x,eventHeight,*outlinePen,color)); // Grab time as string and convert to UTC QDateTime temp = QDateTime::fromTime_t(event->time); temp.setTimeZone(QTimeZone::utc()); temp.setTimeSpec(Qt::UTC); // Define tooltip QString tooltip = QString::fromStdString(graph->rows[REFEVNT_OFF].name ).append(" from: (" ).append(temp.toString() ).append(")" ).append(" -> (UNFINISHED)" ).append("\nSev: " ).append(sevToQString(event->severity) ).append("\tMsg: \"" ).append(QString::fromStdString(event->message) ).append("\"\nSource: " ).append(" ").append(QString::fromStdString(currOrig.name) ).append(" from " ).append(QString::fromStdString(event->filename) ).append(" on line " ).append(QString::number(event->lineNumber)); // Set event's tooltip rectangles.back()->setToolTip(tooltip); for(QGraphicsRectItem* r:rectangles) r->setZValue(1); // Push back the event item reference vector graph->events.push_back(new Graph::EventItem(rectangles, Graph::EventItem::Unfinished, event)); // Add this item to the event tree graph->addTreeItem(new BC_DITL_SEVTREE_ITEM(event->severity, graph->rows[REFEVNT_OFF].name, tooltip.toStdString(), x, graph->gridLineY[REFEVNT_OFF], graph->gridLineX.back()-x, eventHeight, false), graph->events.back()); // Add arrow to display that the event was unfinished graph->events.back()->unboundedEventArrow = graphScene->addPixmap(*unboundedArrowRight); graph->events.back()->unboundedEventArrow->setPos(graph->gridLineX.back()-45,graph->gridLineY[REFEVNT_OFF]-1); graph->events.back()->unboundedEventArrow->setZValue(2); } // Clear status message ui->DITL_statusBar->clearMessage(); }
void Macro::draw(QGraphicsScene* scene, QColor background, QColor font) { //size 241, 281 //QBrush Ybrush(Qt::blue); //scene->setBackgroundBrush(Ybrush); QFont titleFont("Times", 10, QFont::Bold); QGraphicsTextItem * titleItem = new QGraphicsTextItem; titleItem->setPos(70,10); titleItem->setDefaultTextColor(font); titleItem->setFont(titleFont); titleItem->setPlainText("Macro Recorder"); scene->addItem(titleItem); QFont actFont("Times", 9, QFont::Bold); QGraphicsTextItem * actItem = new QGraphicsTextItem; actItem->setPos(30,40); actItem->setDefaultTextColor(font); actItem->setFont(actFont); if (activationKeyRec == false) { QChar key = static_cast<char>(activationKey); QString sKey = key; actItem->setPlainText("Activation Key: (" + sKey + ")"); } else { actItem->setPlainText("Activation Key: RECORDING"); } scene->addItem(actItem); QBrush onB(font); QPen onP(font); scene->addRect(160,150,40,40, onP, onB); scene->addRect(160,200,40,40, onP, onB); QFont onFont("Times", 11, QFont::Bold); QGraphicsTextItem * onItem = new QGraphicsTextItem; onItem->setPos(166,158); if (on) { onItem->setDefaultTextColor(Qt::yellow); } else { onItem->setDefaultTextColor(Qt::black); } onItem->setFont(onFont); onItem->setPlainText("On"); scene->addItem(onItem); QFont offFont("Times", 11, QFont::Bold); QGraphicsTextItem * offItem = new QGraphicsTextItem; offItem->setPos(166,208); if (on) { offItem->setDefaultTextColor(Qt::black); } else { offItem->setDefaultTextColor(Qt::yellow); } offItem->setFont(offFont); offItem->setPlainText("Off"); scene->addItem(offItem); if (recording) { QBrush recB(Qt::red); QPen recP(Qt::red); scene->addRect(60,80,30,30, recP, recB); } else { QBrush recB(font); QPen recP(font); scene->addRect(60,80,30,30, recP, recB); } QBrush loadB(font); QPen loadP(font); scene->addRect(140,80,30,30, loadP, loadB); QFont loadFont("Times", 7, QFont::Bold); QGraphicsTextItem * loadItem = new QGraphicsTextItem; loadItem->setPos(140,85); loadItem->setDefaultTextColor(Qt::black); loadItem->setFont(loadFont); loadItem->setPlainText("Load"); scene->addItem(loadItem); QFont recFont("Times", 8, QFont::Bold); QGraphicsTextItem * recItem = new QGraphicsTextItem; recItem->setPos(61,83); recItem->setDefaultTextColor(Qt::black); recItem->setFont(recFont); recItem->setPlainText("Rec"); scene->addItem(recItem); }
void QGraphicsVolumeView::updateDisplay(int volumeId) { if (this->isHidden()) { return; } if (_airImages == NULL) { return; } _currentSliceMarker = NULL; QFont sliceIndexFont("Courier", 20); int showingVolumeCount = _showAll ? _airImages->Count() : 1; for (int id = 0; id < showingVolumeCount; id++) { AIRImageDisplay src = _airImages->at(id); if (_volumeDisplays.size() <= id) { _volumeDisplays.push_back(AIRVolumeDisplay()); } if (!_volumeDisplays[id].Has(src)) { _volumeDisplays[id].SetDisplay(src); } if (_volumeDisplays[id].UpdateSlice(_directionCache, _useNavigationImage)) { const int w = _volumeDisplays[id].Width(); const int h = _volumeDisplays[id].Height(); const int s = _volumeDisplays[id].Count(); for (int i = 0; i < s; i++) { int realSliceIdx = i; int colPos = i * w; int rowPos = id * h; QGraphicsRectItem* item = _volumeDisplays[id].GetSliceData<QGraphicsRectItem>(i); QGraphicsPixmapItem* pixmapItem = NULL; uchar* colorPointer = _volumeDisplays[id].GetColorImageBuffer(i); QPixmap pixmap = QPixmap::fromImage(QImage(colorPointer, w, h, QImage::Format_ARGB32)); if (item == NULL) { item = new QGraphicsRectItem(QRect(0, 0, w, h)); item->setPen(Qt::NoPen); item->setBrush(Qt::NoBrush); item->setPos(colPos, rowPos); item->setData(SliceIndex, QVariant(i)); item->setData(AnnotationType, QVariant(SliceImage)); item->setData(RealSliceIndex, QVariant(realSliceIdx)); pixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(QImage(_volumeDisplays[id].GetColorImageBuffer(i), w, h, QImage::Format_ARGB32)), item); pixmapItem->setZValue(1); QGraphicsTextItem* text = new QGraphicsTextItem(QString("#%1.%2").arg(id).arg(realSliceIdx), item); text->setFont(sliceIndexFont); text->setPos(3, 3); text->setZValue(2); text->setDefaultTextColor(Qt::yellow); _volumeDisplays[id].SetSliceData(i, item); scene()->addItem(item); } else { QGraphicsPixmapItem* pixmapItem = (QGraphicsPixmapItem*) item->childItems()[0]; pixmapItem->setPixmap(pixmap); } if (_workingSet.contains(i)) { addWorkingSetItem(item); } } } } updatePixmaps(); }
void MainWindow::create_graphic() { ui->graphicsView->setRenderHint(QPainter::Antialiasing, true); /* int sizew=1536;//1400; int sizeh=668; int space=40; int const_for_ky=25.5; int const_for_kx=10.971;*/ int sizew=1036;//1400; int sizeh=536; int space=40; int const_for_ky=20.5; int const_for_kx=10.971; int shift_y=300; sc=new QGraphicsScene(0,0,sizew,sizeh,ui->graphicsView); QPen pen(QBrush(QColor(139,134,130),Qt::SolidPattern),4,Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin); pen.setColor(QColor(139,119,101)); sc->addLine(space,space,space,sizeh-space,pen); sc->addLine(space,sizeh-space,sizew-space,sizeh-space,pen); float ky=sizeh*const_for_ky;//18000; float kx=sizew/const_for_kx;//140; float x1,y1,x2,y2; //mu_lines int max_len=45; QMap<int,QString> mu_text; for(int i=0;i<periods.size();i++) { if(mu_text[periods[i].nod].length()>max_len) { if(mu_text[periods[i].nod][mu_text[periods[i].nod].length()-1]!='.') mu_text[periods[i].nod]+=" ..."; continue; } if(mu_text[periods[i].nod].length()==0) mu_text[periods[i].nod]+=periods[i].substr;//+QString().sprintf("(%d)",periods[i].indexes.size()); else mu_text[periods[i].nod]+="," + periods[i].substr;//+QString().sprintf("(%d)",periods[i].indexes.size()); } QMap<int,int> temp; for(int i=periods.size()-1;i>=0;i--) { if(temp[periods[i].nod]==0) { temp[periods[i].nod]=1; x1 = space + (periods[i].nod-1)*kx; y1 = (temp.size()+1)*space; x2 = space + (periods[i].nod-1)*kx; if(periods[i].nod-1<corr_table.size()) y2 = sizeh + shift_y - space - (float)(corr_table[periods[i].nod-1][1]*ky); else y2 = sizeh + shift_y - space - (float)(corr_table[corr_table.size()-1][1]*ky); QPen p(QColor(139,119,101,200),2,Qt::DotLine); if(i==mu) p.setColor(QColor(102,205,0)); int ind=(periods[i].nod>7)?(corr_table.size()-1):(periods[i].nod-1); if(icx>corr_table[ind][3] && icx<corr_table[ind][2]) p.setColor(QColor(102,205,0)); else { if(icx>corr_table[ind][1] && icx<corr_table[ind][3]) p.setColor(QColor(255,215,0)); else p.setColor(QColor(178,34,34)); } sc->addLine(x1,y1,x2,y2,p); sc->addLine(x1-space/4,y1+space/4,(x1-space/4)+30+(mu_text[periods[i].nod].length()*7),y1+space/4,p); QGraphicsTextItem *t; t=new QGraphicsTextItem(mu_text[periods[i].nod]); t->setDefaultTextColor(QColor(p.color().red()-30,p.color().green()-30,p.color().blue()));//(238,130,98)); t->setPos(x1,y1+space/4-22); sc->addItem(t); } } //icx x1=space; y1=sizeh + shift_y - space - (float)(icx*ky); x2=sizew-space; y2=sizeh + shift_y - space - (float)(icx*ky); sc->addLine(x1,y1,x2,y2,QPen(QColor(139,119,101,200),2,Qt::DashLine)); int per_lim; if(periods.size()!=0 && corr_table.size()<periods[0].nod) { per_lim=periods[0].nod-1; } else per_lim=corr_table.size()-1; //оси и точки и icmni sr max pen.setColor(QColor(205,175,149)); for(int j=1;j<corr_table[0].size();j++) { for(int i=0;i<per_lim;i++) { if(i>=corr_table.size()-1) { x1 = x2; y1 = y2; x2 = space + (i+1)*kx; y2 = y2; } else { x1 = space + (corr_table[i][0]-1)*kx; y1 = sizeh + shift_y - space - (float)(corr_table[i][j]*ky); x2 = space + (corr_table[i+1][0]-1)*kx; y2 = sizeh + shift_y - space - (float)(corr_table[i+1][j]*ky); } sc->addLine(x1,y1,x2,y2,QPen(QBrush(QColor(205,175,149),Qt::SolidPattern),4,Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin)); sc->addEllipse(x1-4,y1-4,8,8,QPen(QColor(139,119,101),2),QBrush(QColor(205,175,149))); sc->addLine(x2,sizeh-space-5,x2,sizeh-space+5,QPen(QBrush(QColor(139,134,130),Qt::SolidPattern),4,Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin)); QGraphicsTextItem *t; t=new QGraphicsTextItem(QString().sprintf("%d",i+2)); t->setDefaultTextColor(QColor(139,134,130)); t->setPos(x2-7,sizeh-space+3); sc->addItem(t); if(i==0) { sc->addEllipse(x1-5,sizeh-space-5,10,10,QPen(QColor(139,119,101),2),QBrush(QColor(139,134,130))); t=new QGraphicsTextItem(QString().sprintf("%d",i+1)); t->setDefaultTextColor(QColor(139,134,130)); t->setPos(x1-7,sizeh-space+3); sc->addItem(t); } } } sc->addEllipse(x2-4,y2-4,8,8,QPen(QColor(139,119,101),2),QBrush(QColor(205,175,149))); //подписи графиков for(int i=1;i<corr_table[0].size();i++) { x1=(corr_table[1][0]-1)*kx; y1 = sizeh + shift_y - space - (float)(corr_table[1][i]*ky); x2 = space + (corr_table[2][0]-1)*kx; y2 = sizeh + shift_y - space - (float)(corr_table[2][i]*ky); float xs,ys; xs=(x1+x2)/2; ys=(y1+y2)/2; QGraphicsTextItem *t; switch(i) { case 1: t=new QGraphicsTextItem("Ic(x)min"); t->setPos(xs-15,ys-55); t->setRotation(23); break; case 2: t=new QGraphicsTextItem("Ic(x)max"); t->setPos(xs+11,ys-70); t->setRotation(52); break; case 3: t=new QGraphicsTextItem("Ic(x)sr."); t->setPos(xs+11,ys-50); t->setRotation(34); break; } t->setDefaultTextColor(QColor(139,134,130)); t->setFont(QFont(t->font().family(),15,11,true)); sc->addItem(t); } QGraphicsTextItem *t; t=new QGraphicsTextItem("Ic(x)=" + QString().sprintf("%0.4f",icx)); t->setDefaultTextColor(QColor(139,134,130)); t->setFont(QFont(t->font().family(),15,11,true)); t->setPos(sizew-5*space,sizeh + shift_y - space - (icx*ky)-40); sc->addItem(t); t=new QGraphicsTextItem("μ"); t->setDefaultTextColor(QColor(139,134,130)); t->setFont(QFont(t->font().family(),15,11,true)); t->setPos(sizew-space-2,sizeh - space-2); sc->addItem(t); pen.setColor(QColor(139,119,101)); sc->addLine(sizew-space,sizeh - space,sizew-space-10,sizeh - space-8,pen); sc->addLine(sizew-space,sizeh - space,sizew-space-10,sizeh - space+8,pen); t=new QGraphicsTextItem("Ic(x)"); t->setDefaultTextColor(QColor(139,134,130)); t->setFont(QFont(t->font().family(),15,11,true)); t->setPos(space+2,space+2); sc->addItem(t); pen.setColor(QColor(139,119,101)); sc->addLine(space,space,space-8,space+10,pen); sc->addLine(space,space,space+8,space+10,pen); for(int i=1;i<corr_table[0].size();i++) { t=new QGraphicsTextItem(QString().sprintf("%0.3f",corr_table[0][i])); t->setDefaultTextColor(QColor(139,134,130)); t->setFont(QFont(t->font().family(),10,11,true)); t->setPos(space + (corr_table[0][0]-1)*kx-52,sizeh + shift_y - space - (float)(corr_table[0][i]*ky)+25); t->setRotation(-45); sc->addItem(t); } ui->graphicsView->setScene(sc); //ui->graphicsView->fitInView(0,0,sizew,sizeh); // ui->graphicsView->scale(10,-1); }
DDisplayscene::DDisplayscene() { setSceneRect(-150,-300,300,600); addLine(-100,-400,-100,400); //侧边栏显示界面 button_home2 = new DButton; button_home2->setPos(-130,-330 + 0*45); button_home2->setHoverEnableFlag(true); button_home2->boundImageToPress(pressIcon[13]); button_home2->boundImageToRelease(releaseIcon[13]); button_home2->boundImageToHover(hoverIcon[13]); button_home2->setBounds(-20,-20,40,40); //button_home2->connect(button_home2,SIGNAL(fireAction()),this,SLOT(home())); addItem(button_home2); button_account2 = new DButton; button_account2->setPos(-130,-330 + 1*45); button_account2->setHoverEnableFlag(true); button_account2->boundImageToPress(pressIcon[0]); button_account2->boundImageToRelease(releaseIcon[0]); button_account2->boundImageToHover(hoverIcon[0]); button_account2->setBounds(-20,-20,40,40); //button_account2->connect(button_account2,SIGNAL(fireAction()),this,SLOT(account())); addItem(button_account2); button_display2 = new DButton; button_display2->setPos(-130,-330 + 2*45); button_display2->setHoverEnableFlag(true); button_display2->boundImageToPress(pressIcon[1]); button_display2->boundImageToRelease(releaseIcon[1]); button_display2->boundImageToHover(hoverIcon[1]); button_display2->setBounds(-20,-20,40,40); //button_display2->connect(button_display2,SIGNAL(fireAction()),this,SLOT(display())); addItem(button_display2); button_default2 = new DButton; button_default2->setPos(-130,-330 + 3*45); button_default2->setHoverEnableFlag(true); button_default2->boundImageToPress(pressIcon[2]); button_default2->boundImageToRelease(releaseIcon[2]); button_default2->boundImageToHover(hoverIcon[2]); button_default2->setBounds(-20,-20,40,40); //button_default2->connect(button_default2,SIGNAL(fireAction()),this,SLOT(default1())); addItem(button_default2); button_personalization2 = new DButton; button_personalization2->setPos(-130,-330 + 4*45); button_personalization2->setHoverEnableFlag(true); button_personalization2->boundImageToPress(pressIcon[3]); button_personalization2->boundImageToRelease(releaseIcon[3]); button_personalization2->boundImageToHover(hoverIcon[3]); button_personalization2->setBounds(-20,-20,40,40); //button_personalization2->connect(button_personalization2,SIGNAL(fireAction()),this,SLOT(personalization())); addItem(button_personalization2); button_network2 = new DButton; button_network2->setPos(-130,-330 + 5*45); button_network2->setHoverEnableFlag(true); button_network2->boundImageToPress(pressIcon[4]); button_network2->boundImageToRelease(releaseIcon[4]); button_network2->boundImageToHover(hoverIcon[4]); button_network2->setBounds(-20,-20,40,40); //button_network2->connect(button_network2,SIGNAL(fireAction()),this,SLOT(network())); addItem(button_network2); button_sound2 = new DButton; button_sound2->setPos(-130,-330 + 6*45); button_sound2->setHoverEnableFlag(true); button_sound2->boundImageToPress(pressIcon[5]); button_sound2->boundImageToRelease(releaseIcon[5]); button_sound2->boundImageToHover(hoverIcon[5]); button_sound2->setBounds(-20,-20,40,40); //button_sound2->connect(button_sound2,SIGNAL(fireAction()),this,SLOT(sound())); addItem(button_sound2); button_date2 = new DButton; button_date2->setPos(-130,-330 + 7*45); button_date2->setHoverEnableFlag(true); button_date2->boundImageToPress(pressIcon[6]); button_date2->boundImageToRelease(releaseIcon[6]); button_date2->boundImageToHover(hoverIcon[6]); button_date2->setBounds(-20,-20,40,40); //button_date2->connect(button_date2,SIGNAL(fireAction()),this,SLOT(date())); addItem(button_date2); button_power2 = new DButton; button_power2->setPos(-130,-330 + 8*45); button_power2->setHoverEnableFlag(true); button_power2->boundImageToPress(pressIcon[7]); button_power2->boundImageToRelease(releaseIcon[7]); button_power2->boundImageToHover(hoverIcon[7]); button_power2->setBounds(-20,-20,40,40); //button_power2->connect(button_power2,SIGNAL(fireAction()),this,SLOT(power())); addItem(button_power2); button_mouse2 = new DButton; button_mouse2->setPos(-130,-330 + 9*45); button_mouse2->setHoverEnableFlag(true); button_mouse2->boundImageToPress(pressIcon[8]); button_mouse2->boundImageToRelease(releaseIcon[8]); button_mouse2->boundImageToHover(hoverIcon[8]); button_mouse2->setBounds(-20,-20,40,40); //button_mouse2->connect(button_mouse2,SIGNAL(fireAction()),this,SLOT(mouse())); addItem(button_mouse2); button_keyboard2 = new DButton; button_keyboard2->setPos(-130,-330 + 10*45); button_keyboard2->setHoverEnableFlag(true); button_keyboard2->boundImageToPress(pressIcon[9]); button_keyboard2->boundImageToRelease(releaseIcon[9]); button_keyboard2->boundImageToHover(hoverIcon[9]); button_keyboard2->setBounds(-20,-20,40,40); //button_keyboard2->connect(button_keyboard2,SIGNAL(fireAction()),this,SLOT(keyboard())); addItem(button_keyboard2); button_shortcuts2 = new DButton; button_shortcuts2->setPos(-130,-330 + 11*45); button_shortcuts2->setHoverEnableFlag(true); button_shortcuts2->boundImageToPress(pressIcon[10]); button_shortcuts2->boundImageToRelease(releaseIcon[10]); button_shortcuts2->boundImageToHover(hoverIcon[10]); button_shortcuts2->setBounds(-20,-20,40,40); //button_shortcuts2->connect(button_shortcuts2,SIGNAL(fireAction()),this,SLOT(shortcuts())); addItem(button_shortcuts2); button_menu2 = new DButton; button_menu2->setPos(-130,-330 + 12*45); button_menu2->setHoverEnableFlag(true); button_menu2->boundImageToPress(pressIcon[11]); button_menu2->boundImageToRelease(releaseIcon[11]); button_menu2->boundImageToHover(hoverIcon[11]); button_menu2->setBounds(-20,-20,40,40); //button_menu2->connect(button_menu2,SIGNAL(fireAction()),this,SLOT(menu())); addItem(button_menu2); button_system2 = new DButton; button_system2->setPos(-130,-330 + 13*45); button_system2->setHoverEnableFlag(true); button_system2->boundImageToPress(pressIcon[12]); button_system2->boundImageToRelease(releaseIcon[12]); button_system2->boundImageToHover(hoverIcon[12]); button_system2->setBounds(-20,-20,40,40); //button_system2->connect(button_system2,SIGNAL(fireAction()),this,SLOT(system())); addItem(button_system2); button_pow2 = new DButton; button_pow2->setPos(-130,-330 + 14*45); button_pow2->setHoverEnableFlag(true); button_pow2->boundImageToPress(pressIcon[14]); button_pow2->boundImageToRelease(releaseIcon[14]); button_pow2->boundImageToHover(hoverIcon[14]); button_pow2->setBounds(-20,-20,40,40); //button_pow2->connect(button_pow2,SIGNAL(fireAction()),this,SLOT(pow())); addItem(button_pow2); addLine(-100,-290,200,-290); QGraphicsTextItem* display = new QGraphicsTextItem("显示"); display->setPos(-90,-335); display->setDefaultTextColor(QColor(255,255,255)); QFont font_dis; font_dis.setPixelSize(14); display->setFont(font_dis); addItem(display); DRset * displayreset = new DRset; displayreset->setPos(100,-320); displayreset->setHoverEnableFlag(true); // displayreset->boundImageToPress(pressIcon[15]); displayreset->boundImageToRelease(pressIcon[15]); displayreset->boundImageToHover(pressIcon[15]); displayreset->setBounds(-30,-10,55,55); // displayreset->connect(displayreset,SIGNAL(fireAction()),this,SLOT(displayreset())); addItem(displayreset); }
void Graph2::on_pushButton_clicked() { char r=R; char v=(predict+65); for(int i=0;i<count2-1;i++) for(int j=0;j<count2-1;j++) repromatrix[i][j] = ' '; for(int i=0;i<count2-1;i++) for(int j=0;j<count2-1;j++) readjmatrix[i][j]=0; for(int i=0;i<count2;i++){ for(int j=0;j<count2;j++){ if(i<(r-65)&&j<(r-65)) readjmatrix[i][j]=adjmatrix[i][j]; if(i<(r-65)&&j>(r-65)) readjmatrix[i][j-1]=adjmatrix[i][j]; if(i>(r-65)&&j<(r-65)) readjmatrix[i-1][j]=adjmatrix[i][j]; if(i>(r-65)&&j>(r-65)) readjmatrix[i-1][j-1]=adjmatrix[i][j]; } } for(int i=0;i<count2;i++){ if(adjmatrix[i][r-65]==1&&v<r&&i<(r-65)&&i!=(v-65)){ readjmatrix[i][v-65]=1; readjmatrix[v-65][i]=1; } if(adjmatrix[i][r-65]==1&&v<r&&i>(r-65)&&i!=(v-65)){ readjmatrix[i-1][v-65]=1; readjmatrix[v-65][i-1]=1; } if(adjmatrix[i][r-65]==1&&v>r&&i<(r-65)&&i!=(v-65)){ readjmatrix[i][v-66]=1; readjmatrix[v-66][i]=1; } if(adjmatrix[i][r-65]==1&&v>r&&i>(r-65)&&i!=(v-65)){ readjmatrix[i-1][v-66]=1; readjmatrix[v-66][i-1]=1; } } for(int i=0;i<count2;i++){ for(int j=0;j<count2;j++){ if(i<(r-65)) repromatrix[i][j]=promatrix[i][j]; if(i>(r-65)) repromatrix[i-1][j]=promatrix[i][j]; } if(i==(v-65)&&i<(r-65)) repromatrix[i][1]=promatrix[r-65][1]; if(i==(v-65)&&i>(r-65)) repromatrix[i-1][1]=promatrix[r-65][1]; } for(int i=0;i<count2-1;i++){ int tmp=0; for(int j=0;j<count2-1;j++) if(readjmatrix[i][j]==1) tmp+=1; repromatrix[i][5]=tmp+48; } QGraphicsScene *scene = new QGraphicsScene; for(int i=0;i<count2;i++){ if(i<(r-65)){ scene->addEllipse((qCos(i*2*3.1415/(count2)))*(count2)*10, (qSin(i*2*3.1415/(count2)))*(count2)*10, (repromatrix[i][1]-48)*5, (repromatrix[i][1]-48)*5, QPen(Qt::cyan),QBrush(Qt::cyan)); QGraphicsTextItem *txtitem = new QGraphicsTextItem(QString(repromatrix[i][0])); txtitem->setPos((qCos(i*2*3.1415/(count2)))*(count2)*10-10,(qSin(i*2*3.1415/(count2)))*(count2)*10-10); txtitem->setDefaultTextColor(Qt::red); scene->addItem(txtitem); } if(i>(r-65)){ scene->addEllipse((qCos(i*2*3.1415/(count2)))*(count2)*10, (qSin(i*2*3.1415/(count2)))*(count2)*10, (repromatrix[i-1][1]-48)*5, (repromatrix[i-1][1]-48)*5, QPen(Qt::cyan),QBrush(Qt::cyan)); QGraphicsTextItem *txtitem = new QGraphicsTextItem(QString(repromatrix[i-1][0])); txtitem->setPos((qCos(i*2*3.1415/(count2)))*(count2)*10-10, (qSin(i*2*3.1415/(count2)))*(count2)*10-10); txtitem->setDefaultTextColor(Qt::red); scene->addItem(txtitem); } } for(int i=0;i<(count2-1);i++) for(int j=i;j<(count2-1);j++){ QGraphicsLineItem *lineitem=new QGraphicsLineItem; lineitem->setPen(QPen(Qt::blue)); if(readjmatrix[i][j]==1&&i<(r-65)&&j<(r-65)){ lineitem->setLine((qCos(i*2*3.1415/count2))*count2*10+(repromatrix[i][1]-48)*5/2, (qSin(i*2*3.1415/count2))*count2*10+(repromatrix[i][1]-48)*5/2, (qCos(j*2*3.1415/count2))*count2*10+(repromatrix[j][1]-48)*5/2, (qSin(j*2*3.1415/count2))*count2*10+(repromatrix[j][1]-48)*5/2); scene->addItem(lineitem); } if(readjmatrix[i][j]==1&&i<(r-65)&&j>=(r-65)){ lineitem->setLine((qCos(i*2*3.1415/(count2)))*(count2)*10+(repromatrix[i][1]-48)*5/2, (qSin(i*2*3.1415/(count2)))*(count2)*10+(repromatrix[i][1]-48)*5/2, (qCos((j+1)*2*3.1415/(count2)))*(count2)*10+(repromatrix[j][1]-48)*5/2, (qSin((j+1)*2*3.1415/(count2)))*(count2)*10+(repromatrix[j][1]-48)*5/2); scene->addItem(lineitem); } if(readjmatrix[i][j]==1&&i>=(r-65)){ lineitem->setLine((qCos((i+1)*2*3.1415/(count2)))*(count2)*10+(repromatrix[i][1]-48)*5/2, (qSin((i+1)*2*3.1415/(count2)))*(count2)*10+(repromatrix[i][1]-48)*5/2, (qCos((j+1)*2*3.1415/(count2)))*(count2)*10+(repromatrix[j][1]-48)*5/2, (qSin((j+1)*2*3.1415/(count2)))*(count2)*10+(repromatrix[j][1]-48)*5/2); scene->addItem(lineitem); } } ui->graphicsView->setScene(scene); ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); }