|
1 | 1 | from PyQt5.QtCore import Qt, QRectF, QPoint, QPointF |
2 | 2 | from PyQt5.QtGui import QBrush, QWheelEvent |
3 | | -from PyQt5.QtWidgets import QGraphicsScene, QWidget, QApplication |
| 3 | +from PyQt5.QtWidgets import QGraphicsScene, QWidget, QApplication, QStyle |
4 | 4 |
|
5 | 5 | from Orange.widgets.tests.base import GuiTest |
6 | 6 |
|
7 | 7 | from Orange.widgets.utils.stickygraphicsview import StickyGraphicsView |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class TestStickyGraphicsView(GuiTest): |
11 | | - def test(self): |
| 11 | + def create_view(self): |
12 | 12 | view = StickyGraphicsView() |
13 | 13 | scene = QGraphicsScene(view) |
14 | | - scene.setBackgroundBrush(QBrush(Qt.lightGray, Qt.CrossPattern)) |
15 | 14 | view.setScene(scene) |
| 15 | + return view |
| 16 | + |
| 17 | + def test(self): |
| 18 | + view = self.create_view() |
| 19 | + scene = view.scene() |
| 20 | + scene.setBackgroundBrush(QBrush(Qt.lightGray, Qt.CrossPattern)) |
16 | 21 | scene.addRect( |
17 | 22 | QRectF(0, 0, 300, 20), Qt.red, QBrush(Qt.red, Qt.BDiagPattern)) |
18 | 23 | scene.addRect(QRectF(0, 25, 300, 100)) |
@@ -48,6 +53,66 @@ def test(self): |
48 | 53 |
|
49 | 54 | qWheelScroll(header.viewport(), angleDelta=QPoint(0, -720 * 8)) |
50 | 55 |
|
| 56 | + @staticmethod |
| 57 | + def _ensure_laid_out(view: QWidget) -> None: |
| 58 | + """Ensure view has had pending resize events flushed.""" |
| 59 | + # when a widget is not visible it does not get resizeEvents dispatched |
| 60 | + # immediately, only before it is actually shown or its rendering is |
| 61 | + # requested. |
| 62 | + view.grab() |
| 63 | + |
| 64 | + def _test_visibility(self, view: StickyGraphicsView) -> None: |
| 65 | + header = view.headerView() |
| 66 | + footer = view.footerView() |
| 67 | + vsbar = view.verticalScrollBar() |
| 68 | + vsbar.triggerAction(vsbar.SliderToMinimum) |
| 69 | + self._ensure_laid_out(view) |
| 70 | + |
| 71 | + self.assertFalse(header.isVisibleTo(view)) |
| 72 | + self.assertTrue(footer.isVisibleTo(view)) |
| 73 | + |
| 74 | + vsbar.triggerAction(vsbar.SliderSingleStepAdd) |
| 75 | + self._ensure_laid_out(view) |
| 76 | + |
| 77 | + self.assertTrue(header.isVisibleTo(view)) |
| 78 | + self.assertTrue(footer.isVisibleTo(view)) |
| 79 | + |
| 80 | + vsbar.triggerAction(vsbar.SliderToMaximum) |
| 81 | + self._ensure_laid_out(view) |
| 82 | + |
| 83 | + self.assertTrue(header.isVisibleTo(view)) |
| 84 | + self.assertFalse(footer.isVisibleTo(view)) |
| 85 | + |
| 86 | + vsbar.triggerAction(vsbar.SliderSingleStepSub) |
| 87 | + self._ensure_laid_out(view) |
| 88 | + if not view.style().styleHint(QStyle.SH_ScrollBar_Transient, None, vsbar): |
| 89 | + # cannot reliably test due to QTBUG-65074 |
| 90 | + self.assertTrue(header.isVisibleTo(view)) |
| 91 | + self.assertTrue(footer.isVisibleTo(view)) |
| 92 | + |
| 93 | + def test_fractional_1(self): |
| 94 | + view = self.create_view() |
| 95 | + view.resize(300, 100) |
| 96 | + scenerect = QRectF(-0.1, -0.1, 300.2, 300.2) |
| 97 | + headerrect = QRectF(-0.1, -0.1, 300.2, 20.2) |
| 98 | + footerrect = QRectF(-0.1, 279.9, 300.2, 20.2) |
| 99 | + view.setSceneRect(scenerect) |
| 100 | + view.setHeaderSceneRect(headerrect) |
| 101 | + view.setFooterSceneRect(footerrect) |
| 102 | + self._test_visibility(view) |
| 103 | + |
| 104 | + def test_fractional_2(self): |
| 105 | + view = self.create_view() |
| 106 | + view.resize(300, 100) |
| 107 | + view.grab() |
| 108 | + scenerect = QRectF(0.1, 0.1, 300, 299.8) |
| 109 | + headerrect = QRectF(0.1, 0.1, 300, 20) |
| 110 | + footerrect = QRectF(0.1, 299.9 - 20, 300, 20) |
| 111 | + view.setSceneRect(scenerect) |
| 112 | + view.setHeaderSceneRect(headerrect) |
| 113 | + view.setFooterSceneRect(footerrect) |
| 114 | + self._test_visibility(view) |
| 115 | + |
51 | 116 |
|
52 | 117 | def qWheelScroll( |
53 | 118 | widget: QWidget, buttons=Qt.NoButton, modifiers=Qt.NoModifier, |
|
0 commit comments