Ejemplo n.º 1
0
Archivo: item.cpp Proyecto: nfrey/qreal
QRectF Item::sceneBoundingRectCoord(QPoint const &topLeftPicture)
{
	QRectF itemBoundingRect = calcNecessaryBoundingRect();
	qreal const x1 = scenePos().x() + itemBoundingRect.x() - topLeftPicture.x();
	qreal const y1 = scenePos().y() + itemBoundingRect.y() - topLeftPicture.y();
	return QRectF(x1, y1, itemBoundingRect.width(), itemBoundingRect.height());
}
Ejemplo n.º 2
0
void PictoProcedure::toXml( QDomDocument& doc, QDomNode& node ) const
{/*{{{*/
     QDomElement item = doc.createElement( "Procedure" );
     node.appendChild( item );
     QDomElement position = doc.createElement( "Position" );
     position.appendChild( doc.createTextNode( QString( "%1;%2" ).arg( scenePos().x() )
                           .arg( scenePos().y() ) ) );
     item.appendChild( position );
     QDomElement style = doc.createElement( "StyleLien" );
     style.appendChild( doc.createTextNode(
                             ( liaison_ ) ?
                             QString::number( static_cast<int>( liaison_->style() ) ) :
                             "1" ) ) ;
     item.appendChild( style );
     QDomElement preAssertion = doc.createElement( "PreAssertion" );
     preAssertion.appendChild( doc.createTextNode( labels_.at( 0 )->label() ) );
     item.appendChild( preAssertion );
     QDomElement postAssertion = doc.createElement( "PostAssertion" );
     postAssertion.appendChild( doc.createTextNode( labels_.at( 2 )->label() ) );
     item.appendChild( postAssertion );
     QDomElement titre = doc.createElement( "Titre" );
     titre.appendChild( doc.createTextNode( labels_.at( 1 )->label() ) );
     item.appendChild( titre );
     QDomElement details = doc.createElement( "DetailsVisible" );
     details.appendChild( doc.createTextNode( detail_ ? "1" : "0" ) );
     item.appendChild( details );
     QDomElement detailsVide = doc.createElement( "DetailsVideVisible" );
     detailsVide.appendChild( doc.createTextNode( emptyDetail_ ? "1" : "0" ) );
     item.appendChild( detailsVide );
     QDomElement enfants = doc.createElement( "Enfants" );
     item.appendChild( enfants );
     AncreItem* picto;
     foreach( picto, children_ )
     static_cast<Pictogramme*>( picto )->toXml( doc, enfants );
}/*}}}*/
Ejemplo n.º 3
0
void TraceGraphPoint::updatePositionOnScene(const Trace::TracePointer& i_trace) {
  LOG_DEBUG("Updating the position on the scene of this Point");
  switch (m_positionOnTrace) {
  case TraceGraphPoint::StartPoint : {
    setPos(QPoint(0,0));
    // No need to change the position, 0,0 is ALWAYS the start point
    break;
  }
  case TraceGraphPoint::EndPoint : {
    if (i_trace->getEndPoint() != scenePos()) {
      LOG_DEBUG("Update end point on scene");
      setPos(Point2D(i_trace->getEndPoint() - i_trace->getStartPoint()));
    }
    break;
  }
  case TraceGraphPoint::CenterPoint : {
    if (RotationTrace::RotationTracePointer rotationTrace =
        std::dynamic_pointer_cast<RotationTrace>(i_trace)) {
      if (rotationTrace->getCentrePoint() != scenePos())
      LOG_DEBUG("Update Center point on scene");
      setPos(Point2D(rotationTrace->getCentrePoint() - i_trace->getStartPoint()));
    } else {
      LOG_ERROR("Could not convert the trace to a rotation" <<
    " trace while the point was a center point!");
    }
    break;
  }
  default : {
    LOG_ERROR("unknown PointPosition");
    break;
  }}
}
Ejemplo n.º 4
0
void CommonItemMECS::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    QGraphicsItem::mouseReleaseEvent(event);

    setX(snapToGrid(scenePos().x()));
    setY(snapToGrid(scenePos().y()));
    update();
}
Ejemplo n.º 5
0
Avoid::Point Handle::getPointPosition(void)
{
    Avoid::Point retVal;

    retVal.x = scenePos().x();
    retVal.y = scenePos().y();

    return retVal;
}
Ejemplo n.º 6
0
void Curve::changeDragState(qreal x, qreal y)
{
	Item::changeDragState(x, y);
	if (QRectF(QPointF(mC1.x() + scenePos().x(), mC1.y() + scenePos().y())
			, QSizeF(0, 0)).adjusted(-resizeDrift, -resizeDrift, resizeDrift, resizeDrift).contains(QPointF(x, y)))
	{
		mDragState = Ctrl;
	}
}
QPointF CopyFilterGUIChannelItem::getPerimeterPointTo(QPointF oppositePoint)
{
    QRectF rect = boundingRect();

    if (output)
        return scenePos() + QPointF(rect.center().x(), rect.top());
    else
        return scenePos() + QPointF(rect.center().x(), rect.top() + rect.height());
}
Ejemplo n.º 8
0
QVariant SCgObject::itemChange(GraphicsItemChange change, const QVariant &value)
{
    // item selection changed
    if (change == QGraphicsItem::ItemSelectedHasChanged)
    {
        if (isSelected())
        {
            mColor = scg_cfg_get_value_color(scg_key_element_color_selected);//QColor(255, 128, 64);
            //setCursor(QCursor(Qt::SizeAllCursor));
        }
        else
        {
            mColor = scg_cfg_get_value_color(scg_key_element_color_normal);//QColor(0, 0, 0);
            //setCursor(QCursor(Qt::ArrowCursor));
        }
    }

    // move to correct position automaticly
    if (change == QGraphicsItem::ItemParentChange && scene())
    {
        // we need to set this flag to prevent processing ItemPositionHasChanged,
        // because item position at this moment not actual
        mParentChanging = true;
        QGraphicsItem* newParent = value.value<QGraphicsItem*>();
        if(newParent)
            setPos(newParent->mapFromScene(scenePos()));
        else
            setPos(scenePos());
    }

    if (change == QGraphicsItem::ItemParentHasChanged)
    {
        // now item position has valid value
        mParentChanging = false;
        updateConnected();
    }

    // Change stacking order
    if (scene() && change == QGraphicsItem::ItemSelectedHasChanged
                && isSelected() && scene()->selectedItems().size() == 1)
    {
        QGraphicsItem* top = this;
        QList<QGraphicsItem*> lst = scene()->items();
        foreach(QGraphicsItem* it, lst)
        {
            if(it != this &&
               it->type() == type() &&
               it->parentItem() == parentItem())
            {
                it->stackBefore(top);
                top = it;
            }
        }
    }
Ejemplo n.º 9
0
void Clock::save()
{
    LxQt::Settings *m_config = m_parent->config();
    QString m_configId = m_parent->configId();
    m_config->beginGroup(m_configId);
    m_config->setValue("plugin", "analogclock");
    m_config->setValue("x", scenePos().x());
    m_config->setValue("y", scenePos().y());
    m_config->setValue("showseconds", mShowSeconds);
    m_config->endGroup();
}
void StelAppGraphicsWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
{
	QGraphicsWidget::resizeEvent(event);
	const float w = geometry().width();
	const float h = geometry().height();
	const float x = scenePos().x();
	const float y = scene()->sceneRect().height() - (scenePos().y() + geometry().height());
	
	stelApp->windowHasBeenResized(x, y, w, h);
	renderer->viewportHasBeenResized(scene()->sceneRect().size().toSize());
}
Ejemplo n.º 11
0
QVariant control_point_2DNode::itemChange
(
  GraphicsItemChange change,
  const QVariant &value
)
{
  const QVariant variant = QGraphicsItem::itemChange(change, value);
  _x = scenePos().x();
  _y = scenePos().y();
  return variant;
}
Ejemplo n.º 12
0
QPair<QDomElement, Item::DomElementTypes> PointPort::generateItem(QDomDocument &document, const QPoint &topLeftPicture)
{
	QRectF itemBoundingRect = boundingRect().adjusted(scalingDrift, scalingDrift, -scalingDrift, -scalingDrift);
	QDomElement pointPort = document.createElement("pointPort");
	const int x = static_cast<int>(scenePos().x() + itemBoundingRect.x() + mRadius - topLeftPicture.x());
	const int y = static_cast<int>(scenePos().y() + itemBoundingRect.y() + mRadius - topLeftPicture.y());
	pointPort.setAttribute("y", setSingleScaleForDoc(4, x, y));
	pointPort.setAttribute("x", setSingleScaleForDoc(0, x, y));
	pointPort.setAttribute("type", mType);

	return QPair<QDomElement, Item::DomElementTypes>(pointPort, mDomElementType);
}
Ejemplo n.º 13
0
Archivo: line.cpp Proyecto: nfrey/qreal
QPair<QDomElement, Item::DomElementTypes> Line::generateItem(QDomDocument &document, QPointF const &topLeftPicture)
{
    qreal const x1 = scenePos().x() + line().x1() - topLeftPicture.x();
    qreal const y1 = scenePos().y() + line().y1() - topLeftPicture.y();
    qreal const x2 = scenePos().x() + line().x2() - topLeftPicture.x();
    qreal const y2 = scenePos().y() + line().y2() - topLeftPicture.y();

    QDomElement line = setPenBrushToDoc(document, "line");
    setXandY(line, QRectF(x1, y1, x2 - x1, y2 - y1));

    return QPair<QDomElement, Item::DomElementTypes>(line, mDomElementType);
}
/**
	Exporte la borne en XML
	@param xml_document Document XML a utiliser pour creer l'element XML
	@return un element XML decrivant la borne
*/
const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const {
	QDomElement xml_element = xml_document.createElement("terminal");
	
	// ecrit la position de la borne
	xml_element.setAttribute("x", QString("%1").arg(scenePos().x()));
	xml_element.setAttribute("y", QString("%1").arg(scenePos().y()));
	
	// ecrit l'orientation de la borne
	xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));
	// Write name and number to XML
	
	return(xml_element);
}
void StelAppGraphicsWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
{
	QGraphicsWidget::resizeEvent(event);
	stelApp->glWindowHasBeenResized(scenePos().x(), scene()->sceneRect().height()-(scenePos().y()+geometry().height()), geometry().width(), geometry().height());
	if (backgroundBuffer)
	{
		delete backgroundBuffer;
		backgroundBuffer = NULL;
	}
	if (foregroundBuffer)
	{
		delete foregroundBuffer;
		foregroundBuffer = NULL;
	}
}
Ejemplo n.º 16
0
void ReportRectEntity::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
    qreal w, h;

    QPointF p  = dynamic_cast<ReportScene*>(scene())->gridPoint(event->scenePos());
    w = p.x() - scenePos().x();
    h = p.y() - scenePos().y();

    //TODO use an enum for the directions

    switch (m_grabAction) {
    case 1:
        if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() > 0)
            setSceneRect(QPointF(p.x(), p.y()), QSizeF(sceneRect().x() - p.x() + rect().width(), sceneRect().y() - p.y() + rect().height()));
        break;
    case 2:
        if (sceneRect().y() - p.y() + rect().height() > 0)
            setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(rect().width(), sceneRect().y() - p.y() + rect().height()));
        break;
    case 3:
        if (sceneRect().y() - p.y() + rect().height() > 0 && w > 0)
            setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(w, sceneRect().y() - p.y() + rect().height()));
        break;
    case 4:
        if (w > 0)
            setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, (rect().height())));
        break;
    case 5:
        if (h > 0 && w > 0)
            setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, h));
        break;
    case 6:
        if (h > 0)
            setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF((rect().width()), h));
        break;
    case 7:
        if (sceneRect().x() - p.x() + rect().width() > 0 && h > 0)
            setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), h));
        break;
        break;
    case 8:
        if (sceneRect().x() - p.x() + rect().width() > 0)
            setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), rect().height()));
        break;
    default:
        QGraphicsItem::mouseMoveEvent(event);
    }
}
Ejemplo n.º 17
0
void MainWindow::enterLocation() {
	auto player = world()->player();
	if (!player) {
		qDebug("No player. Will not enter any location");
		return;
	}
	auto global_pos = player->scenePos();
	qDebug() << "Player global position:" << global_pos.x() << global_pos.y();
	auto global_cell = world()->globalField()->cell(global_pos);
	auto local_pos = global_pos * global_cell->sceneMatrix().inverted();
	qDebug() << "Player local position:" << local_pos.x() << local_pos.y();
	if (global_cell) {
		//world()->globalField()->removeItem(player);
		auto v = global_cell->localField();
		connect(v, SIGNAL(toggleInventory(Character*)), ui->m_inventory, SLOT(toggle(Character*)));
		ui->m_render_view->setScene(v);
		//auto s = GLOBAL_FIELD_SIZE / (float)GLOBAL_FIELD_CELL_REAL_SIZE;
		ui->m_render_view->resetTransform();		
		auto local_cell = v->cell(local_pos);
		local_pos = global_pos * local_cell->sceneMatrix().inverted();
		//local_pos = local_pos * cell->sceneMatrix().inverted();
		qDebug() << "Player local local position:" << local_pos.x() << local_pos.y();
		world()->player()->setParentItem(local_cell);
		world()->player()->setPos(local_pos);	
		world()->setLocalField(v);
		if (player)
			ui->m_render_view->centerOn(player);
	}
}
Ejemplo n.º 18
0
void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint & dropPoint)
{
    QPoint point = dropPoint + scenePos().toPoint();
    int x = -1;
    if (settingsCache->getHorizontalHand()) {
        for (x = 0; x < cards.size(); x++)
            if (point.x() < ((CardItem *) cards.at(x))->scenePos().x())
                break;
    } else {
        for (x = 0; x < cards.size(); x++)
            if (point.y() < ((CardItem *) cards.at(x))->scenePos().y())
                break;
    }
    
    Command_MoveCard cmd;
    cmd.set_start_player_id(startZone->getPlayer()->getId());
    cmd.set_start_zone(startZone->getName().toStdString());
    cmd.set_target_player_id(player->getId());
    cmd.set_target_zone(getName().toStdString());
    cmd.set_x(x);
    cmd.set_y(-1);
    
    for (int i = 0; i < dragItems.size(); ++i)
        cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
    
    player->sendGameCommand(cmd);
}
Ejemplo n.º 19
0
void LinkDialogGraphicsScene::offsetItems(float yIncrement, bool scrollLeft) {
    auto proc = scrollLeft ? srcProcessor_ : dstProcessor_;

    auto items = proc->getPropertyItemList();
    while (!items.empty() && items.back()->hasSubProperties() && items.back()->isExpanded()) {
        items = items.back()->getSubPropertyItemList();
    }
    qreal miny = std::numeric_limits<double>::lowest();
    if (!items.empty()) {
        miny = items.back()->scenePos().y();
    }

    auto view = views().front();
    auto top = view->mapToScene(QPoint(0, 0)).y();

    QPointF pos = proc->scenePos();
    qreal newy = std::min(pos.y() + yIncrement,
                          top + static_cast<qreal>(linkdialog::processorHeight));

    qreal listHeight = miny - pos.y();
    newy = std::max(newy, top - (listHeight - linkdialog::processorHeight));
    proc->setPos(pos.x(), newy);

    update();
}
Ejemplo n.º 20
0
/**
 * Sets 'y' coordinate  of end of line.
 *
 * @param yPos This represents 'y' in scene coords which will become
 *             end of line.
 */
void SeqLineWidget::setEndOfLine(qreal yPos)
{
    qreal len = yPos - scenePos().y();
//:TODO:    if (len > 0.0) {
        setLength(len);
//    }
}
void GroupingGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option)
    Q_UNUSED(widget)

    QSettings settings;
    _font = settings.value("Visualisation/Font", QFont("sans-serif", 10)).value<QFont>();
    int displayOptions = settings.value("Visualisation/Grouping/DisplayOptions", (DisplayCapturing | DisplayNamed)).toInt();
    double horizontalPadding = settings.value("Visualisation/Grouping/HorizontalPadding", 8.0).toDouble();
    double verticalPadding   = settings.value("Visualisation/Grouping/VerticalPadding", 6.0).toDouble();
    double cornerRadius   = settings.value("Visualisation/Grouping/CornerRadius", 5.0).toDouble();
    QColor bgColor = settings.value("Visualisation/Grouping/Color", QColor(245,245,245)).value<QColor>();

    painter->setFont(_font);
    painter->setBrush(bgColor);
    painter->setPen(Qt::black);

    if((_capturing && (displayOptions & DisplayCapturing))
            || (!_capturing && (displayOptions & DisplayNonCapturing))
            || (!_name.isEmpty() && (displayOptions & DisplayNamed))
            )
    {
        QRectF drawRect = boundingRect();
        // Align the rect to the pixel grid
        if(qRound(scenePos().x()) == scenePos().x())
        {
            drawRect.setX(0.5);
            drawRect.setWidth(drawRect.width()-.5);
        }
        if(qRound(scenePos().y()) == scenePos().y())
        {
            drawRect.setHeight(drawRect.height()-.5);
            drawRect.setY(0.5);
        }
        painter->drawRoundedRect(drawRect, cornerRadius, cornerRadius);

        if(!_name.isEmpty())
            painter->drawText(QRectF(
                                  horizontalPadding,
                                  verticalPadding,
                                  _metrics.width(_title),
                                  _metrics.height()),
                              Qt::AlignCenter,
                              _title);
    }
}
Ejemplo n.º 22
0
void AbstractContent::slotConfigure()
{
    ButtonItem * item = dynamic_cast<ButtonItem *>(sender());
    if (item)
        emit requestConfig(item->scenePos().toPoint());
    else
        emit requestConfig(scenePos().toPoint());
}
Ejemplo n.º 23
0
void SceneItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
    // don't handle clicks for things that are outside of the scene
    int adjust = -TILE_SIZE;
    QRectF rect = scene()->sceneRect().adjusted(0, 0, adjust, adjust);
    if (!rect.contains(scenePos()))
        return;

    if (event->button() == Qt::LeftButton)
        this->editItem();
}
void QBlockDiagramLinkEnd::mouseMoveEvent( QGraphicsSceneMouseEvent * event )
{
    QBlockDiagramConnector::mouseMoveEvent(event);
    m_bIsMoving = true;
    m_pSnapedSlot = scene()->nodeSlotAroundLinkEnd(this);
    if(m_pSnapedSlot != NULL)
    {
      setPos(pos()+(m_pSnapedSlot->scenePos()-scenePos()));
    }
}
Ejemplo n.º 25
0
    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event){
        QGraphicsEllipseItem::mouseMoveEvent(event);

        if(connector_){
            QLineF line;
            line.setP1(scenePos());
            line.setP2(event->scenePos());

            connector_->setLine(line);
        }
    }
Ejemplo n.º 26
0
Archivo: item.cpp Proyecto: nfrey/qreal
void Item::changeDragState(qreal x, qreal y)
{
	if (QRectF(QPointF(mX1 + scenePos().x(), mY1 + scenePos().y()), QSizeF(0, 0)).adjusted(-resizeDrift, -resizeDrift, resizeDrift, resizeDrift).contains(QPointF(x, y)))
		mDragState = TopLeft;
	else if (QRectF(QPointF(mX2 + scenePos().x(), mY1 + scenePos().y()), QSizeF(0, 0)).adjusted(-resizeDrift, -resizeDrift, resizeDrift, resizeDrift).contains(QPointF(x, y)))
		mDragState = TopRight;
	else if (QRectF(QPointF(mX1 + scenePos().x(), mY2 + scenePos().y()), QSizeF(0, 0)).adjusted(-resizeDrift, -resizeDrift, resizeDrift, resizeDrift).contains(QPointF(x, y)))
		mDragState = BottomLeft;
	else if (QRectF(QPointF(mX2 + scenePos().x(), mY2 + scenePos().y()), QSizeF(0, 0)).adjusted(-resizeDrift, -resizeDrift, resizeDrift, resizeDrift).contains(QPointF(x, y)))
		mDragState = BottomRight;
	else
		mDragState = None;
}
Ejemplo n.º 27
0
QRectF ScenePixmapItem::sceneBoundingRect() {
	if( !parentItem() ){
// 		if (d_ptr->parent || d_ptr->hasTransform)
// 		qDebug() << "ScenePixmapItem::has parent";
		return sceneTransform().mapRect(boundingRect());
	}
	else {
// 		qDebug() << "ScenePixmapItem::has not parent"; // totally random choice for scenePos() :S
		return boundingRect().translated(scenePos());
	}
}
Ejemplo n.º 28
0
void
RoadMoveHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    // Let the trackEditor handle the movement //
    //
    if (isSelected()) // only if this handle is actually selected
    {
        trackEditor_->translateRoadMoveHandles(scenePos(), event->scenePos());
    }

    //	MoveHandle::mouseMoveEvent(event); // pass to baseclass
}
Ejemplo n.º 29
0
void LineObject::setObjectEndPoint2(qreal x2, qreal y2)
{
    QPointF endPt1 = scenePos();
    qreal x1 = endPt1.x();
    qreal y1 = endPt1.y();
    qreal dx = x2 - x1;
    qreal dy = y2 - y1;
    setRotation(0);
    setScale(1);
    setLine(0, 0, dx, dy);
    setPos(x1, y1);
}
Ejemplo n.º 30
0
void SceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem* /* option */, QWidget* /* widget */) {
    // don't draw things that are outside of the scene
    int adjust = -TILE_SIZE;
    QRectF rect = scene()->sceneRect().adjusted(0, 0, adjust, adjust);
    if (!rect.contains(scenePos()))
        return;

    painter->fillRect(this->boundingRect(), this->color(this->isSelected()));

    painter->setPen(QPen(strokeColor, 2));
    painter->drawRect(this->boundingRect());
}