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 Main::addSprite()
{
    QCanvasItem* i = new BouncyLogo(&canvas);
    i->setZ(rand()%256);
    i->show();
}
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();
	}