void eScopesScene::drawForeground(QPainter *painter, const QRectF &rect) { QGraphicsScene::drawForeground(painter, rect); QFont fwFont = painter->font(); m_rowTextWidth = QFontMetrics(fwFont).width("0000"); const eU32 fwHeight = QFontMetrics(fwFont).height(); m_headerHeight = 2+2*fwHeight; tfSong *song = m_seqView->getSong(); if (!song) return; for (eU32 i=0; i<tfSong::MAX_SEQ_TRACKS; i++) { if (song->getMuted(i)) { painter->setPen(Qt::black); painter->fillRect( i*TRACK_WIDTH+m_rowTextWidth+2, sceneRect().top()+m_headerHeight, TRACK_WIDTH, sceneRect().bottom()-m_headerHeight, Qt::Dense4Pattern); } } }
void GameScene::processViewSizeChange(const QSize &newSize) { viewSize = newSize; qreal newRatio = ((qreal) newSize.width()) / newSize.height(); qreal minWidth = 0; QList<qreal> minWidthByColumn; for (int col = 0; col < playersByColumn.size(); ++col) { minWidthByColumn.append(0); for (int row = 0; row < playersByColumn[col].size(); ++row) { qreal w = playersByColumn[col][row]->getMinimumWidth(); if (w > minWidthByColumn[col]) minWidthByColumn[col] = w; } minWidth += minWidthByColumn[col]; } minWidth += phasesToolbar->getWidth(); qreal minRatio = minWidth / sceneRect().height(); qreal newWidth; if (minRatio > newRatio) { // Aspect ratio is dominated by table width. newWidth = minWidth; } else { // Aspect ratio is dominated by window dimensions. newWidth = newRatio * sceneRect().height(); } setSceneRect(0, 0, newWidth, sceneRect().height()); qreal extraWidthPerColumn = (newWidth - minWidth) / playersByColumn.size(); for (int col = 0; col < playersByColumn.size(); ++col) for (int row = 0; row < playersByColumn[col].size(); ++row) playersByColumn[col][row]->processSceneSizeChange(minWidthByColumn[col] + extraWidthPerColumn); }
void GameScene::spawnPlayer() { Q_ASSERT(!m_player); addItem(m_player = new GraphicsPlayerObject(PLAYER_HEALTH)); const auto playerSize = m_player->boundingRect().size(); QPointF pos{ sceneRect().width() / 2 - playerSize.width() / 2, sceneRect().height()/* - playerSize.height()*/, }; m_player->setPos(pos); m_hudObject->setHealth(m_player->health()); addItem(m_player); connect(m_player, &GraphicsPlayerObject::cannonTriggered, this, &GameScene::planeShot); connect(m_player, &GraphicsPlayerObject::exploded, this, &GameScene::planeExploded); connect(m_player, &GraphicsPlayerObject::damaged, m_hudObject, &GraphicsHudObject::addScore); connect(m_player, &GraphicsPlayerObject::damaged, m_hudObject, &GraphicsHudObject::setHealth); connect(m_player, &GraphicsPlayerObject::exploded, m_hudObject, &GraphicsHudObject::playerDeath); setFocusItem(m_player); }
void CSharedPainterScene::drawBackgroundImage( boost::shared_ptr<CBackgroundImageItem> image ) { backgroundImageItem_ = image; if( image ) { backgroundPixmap_ = image->createPixmap(); int newSceneW = sceneRect().width(); int newSceneH = sceneRect().height(); QSize size = backgroundPixmap_.size(); if( newSceneW < size.width() ) newSceneW = size.width(); if( newSceneH < size.height() ) newSceneH = size.height(); setSceneRect( 0, 0, newSceneW, newSceneH ); } else { clearBackgroundImage(); return; } resetBackground( sceneRect () ); }
void dmz::QtCanvasScene::drawBackground (QPainter *painter, const QRectF &rect) { painter->drawRect (sceneRect ()); if (_drawGrid) { painter->fillRect (sceneRect (), QBrush (QColor (230, 240, 255))); painter->setPen (QPen (Qt::lightGray, 1)); painter->setOpacity(0.75f); const int gridSize = 100; qreal left = int(rect.left ()) - (int(rect.left ()) % gridSize); qreal top = int(rect.top ()) - (int(rect.top ()) % gridSize); QVarLengthArray<QLineF, 100> lines; for (qreal x = left; x < rect.right (); x += gridSize) { lines.append (QLineF (x, rect.top (), x, rect.bottom ())); } for (qreal y = top; y < rect.bottom (); y += gridSize) { lines.append (QLineF (rect.left (), y, rect.right (), y)); } // qDebug () << lines.size (); painter->drawLines (lines.data (), lines.size ()); QGraphicsScene::drawBackground (painter, rect); } }
void PaintScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { qreal widthScene = sceneRect().width(); qreal sceneHeight = sceneRect().height(); QImage image(widthScene, sceneHeight,QImage::Format_RGB32); //image.fill(Qt::white); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); render(&painter); QPoint newPos; newPos.setX(event->scenePos().x()); newPos.setY(event->scenePos().y()); QPen pen; pen.setWidth(brushWidth()); pen.setColor(brushColor()); painter.setPen(pen); QString type("Pencil"); QRect rect = drawRect(type, painter, m_oldPos, newPos); m_oldPos = newPos; QBrush br(image); br.setColor(Qt::transparent); setBackgroundBrush(br); update(); QGraphicsScene::mouseMoveEvent(event); }
void ReportRectEntity::mousePressEvent(QGraphicsSceneMouseEvent * event) { //Update and show properties m_ppos->setScenePos(QPointF(sceneRect().x(), sceneRect().y())); m_reportDesigner->changeSet(m_pset); setSelected(true); scene()->update(); }
void GraphDrawingScene::expandSceneRect(const QPoint& position) { // start by creating a rectangle around the position that has been passed QRect expander(position.x() - 250, position.y() - 250, 500, 500); // calculate the bounding rectangle of what we already have and what we wan to add setSceneRect(sceneRect().united(expander)); dynamic_cast<GraphDrawingView*>(parent())->setSceneRect(sceneRect()); }
void MessageView::setWidth(int width) { setSceneRect(sceneRect().x(), sceneRect().y(), width, sceneRect().height()); QListIterator<YawnerNS::UiNS::ViewNS::MessageViewNS::MessageItem*> it(_messagesItems); while (it.hasNext()) { it.next()->setWidth(width - std::min(4, verticalScrollBar()->width())); } layoutItems(&_messagesItems); }
void SinglePlayerView::hideMsg() { connect( msgtline, SIGNAL( finished() ), this, SLOT( cleanUpMsg() ) ); msganimation->setPosAt( 0, sceneRect().center() - msg->boundingRect().center() ); msganimation->setScaleAt( 0, 1, 1 ); msganimation->setPosAt( 1, QPointF( sceneRect().center().x(), sceneRect().bottomRight().y() ) ); msganimation->setScaleAt( 1, 0.01, 0.01 ); msgtline->start(); }
void MapView::scrollContentsBy(int dx, int dy) { QGraphicsView::scrollContentsBy( dx, dy ); emit sig_viewportScrolled( std::max(0.0, (double)mapToScene(rect()).boundingRect().x() / (double)sceneRect().width()), std::max(0.0, (double)mapToScene(rect()).boundingRect().y() / (double)sceneRect().height())); }
void GraphicsScene::printPage(int index, int percentual , QPainter &painter, QPrinter * printer) { QPixmap pixmap(painter.viewport().width(),painter.viewport().height()); /* virtual paper */ bool portrait = printer->orientation() == QPrinter::Portrait ? true : false; const qreal wit = qMin(printer->pageRect().width(),printer->paperRect().width()); const qreal hei = qMin(printer->pageRect().height(),printer->paperRect().height()); const qreal faktor_print = qMax(wit,hei) / qMin(wit,hei); const QRect Paper_Rect = printer->pageRect(); qreal onepagescene_HI = sceneRect().width() * faktor_print; if (!portrait) { onepagescene_HI = sceneRect().width() / faktor_print; } QRectF rectScenePiece = QRectF (0.,0.,sceneRect().width(),onepagescene_HI); /* first slice from scene */ const qreal page = sceneRect().height() / onepagescene_HI; /* page need */ int PageSumm = page; if (page > PageSumm) { PageSumm++; /* float to next int */ } if ( index > PageSumm ) { return; /* not having this page */ } qreal InitOnYtop = 0; if (index != 0) { InitOnYtop = rectScenePiece.height() * index; } QRect pagepiece = QRect(0,InitOnYtop,rectScenePiece.width(),rectScenePiece.height()); //////////qDebug() << "### page " << index << "," << percentual << "," << printer->pageRect(); const qreal smallpart = qMax(pixmap.width(),pixmap.height()) / faktor_print; QRectF AFormatPaper; /* Paper dimension from printer Faktor run */ if (portrait) { AFormatPaper = QRect(0,0,smallpart,qMax(pixmap.width(),pixmap.height())); } else { AFormatPaper = QRect(0,0,qMax(pixmap.width(),pixmap.height()),smallpart); } QRectF ZoomFaktorPage = Reduce(AFormatPaper,percentual); /* zoom rect */ QRect WhitePaper = CenterRectSlaveFromMaster(pixmap.rect(),AFormatPaper).toRect(); QRect RenderPage = CenterRectSlaveFromMaster(pixmap.rect(),ZoomFaktorPage).toRect(); painter.fillRect(painter.viewport(),QBrush(Qt::lightGray)); /* device to cover */ painter.fillRect(WhitePaper,QBrush(Qt::white)); /* paper */ /////////painter.fillRect(RenderPage,QBrush(Qt::red)); /* page result */ render(&painter,RenderPage,pagepiece,Qt::KeepAspectRatio); }
void OpenInfraPlatform::UserInterface::Alignment2DScene::exportToFile(QWidget* parent) { QString filter; QString fn = QFileDialog::getSaveFileName(parent, tr("Save Vertical Alignment as..."), QString(), tr("PNG File (*.png);; JPG File (*.jpg);; PDF File (*.pdf);; SVG File (*.svg)"), &filter); if(fn.isEmpty()) return; if(filter == "PNG File (*.png)" || filter == "JPG File (*.jpg)") { QImage image(sceneRect().size().toSize(), QImage::Format::Format_ARGB32); image.fill(Qt::darkGray); QPainter painter(&image); painter.setRenderHints(QPainter::Antialiasing); render(&painter); image.save(fn); } else { QPrinter printer; QSvgGenerator svgGen; QPaintDevice* device; if(filter == "PDF File (*.pdf)") { printer.setResolution(QPrinter::HighResolution); printer.setPageSize( QPrinter::A4 ); printer.setOrientation( QPrinter::Landscape ); printer.setOutputFormat( QPrinter::PdfFormat ); printer.setOutputFileName(fn); device = &printer; } else if(filter == "SVG File (*.svg)") { QRectF rect = sceneRect(); svgGen.setFileName(fn); svgGen.setSize(QSize(rect.width(),rect.height())); svgGen.setViewBox(QRect(0,0,rect.width(),rect.height())); svgGen.setTitle("Vertical Alignment"); device = &svgGen; } else { return; } QPainter painter(device); configureColors(A2D_DrawState::A2D_Print); render(&painter); configureColors(A2D_DrawState::A2D_Draw); } }
void View::save(QXmlStreamWriter &xml) { QList<QGraphicsItem*> items = scene()->items(); xml.writeAttribute("width", QVariant(sceneRect().width()).toString()); xml.writeAttribute("height", QVariant(sceneRect().height()).toString()); foreach(QGraphicsItem* viewItem, items) { if (!viewItem->parentItem()) { qgraphicsitem_cast<ViewItem*>(viewItem)->save(xml); } } }
void AnimatorScene::setSceneInfoText(QString text, bool show) { m_sceneInfoText->setText (text); m_sceneInfoText->setVisible (show); QFontMetrics fm (font ()); QRectF r = sceneRect (); QPointF pos = QPointF ((sceneRect ().width () - fm.width (text))/2, r.center ().y ()); m_sceneInfoText->setPos (pos); }
void Tchart::ajustChartHeight() { qreal factor = (viewport()->rect().height() / scene->sceneRect().height()) * 0.95; if (viewport()->rect().width() > (scene->sceneRect().width() + qAbs(sceneRect().x())) * factor) { setSceneRect(0, 0, viewport()->rect().width() / factor, scene->sceneRect().height()); } else { setSceneRect(sceneRect().adjusted(-sceneRect().x(), 0, qAbs(sceneRect().x()), 0)); } scale(factor, factor); horizontalScrollBar()->setValue(horizontalScrollBar()->minimum()); }
void FormEditorGraphicsView::drawBackground(QPainter *painter, const QRectF &rect) { painter->save(); painter->setBrushOrigin(0, 0); painter->fillRect(rect.intersected(sceneRect()), backgroundBrush()); // paint rect around editable area painter->setPen(Qt::black); QRectF frameRect = sceneRect().adjusted(0, 0, 0, 0); painter->drawRect(frameRect); painter->restore(); }
void TrackInfo::plot(QPainter *painter, const QRectF &target) { qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI; QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio); QSizeF diff = QSizeF(qAbs(canvas.width() - sceneRect().width()), qAbs(canvas.height() - sceneRect().height())); QRectF adj = sceneRect().adjusted(0, -diff.height()/2, diff.width(), diff.height()/2); render(painter, target, adj); }
void ObjectGroup::move(int x, int y) { QRect prevSceneRect = sceneRect(); int difX, difY; Object::move(x, y); difX = sceneRect().topLeft().x() - prevSceneRect.topLeft().x(); difY = sceneRect().topLeft().y() - prevSceneRect.topLeft().y(); for(int i=mObjects.size()-1; i >=0; --i) { mObjects[i]->move( mObjects[i]->x()+difX, mObjects[i]->y()+difY); } }
void chatGraphicsView::addMessage(const QString& user, const QString& message) { if(m_scene) m_scene->addMessage(user, message); QRectF rect = scene()->sceneRect(); rect.adjust(-4, -4, 4, 4); setSceneRect(rect); rect = sceneRect(); rect.setTop(sceneRect().height() - 20); rect.setWidth(20); ensureVisible(rect, 50, 50); }
bool PaintScene::saveImage(const QString &fileName, const char *fileFormat) { qreal widthScene = sceneRect().width(); qreal sceneHeight = sceneRect().height(); QImage image(widthScene, sceneHeight,QImage::Format_RGB32); //image.fill(Qt::white); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); render(&painter); return image.save(fileName, fileFormat); }
void eScopesScene::drawBackground(QPainter *painter, const QRectF &rect) { QGraphicsScene::drawBackground(painter, rect); QFont fwFont = painter->font(); const eU32 fwHeight = QFontMetrics(fwFont).height(); const eU32 rowTextWidth = QFontMetrics(fwFont).width("0000"); const eU32 startX = rowTextWidth+FIRST_COL_DIST; tfSong *song = m_seqView->getSong(); if (!song) return; setSceneRect(0, 0, TRACK_WIDTH*tfSong::MAX_SEQ_TRACKS+rowTextWidth+FIRST_COL_DIST, (eF32)2.0f*(eF32)fwHeight); painter->setPen(QColor(80,90,100)); painter->drawLine(sceneRect().left()+rowTextWidth+FIRST_COL_DIST, fwHeight, sceneRect().right(), fwHeight); painter->setFont(fwFont); painter->setPen(Qt::white); for (eU32 i=0; i<tfSong::MAX_SEQ_TRACKS; i++) { if (song->getMuted(i)) { painter->setPen(Qt::gray); painter->drawText(QRectF(i*TRACK_WIDTH+startX, fwHeight, TRACK_WIDTH, fwHeight), Qt::AlignCenter, "Muted"); } else { eF32 peak = eDemo::getSynth().getPeakTrack(i) * 4; eU32 ipeak = eMin<eU32>(peak * (TRACK_WIDTH-4), TRACK_WIDTH-4); painter->setPen(Qt::white); painter->fillRect(i*TRACK_WIDTH+startX+2, fwHeight+2, ipeak, fwHeight-4, QBrush(Qt::white, Qt::SolidPattern)); } painter->drawText(QRectF(i*TRACK_WIDTH+startX, 0, TRACK_WIDTH, fwHeight), Qt::AlignCenter, QString::number(i).rightJustified(2, '0')); painter->setPen(QColor(80,90,100)); if (i > 0) { painter->setPen(QPen(QBrush(QColor(80,90,100)), 1, Qt::DashLine)); } painter->drawLine(i*TRACK_WIDTH+rowTextWidth+2, sceneRect().top(), i*TRACK_WIDTH+rowTextWidth+2, sceneRect().bottom()); } }
void SnapshotCanvas::adjustMaximumSize() { QRectF sr = sceneRect(); int width = sr.width() + frameWidth() * 2; int height = sr.height() + frameWidth() * 2; if (minimumWidth() > width) { width = minimumWidth(); } if (minimumHeight() > height) { height = minimumHeight(); } int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); if (verticalScrollBar()->isVisible()) { width += scrollBarExtent + frameWidth() * 2; } if (horizontalScrollBar()->isVisible()) { height += scrollBarExtent + frameWidth() * 2; } setMaximumSize(width, height); }
void DisplayGroupGraphicsView::resizeEvent( QResizeEvent * resizeEvt ) { // compute the scene rectangle to show such that the aspect ratio // corresponds to the actual aspect ratio of the tiled display const float tiledDisplayAspect = g_configuration->getAspectRatio(); const float windowAspect = (float)width() / (float)height(); float sceneWidth, sceneHeight; if( tiledDisplayAspect >= windowAspect ) { sceneWidth = 1.; sceneHeight = tiledDisplayAspect / windowAspect; } else // tiledDisplayAspect < windowAspect { sceneHeight = 1.; sceneWidth = windowAspect / tiledDisplayAspect; } // make sure we have a small buffer around the (0,0,1,1) scene rectangle float border = 0.05; sceneWidth = std::max( sceneWidth, (float)1. + border ); sceneHeight = std::max( sceneHeight, (float)1. + border ); setSceneRect( -(sceneWidth - 1.)/2., -(sceneHeight - 1.)/2., sceneWidth, sceneHeight ); fitInView(sceneRect()); QGraphicsView::resizeEvent(resizeEvt); }
//no more used void MapView::updateMapRect( QRectF rect ) { TRACE("updateMapRect rect.x() %f, rect.y() %f, width() %f, height() %f ", rect.x(), rect.y(), rect.width(), rect.height()); QList<QRectF> rectlist; rectlist.append( rect ); _map->updateMapRect(sceneRect()); }
/* * 功能: * 满屏显示用户视角区域 * 参数: * 返回值: */ void SlidingScreen::resizeEvent(QResizeEvent *event) { if (!m_enable) return; fitInView(sceneRect(), Qt::IgnoreAspectRatio); QGraphicsView::resizeEvent(event); }
//================================================================================================= void SlideScene::drawForeground( QPainter *painter, const QRectF &/*rect*/ ) { if (!image) return; painter->drawImage( sceneRect(), *image ); }
bool PacketsScene::setUpNodeLines () { bool foundNodes = false; QRectF r = sceneRect (); qreal height = r.bottom () - r.top (); m_borderHeight = 0.01 * height; m_lineLength = r.bottom () - m_borderHeight; r.setWidth (100 * m_interNodeSpacing); setSceneRect (r); uint32_t nodeCount = AnimNodeMgr::getInstance ()->getCount (); if (!nodeCount) return foundNodes; for (int lineIndex = 0; lineIndex < m_allowedNodes.count () ; ++lineIndex) { foundNodes = true; QGraphicsLineItem * lineItem = addLine (m_interNodeSpacing * lineIndex, m_borderHeight, m_interNodeSpacing * lineIndex, m_lineLength); m_nodeLines[m_allowedNodes[lineIndex]] = lineItem; QGraphicsSimpleTextItem * nodeIdText = new QGraphicsSimpleTextItem (QString::number (m_allowedNodes[lineIndex])); addItem (nodeIdText); m_nodeIdTexts.push_back (nodeIdText); nodeIdText->setPos (m_interNodeSpacing * lineIndex, -m_borderHeight); m_lineIndex[m_allowedNodes[lineIndex]] = lineIndex; } m_rulerLine->setLine (RULER_X, m_borderHeight, RULER_X, m_lineLength); return foundNodes; }
void PHIAScene::drawBackground( QPainter *painter, const QRectF &r ) { QGraphicsScene::drawBackground( painter, r ); if ( _bgImage.isNull() ) return; QRectF rect=sceneRect(); PHIPage::ImageOptions opts=static_cast<PHIPage::ImageOptions>(_bgOptions); QPointF off=_bgOffset; if ( opts & PHIPage::IFixed ) off+=views().first()->mapToScene( QPoint( 0, 0 ) ); painter->translate( off ); if ( opts & PHIPage::IRepeatX && opts & PHIPage::IRepeatY ) { for ( qreal x=-_bgImage.width(); x<rect.width()+_bgImage.width(); x=x+_bgImage.width() ) { for ( qreal y=-_bgImage.height(); y<rect.height()+_bgImage.height(); y=y+_bgImage.height() ) { painter->drawImage( x, y, _bgImage ); } } } else if ( opts & PHIPage::IRepeatX ) { for ( qreal x=-_bgImage.width(); x<rect.width()+_bgImage.width(); x=x+_bgImage.width() ) { painter->drawImage( x, 0, _bgImage ); } } else if ( opts & PHIPage::IRepeatY ) { for ( qreal y=-_bgImage.height(); y<rect.height()+_bgImage.height(); y=y+_bgImage.height() ) { painter->drawImage( 0, y, _bgImage ); } } else painter->drawImage( 0, 0, _bgImage ); painter->translate( -off ); }
void SCgView::updateSceneRect(const QRectF& rect) { if(!isSceneRectControlled && !sceneRect().contains(rect)) isSceneRectControlled = true; if(isSceneRectControlled) { QPointF topLeft = mapToScene(0,0); QPointF bottomRight = mapToScene(viewport()->width(), viewport()->height()); QRectF vis(topLeft, bottomRight); QRectF result = rect.adjusted(-100, -100, 100, 100).united(vis).united(sceneRect()); setSceneRect(result); emit sceneRectChanged(result); } }