From 7e4883f3bbd22aa4cfc5c27c6d901fb6370ee348 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 30 Nov 2011 15:39:29 +0100 Subject: [PATCH] handle titles a little nicer: centered, no wrap for short titles --- private/tooltip.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/private/tooltip.cpp b/private/tooltip.cpp index 0f4b4d3c2..25c961ba2 100644 --- a/private/tooltip.cpp +++ b/private/tooltip.cpp @@ -56,6 +56,9 @@ public: m_toolTip(parent), m_document(new QTextDocument(this)) { + QTextOption option = m_document->defaultTextOption(); + option.setWrapMode(QTextOption::WordWrap); + m_document->setDefaultTextOption(option); } void setStyleSheet(const QString &css) @@ -66,8 +69,13 @@ public: void setContent(const ToolTipContent &data) { QString html; - if (!data.mainText().isEmpty()) { - html.append("
" + data.mainText() + "
"); + QString mainText = data.mainText(); + if (!mainText.isEmpty()) { + if (mainText.size() < 50) { + // don't let short texts wrap on us! + mainText = mainText.replace(" ", " "); + } + html.append("
" + mainText + "
"); } html.append(data.subText()); @@ -76,6 +84,8 @@ public: data.registerResources(m_document); if (!html.isEmpty()) { m_document->setHtml("

" + html + "

"); + } else { + m_document->clear(); } m_document->adjustSize(); @@ -179,8 +189,8 @@ ToolTip::ToolTip(QWidget *parent) d->preview = new WindowPreview(this); d->text = new TipTextWidget(this); d->imageLabel = new QLabel(this); - d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft); + d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft); d->animation = new QPropertyAnimation(this, "pos", this); d->animation->setEasingCurve(QEasingCurve::InOutQuad); d->animation->setDuration(250); @@ -198,7 +208,7 @@ ToolTip::ToolTip(QWidget *parent) QHBoxLayout *iconTextHBoxLayout = new QHBoxLayout; iconTextHBoxLayout->addWidget(d->imageLabel); - iconTextHBoxLayout->setAlignment(d->imageLabel, Qt::AlignCenter); + iconTextHBoxLayout->setAlignment(d->imageLabel, Qt::AlignTop | Qt::AlignHCenter); iconTextHBoxLayout->addWidget(d->text); iconTextHBoxLayout->setAlignment(d->text, Qt::AlignLeft | Qt::AlignVCenter); iconTextHBoxLayout->setStretchFactor(d->text, 1);