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:
@@ -38,34 +38,42 @@ WidgetDragFilter::WidgetDragFilter( QObject* parent )
|
|||||||
bool
|
bool
|
||||||
WidgetDragFilter::eventFilter( QObject* obj, QEvent* event )
|
WidgetDragFilter::eventFilter( QObject* obj, QEvent* event )
|
||||||
{
|
{
|
||||||
if( m_target.isNull() || m_target.data() != obj )
|
if ( m_target.isNull() || m_target.data() != obj )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( event->type() == QEvent::MouseButtonPress ) {
|
if ( event->type() == QEvent::MouseButtonPress )
|
||||||
|
{
|
||||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event );
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event );
|
||||||
if( !canDrag( obj, mouseEvent ) )
|
if ( !canDrag( obj, mouseEvent ) )
|
||||||
return false;
|
return false;
|
||||||
if( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) )
|
if ( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_dragPoint = mouseEvent->pos();
|
m_dragPoint = mouseEvent->pos();
|
||||||
m_dragStarted = true;
|
m_dragStarted = true;
|
||||||
return false;
|
return false;
|
||||||
} else if( event->type() == QEvent::MouseMove ) {
|
}
|
||||||
if( !m_dragStarted )
|
else if ( event->type() == QEvent::MouseMove )
|
||||||
|
{
|
||||||
|
if ( !m_dragStarted )
|
||||||
return false;
|
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;
|
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 ) );
|
m_target.data()->window()->move( m_target.data()->window()->pos() + ( e->pos() - m_dragPoint ) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if( event->type() == QEvent::MouseButtonRelease ) {
|
|
||||||
m_dragStarted = false;
|
|
||||||
}
|
}
|
||||||
|
else if ( event->type() == QEvent::MouseButtonRelease )
|
||||||
|
m_dragStarted = false;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,38 +84,39 @@ WidgetDragFilter::eventFilter( QObject* obj, QEvent* event )
|
|||||||
bool
|
bool
|
||||||
WidgetDragFilter::canDrag( QObject* obj, QMouseEvent* ev ) const
|
WidgetDragFilter::canDrag( QObject* obj, QMouseEvent* ev ) const
|
||||||
{
|
{
|
||||||
if( !obj->isWidgetType() )
|
if ( !obj->isWidgetType() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QWidget* w = static_cast< QWidget* >( obj );
|
QWidget* w = static_cast< QWidget* >( obj );
|
||||||
|
|
||||||
if( QWidget::mouseGrabber() )
|
if ( QWidget::mouseGrabber() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( w->cursor().shape() != Qt::ArrowCursor )
|
if ( w->cursor().shape() != Qt::ArrowCursor )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Now we check various things about the child position and mouse
|
// Now we check various things about the child position and mouse
|
||||||
QPoint position( ev->pos() );
|
QPoint position( ev->pos() );
|
||||||
QWidget* child = w->childAt( position );
|
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
|
// 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
|
// 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
|
// 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->isSeparator() )
|
||||||
if( action->isEnabled() ) return false;
|
return true;
|
||||||
|
if ( action->isEnabled() )
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// return true in all other cases
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user