Ignore:
Timestamp:
Jan 11, 2008, 3:44:33 PM (16 years ago)
Author:
garnier
Message:

modifs de test pour rubberband et mise en place du button mouse zoom

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc

    r677 r678  
    5454 QGLWidget(QGLFormat(QGL::SampleBuffers))             // FIXME : gerer le pb du parent !
    5555 {
    56    zoomAction = false;
    5756   nbPaint =0;
    5857   hasToRepaint =false;
     
    257256void G4OpenGLStoredQtViewer::paintGL()
    258257 {
    259    if (zoomAction) {
    260      glEnable (GL_DEPTH_TEST);
    261      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    262 
    263      setupViewport(width(),height());     
    264      SetView();
    265      ClearView (); //ok, put the background correct
    266 
    267      QPainter painter;
    268      painter.begin(this);
    269      //      painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
    270      //      painter.setCompositionMode(QPainter::CompositionMode_SourceOver); // diagonale en pointillé
    271      //     painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); // blanc
    272      //     painter.setCompositionMode(QPainter::CompositionMode_Clear);// diagonale noire
    273      //     painter.setCompositionMode(QPainter::CompositionMode_Source); // diagonale en pointillé
    274      //     painter.setCompositionMode(QPainter::CompositionMode_Destination); // blanc
    275      //     painter.setCompositionMode(QPainter::CompositionMode_SourceIn); // blanc ?
    276      //     painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); // blanc
    277      //     painter.setCompositionMode(QPainter::CompositionMode_SourceOut); // digonale noire
    278      //     painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); // diagonale noire
    279      //     painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); // diagonale noire
    280      //     painter.setCompositionMode(QPainter::CompositionMode_DestinationAtop); // blanc
    281      //     painter.setCompositionMode(QPainter::CompositionMode_Xor); // diagonale noire
    282      //     painter.setRenderHint(QPainter::Antialiasing);
    283      //         painter.setBackgroundMode(Qt::OpaqueMode);
    284      //          painter.drawImage(0, 0, glBufferImage);
    285      
    286      //     painter.setRenderHint(QPainter::Antialiasing);
    287      //      QColor bg = QColor(glBufferImage.pixel(0,0));
    288      //      printf("%d+%d+%d+%d %d+%d+%d+%d",bg.red(),bg.green(),bg.blue(),bg.alpha(),qAlpha(glBufferImage.pixel(0,0)),qRed(glBufferImage.pixel(0,0)),qGreen(glBufferImage.pixel(0,0)),qBlue(glBufferImage.pixel(0,0)));
    289      //      painter.setBackground(QBrush(bg));
    290      //      //     painter.drawRect(10,10,50,80);
    291      // //      QImage test = grabFrameBuffer().copy();
    292      // //      painter.drawImage(0, 0,test);
    293      for (int ay=0;ay<glBufferImage.height();ay++) {
    294        for (int ax=0;ax<glBufferImage.width();ax++) {
    295          //         if(QColor(glBufferImage.pixel(ax,ay)) != bg) {
    296          //.           painter.setPen(QColor(glBufferImage.pixel(ax,ay)));
    297          //.           painter.drawPoint(ax,ay);
    298            //          } else {
    299            //            printf("o");
    300            //          }
    301          //          printf("%d+%d+%d+%d ",QColor(glBufferImage.pixel(ax,ay)).red(),QColor(glBufferImage.pixel(ax,ay)).green(),QColor(glBufferImage.pixel(ax,ay)).blue(),QColor(glBufferImage.pixel(ax,ay)).alpha());
    302          //          if (glBufferImage.pixel(ax,ay) == 255) {
    303          //            test.setPixel(ax,ay,1);
    304          //          } else {
    305          //            test.setPixel(ax,ay,0);
    306          //          }
    307        }
    308        //       printf("\n");
    309      }
    310      // //      for (int ay=0;ay<test.height();ay++) {
    311      // //        for (int ax=0;ax<test.width();ax++) {
    312      // //          if (test.pixel(ax,ay) == 1) {
    313      // //            printf(".");
    314      // //          } else if (!test.pixel(ax,ay)) {
    315      // //            printf("X");
    316      // //          } else {
    317      // //            printf("%d",test.pixel(ax,ay));
    318      // //          }
    319      // //        }
    320      // //        printf("\n");
    321      // //      }
    322      
    323      //     painter.drawImage(0, 0, glBufferImage);
    324      //     painter.drawImage(0, 0, test,0,0,-1,-1,Qt::ColorOnly);
    325      
    326 #ifdef GEANT4_QT_DEBUG
    327        printf("G4OpenGLStoredQtViewer::paintGL ============  zoom event\n");
    328 #endif
    329        painter.setBrush(Qt::NoBrush);
    330        painter.setPen(Qt::red);
    331        painter.setPen(Qt::DashLine);
    332        painter.drawRect(beginZoom.x(),beginZoom.y(),endZoom.x()-beginZoom.x(),endZoom.y()-beginZoom.y());
    333      painter.end();
    334    } else {
    335258     
    336259     if (!readyToPaint) {
     
    376299     hasToRepaint =false;
    377300     
    378    }
    379301#ifdef GEANT4_QT_DEBUG
    380302     printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
     
    391313}
    392314
     315/**
     316 * This function was build in order to make a zoom on double clic event.
     317 * It was think to build a rubberband on the zoom area, but never work fine
     318 */
    393319void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
    394320{
     
    396322  printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
    397323#endif
    398   setMouseTracking(true);
    399   zoomAction=true;
    400   //  makeCurrent();
    401 //   glBufferImage = QImage( width(), height(), QImage::Format_ARGB32_Premultiplied );
    402 //   glReadPixels( 0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, glBufferImage.bits() );
    403   glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);
    404   QImage acha( glBufferImage.size(), QImage::Format_RGB32 );
    405   acha.fill( Qt::black );
    406   glBufferImage.setAlphaChannel( acha );
    407  
    408 #ifdef GEANT4_QT_DEBUG
    409 //   for (int ay=0;ay<glBufferImage.height();ay++) {
    410 //     for (int ax=0;ax<glBufferImage.width();ax++) {
    411 //       if (glBufferImage.pixel(ax,ay) == 255) {
    412 //         printf(".");
    413 //       } else if (!glBufferImage.pixel(ax,ay)) {
    414 //         printf("X");
    415 //       } else {
    416 //         printf("%d",glBufferImage.pixel(ax,ay));
    417 //       }
    418 //     }
    419 //     printf("\n");
    420 //   }
    421 #endif
    422   beginZoom.setX(event->x());
    423   beginZoom.setY(event->y());
     324//   setMouseTracking(true);
     325//   glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied); 
    424326}
    425327
     
    429331  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
    430332#endif
    431   setMouseTracking(false);
    432   zoomAction =false;
     333//   setMouseTracking(false);
    433334}
    434335
    435336void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
    436337{
    437   // special case of mouse zoom action, it should draw a rect on
    438   // the openGL buffer, so it could only be done in this class
    439   // and sould be reimplemented in G4OpenGLImmediateQtViewer
    440   if (!zoomAction) {
     338
    441339#if QT_VERSION < 0x040000
    442340    G4MouseMoveEvent(event->x(),event->y(),event->state());
     
    444342    G4MouseMoveEvent(event->x(),event->y(),event->buttons());
    445343#endif
    446   } else {
    447 #ifdef GEANT4_QT_DEBUG
    448     printf("G4OpenGLStoredQtViewer::mouseMoveEvent zoom\n");
    449 #endif
    450     endZoom.setX(event->x());
    451     endZoom.setY(event->y());
    452     updateGL();
    453   }
    454   //  DrawView();
    455344}
    456345
Note: See TracChangeset for help on using the changeset viewer.