diff --git a/src/libtomahawk/utils/WidgetDragFilter.cpp b/src/libtomahawk/utils/WidgetDragFilter.cpp index 46797ca46..3d427d097 100644 --- a/src/libtomahawk/utils/WidgetDragFilter.cpp +++ b/src/libtomahawk/utils/WidgetDragFilter.cpp @@ -38,34 +38,42 @@ WidgetDragFilter::WidgetDragFilter( QObject* parent ) bool WidgetDragFilter::eventFilter( QObject* obj, QEvent* event ) { - if( m_target.isNull() || m_target.data() != obj ) + if ( m_target.isNull() || m_target.data() != obj ) return false; - if( event->type() == QEvent::MouseButtonPress ) { + if ( event->type() == QEvent::MouseButtonPress ) + { QMouseEvent *mouseEvent = static_cast( event ); - if( !canDrag( obj, mouseEvent ) ) + if ( !canDrag( obj, mouseEvent ) ) return false; - if( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) ) + if ( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) ) return false; + m_dragPoint = mouseEvent->pos(); m_dragStarted = true; return false; - } else if( event->type() == QEvent::MouseMove ) { - if( !m_dragStarted ) + } + else if ( event->type() == QEvent::MouseMove ) + { + if ( !m_dragStarted ) return false; - QMouseEvent* e = static_cast(event); - if( !canDrag( obj, e ) ) { - m_dragStarted = false; + QMouseEvent* e = static_cast(event); + if ( !canDrag( obj, e ) ) + { + m_dragStarted = false; return false; } - if( e->buttons().testFlag( Qt::LeftButton ) ) { + + if ( e->buttons().testFlag( Qt::LeftButton ) ) + { m_target.data()->window()->move( m_target.data()->window()->pos() + ( e->pos() - m_dragPoint ) ); return true; } - } else if( event->type() == QEvent::MouseButtonRelease ) { - m_dragStarted = false; } + else if ( event->type() == QEvent::MouseButtonRelease ) + m_dragStarted = false; + return false; } @@ -76,38 +84,39 @@ WidgetDragFilter::eventFilter( QObject* obj, QEvent* event ) bool WidgetDragFilter::canDrag( QObject* obj, QMouseEvent* ev ) const { - if( !obj->isWidgetType() ) + if ( !obj->isWidgetType() ) return false; QWidget* w = static_cast< QWidget* >( obj ); - if( QWidget::mouseGrabber() ) + if ( QWidget::mouseGrabber() ) return false; - if( w->cursor().shape() != Qt::ArrowCursor ) + if ( w->cursor().shape() != Qt::ArrowCursor ) return false; // Now we check various things about the child position and mouse QPoint position( ev->pos() ); QWidget* child = w->childAt( position ); - if( child && child->cursor().shape() != Qt::ArrowCursor ) return false; + if ( child && child->cursor().shape() != Qt::ArrowCursor ) + return false; // Don't want to drag menubars when selecting an action - if( QMenuBar* menuBar = qobject_cast( w ) ) + if ( QMenuBar* menuBar = qobject_cast( w ) ) { // check if there is an active action - if( menuBar->activeAction() && menuBar->activeAction()->isEnabled() ) return false; + if ( menuBar->activeAction() && menuBar->activeAction()->isEnabled() ) + return false; // check if action at position exists and is enabled - if( QAction* action = menuBar->actionAt( position ) ) + if ( QAction* action = menuBar->actionAt( position ) ) { - if( action->isSeparator() ) return true; - if( action->isEnabled() ) return false; + if ( action->isSeparator() ) + return true; + if ( action->isEnabled() ) + return false; } - // return true in all other cases - return true; - } return true;