- if (size.height() > screen.height()) {
- size.setHeight(screen.height());
- }
-
- // m_itemRect defines the area of the item, where the tooltip should be
- // shown. Per default the tooltip is shown centered at the bottom.
- // It must be assured that:
- // - the content is fully visible
- // - the content is not drawn inside m_itemRect
- const bool hasRoomToLeft = (m_itemRect.left() - size.width() - m_margin >= screen.left());
- const bool hasRoomToRight = (m_itemRect.right() + size.width() + m_margin <= screen.right());
- const bool hasRoomAbove = (m_itemRect.top() - size.height() - m_margin >= screen.top());
- const bool hasRoomBelow = (m_itemRect.bottom() + size.height() + m_margin <= screen.bottom());
- if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) {
- return;
- }
-
- int x, y;
- if (hasRoomBelow || hasRoomAbove) {
- x = qMax(screen.left(), m_itemRect.center().x() - size.width() / 2);
- if (x + size.width() >= screen.right()) {
- x = screen.right() - size.width() + 1;
- }
- if (hasRoomBelow) {
- y = m_itemRect.bottom() + m_margin;
- } else {
- y = m_itemRect.top() - size.height() - m_margin;
- }
- } else {
- Q_ASSERT(hasRoomToLeft || hasRoomToRight);
- if (hasRoomToRight) {
- x = m_itemRect.right() + m_margin;
- } else {
- x = m_itemRect.left() - size.width() - m_margin;
- }
- // Put the tooltip at the bottom of the screen. The x-coordinate has already
- // been adjusted, so that no overlapping with m_itemRect occurs.
- y = screen.bottom() - size.height() + 1;
- }
-
- // Step #3 - Alter tooltip geometry
- m_fileMetaDataToolTip->setFixedSize(size);
- m_fileMetaDataToolTip->layout()->setSizeConstraint(QLayout::SetNoConstraint);
- m_fileMetaDataToolTip->move(QPoint(x, y));
- m_fileMetaDataToolTip->show();
-