Vuo  2.1.2
VuoDialogForInputEditor.cc
Go to the documentation of this file.
1 
11 #include "VuoInputEditor.hh"
12 
14 const int VuoDialogForInputEditor::popoverArrowHalfWidth = 8;
15 
20 {
21  setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
22 
24  // Transparent background behind rounded corners
25  setAttribute(Qt::WA_TranslucentBackground, true);
26 
27  arrowPixelsFromTopOrLeft = 0;
28 
29  this->_isDark = isDark;
30  this->_showArrow = showArrow;
31 
32  setStyleSheet(getStyleSheet(isDark));
33 }
34 
39 {
40  QString styleSheet = "* { " + VuoInputEditor::getDefaultFontCss() + " } ";
41  if (isDark)
42  styleSheet += VUO_QSTRINGIFY(
43  QCheckBox,
44  QLabel {
45  color: #cfcfcf;
46  }
47  QLabel:disabled {
48  color: #8f8f8f;
49  }
50 
51 
52  QLineEdit,
53  QPlainTextEdit,
54  QDoubleSpinBox,
55  QSpinBox {
56  color: #cfcfcf;
57  border: 2px solid #707070;
58  border-radius: 4px;
59  background: #1a1a1a;
60  selection-background-color: #1f365b;
61  selection-color: #ffffff;
62  }
63  QLineEdit:disabled,
64  QPlainTextEdit:disabled,
65  QDoubleSpinBox:disabled,
66  QSpinBox:disabled {
67  color: #8f8f8f;
68  border: 2px solid #606060;
69  background: #353535;
70  }
71 
72  QSlider::groove:horizontal {
73  height: 4px;
74  background: #404040;
75  border-radius: 2px;
76  margin: 5px 5px;
77  }
78  QSlider::groove:horizontal:disabled {
79  background: #484848;
80  }
81 
82  QSlider::handle:horizontal {
83  background: #262626;
84  border: 1px solid #808080;
85  border-radius: 2px;
86  width: 10px;
87  height: 10px;
88  margin: -5px -5px;
89  }
90  QSlider::handle:horizontal:disabled {
91  background: #3b3b3b;
92  border: 1px solid #686868;
93  }
94 
95 
96  // The combo box widget (not the combo box's popup menu).
97  QComboBox {
98  border: 2px solid #707070;
99  border-radius: 4px;
100  padding: 0 22px 0 4px;
101  background: #1a1a1a;
102  color: #cfcfcf;
103  min-height: 22px;
104  }
105  QComboBox:on {
106  color: black;
107  }
108  QComboBox:off {
109  color: black;
110  }
111  QComboBox:focus {
112  background: #1a1a1a;
113  color: #cfcfcf;
114  }
115  QComboBox::drop-down {
116  width: 22px;
117  background: #1a1a1a;
118  }
119  QComboBox::down-arrow {
120  image: url(:/Icons/spinbox-dec.png);
121  }
122 
123  // The combo box's popup menu.
124  // Should parallel VuoEditorWindow::updateColor()'s QMenu styles.
125  QComboBox QAbstractItemView {
126  border-top: 4px solid #404040;
127  border-bottom: 4px solid #404040;
128  background-color: #404040;
129  }
130  QComboBox::item {
131  color: #cfcfcf;
132  padding-left: 22px;
133  padding-right: 36px;
134  height: 21px;
135  }
136  QComboBox::item:disabled {
137  color: #707070;
138  }
139  QComboBox::item:selected {
140  background-color: #1060d0;
141  color: #ffffff;
142  }
143  QComboBox::separator {
144  height: 2px;
145  background: #505050;
146  margin: 5px 0;
147  }
148  QComboBox::indicator:checked {
149  image: url(:/Icons/checkmark.svg);
150  width: 11px;
151  }
152  QComboBox::indicator:checked,
153  QComboBox::icon {
154  margin-left: 6px;
155  }
156  QComboBox::icon:checked,
157  QComboBox::icon:unchecked {
158  margin-left: 0;
159  }
160  );
161 
162  // Restyle spinboxes both in light and dark mode.
163  styleSheet += VUO_QSTRINGIFY(
164  QDoubleSpinBox,
165  QSpinBox {
166  padding-right: -1px;
167  padding-bottom: 1px;
168  }
169 
170  QDoubleSpinBox::up-button,
171  QSpinBox::up-button {
172  subcontrol-origin: content;
173  subcontrol-position: top right;
174  border: none;
175  }
176  QDoubleSpinBox::up-arrow,
177  QSpinBox::up-arrow {
178  image: url(:/Icons/spinbox-inc.png);
179  width: 11px;
180  height: 7px;
181  }
182  QDoubleSpinBox::down-button,
183  QSpinBox::down-button {
184  subcontrol-origin: content;
185  subcontrol-position: bottom right;
186  border: none;
187  }
188  QDoubleSpinBox::down-arrow,
189  QSpinBox::down-arrow {
190  image: url(:/Icons/spinbox-dec.png);
191  width: 11px;
192  height: 7px;
193  }
194 
195  QDoubleSpinBox::up-arrow:hover,
196  QDoubleSpinBox::down-arrow:hover,
197  QSpinBox::up-arrow:hover,
198  QSpinBox::down-arrow:hover {
199  background: %1;
200  }
201 
202  // The `off` state is applied when the current value is at the max/min of the range.
203  QDoubleSpinBox::up-arrow:disabled,
204  QSpinBox::up-arrow:disabled,
205  QDoubleSpinBox::up-arrow:off,
206  QSpinBox::up-arrow:off {
207  image: url(:/Icons/spinbox-inc-disabled.png);
208  }
209  QDoubleSpinBox::down-arrow:disabled,
210  QSpinBox::down-arrow:disabled,
211  QDoubleSpinBox::down-arrow:off,
212  QSpinBox::down-arrow:off {
213  image: url(:/Icons/spinbox-dec-disabled.png);
214  }
215  )
216  .arg(isDark ? "#3a3a3a" : "#c4c4c4");
217 
218  if (!isDark)
219  styleSheet += VUO_QSTRINGIFY(
220  QDoubleSpinBox,
221  QSpinBox {
222  border: 1px solid #c9c9c9;
223  border-radius: 1px;
224  }
225  );
226 
227  return styleSheet;
228 }
229 
233 QPainterPath VuoDialogForInputEditor::getPopoverPath(void)
234 {
236  int cornerRadius = 8;
237  QPainterPath path;
238  path.moveTo(width()-popoverArrowHalfWidth-cornerRadius,0);
239  path.cubicTo(width()-popoverArrowHalfWidth,0, width()-popoverArrowHalfWidth,0, width()-popoverArrowHalfWidth,cornerRadius);
240  path.lineTo(width()-popoverArrowHalfWidth,arrowPixelsFromTopOrLeft-popoverArrowHalfWidth);
241  if (_showArrow && arrowPixelsFromTopOrLeft+popoverArrowHalfWidth < height())
242  path.lineTo(width(),arrowPixelsFromTopOrLeft);
243  path.lineTo(width()-popoverArrowHalfWidth,arrowPixelsFromTopOrLeft+popoverArrowHalfWidth);
244  path.lineTo(width()-popoverArrowHalfWidth,height()-cornerRadius);
245  path.cubicTo(width()-popoverArrowHalfWidth,height(), width()-popoverArrowHalfWidth,height(), width()-popoverArrowHalfWidth-cornerRadius,height());
246  path.lineTo(cornerRadius,height());
247  path.cubicTo(0,height(), 0,height(), 0,height()-cornerRadius);
248  path.lineTo(0,cornerRadius);
249  path.cubicTo(0,0, 0,0, cornerRadius,0);
250  path.closeSubpath();
251 
252  return path;
253 }
254 
259 {
260  return QMargins(5, 5, 5 + popoverArrowHalfWidth, 5);
261 }
262 
268 {
269  QRect rect = childrenRect();
270  if (rect.width() > 0 && rect.height() > 0)
271  {
272  QRect rectWithMargins = rect.marginsAdded( getPopoverContentsMargins() );
273  return rectWithMargins.size();
274  }
275 
276  return QDialog::sizeHint();
277 }
278 
282 void VuoDialogForInputEditor::paintEvent(QPaintEvent *event)
283 {
285 
286  QColor backgroundColor = _isDark ? QColor("#505050") : QColor("#f9f9f9");
287 
288  QPainter painter(this);
289 
290  // Workaround to ensure that transparent background behind rounded corners works consistently
291  painter.setCompositionMode(QPainter::CompositionMode_Clear);
292  painter.setBrush(backgroundColor);
293  painter.drawRect(QRect(0, 0, width(), height()));
294  painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
295 
296  painter.setRenderHint(QPainter::Antialiasing, true);
297 
298  painter.setPen(Qt::NoPen);
299  painter.fillPath(getPopoverPath(), backgroundColor);
300 }
301 
305 void VuoDialogForInputEditor::showEvent(QShowEvent *event)
306 {
307  QDialog::showEvent(event);
308 
309  arrowPixelsFromTopOrLeft = height()/2;
310 }
311 
316 {
317  if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
318  accept();
319  }
320 
321  QDialog::keyPressEvent(e);
322 }
323 
328 {
329  if (e->type() == QEvent::WindowDeactivate)
330  {
331  accept();
332  return true;
333  }
334 
335  return QDialog::event(e);
336 }
337 
342 {
343  this->_showArrow = show;
344 }