Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_dial_needle.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_dial_needle.cpp (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_dial_needle.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_dial_needle.h" 11 #include "qwt_global.h"12 11 #include "qwt_math.h" 13 #include "qwt_painter.h" 12 14 13 #include <qapplication.h> 15 14 #include <qpainter.h> 16 15 #include <qpainterpath.h> 17 18 #if QT_VERSION < 0x040601 19 #define qFastSin(x) qSin(x) 20 #define qFastCos(x) qCos(x) 21 #endif 22 23 static void qwtDrawStyle1Needle( QPainter *painter, 24 const QPalette &palette, QPalette::ColorGroup colorGroup, 25 double length ) 26 { 27 const double r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 }; 28 const double a[] = { -45, -20, -15, 0, 15, 20, 45 }; 16 #include <qmath.h> 17 18 static void qwtDrawStyle1Needle( QPainter* painter, 19 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length ) 20 { 21 const qreal r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 }; 22 const qreal a[] = { -45, -20, -15, 0, 15, 20, 45 }; 29 23 30 24 QPainterPath path; 31 25 for ( int i = 0; i < 7; i++ ) 32 26 { 33 const doubleangle = a[i] / 180.0 * M_PI;34 const doubleradius = r[i] * length;35 36 const doublex = radius * qFastCos( angle );37 const doubley = radius * qFastSin( angle );27 const qreal angle = a[i] / 180.0 * M_PI; 28 const qreal radius = r[i] * length; 29 30 const qreal x = radius * qFastCos( angle ); 31 const qreal y = radius * qFastSin( angle ); 38 32 39 33 path.lineTo( x, -y ); … … 45 39 } 46 40 47 static void qwtDrawStyle2Needle( QPainter *painter,48 const QPalette &palette, QPalette::ColorGroup colorGroup,doublelength )49 { 50 const doubleratioX = 0.7;51 const doubleratioY = 0.3;41 static void qwtDrawStyle2Needle( QPainter* painter, 42 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length ) 43 { 44 const qreal ratioX = 0.7; 45 const qreal ratioY = 0.3; 52 46 53 47 QPainterPath path1; … … 68 62 } 69 63 70 static void qwtDrawShadedPointer( QPainter *painter,71 const QColor &lightColor, const QColor&darkColor,72 doublelength,doublewidth )73 { 74 const doublepeak = qMax( length / 10.0, 5.0 );75 76 const doubleknobWidth = width + 8;64 static void qwtDrawShadedPointer( QPainter* painter, 65 const QColor& lightColor, const QColor& darkColor, 66 qreal length, qreal width ) 67 { 68 const qreal peak = qwtMaxF( length / 10.0, 5.0 ); 69 70 const qreal knobWidth = width + 8; 77 71 QRectF knobRect( 0, 0, knobWidth, knobWidth ); 78 72 knobRect.moveCenter( QPointF(0, 0) ); … … 109 103 } 110 104 111 static void qwtDrawArrowNeedle( QPainter *painter,112 const QPalette &palette, QPalette::ColorGroup colorGroup,113 doublelength,doublewidth )105 static void qwtDrawArrowNeedle( QPainter* painter, 106 const QPalette& palette, QPalette::ColorGroup colorGroup, 107 qreal length, qreal width ) 114 108 { 115 109 if ( width <= 0 ) 116 width = q Max( length * 0.06, 9.0 );117 118 const doublepeak = qMax( 2.0, 0.4 * width );110 width = qwtMaxF( length * 0.06, 9.0 ); 111 112 const qreal peak = qwtMaxF( 2.0, 0.4 * width ); 119 113 120 114 QPainterPath path; … … 146 140 } 147 141 148 static void qwtDrawTriangleNeedle( QPainter *painter, 149 const QPalette &palette, QPalette::ColorGroup colorGroup, 150 double length ) 151 { 152 const double width = qRound( length / 3.0 ); 142 static void qwtDrawTriangleNeedle( QPainter* painter, 143 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length ) 144 { 145 const qreal width = qRound( length / 3.0 ); 153 146 154 147 QPainterPath path[4]; … … 167 160 168 161 169 const int colorOffset = 10;162 const int colorOffset = 10; 170 163 const QColor darkColor = palette.color( colorGroup, QPalette::Dark ); 171 164 const QColor lightColor = palette.color( colorGroup, QPalette::Light ); … … 187 180 188 181 //! Constructor 189 QwtDialNeedle::QwtDialNeedle() :190 d_palette( QApplication::palette() )182 QwtDialNeedle::QwtDialNeedle() 183 : m_palette( QApplication::palette() ) 191 184 { 192 185 } … … 201 194 202 195 \param palette New Palette 203 */ 204 void QwtDialNeedle::setPalette( const QPalette &palette )205 { 206 d_palette = palette;207 } 208 209 /*! 210 \return the palette of the needle. 211 */ 212 const QPalette &QwtDialNeedle::palette() const213 { 214 return d_palette;215 } 216 217 /*! 218 Draw the needle 219 220 \param painter Painter 221 \param center Center of the dial, start position for the needle 222 \param length Length of the needle 223 \param direction Direction of the needle, in degrees counter clockwise 224 \param colorGroup Color group, used for painting 225 */ 226 void QwtDialNeedle::draw( QPainter *painter,227 const QPointF ¢er, double length, double direction,196 */ 197 void QwtDialNeedle::setPalette( const QPalette& palette ) 198 { 199 m_palette = palette; 200 } 201 202 /*! 203 \return the palette of the needle. 204 */ 205 const QPalette& QwtDialNeedle::palette() const 206 { 207 return m_palette; 208 } 209 210 /*! 211 Draw the needle 212 213 \param painter Painter 214 \param center Center of the dial, start position for the needle 215 \param length Length of the needle 216 \param direction Direction of the needle, in degrees counter clockwise 217 \param colorGroup Color group, used for painting 218 */ 219 void QwtDialNeedle::draw( QPainter* painter, 220 const QPointF& center, double length, double direction, 228 221 QPalette::ColorGroup colorGroup ) const 229 222 { … … 239 232 240 233 //! Draw the knob 241 void QwtDialNeedle::drawKnob( QPainter *painter,242 double width, const QBrush &brush, bool sunken ) const234 void QwtDialNeedle::drawKnob( QPainter* painter, 235 double width, const QBrush& brush, bool sunken ) const 243 236 { 244 237 QPalette palette( brush.color() ); … … 251 244 252 245 QRectF rect( 0.0, 0.0, width, width ); 253 rect.moveCenter( painter-> combinedTransform().map( QPointF() ) );246 rect.moveCenter( painter->transform().map( QPointF() ) ); 254 247 255 248 QLinearGradient gradient( rect.topLeft(), rect.bottomRight() ); … … 271 264 272 265 /*! 273 Constructor 274 275 \param style Style 276 \param hasKnob With/Without knob 277 \param mid Middle color 278 \param base Base color 279 */ 266 Constructor 267 268 \param style Style 269 \param hasKnob With/Without knob 270 \param mid Middle color 271 \param base Base color 272 */ 280 273 QwtDialSimpleNeedle::QwtDialSimpleNeedle( Style style, bool hasKnob, 281 const QColor&mid, const QColor&base ):282 d_style( style ),283 d_hasKnob( hasKnob ),284 d_width( -1 )274 const QColor& mid, const QColor& base ): 275 m_style( style ), 276 m_hasKnob( hasKnob ), 277 m_width( -1 ) 285 278 { 286 279 QPalette palette; … … 292 285 293 286 /*! 294 Set the width of the needle 295 \param width Width 296 \sa width() 297 */ 287 Set the width of the needle 288 \param width Width 289 \sa width() 290 */ 298 291 void QwtDialSimpleNeedle::setWidth( double width ) 299 292 { 300 d_width = width;301 } 302 303 /*! 304 \return the width of the needle 305 \sa setWidth() 306 */ 293 m_width = width; 294 } 295 296 /*! 297 \return the width of the needle 298 \sa setWidth() 299 */ 307 300 double QwtDialSimpleNeedle::width() const 308 301 { 309 return d_width;310 } 311 312 /*! 313 Draw the needle 314 315 \param painter Painter 316 \param length Length of the needle 317 \param colorGroup Color group, used for painting 318 */ 319 void QwtDialSimpleNeedle::drawNeedle( QPainter *painter,302 return m_width; 303 } 304 305 /*! 306 Draw the needle 307 308 \param painter Painter 309 \param length Length of the needle 310 \param colorGroup Color group, used for painting 311 */ 312 void QwtDialSimpleNeedle::drawNeedle( QPainter* painter, 320 313 double length, QPalette::ColorGroup colorGroup ) const 321 314 { 322 doubleknobWidth = 0.0;323 doublewidth =d_width;324 325 if ( d_style == Arrow )315 qreal knobWidth = 0.0; 316 qreal width = m_width; 317 318 if ( m_style == Arrow ) 326 319 { 327 320 if ( width <= 0.0 ) 328 width = q Max(length * 0.06, 6.0);321 width = qwtMaxF( length * 0.06, 6.0 ); 329 322 330 323 qwtDrawArrowNeedle( painter, 331 324 palette(), colorGroup, length, width ); 332 325 333 knobWidth = q Min( width * 2.0, 0.2 * length );326 knobWidth = qwtMinF( width * 2.0, 0.2 * length ); 334 327 } 335 328 else … … 344 337 painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) ); 345 338 346 knobWidth = q Max( width * 3.0, 5.0 );347 } 348 349 if ( d_hasKnob && knobWidth > 0.0 )339 knobWidth = qwtMaxF( width * 3.0, 5.0 ); 340 } 341 342 if ( m_hasKnob && knobWidth > 0.0 ) 350 343 { 351 344 drawKnob( painter, knobWidth, … … 356 349 //! Constructor 357 350 QwtCompassMagnetNeedle::QwtCompassMagnetNeedle( Style style, 358 const QColor&light, const QColor&dark ):359 d_style( style )351 const QColor& light, const QColor& dark ): 352 m_style( style ) 360 353 { 361 354 QPalette palette; … … 373 366 \param length Length of the needle 374 367 \param colorGroup Color group, used for painting 375 */ 376 void QwtCompassMagnetNeedle::drawNeedle( QPainter *painter,368 */ 369 void QwtCompassMagnetNeedle::drawNeedle( QPainter* painter, 377 370 double length, QPalette::ColorGroup colorGroup ) const 378 371 { 379 if ( d_style == ThinStyle )380 { 381 const doublewidth = qMax( length / 6.0, 3.0 );372 if ( m_style == ThinStyle ) 373 { 374 const qreal width = qwtMaxF( length / 6.0, 3.0 ); 382 375 383 376 const int colorOffset = 10; … … 413 406 \param light Light color 414 407 \param dark Dark color 415 */ 408 */ 416 409 QwtCompassWindArrow::QwtCompassWindArrow( Style style, 417 const QColor&light, const QColor&dark ):418 d_style( style )410 const QColor& light, const QColor& dark ): 411 m_style( style ) 419 412 { 420 413 QPalette palette; … … 426 419 427 420 /*! 428 Draw the needle 429 430 \param painter Painter 431 \param length Length of the needle 432 \param colorGroup Color group, used for painting 433 */ 434 void QwtCompassWindArrow::drawNeedle( QPainter *painter,421 Draw the needle 422 423 \param painter Painter 424 \param length Length of the needle 425 \param colorGroup Color group, used for painting 426 */ 427 void QwtCompassWindArrow::drawNeedle( QPainter* painter, 435 428 double length, QPalette::ColorGroup colorGroup ) const 436 429 { 437 if ( d_style == Style1 )430 if ( m_style == Style1 ) 438 431 qwtDrawStyle1Needle( painter, palette(), colorGroup, length ); 439 432 else
Note:
See TracChangeset
for help on using the changeset viewer.
