Example #1
0
QVariant MapObjectItem::itemChange(GraphicsItemChange change,
                                   const QVariant &value)
{
    if (!mSyncing) {
        MapRenderer *renderer = mMapDocument->renderer();

        if (change == ItemPositionChange
            && (QApplication::keyboardModifiers() & Qt::ControlModifier))
        {
            const QPointF pixelDiff = value.toPointF() - mOldItemPos;
            const QPointF newPixelPos =
                    renderer->tileToPixelCoords(mOldObjectPos) + pixelDiff;
            // Snap the position to the grid
            const QPointF newTileCoords =
                    renderer->pixelToTileCoords(newPixelPos).toPoint();

            return renderer->tileToPixelCoords(newTileCoords);
        }
        else if (change == ItemPositionHasChanged) {
            // Update the position of the map object
            const QPointF pixelDiff = value.toPointF() - mOldItemPos;
            const QPointF newPixelPos =
                    renderer->tileToPixelCoords(mOldObjectPos) + pixelDiff;
            mObject->setPosition(renderer->pixelToTileCoords(newPixelPos));
        }
    }

    return QGraphicsItem::itemChange(change, value);
}
Example #2
0
QVariant ResizeHandle::itemChange(GraphicsItemChange change,
                                  const QVariant &value)
{
    if (!mMapObjectItem->mSyncing) {
        MapRenderer *renderer = mMapObjectItem->mapDocument()->renderer();

        if (change == ItemPositionChange) {
            // Calculate the absolute pixel position
            const QPointF itemPos = mMapObjectItem->pos();
            QPointF pixelPos = value.toPointF() + itemPos;

            // Calculate the new coordinates in tiles
            QPointF tileCoords = renderer->pixelToTileCoords(pixelPos);
            const QPointF objectPos = mMapObjectItem->mapObject()->position();
            tileCoords -= objectPos;
            tileCoords.setX(qMax(tileCoords.x(), qreal(0)));
            tileCoords.setY(qMax(tileCoords.y(), qreal(0)));
            if (QApplication::keyboardModifiers() & Qt::ControlModifier)
                tileCoords = tileCoords.toPoint();
            tileCoords += objectPos;

            return renderer->tileToPixelCoords(tileCoords) - itemPos;
        }
        else if (change == ItemPositionHasChanged) {
            // Update the size of the map object
            const QPointF newPos = value.toPointF() + mMapObjectItem->pos();
            QPointF tileCoords = renderer->pixelToTileCoords(newPos);
            tileCoords -= mMapObjectItem->mapObject()->position();
            mMapObjectItem->resize(QSizeF(tileCoords.x(), tileCoords.y()));
        }
    }

    return QGraphicsItem::itemChange(change, value);
}
Example #3
0
QVariant EqHandle::itemChange( QGraphicsItem::GraphicsItemChange change, const QVariant &value )
{
    if( change == ItemPositionChange )
    {
        // pass filter don't move in y direction
        if ( m_type == highpass || m_type == lowpass )
        {
            float newX = value.toPointF().x();
            if( newX < 0 )
            {
                newX = 0;
            }
            if( newX > m_width )
            {
                newX = m_width;
            }
            return QPointF(newX, m_heigth/2);
        }
    }

    QPointF newPos = value.toPointF();
    QRectF rect = QRectF( 0, 0, m_width, m_heigth );
    if( !rect.contains( newPos ) )
    {
        // Keep the item inside the scene rect.
        newPos.setX( qMin( rect.right(), qMax( newPos.x(), rect.left() ) ) );
        newPos.setY( qMin( rect.bottom(), qMax( newPos.y(), rect.top() ) ) );
        return newPos;
    }
    return QGraphicsItem::itemChange( change, value );
}
QVariant TrajectoriesProxyModel::data(const QModelIndex &proxyIndex, int role) const
{
    if (role != Qt::DisplayRole ||
        !proxyIndex.isValid() ||
        !_parentIndex.isValid()) {
        return QVariant();
    }

    if (!proxyIndex.parent().isValid()) {
        return proxyIndex.column() == 0? tr("Trajectory %1").arg(proxyIndex.row()) : QVariant();
    }

    QVariant data = mapToSource(proxyIndex).data();

    switch (proxyIndex.column()) {
    case VideoModel::LFrameColumn:
        return data;
    case VideoModel::PositionColumn:
        return tr("(%1, %2)").arg(data.toPointF().x()).arg(data.toPointF().y());
    case VideoModel::LSpeedColumn:
    case VideoModel::LAccelerationColumn:
        return QLineF(QPointF(0, 0), data.toPointF()).length();
    default:
        return QVariant();
    }
}
QVariant GraphicsClientItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
    if (change == QGraphicsItem::ItemPositionHasChanged) {
        if (jackClient) {
            jackClient->setClientItemPosition(value.toPointF());
        } else {
            clientItemsClient->setClientItemPositionByName(clientName, value.toPointF());
        }
    }
    return QGraphicsPathItem::itemChange(change, value);
}
QVariant MeshGraphItemVelocityHandle::itemChange(GraphicsItemChange change, const QVariant &value)
{
    switch (change)
    {
    case QGraphicsItem::ItemPositionHasChanged:
        m_station->setVelocity(value.toPointF());
        m_arrow->setEdges(QPointF(0, 0), value.toPointF());
        m_station->stationChanged();
        updateText();
        break;
    default:
        break;
    };
    return QGraphicsItem::itemChange(change, value);
}
Example #7
0
/**
 * @brief itemChange handle detail change.
 * @param change change
 * @param value value
 * @return new value.
 */
QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
    if (change == ItemPositionHasChanged && scene())
    {
        // value - this is new position.
        QPointF newPos = value.toPointF();

        MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id, this->scene());
        connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VPattern::LiteParseTree);
        qApp->getUndoStack()->push(moveDet);
    }

    if (change == QGraphicsItem::ItemSelectedChange)
    {
        if (value == true)
        {
            // do stuff if selected
            this->setFocus();
        }
        else
        {
            // do stuff if not selected
        }
    }

    return QGraphicsItem::itemChange(change, value);
}
/*!
    \internal

    Reimplemented from QGraphicsItemPrivate. ### Qt 5: Move impl to
    reimplementation QGraphicsProxyWidget::inputMethodQuery().
*/
QVariant QGraphicsProxyWidgetPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const
{
    Q_Q(const QGraphicsProxyWidget);
    if (!widget || !q->hasFocus())
        return QVariant();

    QWidget *focusWidget = widget->focusWidget();
    if (!focusWidget)
        focusWidget = widget;
    QVariant v = focusWidget->inputMethodQuery(query);
    QPointF focusWidgetPos = q->subWidgetRect(focusWidget).topLeft();
    switch (v.type()) {
    case QVariant::RectF:
        v = v.toRectF().translated(focusWidgetPos);
        break;
    case QVariant::PointF:
        v = v.toPointF() + focusWidgetPos;
        break;
    case QVariant::Rect:
        v = v.toRect().translated(focusWidgetPos.toPoint());
        break;
    case QVariant::Point:
        v = v.toPoint() + focusWidgetPos.toPoint();
        break;
    default:
        break;
    }
    return v;
}
Example #9
0
void PointFComposedProperty::setValue(Property *property,
    const QVariant &value, bool rememberOldValue)
{
    const QPointF p( value.toPointF() );
    property->child("x")->setValue(p.x(), rememberOldValue, false);
    property->child("y")->setValue(p.y(), rememberOldValue, false);
}
Example #10
0
QVariant SceneItem::itemChange(GraphicsItemChange change, const QVariant& value) {
    if (scene() && change == QGraphicsItem::ItemPositionChange) {
        QPointF newPos = value.toPointF();
        // rect is adjusted so that items cannot be placed one tile to the right/bottom
        int adjust = -TILE_SIZE;
        QRectF rect = scene()->sceneRect().adjusted(0, 0, adjust, adjust);

        if (!rect.contains(newPos)) {
            // don't allow the item to be moved outside the scene
            newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
            newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
        }
        newPos.setX(round(newPos.x() / TILE_SIZE) * TILE_SIZE);
        newPos.setY(round(newPos.y() / TILE_SIZE) * TILE_SIZE);

        return newPos;
    } else if (change == QGraphicsItem::ItemPositionHasChanged) {
        // update the position of the sprite/exit (or whatever) based on the new position

        // TODO: generate undo/redo actions for movement somehow
        this->updateObject();
        return value;
    }

    return QGraphicsItem::itemChange(change, value);
}
Example #11
0
QVariant QBayesNode::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
    switch (change) {
    case QGraphicsItem::ItemSelectedChange:
        mIsSelected = value.toBool();
        if (mIsSelected)
            setFocus();
        break;
    case QGraphicsItem::ItemPositionChange:
    {
        if (scene()) {
            // value is the new position.
            QPointF newPos = value.toPointF();
            QRectF sceneRect = scene()->sceneRect();
            if (!sceneRect.contains(newPos)) {
                // Keep the item inside the scene rect.
                newPos.setX(qMin(sceneRect.right(), qMax(newPos.x(), sceneRect.left())));
                newPos.setY(qMin(sceneRect.bottom(), qMax(newPos.y(), sceneRect.top())));
            }
            emit positionChanged(newPos);
            update();
            return QGraphicsItem::itemChange(change, newPos);
        }
        break;
    }
    default:
        break;
    }
    return QGraphicsItem::itemChange(change, value);
}
Example #12
0
QVariant Component::itemChange(GraphicsItemChange change,
		const QVariant &value) {
	if (change == ItemPositionChange && scene()) {
		int i = 0;


//		QList<Connection *> connectionlist = scene->getConnections();
//		qDebug() << "connections are " + QString::number(m);

//		foreach (Connection *connection, connections)
//			{
//				connection->updatePosition();
//				qDebug() << i++;
//			}
	}

	  if (change == ItemPositionChange && scene()) {
	         // value is the new position.
	         QPointF newPos = value.toPointF();
	         QRectF rect = scene()->sceneRect();
	         if (!rect.contains(newPos)) {
	             // Keep the item inside the scene rect.
	             newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
	             newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
	             return newPos;
	         }
	     }

	     return QGraphicsItem::itemChange(change, value);
}
Example #13
0
void RefactoringApplier::changeElementInModel(const Id &changeFromId, const Id &changeToId)
{
	if (mLogicalModelApi.isLogicalId(changeFromId)) {
		return;
	}
	if (!refactoringElements.contains(changeToId.element())) {
		IdList const inLinks = mGraphicalModelApi.mutableGraphicalRepoApi().incomingLinks(changeFromId);
		IdList const outLinks = mGraphicalModelApi.mutableGraphicalRepoApi().outgoingLinks(changeFromId);
		Id const parentId = mGraphicalModelApi.mutableGraphicalRepoApi().parent(changeFromId);
		QVariant const position = mGraphicalModelApi.mutableGraphicalRepoApi().position(changeFromId);
		bool const isFromLogicalModel = false;
		QString const refactoringsMetamodel = "RefactoringsMetamodel";
		QString newEditor = changeToId.editor();
		newEditor.chop(refactoringsMetamodel.length());
		Id const newId = Id(newEditor, changeToId.diagram(), changeToId.element(), QUuid::createUuid().toString());
		Id const newElementId = mGraphicalModelApi.createElement(parentId, newId
				, isFromLogicalModel, "ololo", position.toPointF());
		for (Id idLink : inLinks) {
			mGraphicalModelApi.mutableGraphicalRepoApi().setTo(idLink, newElementId);
		}
		for (Id idLink : outLinks) {
			mGraphicalModelApi.mutableGraphicalRepoApi().setFrom(idLink, newElementId);
		}
		mGraphicalModelApi.mutableGraphicalRepoApi().removeChild(parentId, changeFromId);
		mGraphicalModelApi.mutableGraphicalRepoApi().removeElement(changeFromId);
	}
}
Example #14
0
void Mapper::setValue(QtProperty* property, const QVariant& value)
{
  if (property == _opacityItem)
  {
    double opacity = qBound(value.toDouble() / 100.0, 0.0, 1.0);
    if (opacity != _mapping->getRawOpacity())
    {
      _mapping->setRawOpacity(opacity);
      emit valueChanged();
    }
  }
  else
  {
    std::map<QtProperty*, std::pair<MShape*, int> >::iterator it = _propertyToVertex.find(property);
    if (it != _propertyToVertex.end())
    {
      const QPointF& p = value.toPointF();
      MShape* shape = it->second.first;
      int    v     = it->second.second;
      if (shape->getVertex(v) != p)
      {
        shape->setVertex(v, p);
        emit valueChanged();
      }
    }
  }
}
Example #15
0
QVariant KWidget::itemChange( GraphicsItemChange change, const QVariant & value )
{
    if(change == QGraphicsItem::ItemParentHasChanged
        || change == QGraphicsItem::ItemParentChange)
    {
        clearThemeCheckFlag();
    }
    else if(change == QGraphicsItem::ItemScenePositionHasChanged)
    {
        emit scenePosition(value.toPointF());
    }
    else if(change == QGraphicsItem::ItemVisibleHasChanged)
    {
        bool bvis = isVisible();
        visibleEvent(bvis);
        if(bvis)
        {
            showEvent();
        }
        else
        {
            hideEvent();
        }
    }
    return QGraphicsWidget::itemChange(change, value);
}
QVariant GraphicEQFilterGUIItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value)
{
	QVariant result = QGraphicsItem::itemChange(change, value);

	if (change == ItemScenePositionHasChanged)
	{
		GraphicEQFilterGUIScene* s = qobject_cast<GraphicEQFilterGUIScene*>(scene());
		s->itemMoved(index);
	}
	else if (change == ItemSelectedHasChanged)
	{
		GraphicEQFilterGUIScene* s = qobject_cast<GraphicEQFilterGUIScene*>(scene());
		s->itemSelectionChanged(index, value.toBool());
	}
	else if (change == ItemPositionChange)
	{
		GraphicEQFilterGUIScene* s = qobject_cast<GraphicEQFilterGUIScene*>(scene());
		if (s->getBandCount() != -1)
		{
			QPointF newPos = value.toPointF();
			newPos.setX(s->hzToX(getHz()));
			result = newPos;
		}
	}

	return result;
}
bool InspectorBase::isDefault(const InspectorItem& ii)
      {
      Element* e = inspector->element();
      for (int i = 0; i < ii.parent; ++i)
            e = e->parent();

      P_ID id      = ii.t;
      P_TYPE t     = propertyType(id);
      QVariant val = getValue(ii);
      QVariant def = e->propertyDefault(id);
      if (t == P_TYPE::SIZE || t == P_TYPE::SCALE || t == P_TYPE::SIZE_MM) {
            QSizeF sz = def.toSizeF();
            qreal v = ii.sv == 0 ? sz.width() : sz.height();
            return val.toDouble() == v;
            }
      if (t == P_TYPE::POINT || t == P_TYPE::POINT_MM) {
            QPointF sz = def.toPointF();
            qreal v = ii.sv == 0 ? sz.x() : sz.y();
            return val.toDouble() == v;
            }
      if (t == P_TYPE::FRACTION) {
            Fraction f = def.value<Fraction>();
            int v = ii.sv == 0 ? f.numerator() : f.denominator();
            return val.toInt() == v;
            }
      return val == def;
      }
/*!

*/
bool HsContentService::addWidget(const QString &uri, const QVariantHash &preferences,
                                 const QVariant &homescreenData)
{
    HsWidgetData data;
    data.uri = uri;

    HsWidgetHost *widget = HsWidgetHost::createInstance(data, preferences);    
    if (!widget) {
        return false;
    }

    HsPage *page = HsScene::instance()->activePage();
    QPointF touchPoint = homescreenData.toPointF();
    if (!page->addNewWidget(widget, touchPoint)) {
        widget->remove();
        return false;
    }
    connect(widget,SIGNAL(event_faulted()),SLOT(widgetStartFaulted()));
    mWidgetStartFaulted = false; 
    widget->startWidget(false); // synchronous operation
    if (mWidgetStartFaulted) {
        // page will destroy widget instance
        return false;
    }
    widget->disconnect(this);
    emit widgetAdded(uri, preferences);
    return true;
}
Example #19
0
//----------------------------------------------------------------------------------------------
QVariant CustomProxy::itemChange(GraphicsItemChange change, const QVariant &value)
{
	// handle positioning
    if (change == ItemPositionChange && scene())
	{
        QRectF rect = boundingRect();
        QPointF pos = value.toPointF();
        QRectF sceneRect = scene()->sceneRect();
    
		if (pos.x() + rect.left() < sceneRect.left())			pos.setX(sceneRect.left() - rect.left());
        else if (pos.x() + rect.right() >= sceneRect.right())   pos.setX(sceneRect.right() - rect.right());
        
		if (pos.y() + rect.top() < sceneRect.top())				pos.setY(sceneRect.top() - rect.top());
        else if (pos.y() + rect.bottom() >= sceneRect.bottom()) pos.setY(sceneRect.bottom() - rect.bottom());
        
		return pos;
    }

	// handle popups
    //if (change == ItemChildAddedChange || change == ItemChildRemovedChange) {
    //    if (change == ItemChildAddedChange) {
    //        currentPopup = qVariantValue<QGraphicsItem *>(value);
    //        currentPopup->setCacheMode(ItemCoordinateCache);
    //        if (scene())
    //            currentPopup->installSceneEventFilter(this);
    //    } else if (scene()) {
    //        currentPopup->removeSceneEventFilter(this);
    //        currentPopup = 0;
    //    }
    //} else if (currentPopup && change == ItemSceneHasChanged) {
    //    currentPopup->installSceneEventFilter(this);
    //}
    return QGraphicsProxyWidget::itemChange(change, value);
}
Example #20
0
QVariant Container::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
    if (change == ItemPositionChange) {
            QPointF newPos = value.toPointF();
            QPointF rigthBottom = QPointF(newPos.x()+this->rect().width(),newPos.y()+this->rect().height());
            if (!margins.contains(newPos) || !margins.contains(rigthBottom)) {
                newPos.setX(qMin(margins.right(), qMax(newPos.x(), margins.left()+1)));
                newPos.setY(qMin(margins.bottom(), qMax(newPos.y(), margins.top()+1)));
                if(!margins.contains(rigthBottom))
                {
                    newPos.setX(qMax(margins.left(), qMin(newPos.x(),margins.right()-this->rect().width())));
                    newPos.setY(qMax(margins.top(), qMin(newPos.y(),margins.bottom()-this->rect().height())));                    
                }                
                return newPos;
            }
            emit moved(this);
     }
    else if(change == ItemSelectedChange)
    {
        bool b = value.toBool();
        if(b)
            this->grabKeyboard();
        else
            this->ungrabKeyboard();
    }
    return QGraphicsItem::itemChange(change, value);
}
Example #21
0
InformationName NodeInstance::setInformation(InformationName name, const QVariant &information, const QVariant &secondInformation, const QVariant &thirdInformation)
{
    switch (name) {
    case Size: return setInformationSize(information.toSizeF());
    case BoundingRect: return setInformationBoundingRect(information.toRectF());
    case ContentItemBoundingRect: return setInformationContentItemBoundingRect(information.toRectF());
    case Transform: return setInformationTransform(information.value<QTransform>());
    case ContentTransform: return setInformationContentTransform(information.value<QTransform>());
    case ContentItemTransform: return setInformationContentItemTransform(information.value<QTransform>());
    case PenWidth: return setInformationPenWith(information.toInt());
    case Position: return setInformationPosition(information.toPointF());
    case IsInLayoutable: return setInformationIsInLayoutable(information.toBool());
    case SceneTransform: return setInformationSceneTransform(information.value<QTransform>());
    case IsResizable: return setInformationIsResizable(information.toBool());
    case IsMovable: return setInformationIsMovable(information.toBool());
    case IsAnchoredByChildren: return setInformationIsAnchoredByChildren(information.toBool());
    case IsAnchoredBySibling: return setInformationIsAnchoredBySibling(information.toBool());
    case HasContent: return setInformationHasContent(information.toBool());
    case HasAnchor: return setInformationHasAnchor(information.toByteArray(), secondInformation.toBool());break;
    case Anchor: return setInformationAnchor(information.toByteArray(), secondInformation.toByteArray(), thirdInformation.value<qint32>());
    case InstanceTypeForProperty: return setInformationInstanceTypeForProperty(information.toByteArray(), secondInformation.toByteArray());
    case HasBindingForProperty: return setInformationHasBindingForProperty(information.toByteArray(), secondInformation.toBool());
    case NoName:
    default: break;
    }

    return NoInformationChange;
}
Example #22
0
void QKineticScroller::setScrollMetric(ScrollMetric metric, const QVariant &value)
{
    Q_D(QKineticScroller);

    switch (metric) {
    case DragVelocitySmoothingFactor:   d->dragVelocitySmoothingFactor = qBound(qreal(0), value.toReal(), qreal(1)); break;
    case LinearDecelerationFactor:      d->linearDecelerationFactor = qBound(qreal(0), value.toReal(), qreal(1)); break;
    case ExponentialDecelerationBase:   d->exponentialDecelerationBase = qBound(qreal(0), value.toReal(), qreal(1)); break;
    case OvershootSpringConstant:       d->overshootSpringConstantRoot = qSqrt(value.toReal()); break;
    case OvershootDragResistanceFactor: d->overshootDragResistanceFactor = value.toReal(); break;
    case OvershootMaximumDistance:      d->overshootMaximumDistance = value.toPointF(); break;
    case DragStartDistance:             d->dragStartDistance = value.toReal(); break;
    case DragStartDirectionErrorMargin: d->dragStartDirectionErrorMargin = value.toReal(); break;
    case MinimumVelocity:               d->minimumVelocity = value.toReal(); break;
    case MaximumVelocity:               d->maximumVelocity = value.toReal(); break;
    case MaximumNonAcceleratedVelocity: d->maximumNonAcceleratedVelocity = value.toReal(); break;
    case MaximumClickThroughVelocity:   d->maximumClickThroughVelocity = value.toReal(); break;
    case AxisLockThreshold:             d->axisLockThreshold = qBound(qreal(0), value.toReal(), qreal(1)); break;
    case FramesPerSecond:               d->framesPerSecond = qBound(1, value.toInt(), 100); break;
    case FastSwipeMaximumTime:          d->fastSwipeMaximumTime = value.toReal(); break;
    case FastSwipeMinimumVelocity:      d->fastSwipeMinimumVelocity = value.toReal(); break;
    case FastSwipeBaseVelocity:         d->fastSwipeBaseVelocity = value.toReal(); break;
    case ScrollMetricCount:             break;
    }
}
Example #23
0
QString PointFDelegate::displayText( const QVariant& value ) const
{
    const QPointF p(value.toPointF());
    return QString::fromLatin1(POINTFEDIT_MASK)
        .arg(p.x())
        .arg(p.y());
}
bool PunchFilter::setOption(int option, const QVariant &value)
{
    bool bOK = true;
    switch (option) {
        case QtImageFilter::Radius:
        {
            double radius = value.toDouble(&bOK);
            if (bOK) m_Radius = radius;
        }
        break;

        case QtImageFilter::Center:
        {
            QPointF center = value.toPointF();
            if (center.isNull()) {
                bOK = false;
            } else {
                m_Center = center;
            }
        }
        break;

        case QtImageFilter::Force:
        {
            double force = value.toDouble(&bOK);
            if (bOK) m_Force = force;
        }
        break;

        default:
            bOK = false;
        break;
    }
    return bOK;
}
Example #25
0
// --------------------------------------------------------------------------------------------------------------------------------------
QVariant CSizeGrip::itemChange(GraphicsItemChange change, const QVariant &value)
{
    switch(change)
    {
    case QGraphicsItem::ItemPositionChange:
        {
            QPointF nextPos =  value.toPointF();
            QPointF targetPos = pos() - nextPos;
            QSizeF resultSize = gWindow()->size() - QSizeF(targetPos.x(), targetPos.y());

            if(resultSize.width() < gWindow()->minSize().width())
            {
                resultSize.setWidth(gWindow()->minSize().width());
                nextPos.setX(pos().x());
            }
            if(resultSize.height() < gWindow()->minSize().height())
            {
                resultSize.setHeight(gWindow()->minSize().height());
                nextPos.setY(pos().y());
            }
            gWindow()->setSize(resultSize);
            return nextPos;
        }
        break;
    default: return QGraphicsItem::itemChange(change, value);
    }
    return QGraphicsItem::itemChange(change, value);
}
QVariant MainElement::itemChange(GraphicsItemChange change, const QVariant &value)
{
    if (change == ItemPositionChange && scene())
    {
        QPointF newPos = value.toPointF();

        if(newPos.x()<0)
        {
            newPos.setX(0);
        }

        if(newPos.y()<0)
        {
            newPos.setY(0);
        }

        if(QApplication::mouseButtons() == Qt::LeftButton)
        {
            int gridSize = STEP_GRID;
            qreal xV = round(newPos.x()/gridSize)*gridSize;
            qreal yV = round(newPos.y()/gridSize)*gridSize;
            this->scene()->update(this->scene()->sceneRect());


            return QPointF(xV, yV);
        }
        else
            return newPos;
    }
    else
        return QGraphicsItem::itemChange(change, value);
}
Example #27
0
QVariant FretboardAxis::itemChange(GraphicsItemChange change, const QVariant& value)
{
    if (change == ItemSelectedChange)
    {
        const QColor penColor = (value.toBool() ? m_selectionColor : m_defaultColor);
        QPen pen = this->pen();
        pen.setColor(penColor);
        setPen(pen);
    }
    else if (change == ItemPositionChange)
    {
        QPointF newPos = value.toPointF();

        FretboardEditScene* scene = getScene();
        if (scene->isInFretMode())
            newPos.setY(scenePos().y());
        else if (scene->isInStringMode())
            newPos.setX(scenePos().x());

        return newPos;
    }
    else if (change == ItemSceneHasChanged)
    {
        QGraphicsScene* scene = value.value<QGraphicsScene*>();
        if (scene == nullptr)
        {
            QApplication::restoreOverrideCursor();
        }
    }

    return QGraphicsLineItem::itemChange(change, value);
}
Example #28
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);
}
QVariant QNodeItem::itemChange(GraphicsItemChange Change, const QVariant& Value)
{
	QPointF NewScenePoint = Value.toPointF();
 
	if (!m_SuspendUpdate && Change == QGraphicsItem::ItemPositionChange)
	{
		const float Width	= m_pTransferFunctionItem->rect().width();
		const float Height	= m_pTransferFunctionItem->rect().height();

		QPointF NodeRangeMin = QPointF(m_pNode->GetMinX() * Width, m_pNode->GetMinY() * Height);
		QPointF NodeRangeMax = QPointF(m_pNode->GetMaxX() * Width, m_pNode->GetMaxY() * Height);

		NewScenePoint.setX(qMin(NodeRangeMax.x() - NODE_POSITION_EPSILON, qMax(NewScenePoint.x(), NodeRangeMin.x() + NODE_POSITION_EPSILON)));
		NewScenePoint.setY(qMin(NodeRangeMax.y(), qMax(NewScenePoint.y(), NodeRangeMin.y())));

		return NewScenePoint;
	}

	if (!m_SuspendUpdate && Change == QGraphicsItem::ItemPositionHasChanged)
	{
		m_pTransferFunctionItem->m_AllowUpdateNodes = false;

		m_pNode->SetIntensity(NewScenePoint.x() / m_pTransferFunctionItem->rect().width());
		m_pNode->SetOpacity(1.0f - (NewScenePoint.y() / m_pTransferFunctionItem->rect().height()));

		m_pTransferFunctionItem->m_AllowUpdateNodes = true;

		return NewScenePoint;
	}

    return QGraphicsItem::itemChange(Change, Value);
}
void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue)
{
    stop(widget, type);

    QPropertyAnimation* propertyAnim = nullptr;
    const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1;

    switch (type) {
    case MovingAnimation: {
        const QPointF newPos = endValue.toPointF();
        if (newPos == widget->pos()) {
            return;
        }

        propertyAnim = new QPropertyAnimation(widget, "pos");
        propertyAnim->setDuration(animationDuration);
        propertyAnim->setEndValue(newPos);
        break;
    }

    case CreateAnimation: {
        propertyAnim = new QPropertyAnimation(widget, "opacity");
        propertyAnim->setEasingCurve(QEasingCurve::InQuart);
        propertyAnim->setDuration(animationDuration);
        propertyAnim->setStartValue(0.0);
        propertyAnim->setEndValue(1.0);
        break;
    }

    case DeleteAnimation: {
        propertyAnim = new QPropertyAnimation(widget, "opacity");
        propertyAnim->setEasingCurve(QEasingCurve::OutQuart);
        propertyAnim->setDuration(animationDuration);
        propertyAnim->setStartValue(1.0);
        propertyAnim->setEndValue(0.0);
        break;
    }

    case ResizeAnimation: {
        const QSizeF newSize = endValue.toSizeF();
        if (newSize == widget->size()) {
            return;
        }

        propertyAnim = new QPropertyAnimation(widget, "size");
        propertyAnim->setDuration(animationDuration);
        propertyAnim->setEndValue(newSize);
        break;
    }

    default:
        break;
    }

    Q_ASSERT(propertyAnim);
    connect(propertyAnim, &QPropertyAnimation::finished, this, &KItemListViewAnimation::slotFinished);
    m_animation[type].insert(widget, propertyAnim);

    propertyAnim->start();
}