14const int VuoDialogForInputEditor::popoverArrowHalfWidth = 8;
21 setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
25 setAttribute(Qt::WA_TranslucentBackground,
true);
27 arrowPixelsFromTopOrLeft = 0;
29 this->_isDark = isDark;
30 this->_showArrow = showArrow;
32 respondingToKeypress =
false;
38QPainterPath VuoDialogForInputEditor::getPopoverPath(
void)
43 path.moveTo(width()-popoverArrowHalfWidth-cornerRadius,0);
44 path.cubicTo(width()-popoverArrowHalfWidth,0, width()-popoverArrowHalfWidth,0, width()-popoverArrowHalfWidth,cornerRadius);
45 path.lineTo(width()-popoverArrowHalfWidth,arrowPixelsFromTopOrLeft-popoverArrowHalfWidth);
46 if (_showArrow && arrowPixelsFromTopOrLeft+popoverArrowHalfWidth < height())
47 path.lineTo(width(),arrowPixelsFromTopOrLeft);
48 path.lineTo(width()-popoverArrowHalfWidth,arrowPixelsFromTopOrLeft+popoverArrowHalfWidth);
49 path.lineTo(width()-popoverArrowHalfWidth,height()-cornerRadius);
50 path.cubicTo(width()-popoverArrowHalfWidth,height(), width()-popoverArrowHalfWidth,height(), width()-popoverArrowHalfWidth-cornerRadius,height());
51 path.lineTo(cornerRadius,height());
52 path.cubicTo(0,height(), 0,height(), 0,height()-cornerRadius);
53 path.lineTo(0,cornerRadius);
54 path.cubicTo(0,0, 0,0, cornerRadius,0);
65 return QMargins(5, 5, 5 + popoverArrowHalfWidth, 5);
74 QRect rect = childrenRect();
75 if (rect.width() > 0 && rect.height() > 0)
78 return rectWithMargins.size();
81 return QDialog::sizeHint();
87void VuoDialogForInputEditor::paintEvent(QPaintEvent *event)
91 QColor backgroundColor = _isDark ? QColor(
"#505050") : QColor(
"#f9f9f9");
93 QPainter painter(
this);
96 painter.setCompositionMode(QPainter::CompositionMode_Clear);
97 painter.setBrush(backgroundColor);
98 painter.drawRect(QRect(0, 0, width(), height()));
99 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
101 painter.setRenderHint(QPainter::Antialiasing,
true);
103 painter.setPen(Qt::NoPen);
104 painter.fillPath(getPopoverPath(), backgroundColor);
110void VuoDialogForInputEditor::showEvent(QShowEvent *event)
112 QDialog::showEvent(
event);
114 arrowPixelsFromTopOrLeft = height()/2;
122 respondingToKeypress =
true;
123 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
127 QDialog::keyPressEvent(e);
128 respondingToKeypress =
false;
136 if (e->type() == QEvent::WindowDeactivate)
140 if (!respondingToKeypress)
146 return QDialog::event(e);
154 this->_showArrow = show;