Pārlūkot izejas kodu

ENH: Add icon to ctkWorkflowWidgetStep, which is added to 'goTo' buttons in ctkWorkflowButtonBoxWidget

- if there is an icon associated with a 'goTo' step in ctkWorkflowButtonBoxWidget, then it will be added to the 'goTo' button
Danielle Pace 15 gadi atpakaļ
vecāks
revīzija
1a25dd595a

+ 12 - 0
Libs/Widgets/Testing/Cpp/ctkWorkflowWidgetTest1.cpp

@@ -25,6 +25,8 @@
 #include <QLabel>
 #include <QLabel>
 #include <QLineEdit>
 #include <QLineEdit>
 #include <QList>
 #include <QList>
+#include <QIcon>
+#include <QStyle>
 
 
 // CTK includes
 // CTK includes
 #include "ctkWorkflow.h"
 #include "ctkWorkflow.h"
@@ -70,6 +72,13 @@ bool buttonClickTest(QApplication& app, int defaultTime, ctkExampleDerivedWorkfl
     return false;
     return false;
     }
     }
 
 
+  // ensure that the finish button has an icon
+  if (shownFinishButton && shownFinishButton->icon().isNull())
+    {
+    std::cerr << "Incorrect finish icon visibility" << std::endl;
+    return false;
+    }
+
   // ensure that widgets of the other step are either invisible, or
   // ensure that widgets of the other step are either invisible, or
   // visible but disabled
   // visible but disabled
   if (hidden->stepArea())
   if (hidden->stepArea())
@@ -820,6 +829,9 @@ int runWorkflowWidgetTest(ctkWorkflowWidget* workflowWidget, QApplication& app,
     }
     }
   testStep3->setHasButtonBoxWidget(true);
   testStep3->setHasButtonBoxWidget(true);
 
 
+  // icon test - add an icon to testStep3, should show up as a icon on the finish button
+  testStep3->setIcon(testStep3->stepArea()->style()->standardIcon(QStyle::SP_ArrowUp));
+
   workflow->addTransition(testStep2, testStep3);
   workflow->addTransition(testStep2, testStep3);
   
   
   // restart the workflow
   // restart the workflow

+ 5 - 1
Libs/Widgets/ctkWorkflowButtonBoxWidget.cpp

@@ -225,8 +225,12 @@ void ctkWorkflowButtonBoxWidgetPrivate::updateGoToButtons(ctkWorkflowStep* curre
       p->layout()->addWidget(goToButton);
       p->layout()->addWidget(goToButton);
       QObject::connect(goToButton, SIGNAL(clicked()), p, SLOT(prepareGoToStep()));
       QObject::connect(goToButton, SIGNAL(clicked()), p, SLOT(prepareGoToStep()));
       this->GoToButtonToStepMap[goToButton] = step;
       this->GoToButtonToStepMap[goToButton] = step;
+      // if the goTo step has an icon associated with it, then add it to the button
+      if (ctkWorkflowWidgetStep* wwStep = qobject_cast<ctkWorkflowWidgetStep*>(step))
+        {
+        goToButton->setIcon(wwStep->icon());
+        }
       }
       }
-      
     }
     }
 
 
   // Show/hide the goTo buttons depending on whether they are accessible from the current step
   // Show/hide the goTo buttons depending on whether they are accessible from the current step

+ 7 - 0
Libs/Widgets/ctkWorkflowWidgetStep.cpp

@@ -22,6 +22,7 @@
 #include <QWidget>
 #include <QWidget>
 #include <QList>
 #include <QList>
 #include <QDebug>
 #include <QDebug>
+#include <QIcon>
 
 
 // CTK includes
 // CTK includes
 #include "ctkWorkflowWidgetStep.h"
 #include "ctkWorkflowWidgetStep.h"
@@ -66,6 +67,8 @@ public:
   bool                        hasButtonBoxWidget;
   bool                        hasButtonBoxWidget;
 
 
   ctkWorkflowWidgetStep::ButtonBoxHints  ButtonBoxHints;
   ctkWorkflowWidgetStep::ButtonBoxHints  ButtonBoxHints;
+
+  QIcon icon;
 };
 };
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -79,6 +82,8 @@ ctkWorkflowWidgetStepPrivate::ctkWorkflowWidgetStepPrivate()
   this->hasButtonBoxWidget = false;
   this->hasButtonBoxWidget = false;
 
 
   stepAreaDirection = QBoxLayout::TopToBottom;
   stepAreaDirection = QBoxLayout::TopToBottom;
+
+  icon = QIcon();
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -110,6 +115,8 @@ CTK_SET_CXX(ctkWorkflowWidgetStep, const QString&, setNextButtonText, nextButton
 // CTK_SET_CXX(ctkWorkflowWidgetStep, QList<QString>, setFinishButtonTexts, finishButtonTexts);
 // CTK_SET_CXX(ctkWorkflowWidgetStep, QList<QString>, setFinishButtonTexts, finishButtonTexts);
 CTK_GET_CXX(ctkWorkflowWidgetStep, bool, hasButtonBoxWidget, hasButtonBoxWidget);
 CTK_GET_CXX(ctkWorkflowWidgetStep, bool, hasButtonBoxWidget, hasButtonBoxWidget);
 CTK_SET_CXX(ctkWorkflowWidgetStep, bool, setHasButtonBoxWidget, hasButtonBoxWidget);
 CTK_SET_CXX(ctkWorkflowWidgetStep, bool, setHasButtonBoxWidget, hasButtonBoxWidget);
+CTK_GET_CXX(ctkWorkflowWidgetStep, QIcon, icon, icon);
+CTK_SET_CXX(ctkWorkflowWidgetStep, const QIcon&, setIcon, icon);
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 CTK_GET_CXX(ctkWorkflowWidgetStep, ctkWorkflowWidgetStep::ButtonBoxHints,
 CTK_GET_CXX(ctkWorkflowWidgetStep, ctkWorkflowWidgetStep::ButtonBoxHints,

+ 4 - 0
Libs/Widgets/ctkWorkflowWidgetStep.h

@@ -24,6 +24,7 @@
 // QT includes
 // QT includes
 class QObject;
 class QObject;
 class QWidget;
 class QWidget;
+class QIcon;
 #include <QBoxLayout>
 #include <QBoxLayout>
 #include <QFlags>
 #include <QFlags>
 
 
@@ -129,6 +130,9 @@ public:
   void setButtonBoxHints(ButtonBoxHints buttonBoxHints);
   void setButtonBoxHints(ButtonBoxHints buttonBoxHints);
   ButtonBoxHints buttonBoxHints()const;
   ButtonBoxHints buttonBoxHints()const;
 
 
+  QIcon icon()const;
+  void setIcon(const QIcon& newIcon);
+
 protected:
 protected:
 
 
   virtual void addButtons();
   virtual void addButtons();