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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
0
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);
        }
    }
}
Exemplo n.º 5
0
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());
        }
}
Exemplo n.º 6
0
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);
    }
}
Exemplo n.º 7
0
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);
}
    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();
    }
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
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");
	//	}
}
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();
}
Exemplo n.º 12
0
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();
}
Exemplo n.º 13
0
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);
    }
}
Exemplo n.º 14
0
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);
}
Exemplo n.º 15
0
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 ) );
  }
}
Exemplo n.º 16
0
void
AnimatorScene::setSimulationBoundaries (QPointF minPoint, QPointF maxPoint)
{
  m_minPoint = minPoint;
  m_maxPoint = maxPoint;
  qreal boundaryWidth = m_maxPoint.x () * 0.1;
  qreal boundaryHeight = m_maxPoint.y () * 0.2;
  qreal boundary = qMax (boundaryWidth, boundaryHeight);

  m_sceneMinPoint = QPointF (m_minPoint.x () - boundary, m_minPoint.y () - boundary);
  m_sceneMaxPoint = QPointF (m_maxPoint.x () + boundary, m_maxPoint.y () + boundary);

  // Make it square
  qreal minimum = qMin (m_sceneMinPoint.x (), m_sceneMinPoint.y ());
  m_sceneMinPoint = QPointF (minimum, minimum);
  qreal maximum = qMax (m_sceneMaxPoint.x (), m_sceneMaxPoint.y ());
  m_sceneMaxPoint = QPointF (maximum, maximum);
  if ((m_sceneMaxPoint.x () == 0) && (m_sceneMaxPoint.y () == 0))
    {
      m_sceneMaxPoint = QPointF (1, 1);
    }

  setSceneRect (QRectF (m_sceneMinPoint, m_sceneMaxPoint));
}
Exemplo n.º 17
0
//______________________________________________________________________________
YSPTView::YSPTView(QMenuBar *mb)
{
    //creates the view with a shared menubar

    // Sets up the subclassed QGraphicsView

    setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);


    //Set-up the scene

    fPt = new YSPeriodicTable(this);
    setScene(fPt);

    //Set-up the view
    setSceneRect(fPt->sceneRect());

    //Use ScrollHand Drag Mode to enable Panning
    setDragMode(ScrollHandDrag);

    fMenuBar = mb;
    CreateActions();
    CreateMenus();
}
// TODO: redesign in Qt way ;)
// i.e. crop as opacity mask not a copy
AvatarEditScene::AvatarEditScene(QObject *parent)
    : QGraphicsScene(parent)
{
    setSceneRect(0, 0, 480, 360);

    isSizing = false;
    isDragged = false;

    crop = QRect(0, 0, 100, 100);

    // background
    setBackgroundBrush(QPixmap(":/images/transparent.png"));
    // scaled photo
    photoItem = addPixmap(QPixmap());
    // gray it down
    photoBlurItem = addRect(QRect(), Qt::NoPen, QBrush(QColor(255, 255, 255, 127)));
    // crop
    cropItem = addPixmap(QPixmap());
    // cropper
    QPixmap pixmap = getCropper();
    cropper = pixmap.rect();
    cropperItem = addPixmap(pixmap);
    cropperItem->setOpacity(0.5);
}
Exemplo n.º 19
0
void WorkbenchGraphicsScene::initialize()
{
	setSceneRect(0,0,640, 480);
}
Exemplo n.º 20
0
void QgsComposerItem::move( double dx, double dy )
{
  QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
  setSceneRect( evalItemRect( newSceneRect ) );
}
Exemplo n.º 21
0
void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint, bool posIncludesFrame, int page )
{
  double upperLeftX = x;
  double upperLeftY = y;

  if ( page > 0 )
  {
    double h = composition()->paperHeight() + composition()->spaceBetweenPages();
    upperLeftY += ( page - 1 ) * h;
  }

  //store the item position mode
  mLastUsedPositionMode = itemPoint;

  //adjust x-coordinate if placement is not done to a left point
  if ( itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle )
  {
    upperLeftX -= width / 2.0;
  }
  else if ( itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight )
  {
    upperLeftX -= width;
  }

  //adjust y-coordinate if placement is not done to an upper point
  if ( itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight )
  {
    upperLeftY -= height / 2.0;
  }
  else if ( itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight )
  {
    upperLeftY -= height;
  }

  if ( posIncludesFrame )
  {
    //adjust position to account for frame size

    if ( qgsDoubleNear( mEvaluatedItemRotation, 0.0 ) )
    {
      upperLeftX += estimatedFrameBleed();
      upperLeftY += estimatedFrameBleed();
    }
    else
    {
      //adjust position for item rotation
      QLineF lineToItemOrigin = QLineF( 0, 0, estimatedFrameBleed(), estimatedFrameBleed() );
      lineToItemOrigin.setAngle( -45 - mEvaluatedItemRotation );
      upperLeftX += lineToItemOrigin.x2();
      upperLeftY += lineToItemOrigin.y2();
    }

    width -= 2 * estimatedFrameBleed();
    height -= 2 * estimatedFrameBleed();
  }

  //consider data defined item size and position before finalising rect
  QRectF newRect = evalItemRect( QRectF( upperLeftX, upperLeftY, width, height ) );

  setSceneRect( newRect );
}
Exemplo n.º 22
0
KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s)
        : KReportItemCheckBox(element), KReportDesignerItemRectBase(d)
{
    init(s, d);
    setSceneRect(m_pos.toScene(), m_size.toScene());
}
Exemplo n.º 23
0
bool QgsComposerItem::_readXml( const QDomElement &itemElem, const QDomDocument &doc )
{
  Q_UNUSED( doc );
  if ( itemElem.isNull() )
  {
    return false;
  }

  QgsComposerObject::readXml( itemElem, doc );

  //rotation
  setItemRotation( itemElem.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble() );

  //uuid
  mUuid = itemElem.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() );

  // temporary for groups imported from templates
  mTemplateUuid = itemElem.attribute( QStringLiteral( "templateUuid" ) );

  //id
  QString id = itemElem.attribute( QStringLiteral( "id" ), QLatin1String( "" ) );
  setId( id );

  //frame
  QString frame = itemElem.attribute( QStringLiteral( "frame" ) );
  if ( frame.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
  {
    mFrame = true;
  }
  else
  {
    mFrame = false;
  }

  //frame
  QString background = itemElem.attribute( QStringLiteral( "background" ) );
  if ( background.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
  {
    mBackground = true;
  }
  else
  {
    mBackground = false;
  }

  //position lock for mouse moves/resizes
  QString positionLock = itemElem.attribute( QStringLiteral( "positionLock" ) );
  if ( positionLock.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
  {
    setPositionLock( true );
  }
  else
  {
    setPositionLock( false );
  }

  //visibility
  setVisibility( itemElem.attribute( QStringLiteral( "visibility" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );

  //position
  int page;
  double x, y, pagex, pagey, width, height;
  bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK;

  x = itemElem.attribute( QStringLiteral( "x" ) ).toDouble( &xOk );
  y = itemElem.attribute( QStringLiteral( "y" ) ).toDouble( &yOk );
  page = itemElem.attribute( QStringLiteral( "page" ) ).toInt( &pageOk );
  pagex = itemElem.attribute( QStringLiteral( "pagex" ) ).toDouble( &pagexOk );
  pagey = itemElem.attribute( QStringLiteral( "pagey" ) ).toDouble( &pageyOk );
  width = itemElem.attribute( QStringLiteral( "width" ) ).toDouble( &widthOk );
  height = itemElem.attribute( QStringLiteral( "height" ) ).toDouble( &heightOk );
  mLastUsedPositionMode = static_cast< ItemPositionMode >( itemElem.attribute( QStringLiteral( "positionMode" ) ).toInt( &positionModeOK ) );
  if ( !positionModeOK )
  {
    mLastUsedPositionMode = UpperLeft;
  }
  if ( pageOk && pagexOk && pageyOk )
  {
    xOk = true;
    yOk = true;
    x = pagex;
    y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey;
  }

  if ( !xOk || !yOk || !widthOk || !heightOk )
  {
    return false;
  }

  mLastValidViewScaleFactor = itemElem.attribute( QStringLiteral( "lastValidViewScaleFactor" ), QStringLiteral( "-1" ) ).toDouble();

  setZValue( itemElem.attribute( QStringLiteral( "zValue" ) ).toDouble() );

  QgsExpressionContext context = createExpressionContext();

  //pen
  QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral( "FrameColor" ) );
  if ( !frameColorList.isEmpty() )
  {
    QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk, widthOk;
    int penRed, penGreen, penBlue, penAlpha;
    double penWidth;

    penWidth = itemElem.attribute( QStringLiteral( "outlineWidth" ) ).toDouble( &widthOk );
    penRed = frameColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
    penGreen = frameColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
    penBlue = frameColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
    penAlpha = frameColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
    mFrameJoinStyle = QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "frameJoinStyle" ), QStringLiteral( "miter" ) ) );

    if ( redOk && greenOk && blueOk && alphaOk && widthOk )
    {
      mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha );
      mFrameWidth = penWidth;
      QPen framePen( mFrameColor );
      framePen.setWidthF( mFrameWidth );
      framePen.setJoinStyle( mFrameJoinStyle );
      setPen( framePen );
      //apply any data defined settings
      refreshFrameColor( false, context );
    }
  }

  //brush
  QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral( "BackgroundColor" ) );
  if ( !bgColorList.isEmpty() )
  {
    QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk;
    int bgRed, bgGreen, bgBlue, bgAlpha;
    bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
    bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
    bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
    bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
    if ( redOk && greenOk && blueOk && alphaOk )
    {
      mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
      setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
    }
    //apply any data defined settings
    refreshBackgroundColor( false, context );
  }

  //blend mode
  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) );

  //opacity
  if ( itemElem.hasAttribute( QStringLiteral( "opacity" ) ) )
  {
    setItemOpacity( itemElem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1" ) ).toDouble() );
  }
  else
  {
    setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() / 100.0 );
  }

  mExcludeFromExports = itemElem.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt();
  mEvaluatedExcludeFromExports = mExcludeFromExports;

  QRectF evaluatedRect = evalItemRect( QRectF( x, y, width, height ) );
  setSceneRect( evaluatedRect );

  return true;
}
Exemplo n.º 24
0
CostScene::CostScene(int x0, int y0, int w, int h, QObject *parent):QGraphicsScene(parent){
    setSceneRect(x0,y0,w,h);
    addItem(new Text(x0+w/10,y0+h/5,w,h,"Total Cost: "));
}
Exemplo n.º 25
0
void GEvScene::UpdateLength( double newLength )
{
    setSceneRect(0.0, 0.0, newLength, sceneRect().height()) ;
}
Exemplo n.º 26
0
void ImageEditorScene::updateSceneSize() {
	setSceneRect(m_pixmap->mapToScene(m_pixmap->boundingRect()).boundingRect());
}
Exemplo n.º 27
0
	FitView(QGraphicsScene *scene) : QGraphicsView(scene) {
		setSceneRect(Config.Rect);
		setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
	}
Exemplo n.º 28
0
void GraphicsScene::changeSceneRect( int w, int h )
{
	setSceneRect(-w/2.0, -h/2.0, w, h);
	updateItems();
	doSomething();
}
Exemplo n.º 29
0
void ReportRectEntity::setSceneRect(QPointF p, QSizeF s)
{
    setSceneRect(QRectF(p, s));
}
Exemplo n.º 30
0
ControlFlowGraphScene::ControlFlowGraphScene(QObject * parent, medusa::Medusa& core, medusa::Address const& cfgAddr)
  : QGraphicsScene(parent)
  , _core(core)
{
  ogdf::Graph graph;
  ogdf::GraphAttributes graphAttr(graph, ogdf::GraphAttributes::nodeGraphics | ogdf::GraphAttributes::edgeGraphics);


  medusa::ControlFlowGraph cfg;
  core.BuildControlFlowGraph(cfgAddr, cfg);

  qreal maxBbWidth = 0.0, maxBbHeight = 0.0;

  QFontMetrics fm(font());
  std::map<ogdf::node,  BasicBlockItem*> nodes;
  std::map<ogdf::edge,  EdgeItem*      > edges;
  std::map<medusa::u64, ogdf::node     > usedBscBlock;
  auto addBscBlk = [&](medusa::u64 bbId) -> BasicBlockItem*
  {
    auto itBscBlk = usedBscBlock.find(bbId);
    if (itBscBlk != std::end(usedBscBlock))
      return nodes[ usedBscBlock[ bbId ] ];
      
    auto bbItem = new BasicBlockItem(this, _core, cfg.GetGraph()[bbId].GetAddresses());
    auto newNode = graph.newNode();
    auto rect = bbItem->boundingRect();
    graphAttr.width()[newNode]  = rect.width();
    graphAttr.height()[newNode] = rect.height();
    maxBbWidth  = std::max(maxBbWidth,  rect.width());
    maxBbHeight = std::max(maxBbHeight, rect.height());
    nodes[newNode]     = bbItem;
    usedBscBlock[bbId] = newNode;
    return bbItem;
  };

  auto const& g = cfg.GetGraph();

  auto vertexRange = boost::vertices(g);
  for (auto vertexIter = vertexRange.first; vertexIter != vertexRange.second; ++vertexIter)
    addBscBlk(*vertexIter);

  auto edgeRange = boost::edges(g);
  for (auto edgeIter = edgeRange.first; edgeIter != edgeRange.second; ++edgeIter)
  {
    auto srcBb     = addBscBlk(edgeIter->m_source);
    auto tgtBb     = addBscBlk(edgeIter->m_target);
    auto newEdge   = graph.newEdge(usedBscBlock[edgeIter->m_source], usedBscBlock[edgeIter->m_target]);
    auto edgeItem  = new EdgeItem(srcBb, tgtBb, g[*edgeIter].GetType());
    edges[newEdge] = edgeItem;
  }

  auto OHL = new ogdf::OptimalHierarchyLayout;
  OHL->nodeDistance(25.0);
  OHL->layerDistance(50.0);
  OHL->weightBalancing(0.0);
  OHL->weightSegments(0.0);

  ogdf::SugiyamaLayout SL;
  SL.setRanking(new ogdf::OptimalRanking);
  SL.setCrossMin(new ogdf::MedianHeuristic);
  SL.alignSiblings(false);
  SL.setLayout(OHL);
  SL.call(graphAttr);

  for (auto nodeIter = std::begin(nodes); nodeIter != std::end(nodes); ++nodeIter)
  {
    addItem(nodeIter->second);
    QRectF bbRect = nodeIter->second->boundingRect();
    qreal x = graphAttr.x(nodeIter->first) - (bbRect.width()  / 2);
    qreal y = graphAttr.y(nodeIter->first) - (bbRect.height() / 2);
    nodeIter->second->setPos(x, y);
  }

  for (auto edgeIter = std::begin(edges); edgeIter != std::end(edges); ++edgeIter)
  {
    auto const& bends = graphAttr.bends(edgeIter->first);
    edgeIter->second->setBends(bends);
    addItem(edgeIter->second);
  }

  setSceneRect(0, 0, graphAttr.boundingBox().width() + maxBbWidth, graphAttr.boundingBox().height() + maxBbHeight);
}