Browse Source

Improved progress widget handling.

Sascha Zelzer 12 years ago
parent
commit
87d51bd9f7

+ 2 - 0
Applications/ctkCommandLineModuleExplorer/CMakeLists.txt

@@ -12,6 +12,7 @@ set(KIT_SRCS
   ctkCmdLineModuleExplorerMainWindow.cpp
   ctkCmdLineModuleExplorerModulesSettings.cpp
   ctkCmdLineModuleExplorerOutputText.cpp
+  ctkCmdLineModuleExplorerProgressListWidget.cpp
   ctkCmdLineModuleExplorerProgressWidget.cpp
   ctkCmdLineModuleExplorerTabList.cpp
   ctkCmdLineModuleExplorerTreeWidget.cpp
@@ -22,6 +23,7 @@ set(KIT_MOC_SRCS
   ctkCmdLineModuleExplorerMainWindow.h
   ctkCmdLineModuleExplorerModulesSettings.h
   ctkCmdLineModuleExplorerOutputText.h
+  ctkCmdLineModuleExplorerProgressListWidget.h
   ctkCmdLineModuleExplorerProgressWidget.h
   ctkCmdLineModuleExplorerTabList.h
   ctkCmdLineModuleExplorerTreeWidget.h

+ 8 - 5
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.cpp

@@ -83,7 +83,7 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
 
   tabList.reset(new ctkCmdLineModuleExplorerTabList(ui->mainTabWidget));
 
-  // If a module is registered via the ModuleManager, add it the tree
+  // If a module is registered via the ModuleManager, add it to the tree
   connect(&moduleManager, SIGNAL(moduleRegistered(ctkCmdLineModuleReference)), ui->modulesTreeWidget, SLOT(addModuleItem(ctkCmdLineModuleReference)));
   connect(&moduleManager, SIGNAL(moduleUnregistered(ctkCmdLineModuleReference)), ui->modulesTreeWidget, SLOT(removeModuleItem(ctkCmdLineModuleReference)));
   // Double-clicking on an item in the tree creates a new tab with the default frontend
@@ -92,7 +92,11 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
   connect(ui->modulesTreeWidget, SIGNAL(moduleFrontendCreated(ctkCmdLineModuleFrontend*)), tabList.data(), SLOT(addTab(ctkCmdLineModuleFrontend*)));
   // React to tab-changes
   connect(tabList.data(), SIGNAL(tabActivated(ctkCmdLineModuleFrontend*)), SLOT(moduleTabActivated(ctkCmdLineModuleFrontend*)));
+  connect(tabList.data(), SIGNAL(tabActivated(ctkCmdLineModuleFrontend*)), ui->progressListWidget, SLOT(setCurrentProgressWidget(ctkCmdLineModuleFrontend*)));
   connect(tabList.data(), SIGNAL(tabClosed(ctkCmdLineModuleFrontend*)), ui->outputText, SLOT(frontendRemoved(ctkCmdLineModuleFrontend*)));
+  connect(tabList.data(), SIGNAL(tabClosed(ctkCmdLineModuleFrontend*)), ui->progressListWidget, SLOT(removeProgressWidget(ctkCmdLineModuleFrontend*)));
+
+  connect(ui->ClearButton, SIGNAL(clicked()), ui->progressListWidget, SLOT(clearList()));
 
   // Listen to future events for the currently active tab
 
@@ -187,19 +191,18 @@ void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
   ctkCmdLineModuleFrontend* moduleFrontend = this->tabList->activeTab();
   Q_ASSERT(moduleFrontend);
 
-  ctkCmdLineModuleExplorerProgressWidget* progressWidget = new ctkCmdLineModuleExplorerProgressWidget();
-  this->ui->progressInfoWidget->layout()->addWidget(progressWidget);
-
   ui->actionRun->setEnabled(false);
   qobject_cast<QWidget*>(moduleFrontend->guiHandle())->setEnabled(false);
 
   ctkCmdLineModuleFuture future = moduleManager.run(moduleFrontend);
 
+  ui->progressListWidget->addProgressWidget(moduleFrontend, future);
+  ui->progressListWidget->setCurrentProgressWidget(moduleFrontend);
+
   ui->actionPause->setEnabled(future.canPause() && future.isRunning());
   ui->actionPause->setChecked(future.isPaused());
   ui->actionCancel->setEnabled(future.canCancel() && future.isRunning());
 
-  progressWidget->setFuture(future);
   this->currentFutureWatcher.setFuture(future);
 }
 

+ 89 - 8
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>800</width>
-    <height>600</height>
+    <width>1126</width>
+    <height>933</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -44,7 +44,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>800</width>
+     <width>1126</width>
      <height>25</height>
     </rect>
    </property>
@@ -136,23 +136,98 @@
       <number>0</number>
      </property>
      <item>
-      <widget class="QWidget" name="progressInfoWidget" native="true">
+      <widget class="QWidget" name="progressContainer" native="true">
        <layout class="QVBoxLayout" name="verticalLayout_4">
         <property name="spacing">
-         <number>4</number>
+         <number>2</number>
         </property>
         <property name="leftMargin">
-         <number>0</number>
+         <number>6</number>
         </property>
         <property name="topMargin">
-         <number>4</number>
+         <number>0</number>
         </property>
         <property name="rightMargin">
          <number>0</number>
         </property>
         <property name="bottomMargin">
-         <number>4</number>
+         <number>0</number>
         </property>
+        <item>
+         <layout class="QHBoxLayout" name="horizontalLayout_2">
+          <item>
+           <spacer name="horizontalSpacer">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item>
+           <widget class="QPushButton" name="ClearButton">
+            <property name="text">
+             <string>Clear</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <widget class="QScrollArea" name="scrollArea">
+          <property name="frameShape">
+           <enum>QFrame::NoFrame</enum>
+          </property>
+          <property name="widgetResizable">
+           <bool>true</bool>
+          </property>
+          <widget class="QWidget" name="scrollAreaContent">
+           <property name="geometry">
+            <rect>
+             <x>0</x>
+             <y>0</y>
+             <width>250</width>
+             <height>110</height>
+            </rect>
+           </property>
+           <layout class="QVBoxLayout" name="verticalLayout_5">
+            <property name="leftMargin">
+             <number>0</number>
+            </property>
+            <property name="rightMargin">
+             <number>0</number>
+            </property>
+            <item>
+             <widget class="Line" name="line">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="ctkCmdLineModuleExplorerProgressListWidget" name="progressListWidget" native="true"/>
+            </item>
+            <item>
+             <spacer name="verticalSpacer">
+              <property name="orientation">
+               <enum>Qt::Vertical</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>20</width>
+                <height>64</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+           </layout>
+          </widget>
+         </widget>
+        </item>
        </layout>
       </widget>
      </item>
@@ -276,6 +351,12 @@
    <extends>QTextEdit</extends>
    <header>ctkCmdLineModuleExplorerOutputText.h</header>
   </customwidget>
+  <customwidget>
+   <class>ctkCmdLineModuleExplorerProgressListWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkCmdLineModuleExplorerProgressListWidget.h</header>
+   <container>1</container>
+  </customwidget>
  </customwidgets>
  <resources>
   <include location="resources/ctkCmdLineModuleExplorer.qrc"/>

+ 119 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerProgressListWidget.cpp

@@ -0,0 +1,119 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#include "ctkCmdLineModuleExplorerProgressListWidget.h"
+#include "ctkCmdLineModuleExplorerProgressWidget.h"
+
+#include "ctkCmdLineModuleFrontend.h"
+#include "ctkCmdLineModuleReference.h"
+#include "ctkCmdLineModuleDescription.h"
+
+#include <QVBoxLayout>
+
+ctkCmdLineModuleExplorerProgressListWidget::ctkCmdLineModuleExplorerProgressListWidget(QWidget *parent)
+  : QWidget(parent)
+  , CurrentWidget(NULL)
+{
+  QVBoxLayout* progressLayout = new QVBoxLayout();
+  progressLayout->setContentsMargins(0, 0, 0, 0);
+  this->setLayout(progressLayout);
+}
+
+void ctkCmdLineModuleExplorerProgressListWidget::addProgressWidget(ctkCmdLineModuleFrontend *frontend,
+                                                                   const ctkCmdLineModuleFuture &future)
+{
+  ctkCmdLineModuleExplorerProgressWidget* progressWidget = FrontendToProgressWidgetMap[frontend];
+  if (progressWidget == NULL)
+  {
+    progressWidget = new ctkCmdLineModuleExplorerProgressWidget();
+    FrontendToProgressWidgetMap[frontend] = progressWidget;
+    ProgressWidgetToFrontendMap[progressWidget] = frontend;
+
+    connect(progressWidget, SIGNAL(destroyed(QObject*)), SLOT(progressWidgetDestroyed(QObject*)));
+
+    this->layout()->addWidget(progressWidget);
+  }
+
+  progressWidget->setHighlightStyle(false);
+  progressWidget->setTitle(frontend->moduleReference().description().title());
+  progressWidget->setFuture(future);
+}
+
+
+void ctkCmdLineModuleExplorerProgressListWidget::progressWidgetDestroyed(QObject* widget)
+{
+  ctkCmdLineModuleExplorerProgressWidget* progressWidget = static_cast<ctkCmdLineModuleExplorerProgressWidget*>(widget);
+  if (CurrentWidget == progressWidget)
+  {
+    CurrentWidget = NULL;
+  }
+  ctkCmdLineModuleFrontend* frontend = ProgressWidgetToFrontendMap.take(progressWidget);
+  FrontendToProgressWidgetMap.remove(frontend);
+}
+
+
+void ctkCmdLineModuleExplorerProgressListWidget::removeProgressWidget(ctkCmdLineModuleFrontend *frontend)
+{
+  if (FrontendToProgressWidgetMap.contains(frontend))
+  {
+    FrontendToProgressWidgetMap[frontend]->deleteLater();
+  }
+}
+
+void ctkCmdLineModuleExplorerProgressListWidget::setCurrentProgressWidget(ctkCmdLineModuleFrontend *frontend)
+{
+  if (frontend == NULL && CurrentWidget != NULL)
+  {
+    CurrentWidget->setHighlightStyle(false);
+    CurrentWidget = NULL;
+    return;
+  }
+
+  ctkCmdLineModuleExplorerProgressWidget* progressWidget = FrontendToProgressWidgetMap[frontend];
+  if (progressWidget == NULL) return;
+
+  if (CurrentWidget != NULL)
+  {
+    CurrentWidget->setHighlightStyle(false);
+  }
+
+  progressWidget->setHighlightStyle(true);
+  CurrentWidget = progressWidget;
+}
+
+void ctkCmdLineModuleExplorerProgressListWidget::clearList()
+{
+  QList<ctkCmdLineModuleExplorerProgressWidget*> widgetsToRemove;
+  QHashIterator<ctkCmdLineModuleFrontend*, ctkCmdLineModuleExplorerProgressWidget*> iter(FrontendToProgressWidgetMap);
+  while (iter.hasNext())
+  {
+    iter.next();
+    if (!iter.key()->isRunning())
+    {
+      widgetsToRemove.push_back(iter.value());
+    }
+  }
+
+  foreach(ctkCmdLineModuleExplorerProgressWidget* widget, widgetsToRemove)
+  {
+    widget->deleteLater();
+  }
+}

+ 65 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerProgressListWidget.h

@@ -0,0 +1,65 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#ifndef CTKCMDLINEMODULEEXPLORERPROGRESSLISTWIDGET_H
+#define CTKCMDLINEMODULEEXPLORERPROGRESSLISTWIDGET_H
+
+#include <QWidget>
+#include <QHash>
+
+class ctkCmdLineModuleFrontend;
+class ctkCmdLineModuleFuture;
+class ctkCmdLineModuleExplorerProgressWidget;
+
+class ctkCmdLineModuleExplorerProgressListWidget : public QWidget
+{
+  Q_OBJECT
+
+public:
+  explicit ctkCmdLineModuleExplorerProgressListWidget(QWidget *parent = 0);
+  
+  void addProgressWidget(ctkCmdLineModuleFrontend* frontend, const ctkCmdLineModuleFuture& future);
+
+signals:
+
+  void progressWidgetDoubleClicked(ctkCmdLineModuleFrontend* frontend);
+
+public slots:
+
+  void removeProgressWidget(ctkCmdLineModuleFrontend* frontend);
+
+  void setCurrentProgressWidget(ctkCmdLineModuleFrontend* frontend);
+
+  void clearList();
+  
+private slots:
+
+  void progressWidgetDestroyed(QObject* progressWidget);
+
+private:
+
+  QHash<ctkCmdLineModuleFrontend*, ctkCmdLineModuleExplorerProgressWidget*> FrontendToProgressWidgetMap;
+  QHash<ctkCmdLineModuleExplorerProgressWidget*, ctkCmdLineModuleFrontend*> ProgressWidgetToFrontendMap;
+
+  ctkCmdLineModuleExplorerProgressWidget* CurrentWidget;
+};
+
+#endif // CTKCMDLINEMODULEEXPLORERPROGRESSLISTWIDGET_H

+ 25 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerProgressWidget.cpp

@@ -31,6 +31,8 @@ ctkCmdLineModuleExplorerProgressWidget::ctkCmdLineModuleExplorerProgressWidget(Q
 {
   ui->setupUi(this);
 
+  ui->RemoveButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarCloseButton));
+
   // Due to Qt bug 12152, we cannot listen to the "paused" signal because it is
   // not emitted directly when the QFuture is paused. Instead, it is emitted after
   // resuming the future, after the "resume" signal has been emitted... we use
@@ -60,14 +62,35 @@ void ctkCmdLineModuleExplorerProgressWidget::setFuture(const ctkCmdLineModuleFut
 {
   ui->PauseButton->setEnabled(future.canPause());
   ui->CancelButton->setEnabled(future.canCancel());
+  ui->RemoveButton->setEnabled(!future.isRunning());
+
   FutureWatcher.setFuture(future);
 }
 
+void ctkCmdLineModuleExplorerProgressWidget::setTitle(const QString &title)
+{
+  ui->ProgressTitle->setText(title);
+}
+
+void ctkCmdLineModuleExplorerProgressWidget::setHighlightStyle(bool highlight)
+{
+  QPalette::ColorRole labelRole = highlight ? QPalette::NoRole : QPalette::Midlight;
+
+  ui->ProgressTitle->setForegroundRole(labelRole);
+  ui->ProgressText->setForegroundRole(labelRole);
+  ui->ProgressBar->setEnabled(highlight);
+}
+
 void ctkCmdLineModuleExplorerProgressWidget::on_PauseButton_toggled(bool toggled)
 {
   this->FutureWatcher.setPaused(toggled);
 }
 
+void ctkCmdLineModuleExplorerProgressWidget::on_RemoveButton_clicked()
+{
+  this->deleteLater();
+}
+
 void ctkCmdLineModuleExplorerProgressWidget::moduleStarted()
 {
   this->ui->ProgressBar->setMaximum(0);
@@ -78,6 +101,7 @@ void ctkCmdLineModuleExplorerProgressWidget::moduleCanceled()
   this->ui->PauseButton->setEnabled(false);
   this->ui->PauseButton->setChecked(false);
   this->ui->CancelButton->setEnabled(false);
+  this->ui->RemoveButton->setEnabled(true);
 }
 
 void ctkCmdLineModuleExplorerProgressWidget::moduleFinished()
@@ -85,6 +109,7 @@ void ctkCmdLineModuleExplorerProgressWidget::moduleFinished()
   this->ui->PauseButton->setEnabled(false);
   this->ui->PauseButton->setChecked(false);
   this->ui->CancelButton->setEnabled(false);
+  this->ui->RemoveButton->setEnabled(true);
 }
 
 void ctkCmdLineModuleExplorerProgressWidget::checkModulePaused()

+ 5 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerProgressWidget.h

@@ -49,9 +49,14 @@ public:
 
   void setFuture(const ctkCmdLineModuleFuture& future);
 
+  void setTitle(const QString& title);
+
+  void setHighlightStyle(bool highlight);
+
 private Q_SLOTS:
 
   void on_PauseButton_toggled(bool toggled);
+  void on_RemoveButton_clicked();
 
   void checkModulePaused();
 

+ 40 - 1
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerProgressWidget.ui

@@ -7,13 +7,19 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>98</height>
+    <height>83</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>2</number>
+   </property>
+   <property name="margin">
+    <number>0</number>
+   </property>
    <item>
     <widget class="QLabel" name="ProgressTitle">
      <property name="text">
@@ -61,6 +67,16 @@
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QToolButton" name="RemoveButton">
+       <property name="text">
+        <string>Remove</string>
+       </property>
+       <property name="autoRaise">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>
@@ -70,6 +86,29 @@
      </property>
     </widget>
    </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType">
+      <enum>QSizePolicy::Fixed</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>4</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="Line" name="line">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources>