int main(int argc, char **argv) { QApplication app( argc, argv ); QGraphicsScene scene; QGraphicsView view(&scene); view.setBackgroundBrush(QBrush(Qt::black)); view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); view.setDragMode(QGraphicsView::ScrollHandDrag); view.show(); // view.showFullScreen(); QGraphicsRectItem *r = scene.addRect(-50, -50, 10, 10); r->setPen(QPen(QColor(255, 0, 0))); r->setBrush(QBrush(QColor(0, 255, 0))); r->show(); r = scene.addRect(0, 0, 10, 10); r->setPen(QPen(QColor(255, 0, 0))); r->setBrush(QBrush(QColor(0, 255, 0))); r->show(); r = scene.addRect(200, 200, 10, 10); r->setPen(QPen(QColor(255, 0, 0))); r->setBrush(QBrush(QColor(0, 255, 0))); r->show(); scene.setSceneRect(-100, -100, 100, 100); view.resize(200, 200); return app.exec(); }
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); }
// tab 1 - QGraphicsScene with ScrollPanner void MainWindow::setupGraphicsScene() { // create and fill the scene QGraphicsScene *scene = new QGraphicsScene(this); ui->GraphicsView->setScene(scene); for (int i = 0; i < 100; i++) { QGraphicsRectItem *rect = scene->addRect( qrand() % 2000, qrand() % 2000, qrand() % 400 + 10, qrand() % 400 + 10, QPen(Qt::red), QBrush(Qt::yellow)); } // setup ScrollPanner ui->SceneScrollPanner->setBackgroundBrush(QBrush(QColor(Qt::cyan))); ui->SceneScrollPanner->setBackgroundPen(QColor(Qt::lightGray)); ui->SceneScrollPanner->setSliderBrush(QBrush(QColor(Qt::white))); ui->SceneScrollPanner->setSliderPen(QColor(Qt::red)); ui->SceneScrollPanner->setOpacity(1); ui->SceneScrollPanner->setSliderOpacity(0.5); // connect ScrollPanner to the scene view ui->SceneScrollPanner->connectSource(ui->GraphicsView); }
int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QApplication a(argc, argv); const QString fileAbsPath = a.arguments().at(1); qDebug("Opening %s...", qPrintable(fileAbsPath)); QMediaPlayer p; p.setMedia(QMediaContent(QUrl(fileAbsPath))); QGraphicsVideoItem* item = new QGraphicsVideoItem; QGraphicsScene* scene = new QGraphicsScene; scene->addText("TEST"); p.setVideoOutput(item); scene->addItem(item); scene->addRect(0, 0, 100, 100, QPen(Qt::red), QBrush(Qt::red)); item->setPos(0, 0); //QImage image(1920, 1080, QImage::Format_ARGB32); //image.fill(Qt::blue); //QPainter painter(&image); //painter.setRenderHint(QPainter::Antialiasing); //scene->render(&painter); QGraphicsView view(scene); //view.scene()->addItem(item); view.setViewport(new QOpenGLWidget); view.show(); p.play(); return a.exec(); }
void MainWindow::on_recoverThread_updateStatus(const DdrescueStatus &status, DdrescueLog const &log) { ui->lblRescuedValue->setText(formatBytes(status.rescued())); ui->lblIposValue->setText(formatBytes(status.ipos())); ui->lblOposValue->setText(formatBytes(status.opos())); ui->lblErrsizeValue->setText(formatBytes(status.errsize())); ui->lblErrorsValue->setText(QString::number(status.errors())); ui->lblAvgRateValue->setText(formatBytes(status.averageRate()) + "/s"); ui->lblCurrRateValue->setText(formatBytes(status.currentRate()) + "/s"); ui->lblTimeFrom->setText(QString::number(status.timeFromLastSuccessfulRead()) + " s"); ui->lblStatus->setText(status.status()); QGraphicsScene *scene = ui->graph->scene(); if (!scene) { scene = new QGraphicsScene(); ui->graph->setScene(scene); } scene->clear(); qreal width = ui->graph->width()-5; qreal height = ui->graph->height()-5; scene->addRect(0,0,width,height,QPen(QColor(Qt::blue)), QBrush(QColor(Qt::blue))); long long sizeTotal = 0; for (int i = 0; i < log.blocks().size(); i++) { sizeTotal += log.blocks().at(i).size; } qreal wfactor = sizeTotal / width; if (sizeTotal > 0) { for (int i = 0; i < log.blocks().size(); i++) { qreal x = log.blocks().at(i).pos/wfactor; qreal w = log.blocks().at(i).size/wfactor; scene->addRect(x,0 ,w,height ,QPen(statusBlock2QColor(log.blocks().at(i).status)) , QBrush(statusBlock2QColor(log.blocks().at(i).status))); } } scene->addText(formatBytes(sizeTotal)); }
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 SectionDialog::redraw() { QGraphicsScene *scene = sectionPreview->scene(); assert(scene!=NULL); scene->clear(); qreal w = widthSpin->value(); qreal h = heightSpin->value(); scene->addRect(0,0,w,h,QPen(Qt::black,1), QBrush(Qt::red,Qt::BDiagPattern)); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView gv; QGraphicsScene *scene = new QGraphicsScene(&gv); gv.setScene(scene); QGraphicsItem *rect = scene->addRect(0, 0, 200, 200, QPen(Qt::NoPen), QBrush(Qt::yellow)); rect->setFlag(QGraphicsItem::ItemHasNoContents); rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape); QGraphicsItem *childRect = scene->addRect(0, 0, 100, 100, QPen(Qt::NoPen), QBrush(Qt::red)); childRect->setParentItem(rect); gv.show(); MyObject o(rect); QMessageBox::information(0, "What you should see", "The red rectangle should toggle visiblity, so you should see it flash on and off"); return a.exec(); }
void Particles::on_color_clicked() { QColor newColor = QColorDialog::getColor(color, this); if (newColor.isValid()) { color = newColor; delete ui->colorView->scene(); QGraphicsScene *scene = new QGraphicsScene(); scene->addRect(0, 0, 21, 21, QPen(color), QBrush(color)); ui->colorView->setScene(scene); } }
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 Particles::on_particles_clicked(QModelIndex index) { controls(true); ui->minX->setText(""); ui->maxX->setText(""); ui->minY->setText(""); ui->maxY->setText(""); ui->minZ->setText(""); ui->maxZ->setText(""); if (ui->particlesType->isChecked()) { StartingParticle *particle = widget->getPainter()->getGrid()->getVelocityField()->getStartingPathLine(stringList.at(index.row()).toInt()); if (particle != 0) { ui->minX->setText(QString::number((particle)->getFrom().getX() + 1)); ui->maxX->setText(QString::number((particle)->getTo().getX() + 1)); ui->minY->setText(QString::number((particle)->getFrom().getY() + 1)); ui->maxY->setText(QString::number((particle)->getTo().getY() + 1)); ui->minZ->setText(QString::number((particle)->getFrom().getZ() + 1)); ui->maxZ->setText(QString::number((particle)->getTo().getZ() + 1)); color = QColor((particle)->getColor().getX(), (particle)->getColor().getY(), (particle)->getColor().getZ()); delete ui->colorView->scene(); QGraphicsScene *scene = new QGraphicsScene(); scene->addRect(0, 0, 21, 21, QPen(color), QBrush(color)); ui->colorView->setScene(scene); } } else { Configuration *conf = PassiveScalarSingleton::getInstance()->get(stringList.at(index.row()).toInt()); if (conf != 0) { ui->minX->setText(QString::number(conf->getMinX() + 1)); ui->maxX->setText(QString::number(conf->getMaxX() + 1)); ui->minY->setText(QString::number(conf->getMinY() + 1)); ui->maxY->setText(QString::number(conf->getMaxY() + 1)); ui->minZ->setText(QString::number(conf->getMinZ() + 1)); ui->maxZ->setText(QString::number(conf->getMaxZ() + 1)); color = QColor((conf)->getColor().getX(), (conf)->getColor().getY(), (conf)->getColor().getZ()); delete ui->colorView->scene(); QGraphicsScene *scene = new QGraphicsScene(); scene->addRect(0, 0, 21, 21, QPen(color), QBrush(color)); ui->colorView->setScene(scene); } } }
void CellMesh2D::draw(QGraphicsScene &scene) { size_t max_val = 0; for (Array<Cell>::const_iterator it = data().begin(); it != data().end(); it++) if (max_val < it->getNumOfParticles()) max_val = it->getNumOfParticles(); for (size_t y = 0; y < getHeight(); y++) { for (size_t x = 0; x < getWidth(); x++) { const size_t val = operator ()(x, y).getNumOfParticles(); const int color = int((float(val)/float(max_val + 1))*255.0); scene.addRect(QRectF(x*10, y*10, 8, 8), QPen(), QBrush(QColor(color, 0, 0))); } } }
GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), warringLine(NULL), viewRect(NULL) { QGraphicsScene *s = new QGraphicsScene(this); this->setScene(s); s->addRect(0, 0, 10, 10); menu = s->addWidget(new VehicleTypeMenu(this)); QPixmap pix("./icon/compass.png"); compass = s->addPixmap(pix.scaled(200, 200)); compass->setZValue(100); }
void ParallelMachine::drawCells(QGraphicsScene &scene) { const size_t max_num = getMaxNumOfParticlesInCell(); for (NodeThreadArray::const_iterator it = threads.begin(); it != threads.end(); it++) { // draw cells of each node/thread const size_t& node_id = it->getId(); const QColor& node_color = colors[node_id % NUM_OF_COLORS]; it->drawCells(scene, node_color, mesh_size, max_num); QGraphicsRectItem *rect = scene.addRect(QRectF(node_id*20, (mesh_size + 2)*10, 10, 10), QPen(Qt::black), QBrush(node_color)); QGraphicsTextItem *text = scene.addText(QString::number(node_id)); text->setPos(rect->boundingRect().left(), rect->boundingRect().bottom()); } }
SEXP scene_addRect(SEXP scene, SEXP x, SEXP y, SEXP w, SEXP h) { QGraphicsScene* s = unwrapQObject(scene, QGraphicsScene); int nw = length(w), nh = length(h); int i, n = length(x); for (i = 0; i < n; i++) { QGraphicsRectItem *item = s->addRect(REAL(x)[i], REAL(y)[i], REAL(w)[i % nw], REAL(h)[i % nh]); // item->setFlags(QGraphicsItem::ItemIsSelectable | // QGraphicsItem::ItemIgnoresTransformations); } return R_NilValue; }
int main(int argc, char **argv) { QApplication app(argc, argv); QGraphicsScene scene; QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); rect->setFlag(QGraphicsItem::ItemIsMovable); QGraphicsView view(&scene); view.show(); return app.exec(); }
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) ); }
void Colors::config(double average, double interval) { this->average = average; this->interval = interval; ui->firstMarker->setText(QString::number(average - 2 * interval, 'g', 3)); ui->secondMarker->setText(QString::number(average - interval, 'g', 3)); ui->thirdMarker->setText(QString::number(average, 'g', 3)); ui->fourthMarker->setText(QString::number(average + interval, 'g', 3)); ui->fifthMarker->setText(QString::number(average + 2 * interval, 'g', 3)); QGraphicsScene *scene = new QGraphicsScene(); for (int i = 0; i < ui->graphicsView->width(); i++) { QColor color = widget->getPainter()->getColor(average - 2 * interval + 4 * interval * i / ui->graphicsView->width()); scene->addRect(i, 0, 1, ui->graphicsView->height(), QPen(color), QBrush(color)); } delete ui->graphicsView->scene(); ui->graphicsView->setScene(scene); }
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { // create a scene with items, // use the view to show the scene QGraphicsScene *scene = new QGraphicsScene(); QGraphicsView *gv = new QGraphicsView(this); gv->setScene(scene); if (gv->scene()) { printf("renc: scene is not null.\n"); // these two lines are at scene origin pos. scene->addLine(0, 0, 100, 0, QPen(Qt::red)); scene->addLine(0, 0, 0, 100, QPen(Qt::green)); /*QGraphicsRectItem *rect = */ scene->addRect(QRectF(0,0,50,50), QPen(Qt::red), QBrush(Qt::green)); // svg image QGraphicsSvgItem *svgItem = new QGraphicsSvgItem(svgFile2); scene->addItem((svgItem)); svgItem->setPos(400, 0); bool rValid1 = svgItem->renderer()->isValid(); printf("--%d--\n", rValid1); // QWidget to scene QPushButton *btn = new QPushButton("button 1");// at (0,0) by default. QGraphicsProxyWidget *btnWidget = scene->addWidget(btn); btnWidget->setPos(0, 400); // { SvgPushButton *btn2 = new SvgPushButton(svgFile1); QGraphicsProxyWidget *btnWidget2 = scene->addWidget(btn2); btnWidget2->setPos(400, 400); } } else printf("renc: scene is null.\n"); //setCentralWidget(gv); setWindowTitle("Demo: graphics view");//QMainWindow setStyleSheet("background-color: rgb(100,120,50);"); }
int main(int argc, char **argv) { QApplication app(argc, argv); QGraphicsScene scene; scene.setSceneRect(0,0, 100, 100); scene.addRect(QRectF(0,0, 100, 100)); scene.addLine(QLineF(0,0, 100, 100)); scene.addLine(QLineF(0,100, 100, 0)); QGraphicsView* view = new QGraphicsView(&scene); CGAL::Qt::GraphicsViewNavigation navigation; view->installEventFilter(&navigation); view->viewport()->installEventFilter(&navigation); view->setRenderHint(QPainter::Antialiasing); view->show(); return app.exec(); }
bool ImageCalibrator::init(QString imgPath) { QList<QString > tmp; QString imgFileM; QString imgOrig; QFileInfo ourFile(imgPath); tmp = ourFile.fileName().split(".", QString::SkipEmptyParts); if(tmp.size()==2) imgFileM = tmp[0] + "m." + tmp[1]; else imgFileM = ""; //mask = ; imgOrig = ourFile.absoluteDir().path() + "/" + tmp[0] + "_orig.png"; bool createOrig=false; if(!QFile::exists(imgOrig)) { createOrig=true; } //Scene->mSpriteImage = QPixmap(fileName); if(createOrig) { sprite = QPixmap::fromImage( Graphics::setAlphaMask( Graphics::loadQImage( imgPath ) ,Graphics::loadQImage( ourFile.absoluteDir().path() + "/" + imgFileM )) ); if(sprite.isNull()) return false; sprite.save(imgOrig, "PNG"); // Generate backup image } else sprite = QPixmap::fromImage( Graphics::loadQImage( imgOrig ) ); // load original sprite instead current if(sprite.isNull()) return false; targetPath = imgPath; pngPath = ourFile.absoluteDir().path() + "/" + tmp[0] + ".png"; gifPath = ourFile.absoluteDir().path() + "/" + tmp[0] + ".gif"; gifPathM = ourFile.absoluteDir().path() + "/" + tmp[0] + "m.gif"; iniPath = ourFile.absoluteDir().path() + "/" + tmp[0] + "_orig_calibrates.ini"; //generate scene ui->PreviewGraph->setScene(new QGraphicsScene(ui->PreviewGraph)); QGraphicsScene * sc = ui->PreviewGraph->scene(); frmX=0; frmY=0; frameOpts xyCell; xyCell.offsetX=0; xyCell.offsetY=0; xyCell.W=0; xyCell.H=0; xyCell.used=false; xyCell.isDuck=false; xyCell.isRightDir=false; xyCell.showGrabItem=false; // Write default values QVector<frameOpts > xRow; for(int i=0; i<10; i++) { xRow.clear(); for(int j=0; j<10; j++) { xRow.push_back(xyCell); } imgOffsets.push_back(xRow); } loadCalibrates(); imgFrame = sc->addPixmap(sprite.copy(frmX*100,frmY*100,100,100)); imgFrame->setZValue(0); imgFrame->setPos(0,0); phsFrame = sc->addRect(0,0,99,99, QPen(QBrush(Qt::gray), 1)); phsFrame->setZValue(-2); phsFrame->setOpacity(0.5f); phsFrame->setPos(0,0); physics = sc->addRect(0,0,99,99, QPen(QBrush(Qt::green), 1)); physics->setZValue(4); physics->setPos(0,0); updateScene(); return true; }
// 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); } } }
//----------------------------------------------------------------------------------------- // 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 FormView::showSetting(Setting setting) { QGraphicsScene *s = scene(); s->clear(); resetTransform(); int scale_fac = 10; int spacing = 20; int planeWidth = setting.get_problem()->get_plane_width()*scale_fac; int planeHeight = setting.get_problem()->get_plane_height()*scale_fac; QRectF bound; for (int i=0; i<setting.get_number_of_planes(); ++i) { int x_offset = i*(planeWidth+spacing)+(spacing/2); int y_offset = (spacing/2); QRectF plane(x_offset,y_offset,planeWidth, planeHeight); s->addRect(plane,QPen(), QBrush(QColor(188, 198, 204),Qt::SolidPattern)); for (int j=0; j<setting.get_plane_at(i)->get_number_of_forms(); ++j) { QPolygonF polygon; Form form; setting.get_plane_at(i)->get_form_at(j, form); vector<Point> points_of_current_form = *(form.get_points()); for (int k=0; k<points_of_current_form.size(); ++k){ Point point = points_of_current_form[k]; polygon.push_back(QPointF(point.get_x()*scale_fac, point.get_y()*scale_fac)); } QGraphicsPolygonItem * polyitem = s->addPolygon(polygon, QPen(QColor(Qt::red)), QBrush(Qt::SolidPattern)); polyitem->setPos(x_offset, y_offset); bound = polygon.boundingRect(); } } float realwidth = container->width() - 50; float width = setting.get_number_of_planes()*(planeWidth+spacing); float realheight = container->height() - 50; float height = planeHeight+spacing; s->setSceneRect(0,0,width,height); float relw = 1; if(width > 0){ relw = realwidth / width; } float relh = 1; if(height > 0){ relh = realheight / height; } float rel = relw; if(relh < relw){ rel = relh; } scale(rel,rel); }
QRectF drawRect(QGraphicsScene &scene, const size_t& x, const size_t& y, const size_t& w, const size_t& h, const QColor& color) { return scene.addRect(QRectF(x, y, w, h), QPen(), QBrush(color))->boundingRect(); }
void SceneImageExporter::PageGraphicsSceneToPrinter(QGraphicsScene *scene, QPrinter &printer, QList<SectorRectHolder>& pageRegions, QString fileName, QString documentName __attribute__((unused))) { PrintingPreferences &pref __attribute__ ((unused)) = PrintingPreferences::prefs(); //qDebug() << pref.yDivisions(); //qDebug() << pref.selectedMeasure(); //qDebug() << pref.measures(); if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive)) { printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); } // When printing, use full page mode, IE ignore hardware margins. It's up // to users to set them as they desire. printer.setFullPage(true); printer.setPaperSize(QSizeF(PrintingPreferences::prefs().selectedMeasure().width(), PrintingPreferences::prefs().selectedMeasure().height()), QPrinter::Millimeter); printer.setPageMargins(PrintingPreferences::prefs().leftMargin(), PrintingPreferences::prefs().topMargin(), PrintingPreferences::prefs().rightMargin(), PrintingPreferences::prefs().bottomMargin(), QPrinter::Millimeter); //here, I print using selected sheets and divisions. QPainter painter(&printer); qreal left,top,right,bottom; printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel); // get the FULL PAGE RECTANGLE and adjust margins. QRectF pageRect = printer.paperRect(); pageRect.adjust(left,top,-right, -bottom); QColor transparent(0,0,0,0); QColor transBorder (0,0,0,128); QPen pen (transBorder); pen.setStyle(Qt::DotLine); QBrush brush; QGraphicsScene sceneFirst; QPen pen2 (QColor(0,0,0)); pen2.setStyle(Qt::DotLine); pen2.setWidthF(2.0); QBrush brush2; for (int h = 0; h < pageRegions.count(); h++) { QRectF rect = pageRegions[h].rectInner(); sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2); rect = pageRegions[h].rectOuter(); sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2); } scene->render(&painter, pageRect, scene->itemsBoundingRect(),Qt::KeepAspectRatio); sceneFirst.render(&painter,pageRect, sceneFirst.sceneRect(),Qt::KeepAspectRatio); for (int h = 0; h < pageRegions.count(); h++) { QRectF rect = pageRegions[h].rectOuter(); double ratio = rect.width()/rect.height(); QRectF rectTarget = QRectF(pageRect.left(), pageRect.top(), pageRect.width(), pageRect.width()/ratio); printer.newPage(); scene->render(&painter,rectTarget, rect); painter.setPen(pen2); painter.setBrush(brush); painter.drawRect(rectTarget); QRectF rect2 = pageRegions[h].rectInner(); double ratioX = rectTarget.width()/rect.width(); double ratioY = rectTarget.height()/rect.height(); double dy = rect2.top()-rect.top(); double dx = rect2.left() - rect.left(); //qDebug() << "rect outer: " << rect // << "\nrect inner: " << rect2 // << "\nrect target: " << rectTarget // << "\nx: " << dx << ",y:" << dy; QRectF rectTarget2 (rectTarget.top()+ dx*ratioX, rectTarget.left()+dy*ratioY, rect2.width()*ratioX, rect2.height()*ratioY); painter.drawRect(rectTarget2); } painter.end(); }
//-------------------------------------------------------------------------------------------- void MReadiness::Init() { //===#### I: Left (Ekranoplan): ####=== QGraphicsScene* PSceneEkranoplan = new QGraphicsScene(this); PSceneEkranoplan->addPixmap(QPixmap(":/lun2.png")); // PSceneEkranoplan->addPixmap(QPixmap(":/Ekranoplan.png")); PViewEkranoplan = new QGraphicsView(PSceneEkranoplan, this); for(int i = 0; i < GetPMainWnd()->GetPListTestRectsReadinessChannels()->count(); i++) { ListTestRectItems << PSceneEkranoplan->addRect((*GetPMainWnd()->GetPListTestRectsReadinessChannels())[i], QPen(), QBrush()); } NRPoint = 5; MRPoints = new qreal[NRPoint]; qreal rPoint1 = 0.5; qreal rPoint2 = 1.0; qreal dRPoint = (rPoint2-rPoint1)/(NRPoint-1); for(int i = 0; i < NRPoint-1; i++) { MRPoints[i] = rPoint1 + i*dRPoint; } MRPoints[NRPoint-1] = rPoint2; Alpha1 = 100; Alpha2 = 200; DIncrementAlpha = 5; DAlpha = (Alpha2-Alpha1)/(NRPoint-1); MAlphas = new int[NRPoint]; MkAlphas = new int[NRPoint]; //===#### II: 1) Right (Channels): ####=== QSplitter* pSplitterReadiness = new QSplitter(Qt::Vertical, this); QList<int> list; list << 150 << 200; setSizes(list); list.clear(); //=== 1) ReadinessTest: QScrollArea* pScrollAreaTest = new QScrollArea(pSplitterReadiness); pScrollAreaTest->setWidgetResizable(true); QWidget* pScrollAreaTestContents = new QWidget(pSplitterReadiness); pScrollAreaTestContents->setObjectName(QStringLiteral("ScrollAreaTestContents")); QRect rect = FillReadinessTest(pScrollAreaTestContents); pScrollAreaTestContents->setMinimumSize(rect.right() + 3,rect.bottom() + 3); pScrollAreaTest->setWidget(pScrollAreaTestContents); //=== 2) ReadinessStart: QScrollArea* pScrollAreaStart = new QScrollArea(pSplitterReadiness); pScrollAreaStart->setGeometry(QRect(40, 70, 611, 111)); pScrollAreaStart->setWidgetResizable(true); QWidget* pScrollAreaStartContents = new QWidget(pSplitterReadiness); rect = FillReadinessStart(pScrollAreaStartContents); pScrollAreaStartContents->setMinimumSize(rect.right()+3,rect.bottom()+3); pScrollAreaStart->setWidget(pScrollAreaStartContents); list << 800 << 200; pSplitterReadiness->setSizes(list); list.clear(); }
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); }