From: <hug...@li...> - 2011-11-02 18:27:26
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/f363aa2e86f0 changeset: 5634:f363aa2e86f0 user: tmodes date: Wed Nov 02 18:29:14 2011 +0100 description: Allow moving multiple image in image tab Initial patch by Stephen Bennett diffstat: src/hugin1/hugin/ImagesList.cpp | 24 ++++++++++ src/hugin1/hugin/ImagesList.h | 8 +++- src/hugin1/hugin/ImagesPanel.cpp | 93 ++++++++++++++++++++++++--------------- 3 files changed, 88 insertions(+), 37 deletions(-) diffs (174 lines): diff -r 426bd4721b14 -r f363aa2e86f0 src/hugin1/hugin/ImagesList.cpp --- a/src/hugin1/hugin/ImagesList.cpp Mon Oct 31 18:47:12 2011 +0100 +++ b/src/hugin1/hugin/ImagesList.cpp Wed Nov 02 18:29:14 2011 +0100 @@ -274,6 +274,30 @@ SetItemState(imgNr, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } +void ImagesList::SelectImageRange(unsigned int imgStart,unsigned int imgEnd) +{ + size_t nrItems = GetItemCount(); + size_t _imgStart=imgStart; + size_t _imgEnd=imgEnd; + if(imgEnd<imgStart) + { + _imgStart=imgEnd; + _imgEnd=imgStart; + } + for (size_t i=0; i < nrItems ; i++) + { + int selected = GetItemState(i, wxLIST_STATE_SELECTED); + if ((i < _imgStart || i>_imgEnd ) && selected) + { + SetItemState(i, 0, wxLIST_STATE_SELECTED); + } + } + for(size_t i=_imgStart; i<=_imgEnd; i++) + { + SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + }; +}; + void ImagesList::SelectAll() { unsigned int nrItems = GetItemCount(); diff -r 426bd4721b14 -r f363aa2e86f0 src/hugin1/hugin/ImagesList.h --- a/src/hugin1/hugin/ImagesList.h Mon Oct 31 18:47:12 2011 +0100 +++ b/src/hugin1/hugin/ImagesList.h Wed Nov 02 18:29:14 2011 +0100 @@ -116,7 +116,13 @@ * selects image @p imgNr, and deselects all other images */ void SelectSingleImage(unsigned int imgNr); - + /** Select an image range + * + * selects images between @p imgNs and @p imgNe, + * and deselects all other images + */ + void SelectImageRange(unsigned int imgStart,unsigned int imgEnd); + /** Select all images */ void SelectAll(); diff -r 426bd4721b14 -r f363aa2e86f0 src/hugin1/hugin/ImagesPanel.cpp --- a/src/hugin1/hugin/ImagesPanel.cpp Mon Oct 31 18:47:12 2011 +0100 +++ b/src/hugin1/hugin/ImagesPanel.cpp Wed Nov 02 18:29:14 2011 +0100 @@ -498,8 +498,6 @@ ShowImgParameters(imgNr); m_optAnchorButton->Enable(); m_colorAnchorButton->Enable(); - m_moveDownButton->Enable(); - m_moveUpButton->Enable(); } else { DEBUG_DEBUG("Multiselection, or no image selected"); // multiselection, clear all values @@ -507,9 +505,10 @@ ClearImgParameters(); m_optAnchorButton->Disable(); m_colorAnchorButton->Disable(); - m_moveDownButton->Disable(); - m_moveUpButton->Disable(); } + bool movePossible=*(sel.begin())+sel.size()-1 == *(sel.rbegin()); + m_moveDownButton->Enable(movePossible); + m_moveUpButton->Enable(movePossible); } } @@ -924,42 +923,64 @@ void ImagesPanel::OnMoveImageDown(wxCommandEvent & e) { UIntSet selImg = images_list->GetSelected(); - if ( selImg.size() == 1) { - unsigned int i1 = *selImg.begin(); - unsigned int i2 = i1+1; - if (i2 < pano->getNrOfImages() ) { - images_list->SetItemState(i1,0,wxLIST_STATE_SELECTED); - GlobalCmdHist::getInstance().addCommand( - new SwapImagesCmd(*pano,i1, i2) - ); - // set new selection - images_list->SelectSingleImage(i2); - // Bring the focus back to the button. - m_moveDownButton->CaptureMouse(); - m_moveDownButton->ReleaseMouse(); - } - } -} + size_t num = selImg.size(); + if(num>0) + { + //last selected image + unsigned int i1 = *selImg.rbegin(); + //image to move into + unsigned int i2 = i1+1; + //Test if there is room to move images down + if (i2 < pano->getNrOfImages() ) + { + //Group repeated move commands within undo history + std::vector<PanoCommand*> cmds; + for (size_t i=0; i<num; i++) + { + cmds.push_back(new SwapImagesCmd(*pano,i2, i1)); + i1--; + i2--; + } + GlobalCmdHist::getInstance().addCommand( + new PT::CombinedPanoCommand(*pano, cmds)); + // set new selection + images_list->SelectImageRange(*selImg.begin()+1,*selImg.begin()+num); + // Bring the focus back to the button. + m_moveDownButton->SetFocus(); + }; + }; +}; void ImagesPanel::OnMoveImageUp(wxCommandEvent & e) { UIntSet selImg = images_list->GetSelected(); - if ( selImg.size() == 1) { - unsigned int i1 = *selImg.begin(); - unsigned int i2 = i1 -1; - if (i1 > 0) { - images_list->SetItemState(i1,0,wxLIST_STATE_SELECTED); - GlobalCmdHist::getInstance().addCommand( - new SwapImagesCmd(*pano,i1, i2) - ); - // set new selection - images_list->SelectSingleImage(i2); - // Bring the focus back to the button. - m_moveUpButton->CaptureMouse(); - m_moveUpButton->ReleaseMouse(); - } - } -} + size_t num = selImg.size(); + if(num>0) + { + //first selected image + size_t i1 = *selImg.begin(); + //image to move into. + size_t i2 = i1-1; + //Test if there is room to move images up + if (i1 > 0 ) + { + //Group repeated move commands within undo history + std::vector<PanoCommand*> cmds; + for (size_t i=0; i<num; i++) + { + cmds.push_back(new SwapImagesCmd(*pano,i2, i1)); + i1++; + i2++; + } + GlobalCmdHist::getInstance().addCommand( + new PT::CombinedPanoCommand(*pano, cmds)); + // set new selection + images_list->SelectImageRange(*selImg.begin()-1,*selImg.begin()+num-2); + // Bring the focus back to the button. + m_moveUpButton->SetFocus(); + }; + }; +}; void ImagesPanel::ReloadCPDetectorSettings() { |