本文整理汇总了C++中setSceneRect函数的典型用法代码示例。如果您正苦于以下问题:C++ setSceneRect函数的具体用法?C++ setSceneRect怎么用?C++ setSceneRect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setSceneRect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: views
void GraphicsCardSelectionScene::calculateScene()
{
// check if there is a view this scene is drawn in
if(views().isEmpty()) return;
QGraphicsView *view = views().first();
int n = items().count();
if(n < 1) return;
qreal w, h, xoffset;
qreal f = 1.0;
do {
w = view->viewport()->width() * f * 0.8; // the width of the arc
h = view->viewport()->height() * f * 0.6; // the height of the arc
xoffset = w / n;
f -= 0.1;
} while(xoffset >= 45.0 && f > 0.1);
qreal x = - xoffset * ((n == 1) ? 0 : (n / 2)); // starting position
qreal r = (w*w + h*h) / (2 * h); // the radius of the circle as a function of w and h
if(n % 2) x -= xoffset / 2;
for(int i = 0; i < n; ++i)
{
GraphicsGameCardItem *item;
item = static_cast<GraphicsGameCardItem*>(items().at(i));
qreal y = r + qSqrt(r*r - x*x); // the y offset for this card on the arc
item->setOffset(x, -y);
item->setTransformOriginPoint(item->offset());
item->setRotation(360 * qAsin(x/r) / (2 * M_PI)); // the card's rotation angle as degrees
x += xoffset;
}
QRectF rect = sceneRect();
setSceneRect(rect.x(), rect.y() -50.0, rect.width(), rect.height() +50.0);
}
示例2: setSceneRect
void CurvedTreeGraphicsScene::updateTree()
{
m_height = m_stepCount * g_settings->treeStepHeight;
setSceneRect(0.0, 0.0, m_width, m_height);
QPen pen = getTreePen();
//Since curved trees can be very narrow during early stages
//of a simulation, it will be drawn wider if it takes up less
//than a defined fraction of the available width.
double minX = 1.0;
double maxX = 0.0;
for (std::list<CurvedTreeLine *>::iterator i = m_lines.begin(); i != m_lines.end(); ++i)
{
CurvedTreeLine * line = *i;
for (size_t j = 0; j < line->m_points.size(); ++j)
{
double pointX = line->m_points[j].x();
if (pointX < minX)
minX = pointX;
if (pointX > maxX)
maxX = pointX;
}
}
double rangeFromCentre = std::max(maxX - 0.5, 0.5 - minX);
//0.45 is the target range: taking up most of the available space.
//If it is less than this, we'll widen the tree.
//If it is more, the widening factor will be less than 1 and the
//tree will be narrowed.
double wideningFactor = 0.45 / rangeFromCentre;
//A very narrow tree will look odd if overly widened, so limit
//widening to a factor of 20.
if (wideningFactor > 20.0)
wideningFactor = 20.0;
for (std::list<CurvedTreeLine *>::iterator i = m_lines.begin(); i != m_lines.end(); ++i)
(*i)->updateLine(m_height, m_width, pen, wideningFactor);
}
示例3: removeItem
void Segmenter::init(DividerList* divlist, QString imagepath)
{
// clear the divider list
if (m_dividers != NULL) {
DividerList::iterator iter;
for (iter = m_dividers->begin(); iter != m_dividers->end(); iter++) {
if ((*iter)->scene() == this) {
removeItem(*iter);
}
}
}
// set the bg image to the new path
m_imagebg->setPixmap(QPixmap(imagepath));
// make sure the scene bounds the image properly
setSceneRect(m_imagebg->boundingRect());
// refresh the height of the marker dividers
m_markerdivider->refreshHeight();
//this->views().first()->fitInView(m_imagebg->boundingRect(), Qt::KeepAspectRatio);
// set out divider list to point to the given one
m_dividers = divlist;
// draw any existing dividers into the scene by setting their
// parent item to the image bg
DividerList::iterator iter;
for (iter = m_dividers->begin(); iter != m_dividers->end(); iter++)
(*iter)->setParentItem(m_imagebg);
// ensure the move focus belongs to the draw marker dividers
grabDivider(m_markerdivider);
update();
// FIXME: move this logic somewhere nicer
emit dividersChanged();
}
示例4: size
void NetworkEditorView::fitNetwork() {
const ProcessorNetwork* network = InviwoApplication::getPtr()->getProcessorNetwork();
if (network) {
if (network->getProcessors().size() > 0) {
QRectF br = networkEditor_->itemsBoundingRect().adjusted(-50, -50, 50, 50);
QSizeF viewsize = size();
QSizeF brsize = br.size();
if (brsize.width() < viewsize.width()) {
br.setLeft(br.left() - 0.5*(viewsize.width() - brsize.width()));
br.setRight(br.right() + 0.5*(viewsize.width() - brsize.width()));
}
if (brsize.height() < viewsize.height()) {
br.setTop(br.top() - 0.5*(viewsize.height() - brsize.height()));
br.setBottom(br.bottom() + 0.5*(viewsize.height() - brsize.height()));
}
setSceneRect(br);
fitInView(br, Qt::KeepAspectRatio);
}
}
}
示例5: sceneRect
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);
if (col == 0)
playersByColumn[col][row]->setPos(phasesToolbar->getWidth(), playersByColumn[col][row]->y());
else
playersByColumn[col][row]->setPos(phasesToolbar->getWidth() + (newWidth - phasesToolbar->getWidth()) / 2, playersByColumn[col][row]->y());
}
}
示例6: sceneRect
void chatGraphicsScene::verticalReposition()
{
m_verticalPosForNewMessage = 0;
chatMsgGraphicsItem* item = 0;
for(int i = 0; i < m_items.size(); ++i)
{
item = m_items.at(i);
item->setViewWidth(views().at(0)->size().width());
item->setPos(0, m_verticalPosForNewMessage);
int height = item->boundingRect().height();
m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing;
}
QRectF rect = sceneRect();
if(item)
{
rect.setHeight(m_verticalPosForNewMessage);
rect.setWidth(item->getMaxWidth() + item->getBoxStartLength() - 4);
setSceneRect(rect);
}
}
示例7: QGraphicsView
CSceneWidget::CSceneWidget(qint32 compkey, qint32 width, qint32 height, QWidget *parent) :
QGraphicsView(parent),
_compkey(compkey),
_currentItem(NULL),
m_currentImage(NULL),
_resizeBegin(false),
m_gridEnabled(false),
m_cellWidth(10),
_timerId(0),
_aspectRatioMode(Qt::KeepAspectRatio)
{
initSceneMenu();
initItemsMenu();
QGraphicsScene *scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->setSceneRect(0,0,width,height);
setScene(scene);
setSceneRect(0,0,width,height);
setTransformationAnchor(AnchorUnderMouse);
setCacheMode(CacheBackground);
setViewportUpdateMode(BoundingRectViewportUpdate);
setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing
| QGraphicsView::DontClipPainter
| QGraphicsView::DontSavePainterState);
setMouseTracking(true);
CGraphicsItem *background = new CGraphicsItem(_compkey);
background->setPos(0,0);
background->setSize(QSize(width,height));
background->setImageFitMode(CGraphicsItem::ImageStretch/*ImageFit*/);
scene->addItem(background);
//scene->addWidget(new QLabel("use +/- for zoming")); // TODO: tempory removed
SettingsManager setting("Video");
setEnabledOpenGl(setting.getBoolValue("OpenGL"));
_timerId = startTimer(1000 / 25);
}
示例8: resizeEvent
virtual void resizeEvent(QResizeEvent *event) {
QGraphicsView::resizeEvent(event);
QGraphicsScene *scene = this->scene();
if (scene) {
QRectF newSceneRect(0, 0, event->size().width(), event->size().height());
scene->setSceneRect(newSceneRect);
if (scene->sceneRect().size() != event->size()) {
QSizeF from(scene->sceneRect().size());
QSizeF to(event->size());
QTransform transform;
transform.scale(to.width() / from.width(), to.height() / from.height());
setTransform(transform);
} else {
resetTransform();
}
setSceneRect(scene->sceneRect());
}
MainWindow *main_window = qobject_cast<MainWindow *>(parentWidget());
if (main_window)
main_window->fitBackgroundBrush();
}
示例9: if
QVariant ReportRectEntity::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange && scene()) {
QPointF newPos = value.toPointF();
newPos = dynamic_cast<ReportScene*>(scene())->gridPoint(newPos);
if (newPos.x() < 0)
newPos.setX(0);
else if (newPos.x() > (scene()->width() - rect().width()))
newPos.setX(scene()->width() - rect().width());
if (newPos.y() < 0)
newPos.setY(0);
else if (newPos.y() > (scene()->height() - rect().height()))
newPos.setY(scene()->height() - rect().height());
return newPos;
} else if (change == ItemPositionHasChanged && scene()) {
m_ppos->setScenePos(value.toPointF());
} else if (change == ItemSceneHasChanged && scene() && m_psize) {
QPointF newPos = pos();
newPos = dynamic_cast<ReportScene*>(scene())->gridPoint(newPos);
if (newPos.x() < 0)
newPos.setX(0);
else if (newPos.x() > (scene()->width() - rect().width()))
newPos.setX(scene()->width() - rect().width());
if (newPos.y() < 0)
newPos.setY(0);
else if (newPos.y() > (scene()->height() - rect().height()))
newPos.setY(scene()->height() - rect().height());
setSceneRect(newPos, m_psize->toScene());
}
return QGraphicsItem::itemChange(change, value);
}
示例10: QGraphicsScene
DrawingCanvas::DrawingCanvas(DrawingInfo *info, FileParser *in_parser, QObject *parent)
: QGraphicsScene(parent),
parser(in_parser),
drawingInfo(info),
myBackgroundColor(Qt::white),
myMoveCursor(QPixmap(":/images/cursor_move.png")),
myRotateCursor(QPixmap(":/images/cursor_rotate.png")),
myBackgroundAlpha(DEFAULT_BACKGROUND_OPACITY/100.0*255)
{
myMode = Select;
bondline = 0;
selectionRectangle = 0;
myArrow = 0;
myTempMoveItem = 0;
// Hack to make the background border disappear (unless background color is changed)
//myBackgroundColor.setAlpha(myBackgroundAlpha);
myBackgroundColor.setAlpha(0);
setBackgroundBrush(QBrush(myBackgroundColor));
setSceneRect(QRectF(0, 0, DEFAULT_SCENE_SIZE_X, DEFAULT_SCENE_SIZE_Y));
// If the user provided a filename from the command line, there's a molecule in the parser.
// The filename is empty, however if that molecule came from a project.
if(parser->numMolecules() && !in_parser->fileName().isEmpty()) {
loadFromParser();
}
// xRot = yRot = zRot = 0;
// for(int r = 0; r < 3; r++)
// {
// for(int c = 0; c < 3; c++)
// {
// rotationMatrix[r][c] = ((r == c) ? 1 : 0);
// //printf("%6.4f ", rotationMatrix[r][c]);
// }
// //printf("\n");
// }
}
示例11: Q_UNUSED
void KoReportDesignerItemText::slotPropertyChanged(KoProperty::Set &s, KoProperty::Property &p)
{
Q_UNUSED(s);
if (p.name() == "Position") {
m_pos.setUnitPos(p.value().toPointF(), KRPos::DontUpdateProperty);
} else if (p.name() == "Size") {
m_size.setUnitSize(p.value().toSizeF(), KRPos::DontUpdateProperty);
} else if (p.name() == "Name") {
//For some reason p.oldValue returns an empty string
if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(m_oldName);
} else {
m_oldName = p.value().toString();
}
}
setSceneRect(m_pos.toScene(), m_size.toScene(), DontUpdateProperty);
if (m_reportDesigner)
m_reportDesigner->setModified(true);
if (scene())
scene()->update();
}
示例12: float
void GraphicsScene::drawBackground(QPainter *painter, const QRectF &)
{
float width = float(painter->device()->width());
float height = float(painter->device()->height());
setSceneRect(0, 0, width, height);
painter->beginNativePainting();
setStates();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
gluPerspective(60.0, width / height, 0.01, 15.0);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0,0,-4);
glScalef(1.5,1,-2);
emit render();
defaultStates();
painter->endNativePainting();
}
示例13: QGraphicsView
Viewport::Viewport(QGraphicsScene* scene, QWidget* parent)
: QGraphicsView(parent), scene(scene),
scale(100), pitch(0), yaw(0), angle_locked(false),
view_selector(new ViewSelector(this)),
mouse_info(new QGraphicsTextItem("\n")),
scene_info(new QGraphicsTextItem()), hover(false),
gl_initialized(false), ui_hidden(false)
{
setScene(scene);
setStyleSheet("QGraphicsView { border-style: none; }");
setSceneRect(-width()/2, -height()/2, width(), height());
setRenderHints(QPainter::Antialiasing);
auto gl = new QOpenGLWidget(this);
setViewport(gl);
for (auto i : {mouse_info, scene_info})
{
i->setDefaultTextColor(Colors::base04);
scene->addItem(i);
}
}
示例14: mapToScene
void CityLordView::mouseMoveEvent(QMouseEvent * e){
int move;
QPointF currentPos = mapToScene(e->pos());
if(startMouse.x() < currentPos.x() and currentPos.x()>-1520){ // -rows*baselength
move = currentPos.x()-startMouse.x();
px-= move;
lastPos.setX(lastPos.x()-move);
}else if(startMouse.x() > currentPos.x() and currentPos.x()<1520){ // rows*baselength
move = startMouse.x()-currentPos.x();
px+= move;
lastPos.setX(lastPos.x()+move);
}
if(startMouse.y() < currentPos.y() and currentPos.y()>0){ // 0
move = currentPos.y()-startMouse.y();
py-=move;
lastPos.setY(lastPos.y()-move);
}else if(startMouse.y() > currentPos.y() and currentPos.y()<1500){// columns*baseheight
move = startMouse.y()-currentPos.y();
py+=move;
lastPos.setY(lastPos.y()+move);
}
lastPos = currentPos;
setSceneRect(-((WIDTH/2)-(BASE.width()/2))+px, py, WIDTH-2, HEIGHT-2);
}
示例15: legendRenderer
void QgsComposerLegend::adjustBoxSize()
{
if ( !mSizeToContents )
return;
if ( !mInitialMapScaleCalculated )
{
// this is messy - but until we have painted the item we have no knowledge of the current DPI
// and so cannot correctly calculate the map scale. This results in incorrect size calculations
// for marker symbols with size in map units, causing the legends to initially expand to huge
// sizes if we attempt to calculate the box size first.
return;
}
QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
QSizeF size = legendRenderer.minimumSize();
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
if ( size.isValid() )
{
QRectF targetRect = QRectF( pos().x(), pos().y(), size.width(), size.height() );
//set new rect, respecting position mode and data defined size/position
setSceneRect( evalItemRect( targetRect, true ) );
}
}