From: mzn Date: Fri, 21 Mar 2014 14:17:39 +0000 (+0000) Subject: The first implementation of drag and drop + dialog buttons icons and translations. X-Git-Tag: BR_hydro_v1_0_1~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d31e2e7449fe14654198b48e2fe2c1e24f973009;p=modules%2Fhydro.git The first implementation of drag and drop + dialog buttons icons and translations. --- diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx index 7055cd08..9e85de97 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx @@ -23,10 +23,14 @@ #include "HYDROGUI_ZLevelsDlg.h" #include "HYDROGUI_ZLevelsModel.h" +#include +#include + #include #include #include #include +#include #include #include @@ -34,6 +38,8 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) : QDialog( theParent ) { + setWindowTitle( tr( "CHANGE_LAYER_ORDER" ) ); + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); aMainLayout->setMargin( 5 ); @@ -55,10 +61,19 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) myList->setModel( aFilteredModel ); - myTop = new QPushButton( tr("TOP") ); - myUp = new QPushButton( tr("UP") ); - myDown = new QPushButton( tr("DOWN") ); - myBottom = new QPushButton( tr("BOTTOM") ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + myTop = new QToolButton; + myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) ); + myTop->setIconSize( QSize( 32, 32 ) ); + myUp = new QToolButton; + myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) ); + myUp->setIconSize( myTop->iconSize() ); + myDown = new QToolButton; + myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) ); + myDown->setIconSize( myTop->iconSize() ); + myBottom = new QToolButton; + myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) ); + myBottom->setIconSize( myTop->iconSize() ); QVBoxLayout* aListButtonsLayout = new QVBoxLayout(); aListButtonsLayout->addWidget( myTop ); aListButtonsLayout->addWidget( myUp ); diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h index 6d249784..e67dcc38 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h @@ -30,12 +30,13 @@ class QCheckBox; class QListView; class QPushButton; +class QToolButton; /** * \class HYDROGUI_ZLevelsDlg * \brief The class representing widget for managing Z levels */ -class HYDROGUI_ZLevelsDlg : public QDialog +class HYDRO_EXPORT HYDROGUI_ZLevelsDlg : public QDialog { Q_OBJECT @@ -55,10 +56,10 @@ private: private: QListView* myList; - QPushButton* myTop; - QPushButton* myUp; - QPushButton* myDown; - QPushButton* myBottom; + QToolButton* myTop; + QToolButton* myUp; + QToolButton* myDown; + QToolButton* myBottom; QCheckBox* myAllObjects; QPushButton* myApply; QPushButton* myClose; diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx index 320ea963..20fb48f5 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx @@ -21,6 +21,10 @@ // #include "HYDROGUI_ZLevelsModel.h" + +#include +#include + #include const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list"; @@ -28,9 +32,11 @@ const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list"; HYDROGUI_ZLevelsModel::HYDROGUI_ZLevelsModel( QObject* theParent ) : QAbstractListModel( theParent ) { + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + myEmpty = QPixmap( 16, 16 ); myEmpty.fill( Qt::white ); - myEye = QPixmap( "eye.png" );//TODO: loading from resources + myEye = aResMgr->loadPixmap( "HYDRO", tr( "EYE_ICO" ) ); setSupportedDragActions( Qt::MoveAction | Qt::CopyAction ); } @@ -185,7 +191,8 @@ bool HYDROGUI_ZLevelsModel::dropMimeData( const QMimeData* theData, Qt::DropActi aStream >> anId; anIdsList << anId; } - move( anIdsList, DragAndDrop, aDropItemId ); + qSort( anIdsList ); // TODO should be moved? + move( anIdsList, DragAndDrop, false, aDropItemId ); //TODO set visibility? return true; } @@ -217,9 +224,11 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, } int aDestinationIndex = -1; + bool isInsertBefore = false; switch ( theType ) { case Up: + isInsertBefore = true; if ( theItem > 0 ) { aDestinationIndex = theItem - 1; if ( theIsVisibleOnly ) { @@ -240,6 +249,7 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, } break; case Top: + isInsertBefore = true; if ( theItem > 0 ) { aDestinationIndex = 0; } @@ -249,10 +259,18 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, aDestinationIndex = myObjects.count() - 1; } break; + case DragAndDrop: + if ( theItem > theDropItem ) { + isInsertBefore = true; + aDestinationIndex = theDropItem; + } else { + aDestinationIndex = theDropItem - 1; + } + break; } if ( aDestinationIndex >= 0 && aDestinationIndex < myObjects.count() ) { - int aDestinationRow = (theType == Up || theType == Top) ? aDestinationIndex : aDestinationIndex + 1; + int aDestinationRow = isInsertBefore ? aDestinationIndex : aDestinationIndex + 1; if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestinationRow ) ) { myObjects.move( theItem, aDestinationIndex ); endMoveRows(); @@ -268,38 +286,80 @@ bool HYDROGUI_ZLevelsModel::move( const QList& theItems, const OpType theTy { bool aRes = true; - bool isReverse = theType == Top || theType == Down; QListIterator anIt( theItems ); - int aShift = 0; - if ( isReverse ) { - anIt.toBack(); - while ( anIt.hasPrevious() ) { - int anId = anIt.previous(); - if ( theType == Top ) { - anId += aShift; - aShift++; - } - if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { - aRes = false; - break; + int aDragShift = 0; + + switch ( theType ) { + case Top: + case Down: + // reverse order + anIt.toBack(); + while ( anIt.hasPrevious() ) { + int anId = anIt.previous(); + if ( theType == Top ) { + anId += aDragShift; + aDragShift++; + } + if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { + aRes = false; + break; + } } - } - } else { - while ( anIt.hasNext() ) { - int anId = anIt.next(); - if ( theType == Bottom ) { - anId -= aShift; - aShift++; + break; + case Bottom: + case Up: + // direct order + while ( anIt.hasNext() ) { + int anId = anIt.next(); + if ( theType == Bottom ) { + anId -= aDragShift; + aDragShift++; + } + if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { + aRes = false; + break; + } } - if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { - aRes = false; - break; + break; + case DragAndDrop: + // direct order + aRes = isDragAndDropAllowed( theItems, theDropItem ); + if ( aRes ) { + int aDropShift = 0; + int aDropItem = theDropItem; + while ( anIt.hasNext() ) { + int anId = anIt.next(); + aDropItem = theDropItem + aDropShift; + if ( anId > aDropItem ) { + aDragShift = 0; + aDropShift++; + } else { + anId -= aDragShift; + if ( ( aDropItem - anId ) != 1 ) { + aDragShift++; + } + } + move( anId, theType, theIsVisibleOnly, aDropItem ); + } } - } + break; + default: + aRes = false; } - - // reset(); //TODO dataChanged? - + return aRes; } +bool HYDROGUI_ZLevelsModel::isDragAndDropAllowed( const QList& theItems, + const int theDropItem ) const +{ + bool isAllowed = false; + + if ( theDropItem >= 0 && theDropItem < myObjects.count() && + !theItems.empty() && theItems.count() < myObjects.count() && + !theItems.contains( theDropItem )) { + isAllowed = true; + } + + return isAllowed; +} diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h index fd2fb374..e1585abd 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h @@ -75,6 +75,7 @@ public: protected: bool isObjectVisible( int theIndex ) const; + bool isDragAndDropAllowed( const QList& theItems, const int theDropItem ) const; private: friend class test_HYDROGUI_ZLevelsModel; diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx index 7d12d15a..61f318b9 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx @@ -50,8 +50,36 @@ void HYDROGUI_ZLevelsOp::startOperation() { HYDROGUI_Operation::startOperation(); - // TODO - abort(); + HYDROGUI_ZLevelsModel::Object2VisibleList anObject2VisibleList; + + // Get the document + Handle(HYDROData_Document) aDoc = doc(); + if( !aDoc.IsNull() ) { + // Get active OCC view id + size_t anActiveOCCViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); + + // Get objects list + HYDROData_SequenceOfObjects aSeqOfObjects = aDoc->GetObjectsLayerOrder( Standard_True ); + HYDROData_SequenceOfObjects::Iterator anIter( aSeqOfObjects ); + for ( ; anIter.More(); anIter.Next() ) { + Handle(HYDROData_Entity) anObject = anIter.Value(); + if ( !anObject.IsNull() ) { + bool isVisible = module()->isObjectVisible( anActiveOCCViewId, anObject ); + anObject2VisibleList << HYDROGUI_ZLevelsModel::Object2Visible( anObject, isVisible ); + } + } + } + + // Show the dialog + myZLevelsDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop() ); + myZLevelsDlg->setModal( true ); + myZLevelsDlg->setObjects( anObject2VisibleList ); + + //TODO: reimplement + connect( myZLevelsDlg, SIGNAL( accepted() ), this, SLOT( commit() ) ); + connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( abort() ) ); + + myZLevelsDlg->exec(); } bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,