@@ -399,7 +399,7 @@ void ModuleWidgetDisplayMini::setupButtons(bool hasUI, QObject* module)
399399
400400void ModuleWidgetDisplayMini::setupIcons ()
401401{
402-
402+
403403}
404404
405405QAbstractButton* ModuleWidgetDisplayMini::getOptionsButton () const
@@ -447,6 +447,20 @@ void ModuleWidgetDisplayMini::adjustLayout(QLayout* layout)
447447 // #endif
448448}
449449
450+ static const int UNSET = -1 ;
451+ static const int SELECTED = -50 ;
452+ static const int ERRORED = -100 ;
453+ static bool isUnsetOrSelected (int state)
454+ {
455+ return UNSET == state || SELECTED == state;
456+ }
457+
458+ typedef boost::bimap<QString, int > ColorStateLookup;
459+ typedef ColorStateLookup::value_type ColorStatePair;
460+ static ColorStateLookup colorStateLookup;
461+ void fillColorStateLookup (const QString& background);
462+
463+
450464ModuleWidget::ModuleWidget (NetworkEditor* ed, const QString& name, SCIRun::Dataflow::Networks::ModuleHandle theModule, boost::shared_ptr<SCIRun::Gui::DialogErrorControl> dialogErrorControl,
451465 QWidget* parent /* = 0 */ )
452466 : QStackedWidget(parent), HasNotes(theModule->get_id (), true),
@@ -459,6 +473,7 @@ ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, SCIRun::Dataf
459473 isMini_(globalMiniMode_),
460474 errored_(false ),
461475 theModule_(theModule),
476+ previousModuleState_(UNSET),
462477 moduleId_(theModule->get_id ()),
463478 dialog_(nullptr ),
464479 dockable_(nullptr ),
@@ -472,6 +487,8 @@ ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, SCIRun::Dataf
472487 miniIndex_(0 ),
473488 isViewScene_(name == " ViewScene" )
474489{
490+ fillColorStateLookup (defaultBackgroundColor_);
491+
475492 setupModuleActions ();
476493 setupLogging ();
477494
@@ -932,7 +949,10 @@ void ModuleWidget::trackConnections()
932949void ModuleWidget::execute ()
933950{
934951 {
952+ // qDebug() << "executing()";
935953 errored_ = false ;
954+ // previousModuleState_ = (int)ModuleInterface::Completed;
955+ // std::cout << "execute() prev = " << previousModuleState_ << std::endl;
936956 // colorLocked_ = true; //TODO
937957 timer_.restart ();
938958 theModule_->do_execute ();
@@ -957,31 +977,60 @@ boost::signals2::connection ModuleWidget::connectErrorListener(const ErrorSignal
957977 return theModule_->connectErrorListener (subscriber);
958978}
959979
980+ void fillColorStateLookup (const QString& background)
981+ {
982+ if (colorStateLookup.empty ())
983+ {
984+ colorStateLookup.insert (ColorStatePair (moduleRGBA (205 ,190 ,112 ), (int )ModuleInterface::Waiting));
985+ colorStateLookup.insert (ColorStatePair (moduleRGBA (170 ,204 ,170 ), (int )ModuleInterface::Executing));
986+ colorStateLookup.insert (ColorStatePair (background, (int )ModuleInterface::Completed));
987+ colorStateLookup.insert (ColorStatePair (moduleRGBA (0 ,255 ,255 ), SELECTED));
988+ colorStateLookup.insert (ColorStatePair (moduleRGBA (176 , 23 , 31 ), ERRORED));
989+ }
990+ }
991+
992+ // primitive state machine
993+ // TODO: slot should set previousModuleState_
960994void ModuleWidget::updateBackgroundColorForModuleState (int moduleState)
961995{
996+ // qDebug() << "updateColor to " << moduleState;
997+ // std::cout << "update prev = " << previousModuleState_ << std::endl;
962998 switch (moduleState)
963999 {
9641000 case (int )ModuleInterface::Waiting:
965- Q_EMIT backgroundColorUpdated (moduleRGBA (205 ,190 ,112 ));
1001+ if (isUnsetOrSelected (previousModuleState_) || previousModuleState_ == (int )ModuleInterface::Completed)
1002+ {
1003+ Q_EMIT backgroundColorUpdated (moduleRGBA (205 ,190 ,112 ));
1004+ }
9661005 break ;
9671006 case (int )ModuleInterface::Executing:
968- Q_EMIT backgroundColorUpdated (moduleRGBA (170 ,204 ,170 ));
1007+ if (isUnsetOrSelected (previousModuleState_) || previousModuleState_ == (int )ModuleInterface::Waiting)
1008+ {
1009+ Q_EMIT backgroundColorUpdated (moduleRGBA (170 ,204 ,170 ));
1010+ }
9691011 break ;
9701012 case (int )ModuleInterface::Completed:
971- if (!errored_)
972- Q_EMIT backgroundColorUpdated (defaultBackgroundColor_);
1013+ // if (isUnsetOrSelected(previousModuleState_) || previousModuleState_ == (int)ModuleInterface::Executing)
1014+ {
1015+ if (!errored_)
1016+ Q_EMIT backgroundColorUpdated (defaultBackgroundColor_);
1017+ }
9731018 break ;
9741019 }
9751020}
9761021
9771022void ModuleWidget::updateBackgroundColor (const QString& color)
9781023{
1024+ // std::cout << "color set to: " << color.toStdString() << std::endl;
9791025 if (!colorLocked_)
9801026 {
9811027 QString rounded;
9821028 if (SCIRunMainWindow::Instance ()->newInterface ())
9831029 rounded = " color: white; border-radius: 7px;" ;
9841030 setStyleSheet (rounded + " background-color: " + color);
1031+ // qDebug() << "looking up color: " << color << "\n";
1032+ previousModuleState_ = colorStateLookup.left .at (color);
1033+ // qDebug() << "state set to: " << previousModuleState_;
9851034 }
9861035}
9871036
@@ -1209,4 +1258,4 @@ void ModuleWidget::changeDisplay(int oldIndex, int newIndex)
12091258 setCurrentIndex (newIndex);
12101259 resize (size);
12111260 Q_EMIT displayChanged ();
1212- }
1261+ }
0 commit comments