Vuo  2.3.2
VuoCodeIssueList.cc
Go to the documentation of this file.
1 
10 #include "VuoCodeIssueList.hh"
11 
12 #include "VuoCodeEditor.hh"
13 #include "VuoCodeEditorStages.hh"
14 #include "VuoCodeWindow.hh"
15 #include "VuoEditor.hh"
16 #include "VuoShaderIssues.hh"
17 
22  : QDockWidget(parent)
23 {
24  codeWindow = static_cast<VuoCodeWindow *>(parent);
25 
26  setFeatures(QDockWidget::NoDockWidgetFeatures);
27  setFixedHeight(0);
28 
29  // Hide the titlebar.
30  setTitleBarWidget(new QWidget);
31 
32  listWidget = new QListWidget(this);
33  setWidget(listWidget);
34 
35  listWidget->setIconSize(QSize(12,12));
36 
37 #ifdef __APPLE__
38  // Disable standard OS X focus 'glow'
39  listWidget->setAttribute(Qt::WA_MacShowFocusRect, false);
40 #endif
41 
42  connect(listWidget, &QListWidget::currentItemChanged, this, &VuoCodeIssueList::moveCursorToIssue);
43 
44  VuoEditor *editor = static_cast<VuoEditor *>(qApp);
45  connect(editor, &VuoEditor::darkInterfaceToggled, this, &VuoCodeIssueList::updateColor);
46  updateColor(editor->isInterfaceDark());
47 }
48 
53 {
54  QIcon errorIcon = *codeWindow->stages->someEditor()->errorIcon;
55 
56  listWidget->clear();
57  for (vector<VuoShaderIssues::Issue>::iterator it = codeWindow->issues->issues().begin(); it != codeWindow->issues->issues().end(); ++it)
58  {
59  QListWidgetItem *item = new QListWidgetItem(errorIcon, QString::fromStdString(it->message), codeWindow->issueList->listWidget);
60  item->setData(Qt::UserRole, it->stage);
61  item->setData(Qt::UserRole+1, it->lineNumber);
62  }
63 
64  setFixedHeight(codeWindow->issues->issues().empty() ? 0 : fmin(listWidget->sizeHintForRow(0) * listWidget->count() + 2, 200));
65 }
66 
67 void VuoCodeIssueList::moveCursorToIssue(QListWidgetItem *item)
68 {
69  if (!item)
70  return;
71 
72  VuoShaderFile::Stage stage = static_cast<VuoShaderFile::Stage>(item->data(Qt::UserRole).toInt());
73  codeWindow->stages->switchToStage(stage);
74 
75  int lineNumber = item->data(Qt::UserRole+1).toInt();
76  if (!VuoShaderIssues::isUserEnteredLine(lineNumber))
77  return;
78 
79  VuoCodeEditor *codeEditor = static_cast<VuoCodeEditor *>(codeWindow->stages->currentWidget());
80  codeEditor->selectLine(lineNumber);
81 }
82 
87 {
88  VuoShaderFile::Stage stage = codeWindow->stages->currentStage();
89 
90  bool matched = false;
91  int itemCount = listWidget->count();
92  for (int i = 0; i < itemCount; ++i)
93  {
94  VuoShaderFile::Stage itemStage = static_cast<VuoShaderFile::Stage>(listWidget->item(i)->data(Qt::UserRole).toInt());
95  int itemLineNumber = listWidget->item(i)->data(Qt::UserRole+1).toInt();
96  if (itemStage == stage
97  && itemLineNumber == lineNumber)
98  {
99  disconnect(listWidget, &QListWidget::currentItemChanged, this, &VuoCodeIssueList::moveCursorToIssue);
100  listWidget->setCurrentRow(i);
101  connect(listWidget, &QListWidget::currentItemChanged, this, &VuoCodeIssueList::moveCursorToIssue);
102 
103  matched = true;
104  break;
105  }
106  }
107 
108  if (!matched)
109  listWidget->setCurrentItem(NULL);
110 }
111 
112 void VuoCodeIssueList::updateColor(bool isDark)
113 {
114  QPalette p;
115 
116  VuoCodeEditor *e = codeWindow->stages->someEditor();
117 
118  QColor background = e->gutterColor.lighter(isDark ? 50 : 150);
119  p.setColor(QPalette::All, QPalette::Base, background);
120 
121  p.setColor(QPalette::Active, QPalette::Highlight, isDark ? "#12418c" : "#74acec");
122  p.setColor(QPalette::Inactive, QPalette::Highlight, isDark ? "#606060" : "#e0e0e0");
123  p.setColor(QPalette::Active, QPalette::HighlightedText, isDark ? "#c0c0c0" : "#404040");
124  p.setColor(QPalette::Inactive, QPalette::HighlightedText, isDark ? "#c0c0c0" : "#404040");
125 
126  listWidget->setPalette(p);
127 
128  setStyleSheet(VUO_QSTRINGIFY(
129  QListWidget {
130  font-size: 12pt;
131  border: none;
132  border-top: 3px solid %1;
133  background: %1;
134  color: %2;
135  }
136  ).arg(background.name(),
137  isDark ? "#a0a0a0" : "#606060"));
138 }