Vuo  2.0.2
VuoCommandSetItemTint.cc
Go to the documentation of this file.
1 
10 #include "VuoCommandCommon.hh"
11 #include "VuoCommandSetItemTint.hh"
12 #include "VuoCompilerComment.hh"
13 #include "VuoCompilerNode.hh"
14 #include "VuoEditorComposition.hh"
15 #include "VuoEditorWindow.hh"
16 #include "VuoRendererComment.hh"
17 #include "VuoComment.hh"
18 
23  : VuoCommandCommon(window)
24 {
25  setText(QApplication::translate("VuoEditorWindow", "Set Tint"));
26  this->window = window;
27  this->revertedSnapshot = window->getComposition()->takeSnapshot();
28  string itemIdentifier = "?";
29 
30  // Start of command content.
31  {
32  VuoRendererNode *node = dynamic_cast<VuoRendererNode *>(item);
33  VuoRendererComment *comment = dynamic_cast<VuoRendererComment *>(item);
34 
35  if (node)
36  {
37  QGraphicsItem::CacheMode normalCacheMode = node->cacheMode();
38  node->setCacheModeForNodeAndPorts(QGraphicsItem::NoCache);
39 
40  set<VuoCable *> connectedCables = node->getConnectedCables(true);
41  foreach (VuoCable *cable, connectedCables)
42  cable->getRenderer()->setCacheMode(QGraphicsItem::NoCache);
43 
44  node->updateGeometry();
45  node->getBase()->setTintColor(tintColor);
46 
47  node->setCacheModeForNodeAndPorts(normalCacheMode);
48 
49  foreach (VuoCable *cable, connectedCables)
50  cable->getRenderer()->setCacheModeForCableAndConnectedPorts(normalCacheMode);
51 
52  if (node->getBase()->hasCompiler())
53  itemIdentifier = node->getBase()->getCompiler()->getIdentifier().c_str();
54  }
55  else if (comment)
56  {
57  QGraphicsItem::CacheMode normalCacheMode = comment->cacheMode();
58  comment->setCacheMode(QGraphicsItem::NoCache);
59  comment->updateGeometry();
60 
61  comment->getBase()->setTintColor(tintColor);
62 
63  comment->setCacheMode(normalCacheMode);
64 
65  itemIdentifier = comment->getBase()->getCompiler()->getGraphvizIdentifier().c_str();
66  }
67  }
68  // End of command content.
69 
70  this->updatedSnapshot = window->getComposition()->takeSnapshot();
71 
72  setDescription("Tint %s to %s",
73  itemIdentifier.c_str(),
74  tintColor == VuoNode::TintNone ? "none" : VuoNode::getGraphvizNameForTint(tintColor).c_str());
75 }
76 
81 {
83 }
84 
89 {
91 
92  window->resetCompositionWithSnapshot(revertedSnapshot);
93 }
94 
99 {
101 
102  window->resetCompositionWithSnapshot(updatedSnapshot);
103 }