void ossimQtVceCanvasWidget::openImageFile(const ossimString& filename,
                                           QPoint& locationPt,
                                           std::vector<QCanvasItem*>& newItemList)
{
   ossimRefPtr<ossimImageHandler> ih = ossimImageHandlerRegistry::instance()->open(filename);
   QCanvasItem* newItem = (QCanvasItem*)NULL;
   if(ih.valid())
   {
      ih->setDescription(ih->getFilename());
      newItem = addObject(ih.get(),
                          locationPt);
      if(!newItem)
      {
         ih = 0;
      }
      else
      {
         QRect bounds = newItem->boundingRect();
         
         locationPt.setY(locationPt.y() + bounds.height() + 10);
         newItemList.push_back(newItem);
         newItem->show();
      }
   }
}
示例#2
0
void k9MenuEditor::contentsMouseMoveEvent(QMouseEvent* e) {
    updateCursor(e);
    if ( moving && (e->state() & Qt::LeftButton ==Qt::LeftButton) ) {
        if (moving->rtti() !=QCanvasItem::Rtti_Text || moving==m_menu->getText()) {
            QPoint p = inverseWorldMatrix().map(e->pos());
            int offsetX=p.x() - moving_start.x();
            int offsetY=p.y() - moving_start.y();
            moving_start = p;
            if (moving->rtti()==1000 || moving->rtti() == QCanvasItem::Rtti_Rectangle) {
                for (k9MenuButton *b=m_selection.first();b;b=m_selection.next()) {
                    k9CanvasSprite*spr=b->getSprite();
                    spr->moveBy(offsetX,offsetY);
                    spr->update();
                }

            } else
                moving->moveBy(offsetX,offsetY);

            if (moving->rtti() >2001 && moving->rtti() <2010) {
                k9CanvasSelectionRedim *ssr=(k9CanvasSelectionRedim*)moving;
                ssr->updateSelection();
            } else if (moving->rtti() != QCanvasItem::Rtti_Text ){
                //if selection not resized, move the selection
                m_canvasSelection->moveBy(offsetX,offsetY);
                m_canvasSelection->update();
            }

            if (moving==m_menu->getText())
                emit m_menu->updateTextPos(QPoint(moving->x(),moving->y()));
            canvas()->update();
        }
    } else if ((e->state() & Qt::LeftButton) ==Qt::LeftButton ) {
        m_canvasSelection->hide();
        canvas()->update();
        QPoint p = inverseWorldMatrix().map(e->pos());
        int offsetX=p.x() - moving_start.x();
        int offsetY=p.y() - moving_start.y();
        m_canvasSelection->setSize(offsetX,offsetY);
        m_canvasSelection->show();
        canvas()->update();
        clearSelection();
        QCanvasItemList l=canvas()->collisions(m_canvasSelection->getRect());
        for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
            QCanvasItem *item = *it;
            if (item->rtti()==1000) {
                addSelection(item);
            }
        }
    }
}
示例#3
0
void Snake::detectCrash()
{
    QCanvasSprite* head = snakelist.first();
    QCanvasItem* item;
    QCanvasItemList l=head->collisions(FALSE);
    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
       item = *it;
       // check if snake hit target
       if ( (item->rtti()== 1500 ) && (item->collidesWith(head)) ) {
              Target* target = (Target*) item;
              target->done();
              emit targethit();
              extendSnake();
              setScore(5);
              return;
       }
       // check if snake hit obstacles
       if ( (item->rtti()==1600) && (item->collidesWith(head)) ) {
             emit dead();
             autoMoveTimer->stop();
             return;
       }
    }
    //check if snake hit itself
    for (uint i = 3; i < snakelist.count(); i++) {
       if (head->collidesWith(snakelist.at(i)) ) {
            emit dead();
            autoMoveTimer->stop();
            return;
       }
   }
   //check if snake hit edge
   if ( (head->x() > canvas->width()-5) || (head->y() > canvas->height()-10)
         || (head->x() <2) || (head->y() <-5) ) {
        emit dead();
        autoMoveTimer->stop();
        return;
   }
}
示例#4
0
void Bullet::checkCollision()
{
    QCanvasItem* item;
    QCanvasItemList l=collisions(FALSE);
      for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
          item = *it;
          if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) {
               Man* deadman = (Man*)item;
               if (deadman->frame() != 5) return;
               deadman->done();
	       emit score(10);
               setShotCount(shotcount+1);
               setAnimated(false);
               nobullets--;
               delete this;
               return;
          }
          else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) {
               Helicopter* deadchopper = (Helicopter*) item;
               deadchopper->done();
	       emit score(50);
               setAnimated(false);
               nobullets--;
               delete this;
               return;
         }
      }
      //check shot is not out of bounds
     if ( (y() < 0) || (x() < 0) ||
          (y() > canvas()->height()) ||
          ( x() > canvas()->width()))  {
          setAnimated(false);
          nobullets--;
          delete this;
          return;
     }
}
示例#5
0
void Main::addSprite()
{
    QCanvasItem* i = new BouncyLogo(&canvas);
    i->setZ(rand()%256);
    i->show();
}
示例#6
0
void BouncyLogo::advance(int stage)
{
    switch ( stage ) {
      case 0: {
	double vx = xVelocity();
	double vy = yVelocity();

	if ( vx == 0.0 && vy == 0.0 ) {
	    // stopped last turn
	    initSpeed();
	    vx = xVelocity();
	    vy = yVelocity();
	}

	double nx = x() + vx;
	double ny = y() + vy;

	if ( nx < 0 || nx >= canvas()->width() )
	    vx = -vx; // 換反方向
	if ( ny < 0 || ny >= canvas()->height() )
	    vy = -vy; // 換反方向

	for (int bounce=0; bounce<4; bounce++) {
	    QCanvasItemList l=collisions(FALSE); // 沒有那麼精準的傳回所有有碰撞的canvas item
	    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
		QCanvasItem *hit = *it;
		if ( hit->rtti()==logo_rtti && hit->collidesWith(this) ) {
		    switch ( bounce ) {
		      case 0:
			vx = -vx;
			break;
		      case 1:
			vy = -vy;
			vx = -vx;
			break;
		      case 2:
			vx = -vx;
			break;
		      case 3:
			// Stop for this turn
			vx = 0;
			vy = 0;
			break;
		    }
		    setVelocity(vx,vy);
		    break;
		}
	    }
	}

	if ( x()+vx < 0 || x()+vx >= canvas()->width() )
	    vx = 0;
	if ( y()+vy < 0 || y()+vy >= canvas()->height() )
	    vy = 0;

	setVelocity(vx,vy);
      } break;
      case 1:
	QCanvasItem::advance(stage);
	break;
    }
}
void ossimQtVceCanvasWidget::addAllObjects(const ossimKeywordlist& kwl,
                                           const QPoint& location,
                                           const char* prefix)
{
   unselectItems();
   QPoint locationPoint = location;
   
   ossimString copyPrefix = prefix;
   std::vector<QCanvasItem*> newItemList;
   
   ossimString regExpression =  ossimString("^(") + copyPrefix + "object[0-9]+.)";
   vector<ossimString> keys =
      kwl.getSubstringKeyList( regExpression );
   long numberOfObjets = keys.size();//kwl.getNumberOfSubstringKeys(regExpression);

   int offset = (copyPrefix+"object").size();
   int idx = 0;
   std::vector<int> theNumberList(numberOfObjets);

   for(idx = 0; idx < (int)theNumberList.size();++idx)
   {
      ossimString numberStr(keys[idx].begin() + offset,
                            keys[idx].end());
      theNumberList[idx] = numberStr.toInt();
   }
   
   std::sort(theNumberList.begin(), theNumberList.end());
   for(idx=0;idx < (int)theNumberList.size();++idx)
   {
      ossimString newPrefix = copyPrefix;
      newPrefix += ossimString("object");
      newPrefix += ossimString::toString(theNumberList[idx]);
      newPrefix += ossimString(".");
      ossimString objType = kwl.find(newPrefix,
                                     ossimKeywordNames::TYPE_KW);
      QCanvasItem* item = NULL;
      if(objType == "ossimQtImageWindow")
      {
         item = new ossimQtVceImageDisplayObject(canvas(),
						 this);
         item->setX(locationPoint.x());
         item->setY(locationPoint.y());
         item->show();
         emit itemAdded(item);
      }
      else if(objType == "ossimImageHandler")
      {
         QStringList filenames = QFileDialog::getOpenFileNames("Images (*.adf *.ccf *.dem *.DEM *.dt1 *.dt0 *.dt2 *.hdr *.hgt *.jpg *.jpeg *.img *.doqq *.fst *.FST *.nitf *.NTF *.ntf *.ras *.sid *.tif *.tiff *.toc *.TOC);;Vectors(*.shp dht *.tab);;All Files(*)",
                                                               QString::null,
                                                               this,
                                                               "open file dialog",
                                                               "Choose a file to open");
         QStringList::Iterator it;
         for(it = filenames.begin(); it != filenames.end(); ++it)
         {
            std::vector<QCanvasItem*> newItems;
            openImageFile((*it).ascii(),
                          locationPoint,
                          newItems);
            if(newItems.size())
            {
               
//                QRect bounds = newItems[newItems.size()-1]->boundingRect();
//                locationPoint.setY(locationPoint.y() + bounds.height() + 10);

               newItemList.insert(newItemList.end(),
                                  newItems.begin(),
                                  newItems.end());
            }
         }
         // we will make sure that we don't adjust the location point any further
         //
         item = NULL;
      }
      else
      {
         ossimObject* object = ossimObjectFactoryRegistry::instance()->createObject(objType);
         
         if(object)
         {
            item = addObject(object, locationPoint);
         }
      }
      if(item)
      {
         newItemList.push_back(item);
         QRect bounds = item->boundingRect();
         
         locationPoint.setY(locationPoint.y() + bounds.height() + 10);
         emit itemAdded(item);
      }
   }
   if(newItemList.size() > 0)
   {
      for(idx = 0; idx < (int)newItemList.size(); ++idx)
      {
         newItemList[idx]->setSelected(true);
         theSelectedItems.push_back(newItemList[idx]);
         emit itemSelected(newItemList[idx]);
      }
   }
}
	void KviCanvasView::insertObjectAt(const QPoint & pnt,ObjectType o)
	{
		QCanvasItem * r = 0;

		switch(o)
		{
			case Rectangle:
				r = new KviCanvasRectangle(canvas(),pnt.x(),pnt.y(),0,0);
			break;
			case RichText:
				r = new KviCanvasRichText(canvas(),pnt.x(),pnt.y(),0,0);
			break;
			case Line:
				r = new KviCanvasLine(canvas(),pnt.x(),pnt.y(),pnt.x(),pnt.y());
			break;
			case Ellipse:
				r = new KviCanvasEllipse(canvas(),pnt.x(),pnt.y(),0,0);
			break;
			case Pie:
				r = new KviCanvasPie(canvas(),pnt.x(),pnt.y(),0,0);
			break;
			case Chord:
				r = new KviCanvasChord(canvas(),pnt.x(),pnt.y(),0,0);
			break;
			case PolygonTriangle:
			{
				QPointArray pa(3);
				pa.setPoint(0,0,-500);
				pa.setPoint(1,-450,220);
				pa.setPoint(2,450,220);
				r = new KviCanvasPolygon(canvas(),pnt.x(),pnt.y(),pa,0.1);
			}
			break;
			case PolygonRectangle:
			{
				QPointArray pa(4);
				pa.setPoint(0,-350,-350);
				pa.setPoint(1,350,-350);
				pa.setPoint(2,350,350);
				pa.setPoint(3,-350,350);
				r = new KviCanvasPolygon(canvas(),pnt.x(),pnt.y(),pa,0.1);
			}
			break;
			case PolygonPentagon:
			{
				QPointArray pa(5);
				calcPolygonPoints(pa,5);
				r = new KviCanvasPolygon(canvas(),pnt.x(),pnt.y(),pa,0.1);
			}
			break;
			case PolygonHexagon:
			{
				QPointArray pa(6);
				calcPolygonPoints(pa,6);
				r = new KviCanvasPolygon(canvas(),pnt.x(),pnt.y(),pa,0.1);
			}
			break;
		}

		if(r)
		{
			setItemSelected(r);
			r->setEnabled(true);
			r->show();
		}

		switch(KVI_CANVAS_RTTI_CONTROL_TYPE(r))
		{
			case KVI_CANVAS_RTTI_CONTROL_TYPE_RECTANGLE:
				beginDragRectangle((KviCanvasRectangleItem *)r,pnt,true);
			break;
			case KVI_CANVAS_RTTI_CONTROL_TYPE_LINE:
				beginDragLine((KviCanvasLine *)r,pnt,true);
			break;
	//		case KVI_CANVAS_RTTI_CONTROL_TYPE_POLYGON:
	//			beginDragPolygon((KviCanvasPolygon *)r,pnt,true);
	//		break;
		}

	//	canvas()->update();
	}