Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_panner.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_panner.cpp (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_panner.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_picker.h" 12 12 #include "qwt_painter.h" 13 13 14 #include <qpainter.h> 14 15 #include <qpixmap.h> … … 17 18 #include <qbitmap.h> 18 19 19 static QVector<QwtPicker *> qwtActivePickers( QWidget*w )20 { 21 QVector<QwtPicker *> pickers;20 static QVector< QwtPicker* > qwtActivePickers( QWidget* w ) 21 { 22 QVector< QwtPicker* > pickers; 22 23 23 24 QObjectList children = w->children(); 24 25 for ( int i = 0; i < children.size(); i++ ) 25 26 { 26 QwtPicker *picker = qobject_cast<QwtPicker*>( children[i] );27 QwtPicker* picker = qobject_cast< QwtPicker* >( children[i] ); 27 28 if ( picker && picker->isEnabled() ) 28 29 pickers += picker; … … 34 35 class QwtPanner::PrivateData 35 36 { 36 public: 37 PrivateData() :38 button( Qt::LeftButton ) ,39 buttonModifiers( Qt::NoModifier ) ,40 abortKey( Qt::Key_Escape ) ,41 abortKeyModifiers( Qt::NoModifier ) ,42 #ifndef QT_NO_CURSOR 43 cursor( NULL ) ,44 restoreCursor( NULL ) ,45 hasCursor( false ) ,46 #endif 47 isEnabled( false ) 48 {49 orientations = Qt::Vertical | Qt::Horizontal;37 public: 38 PrivateData() 39 : button( Qt::LeftButton ) 40 , buttonModifiers( Qt::NoModifier ) 41 , abortKey( Qt::Key_Escape ) 42 , abortKeyModifiers( Qt::NoModifier ) 43 #ifndef QT_NO_CURSOR 44 , cursor( NULL ) 45 , restoreCursor( NULL ) 46 , hasCursor( false ) 47 #endif 48 , isEnabled( false ) 49 , orientations( Qt::Vertical | Qt::Horizontal ) 50 { 50 51 } 51 52 … … 59 60 60 61 Qt::MouseButton button; 61 Qt::KeyboardModifiers buttonModifiers;62 Qt::KeyboardModifiers buttonModifiers; 62 63 63 64 int abortKey; … … 71 72 72 73 #ifndef QT_NO_CURSOR 73 QCursor *cursor;74 QCursor *restoreCursor;74 QCursor* cursor; 75 QCursor* restoreCursor; 75 76 bool hasCursor; 76 77 #endif … … 80 81 81 82 /*! 82 Creates an panner that is enabled for the left mouse button. 83 84 \param parent Parent widget to be panned 85 */ 86 QwtPanner::QwtPanner( QWidget *parent ):87 QWidget( parent ) 88 { 89 d_data = new PrivateData();83 Creates an panner that is enabled for the left mouse button. 84 85 \param parent Parent widget to be panned 86 */ 87 QwtPanner::QwtPanner( QWidget* parent ) 88 : QWidget( parent ) 89 { 90 m_data = new PrivateData(); 90 91 91 92 setAttribute( Qt::WA_TransparentForMouseEvents ); … … 100 101 QwtPanner::~QwtPanner() 101 102 { 102 delete d_data;103 delete m_data; 103 104 } 104 105 … … 106 107 Change the mouse button and modifiers used for panning 107 108 The defaults are Qt::LeftButton and Qt::NoModifier 108 */ 109 */ 109 110 void QwtPanner::setMouseButton( Qt::MouseButton button, 110 111 Qt::KeyboardModifiers modifiers ) 111 112 { 112 d_data->button = button;113 d_data->buttonModifiers = modifiers;113 m_data->button = button; 114 m_data->buttonModifiers = modifiers; 114 115 } 115 116 116 117 //! Get mouse button and modifiers used for panning 117 void QwtPanner::getMouseButton( Qt::MouseButton &button,118 Qt::KeyboardModifiers &modifiers ) const119 { 120 button = d_data->button;121 modifiers = d_data->buttonModifiers;118 void QwtPanner::getMouseButton( Qt::MouseButton& button, 119 Qt::KeyboardModifiers& modifiers ) const 120 { 121 button = m_data->button; 122 modifiers = m_data->buttonModifiers; 122 123 } 123 124 … … 128 129 \param key Key ( See Qt::Keycode ) 129 130 \param modifiers Keyboard modifiers 130 */ 131 */ 131 132 void QwtPanner::setAbortKey( int key, 132 133 Qt::KeyboardModifiers modifiers ) 133 134 { 134 d_data->abortKey = key;135 d_data->abortKeyModifiers = modifiers;135 m_data->abortKey = key; 136 m_data->abortKeyModifiers = modifiers; 136 137 } 137 138 138 139 //! Get the abort key and modifiers 139 void QwtPanner::getAbortKey( int &key,140 Qt::KeyboardModifiers &modifiers ) const141 { 142 key = d_data->abortKey;143 modifiers = d_data->abortKeyModifiers;140 void QwtPanner::getAbortKey( int& key, 141 Qt::KeyboardModifiers& modifiers ) const 142 { 143 key = m_data->abortKey; 144 modifiers = m_data->abortKeyModifiers; 144 145 } 145 146 … … 151 152 152 153 \sa setCursor() 153 */ 154 #ifndef QT_NO_CURSOR 155 void QwtPanner::setCursor( const QCursor &cursor )156 { 157 d_data->cursor = new QCursor( cursor );154 */ 155 #ifndef QT_NO_CURSOR 156 void QwtPanner::setCursor( const QCursor& cursor ) 157 { 158 m_data->cursor = new QCursor( cursor ); 158 159 } 159 160 #endif … … 162 163 \return Cursor that is active while panning 163 164 \sa setCursor() 164 */ 165 */ 165 166 #ifndef QT_NO_CURSOR 166 167 const QCursor QwtPanner::cursor() const 167 168 { 168 if ( d_data->cursor )169 return * d_data->cursor;169 if ( m_data->cursor ) 170 return *m_data->cursor; 170 171 171 172 if ( parentWidget() ) … … 177 178 178 179 /*! 179 \brief En/disable the panner 180 181 When enabled is true an event filter is installed for 182 the observed widget, otherwise the event filter is removed. 183 184 \param on true or false 185 \sa isEnabled(), eventFilter() 186 */ 180 \brief En/disable the panner 181 182 When enabled is true an event filter is installed for 183 the observed widget, otherwise the event filter is removed. 184 185 \param on true or false 186 \sa isEnabled(), eventFilter() 187 */ 187 188 void QwtPanner::setEnabled( bool on ) 188 189 { 189 if ( d_data->isEnabled != on )190 { 191 d_data->isEnabled = on;192 193 QWidget *w = parentWidget();190 if ( m_data->isEnabled != on ) 191 { 192 m_data->isEnabled = on; 193 194 QWidget* w = parentWidget(); 194 195 if ( w ) 195 196 { 196 if ( d_data->isEnabled )197 if ( m_data->isEnabled ) 197 198 { 198 199 w->installEventFilter( this ); … … 212 213 213 214 /param o Orientation 214 */ 215 */ 215 216 void QwtPanner::setOrientations( Qt::Orientations o ) 216 217 { 217 d_data->orientations = o;218 } 219 220 //! Return the orientation, where paning is enabled 218 m_data->orientations = o; 219 } 220 221 //! Return the orientation, where panning is enabled 221 222 Qt::Orientations QwtPanner::orientations() const 222 223 { 223 return d_data->orientations;224 return m_data->orientations; 224 225 } 225 226 … … 227 228 \return True if an orientation is enabled 228 229 \sa orientations(), setOrientations() 229 */ 230 */ 230 231 bool QwtPanner::isOrientationEnabled( Qt::Orientation o ) const 231 232 { 232 return d_data->orientations & o;233 } 234 235 /*! 236 \return true when enabled, false otherwise 237 \sa setEnabled, eventFilter() 238 */ 233 return m_data->orientations & o; 234 } 235 236 /*! 237 \return true when enabled, false otherwise 238 \sa setEnabled, eventFilter() 239 */ 239 240 bool QwtPanner::isEnabled() const 240 241 { 241 return d_data->isEnabled;242 return m_data->isEnabled; 242 243 } 243 244 … … 249 250 250 251 \param event Paint event 251 */ 252 void QwtPanner::paintEvent( QPaintEvent *event )253 { 254 int dx = d_data->pos.x() -d_data->initialPos.x();255 int dy = d_data->pos.y() -d_data->initialPos.y();252 */ 253 void QwtPanner::paintEvent( QPaintEvent* event ) 254 { 255 int dx = m_data->pos.x() - m_data->initialPos.x(); 256 int dy = m_data->pos.y() - m_data->initialPos.y(); 256 257 257 258 QRectF r; 258 r.setSize( d_data->pixmap.size() ); 259 #if QT_VERSION >= 0x050000 260 r.setSize( r.size() / d_data->pixmap.devicePixelRatio() ); 261 #endif 259 r.setSize( m_data->pixmap.size() / QwtPainter::devicePixelRatio( &m_data->pixmap ) ); 262 260 r.moveCenter( QPointF( r.center().x() + dx, r.center().y() + dy ) ); 263 261 … … 267 265 QPainter painter( &pm ); 268 266 269 if ( ! d_data->contentsMask.isNull() )270 { 271 QPixmap masked = d_data->pixmap;272 masked.setMask( d_data->contentsMask );267 if ( !m_data->contentsMask.isNull() ) 268 { 269 QPixmap masked = m_data->pixmap; 270 masked.setMask( m_data->contentsMask ); 273 271 painter.drawPixmap( r.toRect(), masked ); 274 272 } 275 273 else 276 274 { 277 painter.drawPixmap( r.toRect(), d_data->pixmap );275 painter.drawPixmap( r.toRect(), m_data->pixmap ); 278 276 } 279 277 280 278 painter.end(); 281 279 282 if ( ! d_data->contentsMask.isNull() )283 pm.setMask( d_data->contentsMask );280 if ( !m_data->contentsMask.isNull() ) 281 pm.setMask( m_data->contentsMask ); 284 282 285 283 painter.begin( this ); … … 289 287 290 288 /*! 291 \brief Calculate a mask for the contents of the panned widget 292 293 Sometimes only parts of the contents of a widget should be 294 panned. F.e. for a widget with a styled background with rounded borders 295 only the area inside of the border should be panned. 296 297 \return An empty bitmap, indicating no mask 298 */ 289 \brief Calculate a mask for the contents of the panned widget 290 291 Sometimes only parts of the contents of a widget should be 292 panned. F.e. for a widget with a styled background with rounded borders 293 only the area inside of the border should be panned. 294 295 \return An empty bitmap, indicating no mask 296 */ 299 297 QBitmap QwtPanner::contentsMask() const 300 298 { … … 303 301 304 302 /*! 305 Grab the widget into a pixmap. 306 \return Grabbed pixmap 307 */ 303 Grab the widget into a pixmap. 304 \return Grabbed pixmap 305 */ 308 306 QPixmap QwtPanner::grab() const 309 307 { … … 316 314 317 315 /*! 318 \brief Event filter 319 320 When isEnabled() is true mouse events of the 321 observed widget are filtered. 322 323 \param object Object to be filtered 324 \param event Event 325 326 \return Always false, beside for paint events for the 316 \brief Event filter 317 318 When isEnabled() is true mouse events of the 319 observed widget are filtered. 320 321 \param object Object to be filtered 322 \param event Event 323 324 \return Always false, beside for paint events for the 327 325 parent widget. 328 326 329 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 327 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 330 328 widgetMouseMoveEvent() 331 */ 332 bool QwtPanner::eventFilter( QObject *object, QEvent*event )329 */ 330 bool QwtPanner::eventFilter( QObject* object, QEvent* event ) 333 331 { 334 332 if ( object == NULL || object != parentWidget() ) … … 339 337 case QEvent::MouseButtonPress: 340 338 { 341 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );339 widgetMousePressEvent( static_cast< QMouseEvent* >( event ) ); 342 340 break; 343 341 } 344 342 case QEvent::MouseMove: 345 343 { 346 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );344 widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) ); 347 345 break; 348 346 } 349 347 case QEvent::MouseButtonRelease: 350 348 { 351 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );349 widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) ); 352 350 break; 353 351 } 354 352 case QEvent::KeyPress: 355 353 { 356 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );354 widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) ); 357 355 break; 358 356 } 359 357 case QEvent::KeyRelease: 360 358 { 361 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );359 widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) ); 362 360 break; 363 361 } … … 375 373 376 374 /*! 377 Handle a mouse press event for the observed widget. 378 379 \param mouseEvent Mouse event 380 \sa eventFilter(), widgetMouseReleaseEvent(), 375 Handle a mouse press event for the observed widget. 376 377 \param mouseEvent Mouse event 378 \sa eventFilter(), widgetMouseReleaseEvent(), 381 379 widgetMouseMoveEvent(), 382 */ 383 void QwtPanner::widgetMousePressEvent( QMouseEvent *mouseEvent )384 { 385 if ( ( mouseEvent->button() != d_data->button )386 || ( mouseEvent->modifiers() != d_data->buttonModifiers ) )380 */ 381 void QwtPanner::widgetMousePressEvent( QMouseEvent* mouseEvent ) 382 { 383 if ( ( mouseEvent->button() != m_data->button ) 384 || ( mouseEvent->modifiers() != m_data->buttonModifiers ) ) 387 385 { 388 386 return; 389 387 } 390 388 391 QWidget *w = parentWidget();389 QWidget* w = parentWidget(); 392 390 if ( w == NULL ) 393 391 return; … … 397 395 #endif 398 396 399 d_data->initialPos =d_data->pos = mouseEvent->pos();397 m_data->initialPos = m_data->pos = mouseEvent->pos(); 400 398 401 399 setGeometry( parentWidget()->rect() ); 402 400 403 401 // We don't want to grab the picker ! 404 QVector<QwtPicker *> pickers = qwtActivePickers( parentWidget() );402 QVector< QwtPicker* > pickers = qwtActivePickers( parentWidget() ); 405 403 for ( int i = 0; i < pickers.size(); i++ ) 406 404 pickers[i]->setEnabled( false ); 407 405 408 d_data->pixmap = grab();409 d_data->contentsMask = contentsMask();406 m_data->pixmap = grab(); 407 m_data->contentsMask = contentsMask(); 410 408 411 409 for ( int i = 0; i < pickers.size(); i++ ) … … 416 414 417 415 /*! 418 Handle a mouse move event for the observed widget. 419 420 \param mouseEvent Mouse event 421 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent() 422 */ 423 void QwtPanner::widgetMouseMoveEvent( QMouseEvent *mouseEvent )416 Handle a mouse move event for the observed widget. 417 418 \param mouseEvent Mouse event 419 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent() 420 */ 421 void QwtPanner::widgetMouseMoveEvent( QMouseEvent* mouseEvent ) 424 422 { 425 423 if ( !isVisible() ) … … 428 426 QPoint pos = mouseEvent->pos(); 429 427 if ( !isOrientationEnabled( Qt::Horizontal ) ) 430 pos.setX( d_data->initialPos.x() );428 pos.setX( m_data->initialPos.x() ); 431 429 if ( !isOrientationEnabled( Qt::Vertical ) ) 432 pos.setY( d_data->initialPos.y() );433 434 if ( pos != d_data->pos && rect().contains( pos ) )435 { 436 d_data->pos = pos;430 pos.setY( m_data->initialPos.y() ); 431 432 if ( pos != m_data->pos && rect().contains( pos ) ) 433 { 434 m_data->pos = pos; 437 435 update(); 438 436 439 Q_EMIT moved( d_data->pos.x() -d_data->initialPos.x(),440 d_data->pos.y() -d_data->initialPos.y() );441 } 442 } 443 444 /*! 445 Handle a mouse release event for the observed widget. 446 447 \param mouseEvent Mouse event 448 \sa eventFilter(), widgetMousePressEvent(), 437 Q_EMIT moved( m_data->pos.x() - m_data->initialPos.x(), 438 m_data->pos.y() - m_data->initialPos.y() ); 439 } 440 } 441 442 /*! 443 Handle a mouse release event for the observed widget. 444 445 \param mouseEvent Mouse event 446 \sa eventFilter(), widgetMousePressEvent(), 449 447 widgetMouseMoveEvent(), 450 */ 451 void QwtPanner::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )448 */ 449 void QwtPanner::widgetMouseReleaseEvent( QMouseEvent* mouseEvent ) 452 450 { 453 451 if ( isVisible() ) … … 460 458 QPoint pos = mouseEvent->pos(); 461 459 if ( !isOrientationEnabled( Qt::Horizontal ) ) 462 pos.setX( d_data->initialPos.x() );460 pos.setX( m_data->initialPos.x() ); 463 461 if ( !isOrientationEnabled( Qt::Vertical ) ) 464 pos.setY( d_data->initialPos.y() );465 466 d_data->pixmap = QPixmap();467 d_data->contentsMask = QBitmap();468 d_data->pos = pos;469 470 if ( d_data->pos !=d_data->initialPos )471 { 472 Q_EMIT panned( d_data->pos.x() -d_data->initialPos.x(),473 d_data->pos.y() -d_data->initialPos.y() );474 } 475 } 476 } 477 478 /*! 479 Handle a key press event for the observed widget. 480 481 \param keyEvent Key event 482 \sa eventFilter(), widgetKeyReleaseEvent() 483 */ 484 void QwtPanner::widgetKeyPressEvent( QKeyEvent *keyEvent )485 { 486 if ( ( keyEvent->key() == d_data->abortKey )487 && ( keyEvent->modifiers() == d_data->abortKeyModifiers ) )462 pos.setY( m_data->initialPos.y() ); 463 464 m_data->pixmap = QPixmap(); 465 m_data->contentsMask = QBitmap(); 466 m_data->pos = pos; 467 468 if ( m_data->pos != m_data->initialPos ) 469 { 470 Q_EMIT panned( m_data->pos.x() - m_data->initialPos.x(), 471 m_data->pos.y() - m_data->initialPos.y() ); 472 } 473 } 474 } 475 476 /*! 477 Handle a key press event for the observed widget. 478 479 \param keyEvent Key event 480 \sa eventFilter(), widgetKeyReleaseEvent() 481 */ 482 void QwtPanner::widgetKeyPressEvent( QKeyEvent* keyEvent ) 483 { 484 if ( ( keyEvent->key() == m_data->abortKey ) 485 && ( keyEvent->modifiers() == m_data->abortKeyModifiers ) ) 488 486 { 489 487 hide(); … … 492 490 showCursor( false ); 493 491 #endif 494 d_data->pixmap = QPixmap();495 } 496 } 497 498 /*! 499 Handle a key release event for the observed widget. 500 501 \param keyEvent Key event 502 \sa eventFilter(), widgetKeyReleaseEvent() 503 */ 504 void QwtPanner::widgetKeyReleaseEvent( QKeyEvent *keyEvent )492 m_data->pixmap = QPixmap(); 493 } 494 } 495 496 /*! 497 Handle a key release event for the observed widget. 498 499 \param keyEvent Key event 500 \sa eventFilter(), widgetKeyReleaseEvent() 501 */ 502 void QwtPanner::widgetKeyReleaseEvent( QKeyEvent* keyEvent ) 505 503 { 506 504 Q_UNUSED( keyEvent ); … … 510 508 void QwtPanner::showCursor( bool on ) 511 509 { 512 if ( on == d_data->hasCursor )510 if ( on == m_data->hasCursor ) 513 511 return; 514 512 515 QWidget *w = parentWidget();516 if ( w == NULL || d_data->cursor == NULL )513 QWidget* w = parentWidget(); 514 if ( w == NULL || m_data->cursor == NULL ) 517 515 return; 518 516 519 d_data->hasCursor = on;517 m_data->hasCursor = on; 520 518 521 519 if ( on ) … … 523 521 if ( w->testAttribute( Qt::WA_SetCursor ) ) 524 522 { 525 delete d_data->restoreCursor;526 d_data->restoreCursor = new QCursor( w->cursor() );527 } 528 w->setCursor( * d_data->cursor );523 delete m_data->restoreCursor; 524 m_data->restoreCursor = new QCursor( w->cursor() ); 525 } 526 w->setCursor( *m_data->cursor ); 529 527 } 530 528 else 531 529 { 532 if ( d_data->restoreCursor )533 { 534 w->setCursor( * d_data->restoreCursor );535 delete d_data->restoreCursor;536 d_data->restoreCursor = NULL;530 if ( m_data->restoreCursor ) 531 { 532 w->setCursor( *m_data->restoreCursor ); 533 delete m_data->restoreCursor; 534 m_data->restoreCursor = NULL; 537 535 } 538 536 else … … 541 539 } 542 540 #endif 541 542 #include "moc_qwt_panner.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
