Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_analog_clock.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_analog_clock.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_analog_clock.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_analog_clock.h" 11 #include "qwt_dial_needle.h" 11 12 #include "qwt_round_scale_draw.h" 12 #include <qmath.h> 13 #include "qwt_text.h" 14 #include "qwt_math.h" 15 13 16 #include <qlocale.h> 14 15 class QwtAnalogClockScaleDraw: public QwtRoundScaleDraw 16 { 17 public: 18 QwtAnalogClockScaleDraw() 19 { 20 setSpacing( 8 ); 21 22 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 23 24 setTickLength( QwtScaleDiv::MinorTick, 2 ); 25 setTickLength( QwtScaleDiv::MediumTick, 4 ); 26 setTickLength( QwtScaleDiv::MajorTick, 8 ); 27 28 setPenWidth( 1 ); 29 } 30 31 virtual QwtText label( double value ) const 32 { 33 if ( qFuzzyCompare( value + 1.0, 1.0 ) ) 34 value = 60.0 * 60.0 * 12.0; 35 36 return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) ); 37 } 38 }; 39 40 /*! 41 Constructor 42 \param parent Parent widget 43 */ 44 QwtAnalogClock::QwtAnalogClock( QWidget *parent ): 45 QwtDial( parent ) 17 #include <qdatetime.h> 18 19 namespace 20 { 21 class QwtAnalogClockScaleDraw QWT_FINAL : public QwtRoundScaleDraw 22 { 23 public: 24 QwtAnalogClockScaleDraw() 25 { 26 setSpacing( 8 ); 27 28 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 29 30 setTickLength( QwtScaleDiv::MinorTick, 2 ); 31 setTickLength( QwtScaleDiv::MediumTick, 4 ); 32 setTickLength( QwtScaleDiv::MajorTick, 8 ); 33 34 setPenWidthF( 1.0 ); 35 } 36 37 virtual QwtText label( double value ) const QWT_OVERRIDE 38 { 39 if ( qFuzzyCompare( value + 1.0, 1.0 ) ) 40 value = 60.0 * 60.0 * 12.0; 41 42 return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) ); 43 } 44 }; 45 } 46 47 /*! 48 Constructor 49 \param parent Parent widget 50 */ 51 QwtAnalogClock::QwtAnalogClock( QWidget* parent ) 52 : QwtDial( parent ) 46 53 { 47 54 setWrapping( true ); … … 55 62 const int secondsPerHour = 60.0 * 60.0; 56 63 57 QList< double> majorTicks;58 QList< double> minorTicks;64 QList< double > majorTicks; 65 QList< double > minorTicks; 59 66 60 67 for ( int i = 0; i < 12; i++ ) … … 91 98 } 92 99 93 QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(100 QwtDialSimpleNeedle* hand = new QwtDialSimpleNeedle( 94 101 QwtDialSimpleNeedle::Arrow, true, handColor, knobColor ); 95 102 hand->setWidth( width ); 96 103 97 d_hand[i] = NULL;98 setHand( static_cast< Hand>( i ), hand );104 m_hand[i] = NULL; 105 setHand( static_cast< Hand >( i ), hand ); 99 106 } 100 107 } … … 104 111 { 105 112 for ( int i = 0; i < NHands; i++ ) 106 delete d_hand[i];107 } 108 109 /*! 110 Nop method, use setHand() instead 111 \sa setHand() 112 */ 113 void QwtAnalogClock::setNeedle( QwtDialNeedle * )113 delete m_hand[i]; 114 } 115 116 /*! 117 Nop method, use setHand() instead 118 \sa setHand() 119 */ 120 void QwtAnalogClock::setNeedle( QwtDialNeedle* ) 114 121 { 115 122 // no op … … 122 129 \param needle Hand 123 130 \sa hand() 124 */ 125 void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle *needle )131 */ 132 void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle* needle ) 126 133 { 127 134 if ( hand >= 0 && hand < NHands ) 128 135 { 129 delete d_hand[hand];130 d_hand[hand] = needle;131 } 132 } 133 134 /*! 135 \return Clock hand 136 \param hd Specifies the type of hand 137 \sa setHand() 138 */ 139 QwtDialNeedle *QwtAnalogClock::hand( Hand hd )136 delete m_hand[hand]; 137 m_hand[hand] = needle; 138 } 139 } 140 141 /*! 142 \return Clock hand 143 \param hd Specifies the type of hand 144 \sa setHand() 145 */ 146 QwtDialNeedle* QwtAnalogClock::hand( Hand hd ) 140 147 { 141 148 if ( hd < 0 || hd >= NHands ) 142 149 return NULL; 143 150 144 return d_hand[hd];145 } 146 147 /*! 148 \return Clock hand 149 \param hd Specifies the type of hand 150 \sa setHand() 151 */ 152 const QwtDialNeedle *QwtAnalogClock::hand( Hand hd ) const153 { 154 return const_cast<QwtAnalogClock *>( this )->hand( hd );155 } 156 157 /*! 158 \brief Set the current time 159 */ 151 return m_hand[hd]; 152 } 153 154 /*! 155 \return Clock hand 156 \param hd Specifies the type of hand 157 \sa setHand() 158 */ 159 const QwtDialNeedle* QwtAnalogClock::hand( Hand hd ) const 160 { 161 return const_cast< QwtAnalogClock* >( this )->hand( hd ); 162 } 163 164 /*! 165 \brief Set the current time 166 */ 160 167 void QwtAnalogClock::setCurrentTime() 161 168 { … … 164 171 165 172 /*! 166 Set a time 167 \param time Time to display 168 */ 169 void QwtAnalogClock::setTime( const QTime &time )173 Set a time 174 \param time Time to display 175 */ 176 void QwtAnalogClock::setTime( const QTime& time ) 170 177 { 171 178 if ( time.isValid() ) … … 179 186 180 187 /*! 181 \brief Draw the needle 182 183 A clock has no single needle but three hands instead. drawNeedle() 184 translates value() into directions for the hands and calls 185 drawHand(). 186 187 \param painter Painter 188 \param center Center of the clock 189 \param radius Maximum length for the hands 190 \param dir Dummy, not used. 191 \param colorGroup ColorGroup 192 193 \sa drawHand() 194 */ 195 void QwtAnalogClock::drawNeedle( QPainter *painter, const QPointF¢er,196 double radius, double dir, QPalette::ColorGroup colorGroup ) const 197 { 198 Q_UNUSED( dir ); 188 \brief Draw the needle 189 190 A clock has no single needle but three hands instead. drawNeedle() 191 translates value() into directions for the hands and calls 192 drawHand(). 193 194 \param painter Painter 195 \param center Center of the clock 196 \param radius Maximum length for the hands 197 \param direction Dummy, not used. 198 \param colorGroup ColorGroup 199 200 \sa drawHand() 201 */ 202 void QwtAnalogClock::drawNeedle( QPainter* painter, const QPointF& center, 203 double radius, double direction, QPalette::ColorGroup colorGroup ) const 204 { 205 Q_UNUSED( direction ); 199 206 200 207 if ( isValid() ) … … 202 209 const double hours = value() / ( 60.0 * 60.0 ); 203 210 const double minutes = 204 ( value() - qFloor(hours) * 60.0 * 60.0 ) / 60.0;205 const double seconds = value() - qFloor(hours) * 60.0 * 60.0206 - qFloor(minutes) * 60.0;211 ( value() - std::floor(hours) * 60.0 * 60.0 ) / 60.0; 212 const double seconds = value() - std::floor(hours) * 60.0 * 60.0 213 - std::floor(minutes) * 60.0; 207 214 208 215 double angle[NHands]; … … 214 221 { 215 222 const double d = 360.0 - angle[hand] - origin(); 216 drawHand( painter, static_cast< Hand>( hand ),223 drawHand( painter, static_cast< Hand >( hand ), 217 224 center, radius, d, colorGroup ); 218 225 } … … 221 228 222 229 /*! 223 Draw a clock hand 224 225 \param painter Painter 226 \param hd Specify the type of hand 227 \param center Center of the clock 228 \param radius Maximum length for the hands 229 \param direction Direction of the hand in degrees, counter clockwise 230 \param cg ColorGroup 231 */ 232 void QwtAnalogClock::drawHand( QPainter *painter, Hand hd,233 const QPointF ¢er, double radius, double direction,230 Draw a clock hand 231 232 \param painter Painter 233 \param hd Specify the type of hand 234 \param center Center of the clock 235 \param radius Maximum length for the hands 236 \param direction Direction of the hand in degrees, counter clockwise 237 \param cg ColorGroup 238 */ 239 void QwtAnalogClock::drawHand( QPainter* painter, Hand hd, 240 const QPointF& center, double radius, double direction, 234 241 QPalette::ColorGroup cg ) const 235 242 { 236 const QwtDialNeedle *needle = hand( hd );243 const QwtDialNeedle* needle = hand( hd ); 237 244 if ( needle ) 238 245 { … … 243 250 } 244 251 } 252 253 #include "moc_qwt_analog_clock.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
