From ce9038f6a2f9233c8dcc0df61a7f2b38334c0780 Mon Sep 17 00:00:00 2001
From: Leandro Melo <leandro.melo@nokia.com>
Date: Wed, 15 Sep 2010 12:42:15 +0200
Subject: [PATCH] Avoid function completion tootltip to go out of the screen.

Task-number: QTCREATORBUG-2307
Reviewed-by: Thorbjorn Lindeijer
---
 src/plugins/cpptools/cppcodecompletion.cpp | 23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 45125a14533..32a51d7f2cc 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -105,6 +105,7 @@ private slots:
 private:
     void updateArgumentHighlight();
     void updateHintText();
+    void placeInsideScreen();
 
     Function *currentFunction() const
     { return m_items.at(m_current); }
@@ -414,8 +415,11 @@ void FunctionArgumentWidget::updateHintText()
 
     m_numberLabel->setText(tr("%1 of %2").arg(m_current + 1).arg(m_items.size()));
 
-    m_popupFrame->setFixedWidth(m_popupFrame->minimumSizeHint().width());
+    placeInsideScreen();
+}
 
+void FunctionArgumentWidget::placeInsideScreen()
+{
     const QDesktopWidget *desktop = QApplication::desktop();
 #ifdef Q_WS_MAC
     const QRect screen = desktop->availableGeometry(desktop->screenNumber(m_editor->widget()));
@@ -423,7 +427,22 @@ void FunctionArgumentWidget::updateHintText()
     const QRect screen = desktop->screenGeometry(desktop->screenNumber(m_editor->widget()));
 #endif
 
-    const QSize sz = m_popupFrame->sizeHint();
+    m_pager->setFixedWidth(m_pager->minimumSizeHint().width());
+
+    setWordWrap(false);
+    const int maxDesiredWidth = screen.width() - 10;
+    const QSize minHint = m_popupFrame->minimumSizeHint();
+    if (minHint.width() > maxDesiredWidth) {
+        setWordWrap(true);
+        m_popupFrame->setFixedWidth(maxDesiredWidth);
+        const int extra =
+            m_popupFrame->contentsMargins().bottom() + m_popupFrame->contentsMargins().top();
+        m_popupFrame->setFixedHeight(heightForWidth(maxDesiredWidth - m_pager->width()) + extra);
+    } else {
+        m_popupFrame->setFixedSize(minHint);
+    }
+
+    const QSize sz = m_popupFrame->size();
     QPoint pos = m_editor->cursorRect(m_startpos).topLeft();
     pos.setY(pos.y() - sz.height() - 1);
 
-- 
GitLab