Explorar o código

Add ctkWorkflowGroupBox::titleFormat, subTitleFormat and errorTextFormat

Give the option to configure the look of the ctkWorkflowGroupBox items.
Julien Finet %!s(int64=12) %!d(string=hai) anos
pai
achega
d4e5d873c9
Modificáronse 2 ficheiros con 104 adicións e 17 borrados
  1. 66 16
      Libs/Widgets/ctkWorkflowGroupBox.cpp
  2. 38 1
      Libs/Widgets/ctkWorkflowGroupBox.h

+ 66 - 16
Libs/Widgets/ctkWorkflowGroupBox.cpp

@@ -26,6 +26,7 @@
 
 // CTK includes
 #include "ctkWorkflowGroupBox.h"
+#include "ctkWorkflowWidget.h"
 #include "ctkWorkflowWidgetStep.h"
 #include "ctkFittedTextBrowser.h"
 #include "ui_ctkWorkflowGroupBox.h"
@@ -37,12 +38,15 @@ static ctkLogger logger("org.commontk.libs.widgets.ctkWorkflowGroupBox");
 
 //-----------------------------------------------------------------------------
 class ctkWorkflowGroupBoxPrivate: public Ui_ctkWorkflowGroupBox
-                                  
 {
 public:
   ctkWorkflowGroupBoxPrivate();
   ~ctkWorkflowGroupBoxPrivate();
 
+  QString TitleFormat;
+  QString SubTitleFormat;
+  QString ErrorTextFormat;
+
   bool HideWidgetsOfNonCurrentSteps;
   bool ErrorTextEnabled;
 
@@ -58,6 +62,10 @@ public:
 //---------------------------------------------------------------------------
 ctkWorkflowGroupBoxPrivate::ctkWorkflowGroupBoxPrivate()
 {
+  this->TitleFormat = "{current:name}";
+  this->SubTitleFormat = "{current:description}";
+  this->ErrorTextFormat = "{current:statusText}";
+
   this->HideWidgetsOfNonCurrentSteps = false;
 
   this->ErrorTextEnabled = true;
@@ -105,14 +113,19 @@ void ctkWorkflowGroupBox::updateGroupBox(ctkWorkflowStep* currentStep)
 {
   Q_D(ctkWorkflowGroupBox);
 
-  d->StepShownPreviously = d->StepShownCurrently;
+  d->StepShownPreviously = (currentStep != d->StepShownCurrently ?
+                            d->StepShownCurrently : d->StepShownPreviously);
   d->StepShownCurrently = currentStep;
 
-  if (currentStep)
-    { 
-    this->setTitle(currentStep->name());
-    this->setSubTitle(currentStep->description());
-    this->setErrorText(currentStep->statusText());
+  ctkWorkflowWidgetStep* currentWidgetStep = dynamic_cast<ctkWorkflowWidgetStep*>(currentStep);
+
+  if (currentWidgetStep)
+    {
+    ctkWorkflowWidget::formatButton(d->CollapsibleButton, d->TitleFormat, currentWidgetStep);
+    QString subTitleText = ctkWorkflowWidget::formatText(d->SubTitleFormat, currentWidgetStep);
+    this->setSubTitle(subTitleText);
+    QString errorText = ctkWorkflowWidget::formatText(d->ErrorTextFormat, currentWidgetStep);
+    this->setErrorText(errorText);
 
     // don't show textual elements if they are empty
     d->SubTitleTextBrowser->setVisible(!this->subTitle().isEmpty());
@@ -134,8 +147,7 @@ void ctkWorkflowGroupBox::updateGroupBox(ctkWorkflowStep* currentStep)
         }
       }
     }
-  
-  ctkWorkflowWidgetStep* currentWidgetStep = dynamic_cast<ctkWorkflowWidgetStep*>(currentStep);
+
   // show/enable the current step
   if (currentWidgetStep)
     {
@@ -164,13 +176,6 @@ QString ctkWorkflowGroupBox::title()const
 }
 
 // --------------------------------------------------------------------------
-void ctkWorkflowGroupBox::setTitle(const QString& newTitleText)
-{
-  Q_D(ctkWorkflowGroupBox);
-  d->CollapsibleButton->setText(newTitleText);
-}
-
-// --------------------------------------------------------------------------
 QString ctkWorkflowGroupBox::subTitle()const
 {
   Q_D(const ctkWorkflowGroupBox);
@@ -225,3 +230,48 @@ void ctkWorkflowGroupBox::setErrorText(const QString& newErrorText)
   Q_D(ctkWorkflowGroupBox);
   d->ErrorTextBrowser->setPlainText(newErrorText);
 }
+
+// --------------------------------------------------------------------------
+QString ctkWorkflowGroupBox::titleFormat()const
+{
+  Q_D(const ctkWorkflowGroupBox);
+  return d->TitleFormat;
+}
+
+// --------------------------------------------------------------------------
+void ctkWorkflowGroupBox::setTitleFormat(const QString& format)
+{
+  Q_D(ctkWorkflowGroupBox);
+  d->TitleFormat = format;
+  this->updateGroupBox(d->StepShownCurrently);
+}
+
+// --------------------------------------------------------------------------
+QString ctkWorkflowGroupBox::subTitleFormat()const
+{
+  Q_D(const ctkWorkflowGroupBox);
+  return d->SubTitleFormat;
+}
+
+// --------------------------------------------------------------------------
+void ctkWorkflowGroupBox::setSubTitleFormat(const QString& format)
+{
+  Q_D(ctkWorkflowGroupBox);
+  d->SubTitleFormat = format;
+  this->updateGroupBox(d->StepShownCurrently);
+}
+
+// --------------------------------------------------------------------------
+QString ctkWorkflowGroupBox::errorTextFormat()const
+{
+  Q_D(const ctkWorkflowGroupBox);
+  return d->ErrorTextFormat;
+}
+
+// --------------------------------------------------------------------------
+void ctkWorkflowGroupBox::setErrorTextFormat(const QString& format)
+{
+  Q_D(ctkWorkflowGroupBox);
+  d->ErrorTextFormat = format;
+  this->updateGroupBox(d->StepShownCurrently);
+}

+ 38 - 1
Libs/Widgets/ctkWorkflowGroupBox.h

@@ -43,6 +43,20 @@ class CTK_WIDGETS_EXPORT ctkWorkflowGroupBox : public QWidget
   Q_OBJECT
   Q_PROPERTY(QString preText READ preText WRITE setPreText)
   Q_PROPERTY(QString postText READ postText WRITE setPostText)
+  /// This property controls the text, icon and tooltip of the title button.
+  /// "{current:name}" by default.
+  /// \sa titleFormat(), setTitleFormat(), ctkWorkflow::formatButton()
+  Q_PROPERTY(QString titleFormat READ titleFormat WRITE setTitleFormat)
+  /// This property controls the text of the subtitle view.
+  /// "{current:description}" by default.
+  /// \sa subTitleFormat(), setSubTitleFormat(), ctkWorkflow::formatButton(),
+  /// titleFormat, errorTextFormat
+  Q_PROPERTY(QString subTitleFormat READ subTitleFormat WRITE setSubTitleFormat)
+  /// This property controls the textof the error view.
+  /// "{current:statusText}" by default.
+  /// \sa errorTextFormat(), setErrorTextFormat(), ctkWorkflow::formatButton(),
+  /// titleFormat, subTitleFormat
+  Q_PROPERTY(QString errorTextFormat READ errorTextFormat WRITE setErrorTextFormat)
   Q_PROPERTY(bool hideWidgetsOfNonCurrentSteps READ hideWidgetsOfNonCurrentSteps WRITE setHideWidgetsOfNonCurrentSteps)
   Q_PROPERTY(bool errorTextEnabled READ errorTextEnabled WRITE setErrorTextEnabled)
 
@@ -85,6 +99,30 @@ public:
   /// \brief Get the layout onto which step specific widgets are placed.
   QLayout* clientAreaLayout()const;
 
+  /// Return the titleFormat property value.
+  /// \sa titleFormat, setTitleFormat()
+  QString titleFormat()const;
+
+  /// Set the titleFormat property value.
+  /// \sa titleFormat, titleFormat()
+  void setTitleFormat(const QString& format);
+
+  /// Return the subTitleFormat property value.
+  /// \sa subTitleFormat, setSubTitleFormat()
+  QString subTitleFormat()const;
+
+  /// Set the subTitleFormat property value.
+  /// \sa subTitleFormat, subTitleFormat()
+  void setSubTitleFormat(const QString& format);
+
+  /// Return the errorTextFormat property value.
+  /// \sa errorTextFormat, setErrorTextFormat()
+  QString errorTextFormat()const;
+
+  /// Set the errorTextFormat property value.
+  /// \sa errorTextFormat, errorTextFormat()
+  void setErrorTextFormat(const QString& format);
+
   ///
   /// If hideWidgetsOfNonCurrentSteps is turned on, then a step's
   /// widgets will be hidden when that step is not the current step.
@@ -107,7 +145,6 @@ public Q_SLOTS:
   virtual void updateGroupBox(ctkWorkflowStep* currentStep);
 
 protected:
-  virtual void setTitle(const QString& newTitle);
   virtual void setSubTitle(const QString& newSubTitle);
   virtual void setErrorText(const QString& newErrorText);