Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_text.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_text.cpp (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_text.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_painter.h" 12 12 #include "qwt_text_engine.h" 13 #include "qwt_math.h" 14 13 15 #include <qmap.h> 14 16 #include <qfont.h> … … 17 19 #include <qbrush.h> 18 20 #include <qpainter.h> 19 #include <qapplication.h> 20 #include <qdesktopwidget.h> 21 #include <qmath.h> 22 23 class QwtTextEngineDict 24 { 25 public: 26 static QwtTextEngineDict &dict(); 27 28 void setTextEngine( QwtText::TextFormat, QwtTextEngine * ); 29 30 const QwtTextEngine *textEngine( QwtText::TextFormat ) const; 31 const QwtTextEngine *textEngine( const QString &, 32 QwtText::TextFormat ) const; 33 34 private: 35 QwtTextEngineDict(); 36 ~QwtTextEngineDict(); 37 38 typedef QMap<int, QwtTextEngine *> EngineMap; 39 40 inline const QwtTextEngine *engine( EngineMap::const_iterator &it ) const 41 { 42 return it.value(); 43 } 44 45 EngineMap d_map; 46 }; 47 48 QwtTextEngineDict &QwtTextEngineDict::dict() 49 { 50 static QwtTextEngineDict engineDict; 51 return engineDict; 52 } 53 54 QwtTextEngineDict::QwtTextEngineDict() 55 { 56 d_map.insert( QwtText::PlainText, new QwtPlainTextEngine() ); 57 #ifndef QT_NO_RICHTEXT 58 d_map.insert( QwtText::RichText, new QwtRichTextEngine() ); 21 22 #if QT_VERSION >= 0x050200 23 24 static QwtText qwtStringToText( const QString& text ) 25 { 26 return QwtText( text ); 27 } 28 59 29 #endif 60 } 61 62 QwtTextEngineDict::~QwtTextEngineDict() 63 { 64 for ( EngineMap::const_iterator it = d_map.constBegin(); 65 it != d_map.constEnd(); ++it ) 66 { 67 const QwtTextEngine *textEngine = engine( it ); 68 delete textEngine; 69 } 70 } 71 72 const QwtTextEngine *QwtTextEngineDict::textEngine( const QString& text, 73 QwtText::TextFormat format ) const 74 { 75 if ( format == QwtText::AutoText ) 76 { 77 for ( EngineMap::const_iterator it = d_map.begin(); 78 it != d_map.end(); ++it ) 30 31 namespace 32 { 33 static const struct RegisterQwtText 34 { 35 inline RegisterQwtText() 79 36 { 80 if ( it.key() != QwtText::PlainText ) 37 qRegisterMetaType< QwtText >(); 38 39 #if QT_VERSION >= 0x050200 40 QMetaType::registerConverter< QString, QwtText >( qwtStringToText ); 41 #endif 42 } 43 44 } qwtRegisterQwtText; 45 } 46 47 namespace 48 { 49 class TextEngineDict 50 { 51 public: 52 static TextEngineDict& dict(); 53 54 void setTextEngine( QwtText::TextFormat, QwtTextEngine* ); 55 56 const QwtTextEngine* textEngine( QwtText::TextFormat ) const; 57 const QwtTextEngine* textEngine( const QString&, 58 QwtText::TextFormat ) const; 59 60 private: 61 TextEngineDict(); 62 ~TextEngineDict(); 63 64 typedef QMap< int, QwtTextEngine* > EngineMap; 65 66 inline const QwtTextEngine* engine( EngineMap::const_iterator& it ) const 67 { 68 return it.value(); 69 } 70 71 EngineMap m_map; 72 }; 73 74 TextEngineDict& TextEngineDict::dict() 75 { 76 static TextEngineDict engineDict; 77 return engineDict; 78 } 79 80 TextEngineDict::TextEngineDict() 81 { 82 m_map.insert( QwtText::PlainText, new QwtPlainTextEngine() ); 83 #ifndef QT_NO_RICHTEXT 84 m_map.insert( QwtText::RichText, new QwtRichTextEngine() ); 85 #endif 86 } 87 88 TextEngineDict::~TextEngineDict() 89 { 90 for ( EngineMap::const_iterator it = m_map.constBegin(); 91 it != m_map.constEnd(); ++it ) 92 { 93 const QwtTextEngine* textEngine = engine( it ); 94 delete textEngine; 95 } 96 } 97 98 const QwtTextEngine* TextEngineDict::textEngine( const QString& text, 99 QwtText::TextFormat format ) const 100 { 101 if ( format == QwtText::AutoText ) 102 { 103 for ( EngineMap::const_iterator it = m_map.begin(); 104 it != m_map.end(); ++it ) 81 105 { 82 const QwtTextEngine *e = engine( it ); 83 if ( e && e->mightRender( text ) ) 84 return e; 106 if ( it.key() != QwtText::PlainText ) 107 { 108 const QwtTextEngine* e = engine( it ); 109 if ( e && e->mightRender( text ) ) 110 return e; 111 } 85 112 } 86 113 } 87 } 88 89 EngineMap::const_iterator it = d_map.find( format );90 if ( it != d_map.end() )91 {92 const QwtTextEngine *e = engine( it );93 if ( e )94 return e;95 } 96 97 it = d_map.find( QwtText::PlainText );98 return engine( it );99 } 100 101 voidQwtTextEngineDict::setTextEngine( QwtText::TextFormat format,102 QwtTextEngine *engine )103 { 104 if ( format == QwtText::AutoText )105 return; 106 107 if ( format == QwtText::PlainText && engine == NULL )108 return; 109 110 EngineMap::const_iterator it = d_map.constFind( format );111 if ( it != d_map.constEnd() )112 {113 delete this->engine( it );114 d_map.remove( format );115 } 116 117 if (engine!= NULL )118 d_map.insert( format, engine );119 } 120 121 constQwtTextEngine *QwtTextEngineDict::textEngine(122 QwtText::TextFormat format ) const123 { 124 const QwtTextEngine *e = NULL; 125 126 EngineMap::const_iterator it = d_map.find( format );127 if ( it != d_map.end() )128 e = engine( it ); 129 130 return e;114 115 EngineMap::const_iterator it = m_map.find( format ); 116 if ( it != m_map.end() ) 117 { 118 const QwtTextEngine* e = engine( it ); 119 if ( e ) 120 return e; 121 } 122 123 it = m_map.find( QwtText::PlainText ); 124 return engine( it ); 125 } 126 127 void TextEngineDict::setTextEngine( QwtText::TextFormat format, 128 QwtTextEngine* engine ) 129 { 130 if ( format == QwtText::AutoText ) 131 return; 132 133 if ( format == QwtText::PlainText && engine == NULL ) 134 return; 135 136 EngineMap::const_iterator it = m_map.constFind( format ); 137 if ( it != m_map.constEnd() ) 138 { 139 delete this->engine( it ); 140 m_map.remove( format ); 141 } 142 143 if ( engine != NULL ) 144 m_map.insert( format, engine ); 145 } 146 147 const QwtTextEngine* TextEngineDict::textEngine( 148 QwtText::TextFormat format ) const 149 { 150 const QwtTextEngine* e = NULL; 151 152 EngineMap::const_iterator it = m_map.find( format ); 153 if ( it != m_map.end() ) 154 e = engine( it ); 155 156 return e; 157 } 131 158 } 132 159 133 160 class QwtText::PrivateData 134 161 { 135 public: 162 public: 136 163 PrivateData(): 137 164 renderFlags( Qt::AlignCenter ), … … 139 166 borderPen( Qt::NoPen ), 140 167 backgroundBrush( Qt::NoBrush ), 141 paintAttributes( 0 ),142 layoutAttributes( 0 ),143 168 textEngine( NULL ) 144 169 { … … 156 181 QwtText::LayoutAttributes layoutAttributes; 157 182 158 const QwtTextEngine *textEngine;183 const QwtTextEngine* textEngine; 159 184 }; 160 185 161 186 class QwtText::LayoutCache 162 187 { 163 public: 188 public: 164 189 void invalidate() 165 190 { … … 173 198 /*! 174 199 Constructor 200 */ 201 QwtText::QwtText() 202 { 203 m_data = new PrivateData; 204 m_data->textEngine = textEngine( m_data->text, PlainText ); 205 206 m_layoutCache = new LayoutCache; 207 } 208 209 /*! 210 Constructor 175 211 176 212 \param text Text content 177 213 \param textFormat Text format 178 */ 179 QwtText::QwtText( const QString &text, QwtText::TextFormat textFormat )180 { 181 d_data = new PrivateData;182 d_data->text = text;183 d_data->textEngine = textEngine( text, textFormat );184 185 d_layoutCache = new LayoutCache;214 */ 215 QwtText::QwtText( const QString& text, QwtText::TextFormat textFormat ) 216 { 217 m_data = new PrivateData; 218 m_data->text = text; 219 m_data->textEngine = textEngine( text, textFormat ); 220 221 m_layoutCache = new LayoutCache; 186 222 } 187 223 188 224 //! Copy constructor 189 QwtText::QwtText( const QwtText &other )190 { 191 d_data = new PrivateData;192 * d_data = *other.d_data;193 194 d_layoutCache = new LayoutCache;195 * d_layoutCache = *other.d_layoutCache;225 QwtText::QwtText( const QwtText& other ) 226 { 227 m_data = new PrivateData; 228 *m_data = *other.m_data; 229 230 m_layoutCache = new LayoutCache; 231 *m_layoutCache = *other.m_layoutCache; 196 232 } 197 233 … … 199 235 QwtText::~QwtText() 200 236 { 201 delete d_data;202 delete d_layoutCache;237 delete m_data; 238 delete m_layoutCache; 203 239 } 204 240 205 241 //! Assignment operator 206 QwtText &QwtText::operator=( const QwtText& other )207 { 208 * d_data = *other.d_data;209 * d_layoutCache = *other.d_layoutCache;242 QwtText& QwtText::operator=( const QwtText& other ) 243 { 244 *m_data = *other.m_data; 245 *m_layoutCache = *other.m_layoutCache; 210 246 return *this; 211 247 } 212 248 213 249 //! Relational operator 214 bool QwtText::operator==( const QwtText &other ) const215 { 216 return d_data->renderFlags == other.d_data->renderFlags &&217 d_data->text == other.d_data->text &&218 d_data->font == other.d_data->font &&219 d_data->color == other.d_data->color &&220 d_data->borderRadius == other.d_data->borderRadius &&221 d_data->borderPen == other.d_data->borderPen &&222 d_data->backgroundBrush == other.d_data->backgroundBrush &&223 d_data->paintAttributes == other.d_data->paintAttributes &&224 d_data->textEngine == other.d_data->textEngine;250 bool QwtText::operator==( const QwtText& other ) const 251 { 252 return m_data->renderFlags == other.m_data->renderFlags && 253 m_data->text == other.m_data->text && 254 m_data->font == other.m_data->font && 255 m_data->color == other.m_data->color && 256 m_data->borderRadius == other.m_data->borderRadius && 257 m_data->borderPen == other.m_data->borderPen && 258 m_data->backgroundBrush == other.m_data->backgroundBrush && 259 m_data->paintAttributes == other.m_data->paintAttributes && 260 m_data->textEngine == other.m_data->textEngine; 225 261 } 226 262 227 263 //! Relational operator 228 bool QwtText::operator!=( const QwtText &other ) const // invalidate264 bool QwtText::operator!=( const QwtText& other ) const // invalidate 229 265 { 230 266 return !( other == *this ); … … 238 274 239 275 \sa text() 240 */ 241 void QwtText::setText( const QString &text,276 */ 277 void QwtText::setText( const QString& text, 242 278 QwtText::TextFormat textFormat ) 243 279 { 244 d_data->text = text;245 d_data->textEngine = textEngine( text, textFormat );246 d_layoutCache->invalidate();280 m_data->text = text; 281 m_data->textEngine = textEngine( text, textFormat ); 282 m_layoutCache->invalidate(); 247 283 } 248 284 … … 250 286 \return Text as QString. 251 287 \sa setText() 252 */ 288 */ 253 289 QString QwtText::text() const 254 290 { 255 return d_data->text;291 return m_data->text; 256 292 } 257 293 … … 265 301 \sa renderFlags(), QwtTextEngine::draw() 266 302 \note Some renderFlags might have no effect, depending on the text format. 267 */ 303 */ 268 304 void QwtText::setRenderFlags( int renderFlags ) 269 305 { 270 if ( renderFlags != d_data->renderFlags )271 { 272 d_data->renderFlags = renderFlags;273 d_layoutCache->invalidate();306 if ( renderFlags != m_data->renderFlags ) 307 { 308 m_data->renderFlags = renderFlags; 309 m_layoutCache->invalidate(); 274 310 } 275 311 } … … 278 314 \return Render flags 279 315 \sa setRenderFlags() 280 */ 316 */ 281 317 int QwtText::renderFlags() const 282 318 { 283 return d_data->renderFlags;319 return m_data->renderFlags; 284 320 } 285 321 … … 290 326 \note Setting the font might have no effect, when 291 327 the text contains control sequences for setting fonts. 292 */ 293 void QwtText::setFont( const QFont &font )294 { 295 d_data->font = font;328 */ 329 void QwtText::setFont( const QFont& font ) 330 { 331 m_data->font = font; 296 332 setPaintAttribute( PaintUsingTextFont ); 297 333 } … … 300 336 QFont QwtText::font() const 301 337 { 302 return d_data->font;338 return m_data->font; 303 339 } 304 340 … … 311 347 312 348 \sa setFont(), font(), PaintAttributes 313 */ 314 QFont QwtText::usedFont( const QFont &defaultFont ) const315 { 316 if ( d_data->paintAttributes & PaintUsingTextFont )317 return d_data->font;349 */ 350 QFont QwtText::usedFont( const QFont& defaultFont ) const 351 { 352 if ( m_data->paintAttributes & PaintUsingTextFont ) 353 return m_data->font; 318 354 319 355 return defaultFont; … … 326 362 \note Setting the color might have no effect, when 327 363 the text contains control sequences for setting colors. 328 */ 329 void QwtText::setColor( const QColor &color )330 { 331 d_data->color = color;364 */ 365 void QwtText::setColor( const QColor& color ) 366 { 367 m_data->color = color; 332 368 setPaintAttribute( PaintUsingTextColor ); 333 369 } … … 336 372 QColor QwtText::color() const 337 373 { 338 return d_data->color;339 } 340 341 /*! 342 Return the color of the text, if it has one. 343 Otherwise return defaultColor. 344 345 \param defaultColor Default color 346 \return Color used for drawing the text 347 348 \sa setColor(), color(), PaintAttributes 349 */ 350 QColor QwtText::usedColor( const QColor &defaultColor ) const351 { 352 if ( d_data->paintAttributes & PaintUsingTextColor )353 return d_data->color;374 return m_data->color; 375 } 376 377 /*! 378 Return the color of the text, if it has one. 379 Otherwise return defaultColor. 380 381 \param defaultColor Default color 382 \return Color used for drawing the text 383 384 \sa setColor(), color(), PaintAttributes 385 */ 386 QColor QwtText::usedColor( const QColor& defaultColor ) const 387 { 388 if ( m_data->paintAttributes & PaintUsingTextColor ) 389 return m_data->color; 354 390 355 391 return defaultColor; … … 357 393 358 394 /*! 359 Set the radius for the corners of the border frame 360 361 \param radius Radius of a rounded corner 362 \sa borderRadius(), setBorderPen(), setBackgroundBrush() 363 */ 395 Set the radius for the corners of the border frame 396 397 \param radius Radius of a rounded corner 398 \sa borderRadius(), setBorderPen(), setBackgroundBrush() 399 */ 364 400 void QwtText::setBorderRadius( double radius ) 365 401 { 366 d_data->borderRadius = qMax( 0.0, radius );367 } 368 369 /*! 370 \return Radius for the corners of the border frame 371 \sa setBorderRadius(), borderPen(), backgroundBrush() 372 */ 402 m_data->borderRadius = qwtMaxF( 0.0, radius ); 403 } 404 405 /*! 406 \return Radius for the corners of the border frame 407 \sa setBorderRadius(), borderPen(), backgroundBrush() 408 */ 373 409 double QwtText::borderRadius() const 374 410 { 375 return d_data->borderRadius;411 return m_data->borderRadius; 376 412 } 377 413 … … 381 417 \param pen Background pen 382 418 \sa borderPen(), setBackgroundBrush() 383 */ 384 void QwtText::setBorderPen( const QPen &pen )385 { 386 d_data->borderPen = pen;419 */ 420 void QwtText::setBorderPen( const QPen& pen ) 421 { 422 m_data->borderPen = pen; 387 423 setPaintAttribute( PaintBackground ); 388 424 } … … 391 427 \return Background pen 392 428 \sa setBorderPen(), backgroundBrush() 393 */ 429 */ 394 430 QPen QwtText::borderPen() const 395 431 { 396 return d_data->borderPen;432 return m_data->borderPen; 397 433 } 398 434 … … 402 438 \param brush Background brush 403 439 \sa backgroundBrush(), setBorderPen() 404 */ 405 void QwtText::setBackgroundBrush( const QBrush &brush )406 { 407 d_data->backgroundBrush = brush;440 */ 441 void QwtText::setBackgroundBrush( const QBrush& brush ) 442 { 443 m_data->backgroundBrush = brush; 408 444 setPaintAttribute( PaintBackground ); 409 445 } … … 412 448 \return Background brush 413 449 \sa setBackgroundBrush(), borderPen() 414 */ 450 */ 415 451 QBrush QwtText::backgroundBrush() const 416 452 { 417 return d_data->backgroundBrush;453 return m_data->backgroundBrush; 418 454 } 419 455 … … 427 463 setBorderPen() and setBackgroundBrush() 428 464 \sa testPaintAttribute() 429 */ 465 */ 430 466 void QwtText::setPaintAttribute( PaintAttribute attribute, bool on ) 431 467 { 432 468 if ( on ) 433 d_data->paintAttributes |= attribute;469 m_data->paintAttributes |= attribute; 434 470 else 435 d_data->paintAttributes &= ~attribute;471 m_data->paintAttributes &= ~attribute; 436 472 } 437 473 … … 443 479 444 480 \sa setPaintAttribute() 445 */ 481 */ 446 482 bool QwtText::testPaintAttribute( PaintAttribute attribute ) const 447 483 { 448 return d_data->paintAttributes & attribute;484 return m_data->paintAttributes & attribute; 449 485 } 450 486 … … 455 491 \param on On/Off 456 492 \sa testLayoutAttribute() 457 */ 493 */ 458 494 void QwtText::setLayoutAttribute( LayoutAttribute attribute, bool on ) 459 495 { 460 496 if ( on ) 461 d_data->layoutAttributes |= attribute;497 m_data->layoutAttributes |= attribute; 462 498 else 463 d_data->layoutAttributes &= ~attribute;499 m_data->layoutAttributes &= ~attribute; 464 500 } 465 501 … … 471 507 472 508 \sa setLayoutAttribute() 473 */ 509 */ 474 510 bool QwtText::testLayoutAttribute( LayoutAttribute attribute ) const 475 511 { 476 return d_data->layoutAttributes | attribute; 512 return m_data->layoutAttributes | attribute; 513 } 514 515 /*! 516 Find the height for a given width 517 518 \param width Width 519 \return Calculated height 520 */ 521 522 double QwtText::heightForWidth( double width ) const 523 { 524 return heightForWidth( width, QFont() ); 477 525 } 478 526 … … 484 532 485 533 \return Calculated height 486 */ 487 double QwtText::heightForWidth( double width, const QFont &defaultFont ) const534 */ 535 double QwtText::heightForWidth( double width, const QFont& defaultFont ) const 488 536 { 489 537 // We want to calculate in screen metrics. So 490 538 // we need a font that uses screen metrics 491 539 492 const QFont font( usedFont( defaultFont ), QApplication::desktop() );540 const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) ); 493 541 494 542 double h = 0; 495 543 496 if ( d_data->layoutAttributes & MinimumLayout )544 if ( m_data->layoutAttributes & MinimumLayout ) 497 545 { 498 546 double left, right, top, bottom; 499 d_data->textEngine->textMargins( font,d_data->text,547 m_data->textEngine->textMargins( font, m_data->text, 500 548 left, right, top, bottom ); 501 549 502 h = d_data->textEngine->heightForWidth(503 font, d_data->renderFlags,d_data->text,550 h = m_data->textEngine->heightForWidth( 551 font, m_data->renderFlags, m_data->text, 504 552 width + left + right ); 505 553 … … 508 556 else 509 557 { 510 h = d_data->textEngine->heightForWidth(511 font, d_data->renderFlags,d_data->text, width );558 h = m_data->textEngine->heightForWidth( 559 font, m_data->renderFlags, m_data->text, width ); 512 560 } 513 561 514 562 return h; 563 } 564 565 /*! 566 Returns the size, that is needed to render text 567 568 \return Calculated size 569 */ 570 QSizeF QwtText::textSize() const 571 { 572 return textSize( QFont() ); 515 573 } 516 574 … … 520 578 \param defaultFont Font of the text 521 579 \return Calculated size 522 */ 523 QSizeF QwtText::textSize( const QFont &defaultFont ) const580 */ 581 QSizeF QwtText::textSize( const QFont& defaultFont ) const 524 582 { 525 583 // We want to calculate in screen metrics. So 526 584 // we need a font that uses screen metrics 527 585 528 const QFont font( usedFont( defaultFont ), QApplication::desktop() );529 530 if ( ! d_layoutCache->textSize.isValid()531 || d_layoutCache->font != font )532 { 533 d_layoutCache->textSize =d_data->textEngine->textSize(534 font, d_data->renderFlags,d_data->text );535 d_layoutCache->font = font;536 } 537 538 QSizeF sz = d_layoutCache->textSize;539 540 if ( d_data->layoutAttributes & MinimumLayout )586 const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) ); 587 588 if ( !m_layoutCache->textSize.isValid() 589 || m_layoutCache->font != font ) 590 { 591 m_layoutCache->textSize = m_data->textEngine->textSize( 592 font, m_data->renderFlags, m_data->text ); 593 m_layoutCache->font = font; 594 } 595 596 QSizeF sz = m_layoutCache->textSize; 597 598 if ( m_data->layoutAttributes & MinimumLayout ) 541 599 { 542 600 double left, right, top, bottom; 543 d_data->textEngine->textMargins( font,d_data->text,601 m_data->textEngine->textMargins( font, m_data->text, 544 602 left, right, top, bottom ); 545 603 sz -= QSizeF( left + right, top + bottom ); … … 554 612 \param painter Painter 555 613 \param rect Rectangle 556 */ 557 void QwtText::draw( QPainter *painter, const QRectF&rect ) const558 { 559 if ( d_data->paintAttributes & PaintBackground )560 { 561 if ( d_data->borderPen != Qt::NoPen ||562 d_data->backgroundBrush != Qt::NoBrush )614 */ 615 void QwtText::draw( QPainter* painter, const QRectF& rect ) const 616 { 617 if ( m_data->paintAttributes & PaintBackground ) 618 { 619 if ( m_data->borderPen != Qt::NoPen || 620 m_data->backgroundBrush != Qt::NoBrush ) 563 621 { 564 622 painter->save(); 565 623 566 painter->setPen( d_data->borderPen );567 painter->setBrush( d_data->backgroundBrush );568 569 if ( d_data->borderRadius == 0 )624 painter->setPen( m_data->borderPen ); 625 painter->setBrush( m_data->backgroundBrush ); 626 627 if ( m_data->borderRadius == 0 ) 570 628 { 571 629 QwtPainter::drawRect( painter, rect ); … … 575 633 painter->setRenderHint( QPainter::Antialiasing, true ); 576 634 painter->drawRoundedRect( rect, 577 d_data->borderRadius,d_data->borderRadius );635 m_data->borderRadius, m_data->borderRadius ); 578 636 } 579 637 … … 584 642 painter->save(); 585 643 586 if ( d_data->paintAttributes & PaintUsingTextFont )587 { 588 painter->setFont( d_data->font );589 } 590 591 if ( d_data->paintAttributes & PaintUsingTextColor )592 { 593 if ( d_data->color.isValid() )594 painter->setPen( d_data->color );644 if ( m_data->paintAttributes & PaintUsingTextFont ) 645 { 646 painter->setFont( m_data->font ); 647 } 648 649 if ( m_data->paintAttributes & PaintUsingTextColor ) 650 { 651 if ( m_data->color.isValid() ) 652 painter->setPen( m_data->color ); 595 653 } 596 654 597 655 QRectF expandedRect = rect; 598 if ( d_data->layoutAttributes & MinimumLayout )656 if ( m_data->layoutAttributes & MinimumLayout ) 599 657 { 600 658 // We want to calculate in screen metrics. So 601 659 // we need a font that uses screen metrics 602 660 603 const QFont font( painter->font (), QApplication::desktop() );661 const QFont font = QwtPainter::scaledFont( painter->font() ); 604 662 605 663 double left, right, top, bottom; 606 d_data->textEngine->textMargins(607 font, d_data->text, left, right, top, bottom );664 m_data->textEngine->textMargins( 665 font, m_data->text, left, right, top, bottom ); 608 666 609 667 expandedRect.setTop( rect.top() - top ); … … 613 671 } 614 672 615 d_data->textEngine->draw( painter, expandedRect,616 d_data->renderFlags,d_data->text );673 m_data->textEngine->draw( painter, expandedRect, 674 m_data->renderFlags, m_data->text ); 617 675 618 676 painter->restore(); … … 627 685 628 686 If no text engine is registered for the format QwtPlainTextEngine 629 is returnd. 687 is returned. 630 688 631 689 \param text Text, needed in case of AutoText … … 633 691 634 692 \return Corresponding text engine 635 */ 636 const QwtTextEngine *QwtText::textEngine( const QString&text,693 */ 694 const QwtTextEngine* QwtText::textEngine( const QString& text, 637 695 QwtText::TextFormat format ) 638 696 { 639 return QwtTextEngineDict::dict().textEngine( text, format );697 return TextEngineDict::dict().textEngine( text, format ); 640 698 } 641 699 … … 651 709 \param engine Text engine 652 710 653 \sa QwtMathMLTextEngine654 711 \warning Using QwtText::AutoText does nothing. 655 */ 712 */ 656 713 void QwtText::setTextEngine( QwtText::TextFormat format, 657 QwtTextEngine *engine )658 { 659 QwtTextEngineDict::dict().setTextEngine( format, engine );714 QwtTextEngine* engine ) 715 { 716 TextEngineDict::dict().setTextEngine( format, engine ); 660 717 } 661 718 … … 667 724 \param format Text format 668 725 \return The text engine, or NULL if no engine is available. 669 */ 670 const QwtTextEngine *QwtText::textEngine( QwtText::TextFormat format ) 671 { 672 return QwtTextEngineDict::dict().textEngine( format ); 673 } 726 */ 727 const QwtTextEngine* QwtText::textEngine( QwtText::TextFormat format ) 728 { 729 return TextEngineDict::dict().textEngine( format ); 730 } 731 732 //! \return text().isNull() 733 bool QwtText::isNull() const 734 { 735 return m_data->text.isNull(); 736 } 737 738 //! \return text().isEmpty() 739 bool QwtText::isEmpty() const 740 { 741 return m_data->text.isEmpty(); 742 } 743
Note:
See TracChangeset
for help on using the changeset viewer.
