NodeStatInspector::NodeStatInspector(QWidget* parent) : QWidget(parent) { setWindowFlags(Qt::Tool); QGraphicsScene* scene = new QGraphicsScene(); scene->addEllipse(70,10,16,16,QPen(),QBrush(DrawingCursor::white)); scene->addEllipse(70,60,16,16,QPen(),QBrush(DrawingCursor::blue)); scene->addRect(32,100,12,12,QPen(),QBrush(DrawingCursor::red)); QPolygonF poly; poly << QPointF(78,100) << QPointF(78+8,100+8) << QPointF(78,100+16) << QPointF(78-8,100+8); scene->addPolygon(poly,QPen(),QBrush(DrawingCursor::green)); scene->addEllipse(110,100,16,16,QPen(),QBrush(DrawingCursor::white)); QPen pen; pen.setStyle(Qt::DotLine); pen.setWidth(0); scene->addLine(78,26,78,60,pen); scene->addLine(78,76,38,100,pen); scene->addLine(78,76,78,100,pen); scene->addLine(78,76,118,100,pen); scene->addLine(135,10,145,10); scene->addLine(145,10,145,110); scene->addLine(145,60,135,60); scene->addLine(145,110,135,110); nodeDepthLabel = scene->addText("0"); nodeDepthLabel->setPos(150,20); subtreeDepthLabel = scene->addText("0"); subtreeDepthLabel->setPos(150,75); choicesLabel = scene->addText("0"); choicesLabel->setPos(45,57); solvedLabel = scene->addText("0"); solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); failedLabel = scene->addText("0"); failedLabel->setPos(30,120); openLabel = scene->addText("0"); openLabel->setPos(110,120); QGraphicsView* view = new QGraphicsView(scene); view->setRenderHints(view->renderHints() | QPainter::Antialiasing); view->show(); scene->setBackgroundBrush(Qt::white); boxLayout = new QVBoxLayout(); boxLayout->setContentsMargins(0,0,0,0); boxLayout->addWidget(view); setLayout(boxLayout); setWindowTitle("Gist node statistics"); setAttribute(Qt::WA_QuitOnClose, false); setAttribute(Qt::WA_DeleteOnClose, false); }
void WheelUkrWord::draw() const { QGraphicsScene * scene = _view->scene(); int letterHeight = 30; qreal radius1 = 20, radius2 = radius1 + letterHeight, radius3 = 200, radius4 = radius3 + letterHeight; QPen pen; pen.setWidth(2); scene->addEllipse(-radius1,-radius1,2*radius1,2*radius1,pen); scene->addEllipse(-radius2,-radius2,2*radius2,2*radius2,pen); scene->addEllipse(-radius3,-radius3,2*radius3,2*radius3,pen); scene->addEllipse(-radius4,-radius4,2*radius4,2*radius4,pen); QVector<QPointF> surnamePoints; QVector<qreal> angles; for (uint i = 0; i < surnameLength(); ++i) { qreal phi = M_PI * (360 / surnameLength() * i) / 180; qreal x1 = radius1 * cos(phi), y1 = radius1 * sin(phi); qreal x2 = radius2 * cos(phi), y2 = radius2 * sin(phi); scene->addLine(x1,y1,x2,y2,pen); surnamePoints.push_back(QPointF(x2,y2)); // TODO: avoid additional computations (i.e. unnecessary conversion from radians to degrees angles.push_back(phi * 180 / M_PI); } surnamePoints.push_back(surnamePoints[0]); angles.push_back(360); QVector<QPointF> aphorismPoints; for (int i = 0; i < aphorism().length(); ++i) { qreal phi = M_PI * (360 / aphorism().length() * i) / 180; qreal x1 = radius3 * qCos(phi), y1 = radius3 * qSin(phi); qreal x2 = radius4 * qCos(phi), y2 = radius4 * qSin(phi); scene->addLine(x1,y1,x2,y2,pen); aphorismPoints.push_back(QPointF(x1,y1)); } aphorismPoints.push_back(aphorismPoints[0]); for (uint i = 0; i < surnameLength(); ++i) { qreal part = 0.5 * (angles[i] + angles[i+1]) / 360 * aphorism().length(); //part = qFloor(phi); int ipart = part; scene->addLine(surnamePoints[i].x(),surnamePoints[i].y(),aphorismPoints[ipart].x(),aphorismPoints[ipart].y(),pen); scene->addLine(surnamePoints[i+1].x(),surnamePoints[i+1].y(),aphorismPoints[ipart+1].x(),aphorismPoints[ipart+1].y(),pen); } }
void GraphicsView::init() { GraphicsArgument &argument = GraphicsArgument::argument(); // ³õʼ»¯ÏÔʾÆ÷´óС qreal sw = this->width() - 40; qreal sh = this->width() - 40; argument.setScreenRect(sw, sh); // ³õʼ»¯ÊÓͼ·¶Î§ qreal vw = argument.getViewWidth(); qreal vh = vw * sw /sh; argument.setViewRect(vw, vh); qreal wr = argument.getWarringRadius(); QGraphicsScene *scene = this->scene(); scene->setSceneRect(-sw/2, -sh/2, sw, sh); menu->setPos(sw/2-100, -(sh/2-23)); compass->setPos(-(sw/2-23), -(sh/2-23)); //»æÖÆÊÓͼ·¶Î§¾ØÐοò if (viewRect != NULL) delete viewRect; viewRect = scene->addRect(-sw/2, -sh/2, sw, sh); viewRect->setZValue(100); //»æÖƾ¯¸æ·¶Î§ if (warringLine != NULL) delete warringLine; qreal r = wr * sw / vw; warringLine = scene->addEllipse(-r, -r, 2*r, 2*r, QPen(QBrush(Qt::red), 3)); warringLine->setZValue(100); }
GSequenceView::GSequenceView(QWidget *parent) : QAbstractItemView(parent), m_GraphicsView(this) { m_GraphicsView.resize(size()); m_GraphicsView.setBackgroundBrush(Qt::yellow); m_GraphicsView.setAlignment(Qt::AlignLeft); QGraphicsScene* pscccc = new QGraphicsScene(this); m_GraphicsView.setScene(pscccc); QGraphicsItem* pell = pscccc->addEllipse(200, 100, 60, 40); pscccc->addRect(pell->boundingRect()); }
void City::draw(QGraphicsScene &scene) { qDebug().noquote().nospace() << "Drawing city: " + name + " at (" << x << ", " << y << ")"; // circle scene.addEllipse(x - 4, y - 4, 8, 8, QPen(Qt::black), QBrush(Qt::red, Qt::SolidPattern)); QGraphicsTextItem *text = new QGraphicsTextItem; text->setPos(x - 4, y - 8); text->setPlainText(name); scene.addItem(text); }
SEXP scene_addPoints(SEXP scene, SEXP x, SEXP y, SEXP radius) { QGraphicsScene* s = unwrapQObject(scene, QGraphicsScene); int i, n = length(x); for (i = 0; i < n; i++) { // QGraphicsEllipseItem *item = s->addEllipse(REAL(x)[i], REAL(y)[i], REAL(radius)[0], REAL(radius)[0]); QGraphicsEllipseItem *item = s->addEllipse(0.0, 0.0, REAL(radius)[0], REAL(radius)[0]); item->setPos(REAL(x)[i], REAL(y)[i]); item->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIgnoresTransformations); } return R_NilValue; }
QGraphicViewDm::QGraphicViewDm(QWidget *parent) : QGraphicsView(parent) { int iWidth , iHeight ; // iWidth = width( ); // iHeight = height( ); iWidth = 600 ; iHeight = 230 ; QGraphicsScene *scene = new QGraphicsScene(this); scene->setSceneRect(-iWidth/2,-iHeight/2,iWidth,iHeight); setScene(scene); setCacheMode(CacheBackground); //加一个矩形 QRectF r = QRectF(-iWidth/2,-iHeight/2,iWidth,iHeight); // qDebug( ) << r.topLeft() << r.bottomRight() ; QRectF r1 = r.adjusted( 20, 20, -20, -20 ); // qDebug( ) << r1.topLeft() << r1.bottomRight() ; QGraphicsRectItem * pRect = scene->addRect( r1 ); //创建用的是对象座标 pRect->setPos( 0, 0 ); //给的是场景座标 pItemDm = new ItemDm ; // 4/5 的宽度 2/3的高度 float fAdjust1, fAdjust2 ; fAdjust1 = 1.0 / 10.0 * iWidth ; fAdjust2 = 1.0 / 6.0 * iHeight ; // qDebug( ) << fAdjust1 << fAdjust2 << r.adjusted( fAdjust1 , fAdjust2, -1*fAdjust1, -1*fAdjust2 ) ; pItemDm->init( r.adjusted( fAdjust1 , fAdjust2, -1*fAdjust1, -1*fAdjust2 ) ); pItemDm->setWater( 1250.00 ); scene->addItem( pItemDm ); pItemDm->setPos( 0, 0 ); //制作 QRectF rectFish( 0, 0, 15, 5 ); pFish = scene->addEllipse( rectFish ); pFish->setPos( 0, 0 ); //pFish->setBrush( QBrush(Qt::red) ); pFish->setBrush( QBrush(Qt::green) ); }
cwTabletGraphicsView::cwTabletGraphicsView(QWidget *parent) : QGraphicsView(parent), SketchModel(new cwSketchModel(this)), SketchView(new cwSketchView(this)) { QGraphicsScene* scene = new QGraphicsScene(this); scene->addEllipse(QRect(QPoint(0, 0), QSize(10, 10))); setScene(scene); SketchView->setScene(scene); SketchView->setSketchModel(SketchModel); setRenderHints(QPainter::Antialiasing); QImage cursorImage(":/images/cursor.png"); QCursor cursor(QPixmap::fromImage(cursorImage)); setCursor(cursor); }
int test_1_shape_ ( Main_Form *b ) { QTextStream std_out ( stdout ); QTextStream std_in ( stdin ); QTransform transform ( 1, 0, 0, 0, -1, 0, 0, 0, 1 ); transform.scale ( 0.5, 0.5 ); QGraphicsView* grView = b->graphicsView; grView->setAlignment ( 0 ); //Qt::AlignLeft | Qt::AlignTop grView->setTransform ( transform ); QGraphicsScene *grScene = new QGraphicsScene; grView->setScene ( grScene ); grView->setTransform ( transform ); grView->setRenderHints ( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing ); int i = 1000; forma_l * a = new forma_l; forma *form = a->get_m_forma(); QList<shapes*>* sh_list = form->get_m_shapes(); sh_list->clear(); shape_e* she_0 = new shape_e(); sh_list->append ( she_0 ); shape_7* sh7_0 = new shape_7 ( 450 ); sh_list->append ( sh7_0 ); shape_56* sh56_0 = new shape_56 ( true ); sh_list->append ( sh56_0 ); shape_b* shb_0 = new shape_b ( 220, -30, -120, -1 ); sh_list->append ( shb_0 ); shape_* sh_0 = new shape_; sh_0->set_length ( 14 ); sh_0->set_sixtant ( 0 ); sh_list->append ( sh_0 ); shape_34* sh34_0 = new shape_34; sh34_0->set_scale_up ( true ); sh34_0->set_scale_factor ( 4 ); sh_list->append ( sh34_0 ); shape_12* sh12_0 = new shape_12 ( false ); sh_list->append ( sh12_0 ); shape_* sh_1 = new shape_; sh_1->set_length ( 14 ); sh_1->set_sixtant ( 4 ); sh_list->append ( sh_1 ); shape_12* sh12_1 = new shape_12 ( true ); sh_list->append ( sh12_1 ); shape_89* sh89_0 = new shape_89; sh89_0->set_xy ( 0, 20, 20 ); sh89_0->append ( -20, 20 ); sh89_0->append ( -20, -20 ); sh89_0->append ( 20, -20 ); sh_list->append ( sh89_0 ); shape_56* sh56_1 = new shape_56 ( false ); sh_list->append ( sh56_1 ); shape_a* sha_0 = new shape_a; sha_0->set_radius ( 120 ); sha_0->set_start ( 0 ); sha_0->set_number ( -1 ); sh_list->append ( sha_0 ); shape_cd* shcd_0 = new shape_cd; shcd_0->set_xy_c ( 0, 20, 20, 127 ); shcd_0->append ( -20, 20, 127 ); shcd_0->append ( -20, -20, 127 ); shcd_0->append ( 20, -20, 127 ); sh_list->append ( shcd_0 ); draw_vars dr; stack st; a->draw ( dr, st, *grScene ); { draw_point p_center ( 0.0, 0.0 ); draw_point p_radius ( 3.5, 3.5 ); grScene->addEllipse ( p_center.x - p_radius.x / 2., p_center.y - p_radius.y / 2., p_radius.x, p_radius.y, QPen ( Qt::red ) ); } std_out << a->out() << endl; forma_l *bb = new forma_l; *bb = *a; std_out << endl; std_out << endl; std_out << bb->out() << endl; delete bb; }
//----------------------------------------------------------------------------------------- // New version, site/cell size is fixed, the blob grows //----------------------------------------------------------------------------------------- void Field::displayField(int hr, int *res) { QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, CANVAS_WIDTH, CANVAS_WIDTH)); QBrush brush; int i, xindex, yindex, ix, iy, w, rgbcol[3]; double xp, yp, d0, d, volume, scale, cmin, cmax, rmax; double a, b, Wc; int Nc; bool growthRate; // LOG_MSG("displayField"); *res = 0; hour = hr; if (slice_changed) { get_fieldinfo(&NX, &axis, &fraction, &nsites, &nconst, const_used, res); if (*res != 0) return; this->data = (FIELD_DATA *)malloc(nsites*sizeof(FIELD_DATA)); get_fielddata(&axis, &fraction, &nsites, &nconst, this->data, res); if (*res != 0) return; slice_changed = false; } if (constituent == GROWTH_RATE) growthRate = true; else growthRate = false; if (axis == X_AXIS) { // Y-Z plane xindex = 1; yindex = 2; } else if (axis == Y_AXIS) { // X-Z plane xindex = 0; yindex = 2; } else if (axis == Z_AXIS) { // X-Y plane xindex = 0; yindex = 1; } /* NX = size of lattice Nc = # of sites to fill the canvas from side to side (or top to bottom) = (2/3)NX Wc = canvas width (pixels) w = site width = Wc/Nc xp = a.ix + b yp = a.iy + b blob centre at (NX/2,NX/2) maps to canvas centre at (Wc/2,Wc/2) => Wc/2 = a.NX/2 + b The width of Nc sites maps to the canvas width => Wc = a.Nc => a = Wc/Nc, b = Wc/2 - a.NX/2 */ Nc = (2*NX)/3; Wc = CANVAS_WIDTH; w = Wc/Nc; a = w; b = Wc/2 - a*NX/2; d0 = w*dfraction; cmin = 1.0e10; cmax = 0; rmax = 0; for (i=0; i<nsites; i++) { rmax = MAX(rmax,data[i].dVdt); cmin = MIN(MAX(cmin,0),data[i].conc[constituent]); cmax = MAX(cmax,data[i].conc[constituent]); } brush.setStyle(Qt::SolidPattern); brush.setColor(QColor(0,0,0)); scene->addRect(0,0,CANVAS_WIDTH,CANVAS_WIDTH,Qt::NoPen, brush); view->setScene(scene); view->setGeometry(QRect(0, 0, 700, 700)); if (cmax == 0) { view->show(); return; } for (i=0; i<nsites; i++) { ix = this->data[i].site[xindex]; iy = this->data[i].site[yindex]; xp = int(a*ix + b - w); yp = int(a*iy + b - w); chooseFieldColor(data[i].conc[constituent],cmin,cmax,use_log,rgbcol); brush.setColor(QColor(rgbcol[0],rgbcol[1],rgbcol[2])); scene->addRect(xp,yp,w,w,Qt::NoPen, brush); } for (i=0; i<nsites; i++) { ix = this->data[i].site[xindex]; iy = this->data[i].site[yindex]; xp = int(a*ix + b - w); yp = int(a*iy + b - w); volume = this->data[i].volume; // = 0 if there is no cell if (volume > 0) { scale = pow(volume,0.3333); d = scale*d0; // fix this - need to change d0 double f; if (rmax > 0) { f = data[i].dVdt/rmax; } else { f = 0.01; } chooseRateColor(f,rgbcol); brush.setColor(QColor(rgbcol[0],rgbcol[1],rgbcol[2])); scene->addEllipse(xp+(w-d)/2,yp+(w-d)/2,d,d,Qt::NoPen, brush); } } view->show(); if (save_images) { scene->clearSelection(); // Selections would also render to the file scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene image.fill(Qt::transparent); // Start all pixels transparent QPainter painter(&image); scene->render(&painter); ifield++; char filename[] = "image/field0000.png"; char numstr[5]; sprintf(numstr,"%04d",hour); for (int i=0; i<4; i++) filename[11+i] = numstr[i]; image.save(filename); } }
//-------------------------------------------------------------------------------------------- void MReadiness::Init() { //===#### I: Left (Ekranoplan): ####=== QGraphicsScene* PSceneEkranoplan = new QGraphicsScene(this);//PMainSplitter); // scene.addText("Hello, world!"); PSceneEkranoplan->addPixmap(QPixmap(":/Ekranoplan.png")); //scene.setSceneRect(0,0, 100,100); QGraphicsView* PViewEkranoplan = new QGraphicsView(PSceneEkranoplan, this); //view.setBaseSize(200,500); // PMainSplitter->addWidget(PViewEkranoplan); //++ addWidget(PViewEkranoplan); //int ind = psplitter->indexOf(&view); //QString s; s.sprintf("ind = %d", ind); //QMessageBox msgBox; msgBox.setText(s); msgBox.exec(); //psplitter->handle(0)->setFixedWidth(100); //psplitter->handle(0)->setMaximumWidth(100); //psplitter->setHandleWidth(50); //psplitter->resize(1200,500); // InitReadiness(this, pSplitter); // scene.addEllipse(QRectF(180,360, 40,40),QPen(),QBrush(QColor(255,0,0,255))); int xc = 200; int yc = 380; int rc = 25; QRadialGradient radialGradTestSpot(QPointF(xc, yc), rc); // radialGradTestSpot.setColorAt(0, Qt::red); radialGradTestSpot.setColorAt(0, QColor(255, 0, 0, 155)); // 255 // radialGrad.setColorAt(0.5, Qt::blue); // radialGradTestSpot.setColorAt(1, Qt::green); radialGradTestSpot.setColorAt(1, QColor(0, 255, 0, 155)); //radialGradTestSpot.setColorAt(0, QColor(20, 255, 180, 255)); // 255 //radialGradTestSpot.setColorAt(0.6, QColor(180, 255, 180, 155)); // 255 //radialGradTestSpot.setColorAt(1, QColor(220, 0, 0, 100)); // 255 QGraphicsEllipseItem* PTestSpot = PSceneEkranoplan->addEllipse(QRectF(xc-rc,yc-rc, 2*rc,2*rc),QPen(Qt::NoPen),QBrush(radialGradTestSpot)); //===#### II: 1) Right (Channels): ####=== QSplitter* pSplitterReadiness = new QSplitter(Qt::Vertical, this);//pSplitter); //++ addWidget(pSplitterReadiness); QList<int> list; list << 150 << 200; setSizes(list); list.clear(); //=== 1) ReadinessTest: // scrollArea = new QScrollArea(centralWidget); QScrollArea* pScrollAreaTest = new QScrollArea(pSplitterReadiness);//this); // pScrollAreaTest->setObjectName(QStringLiteral("ScrollAreaTest")); //+ pScrollAreaTest->setGeometry(QRect(40, 70, 611, 111)); pScrollAreaTest->setWidgetResizable(true); //pScrollAreaTest->setBaseSize(30,40); //addWidget(pScrollAreaTest); QWidget* pScrollAreaTestContents = new QWidget(pSplitterReadiness);//this); pScrollAreaTestContents->setObjectName(QStringLiteral("ScrollAreaTestContents")); //+ pScrollAreaTestContents->setGeometry(QRect(0, 0, 609, 109)); //pScrollAreaTestContents->setBaseSize(30,40); // pScrollAreaTestContents->setMinimumSize(609,109); //pScrollAreaTest->setWidget(pScrollAreaTestContents); //pScrollAreaTestContents->setParent(pScrollAreaTest); // pScrollAreaTestContents->setMinimumSize(609,109); QRect rect = FillReadinessTest(pScrollAreaTestContents); pScrollAreaTestContents->setMinimumSize(rect.right()+3,rect.bottom()+3); //pScrollAreaTest->adjustSize(); //pScrollAreaTest->setMinimumWidth(100); //pScrollAreaTest->setMaximumWidth(200); //pScrollAreaTestContents->setMinimumWidth(600); //pScrollAreaTestContents->setMaximumWidth(200); pScrollAreaTest->setWidget(pScrollAreaTestContents); //=== 2) ReadinessStart: QScrollArea* pScrollAreaStart = new QScrollArea(pSplitterReadiness);//this); // pScrollAreaStart->setObjectName(QStringLiteral("ScrollAreaStart")); pScrollAreaStart->setGeometry(QRect(40, 70, 611, 111)); pScrollAreaStart->setWidgetResizable(true); //addWidget(pScrollAreaStart); QWidget* pScrollAreaStartContents = new QWidget(pSplitterReadiness);//this); // pScrollAreaStartContents->setObjectName(QStringLiteral("ScrollAreaStartContents")); // pScrollAreaStartContents->setGeometry(QRect(0, 0, 609, 109)); // pScrollAreaStartContents->setMinimumSize(609,109); rect = FillReadinessStart(pScrollAreaStartContents); pScrollAreaStartContents->setMinimumSize(rect.right()+3,rect.bottom()+3); pScrollAreaStart->setWidget(pScrollAreaStartContents); //=== // pSplitterReadiness->addWidget(pScrollAreaTest); // pSplitterReadiness->addWidget(pScrollAreaStart); // list << 700 << 200; pSplitterReadiness->setSizes(list); //++ pSplitterReadiness->addWidget(pScrollAreaTest); //++ pSplitterReadiness->addWidget(pScrollAreaStart); list << 800 << 200; pSplitterReadiness->setSizes(list); list.clear(); //pScrollAreaTest->setWidget(listview); //pScrollAreaTest->setWidget(treeview); //pScrollAreaTest->setWidget(textedit); // MTestChannel* pTestCannel = new MTestChannel; //================= //================= /* // QSerialPort* pSerialPort = new QSerialPort(this); QString sp; foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { sp += QObject::tr("Port: ") + info.portName() + "\n" + QObject::tr("Location: ") + info.systemLocation() + "\n" + QObject::tr("Description: ") + info.description() + "\n" + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n" + QObject::tr("Vendor Identifier: ") + (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) + "\n" + QObject::tr("Product Identifier: ") + (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()) + "\n" + QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) + "\n"; } QMessageBox msgBox; msgBox.setText(sp); msgBox.exec(); */ /*++++ //================= // QSerialPort* pSerialPort = new QSerialPort(this); // QString sp; QSlider* pSlider = new QSlider(pScrollAreaTest); //pSlider->setObjectName(QStringLiteral("verticalSlider")); pSlider->setOrientation(Qt::Vertical); pSlider->setGeometry(QRect(600, 120, 16, 160)); pSlider->setMinimum(0); pSlider->setMaximum(255); pSlider->setSingleStep(1); pSlider->setPageStep(25); pSlider->setValue(0); pSlider->setTickPosition(QSlider::TicksAbove); QString portName("COM3"); PPort = new QSerialPort(this); PPort->setPortName(portName); if(PPort->open(QIODevice::WriteOnly)) { PPort->setBaudRate(QSerialPort::Baud9600); PPort->setDataBits(QSerialPort::Data8); PPort->setParity(QSerialPort::NoParity); PPort->setStopBits(QSerialPort::OneStop); PPort->setFlowControl(QSerialPort::NoFlowControl); QMessageBox msgBox; msgBox.setText("Port \""+portName+"\" is open"); msgBox.exec(); } else { QMessageBox msgBox; msgBox.setText("Port \""+portName+"\" is not open"); msgBox.exec(); } connect(pSlider, SIGNAL(valueChanged(int)), this, SLOT(SlotArduino_ControlLED(int))); connect(PPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(SlotPortError(QSerialPort::SerialPortError))); //================= */ }
//----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- void MyVTK::key_canvas(QWidget *key_page) { // QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, 130, 280)); QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, 130, 310)); QBrush brush; QGraphicsTextItem *text; // brush.setColor(QColor(255,128,77)); brush.setColor(QColor(150,100,0)); // dark brown brush.setStyle(Qt::SolidPattern); scene->addEllipse(10,10,20,20,Qt::NoPen, brush); text = scene->addText("FDC"); text->setPos(35, 10); // brush.setColor(QColor(255,77,128)); brush.setColor(QColor(200,60,100)); // dark red brush.setStyle(Qt::SolidPattern); scene->addEllipse(10,40,20,20,Qt::NoPen, brush); text = scene->addText("MRC"); text->setPos(35, 40); brush.setColor(QColor(30,20,255)); // dark blue scene->addEllipse(10,70,20,20,Qt::NoPen, brush); text = scene->addText("Naive B cell"); text->setPos(35, 70); brush.setColor(QColor(0,200,255)); // light blue scene->addEllipse(10,100,20,20,Qt::NoPen, brush); text = scene->addText("CCR7 UP"); text->setPos(35, 100); brush.setColor(QColor(50,255,150)); // light green scene->addEllipse(10,130,20,20,Qt::NoPen, brush); text = scene->addText("EBI2 UP"); text->setPos(35, 130); // brush.setColor(QColor(255,255,0)); // yellow brush.setColor(Qt::yellow ); // yellow scene->addEllipse(10,160,20,20,Qt::NoPen, brush); text = scene->addText("BCL6 HI"); text->setPos(35, 160); brush.setColor(QColor(0,150,0)); // dark green scene->addEllipse(10,190,20,20,Qt::NoPen, brush); text = scene->addText("BCL6 LO"); text->setPos(35, 190); brush.setColor(QColor(128,128,128)); // grey scene->addEllipse(10,220,20,20,Qt::NoPen, brush); text = scene->addText("Max divisions"); text->setPos(35, 220); brush.setColor(QColor(255,0,0)); // red scene->addEllipse(10,250,20,20,Qt::NoPen, brush); text = scene->addText("Plasma cell"); text->setPos(35, 250); brush.setColor(QColor(255,130,0)); // orange scene->addEllipse(10,280,20,20,Qt::NoPen, brush); text = scene->addText("CD4 T cell"); text->setPos(35, 280); QGraphicsView* view = new QGraphicsView(key_page); view->setScene(scene); // view->setGeometry(QRect(0, 0, 150, 300)); view->setGeometry(QRect(0, 0, 150, 330)); view->show(); }
void skeletonVisualization::updateImage() { if (ready) { QGraphicsScene *newScene = new QGraphicsScene; // draw image if (drawImage) { QPixmap newPixmap = QPixmap::fromImage(image); if (scale != 1) newPixmap = newPixmap.scaled(newPixmap.size() * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation); newScene->addPixmap(newPixmap); } // draw image if (drawContours) { QPen pen(Qt::blue, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); for (uint i = 0; i < skeleton.contours.size(); i++) { for (uint j = 0; j < skeleton.contours[i].corners.size() - 1; j++) newScene->addLine( scale * skeleton.contours[i].corners[j].x, scale * skeleton.contours[i].corners[j].y, scale * skeleton.contours[i].corners[j + 1].x, scale * skeleton.contours[i].corners[j + 1].y, pen); newScene->addLine( scale * skeleton.contours[i].corners[0].x, scale * skeleton.contours[i].corners[0].y, scale * skeleton.contours[i].corners [skeleton.contours[i].corners.size() - 1].x, scale * skeleton.contours[i].corners [skeleton.contours[i].corners.size() - 1].y, pen); } } // draw skeleton (bones & circles) for (uint i = 0; i < skeleton.components.size(); i++) { // draw bones if (drawBones) { QPen pen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); for (uint j = 0; j < skeleton.components[i].bones.size(); j++) newScene->addLine( scale * skeleton.components[i].nodes [skeleton.components[i].bones[j].i].x + 1, scale * skeleton.components[i].nodes [skeleton.components[i].bones[j].i].y + 1, scale * skeleton.components[i].nodes [skeleton.components[i].bones[j].j].x + 1, scale * skeleton.components[i].nodes [skeleton.components[i].bones[j].j].y + 1, pen); } // draw circles if (drawCircles) { QPen pen(Qt::green, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); for (uint j = 0; j < skeleton.components[i].nodes.size(); j++) newScene->addEllipse(scale * (skeleton.components[i].nodes[j].x + 1 - skeleton.components[i]. nodes[j].r), scale * (skeleton.components[i].nodes[j].y + 1 - skeleton.components[i]. nodes[j].r), 2*scale*skeleton.components[i].nodes[j].r, 2*scale*skeleton.components[i].nodes[j].r, pen); } } ui.imageView->setScene(newScene); if (scene) delete scene; scene = newScene; } }
FenPrincipale::FenPrincipale() { // setFixedSize(1200,800); // Dimensions fixées à 850x480px QGridLayout *layout0 = new QGridLayout; // c le layout de base de la page1 QGraphicsScene *scene = new QGraphicsScene; QGraphicsView *vue = new QGraphicsView(scene,this); scene->setSceneRect(0,0,mapLargeur+50,mapHauteur+50); // taille de la scene vue->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); vue->setFixedSize(mapLargeur+100,mapHauteur+100); //taille de la vue //Mise en place de la map QPixmap map_im ; map_im.load("map.png"); map=scene->addPixmap(map_im); map->setPos(0,0); map->setZValue(-1); //Rectangle test_debug QRect rectangle1(15,15,618,418); scene->addRect(rectangle1); //rectangle1.moveCenter(QPoint(0,0)); // met le centre au centre //Création de l'origine QRect rectangle(0,0,10,10); rectangle.moveCenter(QPoint(0,0)); // met le centre au centre origine=scene->addRect(rectangle); origine->setPos(map_im.width()/2,map_im.height()/2);// au centre de l'image //Mise en place de du robot QPixmap robot_im ; robot_im.load("petit_robot.png"); robot=scene->addPixmap(robot_im); robot->setZValue(2);// au dessus de l'image carte 2>-1 robot->setOffset(-robot_im.width()/2,-robot_im.height()/2); // origine du robot au centre robot->setPos(origine->x(),origine->y());//placer au centre du palteau //Mise en place de l'obstacle QPen pen(Qt::black, 1, Qt::SolidLine); QBrush brush(Qt::black); //scene.addRect(rectangle, pen, brush); obstacle = scene->addEllipse(0,0,15,15,pen,brush); obstacle->setZValue(1); obstacle->setPos(origine->x(),origine->y()); obstacle2 = scene->addEllipse(0,0,15,15,pen,brush); obstacle2->setZValue(1); obstacle2->setPos(origine->x(),origine->y()); //Ajout au layout principale puis à la fenetre layout0->addWidget(vue, 0,0); setLayout(layout0); //Configuration du Timer pas utiliser (debug) timer = new QTimer(this); // timer->start(1000); //Connection des Signaux/Solts connect( timer, SIGNAL(timeout()), this, SLOT(timerOut()) ); //Pacement par defaut //modifPosition(robot,-750,-1250,90); modifPosition(robot,-750,0,0); testPosObs(obstacle,100,90); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QList<double> listX; QList<double> listY; // listX << 0.45689999999999997 // << 1.4893000000000001 // << 2.7387999999999999 // << 3.8527999999999998 // << 5.0213000000000001 // << 6.1910999999999996 // << 7.3179999999999996 // << 8.5601000000000003 // << 9.8018000000000001 // << 11.041600000000001 // << 12.426399999999999 // << 13.5808 // << 14.8553; // listY << 1203.3999999999999 // << 1084.4000000000001 // << 1135.3 // << 1201.8 // << 1139.4000000000001 // << 1140.6999999999998 // << 1183.5000000000005 // << 1211.7000000000005 // << 1306.799999999999 // << 1230.8000000000004 // << 1146.3999999999999 // << 1239.4999999999995 // << 1348.9000000000005; for(int i = 0; i < 20; i++) { listX.append(i*10); listY.append(rand()%500); } QGraphicsScene* scene = new QGraphicsScene; ui->graphicsView->setScene(scene); ui->graphicsView->setRenderHint(QPainter::Antialiasing); double x, y; for(int i = 0; i < listX.size(); i++) { x = listX.at(i); y = listY.at(i); scene->addEllipse(x, y, 3, 3, QPen(Qt::black), QBrush(Qt::black)); } double appK = approxKoef(&listX, &listY); double appAddK = approxAddKoef(&listX, &listY); int f = 0; ui->label->setText(QString::number(appK)); ui->label_2->setText(QString::number(appAddK)); double n = 0; scene->addLine(listX.first(), appK*listX.at(0) + appAddK, listX.last(),appK*listX.last() + appAddK); scene->addEllipse(0,0,10,10, QPen(Qt::red), QBrush(Qt::red)); }
// refresh ui elements // void BSplineVisDialog::renderScene(QGraphicsScene& scene, bool isPrinter) { scene.clear(); if (ui.showCheckerboard->isChecked()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_SrcImage, ui.imageOpacity->value()); QPixmap qPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qPixmap)->setZValue(-10); } if (ui.showWarpedCheckerboard->isChecked()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_DstImage, ui.imageOpacity->value()); QPixmap qPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qPixmap)->setZValue(-10); } if (ui.showWarpedSlice->isChecked()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_WarpedSlice, ui.imageOpacity->value()); QPixmap qPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qPixmap)->setZValue(-10); } if (m_RefImage.IsNotNull()) { const int gridRes = ui.gridResolution->value(); QPen blackPen = QPen(QColor::fromRgbF(0,0,0,0.5)); blackPen.setWidthF(.1); QPen linePen(QColor::fromRgbF(.5,.5,.5,ui.imageOpacity->value() / 255.0)); if (ui.showCoordinateGrid->isChecked()) { QGraphicsGridItem* originalGrid = new QGraphicsGridItem(); if (isPrinter) { // can printer have alpha value? originalGrid->SetPen(blackPen); } else { originalGrid->SetPen(linePen); } originalGrid->SetResolution(gridRes); originalGrid->SetGrid(gX, gY); scene.addItem(originalGrid); ui.bspView->fitInView(originalGrid, Qt::KeepAspectRatio); } if (ui.showWarpedCoordinateGrid->isChecked()) { QGraphicsGridItem* warpedGrid = new QGraphicsGridItem(); if (isPrinter) { // can printer have alpha value? if (!ui.showNoImage->isChecked()) { blackPen.setColor(QColor::fromRgbF(1, 1, 0)); blackPen.setWidthF(0.2); } warpedGrid->SetPen(blackPen); } else { warpedGrid->SetPen(linePen); } warpedGrid->SetResolution(gridRes); warpedGrid->SetGrid(tX, tY); scene.addItem(warpedGrid); ui.bspView->fitInView(warpedGrid, Qt::KeepAspectRatio); } } if (ui.showDetJacobian->isChecked() && m_DetJacobian.IsNotNull()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_DetJacobian); QPixmap qDetPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qDetPixmap); } if (m_Field.IsNotNull() && ui.showDisplacementField->isChecked()) { FieldIteratorType iter(m_Field, m_Field->GetBufferedRegion()); for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter) { DisplacementFieldType::IndexType idx = iter.GetIndex(); DisplacementFieldType::PointType point; m_Field->TransformIndexToPhysicalPoint(idx, point); VectorType v = iter.Get(); if (v.GetNorm() < 1) { continue; } DisplacementFieldType::PointType point2; point2[0] = point[0] + v[0]; point2[1] = point[1] + v[1]; scene.addLine(point[0], point[1], point2[0], point2[1], QPen(Qt::yellow)); } } if (ui.showWarpedLandmarks->isChecked()) { double sz = ui.landmarkSize->value(); for (int i = 0; i < m_WarpedLandmarks.rows(); i++) { double x = m_WarpedLandmarks[i][0]; double y = m_WarpedLandmarks[i][1]; QGraphicsItem* p = scene.addRect(x - sz, y - sz, sz*2, sz*2, QPen(Qt::yellow), QBrush(Qt::yellow, Qt::SolidPattern)); } } // drawing order is important for correct pick up // only show when showLandmarks is checked // if (ui.showLandmarks->isChecked()) { double sz = ui.landmarkSize->value(); for (int i = 0; i < m_VectorList.size(); i++) { QRectF& xy = m_VectorList[i]; QPen linePen(Qt::yellow); QPen sourcePen(Qt::red); QBrush sourceBrush(Qt::red, Qt::SolidPattern); QPen targetPen(Qt::blue); QBrush targetBrush(Qt::blue, Qt::SolidPattern); linePen.setWidthF(sz * .5); if (isPrinter) { linePen.setWidthF(sz); linePen.setColor(QColor::fromRgbF(0.3, 0.6, 0.3)); } scene.addLine(xy.left(), xy.top(), xy.right(), xy.bottom(), linePen); QGraphicsItem* dx = scene.addEllipse(xy.left() - sz, xy.top() - sz, sz*2, sz*2, sourcePen, sourceBrush); QGraphicsItem* dy = scene.addEllipse(xy.right() - sz, xy.bottom() - sz, sz*2, sz*2, targetPen, targetBrush); dx->setData(1, i); dy->setData(2, i); } } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; MyTimer timer; QPainterPath painter; QPainter paint; QBrush brush(Qt::red); QGraphicsScene scene; scene.addItem(r1); scene.addItem(r2); scene.addItem(r3); scene.addItem(r4); scene.addItem(r5); scene.addItem(r6); scene.addItem(r7); scene.addItem(r8); scene.addItem(r9); scene.addItem(r10); scene.addItem(r11); scene.addItem(r12); scene.addItem(r13); scene.addItem(r14); scene.addItem(r15); scene.addItem(r16); scene.addItem(r17); scene.addItem(r18); scene.addItem(r19); scene.addItem(r20); scene.addItem(r21); q1 = scene.addText("new text"); q1->setPos(-100,0); r1->setBrush(QColor(255, 255, 255, 127)); r2->setBrush(QColor(255, 255, 255, 127)); r3->setBrush(QColor(255, 255, 255, 127)); r4->setBrush(QColor(255, 255, 255, 127)); r5->setBrush(QColor(255, 255, 255, 127)); r6->setBrush(QColor(255, 255, 255, 127)); r7->setBrush(QColor(255, 255, 255, 127)); r8->setBrush(QColor(255, 255, 255, 127)); r9->setBrush(QColor(255, 255, 255, 127)); r10->setBrush(QColor(255, 255, 255, 127)); r11->setBrush(QColor(255, 255, 255, 127)); r12->setBrush(QColor(255, 255, 255, 127)); r13->setBrush(QColor(255, 255, 255, 127)); r14->setBrush(QColor(255, 255, 255, 127)); r15->setBrush(QColor(255, 255, 255, 127)); r16->setBrush(QColor(255, 255, 255, 127)); r17->setBrush(QColor(255, 255, 255, 127)); r18->setBrush(QColor(255, 255, 255, 127)); r19->setBrush(QColor(255, 255, 255, 127)); r20->setBrush(QColor(255, 255, 255, 127)); r21->setBrush(QColor(255, 255, 255, 127)); QPen pen(Qt::red); scene.addEllipse(-40,20,20,20,pen,brush); scene.addEllipse(300,80,20,20,pen,brush); scene.addEllipse(140,140,20,20,pen,brush); scene.setBackgroundBrush(QColor(160,200,190,140)); QGraphicsView view(&scene); view.show(); // window->setLayout(layout); //window->show(); // w.show(); return a.exec(); }
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); }