| 52 | } |
| 53 | |
| 54 | void ActiveToolTipManager::doVisibility() |
| 55 | { |
| 56 | bool exclusive = false; |
| 57 | int lastBottomPosition = -1; |
| 58 | int lastLeftPosition = -1; |
| 59 | QRect fullGeometry; //Geometry of all visible tooltips together |
| 60 | |
| 61 | for (auto it = registeredToolTips.constBegin(); it != registeredToolTips.constEnd(); ++it) { |
| 62 | QPointer<ActiveToolTip> w = (*it).first; |
| 63 | if (w) { |
| 64 | if (exclusive) { |
| 65 | (w.data())->hide(); |
| 66 | } else { |
| 67 | QRect geom = (w.data())->geometry(); |
| 68 | if ((w.data())->geometry().top() < lastBottomPosition) { |
| 69 | geom.moveTop(lastBottomPosition); |
| 70 | } |
| 71 | if (lastLeftPosition != -1) { |
| 72 | geom.moveLeft(lastLeftPosition); |
| 73 | } |
| 74 | |
| 75 | (w.data())->setGeometry(geom); |
| 76 | |
| 77 | lastBottomPosition = (w.data())->geometry().bottom(); |
| 78 | lastLeftPosition = (w.data())->geometry().left(); |
| 79 | |
| 80 | if (it == registeredToolTips.constBegin()) { |
| 81 | fullGeometry = (w.data())->geometry(); |
| 82 | } else { |
| 83 | fullGeometry = fullGeometry.united((w.data())->geometry()); |
| 84 | } |
| 85 | } |
| 86 | if (it.key() == 0) { |
| 87 | exclusive = true; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (!fullGeometry.isEmpty()) { |
| 93 | QRect oldFullGeometry = fullGeometry; |
| 94 | const auto *screen = QGuiApplication::screenAt(fullGeometry.topLeft()); |
| 95 | if (!screen) { |
| 96 | screen = qApp->primaryScreen(); |
| 97 | qWarning() << "failed to find screen:" << fullGeometry << "fallback primary geometry:" << screen->geometry(); |
| 98 | } |
| 99 | QRect screenGeometry = screen->geometry(); |
| 100 | if (fullGeometry.bottom() > screenGeometry.bottom()) { |
| 101 | //Move up, avoiding the mouse-cursor |
| 102 | fullGeometry.moveBottom(fullGeometry.top() - 10); |
| 103 | if (fullGeometry.adjusted(-20, -20, 20, 20).contains(QCursor::pos())) { |
| 104 | fullGeometry.moveBottom(QCursor::pos().y() - 20); |
| 105 | } |
| 106 | } |
| 107 | if (fullGeometry.right() > screenGeometry.right()) { |
| 108 | //Move to left, avoiding the mouse-cursor |
| 109 | fullGeometry.moveRight(fullGeometry.left() - 10); |
| 110 | if (fullGeometry.adjusted(-20, -20, 20, 20).contains(QCursor::pos())) { |
| 111 | fullGeometry.moveRight(QCursor::pos().x() - 20); |
nothing calls this directly
no test coverage detected