mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Style fixes for WidgetDragFilter.
This commit is contained in:
@@ -41,31 +41,39 @@ WidgetDragFilter::eventFilter( QObject* obj, QEvent* event )
|
||||
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 ) )
|
||||
return false;
|
||||
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 ) {
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -91,23 +99,24 @@ WidgetDragFilter::canDrag( QObject* obj, QMouseEvent* ev ) const
|
||||
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 ) )
|
||||
{
|
||||
// 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( action->isSeparator() ) return true;
|
||||
if( action->isEnabled() ) return false;
|
||||
}
|
||||
// return true in all other cases
|
||||
if ( action->isSeparator() )
|
||||
return true;
|
||||
|
||||
if ( action->isEnabled() )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user