/*! 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() ) { int indent = d_data->indent; if ( indent <= 0 ) indent = defaultIndent(); if ( indent > 0 ) { const int renderFlags = d_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 ); } } return r; }
/*! \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; if ( indent <= 0 ) indent = defaultIndent(); width -= 2 * frameWidth(); if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight ) width -= indent; int height = qCeil( d_data->text.heightForWidth( width, font() ) ); if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) ) height += indent; height += 2 * frameWidth(); return height; }
//! Return a minimum size hint QSize QwtTextLabel::minimumSizeHint() const { QSize sz = d_data->text.textSize(font()); int mw = 2 * (frameWidth() + d_data->margin); int mh = mw; int indent = d_data->indent; if ( indent <= 0 ) indent = defaultIndent(); if ( indent > 0 ) { const int align = d_data->text.renderFlags(); if ( align & Qt::AlignLeft || align & Qt::AlignRight ) mw += d_data->indent; else if ( align & Qt::AlignTop || align & Qt::AlignBottom ) mh += d_data->indent; } sz += QSize(mw, mh); return sz; }