Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_textlabel.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_textlabel.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_textlabel.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_textlabel.h" 11 11 #include "qwt_painter.h" 12 #include "qwt_scale_map.h" 12 #include "qwt_text.h" 13 #include "qwt_math.h" 14 13 15 #include <qpainter.h> 16 #include <qpaintengine.h> 14 17 #include <qpixmap.h> 15 #include <qmath.h>16 18 17 19 static QRect qwtItemRect( int renderFlags, 18 const QRectF &rect, const QSizeF&itemSize )20 const QRectF& rect, const QSizeF& itemSize ) 19 21 { 20 22 int x; … … 51 53 class QwtPlotTextLabel::PrivateData 52 54 { 53 public: 54 PrivateData() :55 margin( 5 ) 55 public: 56 PrivateData() 57 : margin( 5 ) 56 58 { 57 59 } … … 76 78 77 79 \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ() 78 */ 79 80 QwtPlotTextLabel::QwtPlotTextLabel() :81 QwtPlotItem( QwtText( "Label" ) ) 82 { 83 d_data = new PrivateData;80 */ 81 82 QwtPlotTextLabel::QwtPlotTextLabel() 83 : QwtPlotItem( QwtText( "Label" ) ) 84 { 85 m_data = new PrivateData; 84 86 85 87 setItemAttribute( QwtPlotItem::AutoScale, false ); … … 92 94 QwtPlotTextLabel::~QwtPlotTextLabel() 93 95 { 94 delete d_data;96 delete m_data; 95 97 } 96 98 … … 102 104 103 105 /*! 104 Set the text 105 106 The label will be aligned to the plot canvas according to 107 the alignment flags of text. 108 109 \param text Text to be displayed 110 111 \sa text(), QwtText::renderFlags() 112 */ 113 void QwtPlotTextLabel::setText( const QwtText &text )114 { 115 if ( d_data->text != text )116 { 117 d_data->text = text;106 Set the text 107 108 The label will be aligned to the plot canvas according to 109 the alignment flags of text. 110 111 \param text Text to be displayed 112 113 \sa text(), QwtText::renderFlags() 114 */ 115 void QwtPlotTextLabel::setText( const QwtText& text ) 116 { 117 if ( m_data->text != text ) 118 { 119 m_data->text = text; 118 120 119 121 invalidateCache(); … … 123 125 124 126 /*! 125 \return Text to be displayed 126 \sa setText() 127 */ 127 \return Text to be displayed 128 \sa setText() 129 */ 128 130 QwtText QwtPlotTextLabel::text() const 129 131 { 130 return d_data->text;131 } 132 133 /*! 134 Set the margin 135 136 The margin is the distance between the contentsRect() 137 of the plot canvas and the rectangle where the label can 138 be displayed. 139 140 \param margin Margin 141 142 \sa margin(), textRect() 132 return m_data->text; 133 } 134 135 /*! 136 Set the margin 137 138 The margin is the distance between the contentsRect() 139 of the plot canvas and the rectangle where the label can 140 be displayed. 141 142 \param margin Margin 143 144 \sa margin(), textRect() 143 145 */ 144 146 void QwtPlotTextLabel::setMargin( int margin ) 145 147 { 146 148 margin = qMax( margin, 0 ); 147 if ( d_data->margin != margin )148 { 149 d_data->margin = margin;149 if ( m_data->margin != margin ) 150 { 151 m_data->margin = margin; 150 152 itemChanged(); 151 153 } … … 153 155 154 156 /*! 155 \return Margin added to the contentsMargins() of the canvas 156 \sa setMargin() 157 */ 157 \return Margin added to the contentsMargins() of the canvas 158 \sa setMargin() 159 */ 158 160 int QwtPlotTextLabel::margin() const 159 161 { 160 return d_data->margin;161 } 162 163 /*! 164 Draw the text label 165 166 \param painter Painter 167 \param xMap x Scale Map 168 \param yMap y Scale Map 169 \param canvasRect Contents rectangle of the canvas in painter coordinates 170 171 \sa textRect() 172 */ 173 174 void QwtPlotTextLabel::draw( QPainter *painter,175 const QwtScaleMap &xMap, const QwtScaleMap&yMap,176 const QRectF &canvasRect ) const162 return m_data->margin; 163 } 164 165 /*! 166 Draw the text label 167 168 \param painter Painter 169 \param xMap x Scale Map 170 \param yMap y Scale Map 171 \param canvasRect Contents rectangle of the canvas in painter coordinates 172 173 \sa textRect() 174 */ 175 176 void QwtPlotTextLabel::draw( QPainter* painter, 177 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 178 const QRectF& canvasRect ) const 177 179 { 178 180 Q_UNUSED( xMap ); 179 181 Q_UNUSED( yMap ); 180 182 181 const int m = d_data->margin;183 const int m = m_data->margin; 182 184 183 185 const QRectF rect = textRect( canvasRect.adjusted( m, m, -m, -m ), 184 d_data->text.textSize( painter->font() ) );186 m_data->text.textSize( painter->font() ) ); 185 187 186 188 bool doCache = QwtPainter::roundingAlignment( painter ); … … 208 210 209 211 int pw = 0; 210 if ( d_data->text.borderPen().style() != Qt::NoPen )211 pw = qMax( d_data->text.borderPen().width(), 1 );212 if ( m_data->text.borderPen().style() != Qt::NoPen ) 213 pw = qMax( m_data->text.borderPen().width(), 1 ); 212 214 213 215 QRect pixmapRect; 214 pixmapRect.setLeft( qFloor( rect.left() ) - pw ); 215 pixmapRect.setTop( qFloor( rect.top() ) - pw ); 216 pixmapRect.setRight( qCeil( rect.right() ) + pw ); 217 pixmapRect.setBottom( qCeil( rect.bottom() ) + pw ); 218 219 #define QWT_HIGH_DPI 1 220 221 #if QT_VERSION >= 0x050100 && QWT_HIGH_DPI 222 const qreal pixelRatio = painter->device()->devicePixelRatio(); 216 pixmapRect.setLeft( qwtFloor( rect.left() ) - pw ); 217 pixmapRect.setTop( qwtFloor( rect.top() ) - pw ); 218 pixmapRect.setRight( qwtCeil( rect.right() ) + pw ); 219 pixmapRect.setBottom( qwtCeil( rect.bottom() ) + pw ); 220 221 #if QT_VERSION >= 0x050000 222 const qreal pixelRatio = QwtPainter::devicePixelRatio( painter->device() ); 223 223 const QSize scaledSize = pixmapRect.size() * pixelRatio; 224 224 #else 225 225 const QSize scaledSize = pixmapRect.size(); 226 226 #endif 227 if ( d_data->pixmap.isNull() || 228 ( scaledSize != d_data->pixmap.size() ) ) 227 228 if ( m_data->pixmap.isNull() || 229 ( scaledSize != m_data->pixmap.size() ) ) 229 230 { 230 d_data->pixmap = QPixmap( scaledSize );231 #if QT_VERSION >= 0x050 100 && QWT_HIGH_DPI232 d_data->pixmap.setDevicePixelRatio( pixelRatio );231 m_data->pixmap = QPixmap( scaledSize ); 232 #if QT_VERSION >= 0x050000 233 m_data->pixmap.setDevicePixelRatio( pixelRatio ); 233 234 #endif 234 d_data->pixmap.fill( Qt::transparent );235 m_data->pixmap.fill( Qt::transparent ); 235 236 236 237 const QRect r( pw, pw, 237 238 pixmapRect.width() - 2 * pw, pixmapRect.height() - 2 * pw ); 238 239 239 QPainter pmPainter( & d_data->pixmap );240 d_data->text.draw( &pmPainter, r );240 QPainter pmPainter( &m_data->pixmap ); 241 m_data->text.draw( &pmPainter, r ); 241 242 } 242 243 243 painter->drawPixmap( pixmapRect, d_data->pixmap );244 painter->drawPixmap( pixmapRect, m_data->pixmap ); 244 245 } 245 246 else 246 247 { 247 d_data->text.draw( painter, rect );248 m_data->text.draw( painter, rect ); 248 249 } 249 250 } … … 261 262 */ 262 263 QRectF QwtPlotTextLabel::textRect( 263 const QRectF &rect, const QSizeF&textSize ) const264 { 265 return qwtItemRect( d_data->text.renderFlags(), rect, textSize );264 const QRectF& rect, const QSizeF& textSize ) const 265 { 266 return qwtItemRect( m_data->text.renderFlags(), rect, textSize ); 266 267 } 267 268 … … 269 270 void QwtPlotTextLabel::invalidateCache() 270 271 { 271 d_data->pixmap = QPixmap();272 } 272 m_data->pixmap = QPixmap(); 273 }
Note:
See TracChangeset
for help on using the changeset viewer.
