34 #include <private/qgraphicsproxywidget_p.h>
35 #include <private/qlayoutengine_p.h>
68 ++counts[
event->type()];
80 void qgraphicsproxywidget();
83 void setWidget_data();
85 void testEventFilter_data();
86 void testEventFilter();
87 void focusInEvent_data();
89 void focusInEventNoWidget();
90 void focusNextPrevChild_data();
91 void focusNextPrevChild();
92 void focusOutEvent_data();
94 void focusProxy_QTBUG_51856();
95 void hoverEnterLeaveEvent_data();
96 void hoverEnterLeaveEvent();
97 void keyPressEvent_data();
99 void keyReleaseEvent_data();
100 void keyReleaseEvent();
101 void mouseDoubleClickEvent();
102 void mousePressReleaseEvent_data();
103 void mousePressReleaseEvent();
104 void resizeEvent_data();
107 #if QT_CONFIG(wheelevent)
114 void setWidget_simple();
115 void setWidget_ownership();
116 void resize_simple_data();
117 void resize_simple();
118 void symmetricMove();
119 void symmetricResize();
120 void symmetricEnabled();
121 void symmetricVisible();
122 void tabFocus_simpleWidget();
123 void tabFocus_simpleTwoWidgets();
124 void tabFocus_complexWidget();
125 void tabFocus_complexTwoWidgets();
126 void setFocus_simpleWidget();
127 void setFocus_simpleTwoWidgets();
128 void setFocus_complexTwoWidgets();
130 void popup_subwidget();
131 void changingCursor_basic();
132 void tooltip_basic();
133 void childPos_data();
136 void windowOpacity();
137 void stylePropagation();
138 void palettePropagation();
139 void fontPropagation();
140 void dontCrashWhenDie();
141 void dontCrashNoParent();
142 void createProxyForChildWidget();
143 #ifndef QT_NO_CONTEXTMENU
144 void actionsContextMenu();
146 void actionsContextMenu_data();
147 void deleteProxyForChildWidget();
148 void bypassGraphicsProxyWidget_data();
149 void bypassGraphicsProxyWidget();
151 void windowFlags_data();
153 void comboboxWindowFlags();
154 void updateAndDelete();
157 void windowFrameMargins();
158 void QTBUG_6986_sendMouseEventToAlienWidget();
160 void mapToGlobalWithoutScene();
161 void QTBUG_43780_visibility();
162 #if QT_CONFIG(wheelevent)
163 void wheelEventPropagation();
165 void forwardTouchEvent();
166 void touchEventPropagation();
197 #if QT_CONFIG(wheelevent)
198 class WheelWidget :
public QWidget
203 virtual void wheelEvent(QWheelEvent *
event)
override {
event->accept(); wheelEventCalled =
true; }
205 bool wheelEventCalled;
211 void tst_QGraphicsProxyWidget::initTestCase()
222 void tst_QGraphicsProxyWidget::cleanup()
227 void tst_QGraphicsProxyWidget::qgraphicsproxywidget()
230 proxy.paint(0, 0, 0);
238 proxy.focusInEvent(&focusEvent);
239 QCOMPARE(focusEvent.isAccepted(),
false);
242 proxy.focusOutEvent(&focusEvent);
244 proxy.hideEvent(&hideEvent);
246 proxy.hoverEnterEvent(&hoverEvent);
247 proxy.hoverLeaveEvent(&hoverEvent);
248 proxy.hoverMoveEvent(&hoverEvent);
250 proxy.keyPressEvent(&keyEvent);
251 proxy.keyReleaseEvent(&keyEvent);
253 proxy.mouseDoubleClickEvent(&mouseEvent);
254 proxy.mouseMoveEvent(&mouseEvent);
255 proxy.mousePressEvent(&mouseEvent);
256 proxy.mouseReleaseEvent(&mouseEvent);
258 proxy.resizeEvent(&resizeEvent);
260 proxy.showEvent(&showEvent);
265 void tst_QGraphicsProxyWidget::paint()
269 proxy.paint(0, 0, 0);
286 void tst_QGraphicsProxyWidget::paint_2()
301 void tst_QGraphicsProxyWidget::setWidget_data()
303 QTest::addColumn<bool>(
"widgetExists");
304 QTest::addColumn<bool>(
"insertWidget");
305 QTest::addColumn<bool>(
"hasParent");
306 QTest::addColumn<bool>(
"proxyHasParent");
308 QTest::newRow(
"setWidget(0)") <<
false <<
false <<
false <<
false;
309 QTest::newRow(
"setWidget(widget)") <<
false <<
true <<
false <<
false;
310 QTest::newRow(
"setWidget(widgetWParent)") <<
false <<
true <<
true <<
false;
311 QTest::newRow(
"setWidget(1), setWidget(0)") <<
true <<
false <<
false <<
false;
312 QTest::newRow(
"setWidget(1), setWidget(widget)") <<
true <<
true <<
false <<
false;
313 QTest::newRow(
"setWidget(1), setWidget(widgetWParent)") <<
true <<
true <<
true <<
false;
314 QTest::newRow(
"p setWidget(0)") <<
false <<
false <<
false <<
true;
315 QTest::newRow(
"p setWidget(widget)") <<
false <<
true <<
false <<
true;
316 QTest::newRow(
"p setWidget(widgetWParent)") <<
false <<
true <<
true <<
true;
317 QTest::newRow(
"p setWidget(1), setWidget(0)") <<
true <<
false <<
false <<
true;
318 QTest::newRow(
"p setWidget(1), setWidget(widget)") <<
true <<
true <<
false <<
true;
319 QTest::newRow(
"p setWidget(1), setWidget(widgetWParent)") <<
true <<
true <<
true <<
true;
323 void tst_QGraphicsProxyWidget::setWidget()
325 QFETCH(
bool, widgetExists);
326 QFETCH(
bool, insertWidget);
328 QFETCH(
bool, proxyHasParent);
335 QSKIP(
"This test requires the Fusion style");
342 proxy->setParent(&parentProxy);
344 proxy->setVisible(
false);
345 proxy->setEnabled(
false);
349 proxy->setWidget(existingSubWidget);
379 bool shouldBeInsertable = !hasParent && subWidget;
380 if (shouldBeInsertable)
385 "QGraphicsProxyWidget::setWidget: cannot embed widget .* which is not a toplevel widget, and is not a child of an embedded widget"));
387 proxy->setWidget(subWidget);
389 if (shouldBeInsertable) {
419 qreal rleft, rtop, rright, rbottom;
420 proxy->getContentsMargins(&rleft, &rtop, &rright, &rbottom);
447 if (shouldBeInsertable)
449 delete existingSubWidget;
450 if (!shouldBeInsertable) {
458 void tst_QGraphicsProxyWidget::testEventFilter_data()
460 QTest::addColumn<QEvent::Type>(
"eventType");
461 QTest::addColumn<bool>(
"fromObject");
463 for (
int i = 0;
i < 2; ++
i) {
464 bool fromObject = (
i == 0);
465 const char fromObjectC = fromObject ?
'1' :
'0';
478 void tst_QGraphicsProxyWidget::testEventFilter()
485 qApp->sendEvent(&
scene, &windowActivate);
510 proxy->resize(newSize);
521 proxy->setPos(newPoint);
553 proxy->setEnabled(
false);
599 void tst_QGraphicsProxyWidget::focusInEvent_data()
601 QTest::addColumn<bool>(
"widgetHasFocus");
602 QTest::addColumn<bool>(
"widgetCanHaveFocus");
611 void tst_QGraphicsProxyWidget::focusInEvent()
616 QSKIP(
"Broken test.");
620 QFETCH(
bool, widgetHasFocus);
621 QFETCH(
bool, widgetCanHaveFocus);
625 qApp->sendEvent(&
scene, &windowActivate);
628 proxy->setEnabled(
true);
633 if (widgetCanHaveFocus)
653 void tst_QGraphicsProxyWidget::focusInEventNoWidget()
658 proxy->setEnabled(
true);
669 void tst_QGraphicsProxyWidget::focusNextPrevChild_data()
671 QTest::addColumn<bool>(
"hasWidget");
672 QTest::addColumn<bool>(
"hasScene");
673 QTest::addColumn<bool>(
"next");
674 QTest::addColumn<bool>(
"focusNextPrevChild");
676 for (
int i = 0;
i < 2; ++
i) {
677 for (
int j = 0;
j < 2; ++
j) {
678 for (
int k = 0; k < 2; ++k) {
679 bool next = (
i == 0);
680 bool hasWidget = (
j == 0);
681 bool hasScene = (k == 0);
682 bool result = hasScene && hasWidget;
684 +
", hasWidget: " + (hasWidget ?
'1' :
'0') +
", hasScene: "
685 + (hasScene ?
'1' :
'0') +
", result: " + (
result ?
'1' :
'0');
693 void tst_QGraphicsProxyWidget::focusNextPrevChild()
696 QFETCH(
bool, focusNextPrevChild);
705 auto *
proxy = proxyGuard.get();
712 <meta name=\"qrichtext\" content=\"1\" />
713 <style type=\"text/css\">
714 p, li { white-space: pre-wrap; }
719 <a href=\"http://www.slashdot.org\">
720 <span style=\" text-decoration: underline; color:#0000ff;\">old</span>
722 <a href=\"http://www.reddit.org\">
723 <span style=\" text-decoration: underline; color:#0000ff;\">new</span>
743 if (!(hasWidget && hasScene)) {
756 void tst_QGraphicsProxyWidget::focusOutEvent_data()
758 QTest::addColumn<bool>(
"hasWidget");
759 QTest::addColumn<bool>(
"call");
760 QTest::newRow(
"no widget, focus to other widget") <<
false <<
false;
762 QTest::newRow(
"widget, focus to other widget") <<
true <<
false;
767 void tst_QGraphicsProxyWidget::focusOutEvent()
778 view.activateWindow();
784 std::unique_ptr<QWidget> widgetGuard(
new QWidget);
788 proxy->setWidget(widgetGuard.release());
792 QEXPECT_FAIL(
"widget, focus to other widget",
"Widget should have focus but doesn't",
Continue);
808 void tst_QGraphicsProxyWidget::focusProxy_QTBUG_51856()
818 switch (
event->type()) {
838 view.activateWindow();
841 FocusedSpinBox *
spinBox =
new FocusedSpinBox;
854 for (
int i = 0;
i < Count; ++
i) {
855 for (
int clickCount = 0; clickCount < Count; ++clickCount) {
856 auto proxyCenter =
proxy->boundingRect().center();
857 auto proxyCenterInScene =
proxy->mapToScene(proxyCenter);
858 auto proxyCenterInView =
view.mapFromScene(proxyCenterInScene);
900 event->setAccepted(
true);
915 switch (
event->type()) {
932 void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent_data()
934 QTest::addColumn<bool>(
"hasWidget");
935 QTest::addColumn<bool>(
"hoverEnabled");
943 void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent()
946 QFETCH(
bool, hoverEnabled);
957 std::unique_ptr<EventLogger> widgetGuard(
new EventLogger);
962 view.resize(100, 100);
964 proxy->setWidget(widgetGuard.release());
965 proxy->setPos(50, 0);
980 QCOMPARE(
widget->hoverEnter, (hasWidget && hoverEnabled) ? 1 : 0);
991 void tst_QGraphicsProxyWidget::keyPressEvent_data()
993 QTest::addColumn<bool>(
"hasWidget");
999 void tst_QGraphicsProxyWidget::keyPressEvent()
1006 view.viewport()->setFocus();
1014 std::unique_ptr<QLineEdit> widgetGuard(
new QLineEdit);
1017 view.resize(100, 100);
1019 proxy->setWidget(widgetGuard.release());
1023 proxy->setPos(50, 0);
1026 QTest::keyPress(
view.viewport(),
'x');
1031 void tst_QGraphicsProxyWidget::keyReleaseEvent_data()
1033 QTest::addColumn<bool>(
"hasWidget");
1039 void tst_QGraphicsProxyWidget::keyReleaseEvent()
1053 std::unique_ptr<QPushButton> widgetGuard(
new QPushButton);
1055 widgetGuard->resize(50, 50);
1056 view.resize(100, 100);
1058 proxy->setWidget(widgetGuard.release());
1061 proxy->setPos(50, 0);
1072 void tst_QGraphicsProxyWidget::mouseDoubleClickEvent()
1084 proxy->setPos(50, 0);
1089 view.resize(100, 100);
1098 QPoint pointInLineEdit =
view.mapFromScene(
proxy->mapToScene(15,
proxy->boundingRect().center().y()));
1106 void tst_QGraphicsProxyWidget::mousePressReleaseEvent_data()
1108 QTest::addColumn<bool>(
"hasWidget");
1114 void tst_QGraphicsProxyWidget::mousePressReleaseEvent()
1120 view.resize(500, 500);
1126 std::unique_ptr<QPushButton> widgetGuard(
new QPushButton);
1128 widgetGuard->resize(50, 50);
1130 proxy->setWidget(widgetGuard.release());
1131 proxy->setPos(50, 0);
1146 void tst_QGraphicsProxyWidget::resizeEvent_data()
1148 QTest::addColumn<bool>(
"hasWidget");
1154 void tst_QGraphicsProxyWidget::resizeEvent()
1163 QSize newSize(100, 100);
1165 event.setOldSize(
QSize(10, 10));
1166 event.setNewSize(newSize);
1172 void tst_QGraphicsProxyWidget::paintEvent()
1196 proxy.paintCount = 0;
1202 #if QT_CONFIG(wheelevent)
1203 void tst_QGraphicsProxyWidget::wheelEvent()
1210 WheelWidget *wheelWidget =
new WheelWidget();
1211 wheelWidget->setFixedSize(400, 400);
1214 proxy->setVisible(
true);
1217 event.setScenePos(
QPoint(50, 50));
1218 event.setAccepted(
false);
1219 wheelWidget->wheelEventCalled =
false;
1224 QVERIFY(wheelWidget->wheelEventCalled);
1228 void tst_QGraphicsProxyWidget::sizePolicy()
1230 for (
int p = 0;
p < 2; ++
p) {
1231 bool hasWidget = (
p == 0);
1233 std::unique_ptr<QWidget> widgetGuard(
new QWidget);
1236 proxy.setSizePolicy(proxyPol);
1243 proxy.setWidget(widgetGuard.release());
1250 proxy.setSizePolicy(widgetPol);
1259 void tst_QGraphicsProxyWidget::minimumSize()
1262 std::unique_ptr<QWidget> widgetGuard(
new QWidget);
1263 QSize minSize(50, 50);
1264 widgetGuard->setMinimumSize(minSize);
1265 proxy.resize(30, 30);
1266 widgetGuard->resize(30,30);
1268 proxy.setWidget(widgetGuard.release());
1271 proxy.widget()->setMinimumSize(70, 70);
1276 void tst_QGraphicsProxyWidget::maximumSize()
1279 std::unique_ptr<QWidget> widgetGuard(
new QWidget);
1280 QSize maxSize(150, 150);
1281 widgetGuard->setMaximumSize(maxSize);
1282 proxy.resize(200, 200);
1283 widgetGuard->resize(200,200);
1285 proxy.setWidget(widgetGuard.release());
1288 proxy.widget()->setMaximumSize(70, 70);
1347 void tst_QGraphicsProxyWidget::scrollUpdate()
1375 void tst_QGraphicsProxyWidget::setWidget_simple()
1395 #ifndef QT_NO_CURSOR
1405 void tst_QGraphicsProxyWidget::setWidget_ownership()
1423 proxy.setWidget(lineEdit2);
1439 void tst_QGraphicsProxyWidget::resize_simple_data()
1441 QTest::addColumn<QSizeF>(
"size");
1444 #if !defined(Q_PROCESSOR_ARM)
1451 void tst_QGraphicsProxyWidget::resize_simple()
1474 void tst_QGraphicsProxyWidget::symmetricMove()
1481 proxy.setPos(10, 10);
1490 void tst_QGraphicsProxyWidget::symmetricResize()
1497 proxy.resize(256, 256);
1506 void tst_QGraphicsProxyWidget::symmetricVisible()
1525 void tst_QGraphicsProxyWidget::symmetricEnabled()
1533 proxy.setEnabled(
false);
1535 proxy.setEnabled(
true);
1543 void tst_QGraphicsProxyWidget::tabFocus_simpleWidget()
1623 void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets()
1747 void tst_QGraphicsProxyWidget::tabFocus_complexWidget()
1752 edit1->
setText(
"QLineEdit 1");
1754 edit2->
setText(
"QLineEdit 2");
1760 box->setCheckable(
true);
1761 box->setChecked(
true);
1762 box->setLayout(vlayout);
1859 void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets()
1865 edit1->
setText(
"QLineEdit 1");
1867 edit2->
setText(
"QLineEdit 2");
1875 box->setCheckable(
true);
1876 box->setChecked(
true);
1877 box->setLayout(vlayout);
1880 edit1_2->
setText(
"QLineEdit 1_2");
1882 edit2_2->
setText(
"QLineEdit 2_2");
1898 proxy_2->
setPos(
proxy->boundingRect().width() * 1.2, 0);
1906 view->scale(0.5, 0.5);
1929 EventSpy eventSpy2_3(fontComboBox2);
2071 void tst_QGraphicsProxyWidget::setFocus_simpleWidget()
2139 void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets()
2191 void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets()
2197 edit1->
setText(
"QLineEdit 1");
2199 edit2->
setText(
"QLineEdit 2");
2205 box->setCheckable(
true);
2206 box->setChecked(
true);
2207 box->setLayout(vlayout);
2210 edit1_2->
setText(
"QLineEdit 1_2");
2212 edit2_2->
setText(
"QLineEdit 2_2");
2226 proxy_2->
setPos(
proxy->boundingRect().width() * 1.2, 0);
2312 void tst_QGraphicsProxyWidget::popup_basic()
2314 std::unique_ptr<QComboBox> boxGuard(
new QComboBox);
2317 opt.editable = boxGuard->isEditable();
2319 QSKIP(
"Does not work due to SH_Combobox_Popup");
2325 view.setGeometry(0, 100, 480, 500);
2330 box->setGeometry(0, 0, 320, 40);
2331 box->addItems(
QStringList() <<
"monday" <<
"tuesday" <<
"wednesday"
2332 <<
"thursday" <<
"saturday" <<
"sunday");
2334 proxy->setWidget(boxGuard.release());
2346 view.mapFromScene(
proxy->mapToScene(
proxy->boundingRect().center())));
2369 void tst_QGraphicsProxyWidget::popup_subwidget()
2376 box->addItems(
QStringList() <<
"monday" <<
"tuesday" <<
"wednesday"
2377 <<
"thursday" <<
"saturday" <<
"sunday");
2402 opt.editable =
box->isEditable();
2404 QSKIP(
"Does not work due to SH_Combobox_Popup");
2413 void tst_QGraphicsProxyWidget::changingCursor_basic()
2415 #if !QT_CONFIG(cursor)
2416 QSKIP(
"This test requires the QCursor API");
2442 static bool findViewAndTipLabel(
const QWidget *
view)
2444 bool foundView =
false;
2445 bool foundTipLabel =
false;
2451 foundTipLabel =
true;
2452 if (foundView && foundTipLabel)
2458 void tst_QGraphicsProxyWidget::tooltip_basic()
2460 QString toolTip =
"Qt rocks!";
2461 QString toolTip2 =
"Qt rocks even more!";
2472 proxy->setToolTip(toolTip);
2476 button->setToolTip(toolTip2);
2484 view.setFixedSize(200, 200);
2490 view.viewport()->mapToGlobal(
view.viewport()->rect().topLeft()));
2494 bool foundView =
false;
2495 bool foundTipLabel =
false;
2500 foundTipLabel =
true;
2508 view.viewport()->mapToGlobal(
view.mapFromScene(
proxy->boundingRect().center())));
2514 void tst_QGraphicsProxyWidget::childPos_data()
2516 QTest::addColumn<bool>(
"moveCombo");
2517 QTest::addColumn<QPoint>(
"comboPos");
2518 QTest::addColumn<QPointF>(
"proxyPos");
2540 void tst_QGraphicsProxyWidget::childPos()
2549 box.addItem(
"Item 1");
2550 box.addItem(
"Item 2");
2551 box.addItem(
"Item 3");
2552 box.addItem(
"Item 4");
2563 proxy->setPos(proxyPos);
2568 for (
int i = 0;
i < 2; ++
i) {
2580 qreal expectedXPosition = 0.0;
2585 expectedXPosition =
qreal(4 - 11);
2592 void tst_QGraphicsProxyWidget::autoShow()
2613 void tst_QGraphicsProxyWidget::windowOpacity()
2628 qRegisterMetaType<QList<QRectF> >(
"QList<QRectF>");
2655 void tst_QGraphicsProxyWidget::stylePropagation()
2680 proxy.setStyle(windowsStyle);
2691 delete windowsStyle;
2694 void tst_QGraphicsProxyWidget::palettePropagation()
2742 void tst_QGraphicsProxyWidget::fontPropagation()
2792 proxy.setWidget(edit2);
2825 void tst_QGraphicsProxyWidget::dontCrashWhenDie()
2831 QTest::mouseMove(
w->view->viewport(),
w->view->mapFromScene(
w->widget->mapToScene(
w->widget->boundingRect().center())));
2840 void tst_QGraphicsProxyWidget::dontCrashNoParent()
2849 parent->setWidget(label0.data());
2851 parent->setWidget(label1.data());
2854 void tst_QGraphicsProxyWidget::createProxyForChildWidget()
2859 edit1->
setText(
"QLineEdit 1");
2861 edit2->
setText(
"QLineEdit 2");
2871 box->setCheckable(
true);
2872 box->setChecked(
true);
2873 box->setLayout(vlayout);
2891 view.resize(500,500);
2903 QCOMPARE(checkboxProxy->parentItem(), boxProxy);
2922 view.mapFromScene(checkboxProxy->mapToScene(
QPointF(8,8))));
2925 view.mapFromScene(checkboxProxy->mapToScene(
QPointF(8,8))));
2939 #ifndef QT_NO_CONTEXTMENU
2948 , m_embeddedPopupSet(
false)
2958 m_timer =
new QTimer(
this);
2975 if (!m_embeddedPopupSet) {
2976 m_embeddedPopupSet =
true;
2985 bool m_embeddedPopupSet;
2990 void tst_QGraphicsProxyWidget::actionsContextMenu_data()
2992 QTest::addColumn<bool>(
"actionsContextMenu");
2993 QTest::addColumn<bool>(
"hasFocus");
2995 QTest::newRow(
"without actionsContextMenu and with focus") <<
false <<
true;
2996 QTest::newRow(
"without actionsContextMenu and without focus") <<
false <<
false;
2997 QTest::newRow(
"with actionsContextMenu and focus") <<
true <<
true;
2998 QTest::newRow(
"with actionsContextMenu without focus") <<
true <<
false;
3001 #ifndef QT_NO_CONTEXTMENU
3002 void tst_QGraphicsProxyWidget::actionsContextMenu()
3005 QFETCH(
bool, actionsContextMenu);
3008 if (actionsContextMenu) {
3018 view.resize(200, 200);
3034 view.viewport()->rect().center(),
3035 view.viewport()->mapToGlobal(
view.viewport()->rect().center()));
3036 contextMenuEvent.accept();
3037 qApp->sendEvent(
view.viewport(), &contextMenuEvent);
3040 if (actionsContextMenu) {
3058 void tst_QGraphicsProxyWidget::deleteProxyForChildWidget()
3068 combo->
addItems(
QStringList() <<
"red" <<
"green" <<
"blue" <<
"white" <<
"black" <<
"yellow" <<
"cyan" <<
"magenta");
3075 proxy->setWidget(0);
3081 void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget_data()
3083 QTest::addColumn<bool>(
"bypass");
3089 void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget()
3093 std::unique_ptr<QWidget> widgetGuard(
new QWidget);
3108 Qt::WindowFlags
flags;
3127 event->setScenePos(
pos);
3128 event->setScreenPos(
view->mapToGlobal(
view->mapFromScene(
pos)));
3130 event->setModifiers({});
3134 event->setWidget(
view->viewport());
3135 event->setSource(
view->viewport());
3139 void tst_QGraphicsProxyWidget::dragDrop()
3158 data.setText(
"hei");
3162 event.setMimeData(&
data);
3169 event.setMimeData(&
data);
3176 event.setMimeData(&
data);
3183 event.setMimeData(&
data);
3190 void tst_QGraphicsProxyWidget::windowFlags_data()
3192 QTest::addColumn<int>(
"proxyFlags");
3193 QTest::addColumn<int>(
"widgetFlags");
3194 QTest::addColumn<int>(
"resultingProxyFlags");
3195 QTest::addColumn<int>(
"resultingWidgetFlags");
3203 void tst_QGraphicsProxyWidget::windowFlags()
3206 QFETCH(
int, widgetFlags);
3207 QFETCH(
int, resultingProxyFlags);
3208 QFETCH(
int, resultingWidgetFlags);
3209 Qt::WindowFlags proxyWFlags = Qt::WindowFlags(proxyFlags);
3210 Qt::WindowFlags widgetWFlags = Qt::WindowFlags(widgetFlags);
3211 Qt::WindowFlags resultingProxyWFlags = Qt::WindowFlags(resultingProxyFlags);
3212 Qt::WindowFlags resultingWidgetWFlags = Qt::WindowFlags(resultingWidgetFlags);
3215 QVERIFY((
proxy.windowFlags() & proxyWFlags) == proxyWFlags);
3222 if (resultingProxyFlags == 0)
3225 QVERIFY((
proxy.windowFlags() & resultingProxyWFlags) == resultingProxyWFlags);
3229 void tst_QGraphicsProxyWidget::comboboxWindowFlags()
3235 QWidget *embedWidget = comboBox;
3251 void tst_QGraphicsProxyWidget::updateAndDelete()
3254 QSKIP(
"Test case unstable on this platform, QTBUG-23700");
3265 const QRect itemDeviceBoundingRect =
proxy->deviceTransform(
view.viewportTransform())
3266 .mapRect(
proxy->boundingRect()).toRect();
3267 const QRegion expectedRegion = itemDeviceBoundingRect.
adjusted(-2, -2, 2, 2);
3302 void tst_QGraphicsProxyWidget::inputMethod()
3307 for (
int i = 0;
i < 2; ++
i)
3316 for (
int i = 0;
i < 2; ++
i)
3347 void tst_QGraphicsProxyWidget::clickFocus()
3360 view.setFrameStyle(0);
3361 view.resize(300, 300);
3376 for (
int retry = 0; retry < 50 && !
proxy->hasFocus(); retry++)
3392 event.setScenePos(lineEditCenter);
3418 event.setScenePos(lineEditCenter);
3453 void tst_QGraphicsProxyWidget::windowFrameMargins()
3471 proxy->unsetWindowFrameMargins();
3476 void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget()
3481 bool hoverLeaveReceived =
false;
3486 hoverLeaveReceived =
true;
3494 HoverButton *hoverButton =
new HoverButton(background);
3495 hoverButton->setText(
"Second button");
3496 hoverButton->setGeometry(10, 10, 200, 50);
3506 view.resize(600, 600);
3514 QCOMPARE(hoverButton->hoverLeaveReceived,
false);
3526 QDebug(&
result) << actual <<
" != " << expected <<
" manhattanLength="
3527 << (expected - actual).manhattanLength();
3528 return result.toLocal8Bit();
3531 void tst_QGraphicsProxyWidget::mapToGlobal()
3548 childWidget->
resize(embeddedWidget->
size() / 2);
3549 childWidget->
move(embeddedWidget->
width() / 4, embeddedWidget->
height() / 4);
3555 const QPoint embeddedCenterGlobal = embeddedWidget->
mapToGlobal(embeddedCenter);
3559 const QPoint viewCenter =
view.geometry().center();
3560 QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= 3,
3561 msgPointMismatch(embeddedCenterGlobal, viewCenter).constData());
3570 QVERIFY2((viewCenter - childCenterGlobal).manhattanLength() <= 4,
3571 msgPointMismatch(childCenterGlobal, viewCenter).constData());
3574 void tst_QGraphicsProxyWidget::mapToGlobalWithoutScene()
3579 const QPoint localPos(0, 0);
3587 void tst_QGraphicsProxyWidget::QTBUG_43780_visibility()
3603 availableGeometry.
height() -
size.height()) / 2);
3627 switch (
event->type()) {
3641 #if QT_CONFIG(wheelevent)
3654 void tst_QGraphicsProxyWidget::wheelEventPropagation()
3659 label->setFixedSize(300, 30);
3661 labelProxy->
setPos(0, 50);
3664 class NestedWidget :
public QWidget
3676 int wheelEventCount = 0;
3678 void wheelEvent(QWheelEvent *)
override
3683 NestedWidget *nestedWidget =
new NestedWidget(
"Nested");
3684 nestedWidget->setFixedSize(300, 60);
3686 nestedProxy->
setPos(0, 120);
3687 nestedProxy->
show();
3690 view.setFixedHeight(200);
3696 view.verticalScrollBar()->setValue(0);
3699 const QPoint wheelPosition(50, 25);
3702 const QPoint pixelDelta(0, -25);
3703 const QPoint angleDelta(0, -120);
3710 int scrollCount = 0;
3715 QCOMPARE(scrollSpy.count(), ++scrollCount);
3720 QCOMPARE(scrollSpy.count(), ++scrollCount);
3723 QCOMPARE(scrollSpy.count(), ++scrollCount);
3728 QCOMPARE(scrollSpy.count(), ++scrollCount);
3733 const int scrollBarValueOnNestedProxy =
view.verticalScrollBar()->value();
3735 QCOMPARE(scrollSpy.count(), scrollCount);
3736 QCOMPARE(nestedWidget->wheelEventCount, 1);
3739 view.verticalScrollBar()->setValue(0);
3746 QCOMPARE(scrollSpy.count(), ++scrollCount);
3747 for (
int i = 0;
i < 5; ++
i) {
3749 QCOMPARE(scrollSpy.count(), ++scrollCount);
3752 QCOMPARE(scrollSpy.count(), ++scrollCount);
3755 view.verticalScrollBar()->setValue(0);
3756 scrollCount = scrollSpy.count();
3761 scrollCount = scrollSpy.count();
3765 QCOMPARE(scrollSpy.count(), ++scrollCount);
3766 for (
int i = 0;
i < 5; ++
i) {
3768 QCOMPARE(scrollSpy.count(), ++scrollCount);
3771 QCOMPARE(scrollSpy.count(), ++scrollCount);
3775 view.verticalScrollBar()->setValue(scrollBarValueOnNestedProxy);
3776 scrollCount = scrollSpy.count();
3780 QCOMPARE(scrollSpy.count(), scrollCount);
3785 void tst_QGraphicsProxyWidget::forwardTouchEvent()
3793 proxy->setAcceptTouchEvents(
true);
3820 void tst_QGraphicsProxyWidget::touchEventPropagation()
3859 view.verticalScrollBar()->setValue(0);
3860 view.horizontalScrollBar()->setValue(0);
3861 view.viewport()->setObjectName(
"GraphicsView's Viewport");
3865 class TouchEventSpy :
public QObject
3870 struct TouchRecord {
3876 QWidget *mousePressReceiver =
nullptr;
3878 int count(
int id = 0)
const {
return records.
value(
id).count(); }
3879 TouchRecord
at(
int i,
int id = 0)
const {
return records.
value(
id).at(
i); }
3883 mousePressReceiver =
nullptr;
3888 switch (
event->type()) {
3896 records[touchPoint.id()] << TouchRecord{receiver,
event->type(), touchPoint.position()};
3897 qCDebug(lcTests) <<
"Recording" <<
event << receiver;
3909 qApp->installEventFilter(&eventSpy);
3916 constexpr
auto closeEnough = [](
QPointF exp,
QPointF act) ->
bool {
3918 const bool contains = expArea.contains(act);
3920 qWarning() << act <<
"not in" << exp;
3928 QCOMPARE(eventSpy.at(0).receiver,
view.windowHandle());
3931 QCOMPARE(eventSpy.at(3).receiver, simpleProxy);
3932 auto record = eventSpy.at(4);
3951 const QPoint pb1TouchPos = pushButton1->
pos() + pb1Center + formProxyPox;
3952 const QPoint pb2TouchPos = pushButton2->
pos() + pb2Center + formProxyPox;
3953 const QPoint tw1TouchPos = touchWidget1->
pos() + tw1Center + formProxyPox;
3954 const QPoint tw2TouchPos = touchWidget2->
pos() + tw2Center + formProxyPox;
3965 QCOMPARE(eventSpy.at(3).receiver, formProxy);
3981 QCOMPARE(eventSpy.mousePressReceiver, pushButton1);
3994 QCOMPARE(eventSpy.at(3).receiver, formProxy);
3999 QCOMPARE(eventSpy.at(5).receiver,
view.windowHandle());
4004 QCOMPARE(eventSpy.at(7).receiver,
view.windowHandle());
4012 qApp->removeEventFilter(&eventSpy);
4021 .
press(0, pb1TouchPos)
4022 .
press(1, tw1TouchPos)
4023 .
press(2, pb2TouchPos)
4024 .
press(3, tw2TouchPos);
4040 QCOMPARE(eventSpy.at(0, 0).receiver, pushButton1);
4041 QCOMPARE(eventSpy.at(1, 0).receiver, formWidget);
4042 QCOMPARE(eventSpy.at(0, 1).receiver, touchWidget1);
4043 QCOMPARE(eventSpy.at(1, 1).receiver, touchWidget1);
4044 QCOMPARE(eventSpy.at(2, 1).receiver, touchWidget1);
4045 QCOMPARE(eventSpy.at(0, 2).receiver, pushButton2);
4046 QCOMPARE(eventSpy.at(1, 2).receiver, formWidget);
4047 QCOMPARE(eventSpy.at(0, 3).receiver, touchWidget2);
4048 QCOMPARE(eventSpy.at(1, 3).receiver, touchWidget2);
4049 QCOMPARE(eventSpy.at(2, 3).receiver, touchWidget2);
4054 #include "tst_qgraphicsproxywidget.moc"
small capitals from c petite p scientific i
[1]
void leaveEvent(QEvent *event) override
bool eventFilter(QObject *object, QEvent *event) override
void enterEvent(QEnterEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
QMap< QEvent::Type, int > counts
bool eventFilter(QObject *, QEvent *event) override
EventSpy(QObject *receiver)
QGraphicsLinearLayout * layout
QGraphicsProxyWidget * widget
void valueChanged(int value)
The QAction class provides an abstraction for user commands that can be added to different user inter...
static QPalette palette()
static QWidget * focusWidget()
static QWidgetList topLevelWidgets()
static void setEffectEnabled(Qt::UIEffect, bool enable=true)
static QWidget * activeWindow()
static void setActiveWindow(QWidget *act)
void insertStretch(int index, int stretch=0)
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
The QByteArray class provides an array of bytes.
The QCheckBox widget provides a checkbox with a text label.
The QColor class provides colors based on RGB, HSV or CMYK values.
The QComboBox widget is a combined button and popup list.
QAbstractItemView * view() const
void addItem(const QString &text, const QVariant &userData=QVariant())
void addItems(const QStringList &texts)
static bool sendEvent(QObject *receiver, QEvent *event)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
[95]
Qt::CursorShape shape() const
The QDebug class provides an output stream for debugging information.
The QDial class provides a rounded range control (like a speedometer or potentiometer).
The QDialog class is the base class of dialog windows.
The QEnterEvent class contains parameters that describe an enter event.
The QEvent class is the base class of all event classes. Event objects contain event parameters.
@ GraphicsSceneMousePress
The QFileDialog class provides a dialog that allow users to select files or directories....
void setOption(Option option, bool on=true)
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
The QFontComboBox widget is a combobox that lets the user select a font family.
The QFont class specifies a query for a font used for drawing text.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
QList< QGraphicsItem * > childItems() const
void setPos(const QPointF &pos)
QGraphicsItem * parentItem() const
void setAcceptTouchEvents(bool enabled)
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void addItem(QGraphicsLayoutItem *item)
QPointF pos
the position of the item
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
void addItem(QGraphicsItem *item)
void changed(const QList< QRectF > ®ion)
QGraphicsProxyWidget * addWidget(QWidget *widget, Qt::WindowFlags wFlags=Qt::WindowFlags())
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
QRectF sceneRect
the scene rectangle; the bounding rectangle of the scene
QRectF itemsBoundingRect() const
void setItemIndexMethod(ItemIndexMethod method)
void setSceneRect(const QRectF &rect)
void render(QPainter *painter, const QRectF &target=QRectF(), const QRectF &source=QRectF(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio)
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display form...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
void paintEvent(QPaintEvent *event) override
void setScene(QGraphicsScene *scene)
The QGroupBox widget provides a group box frame with a title.
void setChecked(bool checked)
void setCheckable(bool checkable)
void setTitle(const QString &title)
QScreen * primaryScreen
the primary (or default) screen of the application.
QString platformName
The name of the underlying platform plugin.
The QHBoxLayout class lines up widgets horizontally.
The QHash class is a template class that provides a hash-table-based dictionary.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
The QHelpEvent class provides an event that is used to request helpful information about a particular...
The QHideEvent class provides an event which is sent after a widget is hidden.
The QKeyEvent class describes a key event.
The QLabel widget provides a text or image display.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
void addWidget(QWidget *w)
virtual QRect geometry() const =0
virtual QWidget * widget() const
The QLineEdit widget is a one-line text editor.
QSize minimumSizeHint() const override
bool event(QEvent *) override
void setText(const QString &)
void setEchoMode(EchoMode)
QString text
the line edit's text.
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
The QMainWindow class provides a main application window.\inmodule QtWidgets.
void setCentralWidget(QWidget *widget)
The QMarginsF class defines the four margins of a rectangle.
constexpr qreal right() const noexcept
constexpr qreal left() const noexcept
constexpr qreal top() const noexcept
constexpr qreal bottom() const noexcept
The QMimeData class provides a container for data that records information about its MIME type.
The QMouseEvent class contains parameters that describe a mouse event.
QNetworkProxy::ProxyType type() const
The QObject class is the base class of all Qt objects.
Q_INVOKABLE QObject(QObject *parent=nullptr)
void installEventFilter(QObject *filterObj)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
virtual bool event(QEvent *event)
virtual bool eventFilter(QObject *watched, QEvent *event)
void setObjectName(const QString &name)
bool inherits(const char *classname) const
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
The QPainter class performs low-level painting on widgets and other paint devices.
RenderHints renderHints() const
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(const QRectF &, const QBrush &)
The QPalette class contains color groups for each widget state.
const QColor & color(ColorGroup cg, ColorRole cr) const
The QPixmap class is an off-screen image representation that can be used as a paint device.
The QPointF class defines a point in the plane using floating point precision.
constexpr qreal x() const noexcept
constexpr QPoint toPoint() const
The QPoint class defines a point in the plane using integer precision.
The QPointer class is a template class that provides guarded pointers to QObject.
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
The QRectF class defines a finite rectangle in the plane using floating point precision.
constexpr qreal height() const noexcept
constexpr qreal width() const noexcept
constexpr QPointF center() const noexcept
constexpr QRect toRect() const noexcept
The QRect class defines a rectangle in the plane using integer precision.
constexpr int height() const noexcept
constexpr int bottom() const noexcept
constexpr QPoint topLeft() const noexcept
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
constexpr QSize size() const noexcept
constexpr QPoint bottomRight() const noexcept
constexpr int width() const noexcept
constexpr QPoint center() const noexcept
The QRegion class specifies a clip region for a painter.
The QRegularExpression class provides pattern matching using regular expressions.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QRect availableGeometry
the screen's available geometry in pixels
The QShowEvent class provides an event that is sent when a widget is shown.
The QSizeF class defines the size of a two-dimensional object using floating point precision.
constexpr QSize toSize() const noexcept
The QSize class defines the size of a two-dimensional object using integer point precision.
constexpr QSize expandedTo(const QSize &) const noexcept
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
The QSpinBox class provides a spin box widget.
bool event(QEvent *event) override
The QString class provides a Unicode character string.
static QStyle * create(const QString &)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
an OR combination of the tool button's features
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
void initFrom(const QWidget *w)
QTouchEventSequence & move(int touchId, const QPoint &pt, QWindow *window=nullptr)
QMap< int, QEventPoint > points
QTouchEventSequence & press(int touchId, const QPoint &pt, QWindow *window=nullptr)
QTouchEventSequence & release(int touchId, const QPoint &pt, QWindow *window=nullptr)
The QTimer class provides repetitive and single-shot timers.
void setInterval(int msec)
bool singleShot
whether the timer is a single-shot timer
The QTouchEvent class contains parameters that describe a touch event.
The QVBoxLayout class lines up widgets vertically.
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
View(QGraphicsScene *scene, QWidget *parent=nullptr)
void paintEvent(QPaintEvent *event) override
qDeleteAll(list.begin(), list.end())
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)))
[0]
QList< QVariant > arguments
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Q_TESTLIB_EXPORT const char * currentTestFunction()
Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType=QInputDevice::DeviceType::TouchScreen, QInputDevice::Capabilities caps=QInputDevice::Capability::Position)
Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout=5000)
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
void mouseMove(QWindow *window, QPoint pos=QPoint(), int delay=-1)
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
void mouseDClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
void mouseRelease(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
void mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Q_CORE_EXPORT void qWait(int ms)
QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit=true)
@ AA_DontUseNativeDialogs
QTextStream & center(QTextStream &stream)
@ BypassGraphicsProxyWidget
MyMainWidget * mainWindow
#define QByteArrayLiteral(str)
QList< QString > QStringList
QT_END_INCLUDE_NAMESPACE typedef double qreal
Q_WIDGETS_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLuint GLsizei const GLchar * label
[43]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLint * box
#define QStringLiteral(str)
#define QTEST_MAIN(TestObject)
#define QSKIP(statement,...)
#define QFETCH(Type, name)
#define QEXPECT_FAIL(dataIndex, comment, mode)
#define QTRY_COMPARE(expr, expected)
#define QVERIFY(statement)
#define QTRY_VERIFY(expr)
#define QVERIFY2(statement, description)
QFileDialog dialog(this)
[1]