1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-24 09:49:42 +01:00

* Style fixes for WidgetDragFilter.

This commit is contained in:
Christian Muehlhaeuser 2012-05-28 17:45:00 +02:00
parent 3b04498661
commit ab86a48ef7

View File

@ -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<QMouseEvent*>( 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<QMouseEvent* >(event);
if( !canDrag( obj, e ) ) {
m_dragStarted = false;
QMouseEvent* e = static_cast<QMouseEvent* >(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<QMenuBar*>( w ) )
if ( QMenuBar* menuBar = qobject_cast<QMenuBar*>( 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;