From 9877bef7c56b07e715d1f7a6dddc8529387b689b Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 26 Jan 2007 19:38:32 +0000 Subject: Further optimizations for the status bar: hide the space information if the status bar text does not fit into the remaining width. svn path=/trunk/playground/utils/dolphin/; revision=627486 --- src/statusbarmessagelabel.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/statusbarmessagelabel.cpp') diff --git a/src/statusbarmessagelabel.cpp b/src/statusbarmessagelabel.cpp index 682aa123b..de66bebba 100644 --- a/src/statusbarmessagelabel.cpp +++ b/src/statusbarmessagelabel.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "statusbarmessagelabel.h" @@ -106,6 +106,13 @@ void StatusBarMessageLabel::setMinimumTextHeight(int min) } } +int StatusBarMessageLabel::widthGap() const +{ + QFontMetrics fontMetrics(font()); + const int defaultGap = 10; + return fontMetrics.width(m_text) - availableTextWidth() + defaultGap; +} + void StatusBarMessageLabel::paintEvent(QPaintEvent* /* event */) { QPainter painter(this); @@ -189,13 +196,10 @@ void StatusBarMessageLabel::assureVisibleText() return; } - - int availableWidth = width() - m_pixmap.width() - pixmapGap() * 2; - QFontMetrics fontMetrics(font()); - QRect bounds(fontMetrics.boundingRect(0, 0, availableWidth, height(), - Qt::AlignVCenter | Qt::TextWordWrap, - m_text)); + const QRect bounds(fontMetrics.boundingRect(0, 0, availableTextWidth(), height(), + Qt::AlignVCenter | Qt::TextWordWrap, + m_text)); int requiredHeight = bounds.height(); if (requiredHeight < m_minTextHeight) { requiredHeight = m_minTextHeight; @@ -204,6 +208,11 @@ void StatusBarMessageLabel::assureVisibleText() updateGeometry(); } +int StatusBarMessageLabel::availableTextWidth() const +{ + return width() - m_pixmap.width() - pixmapGap() * 2; +} + QColor StatusBarMessageLabel::mixColors(const QColor& c1, const QColor& c2, int percent) const -- cgit v1.3