瀏覽代碼

Reflect current displayed image preview on thumbnail list selection

nherlambang 14 年之前
父節點
當前提交
ca1ebf5995

+ 10 - 4
Libs/DICOM/Widgets/ctkDICOMAppWidget.cpp

@@ -307,6 +307,7 @@ void ctkDICOMAppWidget::onNextImage(){
             QModelIndex nextIndex = currentIndex.sibling(imageID, 0);
 
             d->imagePreview->onModelSelected(nextIndex);
+            d->thumbnailsWidget->selectThumbnail(nextIndex);
         }
     }
 }
@@ -332,6 +333,7 @@ void ctkDICOMAppWidget::onPreviousImage(){
             QModelIndex prevIndex = currentIndex.sibling(imageID, 0);
 
             d->imagePreview->onModelSelected(prevIndex);
+            d->thumbnailsWidget->selectThumbnail(prevIndex);
         }
     }
 }
@@ -357,6 +359,7 @@ void ctkDICOMAppWidget::onNextSeries(){
             QModelIndex nextIndex = seriesIndex.sibling(seriesID, 0);
 
             d->imagePreview->onModelSelected(nextIndex);
+            d->thumbnailsWidget->selectThumbnail(nextIndex);
         }
     }
 }
@@ -380,9 +383,10 @@ void ctkDICOMAppWidget::onPreviousSeries(){
             seriesID--;
             if(seriesID < 0) seriesID += seriesCount;
 
-            QModelIndex nextIndex = seriesIndex.sibling(seriesID, 0);
+            QModelIndex prevIndex = seriesIndex.sibling(seriesID, 0);
 
-            d->imagePreview->onModelSelected(nextIndex);
+            d->imagePreview->onModelSelected(prevIndex);
+            d->thumbnailsWidget->selectThumbnail(prevIndex);
         }
     }
 }
@@ -409,6 +413,7 @@ void ctkDICOMAppWidget::onNextStudy(){
             QModelIndex nextIndex = studyIndex.sibling(studyID, 0);
 
             d->imagePreview->onModelSelected(nextIndex);
+            d->thumbnailsWidget->selectThumbnail(nextIndex);
         }
     }
 }
@@ -433,9 +438,10 @@ void ctkDICOMAppWidget::onPreviousStudy(){
             studyID--;
             if(studyID < 0) studyID += studyCount;
 
-            QModelIndex nextIndex = studyIndex.sibling(studyID, 0);
+            QModelIndex prevIndex = studyIndex.sibling(studyID, 0);
 
-            d->imagePreview->onModelSelected(nextIndex);
+            d->imagePreview->onModelSelected(prevIndex);
+            d->thumbnailsWidget->selectThumbnail(prevIndex);
         }
     }
 }

+ 33 - 0
Libs/DICOM/Widgets/ctkDICOMThumbnailListWidget.cpp

@@ -36,6 +36,8 @@ public:
 
   QString databaseDirectory;
 
+  QModelIndex currentSelectedModel;
+
   void clearAllThumbnails();
 
   void onPatientModelSelected(const QModelIndex &index);
@@ -231,6 +233,35 @@ void ctkDICOMThumbnailListWidget::selectThumbnail(int index){
 }
 
 //----------------------------------------------------------------------------
+void ctkDICOMThumbnailListWidget::selectThumbnail(const QModelIndex &index){
+    Q_D(ctkDICOMThumbnailListWidget);
+
+    logger.debug("select thumbnail from model index");
+
+    if(!d->currentSelectedModel.isValid())return;
+    if(index.parent() != d->currentSelectedModel)return;
+
+    logger.debug("select thumbnail from model index");
+
+    ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(index.model()));
+
+    if(model){
+        int count = d->scrollAreaContentWidget->layout()->count();
+
+        for(int i=0; i<count; i++){
+            ctkDICOMThumbnailWidget* thumbnailWidget = qobject_cast<ctkDICOMThumbnailWidget*>(d->scrollAreaContentWidget->layout()->itemAt(i)->widget());
+            if(thumbnailWidget->sourceIndex() == index){
+                thumbnailWidget->setSelected(true);
+                logger.debug("set selected true");
+            }else{
+                thumbnailWidget->setSelected(false);
+                logger.debug("set selected false");
+            }
+        }
+    }
+}
+
+//----------------------------------------------------------------------------
 void ctkDICOMThumbnailListWidget::onModelSelected(const QModelIndex &index){
     Q_D(ctkDICOMThumbnailListWidget);
 
@@ -241,6 +272,8 @@ void ctkDICOMThumbnailListWidget::onModelSelected(const QModelIndex &index){
     if(model){
         QModelIndex index0 = index.sibling(index.row(), 0);
 
+        d->currentSelectedModel = index0;
+
         if ( model->data(index0,ctkDICOMModel::TypeRole) == ctkDICOMModel::PatientType ){
             d->onPatientModelSelected(index0);
         }else if ( model->data(index0,ctkDICOMModel::TypeRole) == ctkDICOMModel::StudyType ){

+ 1 - 0
Libs/DICOM/Widgets/ctkDICOMThumbnailListWidget.h

@@ -41,6 +41,7 @@ public:
   void setDatabaseDirectory(const QString& directory);
 
   void selectThumbnail(int index);
+  void selectThumbnail(const QModelIndex& index);
 
 protected:
   QScopedPointer<ctkDICOMThumbnailListWidgetPrivate> d_ptr;