Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_legend_label.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_legend_label.cpp (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_legend_label.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_legend_label.h" 11 11 #include "qwt_legend_data.h" 12 #include "qwt_ math.h"12 #include "qwt_graphic.h" 13 13 #include "qwt_painter.h" 14 #include "qwt _symbol.h"15 #include "qwt_graphic.h" 14 #include "qwt.h" 15 16 16 #include <qpainter.h> 17 17 #include <qdrawutil.h> 18 18 #include <qstyle.h> 19 #include <qpen.h>20 19 #include <qevent.h> 21 20 #include <qstyleoption.h> 22 #include <qapplication.h>23 21 24 22 static const int ButtonFrame = 2; 25 23 static const int Margin = 2; 26 24 27 static QSize buttonShift( const QwtLegendLabel *w )25 static QSize buttonShift( const QwtLegendLabel* w ) 28 26 { 29 27 QStyleOption option; 30 option.init( w ); 28 option.initFrom( w ); 31 29 32 30 const int ph = w->style()->pixelMetric( … … 39 37 class QwtLegendLabel::PrivateData 40 38 { 41 public: 42 PrivateData() :43 itemMode( QwtLegendData::ReadOnly ) ,44 isDown( false ) ,45 spacing( Margin ) 39 public: 40 PrivateData() 41 : itemMode( QwtLegendData::ReadOnly ) 42 , isDown( false ) 43 , spacing( Margin ) 46 44 { 47 45 } … … 57 55 58 56 /*! 59 Set the attributes of the legend label 60 61 \param legendData Attributes of the label 62 \sa data() 63 */ 64 void QwtLegendLabel::setData( const QwtLegendData &legendData )65 { 66 d_data->legendData = legendData;57 Set the attributes of the legend label 58 59 \param legendData Attributes of the label 60 \sa data() 61 */ 62 void QwtLegendLabel::setData( const QwtLegendData& legendData ) 63 { 64 m_data->legendData = legendData; 67 65 68 66 const bool doUpdate = updatesEnabled(); 69 setUpdatesEnabled( false ); 67 if ( doUpdate ) 68 setUpdatesEnabled( false ); 70 69 71 70 setText( legendData.title() ); … … 76 75 77 76 if ( doUpdate ) 78 {79 77 setUpdatesEnabled( true ); 80 update(); 81 } 82 } 83 84 /*! 85 \return Attributes of the label 86 \sa setData(), QwtPlotItem::legendData() 87 */ 88 const QwtLegendData &QwtLegendLabel::data() const 89 { 90 return d_data->legendData; 91 } 92 93 /*! 94 \param parent Parent widget 95 */ 96 QwtLegendLabel::QwtLegendLabel( QWidget *parent ): 97 QwtTextLabel( parent ) 98 { 99 d_data = new PrivateData; 78 } 79 80 /*! 81 \return Attributes of the label 82 \sa setData(), QwtPlotItem::legendData() 83 */ 84 const QwtLegendData& QwtLegendLabel::data() const 85 { 86 return m_data->legendData; 87 } 88 89 /*! 90 \param parent Parent widget 91 */ 92 QwtLegendLabel::QwtLegendLabel( QWidget* parent ) 93 : QwtTextLabel( parent ) 94 { 95 m_data = new PrivateData; 100 96 setMargin( Margin ); 101 97 setIndent( Margin ); … … 105 101 QwtLegendLabel::~QwtLegendLabel() 106 102 { 107 delete d_data;108 d_data = NULL;103 delete m_data; 104 m_data = NULL; 109 105 } 110 106 … … 114 110 \param text Text label 115 111 \sa QwtTextLabel::text() 116 */ 117 void QwtLegendLabel::setText( const QwtText &text )112 */ 113 void QwtLegendLabel::setText( const QwtText& text ) 118 114 { 119 115 const int flags = Qt::AlignLeft | Qt::AlignVCenter … … 132 128 \param mode Item mode 133 129 \sa itemMode() 134 */ 130 */ 135 131 void QwtLegendLabel::setItemMode( QwtLegendData::Mode mode ) 136 132 { 137 if ( mode != d_data->itemMode )138 { 139 d_data->itemMode = mode;140 d_data->isDown = false;133 if ( mode != m_data->itemMode ) 134 { 135 m_data->itemMode = mode; 136 m_data->isDown = false; 141 137 142 138 setFocusPolicy( ( mode != QwtLegendData::ReadOnly ) … … 151 147 \return Item mode 152 148 \sa setItemMode() 153 */ 149 */ 154 150 QwtLegendData::Mode QwtLegendLabel::itemMode() const 155 151 { 156 return d_data->itemMode;157 } 158 159 /*! 160 Assign the icon 161 162 \param icon Pixmap representing a plot item 163 164 \sa icon(), QwtPlotItem::legendIcon() 165 */ 166 void QwtLegendLabel::setIcon( const QPixmap &icon )167 { 168 d_data->icon = icon;169 170 int indent = margin() + d_data->spacing;152 return m_data->itemMode; 153 } 154 155 /*! 156 Assign the icon 157 158 \param icon Pixmap representing a plot item 159 160 \sa icon(), QwtPlotItem::legendIcon() 161 */ 162 void QwtLegendLabel::setIcon( const QPixmap& icon ) 163 { 164 m_data->icon = icon; 165 166 int indent = margin() + m_data->spacing; 171 167 if ( icon.width() > 0 ) 172 indent += icon.width() + d_data->spacing; 168 { 169 const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &icon ); 170 indent += icon.width() / devicePixelRatio + m_data->spacing; 171 } 173 172 174 173 setIndent( indent ); … … 176 175 177 176 /*! 178 \return Pixmap representing a plot item 179 \sa setIcon() 180 */ 177 \return Pixmap representing a plot item 178 \sa setIcon() 179 */ 181 180 QPixmap QwtLegendLabel::icon() const 182 181 { 183 return d_data->icon;182 return m_data->icon; 184 183 } 185 184 … … 189 188 \param spacing Spacing 190 189 \sa spacing(), QwtTextLabel::margin() 191 */ 190 */ 192 191 void QwtLegendLabel::setSpacing( int spacing ) 193 192 { 194 193 spacing = qMax( spacing, 0 ); 195 if ( spacing != d_data->spacing )196 { 197 d_data->spacing = spacing;198 199 int indent = margin() + d_data->spacing;200 if ( d_data->icon.width() > 0 )201 indent += d_data->icon.width() +d_data->spacing;194 if ( spacing != m_data->spacing ) 195 { 196 m_data->spacing = spacing; 197 198 int indent = margin() + m_data->spacing; 199 if ( m_data->icon.width() > 0 ) 200 indent += m_data->icon.width() + m_data->spacing; 202 201 203 202 setIndent( indent ); … … 208 207 \return Spacing between icon and text 209 208 \sa setSpacing(), QwtTextLabel::margin() 210 */ 209 */ 211 210 int QwtLegendLabel::spacing() const 212 211 { 213 return d_data->spacing;212 return m_data->spacing; 214 213 } 215 214 … … 219 218 \param on check/uncheck 220 219 \sa setItemMode() 221 */ 220 */ 222 221 void QwtLegendLabel::setChecked( bool on ) 223 222 { 224 if ( d_data->itemMode == QwtLegendData::Checkable )223 if ( m_data->itemMode == QwtLegendData::Checkable ) 225 224 { 226 225 const bool isBlocked = signalsBlocked(); … … 236 235 bool QwtLegendLabel::isChecked() const 237 236 { 238 return d_data->itemMode == QwtLegendData::Checkable && isDown();237 return m_data->itemMode == QwtLegendData::Checkable && isDown(); 239 238 } 240 239 … … 242 241 void QwtLegendLabel::setDown( bool down ) 243 242 { 244 if ( down == d_data->isDown )243 if ( down == m_data->isDown ) 245 244 return; 246 245 247 d_data->isDown = down;246 m_data->isDown = down; 248 247 update(); 249 248 250 if ( d_data->itemMode == QwtLegendData::Clickable )251 { 252 if ( d_data->isDown )249 if ( m_data->itemMode == QwtLegendData::Clickable ) 250 { 251 if ( m_data->isDown ) 253 252 Q_EMIT pressed(); 254 253 else … … 259 258 } 260 259 261 if ( d_data->itemMode == QwtLegendData::Checkable )262 Q_EMIT checked( d_data->isDown );260 if ( m_data->itemMode == QwtLegendData::Checkable ) 261 Q_EMIT checked( m_data->isDown ); 263 262 } 264 263 … … 266 265 bool QwtLegendLabel::isDown() const 267 266 { 268 return d_data->isDown;267 return m_data->isDown; 269 268 } 270 269 … … 273 272 { 274 273 QSize sz = QwtTextLabel::sizeHint(); 275 sz.setHeight( qMax( sz.height(), d_data->icon.height() + 4 ) );276 277 if ( d_data->itemMode != QwtLegendData::ReadOnly )274 sz.setHeight( qMax( sz.height(), m_data->icon.height() + 4 ) ); 275 276 if ( m_data->itemMode != QwtLegendData::ReadOnly ) 278 277 { 279 278 sz += buttonShift( this ); 280 sz = sz.expandedTo( QApplication::globalStrut());279 sz = qwtExpandedToGlobalStrut( sz ); 281 280 } 282 281 … … 285 284 286 285 //! Paint event 287 void QwtLegendLabel::paintEvent( QPaintEvent *e )286 void QwtLegendLabel::paintEvent( QPaintEvent* e ) 288 287 { 289 288 const QRect cr = contentsRect(); … … 292 291 painter.setClipRegion( e->region() ); 293 292 294 if ( d_data->isDown )293 if ( m_data->isDown ) 295 294 { 296 295 qDrawWinButton( &painter, 0, 0, width(), height(), … … 300 299 painter.save(); 301 300 302 if ( d_data->isDown )301 if ( m_data->isDown ) 303 302 { 304 303 const QSize shiftSize = buttonShift( this ); … … 310 309 drawContents( &painter ); 311 310 312 if ( ! d_data->icon.isNull() )311 if ( !m_data->icon.isNull() ) 313 312 { 314 313 QRect iconRect = cr; 315 314 iconRect.setX( iconRect.x() + margin() ); 316 if ( d_data->itemMode != QwtLegendData::ReadOnly )315 if ( m_data->itemMode != QwtLegendData::ReadOnly ) 317 316 iconRect.setX( iconRect.x() + ButtonFrame ); 318 317 319 iconRect.setSize( d_data->icon.size() ); 318 const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &m_data->icon ); 319 iconRect.setSize( m_data->icon.size() / devicePixelRatio ); 320 320 iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) ); 321 321 322 painter.drawPixmap( iconRect, d_data->icon );322 painter.drawPixmap( iconRect, m_data->icon ); 323 323 } 324 324 … … 327 327 328 328 //! Handle mouse press events 329 void QwtLegendLabel::mousePressEvent( QMouseEvent *e )329 void QwtLegendLabel::mousePressEvent( QMouseEvent* e ) 330 330 { 331 331 if ( e->button() == Qt::LeftButton ) 332 332 { 333 switch ( d_data->itemMode )333 switch ( m_data->itemMode ) 334 334 { 335 335 case QwtLegendData::Clickable: … … 350 350 351 351 //! Handle mouse release events 352 void QwtLegendLabel::mouseReleaseEvent( QMouseEvent *e )352 void QwtLegendLabel::mouseReleaseEvent( QMouseEvent* e ) 353 353 { 354 354 if ( e->button() == Qt::LeftButton ) 355 355 { 356 switch ( d_data->itemMode )356 switch ( m_data->itemMode ) 357 357 { 358 358 case QwtLegendData::Clickable: … … 372 372 373 373 //! Handle key press events 374 void QwtLegendLabel::keyPressEvent( QKeyEvent *e )374 void QwtLegendLabel::keyPressEvent( QKeyEvent* e ) 375 375 { 376 376 if ( e->key() == Qt::Key_Space ) 377 377 { 378 switch ( d_data->itemMode )378 switch ( m_data->itemMode ) 379 379 { 380 380 case QwtLegendData::Clickable: … … 398 398 399 399 //! Handle key release events 400 void QwtLegendLabel::keyReleaseEvent( QKeyEvent *e )400 void QwtLegendLabel::keyReleaseEvent( QKeyEvent* e ) 401 401 { 402 402 if ( e->key() == Qt::Key_Space ) 403 403 { 404 switch ( d_data->itemMode )404 switch ( m_data->itemMode ) 405 405 { 406 406 case QwtLegendData::Clickable: … … 420 420 QwtTextLabel::keyReleaseEvent( e ); 421 421 } 422 423 #include "moc_qwt_legend_label.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
