home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / opengl / overlay_x11 / rubberbandwidget.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-11  |  1.4 KB  |  61 lines

  1. /****************************************************************************
  2. ** $Id:  qt/rubberbandwidget.cpp   3.0.0   edited Jun 1 18:44 $
  3. **
  4. ** Implementation of a widget that draws a rubberband. Designed to be used 
  5. ** in an X11 overlay visual
  6. **
  7. ** Copyright (C) 1999 by Trolltech AS.  All rights reserved.
  8. **
  9. ** This file is part of an example program for Qt.  This example
  10. ** program may be used, distributed and modified without limitation.
  11. **
  12. *****************************************************************************/
  13.  
  14. #include "rubberbandwidget.h"
  15. #include <qpainter.h>
  16.  
  17.  
  18. RubberbandWidget::RubberbandWidget( QColor transparentColor, QWidget *parent, 
  19.                     const char *name, WFlags f )
  20.     : QWidget( parent, name, f )
  21. {
  22.     setBackgroundColor( transparentColor );
  23.     on = FALSE;
  24. }
  25.  
  26.  
  27. void RubberbandWidget::mousePressEvent( QMouseEvent* e )
  28. {
  29.     p1 = e->pos();
  30.     p2 = p1;
  31.     p3 = p1;
  32.     on = TRUE;
  33.     setMouseTracking( TRUE );
  34. }
  35.  
  36.  
  37. void RubberbandWidget::mouseMoveEvent( QMouseEvent* e )
  38. {
  39.     if ( on ) {
  40.     p2 = e->pos();
  41.     QPainter p( this );
  42.     // Erase last drawn rubberband:
  43.     p.setPen( QPen( backgroundColor(), 3 ) );
  44.     p.drawRect( QRect( p1, p3 ) );
  45.     // Draw the new one:
  46.     p.setPen( QPen( white, 3 ) );
  47.     p.drawRect( QRect(p1, p2) );
  48.     p3 = p2;
  49.     }
  50. }
  51.  
  52. void RubberbandWidget::mouseReleaseEvent( QMouseEvent* )
  53. {
  54.     if ( on ) {
  55.     QPainter p ( this );
  56.     p.eraseRect( rect() );
  57.     }
  58.     on = FALSE;
  59.     setMouseTracking( FALSE );
  60. }
  61.