Changeset 9383 in ntrip for trunk/BNC/qwt/qwt_picker.cpp
- Timestamp:
- Mar 19, 2021, 9:15:03 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_picker.cpp
r8127 r9383 53 53 if ( l.x1() == l.x2() ) 54 54 { 55 region += QRect( l.x1() - pw2, l.y1(), 55 region += QRect( l.x1() - pw2, l.y1(), 56 56 pw, l.y2() ).normalized(); 57 57 } 58 58 else if ( l.y1() == l.y2() ) 59 59 { 60 region += QRect( l.x1(), l.y1() - pw2, 60 region += QRect( l.x1(), l.y1() - pw2, 61 61 l.x2(), pw ).normalized(); 62 62 } … … 78 78 79 79 class QwtPickerTracker: public QwtWidgetOverlay 80 { 80 { 81 81 public: 82 82 QwtPickerTracker( QwtPicker *, QWidget * ); 83 83 84 84 protected: 85 85 virtual void drawOverlay( QPainter * ) const; 86 86 virtual QRegion maskHint() const; 87 87 88 88 QwtPicker *d_picker; 89 }; 89 }; 90 90 91 91 … … 105 105 { 106 106 } 107 107 108 108 bool enabled; 109 109 … … 558 558 case VLineRubberBand: 559 559 { 560 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 560 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 561 561 pos.x(), pRect.bottom() ), pw ); 562 562 break; … … 564 564 case HLineRubberBand: 565 565 { 566 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 566 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 567 567 pRect.right(), pos.y() ), pw ); 568 568 break; … … 570 570 case CrossRubberBand: 571 571 { 572 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 572 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 573 573 pos.x(), pRect.bottom() ), pw ); 574 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 574 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 575 575 pRect.right(), pos.y() ), pw ); 576 576 break; … … 752 752 depends on the application requirements. F.e. : 753 753 754 - A rectangular selection might need to have a specific aspect ratio only.\n755 - A selection could accept non intersecting polygons only.\n756 - ...\n754 - A rectangular selection might need to have a specific aspect ratio only. 755 - A selection could accept non intersecting polygons only. 756 - ... 757 757 758 758 The example below is for a rectangular selection, where the first 759 759 point is the center of the selected rectangle. 760 760 761 \par Example 761 \verbatim QPolygon MyPicker::adjustedPoints(const QPolygon &points) const 762 { 763 QPolygon adjusted; 764 if ( points.size() == 2 ) 765 { 766 const int width = qAbs(points[1].x() - points[0].x()); 767 const int height = qAbs(points[1].y() - points[0].y()); 768 769 QRect rect(0, 0, 2 * width, 2 * height); 770 rect.moveCenter(points[0]); 771 772 adjusted += rect.topLeft(); 773 adjusted += rect.bottomRight(); 774 } 775 return adjusted; 776 }\endverbatim\n 762 \code 763 QPolygon MyPicker::adjustedPoints( const QPolygon &points ) const 764 { 765 QPolygon adjusted; 766 if ( points.size() == 2 ) 767 { 768 const int width = qAbs( points[1].x() - points[0].x() ); 769 const int height = qAbs( points[1].y() - points[0].y() ); 770 771 QRect rect( 0, 0, 2 * width, 2 * height ); 772 rect.moveCenter( points[0] ); 773 774 adjusted += rect.topLeft(); 775 adjusted += rect.bottomRight(); 776 } 777 return adjusted; 778 } 779 \endcode 780 \endpar 777 781 778 782 \param points Selected points … … 833 837 { 834 838 const QPoint last = 835 d_data->pickedPoints[ int( d_data->pickedPoints.count() ) - 2];839 d_data->pickedPoints[ d_data->pickedPoints.count() - 2 ]; 836 840 837 841 alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft; … … 1183 1187 case QEvent::MouseMove: 1184 1188 { 1185 const QMouseEvent *me = 1189 const QMouseEvent *me = 1186 1190 static_cast< const QMouseEvent * >( event ); 1187 1191 pos = me->pos(); … … 1235 1239 return; 1236 1240 1237 d_data->pickedPoints. resize( 0);1241 d_data->pickedPoints.clear(); 1238 1242 d_data->isActive = true; 1239 1243 Q_EMIT activated( true ); … … 1281 1285 Q_EMIT selected( d_data->pickedPoints ); 1282 1286 else 1283 d_data->pickedPoints. resize( 0);1287 d_data->pickedPoints.clear(); 1284 1288 1285 1289 updateDisplay(); … … 1315 1319 if ( d_data->isActive ) 1316 1320 { 1317 const int idx = d_data->pickedPoints.count(); 1318 d_data->pickedPoints.resize( idx + 1 ); 1319 d_data->pickedPoints[idx] = pos; 1321 d_data->pickedPoints += pos; 1320 1322 1321 1323 updateDisplay(); … … 1333 1335 void QwtPicker::move( const QPoint &pos ) 1334 1336 { 1335 if ( d_data->isActive ) 1336 { 1337 const int idx = d_data->pickedPoints.count() - 1; 1338 if ( idx >= 0 ) 1339 { 1340 if ( d_data->pickedPoints[idx] != pos ) 1341 { 1342 d_data->pickedPoints[idx] = pos; 1343 1344 updateDisplay(); 1345 Q_EMIT moved( pos ); 1346 } 1337 if ( d_data->isActive && !d_data->pickedPoints.isEmpty() ) 1338 { 1339 QPoint &point = d_data->pickedPoints.last(); 1340 if ( point != pos ) 1341 { 1342 point = pos; 1343 1344 updateDisplay(); 1345 Q_EMIT moved( pos ); 1347 1346 } 1348 1347 } … … 1357 1356 void QwtPicker::remove() 1358 1357 { 1359 if ( d_data->isActive ) 1360 { 1361 const int idx = d_data->pickedPoints.count() - 1; 1362 if ( idx > 0 ) 1363 { 1364 const int idx = d_data->pickedPoints.count(); 1365 1366 const QPoint pos = d_data->pickedPoints[idx - 1]; 1367 d_data->pickedPoints.resize( idx - 1 ); 1368 1369 updateDisplay(); 1370 Q_EMIT removed( pos ); 1371 } 1358 if ( d_data->isActive && !d_data->pickedPoints.isEmpty() ) 1359 { 1360 #if QT_VERSION >= 0x050100 1361 const QPoint pos = d_data->pickedPoints.takeLast(); 1362 #else 1363 const QPoint pos = d_data->pickedPoints.last(); 1364 d_data->pickedPoints.resize( d_data->pickedPoints.count() - 1 ); 1365 #endif 1366 1367 updateDisplay(); 1368 Q_EMIT removed( pos ); 1372 1369 } 1373 1370 } … … 1424 1421 } 1425 1422 1426 const double xRatio = 1427 double( newSize.width() ) / double( oldSize.width() ); 1428 const double yRatio = 1429 double( newSize.height() ) / double( oldSize.height() ); 1430 1431 for ( int i = 0; i < int( d_data->pickedPoints.count() ); i++ ) 1423 const double xRatio = double( newSize.width() ) / double( oldSize.width() ); 1424 const double yRatio = double( newSize.height() ) / double( oldSize.height() ); 1425 1426 for ( int i = 0; i < d_data->pickedPoints.count(); i++ ) 1432 1427 { 1433 1428 QPoint &p = d_data->pickedPoints[i]; … … 1472 1467 Find the area of the observed widget, where selection might happen. 1473 1468 1474 \return parentWidget()->contentsRect() 1469 \return parentWidget()->contentsRect() 1475 1470 */ 1476 1471 QPainterPath QwtPicker::pickArea() const … … 1504 1499 ( trackerMode() == ActiveOnly && isActive() ) ) 1505 1500 { 1506 if ( trackerPen() != Qt::NoPen 1501 if ( trackerPen() != Qt::NoPen 1507 1502 && !trackerRect( QFont() ).isEmpty() ) 1508 1503 {
Note:
See TracChangeset
for help on using the changeset viewer.