Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_text_label.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_text_label.cpp (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_text_label.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_text.h" 12 12 #include "qwt_painter.h" 13 #include "qwt_math.h" 14 15 #include <qstyle.h> 16 #include <qstyleoption.h> 13 17 #include <qpainter.h> 14 18 #include <qevent.h> 15 #include <qma th.h>19 #include <qmargins.h> 16 20 17 21 class QwtTextLabel::PrivateData 18 22 { 19 public: 20 PrivateData() :21 indent( 4 ) ,22 margin( 0 ) 23 public: 24 PrivateData() 25 : indent( 4 ) 26 , margin( 0 ) 23 27 { 24 28 } … … 30 34 31 35 /*! 32 Constructs an empty label. 33 \param parent Parent widget 34 */ 35 QwtTextLabel::QwtTextLabel( QWidget *parent ):36 QFrame( parent ) 36 Constructs an empty label. 37 \param parent Parent widget 38 */ 39 QwtTextLabel::QwtTextLabel( QWidget* parent ) 40 : QFrame( parent ) 37 41 { 38 42 init(); … … 40 44 41 45 /*! 42 Constructs a label that displays the text, text 43 \param parent Parent widget 44 \param text Text 45 */ 46 QwtTextLabel::QwtTextLabel( const QwtText &text, QWidget*parent ):47 QFrame( parent ) 46 Constructs a label that displays the text, text 47 \param parent Parent widget 48 \param text Text 49 */ 50 QwtTextLabel::QwtTextLabel( const QwtText& text, QWidget* parent ) 51 : QFrame( parent ) 48 52 { 49 53 init(); 50 d_data->text = text;54 m_data->text = text; 51 55 } 52 56 … … 54 58 QwtTextLabel::~QwtTextLabel() 55 59 { 56 delete d_data;60 delete m_data; 57 61 } 58 62 59 63 void QwtTextLabel::init() 60 64 { 61 d_data = new PrivateData();65 m_data = new PrivateData(); 62 66 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); 63 67 } … … 67 71 \sa plainText() 68 72 */ 69 void QwtTextLabel::setPlainText( const QString &text )73 void QwtTextLabel::setPlainText( const QString& text ) 70 74 { 71 75 setText( QwtText( text ) ); … … 80 84 QString QwtTextLabel::plainText() const 81 85 { 82 return d_data->text.text();86 return m_data->text.text(); 83 87 } 84 88 … … 88 92 \param textFormat Format of text 89 93 90 \sa QwtText 91 */ 92 void QwtTextLabel::setText( const QString &text,94 \sa QwtText 95 */ 96 void QwtTextLabel::setText( const QString& text, 93 97 QwtText::TextFormat textFormat ) 94 98 { 95 d_data->text.setText( text, textFormat );99 m_data->text.setText( text, textFormat ); 96 100 97 101 update(); … … 102 106 Change the label's text 103 107 \param text New text 104 */ 105 void QwtTextLabel::setText( const QwtText &text )106 { 107 d_data->text = text;108 */ 109 void QwtTextLabel::setText( const QwtText& text ) 110 { 111 m_data->text = text; 108 112 109 113 update(); … … 112 116 113 117 //! Return the text 114 const QwtText &QwtTextLabel::text() const115 { 116 return d_data->text;118 const QwtText& QwtTextLabel::text() const 119 { 120 return m_data->text; 117 121 } 118 122 … … 120 124 void QwtTextLabel::clear() 121 125 { 122 d_data->text = QwtText();126 m_data->text = QwtText(); 123 127 124 128 update(); … … 129 133 int QwtTextLabel::indent() const 130 134 { 131 return d_data->indent;132 } 133 134 /*! 135 Set label's text indent in pixels 136 \param indent Indentation in pixels 137 */ 135 return m_data->indent; 136 } 137 138 /*! 139 Set label's text indent in pixels 140 \param indent Indentation in pixels 141 */ 138 142 void QwtTextLabel::setIndent( int indent ) 139 143 { … … 141 145 indent = 0; 142 146 143 d_data->indent = indent;147 m_data->indent = indent; 144 148 145 149 update(); … … 150 154 int QwtTextLabel::margin() const 151 155 { 152 return d_data->margin;153 } 154 155 /*! 156 Set label's margin in pixels 157 \param margin Margin in pixels 158 */ 156 return m_data->margin; 157 } 158 159 /*! 160 Set label's margin in pixels 161 \param margin Margin in pixels 162 */ 159 163 void QwtTextLabel::setMargin( int margin ) 160 164 { 161 d_data->margin = margin;165 m_data->margin = margin; 162 166 163 167 update(); … … 174 178 QSize QwtTextLabel::minimumSizeHint() const 175 179 { 176 QSizeF sz = d_data->text.textSize( font() ); 177 178 int mw = 2 * ( frameWidth() + d_data->margin ); 179 int mh = mw; 180 181 int indent = d_data->indent; 180 QSizeF sz = m_data->text.textSize( font() ); 181 182 const QMargins m = contentsMargins(); 183 184 int mw = m.left() + m.right() + 2 * m_data->margin; 185 int mh = m.top() + m.bottom() + 2 * m_data->margin; 186 187 int indent = m_data->indent; 182 188 if ( indent <= 0 ) 183 189 indent = defaultIndent(); … … 185 191 if ( indent > 0 ) 186 192 { 187 const int align = d_data->text.renderFlags();193 const int align = m_data->text.renderFlags(); 188 194 if ( align & Qt::AlignLeft || align & Qt::AlignRight ) 189 mw += d_data->indent;195 mw += m_data->indent; 190 196 else if ( align & Qt::AlignTop || align & Qt::AlignBottom ) 191 mh += d_data->indent;197 mh += m_data->indent; 192 198 } 193 199 194 200 sz += QSizeF( mw, mh ); 195 201 196 return QSize( qCeil( sz.width() ), qCeil( sz.height() ) ); 202 return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) ); 197 203 } 198 204 … … 200 206 \param width Width 201 207 \return Preferred height for this widget, given the width. 202 */ 208 */ 203 209 int QwtTextLabel::heightForWidth( int width ) const 204 210 { 205 const int renderFlags = d_data->text.renderFlags();206 207 int indent = d_data->indent;211 const int renderFlags = m_data->text.renderFlags(); 212 213 int indent = m_data->indent; 208 214 if ( indent <= 0 ) 209 215 indent = defaultIndent(); 210 216 211 width -= 2 * frameWidth(); 217 const QMargins m = contentsMargins(); 218 219 width -= m.left() + m.right() - 2 * m_data->margin; 212 220 if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight ) 213 221 width -= indent; 214 222 215 int height = q Ceil( d_data->text.heightForWidth( width, font() ) );223 int height = qwtCeil( m_data->text.heightForWidth( width, font() ) ); 216 224 if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) ) 217 225 height += indent; 218 226 219 height += 2 * frameWidth();227 height += m.top() + m.bottom() + 2 * m_data->margin; 220 228 221 229 return height; … … 225 233 Qt paint event 226 234 \param event Paint event 227 */ 228 void QwtTextLabel::paintEvent( QPaintEvent *event )235 */ 236 void QwtTextLabel::paintEvent( QPaintEvent* event ) 229 237 { 230 238 QPainter painter( this ); 239 painter.setClipRegion( event->region() ); 240 241 QStyleOption opt; 242 opt.initFrom(this); 243 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 231 244 232 245 if ( !contentsRect().contains( event->rect() ) ) 233 246 { 234 painter.save();235 247 painter.setClipRegion( event->region() & frameRect() ); 236 248 drawFrame( &painter ); 237 painter.restore();238 249 } 239 250 … … 244 255 245 256 //! Redraw the text and focus indicator 246 void QwtTextLabel::drawContents( QPainter *painter )257 void QwtTextLabel::drawContents( QPainter* painter ) 247 258 { 248 259 const QRect r = textRect(); … … 266 277 267 278 //! Redraw the text 268 void QwtTextLabel::drawText( QPainter *painter, const QRectF&textRect )269 { 270 d_data->text.draw( painter, textRect );271 } 272 273 /*! 274 Calculate geometry for the text in widget coordinates 275 \return Geometry for the text 276 */ 279 void QwtTextLabel::drawText( QPainter* painter, const QRectF& textRect ) 280 { 281 m_data->text.draw( painter, textRect ); 282 } 283 284 /*! 285 Calculate geometry for the text in widget coordinates 286 \return Geometry for the text 287 */ 277 288 QRect QwtTextLabel::textRect() const 278 289 { 279 290 QRect r = contentsRect(); 280 291 281 if ( !r.isEmpty() && d_data->margin > 0 )282 { 283 r.setRect( r.x() + d_data->margin, r.y() + d_data->margin,284 r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin);292 if ( !r.isEmpty() && m_data->margin > 0 ) 293 { 294 const int m = m_data->margin; 295 r.adjust( m, m, -m, -m ); 285 296 } 286 297 287 298 if ( !r.isEmpty() ) 288 299 { 289 int indent = d_data->indent;300 int indent = m_data->indent; 290 301 if ( indent <= 0 ) 291 302 indent = defaultIndent(); … … 293 304 if ( indent > 0 ) 294 305 { 295 const int renderFlags = d_data->text.renderFlags();306 const int renderFlags = m_data->text.renderFlags(); 296 307 297 308 if ( renderFlags & Qt::AlignLeft ) 309 { 298 310 r.setX( r.x() + indent ); 311 } 299 312 else if ( renderFlags & Qt::AlignRight ) 313 { 300 314 r.setWidth( r.width() - indent ); 315 } 301 316 else if ( renderFlags & Qt::AlignTop ) 317 { 302 318 r.setY( r.y() + indent ); 319 } 303 320 else if ( renderFlags & Qt::AlignBottom ) 321 { 304 322 r.setHeight( r.height() - indent ); 323 } 305 324 } 306 325 } … … 315 334 316 335 QFont fnt; 317 if ( d_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )318 fnt = d_data->text.font();336 if ( m_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) 337 fnt = m_data->text.font(); 319 338 else 320 339 fnt = font(); 321 340 322 return QFontMetrics( fnt ).width( 'x' ) / 2; 323 } 324 341 return QwtPainter::horizontalAdvance( QFontMetrics( fnt ), 'x' ) / 2; 342 } 343 344 #include "moc_qwt_text_label.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
