Esempio n. 1
0
void QgsAnnotation::setFrameOffsetFromReferencePoint( QPointF offset )
{
  mOffsetFromReferencePoint = offset;
  updateBalloon();
  emit moved();
  emit appearanceChanged();
}
Esempio n. 2
0
void QgsAnnotationItem::setFrameSize( QSizeF size )
{
  QSizeF frameSize = minimumFrameSize().expandedTo( size ); //don't allow frame sizes below minimum
  mFrameSize = frameSize;
  updateBoundingRect();
  updateBalloon();
}
Esempio n. 3
0
void QgsAnnotation::setFrameSize( QSizeF size )
{
  QSizeF frameSize = minimumFrameSize().expandedTo( size ); //don't allow frame sizes below minimum
  mFrameSize = frameSize;
  updateBalloon();
  emit moved();
  emit appearanceChanged();
}
Esempio n. 4
0
void QgsAnnotation::setHasFixedMapPosition( bool fixed )
{
  if ( mHasFixedMapPosition == fixed )
    return;

  mHasFixedMapPosition = fixed;
  updateBalloon();
  emit moved();
}
Esempio n. 5
0
void QgsAnnotationItem::_readXml( const QDomDocument& doc, const QDomElement& annotationElem )
{
  Q_UNUSED( doc );
  if ( annotationElem.isNull() )
  {
    return;
  }
  QPointF pos;
  pos.setX( annotationElem.attribute( "canvasPosX", "0" ).toDouble() );
  pos.setY( annotationElem.attribute( "canvasPosY", "0" ).toDouble() );
  setPos( pos );
  QgsPoint mapPos;
  mapPos.setX( annotationElem.attribute( "mapPosX", "0" ).toDouble() );
  mapPos.setY( annotationElem.attribute( "mapPosY", "0" ).toDouble() );
  mMapPosition = mapPos;

  if ( !mMapPositionCrs.readXml( annotationElem ) )
  {
    mMapPositionCrs = mMapCanvas->mapSettings().destinationCrs();
  }

  mFrameBorderWidth = annotationElem.attribute( "frameBorderWidth", "0.5" ).toDouble();
  mFrameColor.setNamedColor( annotationElem.attribute( "frameColor", "#000000" ) );
  mFrameColor.setAlpha( annotationElem.attribute( "frameColorAlpha", "255" ).toInt() );
  mFrameBackgroundColor.setNamedColor( annotationElem.attribute( "frameBackgroundColor" ) );
  mFrameBackgroundColor.setAlpha( annotationElem.attribute( "frameBackgroundColorAlpha", "255" ).toInt() );
  mFrameSize.setWidth( annotationElem.attribute( "frameWidth", "50" ).toDouble() );
  mFrameSize.setHeight( annotationElem.attribute( "frameHeight", "50" ).toDouble() );
  mOffsetFromReferencePoint.setX( annotationElem.attribute( "offsetX", "0" ).toDouble() );
  mOffsetFromReferencePoint.setY( annotationElem.attribute( "offsetY", "0" ).toDouble() );
  mMapPositionFixed = annotationElem.attribute( "mapPositionFixed", "1" ).toInt();
  setVisible( annotationElem.attribute( "visible", "1" ).toInt() );

  //marker symbol
  QDomElement symbolElem = annotationElem.firstChildElement( "symbol" );
  if ( !symbolElem.isNull() )
  {
    QgsMarkerSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );
    if ( symbol )
    {
      delete mMarkerSymbol;
      mMarkerSymbol = symbol;
    }
  }

  updateBoundingRect();
  updateBalloon();
}
Esempio n. 6
0
void QgsAnnotationItem::setMapPositionFixed( bool fixed )
{
  if ( mMapPositionFixed && !fixed )
  {
    //set map position to the top left corner of the balloon
    setMapPosition( toMapCoordinates( QPointF( pos() + mOffsetFromReferencePoint ).toPoint() ) );
    mOffsetFromReferencePoint = QPointF( 0, 0 );
  }
  else if ( fixed && !mMapPositionFixed )
  {
    setMapPosition( toMapCoordinates( QPointF( pos() + QPointF( -100, -100 ) ).toPoint() ) );
    mOffsetFromReferencePoint = QPointF( 100, 100 );
  }
  mMapPositionFixed = fixed;
  updateBoundingRect();
  updateBalloon();
  update();
}
Esempio n. 7
0
void QgsAnnotationItem::setOffsetFromReferencePoint( QPointF offset )
{
  mOffsetFromReferencePoint = offset;
  updateBoundingRect();
  updateBalloon();
}
Esempio n. 8
0
void AiEntity::update() {
  Physics& physics = *mGameModel->physics;
  // this has to be non-NULL since AiManager::update() checks before calling this.
  // all the same...
  mPhysicsEntity = physics.getEntityByHandle(mPhysicsHandle);
  if (mPhysicsEntity == NULL) {
    // this is bad!
    printf("AiEntity::update(): error: NULL physics entity\n");
    mActive = false;
    return;
  }

  mWorldPosition = physics.getCenter(mPhysicsHandle);

  // won't know this until we read the mail
  mWasAttacked = false;

  readMail();

  // handle death
  // FIXME: the other half of this exists in AiManager...
  // ever get the urge to merge?
  if (mCurrentHealth <= 0.0) {
    // turn inventory items into phys entities
    for (int i = 0; i < AI_INVENTORY_SIZE; i++) {
      if (mInventory[i] > 0) {
        item_t item = mGameModel->itemManager->getItem(mInventory[i]);

        if (item.type == ITEMTYPE_GUN_ONE_HANDED && r_numi(0, 10) < 3) {
          mGameModel->itemManager->destroyItem(mInventory[i]);
        }
        else {
          v3d_t itemForce = v3d_random(20.0);
          itemForce.y = 10.0;
          PhysicsEntity* itemPhysicsEntity = physics.createEntity(OBJTYPE_ITEM, mWorldPosition, itemForce, true);
          if (itemPhysicsEntity != NULL) {
            physics.setItemHandleAndType(itemPhysicsEntity->handle, mInventory[i], mGameModel->itemManager->getItemType(mInventory[i]));
          }

        }

        mInventory[i] = 0;
      }
    }

    return;
  }

  double time = mGameModel->physics->getLastUpdateTime();

  // is it time to think yet?
  if (mNextUpdateTime < time) {
    updateTarget();

//    updateState(time, worldMap, physics, aiEntities, itemManager);

    mNextUpdateTime = time + 0.3;
  }

  if (mTargetPhysicsHandle > 0) {
    mTargetPhysicsEntity = physics.getEntityByHandle(mTargetPhysicsHandle);
  }

  bool couldHaveFiredGun = false;
  bool didFireGun = false;

  if (mTargetPhysicsEntity == NULL) {
    mTargetPhysicsHandle = 0;
  }
  else {
    // now shoot'm if you got'm!
    v3d_t targetPosition = mTargetPhysicsEntity->boundingBox.getCenterPosition();

    bool hasLineOfSight = mGameModel->location->getWorldMap()->lineOfSight(mWorldPosition, targetPosition);
    if (mTargetPhysicsEntity->type != OBJTYPE_TIGER_BAIT && hasLineOfSight) {
      if (mInventory[0] > 0 && mGameModel->itemManager->getItem(mInventory[0]).type == ITEMTYPE_GUN_ONE_HANDED) {
        couldHaveFiredGun = true;
      }

      didFireGun = useWeapon();
    }
  }

  // now for movement
  switch (mType) {
    case AITYPE_BALLOON:
      updateBalloon();
      break;

    case AITYPE_SHOOTER:
      if (!couldHaveFiredGun || (couldHaveFiredGun && !didFireGun && mNextShotTime <= time)) {
        updateHopper();
      }
      break;

    case AITYPE_HOPPER:
      updateHopper();
      break;

    case AITYPE_HUMAN:
      if (!couldHaveFiredGun || (couldHaveFiredGun && !didFireGun && mNextShotTime <= time)) {
        updateHopper();
      }
      break;

    case AITYPE_DUMMY:
      updateDummy();
      break;

    default:
      break;
  }
}
Esempio n. 9
0
void QgsAnnotation::_readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context )
{
  if ( annotationElem.isNull() )
  {
    return;
  }
  QPointF pos;
  pos.setX( annotationElem.attribute( QStringLiteral( "canvasPosX" ), QStringLiteral( "0" ) ).toDouble() );
  pos.setY( annotationElem.attribute( QStringLiteral( "canvasPosY" ), QStringLiteral( "0" ) ).toDouble() );
  if ( pos.x() >= 1 || pos.x() < 0 || pos.y() < 0 || pos.y() >= 1 )
    mRelativePosition = QPointF();
  else
    mRelativePosition = pos;
  QgsPointXY mapPos;
  mapPos.setX( annotationElem.attribute( QStringLiteral( "mapPosX" ), QStringLiteral( "0" ) ).toDouble() );
  mapPos.setY( annotationElem.attribute( QStringLiteral( "mapPosY" ), QStringLiteral( "0" ) ).toDouble() );
  mMapPosition = mapPos;

  if ( !mMapPositionCrs.readXml( annotationElem ) )
  {
    mMapPositionCrs = QgsCoordinateReferenceSystem();
  }

  mContentsMargins = QgsMargins::fromString( annotationElem.attribute( QStringLiteral( "contentsMargin" ) ) );
  mFrameSize.setWidth( annotationElem.attribute( QStringLiteral( "frameWidth" ), QStringLiteral( "50" ) ).toDouble() );
  mFrameSize.setHeight( annotationElem.attribute( QStringLiteral( "frameHeight" ), QStringLiteral( "50" ) ).toDouble() );
  mOffsetFromReferencePoint.setX( annotationElem.attribute( QStringLiteral( "offsetX" ), QStringLiteral( "0" ) ).toDouble() );
  mOffsetFromReferencePoint.setY( annotationElem.attribute( QStringLiteral( "offsetY" ), QStringLiteral( "0" ) ).toDouble() );
  mHasFixedMapPosition = annotationElem.attribute( QStringLiteral( "mapPositionFixed" ), QStringLiteral( "1" ) ).toInt();
  mVisible = annotationElem.attribute( QStringLiteral( "visible" ), QStringLiteral( "1" ) ).toInt();
  if ( annotationElem.hasAttribute( QStringLiteral( "mapLayer" ) ) )
  {
    mMapLayer = QgsProject::instance()->mapLayer( annotationElem.attribute( QStringLiteral( "mapLayer" ) ) );
  }

  //marker symbol
  QDomElement symbolElem = annotationElem.firstChildElement( QStringLiteral( "symbol" ) );
  if ( !symbolElem.isNull() )
  {
    QgsMarkerSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context );
    if ( symbol )
    {
      mMarkerSymbol.reset( symbol );
    }
  }

  mFillSymbol.reset( nullptr );
  QDomElement fillElem = annotationElem.firstChildElement( QStringLiteral( "fillSymbol" ) );
  if ( !fillElem.isNull() )
  {
    QDomElement symbolElem = fillElem.firstChildElement( QStringLiteral( "symbol" ) );
    if ( !symbolElem.isNull() )
    {
      QgsFillSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context );
      if ( symbol )
      {
        mFillSymbol.reset( symbol );
      }
    }
  }
  if ( !mFillSymbol )
  {
    QColor frameColor;
    frameColor.setNamedColor( annotationElem.attribute( QStringLiteral( "frameColor" ), QStringLiteral( "#000000" ) ) );
    frameColor.setAlpha( annotationElem.attribute( QStringLiteral( "frameColorAlpha" ), QStringLiteral( "255" ) ).toInt() );
    QColor frameBackgroundColor;
    frameBackgroundColor.setNamedColor( annotationElem.attribute( QStringLiteral( "frameBackgroundColor" ) ) );
    frameBackgroundColor.setAlpha( annotationElem.attribute( QStringLiteral( "frameBackgroundColorAlpha" ), QStringLiteral( "255" ) ).toInt() );
    double frameBorderWidth = annotationElem.attribute( QStringLiteral( "frameBorderWidth" ), QStringLiteral( "0.5" ) ).toDouble();
    // need to roughly convert border width from pixels to mm - just assume 96 dpi
    frameBorderWidth = frameBorderWidth * 25.4 / 96.0;
    QgsStringMap props;
    props.insert( QStringLiteral( "color" ), frameBackgroundColor.name() );
    props.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) );
    props.insert( QStringLiteral( "style_border" ), QStringLiteral( "solid" ) );
    props.insert( QStringLiteral( "color_border" ), frameColor.name() );
    props.insert( QStringLiteral( "width_border" ), QString::number( frameBorderWidth ) );
    props.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
    mFillSymbol.reset( QgsFillSymbol::createSimple( props ) );
  }

  updateBalloon();
  emit mapLayerChanged();
}