void IGraphicsItem::onHoverEnterEvent(QGraphicsSceneHoverEvent *)
{
    hovered_ = true;
    if(item_->isSelected()) {
        setupGrabbers();
    }
}
void IGraphicsItem::onItemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
    if(change == QGraphicsItem::ItemSelectedHasChanged) {
        if(item_->isSelected() && hovered_) {
            setupGrabbers();
        }
    }

    emit itemChanged(change, value);
}
// ######################################################################
int submain(const int argc, const char** argv)
{
  // catch signals and redirect them for a clean exit (in particular, this gives us a chance to do useful things like
  // flush and close output files that would otherwise be left in a bogus state, like mpeg output files):
  catchsignals(&signum);

  LINFO("#############################################STARTING##############################################");

  ModelManager mgr("App Scorbot MultiGrab");

  scorbot.reset(new ScorbotSimple(mgr));
  mgr.addSubComponent(scorbot);

  setupGrabbers(mgr);

  ofs.reset(new OutputFrameSeries(mgr));
  mgr.addSubComponent(ofs);

  if(mgr.parseCommandLine(argc, argv, "FilePrefix SceneID", 2, 2) == false) return -1;
  mgr.start();

  if (grabbers.size() < NUMCAMS) LFATAL("Only found %" ZU " cameras instead of %d. Reboot your machine and try again.", grabbers.size(), NUMCAMS);

  // get our grabbers to start grabbing:  
  for (size_t cameraID = 0; cameraID < grabbers.size(); ++cameraID)
    grabberThreadServer.enqueueJob(rutz::make_shared(new GrabJob(cameraID)));

  sceneDir = mgr.getExtraArg(0);
  sceneID = boost::lexical_cast<int>(mgr.getExtraArg(1));

  pthread_t displayThread;
  pthread_create(&displayThread, NULL, &displayThreadMethod, NULL);

  // Create the interactive window
  userInteractiveWindow = new XWinManaged(Dims(640,480), -1, -1, "User Interactive");
  userInteractiveWindow->setVisible(false);
  userInteractiveWindow->setPosition(0, 0);

  // Main loop:
  int runnumber = 0;
  while(true) {
    if(signum != 0) break;

    // home the robot once in a while:
    if ((runnumber % 5) == 0) {
      int gogo = 0; getInt("Perform robot homing sequence and press ENTER", gogo);
    }

    // select the scene:
    getInt("Enter scene ID (-1 to exit):", sceneID);

    if (sceneID == -1) break; // abort on scene -1

    // STEP 1. Load the scene file
    SceneSetup setup = loadSceneSetup(sceneID);

    // STEP 2. Show the interactive window:
    userInteractiveWindow->setVisible(true);

    // STEP 3. Display background image and ask the user to place it on the scene
    Image< PixRGB<byte> > backgroundImage = Raster::ReadRGB(setup.setupPath + "/" + setup.backgroundFileName);
    backgroundImage = rescale(backgroundImage, Dims(640, 480));
    writeText(backgroundImage, Point2D<int>(0, 0), "Please place this background on the scene and press ENTER.");
    userInteractiveWindow->drawImage(backgroundImage, 0, 0, true);
    LINFO("Place background map on scene and add houses, trees, and other background objects. See User Interactive window for instructions...");
    // eat all previous mouse clicks and key presses, just in case:
    while (userInteractiveWindow->getLastMouseClick() != Point2D<int>(-1, -1)) { }
    while (userInteractiveWindow->getLastKeyPress() != -1) { }
    // wait for ENTER:
    while(userInteractiveWindow->getLastKeyPress() != 36) usleep(100000);
    LINFO("Background map done. Make sure you have built a nice scene.");

    // STEP 4. Display each object and ask user to put on the scene and specify its bounding box
    for (size_t i = 0; i < setup.objects.size(); ++i)
      setup.objects[i].outline = promptPlaceObjectOnScene(setup, i);

    // STEP 5. Hide the interactive window
    userInteractiveWindow->setVisible(false);

    // STEP 6. Write out outlines to a file
    {
      std::string objectFileName = sformat("%s/RobotScene-s%04d-polygons.txt", dataDir, sceneID);
      std::ofstream objectFile(objectFileName.c_str());

      LINFO("Saving the object bounding boxes into: %s", objectFileName.c_str());
 
      for(size_t i=0; i<setup.objects.size(); ++i)
	{
	  for(size_t j=0; j<setup.objects[i].outline.size(); ++j)
	    {
	      Point2D<int> &pnt = setup.objects[i].outline[j];
	      if(j != 0) objectFile << ',';
	      objectFile << pnt.i << ',' << pnt.j;
	    }
	  objectFile << std::endl;
	}
    }

    // STEP 7. Execute the path and record the videos
    for (pathID = 0; pathID < int(setup.pathIndex.size()); ++pathID) {
      if(signum != 0) break;
      // create a directory for this scene / light:
      const std::string dir = sformat("%s/RobotScene-s%04d-p%02d", dataDir, sceneID, pathID);
      const std::string cmd = sformat("/bin/mkdir -p %s", dir.c_str());
      if (system(cmd.c_str()) == -1) PLFATAL("Could not create directory %s", dir.c_str());

      int gogo = pathID; getInt("Set light and press ENTER to start video recording", gogo);

      // make sure we don't have too many pending disk writes:
      while(writer.size() > 1000) {
	LINFO("Waiting for image writer thread, queue size = %" ZU "...", writer.size());
	usleep(1000000);
      }

      LINFO("Running Scene %04d Path %02d ...", sceneID, setup.pathIndex[pathID]);

      executePath(setup.pathIndex[pathID]);
    }
    if(signum != 0) break;

    // STEP 8. Instruct users to place the objects back into the bins
    userInteractiveWindow->setVisible(true);
    userInteractiveWindow->setPosition(0, 0);
    for(size_t i=0; i<setup.objects.size(); ++i) promptReturnObjectToTray(setup, i);
    userInteractiveWindow->setVisible(false);

    // STEP 9. Ready for next scene
    ++sceneID;
    ++runnumber;
  }

  // stop grabbing:
  keepgoing = false;

  // wait for all pics to be written (note: this just waits until the queue of pending jobs is empty, the writer's
  // destructor will wait until all jobs are complete):
  while(writer.size()) {
    LINFO("Waiting for image writer thread, queue size = %" ZU "...", writer.size());
    usleep(500000);
  }
  writer.flushQueue(250000, true);

  // make sure all is done
  LINFO("Cleaning up... Stand by...");
  usleep(2000000);

  // stop all our ModelComponents
  mgr.stop();

  LINFO("Finished.");

  return 0;
}