From: vsr Date: Thu, 3 Mar 2005 13:19:32 +0000 (+0000) Subject: PAL8232: improve drag-n-drop mechanizm for UseCase browser - dragging operation start... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8a95f629099052d23572deff7aecc3cbd608a67f;p=modules%2Fkernel.git PAL8232: improve drag-n-drop mechanizm for UseCase browser - dragging operation starts only if neither Ctrl no Shift key is pressed and only when mouse starts moving). This allows to process correctly standard item selection behavior (including when Ctrl, Shift key is pressed). --- diff --git a/src/SALOMEGUI/QAD_ObjectBrowser.cxx b/src/SALOMEGUI/QAD_ObjectBrowser.cxx index 91b58cba0..958cd0b28 100644 --- a/src/SALOMEGUI/QAD_ObjectBrowser.cxx +++ b/src/SALOMEGUI/QAD_ObjectBrowser.cxx @@ -340,8 +340,11 @@ void QAD_ObjectBrowser::setupListView() /*! Event filter + We can use the following static variables for drag-n-drop operations because it is impossible + to perform several dragging operation at one time. */ - +static bool dragged = false; +static QStringList draggedlist; bool QAD_ObjectBrowser::eventFilter( QObject* o, QEvent* e ) { QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop(); @@ -357,7 +360,7 @@ bool QAD_ObjectBrowser::eventFilter( QObject* o, QEvent* e ) // Test if clicked on selection and start drag if necessary QMouseEvent* me = ( QMouseEvent* )e; QAD_ObjectBrowserItem* item = ( QAD_ObjectBrowserItem* )( myUseCaseView->itemAt( me->pos() ) ); - if ( item && item->isSelected() && me->button() == LeftButton) { + if ( item && item->isSelected() && me->button() == LeftButton && !(me->state() & (ControlButton | ShiftButton)) ) { if ( me->pos().x() > myUseCaseView->header()->sectionPos( myUseCaseView->header()->mapToIndex( 0 ) ) + myUseCaseView->treeStepSize() * ( item->depth() + ( myUseCaseView->rootIsDecorated() ? 1 : 0 ) ) + myUseCaseView->itemMargin() || @@ -378,13 +381,40 @@ bool QAD_ObjectBrowser::eventFilter( QObject* o, QEvent* e ) } } if ( done && !entryList.isEmpty() ) { - QTextDrag *d = new QTextDrag( entryList.join("*"), myUseCaseView->viewport() ); - d->dragMove(); + draggedlist = entryList; + // vsr 03/03/05 - start dragging only if mouse starts moving after pressing left button (see below) + //QTextDrag *d = new QTextDrag( entryList.join("*"), myUseCaseView->viewport() ); + //d->dragMove(); + dragged = true; return true; } } } } + else if ( e->type() == QEvent::MouseMove ) { + // vsr 03/03/05 - start dragging only if mouse starts moving + if ( dragged ) { + if ( !draggedlist.isEmpty() ) { + QTextDrag *d = new QTextDrag( draggedlist.join("*"), myUseCaseView->viewport() ); + d->dragMove(); + } + dragged = false; + draggedlist.clear(); + } + } + else if ( e->type() == QEvent::MouseButtonRelease ) { + // vsr 03/03/05 - if dragging was not performed (mouse was not moved after mouse press) + // simulate the ordinary mouse click that means just selection of the one item + QMouseEvent* me = ( QMouseEvent* )e; + if ( dragged ) { + draggedlist.clear(); + dragged = false; + QAD_ObjectBrowserItem* item = ( QAD_ObjectBrowserItem* )( myUseCaseView->itemAt( me->pos() ) ); + myUseCaseView->clearSelection(); + myUseCaseView->setSelected( item, true ); + myUseCaseView->setCurrentItem( item ); + } + } else if ( e->type() == QEvent::DragMove ) { QDragMoveEvent* dme = ( QDragMoveEvent* )e; if ( dme->source() == myUseCaseView->viewport() ) {