Index: trunk/BNC/qwt/qwt_text_label.cpp
===================================================================
--- trunk/BNC/qwt/qwt_text_label.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_text_label.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -11,14 +11,18 @@
 #include "qwt_text.h"
 #include "qwt_painter.h"
+#include "qwt_math.h"
+
+#include <qstyle.h>
+#include <qstyleoption.h>
 #include <qpainter.h>
 #include <qevent.h>
-#include <qmath.h>
+#include <qmargins.h>
 
 class QwtTextLabel::PrivateData
 {
-public:
-    PrivateData():
-        indent( 4 ),
-        margin( 0 )
+  public:
+    PrivateData()
+        : indent( 4 )
+        , margin( 0 )
     {
     }
@@ -30,9 +34,9 @@
 
 /*!
-  Constructs an empty label.
-  \param parent Parent widget
-*/
-QwtTextLabel::QwtTextLabel( QWidget *parent ):
-    QFrame( parent )
+   Constructs an empty label.
+   \param parent Parent widget
+ */
+QwtTextLabel::QwtTextLabel( QWidget* parent )
+    : QFrame( parent )
 {
     init();
@@ -40,13 +44,13 @@
 
 /*!
-  Constructs a label that displays the text, text
-  \param parent Parent widget
-  \param text Text
-*/
-QwtTextLabel::QwtTextLabel( const QwtText &text, QWidget *parent ):
-    QFrame( parent )
+   Constructs a label that displays the text, text
+   \param parent Parent widget
+   \param text Text
+ */
+QwtTextLabel::QwtTextLabel( const QwtText& text, QWidget* parent )
+    : QFrame( parent )
 {
     init();
-    d_data->text = text;
+    m_data->text = text;
 }
 
@@ -54,10 +58,10 @@
 QwtTextLabel::~QwtTextLabel()
 {
-    delete d_data;
+    delete m_data;
 }
 
 void QwtTextLabel::init()
 {
-    d_data = new PrivateData();
+    m_data = new PrivateData();
     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
 }
@@ -67,5 +71,5 @@
    \sa plainText()
  */
-void QwtTextLabel::setPlainText( const QString &text )
+void QwtTextLabel::setPlainText( const QString& text )
 {
     setText( QwtText( text ) );
@@ -80,5 +84,5 @@
 QString QwtTextLabel::plainText() const
 {
-    return d_data->text.text();
+    return m_data->text.text();
 }
 
@@ -88,10 +92,10 @@
    \param textFormat Format of text
 
-  \sa QwtText
-*/
-void QwtTextLabel::setText( const QString &text,
+   \sa QwtText
+ */
+void QwtTextLabel::setText( const QString& text,
     QwtText::TextFormat textFormat )
 {
-    d_data->text.setText( text, textFormat );
+    m_data->text.setText( text, textFormat );
 
     update();
@@ -102,8 +106,8 @@
    Change the label's text
    \param text New text
-*/
-void QwtTextLabel::setText( const QwtText &text )
-{
-    d_data->text = text;
+ */
+void QwtTextLabel::setText( const QwtText& text )
+{
+    m_data->text = text;
 
     update();
@@ -112,7 +116,7 @@
 
 //! Return the text
-const QwtText &QwtTextLabel::text() const
-{
-    return d_data->text;
+const QwtText& QwtTextLabel::text() const
+{
+    return m_data->text;
 }
 
@@ -120,5 +124,5 @@
 void QwtTextLabel::clear()
 {
-    d_data->text = QwtText();
+    m_data->text = QwtText();
 
     update();
@@ -129,11 +133,11 @@
 int QwtTextLabel::indent() const
 {
-    return d_data->indent;
-}
-
-/*!
-  Set label's text indent in pixels
-  \param indent Indentation in pixels
-*/
+    return m_data->indent;
+}
+
+/*!
+   Set label's text indent in pixels
+   \param indent Indentation in pixels
+ */
 void QwtTextLabel::setIndent( int indent )
 {
@@ -141,5 +145,5 @@
         indent = 0;
 
-    d_data->indent = indent;
+    m_data->indent = indent;
 
     update();
@@ -150,14 +154,14 @@
 int QwtTextLabel::margin() const
 {
-    return d_data->margin;
-}
-
-/*!
-  Set label's margin in pixels
-  \param margin Margin in pixels
-*/
+    return m_data->margin;
+}
+
+/*!
+   Set label's margin in pixels
+   \param margin Margin in pixels
+ */
 void QwtTextLabel::setMargin( int margin )
 {
-    d_data->margin = margin;
+    m_data->margin = margin;
 
     update();
@@ -174,10 +178,12 @@
 QSize QwtTextLabel::minimumSizeHint() const
 {
-    QSizeF sz = d_data->text.textSize( font() );
-
-    int mw = 2 * ( frameWidth() + d_data->margin );
-    int mh = mw;
-
-    int indent = d_data->indent;
+    QSizeF sz = m_data->text.textSize( font() );
+
+    const QMargins m = contentsMargins();
+
+    int mw = m.left() + m.right() + 2 * m_data->margin;
+    int mh = m.top() + m.bottom() + 2 * m_data->margin;
+
+    int indent = m_data->indent;
     if ( indent <= 0 )
         indent = defaultIndent();
@@ -185,14 +191,14 @@
     if ( indent > 0 )
     {
-        const int align = d_data->text.renderFlags();
+        const int align = m_data->text.renderFlags();
         if ( align & Qt::AlignLeft || align & Qt::AlignRight )
-            mw += d_data->indent;
+            mw += m_data->indent;
         else if ( align & Qt::AlignTop || align & Qt::AlignBottom )
-            mh += d_data->indent;
+            mh += m_data->indent;
     }
 
     sz += QSizeF( mw, mh );
 
-    return QSize( qCeil( sz.width() ), qCeil( sz.height() ) );
+    return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) );
 }
 
@@ -200,22 +206,24 @@
    \param width Width
    \return Preferred height for this widget, given the width.
-*/
+ */
 int QwtTextLabel::heightForWidth( int width ) const
 {
-    const int renderFlags = d_data->text.renderFlags();
-
-    int indent = d_data->indent;
+    const int renderFlags = m_data->text.renderFlags();
+
+    int indent = m_data->indent;
     if ( indent <= 0 )
         indent = defaultIndent();
 
-    width -= 2 * frameWidth();
+    const QMargins m = contentsMargins();
+
+    width -= m.left() + m.right() - 2 * m_data->margin;
     if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight )
         width -= indent;
 
-    int height = qCeil( d_data->text.heightForWidth( width, font() ) );
+    int height = qwtCeil( m_data->text.heightForWidth( width, font() ) );
     if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) )
         height += indent;
 
-    height += 2 * frameWidth();
+    height += m.top() + m.bottom() + 2 * m_data->margin;
 
     return height;
@@ -225,15 +233,18 @@
    Qt paint event
    \param event Paint event
-*/
-void QwtTextLabel::paintEvent( QPaintEvent *event )
+ */
+void QwtTextLabel::paintEvent( QPaintEvent* event )
 {
     QPainter painter( this );
+    painter.setClipRegion( event->region() );
+
+    QStyleOption opt;
+    opt.initFrom(this);
+    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
 
     if ( !contentsRect().contains( event->rect() ) )
     {
-        painter.save();
         painter.setClipRegion( event->region() & frameRect() );
         drawFrame( &painter );
-        painter.restore();
     }
 
@@ -244,5 +255,5 @@
 
 //! Redraw the text and focus indicator
-void QwtTextLabel::drawContents( QPainter *painter )
+void QwtTextLabel::drawContents( QPainter* painter )
 {
     const QRect r = textRect();
@@ -266,26 +277,26 @@
 
 //! Redraw the text
-void QwtTextLabel::drawText( QPainter *painter, const QRectF &textRect )
-{
-    d_data->text.draw( painter, textRect );
-}
-
-/*!
-  Calculate geometry for the text in widget coordinates
-  \return Geometry for the text
-*/
+void QwtTextLabel::drawText( QPainter* painter, const QRectF& textRect )
+{
+    m_data->text.draw( painter, textRect );
+}
+
+/*!
+   Calculate geometry for the text in widget coordinates
+   \return Geometry for the text
+ */
 QRect QwtTextLabel::textRect() const
 {
     QRect r = contentsRect();
 
-    if ( !r.isEmpty() && d_data->margin > 0 )
-    {
-        r.setRect( r.x() + d_data->margin, r.y() + d_data->margin,
-            r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin );
+    if ( !r.isEmpty() && m_data->margin > 0 )
+    {
+        const int m = m_data->margin;
+        r.adjust( m, m, -m, -m );
     }
 
     if ( !r.isEmpty() )
     {
-        int indent = d_data->indent;
+        int indent = m_data->indent;
         if ( indent <= 0 )
             indent = defaultIndent();
@@ -293,14 +304,22 @@
         if ( indent > 0 )
         {
-            const int renderFlags = d_data->text.renderFlags();
+            const int renderFlags = m_data->text.renderFlags();
 
             if ( renderFlags & Qt::AlignLeft )
+            {
                 r.setX( r.x() + indent );
+            }
             else if ( renderFlags & Qt::AlignRight )
+            {
                 r.setWidth( r.width() - indent );
+            }
             else if ( renderFlags & Qt::AlignTop )
+            {
                 r.setY( r.y() + indent );
+            }
             else if ( renderFlags & Qt::AlignBottom )
+            {
                 r.setHeight( r.height() - indent );
+            }
         }
     }
@@ -315,10 +334,11 @@
 
     QFont fnt;
-    if ( d_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )
-        fnt = d_data->text.font();
+    if ( m_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )
+        fnt = m_data->text.font();
     else
         fnt = font();
 
-    return QFontMetrics( fnt ).width( 'x' ) / 2;
-}
-
+    return QwtPainter::horizontalAdvance( QFontMetrics( fnt ), 'x' ) / 2;
+}
+
+#include "moc_qwt_text_label.cpp"
