10 #include "qwt_panner.h" 
   11 #include "qwt_picker.h" 
   12 #include "qwt_painter.h" 
   24     QObjectList children = w->children();
 
   25     for ( 
int i = 0; i < children.size(); i++ )
 
   27         QwtPicker* picker = qobject_cast< QwtPicker* >( children[i] );
 
   35 class QwtPanner::PrivateData
 
   39         : button( Qt::LeftButton )
 
   40         , buttonModifiers( Qt::NoModifier )
 
   41         , abortKey( Qt::Key_Escape )
 
   42         , abortKeyModifiers( Qt::NoModifier )
 
   45         , restoreCursor( NULL )
 
   61     Qt::MouseButton button;
 
   62     Qt::KeyboardModifiers buttonModifiers;
 
   65     Qt::KeyboardModifiers abortKeyModifiers;
 
   75     QCursor* restoreCursor;
 
   90     m_data = 
new PrivateData();
 
   92     setAttribute( Qt::WA_TransparentForMouseEvents );
 
   93     setAttribute( Qt::WA_NoSystemBackground );
 
   94     setFocusPolicy( Qt::NoFocus );
 
  111     Qt::KeyboardModifiers modifiers )
 
  113     m_data->button = button;
 
  114     m_data->buttonModifiers = modifiers;
 
  119     Qt::KeyboardModifiers& modifiers )
 const 
  121     button = m_data->button;
 
  122     modifiers = m_data->buttonModifiers;
 
  133     Qt::KeyboardModifiers modifiers )
 
  135     m_data->abortKey = key;
 
  136     m_data->abortKeyModifiers = modifiers;
 
  141     Qt::KeyboardModifiers& modifiers )
 const 
  143     key = m_data->abortKey;
 
  144     modifiers = m_data->abortKeyModifiers;
 
  158     m_data->cursor = 
new QCursor( 
cursor );
 
  169     if ( m_data->cursor )
 
  170         return *m_data->cursor;
 
  172     if ( parentWidget() )
 
  173         return parentWidget()->cursor();
 
  190     if ( m_data->isEnabled != on )
 
  192         m_data->isEnabled = on;
 
  194         QWidget* w = parentWidget();
 
  197             if ( m_data->isEnabled )
 
  199                 w->installEventFilter( 
this );
 
  203                 w->removeEventFilter( 
this );
 
  218     m_data->orientations = o;
 
  224     return m_data->orientations;
 
  233     return m_data->orientations & o;
 
  242     return m_data->isEnabled;
 
  255     int dx = m_data->pos.x() - m_data->initialPos.x();
 
  256     int dy = m_data->pos.y() - m_data->initialPos.y();
 
  260     r.moveCenter( QPointF( r.center().x() + dx, r.center().y() + dy ) );
 
  265     QPainter painter( &pm );
 
  267     if ( !m_data->contentsMask.isNull() )
 
  269         QPixmap masked = m_data->pixmap;
 
  270         masked.setMask( m_data->contentsMask );
 
  271         painter.drawPixmap( r.toRect(), masked );
 
  275         painter.drawPixmap( r.toRect(), m_data->pixmap );
 
  280     if ( !m_data->contentsMask.isNull() )
 
  281         pm.setMask( m_data->contentsMask );
 
  283     painter.begin( 
this );
 
  284     painter.setClipRegion( event->region() );
 
  285     painter.drawPixmap( 0, 0, pm );
 
  308 #if QT_VERSION >= 0x050000 
  309     return parentWidget()->grab( parentWidget()->rect() );
 
  311     return QPixmap::grabWidget( parentWidget() );
 
  332     if ( 
object == NULL || 
object != parentWidget() )
 
  335     switch ( event->type() )
 
  337         case QEvent::MouseButtonPress:
 
  342         case QEvent::MouseMove:
 
  347         case QEvent::MouseButtonRelease:
 
  352         case QEvent::KeyPress:
 
  357         case QEvent::KeyRelease:
 
  383     if ( ( mouseEvent->button() != m_data->button )
 
  384         || ( mouseEvent->modifiers() != m_data->buttonModifiers ) )
 
  389     QWidget* w = parentWidget();
 
  397     m_data->initialPos = m_data->pos = mouseEvent->pos();
 
  399     setGeometry( parentWidget()->rect() );
 
  403     for ( 
int i = 0; i < pickers.size(); i++ )
 
  406     m_data->pixmap = 
grab();
 
  409     for ( 
int i = 0; i < pickers.size(); i++ )
 
  426     QPoint pos = mouseEvent->pos();
 
  428         pos.setX( m_data->initialPos.x() );
 
  430         pos.setY( m_data->initialPos.y() );
 
  432     if ( pos != m_data->pos && rect().contains( pos ) )
 
  437         Q_EMIT 
moved( m_data->pos.x() - m_data->initialPos.x(),
 
  438             m_data->pos.y() - m_data->initialPos.y() );
 
  458         QPoint pos = mouseEvent->pos();
 
  460             pos.setX( m_data->initialPos.x() );
 
  462             pos.setY( m_data->initialPos.y() );
 
  464         m_data->pixmap = QPixmap();
 
  465         m_data->contentsMask = QBitmap();
 
  468         if ( m_data->pos != m_data->initialPos )
 
  470             Q_EMIT 
panned( m_data->pos.x() - m_data->initialPos.x(),
 
  471                 m_data->pos.y() - m_data->initialPos.y() );
 
  484     if ( ( keyEvent->key() == m_data->abortKey )
 
  485         && ( keyEvent->modifiers() == m_data->abortKeyModifiers ) )
 
  492         m_data->pixmap = QPixmap();
 
  504     Q_UNUSED( keyEvent );
 
  508 void QwtPanner::showCursor( 
bool on )
 
  510     if ( on == m_data->hasCursor )
 
  513     QWidget* w = parentWidget();
 
  514     if ( w == NULL || m_data->cursor == NULL )
 
  517     m_data->hasCursor = on;
 
  521         if ( w->testAttribute( Qt::WA_SetCursor ) )
 
  523             delete m_data->restoreCursor;
 
  524             m_data->restoreCursor = 
new QCursor( w->cursor() );
 
  526         w->setCursor( *m_data->cursor );
 
  530         if ( m_data->restoreCursor )
 
  532             w->setCursor( *m_data->restoreCursor );
 
  533             delete m_data->restoreCursor;
 
  534             m_data->restoreCursor = NULL;
 
  543 #include "moc_qwt_panner.cpp" 
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
static qreal devicePixelRatio(const QPaintDevice *)
static QPixmap backingStore(QWidget *, const QSize &)
Qt::Orientations orientations() const
Return the orientation, where panning is enabled.
virtual ~QwtPanner()
Destructor.
const QCursor cursor() const
virtual bool eventFilter(QObject *, QEvent *) override
Event filter.
void setEnabled(bool)
En/disable the panner.
virtual void widgetMouseMoveEvent(QMouseEvent *)
void setMouseButton(Qt::MouseButton, Qt::KeyboardModifiers=Qt::NoModifier)
virtual void widgetKeyPressEvent(QKeyEvent *)
void getMouseButton(Qt::MouseButton &button, Qt::KeyboardModifiers &) const
Get mouse button and modifiers used for panning.
virtual void widgetKeyReleaseEvent(QKeyEvent *)
void moved(int dx, int dy)
bool isOrientationEnabled(Qt::Orientation) const
virtual void paintEvent(QPaintEvent *) override
Paint event.
void setOrientations(Qt::Orientations)
virtual QBitmap contentsMask() const
Calculate a mask for the contents of the panned widget.
virtual void widgetMouseReleaseEvent(QMouseEvent *)
void getAbortKey(int &key, Qt::KeyboardModifiers &) const
Get the abort key and modifiers.
virtual QPixmap grab() const
void setCursor(const QCursor &)
void setAbortKey(int key, Qt::KeyboardModifiers=Qt::NoModifier)
virtual void widgetMousePressEvent(QMouseEvent *)
void panned(int dx, int dy)
QwtPanner(QWidget *parent)
QwtPicker provides selections on a widget.