Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_picker.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_picker.cpp
r4271 r8127 12 12 #include "qwt_painter.h" 13 13 #include "qwt_math.h" 14 #include "qwt_widget_overlay.h" 14 15 #include <qapplication.h> 15 16 #include <qevent.h> … … 22 23 #include <qmath.h> 23 24 24 class QwtPicker::PickerWidget: public QWidget 25 static inline QRegion qwtMaskRegion( const QRect &r, int penWidth ) 26 { 27 const int pw = qMax( penWidth, 1 ); 28 const int pw2 = penWidth / 2; 29 30 int x1 = r.left() - pw2; 31 int x2 = r.right() + 1 + pw2 + ( pw % 2 ); 32 33 int y1 = r.top() - pw2; 34 int y2 = r.bottom() + 1 + pw2 + ( pw % 2 ); 35 36 QRegion region; 37 38 region += QRect( x1, y1, x2 - x1, pw ); 39 region += QRect( x1, y1, pw, y2 - y1 ); 40 region += QRect( x1, y2 - pw, x2 - x1, pw ); 41 region += QRect( x2 - pw, y1, pw, y2 - y1 ); 42 43 return region; 44 } 45 46 static inline QRegion qwtMaskRegion( const QLine &l, int penWidth ) 47 { 48 const int pw = qMax( penWidth, 1 ); 49 const int pw2 = penWidth / 2; 50 51 QRegion region; 52 53 if ( l.x1() == l.x2() ) 54 { 55 region += QRect( l.x1() - pw2, l.y1(), 56 pw, l.y2() ).normalized(); 57 } 58 else if ( l.y1() == l.y2() ) 59 { 60 region += QRect( l.x1(), l.y1() - pw2, 61 l.x2(), pw ).normalized(); 62 } 63 64 return region; 65 } 66 67 class QwtPickerRubberband: public QwtWidgetOverlay 25 68 { 26 69 public: 27 enum Type 28 { 29 RubberBand, 30 Text 31 }; 32 33 PickerWidget( QwtPicker *, QWidget *, Type ); 34 void updateMask(); 35 36 /* 37 For a tracker text with a background we can use the background 38 rect as mask. Also for "regular" Qt widgets >= 4.3.0 we 39 don't need to mask the text anymore. 40 */ 41 bool d_hasTextMask; 70 QwtPickerRubberband( QwtPicker *, QWidget * ); 42 71 43 72 protected: 44 virtual void paintEvent( QPaintEvent * ); 73 virtual void drawOverlay( QPainter * ) const; 74 virtual QRegion maskHint() const; 45 75 46 76 QwtPicker *d_picker; 47 Type d_type;48 77 }; 49 78 79 class QwtPickerTracker: public QwtWidgetOverlay 80 { 81 public: 82 QwtPickerTracker( QwtPicker *, QWidget * ); 83 84 protected: 85 virtual void drawOverlay( QPainter * ) const; 86 virtual QRegion maskHint() const; 87 88 QwtPicker *d_picker; 89 }; 90 91 50 92 class QwtPicker::PrivateData 51 93 { 52 94 public: 95 PrivateData(): 96 enabled( false ), 97 stateMachine( NULL ), 98 resizeMode( QwtPicker::Stretch ), 99 rubberBand( QwtPicker::NoRubberBand ), 100 trackerMode( QwtPicker::AlwaysOff ), 101 isActive( false ), 102 trackerPosition( -1, -1 ), 103 mouseTracking( false ), 104 openGL( false ) 105 { 106 } 107 53 108 bool enabled; 54 109 … … 70 125 bool mouseTracking; // used to save previous value 71 126 72 /* 73 On X11 the widget below the picker widgets gets paint events 74 with a region that is the bounding rect of the mask, if it is complex. 75 In case of (f.e) a CrossRubberBand and a text this creates complete 76 repaints of the widget. So we better use two different widgets. 77 */ 78 79 QPointer<PickerWidget> rubberBandWidget; 80 QPointer<PickerWidget> trackerWidget; 127 QPointer< QwtPickerRubberband > rubberBandOverlay; 128 QPointer< QwtPickerTracker> trackerOverlay; 129 130 bool openGL; 81 131 }; 82 132 83 QwtPicker::PickerWidget::PickerWidget( 84 QwtPicker *picker, QWidget *parent, Type type ): 85 QWidget( parent ), 86 d_hasTextMask( false ), 87 d_picker( picker ), 88 d_type( type ) 89 { 90 setAttribute( Qt::WA_TransparentForMouseEvents ); 91 setAttribute( Qt::WA_NoSystemBackground ); 92 setFocusPolicy( Qt::NoFocus ); 93 } 94 95 void QwtPicker::PickerWidget::updateMask() 96 { 97 QRegion mask; 98 99 if ( d_type == RubberBand ) 100 { 101 QBitmap bm( width(), height() ); 102 bm.fill( Qt::color0 ); 103 104 QPainter painter( &bm ); 105 QPen pen = d_picker->rubberBandPen(); 106 pen.setColor( Qt::color1 ); 107 painter.setPen( pen ); 108 109 d_picker->drawRubberBand( &painter ); 110 111 mask = QRegion( bm ); 112 } 113 if ( d_type == Text ) 114 { 115 d_hasTextMask = parentWidget()->testAttribute( Qt::WA_PaintOnScreen ); 116 117 if ( d_hasTextMask ) 118 { 119 const QwtText label = d_picker->trackerText( 120 d_picker->trackerPosition() ); 121 122 if ( label.testPaintAttribute( QwtText::PaintBackground ) 123 && label.backgroundBrush().style() != Qt::NoBrush ) 124 { 125 if ( label.backgroundBrush().color().alpha() > 0 ) 126 { 127 // We don't need a text mask, when we have a background 128 d_hasTextMask = false; 129 } 130 } 131 } 132 133 if ( d_hasTextMask ) 134 { 135 QBitmap bm( width(), height() ); 136 bm.fill( Qt::color0 ); 137 138 QPainter painter( &bm ); 139 painter.setFont( font() ); 140 141 QPen pen = d_picker->trackerPen(); 142 pen.setColor( Qt::color1 ); 143 painter.setPen( pen ); 144 145 d_picker->drawTracker( &painter ); 146 147 mask = QRegion( bm ); 148 } 149 else 150 { 151 mask = d_picker->trackerRect( font() ); 152 } 153 } 154 155 QWidget *w = parentWidget(); 156 if ( w && !w->testAttribute( Qt::WA_PaintOnScreen ) ) 157 { 158 // The parent widget gets an update for its complete rectangle 159 // when the mask is changed in visible state. 160 // With this hide/show we only get an update for the 161 // previous mask. 162 163 hide(); 164 } 165 setMask( mask ); 166 setVisible( !mask.isEmpty() ); 167 } 168 169 void QwtPicker::PickerWidget::paintEvent( QPaintEvent *e ) 170 { 171 QPainter painter( this ); 172 painter.setClipRegion( e->region() ); 173 174 if ( d_type == RubberBand ) 175 { 176 painter.setPen( d_picker->rubberBandPen() ); 177 d_picker->drawRubberBand( &painter ); 178 } 179 180 if ( d_type == Text ) 181 { 182 /* 183 If we have a text mask we simply fill the region of 184 the mask. This gives better results for antialiased fonts. 185 */ 186 if ( d_hasTextMask ) 187 { 188 painter.fillRect( e->rect(), 189 QBrush( d_picker->trackerPen().color() ) ); 190 } 191 else 192 { 193 painter.setPen( d_picker->trackerPen() ); 194 d_picker->drawTracker( &painter ); 195 } 196 } 133 QwtPickerRubberband::QwtPickerRubberband( 134 QwtPicker *picker, QWidget *parent ): 135 QwtWidgetOverlay( parent ), 136 d_picker( picker ) 137 { 138 setMaskMode( QwtWidgetOverlay::MaskHint ); 139 } 140 141 QRegion QwtPickerRubberband::maskHint() const 142 { 143 return d_picker->rubberBandMask(); 144 } 145 146 void QwtPickerRubberband::drawOverlay( QPainter *painter ) const 147 { 148 painter->setPen( d_picker->rubberBandPen() ); 149 d_picker->drawRubberBand( painter ); 150 } 151 152 QwtPickerTracker::QwtPickerTracker( 153 QwtPicker *picker, QWidget *parent ): 154 QwtWidgetOverlay( parent ), 155 d_picker( picker ) 156 { 157 setMaskMode( QwtWidgetOverlay::MaskHint ); 158 } 159 160 QRegion QwtPickerTracker::maskHint() const 161 { 162 return d_picker->trackerRect( font() ); 163 } 164 165 void QwtPickerTracker::drawOverlay( QPainter *painter ) const 166 { 167 painter->setPen( d_picker->trackerPen() ); 168 d_picker->drawTracker( painter ); 197 169 } 198 170 … … 201 173 202 174 Creates an picker that is enabled, but without a state machine. 203 rubber band and tracker are disabled.175 rubber band and tracker are disabled. 204 176 205 177 \param parent Parent widget, that will be observed … … 215 187 Constructor 216 188 217 \param rubberBand Rubber band style189 \param rubberBand Rubber band style 218 190 \param trackerMode Tracker mode 219 191 \param parent Parent widget, that will be observed … … 230 202 { 231 203 setMouseTracking( false ); 204 232 205 delete d_data->stateMachine; 233 delete d_data->rubberBandWidget; 234 delete d_data->trackerWidget; 206 delete d_data->rubberBandOverlay; 207 delete d_data->trackerOverlay; 208 235 209 delete d_data; 236 210 } 237 211 238 //! Init the picker,used by the constructors212 //! Initialize the picker - used by the constructors 239 213 void QwtPicker::init( QWidget *parent, 240 214 RubberBand rubberBand, DisplayMode trackerMode ) … … 242 216 d_data = new PrivateData; 243 217 244 d_data->rubberBandWidget = NULL;245 d_data->trackerWidget = NULL;246 247 218 d_data->rubberBand = rubberBand; 248 d_data->enabled = false;249 d_data->resizeMode = Stretch;250 d_data->trackerMode = AlwaysOff;251 d_data->isActive = false;252 d_data->trackerPosition = QPoint( -1, -1 );253 d_data->mouseTracking = false;254 255 d_data->stateMachine = NULL;256 219 257 220 if ( parent ) … … 260 223 parent->setFocusPolicy( Qt::WheelFocus ); 261 224 225 d_data->openGL = parent->inherits( "QGLWidget" ); 262 226 d_data->trackerFont = parent->font(); 263 227 d_data->mouseTracking = parent->hasMouseTracking(); 228 264 229 setEnabled( true ); 265 230 } 231 266 232 setTrackerMode( trackerMode ); 267 233 } … … 326 292 327 293 /*! 328 Set the rubber band style329 330 \param rubberBand Rubber band style294 Set the rubber band style 295 296 \param rubberBand Rubber band style 331 297 The default value is NoRubberBand. 332 298 … … 339 305 340 306 /*! 341 \return Rubber band style307 \return Rubber band style 342 308 \sa setRubberBand(), RubberBand, rubberBandPen() 343 309 */ … … 500 466 Set the pen for the rubberband 501 467 502 \param pen Rubber band pen468 \param pen Rubber band pen 503 469 \sa rubberBandPen(), setRubberBand() 504 470 */ … … 513 479 514 480 /*! 515 \return Rubber band pen481 \return Rubber band pen 516 482 \sa setRubberBandPen(), rubberBand() 517 483 */ … … 553 519 554 520 /*! 555 Draw a rubberband, depending on rubberBand()556 557 \param painter Painter, initialized with clip rect558 559 \sa rubberBand(), RubberBand560 */ 561 562 void QwtPicker::drawRubberBand( QPainter *painter ) const 563 { 521 Calculate the mask for the rubber band overlay 522 523 \return Region for the mask 524 \sa QWidget::setMask() 525 */ 526 QRegion QwtPicker::rubberBandMask() const 527 { 528 QRegion mask; 529 564 530 if ( !isActive() || rubberBand() == NoRubberBand || 565 531 rubberBandPen().style() == Qt::NoPen ) 566 532 { 567 return; 568 } 569 570 const QRect &pRect = pickRect(); 533 return mask; 534 } 535 571 536 const QPolygon pa = adjustedPoints( d_data->pickedPoints ); 572 537 … … 583 548 { 584 549 if ( pa.count() < 1 ) 550 return mask; 551 552 const QPoint pos = pa[0]; 553 const int pw = rubberBandPen().width(); 554 555 const QRect pRect = pickArea().boundingRect().toRect(); 556 switch ( rubberBand() ) 557 { 558 case VLineRubberBand: 559 { 560 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 561 pos.x(), pRect.bottom() ), pw ); 562 break; 563 } 564 case HLineRubberBand: 565 { 566 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 567 pRect.right(), pos.y() ), pw ); 568 break; 569 } 570 case CrossRubberBand: 571 { 572 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 573 pos.x(), pRect.bottom() ), pw ); 574 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 575 pRect.right(), pos.y() ), pw ); 576 break; 577 } 578 default: 579 break; 580 } 581 break; 582 } 583 case QwtPickerMachine::RectSelection: 584 { 585 if ( pa.count() < 2 ) 586 return mask; 587 588 const int pw = rubberBandPen().width(); 589 590 switch ( rubberBand() ) 591 { 592 case RectRubberBand: 593 { 594 const QRect r = QRect( pa.first(), pa.last() ); 595 mask = qwtMaskRegion( r.normalized(), pw ); 596 break; 597 } 598 case EllipseRubberBand: 599 { 600 const QRect r = QRect( pa.first(), pa.last() ); 601 mask += r.adjusted( -pw, -pw, pw, pw ); 602 break; 603 } 604 default: 605 break; 606 } 607 break; 608 } 609 case QwtPickerMachine::PolygonSelection: 610 { 611 const int pw = rubberBandPen().width(); 612 if ( pw <= 1 ) 613 { 614 // because of the join style we better 615 // return a mask for a pen width <= 1 only 616 617 const int off = 2 * pw; 618 const QRect r = pa.boundingRect(); 619 mask += r.adjusted( -off, -off, off, off ); 620 } 621 break; 622 } 623 default: 624 break; 625 } 626 627 return mask; 628 } 629 630 /*! 631 Draw a rubber band, depending on rubberBand() 632 633 \param painter Painter, initialized with a clip region 634 635 \sa rubberBand(), RubberBand 636 */ 637 638 void QwtPicker::drawRubberBand( QPainter *painter ) const 639 { 640 if ( !isActive() || rubberBand() == NoRubberBand || 641 rubberBandPen().style() == Qt::NoPen ) 642 { 643 return; 644 } 645 646 const QPolygon pa = adjustedPoints( d_data->pickedPoints ); 647 648 QwtPickerMachine::SelectionType selectionType = 649 QwtPickerMachine::NoSelection; 650 651 if ( d_data->stateMachine ) 652 selectionType = d_data->stateMachine->selectionType(); 653 654 switch ( selectionType ) 655 { 656 case QwtPickerMachine::NoSelection: 657 case QwtPickerMachine::PointSelection: 658 { 659 if ( pa.count() < 1 ) 585 660 return; 586 661 587 662 const QPoint pos = pa[0]; 588 663 664 const QRect pRect = pickArea().boundingRect().toRect(); 589 665 switch ( rubberBand() ) 590 666 { 591 667 case VLineRubberBand: 668 { 592 669 QwtPainter::drawLine( painter, pos.x(), 593 670 pRect.top(), pos.x(), pRect.bottom() ); 594 671 break; 595 672 } 596 673 case HLineRubberBand: 674 { 597 675 QwtPainter::drawLine( painter, pRect.left(), 598 676 pos.y(), pRect.right(), pos.y() ); 599 677 break; 600 678 } 601 679 case CrossRubberBand: 680 { 602 681 QwtPainter::drawLine( painter, pos.x(), 603 682 pRect.top(), pos.x(), pRect.bottom() ); … … 605 684 pos.y(), pRect.right(), pos.y() ); 606 685 break; 686 } 607 687 default: 608 688 break; … … 615 695 return; 616 696 617 const QPoint p1 = pa[0]; 618 const QPoint p2 = pa[int( pa.count() - 1 )]; 619 620 const QRect rect = QRect( p1, p2 ).normalized(); 697 const QRect rect = QRect( pa.first(), pa.last() ).normalized(); 621 698 switch ( rubberBand() ) 622 699 { 623 700 case EllipseRubberBand: 701 { 624 702 QwtPainter::drawEllipse( painter, rect ); 625 703 break; 704 } 626 705 case RectRubberBand: 706 { 627 707 QwtPainter::drawRect( painter, rect ); 628 708 break; 709 } 629 710 default: 630 711 break; … … 694 775 return adjusted; 695 776 }\endverbatim\n 777 778 \param points Selected points 779 \return Selected points unmodified 696 780 */ 697 781 QPolygon QwtPicker::adjustedPoints( const QPolygon &points ) const … … 773 857 textRect.moveTopLeft( QPoint( x, y ) ); 774 858 775 int right = qMin( textRect.right(), pickRect().right() - margin ); 776 int bottom = qMin( textRect.bottom(), pickRect().bottom() - margin ); 859 const QRect pickRect = pickArea().boundingRect().toRect(); 860 861 int right = qMin( textRect.right(), pickRect.right() - margin ); 862 int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin ); 777 863 textRect.moveBottomRight( QPoint( right, bottom ) ); 778 864 779 int left = qMax( textRect.left(), pickRect ().left() + margin );780 int top = qMax( textRect.top(), pickRect ().top() + margin );865 int left = qMax( textRect.left(), pickRect.left() + margin ); 866 int top = qMax( textRect.top(), pickRect.top() + margin ); 781 867 textRect.moveTopLeft( QPoint( left, top ) ); 782 868 … … 787 873 \brief Event filter 788 874 789 When isEnabled() ==true all events of the observed widget are filtered.875 When isEnabled() is true all events of the observed widget are filtered. 790 876 Mouse and keyboard events are translated into widgetMouse- and widgetKey- 791 877 and widgetWheel-events. Paint and Resize events are handled to keep 792 rubber band and tracker up to date.878 rubber band and tracker up to date. 793 879 794 880 \param object Object to be filtered 795 881 \param event Event 882 883 \return Always false. 796 884 797 885 \sa widgetEnterEvent(), widgetLeaveEvent(), … … 809 897 case QEvent::Resize: 810 898 { 811 const QResizeEvent *re = ( QResizeEvent * )event; 899 const QResizeEvent *re = static_cast<QResizeEvent *>( event ); 900 901 /* 902 Adding/deleting additional event filters inside of an event filter 903 is not safe dues to the implementation in Qt ( changing alist while iterating ). 904 So we create the overlays in a way, that they don't install en event filter 905 ( parent set to NULL ) and do the resizing here. 906 */ 907 if ( d_data->trackerOverlay ) 908 d_data->trackerOverlay->resize( re->size() ); 909 910 if ( d_data->rubberBandOverlay ) 911 d_data->rubberBandOverlay->resize( re->size() ); 912 812 913 if ( d_data->resizeMode == Stretch ) 813 914 stretchSelection( re->oldSize(), re->size() ); 814 915 815 if ( d_data->rubberBandWidget ) 816 d_data->rubberBandWidget->resize( re->size() ); 817 818 if ( d_data->trackerWidget ) 819 d_data->trackerWidget->resize( re->size() ); 916 updateDisplay(); 820 917 break; 821 918 } 822 919 case QEvent::Enter: 920 { 823 921 widgetEnterEvent( event ); 824 922 break; 923 } 825 924 case QEvent::Leave: 925 { 826 926 widgetLeaveEvent( event ); 827 927 break; 928 } 828 929 case QEvent::MouseButtonPress: 829 widgetMousePressEvent( ( QMouseEvent * )event ); 930 { 931 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) ); 830 932 break; 933 } 831 934 case QEvent::MouseButtonRelease: 832 widgetMouseReleaseEvent( ( QMouseEvent * )event ); 935 { 936 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) ); 833 937 break; 938 } 834 939 case QEvent::MouseButtonDblClick: 835 widgetMouseDoubleClickEvent( ( QMouseEvent * )event ); 940 { 941 widgetMouseDoubleClickEvent( static_cast<QMouseEvent *>( event ) ); 836 942 break; 943 } 837 944 case QEvent::MouseMove: 838 widgetMouseMoveEvent( ( QMouseEvent * )event ); 945 { 946 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) ); 839 947 break; 948 } 840 949 case QEvent::KeyPress: 841 widgetKeyPressEvent( ( QKeyEvent * )event ); 950 { 951 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) ); 842 952 break; 953 } 843 954 case QEvent::KeyRelease: 844 widgetKeyReleaseEvent( ( QKeyEvent * )event ); 955 { 956 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) ); 845 957 break; 958 } 846 959 case QEvent::Wheel: 847 widgetWheelEvent( ( QWheelEvent * )event ); 960 { 961 widgetWheelEvent( static_cast<QWheelEvent *>( event ) ); 848 962 break; 963 } 849 964 default: 850 965 break; … … 879 994 void QwtPicker::widgetMouseMoveEvent( QMouseEvent *mouseEvent ) 880 995 { 881 if ( pick Rect().contains( mouseEvent->pos() ) )996 if ( pickArea().contains( mouseEvent->pos() ) ) 882 997 d_data->trackerPosition = mouseEvent->pos(); 883 998 else … … 923 1038 924 1039 /*! 925 Handle a mouse rel ase event for the observed widget.1040 Handle a mouse release event for the observed widget. 926 1041 927 1042 \param mouseEvent Mouse event … … 964 1079 void QwtPicker::widgetWheelEvent( QWheelEvent *wheelEvent ) 965 1080 { 966 if ( pick Rect().contains( wheelEvent->pos() ) )1081 if ( pickArea().contains( wheelEvent->pos() ) ) 967 1082 d_data->trackerPosition = wheelEvent->pos(); 968 1083 else … … 1014 1129 if ( dx != 0 || dy != 0 ) 1015 1130 { 1016 const QRect rect = pick Rect();1131 const QRect rect = pickArea().boundingRect().toRect(); 1017 1132 const QPoint pos = parentWidget()->mapFromGlobal( QCursor::pos() ); 1018 1133 … … 1048 1163 Passes an event to the state machine and executes the resulting 1049 1164 commands. Append and Move commands use the current position 1050 of the cursor ( QCursor::pos()).1165 of the cursor ( QCursor::pos() ). 1051 1166 1052 1167 \param event Event … … 1177 1292 1178 1293 /*! 1179 Reset the state machine and terminate ( end(false)) the selection1294 Reset the state machine and terminate ( end(false) ) the selection 1180 1295 */ 1181 1296 void QwtPicker::reset() … … 1189 1304 1190 1305 /*! 1191 Append a point to the selection and update rubber band and tracker.1306 Append a point to the selection and update rubber band and tracker. 1192 1307 The appended() signal is emitted. 1193 1308 … … 1259 1374 1260 1375 /*! 1261 \brief Validate and fix up the selection1376 \brief Validate and fix up the selection 1262 1377 1263 1378 Accepts all selections unmodified 1264 1379 1265 \param selection Selection to validate and fix up1380 \param selection Selection to validate and fix up 1266 1381 \return true, when accepted, false otherwise 1267 1382 */ … … 1359 1474 \return parentWidget()->contentsRect() 1360 1475 */ 1361 QRect QwtPicker::pickRect() const 1362 { 1476 QPainterPath QwtPicker::pickArea() const 1477 { 1478 QPainterPath path; 1479 1363 1480 const QWidget *widget = parentWidget(); 1364 1481 if ( widget ) 1365 return widget->contentsRect();1366 1367 return QRect();1368 } 1369 1370 //! Update the state of rubber band and tracker label1482 path.addRect( widget->contentsRect() ); 1483 1484 return path; 1485 } 1486 1487 //! Update the state of rubber band and tracker label 1371 1488 void QwtPicker::updateDisplay() 1372 1489 { … … 1375 1492 bool showRubberband = false; 1376 1493 bool showTracker = false; 1494 1377 1495 if ( w && w->isVisible() && d_data->enabled ) 1378 1496 { … … 1386 1504 ( trackerMode() == ActiveOnly && isActive() ) ) 1387 1505 { 1388 if ( trackerPen() != Qt::NoPen ) 1506 if ( trackerPen() != Qt::NoPen 1507 && !trackerRect( QFont() ).isEmpty() ) 1508 { 1389 1509 showTracker = true; 1390 } 1391 } 1392 1393 QPointer<PickerWidget> &rw = d_data->rubberBandWidget; 1510 } 1511 } 1512 } 1513 1514 QPointer< QwtPickerRubberband > &rw = d_data->rubberBandOverlay; 1394 1515 if ( showRubberband ) 1395 1516 { 1396 1517 if ( rw.isNull() ) 1397 1518 { 1398 rw = new PickerWidget( this, w, PickerWidget::RubberBand ); 1519 rw = new QwtPickerRubberband( this, NULL ); // NULL -> no extra event filter 1520 rw->setObjectName( "PickerRubberBand" ); 1521 rw->setParent( w ); 1399 1522 rw->resize( w->size() ); 1400 1523 } 1401 rw->updateMask(); 1402 rw->update(); // Needed, when the mask doesn't change 1524 1525 if ( d_data->rubberBand <= RectRubberBand ) 1526 rw->setMaskMode( QwtWidgetOverlay::MaskHint ); 1527 else 1528 rw->setMaskMode( QwtWidgetOverlay::AlphaMask ); 1529 1530 rw->updateOverlay(); 1403 1531 } 1404 1532 else 1405 delete rw; 1406 1407 QPointer<PickerWidget> &tw = d_data->trackerWidget; 1533 { 1534 if ( d_data->openGL ) 1535 { 1536 // Qt 4.8 crashes for a delete 1537 if ( !rw.isNull() ) 1538 { 1539 rw->hide(); 1540 rw->deleteLater(); 1541 rw = NULL; 1542 } 1543 } 1544 else 1545 { 1546 delete rw; 1547 } 1548 } 1549 1550 QPointer< QwtPickerTracker > &tw = d_data->trackerOverlay; 1408 1551 if ( showTracker ) 1409 1552 { 1410 1553 if ( tw.isNull() ) 1411 1554 { 1412 tw = new PickerWidget( this, w, PickerWidget::Text ); 1555 tw = new QwtPickerTracker( this, NULL ); // NULL -> no extra event filter 1556 tw->setObjectName( "PickerTracker" ); 1557 tw->setParent( w ); 1413 1558 tw->resize( w->size() ); 1414 1559 } 1415 1560 tw->setFont( d_data->trackerFont ); 1416 tw->updateMask(); 1417 tw->update(); // Needed, when the mask doesn't change 1561 tw->updateOverlay(); 1418 1562 } 1419 1563 else 1420 delete tw; 1421 } 1422 1423 //! \return Widget displaying the rubberband 1424 const QWidget *QwtPicker::rubberBandWidget() const 1425 { 1426 return d_data->rubberBandWidget; 1427 } 1428 1429 //! \return Widget displaying the tracker text 1430 const QWidget *QwtPicker::trackerWidget() const 1431 { 1432 return d_data->trackerWidget; 1433 } 1434 1564 { 1565 if ( d_data->openGL ) 1566 { 1567 // Qt 4.8 crashes for a delete 1568 if ( !tw.isNull() ) 1569 { 1570 tw->hide(); 1571 tw->deleteLater(); 1572 tw = NULL; 1573 } 1574 } 1575 else 1576 { 1577 delete tw; 1578 } 1579 } 1580 } 1581 1582 //! \return Overlay displaying the rubber band 1583 const QwtWidgetOverlay *QwtPicker::rubberBandOverlay() const 1584 { 1585 return d_data->rubberBandOverlay; 1586 } 1587 1588 //! \return Overlay displaying the tracker text 1589 const QwtWidgetOverlay *QwtPicker::trackerOverlay() const 1590 { 1591 return d_data->trackerOverlay; 1592 } 1593
Note:
See TracChangeset
for help on using the changeset viewer.