コード例 #1
0
ファイル: qquickmenupopupwindow.cpp プロジェクト: xjohncz/qt5
void QQuickMenuPopupWindow::setGeometry(int posx, int posy, int w, int h)
{
    QWindow *pw = transientParent();
    if (!pw && parentItem())
        pw = parentItem()->window();
    if (!pw)
        pw = this;
    QRect g = pw->screen()->availableVirtualGeometry();

    if (posx + w > g.right()) {
        if (qobject_cast<QQuickMenuPopupWindow *>(transientParent())) {
            // reposition submenu window on the parent menu's left side
            int submenuOverlap = pw->x() + pw->width() - posx;
            posx -= pw->width() + w - 2 * submenuOverlap;
        } else {
            posx = g.right() - w;
        }
    } else {
        posx = qMax(posx, g.left());
    }

    posy = qBound(g.top(), posy, g.bottom() - h);

    QQuickWindow::setGeometry(posx, posy, w, h);
}
コード例 #2
0
QVariant PixmapItem::itemChange(GraphicsItemChange change,
                                const QVariant &value)
{
    if (change == ItemPositionChange)
    {
        // value is the new position.
        QPointF newPos = value.toPointF();
        QRectF rect = parentItem()->boundingRect();

        rect.moveLeft(boundingRect().width()*3/4*-1);
        rect.setWidth(rect.width() + boundingRect().width()*2/4 );

        rect.moveTop(boundingRect().height()*3/4*-1);
        rect.setHeight(rect.height() + boundingRect().height()*2/4 );

        CardItem *card = qgraphicsitem_cast<CardItem *>(parentItem());

        if (!rect.contains(newPos))
        {
            // Keep the item inside the scene rect.
            int newX = (int)qMin(rect.right(), qMax(newPos.x(), rect.left()));
            int newY = (int)qMin(rect.bottom(), qMax(newPos.y(), rect.top()));



            if(card->isAlign())
            {
                int gridSize = card->getGridSize();
                newX = (newX/(10*gridSize))*(10*gridSize);
                newY = (newY/(10*gridSize))*(10*gridSize);
            }

            newPos.setX(newX);
            newPos.setY(newY);
            return newPos;
        }
        else
        {
            int newX =  newPos.x();
            int newY = newPos.y();

            if(card->isAlign())
            {
                int gridSize = card->getGridSize();
                newX = newPos.x()/(10*gridSize);
                newX = newX * (10*gridSize);
                newY = newPos.y()/(10*gridSize);
                newY = newY*(10*gridSize);

            }

            newPos.setX(newX);
            newPos.setY(newY);
            return newPos;

        }
    }

    return QGraphicsItem::itemChange(change, value);
}
コード例 #3
0
ファイル: elementTitle.cpp プロジェクト: ArtemKopylov/qreal
void ElementTitle::focusOutEvent(QFocusEvent *event)
{
	QGraphicsTextItem::focusOutEvent(event);

	QString htmlNormalizedText = toHtml().remove("\n", Qt::CaseInsensitive);

	setTextInteractionFlags(Qt::NoTextInteraction);

	parentItem()->setSelected(true);

	// Clear selection
	QTextCursor cursor = textCursor();
	cursor.clearSelection();
	setTextCursor(cursor);

	unsetCursor();

	if (mReadOnly)
		return;

	if (mOldText != toPlainText()) {
		QString value = toPlainText();
		if (mBinding == "name")
			static_cast<NodeElement*>(parentItem())->setName(value);
		else
			static_cast<NodeElement*>(parentItem())->setLogicalProperty(mBinding, value);
	}
	setHtml(htmlNormalizedText);
}
コード例 #4
0
 QRectF RadicalElectron::boundingRect() const {
   if (!parentItem()) return QRectF();
   Q_D(const RadicalElectron);
   QRectF bounds(0,0,d->diameter,d->diameter);
   bounds.translate(d->linker.getShift(parentItem()->boundingRect(), bounds));
   return bounds;
 }
コード例 #5
0
ファイル: cell.cpp プロジェクト: JustFFunny/WorkSpace
Cell::CellState Cell::shrinkOrGrow()
{
    int dishSize = qRound(parentItem()->boundingRect().width());
    int neighbours = 0;
    QListIterator<QGraphicsItem*> i(parentItem()->childItems());
    while (i.hasNext()) {
        QGraphicsItem *item = i.next();
        if (item != this && collidesWithItem(item))
            ++neighbours;
    }
    if (!neighbours || m_size > dishSize / 3)
        m_size *= randomReal(); // shrink - lonely or too big
    else if (neighbours < 4) // grow - happy
        m_size *= ((5 - neighbours) * randomReal());
    else // shrink - too crowded
        m_size *= ((1.0 / neighbours) + randomReal());

    QPainterPath path;
    qreal x = m_size * std::cos(AQP::radiansFromDegrees(1));
    qreal y = m_size * std::sin(AQP::radiansFromDegrees(1));
    path.moveTo(x, y);
    for (int angle = 1; angle < 360; ++angle) {
        qreal factor = m_size + ((m_size / 3) * (randomReal() - 0.5));
        x = factor * std::cos(AQP::radiansFromDegrees(angle));
        y = factor * std::sin(AQP::radiansFromDegrees(angle));
        path.lineTo(x, y);
    }
    path.closeSubpath();
    m_path = path;

    prepareGeometryChange();
    if (m_size < 5.0 && (qrand() % 20 == 0))
        return Die; // small ones randomly die
    return Live;
}
コード例 #6
0
ファイル: node.cpp プロジェクト: Razmataz88/Graphic
QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
{
    switch (change)
    {
      case ItemPositionHasChanged:
        if (parentItem() != 0)
        {
            if (parentItem()->type() == Graph::Type)
            {
                Graph * graph = qgraphicsitem_cast<Graph*>(parentItem());
                Graph * tempGraph = graph;
                graph = qgraphicsitem_cast<Graph*>(graph->getRootParent());
                this->setParentItem(nullptr);
                this->setParentItem(tempGraph);
            }
            if (verbose)
                qDebug() << "node does not have a graph item parent";
        }
        foreach (Edge * edge, edgeList)
            edge->adjust();
        break;

      case ItemRotationChange:
        foreach (Edge * edge, edgeList)
            edge->adjust();
        break;

      default:
        break;
    };

    return QGraphicsItem::itemChange(change, value);
}
コード例 #7
0
/*!
    \internal

    This function is called from subclasses to add a layout item \a layoutItem
    to a layout.

    It takes care of automatically reparenting graphics items, if needed.

    If \a layoutItem is a  is already in a layout, it will remove it  from that layout.

*/
void QGraphicsLayoutPrivate::addChildLayoutItem(QGraphicsLayoutItem *layoutItem)
{
    Q_Q(QGraphicsLayout);
    if (QGraphicsLayoutItem *maybeLayout = layoutItem->parentLayoutItem()) {
        if (maybeLayout->isLayout())
            removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(maybeLayout), layoutItem);
    }
    layoutItem->setParentLayoutItem(q);
    if (layoutItem->isLayout()) {
        if (QGraphicsItem *parItem = parentItem()) {
            static_cast<QGraphicsLayout*>(layoutItem)->d_func()->reparentChildItems(parItem);
        }
    } else {
        if (QGraphicsItem *item = layoutItem->graphicsItem()) {
            QGraphicsItem *newParent = parentItem();
            QGraphicsItem *oldParent = item->parentItem();
            if (oldParent == newParent || !newParent)
                return;

#ifdef QT_DEBUG
            if (oldParent && item->isWidget()) {
                QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item);
                qWarning("QGraphicsLayout::addChildLayoutItem: %s \"%s\" in wrong parent; moved to correct parent",
                    w->metaObject()->className(), w->objectName().toLocal8Bit().constData());
            }
#endif

            item->setParentItem(newParent);
        }
    }
}
UIGChooserItemMachine::~UIGChooserItemMachine()
{
    /* If that item is focused: */
    if (model()->focusItem() == this)
    {
        /* Unset the focus: */
        model()->setFocusItem(0);
    }
    /* If that item is in selection list: */
    if (model()->currentItems().contains(this))
    {
        /* Remove item from the selection list: */
        model()->removeFromCurrentItems(this);
    }
    /* If that item is in navigation list: */
    if (model()->navigationList().contains(this))
    {
        /* Remove item from the navigation list: */
        model()->removeFromNavigationList(this);
    }

    /* Remove item from the parent: */
    AssertMsg(parentItem(), ("No parent set for machine-item!"));
    parentItem()->removeItem(this);
}
コード例 #9
0
bool FormEditorItem::isContentVisible() const
{
    if (parentItem())
        return parentItem()->isContentVisible() && m_isContentVisible;

    return m_isContentVisible;
}
コード例 #10
0
ファイル: canvasbezierlinemov.cpp プロジェクト: 87maxi/oom
CanvasBezierLineMov::CanvasBezierLineMov(PortMode port_mode_, PortType port_type_, QGraphicsItem* parent) :
    QGraphicsPathItem(parent, canvas.scene)
{
    port_mode = port_mode_;
    port_type = port_type_;

    // Port position doesn't change while moving around line
    item_x = parentItem()->scenePos().x();
    item_y = parentItem()->scenePos().y();
    item_width = ((CanvasPort*)parentItem())->getPortWidth(); // FIXME

    QPen pen;

    if (port_type == PORT_TYPE_AUDIO_JACK)
        pen = QPen(canvas.theme->line_audio_jack, 2);
    else if (port_type == PORT_TYPE_MIDI_JACK)
        pen = QPen(canvas.theme->line_midi_jack, 2);
    else if (port_type == PORT_TYPE_MIDI_A2J)
        pen = QPen(canvas.theme->line_midi_a2j, 2);
    else if (port_type == PORT_TYPE_MIDI_ALSA)
        pen = QPen(canvas.theme->line_midi_alsa, 2);

    QColor color(0,0,0,0);
    setBrush(color);
    setPen(pen);
    update();
}
コード例 #11
0
UIGDetailsElement::UIGDetailsElement(UIGDetailsSet *pParent, DetailsElementType type, bool fOpened)
    : UIGDetailsItem(pParent)
    , m_pSet(pParent)
    , m_type(type)
    , m_iCornerRadius(10)
    , m_iMinimumHeaderWidth(0)
    , m_iMinimumHeaderHeight(0)
    , m_iMinimumTextWidth(0)
    , m_iMinimumTextHeight(0)
    , m_fClosed(!fOpened)
    , m_pButton(0)
    , m_iAdditionalHeight(0)
    , m_fAnimationRunning(false)
    , m_fHovered(false)
    , m_fNameHovered(false)
    , m_pHighlightMachine(0)
    , m_pForwardAnimation(0)
    , m_pBackwardAnimation(0)
    , m_iAnimationDuration(400)
    , m_iDefaultDarkness(100)
    , m_iHighlightDarkness(90)
    , m_iAnimationDarkness(m_iDefaultDarkness)
{
    /* Prepare element: */
    prepareElement();
    /* Prepare button: */
    prepareButton();

    /* Setup size-policy: */
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);

    /* Add item to the parent: */
    AssertMsg(parentItem(), ("No parent set for details element!"));
    parentItem()->addItem(this);
}
コード例 #12
0
void UIGChooserItem::updateGeometry()
{
    /* Call to base-class: */
    QIGraphicsWidget::updateGeometry();

    /* Update parent's geometry: */
    if (parentItem())
        parentItem()->updateGeometry();

    /* Special handling for root-items: */
    if (isRoot())
    {
        /* Root-item should notify chooser-view if minimum-width-hint was changed: */
        int iMinimumWidthHint = minimumWidthHint();
        if (m_iPreviousMinimumWidthHint != iMinimumWidthHint)
        {
            /* Save new minimum-width-hint, notify listener: */
            m_iPreviousMinimumWidthHint = iMinimumWidthHint;
            emit sigMinimumWidthHintChanged(m_iPreviousMinimumWidthHint);
        }
        /* Root-item should notify chooser-view if minimum-height-hint was changed: */
        int iMinimumHeightHint = minimumHeightHint();
        if (m_iPreviousMinimumHeightHint != iMinimumHeightHint)
        {
            /* Save new minimum-height-hint, notify listener: */
            m_iPreviousMinimumHeightHint = iMinimumHeightHint;
            emit sigMinimumHeightHintChanged(m_iPreviousMinimumHeightHint);
        }
    }
}
コード例 #13
0
void QSGParticlePainter::componentComplete()
{
    if (!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
        setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
    if (!m_system)
        qWarning() << "ParticlePainter created without a particle system specified";//TODO: useful QML warnings, like line number?
    QSGItem::componentComplete();
}
コード例 #14
0
QRectF HighlightItem::parentRect() const
{
    if (parentItem())
        return parentItem()->boundingRect();
    else if (scene())
        return scene()->sceneRect();
    return QRectF(0, 0, 10, 10);
}
コード例 #15
0
ファイル: GEventNode.cpp プロジェクト: GaelReinaudi/LabExe
void GEventNode::UpdateVerticalPosition()
{
	// if their is a parent item, we draw the line within the pParentItem->boundingRect(). 
	double heightLine = 11.4159;
	if(parentItem())
		heightLine = parentItem()->boundingRect().height();
	setLine(0.0, 0.0, 0.0, heightLine);
}
コード例 #16
0
UIGSelectorItemGroup::~UIGSelectorItemGroup()
{
    /* Delete all the items: */
    clearItems();

    /* Remove item from the parent: */
    if (parentItem())
        parentItem()->removeItem(this);
}
コード例 #17
0
ファイル: cell.cpp プロジェクト: DoubleYouEl/CrochetCharts
bool Cell::isGrouped()
{

    if(parentItem()) {
        qDebug() << "isGrouped parent type:" << parentItem()->Type;
        return true;
    }

    return false;
}
コード例 #18
0
KoFilterEffect * ConnectorItem::effect() const
{
    if (!parentItem())
        return 0;
    EffectItemBase * effectItem = dynamic_cast<EffectItemBase*>(parentItem());
    if (!effectItem)
        return 0;

    return effectItem->effect();
}
コード例 #19
0
QString UIGChooserItemMachine::fullName() const
{
    /* Get full parent name, append with '/' if not yet appended: */
    AssertMsg(parentItem(), ("Incorrect parent set!"));
    QString strFullParentName = parentItem()->fullName();
    if (!strFullParentName.endsWith('/'))
        strFullParentName.append('/');
    /* Return full item name based on parent prefix: */
    return strFullParentName + name();
}
コード例 #20
0
UIGSelectorItemMachine::UIGSelectorItemMachine(UIGSelectorItem *pParent,
                                               UIGSelectorItemMachine *pCopyFrom,
                                               int iPosition /* = -1 */)
    : UIGSelectorItem(pParent, iPosition)
    , UIVMItem(pCopyFrom->machine())
{
    /* Add item to the parent: */
    AssertMsg(parentItem(), ("No parent set for machine item!"));
    parentItem()->addItem(this, iPosition);
}
コード例 #21
0
bool ItemGroup::isGrouped()
{
    if(parentItem()) {
        if(parentItem()->Type == ItemGroup::Type) {
            return true;
        }
    }

    return false;
}
コード例 #22
0
UIGSelectorItemMachine::UIGSelectorItemMachine(UIGSelectorItem *pParent,
                                               const CMachine &machine,
                                               int iPosition /* = -1 */)
    : UIGSelectorItem(pParent, iPosition)
    , UIVMItem(machine)
{
    /* Add item to the parent: */
    AssertMsg(parentItem(), ("No parent set for machine item!"));
    parentItem()->addItem(this, iPosition);
}
コード例 #23
0
ファイル: fixture.cpp プロジェクト: dallarosa/Quasi-Engine
void Fixture::onParentChanged()
{
    if (!m_shapeItem)
        return;

    // NOTE: Probably we need to check if there is a
    // better place to set container Entity to be
    // parent of Shape.
    m_shapeItem->setParent(parentItem());
    m_shapeItem->setParentItem(parentItem());
}
コード例 #24
0
void GraphicsClientItem::focusInEvent(QFocusEvent *)
{
    QGraphicsItem *topSibling = 0;
    if (parentItem()) {
        topSibling = parentItem()->childItems().first();
    } else {
        topSibling = scene()->items().first()->topLevelItem();
    }
    Q_ASSERT(topSibling->parentItem() == parentItem());
    setZValue(topSibling->zValue() + 1);
}
コード例 #25
0
ファイル: AbstractGraphicsItem.cpp プロジェクト: Giladx/vlmc
qint32
AbstractGraphicsItem::trackNumber()
{
    if ( parentItem() )
    {
        GraphicsTrack* graphicsTrack = qgraphicsitem_cast<GraphicsTrack*>( parentItem() );
        if ( graphicsTrack )
            return graphicsTrack->trackNumber();
    }
    return -1;
}
コード例 #26
0
ファイル: DateItem.cpp プロジェクト: chrono35/chronomodel
void DateItem::mousePressEvent(QGraphicsSceneMouseEvent* e)
{
    parentItem()->setZValue(2.);
    EventItem* eventItem = dynamic_cast<EventItem*>(parentItem());
    if(eventItem)// && e->button() == Qt::LeftButton)
    {
        eventItem->setSelected(true);
        mEventsScene->itemClicked(eventItem, e);
        e->accept();
    }
    QGraphicsObject::mousePressEvent(e);
}
コード例 #27
0
ファイル: fadingitem.cpp プロジェクト: ashl1/ktorrent-stream
void FadingItem::updatePixmap()
{
    QStyleOptionGraphicsItem option;
    mParent = QPixmap( parentItem()->boundingRect().size().toSize() + QSize( 1, 1 ) );
    mParent.fill(Qt::transparent);
    QPainter painter( &mParent );
    parentItem()->paint( &painter, &option, 0 );
    foreach ( QGraphicsItem *item, parentItem()->childItems() ) {
        painter.save();
        painter.translate( item->pos() );
        item->paint( &painter, &option, 0 );
        painter.restore();
    }
コード例 #28
0
void ORSectionHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
{
  if(!parentItem())
    return;

  // When the mouse is released we want to resize our parent to have
  // a new height according to the position we ended up at
  ORGraphicsSectionItem * sec = static_cast<ORGraphicsSectionItem*>(parentItem());
  sec->setRect(0, 0, sec->rect().width(), qMax(pos().y(), 0.0));
  DocumentScene * ds = static_cast<DocumentScene*>(sec->scene());
  if(ds)
    ds->repositionSections();
}
コード例 #29
0
ファイル: viewport.cpp プロジェクト: slavablind91/code
/*!
  Some elements of the image are drawn as an "early" draw activity.  Essentially it performs clearing
  and drawing of backdrop effects in preparation for primary drawing activities using \a painter.
*/
void Viewport::earlyDraw(QGLPainter *painter)
{
    // If are running with the regular qml viewer, then assume that it
    // has cleared the background for us, and just clear the depth buffer.
    if (!d->view && parentItem() && !d->showPicking) {
        painter->clear(QGL::ClearDepthBuffer);
    } else {
        if (d->showPicking)
            painter->setClearColor(Qt::black);
        else
            painter->setClearColor(d->backgroundColor);
        painter->clear();
    }

    // If we have a scene backdrop, then draw it now.
    if (d->backdrop) {
        painter->projectionMatrix().setToIdentity();
        painter->modelViewMatrix().setToIdentity();
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        glDepthMask(GL_FALSE);

        // Select the effect and draw the backdrop quad.
        d->backdrop->enableEffect(painter);
        painter->setVertexBuffer(d->backdropVertices);
        painter->draw(QGL::TriangleFan, 4);
        d->backdrop->disableEffect(painter);

        glDepthMask(GL_TRUE);
        glEnable(GL_DEPTH_TEST);
    } else if (d->backgroundColor.alpha() != 0 || !parentItem()) {
        painter->projectionMatrix().setToIdentity();
        painter->modelViewMatrix().setToIdentity();
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        glDepthMask(GL_FALSE);

        painter->setStandardEffect(QGL::FlatColor);
        painter->setColor(d->backgroundColor);
        painter->setVertexBuffer(d->backdropVertices);
        painter->draw(QGL::TriangleFan, 4);

        glDepthMask(GL_TRUE);
        glEnable(GL_DEPTH_TEST);
    }

#ifdef GL_RESCALE_NORMAL
    glEnable(GL_RESCALE_NORMAL);
#endif
}
コード例 #30
0
ファイル: TraceGraphPoint.cpp プロジェクト: Kaldie/GeRoBot
void TraceGraphPoint::updateTracePosition(Trace::TracePointer& i_trace,
                                          QPointF& i_newPosition) {
  LOG_DEBUG("Update trace position based on the current position of the point in the scene");
  LOG_DEBUG("Current Start point: " << i_trace->getStartPoint().x << " , " << i_trace->getStartPoint().y);
  LOG_DEBUG("Current End point: " << i_trace->getEndPoint().x << " , " << i_trace->getEndPoint().y);
  
  switch (m_positionOnTrace) {
  case TraceGraphPoint::StartPoint : {
    LOG_DEBUG("Start Point At MouseDown" << m_startPointAtMouseDown.x() << " , " << m_startPointAtMouseDown.y());
    Point2D newPoint = Point2D(i_newPosition) + m_startPointAtMouseDown;
    correctTracePosition(i_trace, &newPoint);
    i_trace->setStartPoint(newPoint);
    TraceGraphItem* traceGraphItem = static_cast<TraceGraphItem*>(parentItem());
    traceGraphItem->setPos(newPoint);
    traceGraphItem->updatePointPositions(this);
    i_newPosition = QPointF(0, 0);
    break;
  }
  case TraceGraphPoint::EndPoint : {
    Point2D point = i_trace->getStartPoint() + Point2D(i_newPosition);
    LOG_DEBUG("New end pos() : " << point.x << " , " << point.y);
    correctTracePosition(i_trace, &point);
    i_trace->setEndPoint(point);
    i_newPosition = Point2D(i_trace->getEndPoint() - i_trace->getStartPoint());
    break;
  }
  case TraceGraphPoint::CenterPoint : {
    if (RotationTrace::RotationTracePointer rotationTrace =
        std::dynamic_pointer_cast<RotationTrace>(i_trace)) {
      LOG_DEBUG("Center point: " << rotationTrace->getCentrePoint().x << " , " << rotationTrace->getCentrePoint().y);
      Point2D possibleCenterPoint = i_trace->getStartPoint() + Point2D(i_newPosition);
      LOG_DEBUG("possibleCenterPoint: " << possibleCenterPoint.x << " , " << possibleCenterPoint.y);
      correctTracePosition(i_trace, &possibleCenterPoint);
      LOG_DEBUG("Corrected position: " << possibleCenterPoint.x << " , " << possibleCenterPoint.y);
      rotationTrace->setCentrePoint(possibleCenterPoint);
      i_newPosition = 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;
  }}  // end switch
  parentItem()->update();
}