Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_dial_needle.cpp


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_dial_needle.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_dial_needle.h"
    11 #include "qwt_global.h"
    1211#include "qwt_math.h"
    13 #include "qwt_painter.h"
     12
    1413#include <qapplication.h>
    1514#include <qpainter.h>
    1615#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
     18static 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 };
    2923
    3024    QPainterPath path;
    3125    for ( int i = 0; i < 7; i++ )
    3226    {
    33         const double angle = a[i] / 180.0 * M_PI;
    34         const double radius = r[i] * length;
    35 
    36         const double x = radius * qFastCos( angle );
    37         const double y = 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 );
    3832
    3933        path.lineTo( x, -y );
    … …  
    4539}
    4640
    47 static void qwtDrawStyle2Needle( QPainter *painter,
    48     const QPalette &palette, QPalette::ColorGroup colorGroup, double length )
    49 {
    50     const double ratioX = 0.7;
    51     const double ratioY = 0.3;
     41static 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;
    5246
    5347    QPainterPath path1;
    … …  
    6862}
    6963
    70 static void qwtDrawShadedPointer( QPainter *painter,
    71     const QColor &lightColor, const QColor &darkColor,
    72     double length, double width )
    73 {
    74     const double peak = qMax( length / 10.0, 5.0 );
    75 
    76     const double knobWidth = width + 8;
     64static 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;
    7771    QRectF knobRect( 0, 0, knobWidth, knobWidth );
    7872    knobRect.moveCenter( QPointF(0, 0) );
    … …  
    109103}
    110104
    111 static void qwtDrawArrowNeedle( QPainter *painter,
    112     const QPalette &palette, QPalette::ColorGroup colorGroup,
    113     double length, double width )
     105static void qwtDrawArrowNeedle( QPainter* painter,
     106    const QPalette& palette, QPalette::ColorGroup colorGroup,
     107    qreal length, qreal width )
    114108{
    115109    if ( width <= 0 )
    116         width = qMax( length * 0.06, 9.0 );
    117 
    118     const double peak = 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 );
    119113
    120114    QPainterPath path;
    … …  
    146140}
    147141
    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 );
     142static void qwtDrawTriangleNeedle( QPainter* painter,
     143    const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
     144{
     145    const qreal width = qRound( length / 3.0 );
    153146
    154147    QPainterPath path[4];
    … …  
    167160
    168161
    169     const int colorOffset =  10;
     162    const int colorOffset = 10;
    170163    const QColor darkColor = palette.color( colorGroup, QPalette::Dark );
    171164    const QColor lightColor = palette.color( colorGroup, QPalette::Light );
    … …  
    187180
    188181//! Constructor
    189 QwtDialNeedle::QwtDialNeedle():
    190     d_palette( QApplication::palette() )
     182QwtDialNeedle::QwtDialNeedle()
     183    : m_palette( QApplication::palette() )
    191184{
    192185}
    … …  
    201194
    202195    \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() const
    213 {
    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 &center, double length, double direction,
     196 */
     197void QwtDialNeedle::setPalette( const QPalette& palette )
     198{
     199    m_palette = palette;
     200}
     201
     202/*!
     203   \return the palette of the needle.
     204 */
     205const 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 */
     219void QwtDialNeedle::draw( QPainter* painter,
     220    const QPointF& center, double length, double direction,
    228221    QPalette::ColorGroup colorGroup ) const
    229222{
    … …  
    239232
    240233//!  Draw the knob
    241 void QwtDialNeedle::drawKnob( QPainter *painter,
    242     double width, const QBrush &brush, bool sunken ) const
     234void QwtDialNeedle::drawKnob( QPainter* painter,
     235    double width, const QBrush& brush, bool sunken ) const
    243236{
    244237    QPalette palette( brush.color() );
    … …  
    251244
    252245    QRectF rect( 0.0, 0.0, width, width );
    253     rect.moveCenter( painter->combinedTransform().map( QPointF() ) );
     246    rect.moveCenter( painter->transform().map( QPointF() ) );
    254247
    255248    QLinearGradient gradient( rect.topLeft(), rect.bottomRight() );
    … …  
    271264
    272265/*!
    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 */
    280273QwtDialSimpleNeedle::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 )
    285278{
    286279    QPalette palette;
    … …  
    292285
    293286/*!
    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 */
    298291void QwtDialSimpleNeedle::setWidth( double width )
    299292{
    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 */
    307300double QwtDialSimpleNeedle::width() const
    308301{
    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 */
     312void QwtDialSimpleNeedle::drawNeedle( QPainter* painter,
    320313    double length, QPalette::ColorGroup colorGroup ) const
    321314{
    322     double knobWidth = 0.0;
    323     double width = d_width;
    324 
    325     if ( d_style == Arrow )
     315    qreal knobWidth = 0.0;
     316    qreal width = m_width;
     317
     318    if ( m_style == Arrow )
    326319    {
    327320        if ( width <= 0.0 )
    328             width = qMax(length * 0.06, 6.0);
     321            width = qwtMaxF( length * 0.06, 6.0 );
    329322
    330323        qwtDrawArrowNeedle( painter,
    331324            palette(), colorGroup, length, width );
    332325
    333         knobWidth = qMin( width * 2.0, 0.2 * length );
     326        knobWidth = qwtMinF( width * 2.0, 0.2 * length );
    334327    }
    335328    else
    … …  
    344337        painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) );
    345338
    346         knobWidth = qMax( 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 )
    350343    {
    351344        drawKnob( painter, knobWidth,
    … …  
    356349//! Constructor
    357350QwtCompassMagnetNeedle::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 )
    360353{
    361354    QPalette palette;
    … …  
    373366    \param length Length of the needle
    374367    \param colorGroup Color group, used for painting
    375 */
    376 void QwtCompassMagnetNeedle::drawNeedle( QPainter *painter,
     368 */
     369void QwtCompassMagnetNeedle::drawNeedle( QPainter* painter,
    377370    double length, QPalette::ColorGroup colorGroup ) const
    378371{
    379     if ( d_style == ThinStyle )
    380     {
    381         const double width = qMax( length / 6.0, 3.0 );
     372    if ( m_style == ThinStyle )
     373    {
     374        const qreal width = qwtMaxF( length / 6.0, 3.0 );
    382375
    383376        const int colorOffset = 10;
    … …  
    413406   \param light Light color
    414407   \param dark Dark color
    415 */
     408 */
    416409QwtCompassWindArrow::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 )
    419412{
    420413    QPalette palette;
    … …  
    426419
    427420/*!
    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 */
     427void QwtCompassWindArrow::drawNeedle( QPainter* painter,
    435428    double length, QPalette::ColorGroup colorGroup ) const
    436429{
    437     if ( d_style == Style1 )
     430    if ( m_style == Style1 )
    438431        qwtDrawStyle1Needle( painter, palette(), colorGroup, length );
    439432    else
Note: See TracChangeset for help on using the changeset viewer.