summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Melo <leandro.melo@nokia.com>2010-08-17 10:10:46 +0200
committerLeandro Melo <leandro.melo@nokia.com>2010-08-17 10:13:38 +0200
commit0ad6dfe09ed5950dcdf513e18509a6202560e2bd (patch)
treef393d18489a4f34a8e65a14555aad7bc58d0cf67
parenteb707d1a03715aadbbd067acb74fda529f2366ba (diff)
downloadqt-creator-0ad6dfe09ed5950dcdf513e18509a6202560e2bd.tar.gz
Do not prevent wrapping for long tooltips.
Reviewed-by: Robert Loehning
-rw-r--r--src/plugins/cppeditor/cpphoverhandler.cpp42
-rw-r--r--src/plugins/cppeditor/cpphoverhandler.h2
2 files changed, 34 insertions, 10 deletions
diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp
index 894e27a72e..4abc903ec1 100644
--- a/src/plugins/cppeditor/cpphoverhandler.cpp
+++ b/src/plugins/cppeditor/cpphoverhandler.cpp
@@ -61,6 +61,8 @@
#include <QtGui/QToolTip>
#include <QtGui/QTextCursor>
#include <QtGui/QTextBlock>
+#include <QtGui/QApplication>
+#include <QtGui/QDesktopWidget>
using namespace CppEditor::Internal;
using namespace CPlusPlus;
@@ -105,7 +107,7 @@ void CppHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint
if (core->hasContext(dbgcontext))
return;
- updateHelpIdAndTooltip(editor, pos);
+ updateHelpIdAndTooltip(editor, pos, QApplication::desktop()->screenNumber(point));
if (m_toolTip.isEmpty())
QToolTip::hideText();
@@ -238,7 +240,9 @@ static FullySpecifiedType resolve(const FullySpecifiedType &ty,
return ty;
}
-void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos)
+void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor,
+ int pos,
+ const int screen)
{
m_helpId.clear();
m_toolTip.clear();
@@ -395,16 +399,36 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
if (!formatTooltip.isEmpty())
m_toolTip = formatTooltip;
+ const int tipWidth = QFontMetrics(QToolTip::font()).width(m_toolTip);
+ bool preventWrapping = true;
+
+ if (screen != -1) {
+#ifdef Q_WS_MAC
+ int screenWidth = QApplication::desktop()->availableGeometry(screen).width();
+#else
+ int screenWidth = QApplication::desktop()->screenGeometry(screen).width();
+#endif
+ if (tipWidth > screenWidth * .8)
+ preventWrapping = false;
+ }
+
if (!m_helpId.isEmpty() && !helpLinks.isEmpty()) {
if (showF1) {
- // we need the original width without escape sequences
- const int width = QFontMetrics(QToolTip::font()).width(m_toolTip);
- m_toolTip = QString(QLatin1String("<table><tr><td valign=middle width=%2>%1</td>"
- "<td><img src=\":/cppeditor/images/f1.png\"></td></tr></table>"))
- .arg(Qt::escape(m_toolTip)).arg(width);
+ if (preventWrapping) {
+ m_toolTip = QString(QLatin1String("<table><tr><td valign=middle width=%2>%1</td>"
+ "<td><img src=\":/cppeditor/images/f1.png\"></td></tr></table>"))
+ .arg(Qt::escape(m_toolTip)).arg(tipWidth);
+ } else {
+ m_toolTip = QString(QLatin1String("<table><tr><td valign=middle>%1</td>"
+ "<td><img src=\":/cppeditor/images/f1.png\"></td></tr></table>"))
+ .arg(Qt::escape(m_toolTip));
+ }
}
editor->setContextHelpId(m_helpId);
- } else if (!m_toolTip.isEmpty() && Qt::mightBeRichText(m_toolTip)) {
- m_toolTip = QString(QLatin1String("<nobr>%1</nobr>")).arg(Qt::escape(m_toolTip));
+ } else if (!m_toolTip.isEmpty()) {
+ if (preventWrapping)
+ m_toolTip = QString(QLatin1String("<table><tr><td width=%2>%1</td></tr></table>")).arg(Qt::escape(m_toolTip)).arg(tipWidth);
+ else if (!Qt::mightBeRichText(m_toolTip))
+ m_toolTip = QString(QLatin1String("<p>%1</p>")).arg(Qt::escape(m_toolTip));
}
}
diff --git a/src/plugins/cppeditor/cpphoverhandler.h b/src/plugins/cppeditor/cpphoverhandler.h
index 311b829223..3e8fa960f1 100644
--- a/src/plugins/cppeditor/cpphoverhandler.h
+++ b/src/plugins/cppeditor/cpphoverhandler.h
@@ -66,7 +66,7 @@ private slots:
void editorOpened(Core::IEditor *editor);
private:
- void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
+ void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos, const int screen = -1);
CppTools::CppModelManagerInterface *m_modelManager;
QString m_helpId;