Vuo 2.4.4
Loading...
Searching...
No Matches
VuoDialogForInputEditor.cc
Go to the documentation of this file.
1
11#include "VuoInputEditor.hh"
12
14const 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 respondingToKeypress = false;
33}
34
38QPainterPath VuoDialogForInputEditor::getPopoverPath(void)
39{
41 int cornerRadius = 8;
42 QPainterPath path;
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);
55 path.closeSubpath();
56
57 return path;
58}
59
64{
65 return QMargins(5, 5, 5 + popoverArrowHalfWidth, 5);
66}
67
73{
74 QRect rect = childrenRect();
75 if (rect.width() > 0 && rect.height() > 0)
76 {
77 QRect rectWithMargins = rect.marginsAdded( getPopoverContentsMargins() );
78 return rectWithMargins.size();
79 }
80
81 return QDialog::sizeHint();
82}
83
87void VuoDialogForInputEditor::paintEvent(QPaintEvent *event)
88{
90
91 QColor backgroundColor = _isDark ? QColor("#505050") : QColor("#f9f9f9");
92
93 QPainter painter(this);
94
95 // Workaround to ensure that transparent background behind rounded corners works consistently
96 painter.setCompositionMode(QPainter::CompositionMode_Clear);
97 painter.setBrush(backgroundColor);
98 painter.drawRect(QRect(0, 0, width(), height()));
99 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
100
101 painter.setRenderHint(QPainter::Antialiasing, true);
102
103 painter.setPen(Qt::NoPen);
104 painter.fillPath(getPopoverPath(), backgroundColor);
105}
106
110void VuoDialogForInputEditor::showEvent(QShowEvent *event)
111{
112 QDialog::showEvent(event);
113
114 arrowPixelsFromTopOrLeft = height()/2;
115}
116
121{
122 respondingToKeypress = true;
123 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
124 accept();
125 }
126
127 QDialog::keyPressEvent(e);
128 respondingToKeypress = false;
129}
130
135{
136 if (e->type() == QEvent::WindowDeactivate)
137 {
138 // If this deactivation was triggered by a keypress, don't override the
139 // accept/reject decision already made in keyPressEvent().
140 if (!respondingToKeypress)
141 accept();
142
143 return true;
144 }
145
146 return QDialog::event(e);
147}
148
153{
154 this->_showArrow = show;
155}