Released version 6.1.3
This commit is contained in:
commit
a94503cb82
1885 changed files with 276310 additions and 0 deletions
127
examples/dials/attitude_indicator.cpp
Normal file
127
examples/dials/attitude_indicator.cpp
Normal file
|
@ -0,0 +1,127 @@
|
|||
#include "attitude_indicator.h"
|
||||
#include <qwt_point_polar.h>
|
||||
#include <qwt_round_scale_draw.h>
|
||||
#include <qevent.h>
|
||||
#include <qpainter.h>
|
||||
#include <qpolygon.h>
|
||||
|
||||
AttitudeIndicatorNeedle::AttitudeIndicatorNeedle( const QColor &color )
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor( QPalette::Text, color );
|
||||
setPalette( palette );
|
||||
}
|
||||
|
||||
void AttitudeIndicatorNeedle::drawNeedle( QPainter *painter,
|
||||
double length, QPalette::ColorGroup colorGroup ) const
|
||||
{
|
||||
double triangleSize = length * 0.1;
|
||||
double pos = length - 2.0;
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo( pos, 0 );
|
||||
path.lineTo( pos - 2 * triangleSize, triangleSize );
|
||||
path.lineTo( pos - 2 * triangleSize, -triangleSize );
|
||||
path.closeSubpath();
|
||||
|
||||
painter->setBrush( palette().brush( colorGroup, QPalette::Text ) );
|
||||
painter->drawPath( path );
|
||||
|
||||
double l = length - 2;
|
||||
painter->setPen( QPen( palette().color( colorGroup, QPalette::Text ), 3 ) );
|
||||
painter->drawLine( QPointF( 0.0, -l ), QPointF( 0.0, l ) );
|
||||
}
|
||||
|
||||
AttitudeIndicator::AttitudeIndicator(
|
||||
QWidget *parent ):
|
||||
QwtDial( parent ),
|
||||
d_gradient( 0.0 )
|
||||
{
|
||||
QwtRoundScaleDraw *scaleDraw = new QwtRoundScaleDraw();
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Labels, false );
|
||||
setScaleDraw( scaleDraw );
|
||||
|
||||
setMode( RotateScale );
|
||||
setWrapping( true );
|
||||
|
||||
setOrigin( 270.0 );
|
||||
|
||||
setScaleMaxMinor( 0 );
|
||||
setScaleStepSize( 30.0 );
|
||||
setScale( 0.0, 360.0 );
|
||||
|
||||
const QColor color = palette().color( QPalette::Text );
|
||||
setNeedle( new AttitudeIndicatorNeedle( color ) );
|
||||
}
|
||||
|
||||
void AttitudeIndicator::setGradient( double gradient )
|
||||
{
|
||||
if ( gradient < -1.0 )
|
||||
gradient = -1.0;
|
||||
else if ( gradient > 1.0 )
|
||||
gradient = 1.0;
|
||||
|
||||
if ( d_gradient != gradient )
|
||||
{
|
||||
d_gradient = gradient;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void AttitudeIndicator::drawScale( QPainter *painter,
|
||||
const QPointF ¢er, double radius ) const
|
||||
{
|
||||
const double offset = 4.0;
|
||||
|
||||
const QPointF p0 = qwtPolar2Pos( center, offset, 1.5 * M_PI );
|
||||
|
||||
const double w = innerRect().width();
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo( qwtPolar2Pos( p0, w, 0.0 ) );
|
||||
path.lineTo( qwtPolar2Pos( path.currentPosition(), 2 * w, M_PI ) );
|
||||
path.lineTo( qwtPolar2Pos( path.currentPosition(), w, 0.5 * M_PI ) );
|
||||
path.lineTo( qwtPolar2Pos( path.currentPosition(), w, 0.0 ) );
|
||||
|
||||
painter->save();
|
||||
painter->setClipPath( path ); // swallow 180 - 360 degrees
|
||||
|
||||
QwtDial::drawScale( painter, center, radius );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void AttitudeIndicator::drawScaleContents( QPainter *painter,
|
||||
const QPointF &, double ) const
|
||||
{
|
||||
int dir = 360 - qRound( origin() - value() ); // counter clockwise
|
||||
int arc = 90 + qRound( gradient() * 90 );
|
||||
|
||||
const QColor skyColor( 38, 151, 221 );
|
||||
|
||||
painter->save();
|
||||
painter->setBrush( skyColor );
|
||||
painter->drawChord( scaleInnerRect(),
|
||||
( dir - arc ) * 16, 2 * arc * 16 );
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void AttitudeIndicator::keyPressEvent( QKeyEvent *event )
|
||||
{
|
||||
switch( event->key() )
|
||||
{
|
||||
case Qt::Key_Plus:
|
||||
{
|
||||
setGradient( gradient() + 0.05 );
|
||||
break;
|
||||
}
|
||||
case Qt::Key_Minus:
|
||||
{
|
||||
setGradient( gradient() - 0.05 );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
QwtDial::keyPressEvent( event );
|
||||
}
|
||||
}
|
39
examples/dials/attitude_indicator.h
Normal file
39
examples/dials/attitude_indicator.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <qwt_dial.h>
|
||||
#include <qwt_dial_needle.h>
|
||||
|
||||
class AttitudeIndicatorNeedle: public QwtDialNeedle
|
||||
{
|
||||
public:
|
||||
AttitudeIndicatorNeedle( const QColor & );
|
||||
|
||||
protected:
|
||||
virtual void drawNeedle( QPainter *,
|
||||
double length, QPalette::ColorGroup ) const;
|
||||
};
|
||||
|
||||
class AttitudeIndicator: public QwtDial
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AttitudeIndicator( QWidget *parent = NULL );
|
||||
|
||||
double angle() const { return value(); }
|
||||
double gradient() const { return d_gradient; }
|
||||
|
||||
public Q_SLOTS:
|
||||
void setGradient( double );
|
||||
void setAngle( double angle ) { setValue( angle ); }
|
||||
|
||||
protected:
|
||||
virtual void keyPressEvent( QKeyEvent * );
|
||||
|
||||
virtual void drawScale( QPainter *,
|
||||
const QPointF ¢er, double radius ) const;
|
||||
|
||||
virtual void drawScaleContents( QPainter *painter,
|
||||
const QPointF ¢er, double radius ) const;
|
||||
|
||||
private:
|
||||
double d_gradient;
|
||||
};
|
186
examples/dials/cockpit_grid.cpp
Normal file
186
examples/dials/cockpit_grid.cpp
Normal file
|
@ -0,0 +1,186 @@
|
|||
#include <qlayout.h>
|
||||
#include <qtimer.h>
|
||||
#include <qwt_analog_clock.h>
|
||||
#include <qwt_round_scale_draw.h>
|
||||
#include "attitude_indicator.h"
|
||||
#include "speedo_meter.h"
|
||||
#include "cockpit_grid.h"
|
||||
|
||||
CockpitGrid::CockpitGrid( QWidget *parent ):
|
||||
QFrame( parent )
|
||||
{
|
||||
setAutoFillBackground( true );
|
||||
|
||||
setPalette( colorTheme( QColor( Qt::darkGray ).dark( 150 ) ) );
|
||||
|
||||
QGridLayout *layout = new QGridLayout( this );
|
||||
layout->setSpacing( 5 );
|
||||
layout->setMargin( 0 );
|
||||
|
||||
int i;
|
||||
for ( i = 0; i < 3; i++ )
|
||||
{
|
||||
QwtDial *dial = createDial( i );
|
||||
layout->addWidget( dial, 0, i );
|
||||
}
|
||||
|
||||
for ( i = 0; i < layout->columnCount(); i++ )
|
||||
layout->setColumnStretch( i, 1 );
|
||||
}
|
||||
|
||||
QwtDial *CockpitGrid::createDial( int pos )
|
||||
{
|
||||
QwtDial *dial = NULL;
|
||||
switch( pos )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
d_clock = new QwtAnalogClock( this );
|
||||
#if 0
|
||||
// disable minor ticks
|
||||
d_clock->scaleDraw()->setTickLength( QwtScaleDiv::MinorTick, 0 );
|
||||
#endif
|
||||
|
||||
const QColor knobColor = QColor( Qt::gray ).light( 130 );
|
||||
|
||||
for ( int i = 0; i < QwtAnalogClock::NHands; i++ )
|
||||
{
|
||||
QColor handColor = QColor( Qt::gray ).light( 150 );
|
||||
int width = 8;
|
||||
|
||||
if ( i == QwtAnalogClock::SecondHand )
|
||||
{
|
||||
handColor = Qt::gray;
|
||||
width = 5;
|
||||
}
|
||||
|
||||
QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
|
||||
QwtDialSimpleNeedle::Arrow, true, handColor, knobColor );
|
||||
hand->setWidth( width );
|
||||
|
||||
d_clock->setHand( static_cast<QwtAnalogClock::Hand>( i ), hand );
|
||||
}
|
||||
|
||||
QTimer *timer = new QTimer( d_clock );
|
||||
timer->connect( timer, SIGNAL( timeout() ),
|
||||
d_clock, SLOT( setCurrentTime() ) );
|
||||
timer->start( 1000 );
|
||||
|
||||
dial = d_clock;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
d_speedo = new SpeedoMeter( this );
|
||||
d_speedo->setScaleStepSize( 20.0 );
|
||||
d_speedo->setScale( 0.0, 240.0 );
|
||||
d_speedo->scaleDraw()->setPenWidth( 2 );
|
||||
|
||||
QTimer *timer = new QTimer( d_speedo );
|
||||
timer->connect( timer, SIGNAL( timeout() ),
|
||||
this, SLOT( changeSpeed() ) );
|
||||
timer->start( 50 );
|
||||
|
||||
dial = d_speedo;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
d_ai = new AttitudeIndicator( this );
|
||||
d_ai->scaleDraw()->setPenWidth( 3 );
|
||||
|
||||
QTimer *gradientTimer = new QTimer( d_ai );
|
||||
gradientTimer->connect( gradientTimer, SIGNAL( timeout() ),
|
||||
this, SLOT( changeGradient() ) );
|
||||
gradientTimer->start( 100 );
|
||||
|
||||
QTimer *angleTimer = new QTimer( d_ai );
|
||||
angleTimer->connect( angleTimer, SIGNAL( timeout() ),
|
||||
this, SLOT( changeAngle() ) );
|
||||
angleTimer->start( 100 );
|
||||
|
||||
dial = d_ai;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( dial )
|
||||
{
|
||||
dial->setReadOnly( true );
|
||||
dial->setLineWidth( 4 );
|
||||
dial->setFrameShadow( QwtDial::Sunken );
|
||||
}
|
||||
return dial;
|
||||
}
|
||||
|
||||
QPalette CockpitGrid::colorTheme( const QColor &base ) const
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor( QPalette::Base, base );
|
||||
palette.setColor( QPalette::Window, base.dark( 150 ) );
|
||||
palette.setColor( QPalette::Mid, base.dark( 110 ) );
|
||||
palette.setColor( QPalette::Light, base.light( 170 ) );
|
||||
palette.setColor( QPalette::Dark, base.dark( 170 ) );
|
||||
palette.setColor( QPalette::Text, base.dark( 200 ).light( 800 ) );
|
||||
palette.setColor( QPalette::WindowText, base.dark( 200 ) );
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
void CockpitGrid::changeSpeed()
|
||||
{
|
||||
static double offset = 0.8;
|
||||
|
||||
double speed = d_speedo->value();
|
||||
|
||||
if ( ( speed < 7.0 && offset < 0.0 ) ||
|
||||
( speed > 203.0 && offset > 0.0 ) )
|
||||
{
|
||||
offset = -offset;
|
||||
}
|
||||
|
||||
static int counter = 0;
|
||||
switch( counter++ % 12 )
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
case 7:
|
||||
case 8:
|
||||
break;
|
||||
default:
|
||||
d_speedo->setValue( speed + offset );
|
||||
}
|
||||
}
|
||||
|
||||
void CockpitGrid::changeAngle()
|
||||
{
|
||||
static double offset = 0.05;
|
||||
|
||||
double angle = d_ai->angle();
|
||||
if ( angle > 180.0 )
|
||||
angle -= 360.0;
|
||||
|
||||
if ( ( angle < -5.0 && offset < 0.0 ) ||
|
||||
( angle > 5.0 && offset > 0.0 ) )
|
||||
{
|
||||
offset = -offset;
|
||||
}
|
||||
|
||||
d_ai->setAngle( angle + offset );
|
||||
}
|
||||
|
||||
void CockpitGrid::changeGradient()
|
||||
{
|
||||
static double offset = 0.005;
|
||||
|
||||
double gradient = d_ai->gradient();
|
||||
|
||||
if ( ( gradient < -0.05 && offset < 0.0 ) ||
|
||||
( gradient > 0.05 && offset > 0.0 ) )
|
||||
{
|
||||
offset = -offset;
|
||||
}
|
||||
|
||||
d_ai->setGradient( gradient + offset );
|
||||
}
|
28
examples/dials/cockpit_grid.h
Normal file
28
examples/dials/cockpit_grid.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <qframe.h>
|
||||
#include <qpalette.h>
|
||||
|
||||
class QwtDial;
|
||||
class QwtAnalogClock;
|
||||
class SpeedoMeter;
|
||||
class AttitudeIndicator;
|
||||
|
||||
class CockpitGrid: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CockpitGrid( QWidget *parent = NULL );
|
||||
|
||||
private Q_SLOTS:
|
||||
void changeSpeed();
|
||||
void changeGradient();
|
||||
void changeAngle();
|
||||
|
||||
private:
|
||||
QPalette colorTheme( const QColor & ) const;
|
||||
QwtDial *createDial( int pos );
|
||||
|
||||
QwtAnalogClock *d_clock;
|
||||
SpeedoMeter *d_speedo;
|
||||
AttitudeIndicator *d_ai;
|
||||
};
|
226
examples/dials/compass_grid.cpp
Normal file
226
examples/dials/compass_grid.cpp
Normal file
|
@ -0,0 +1,226 @@
|
|||
#include <qlayout.h>
|
||||
#include <qwt_compass.h>
|
||||
#include <qwt_compass_rose.h>
|
||||
#include <qwt_dial_needle.h>
|
||||
#include "compass_grid.h"
|
||||
|
||||
CompassGrid::CompassGrid( QWidget *parent ):
|
||||
QFrame( parent )
|
||||
{
|
||||
QPalette p = palette();
|
||||
p.setColor( backgroundRole(), Qt::gray );
|
||||
setPalette( p );
|
||||
|
||||
setAutoFillBackground( true );
|
||||
|
||||
QGridLayout *layout = new QGridLayout( this );
|
||||
layout->setSpacing( 5 );
|
||||
layout->setMargin( 0 );
|
||||
|
||||
int i;
|
||||
for ( i = 0; i < 6; i++ )
|
||||
{
|
||||
QwtCompass *compass = createCompass( i );
|
||||
layout->addWidget( compass, i / 3, i % 3 );
|
||||
}
|
||||
|
||||
for ( i = 0; i < layout->columnCount(); i++ )
|
||||
layout->setColumnStretch( i, 1 );
|
||||
}
|
||||
|
||||
QwtCompass *CompassGrid::createCompass( int pos )
|
||||
{
|
||||
int c;
|
||||
|
||||
QPalette palette0;
|
||||
for ( c = 0; c < QPalette::NColorRoles; c++ )
|
||||
{
|
||||
const QPalette::ColorRole colorRole =
|
||||
static_cast<QPalette::ColorRole>( c );
|
||||
|
||||
palette0.setColor( colorRole, QColor() );
|
||||
}
|
||||
|
||||
palette0.setColor( QPalette::Base,
|
||||
palette().color( backgroundRole() ).light( 120 ) );
|
||||
palette0.setColor( QPalette::WindowText,
|
||||
palette0.color( QPalette::Base ) );
|
||||
|
||||
QwtCompass *compass = new QwtCompass( this );
|
||||
compass->setLineWidth( 4 );
|
||||
compass->setFrameShadow(
|
||||
pos <= 2 ? QwtCompass::Sunken : QwtCompass::Raised );
|
||||
|
||||
switch( pos )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
/*
|
||||
A compass with a rose and no needle. Scale and rose are
|
||||
rotating.
|
||||
*/
|
||||
compass->setMode( QwtCompass::RotateScale );
|
||||
|
||||
QwtSimpleCompassRose *rose = new QwtSimpleCompassRose( 16, 2 );
|
||||
rose->setWidth( 0.15 );
|
||||
|
||||
compass->setRose( rose );
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
/*
|
||||
A windrose, with a scale indicating the main directions only
|
||||
*/
|
||||
QMap<double, QString> map;
|
||||
map.insert( 0.0, "N" );
|
||||
map.insert( 90.0, "E" );
|
||||
map.insert( 180.0, "S" );
|
||||
map.insert( 270.0, "W" );
|
||||
|
||||
compass->setScaleDraw( new QwtCompassScaleDraw( map ) );
|
||||
|
||||
QwtSimpleCompassRose *rose = new QwtSimpleCompassRose( 4, 1 );
|
||||
compass->setRose( rose );
|
||||
|
||||
compass->setNeedle(
|
||||
new QwtCompassWindArrow( QwtCompassWindArrow::Style2 ) );
|
||||
compass->setValue( 60.0 );
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
/*
|
||||
A compass with a rotating needle in darkBlue. Shows
|
||||
a ticks for each degree.
|
||||
*/
|
||||
|
||||
palette0.setColor( QPalette::Base, Qt::darkBlue );
|
||||
palette0.setColor( QPalette::WindowText,
|
||||
QColor( Qt::darkBlue ).dark( 120 ) );
|
||||
palette0.setColor( QPalette::Text, Qt::white );
|
||||
|
||||
QwtCompassScaleDraw *scaleDraw = new QwtCompassScaleDraw();
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Ticks, true );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Labels, true );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MinorTick, 1 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MediumTick, 1 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MajorTick, 3 );
|
||||
|
||||
compass->setScaleDraw( scaleDraw );
|
||||
|
||||
compass->setScaleMaxMajor( 36 );
|
||||
compass->setScaleMaxMinor( 5 );
|
||||
|
||||
compass->setNeedle(
|
||||
new QwtCompassMagnetNeedle( QwtCompassMagnetNeedle::ThinStyle ) );
|
||||
compass->setValue( 220.0 );
|
||||
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
/*
|
||||
A compass without a frame, showing numbers as tick labels.
|
||||
The origin is at 220.0
|
||||
*/
|
||||
palette0.setColor( QPalette::Base,
|
||||
palette().color( backgroundRole() ) );
|
||||
palette0.setColor( QPalette::WindowText, Qt::blue );
|
||||
|
||||
compass->setLineWidth( 0 );
|
||||
|
||||
QMap<double, QString> map;
|
||||
for ( double d = 0.0; d < 360.0; d += 60.0 )
|
||||
{
|
||||
QString label;
|
||||
label.sprintf( "%.0f", d );
|
||||
map.insert( d, label );
|
||||
}
|
||||
|
||||
QwtCompassScaleDraw *scaleDraw =
|
||||
new QwtCompassScaleDraw( map );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Ticks, true );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Labels, true );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, true );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MinorTick, 0 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MediumTick, 0 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MajorTick, 3 );
|
||||
|
||||
compass->setScaleDraw( scaleDraw );
|
||||
|
||||
compass->setScaleMaxMajor( 36 );
|
||||
compass->setScaleMaxMinor( 5 );
|
||||
|
||||
compass->setNeedle( new QwtDialSimpleNeedle( QwtDialSimpleNeedle::Ray,
|
||||
true, Qt::white ) );
|
||||
compass->setOrigin( 220.0 );
|
||||
compass->setValue( 20.0 );
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
/*
|
||||
A compass showing another needle
|
||||
*/
|
||||
QwtCompassScaleDraw *scaleDraw = new QwtCompassScaleDraw();
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Ticks, true );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Labels, true );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MinorTick, 0 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MediumTick, 0 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MajorTick, 3 );
|
||||
|
||||
compass->setScaleDraw( scaleDraw );
|
||||
|
||||
compass->setNeedle( new QwtCompassMagnetNeedle(
|
||||
QwtCompassMagnetNeedle::TriangleStyle, Qt::white, Qt::red ) );
|
||||
compass->setValue( 220.0 );
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
/*
|
||||
A compass with a yellow on black ray
|
||||
*/
|
||||
palette0.setColor( QPalette::WindowText, Qt::black );
|
||||
|
||||
compass->setNeedle( new QwtDialSimpleNeedle( QwtDialSimpleNeedle::Ray,
|
||||
false, Qt::yellow ) );
|
||||
compass->setValue( 315.0 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QPalette newPalette = compass->palette();
|
||||
for ( c = 0; c < QPalette::NColorRoles; c++ )
|
||||
{
|
||||
const QPalette::ColorRole colorRole =
|
||||
static_cast<QPalette::ColorRole>( c );
|
||||
|
||||
if ( palette0.color( colorRole ).isValid() )
|
||||
newPalette.setColor( colorRole, palette0.color( colorRole ) );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < QPalette::NColorGroups; i++ )
|
||||
{
|
||||
const QPalette::ColorGroup colorGroup =
|
||||
static_cast<QPalette::ColorGroup>( i );
|
||||
|
||||
const QColor light =
|
||||
newPalette.color( colorGroup, QPalette::Base ).light( 170 );
|
||||
const QColor dark = newPalette.color( colorGroup, QPalette::Base ).dark( 170 );
|
||||
const QColor mid = compass->frameShadow() == QwtDial::Raised
|
||||
? newPalette.color( colorGroup, QPalette::Base ).dark( 110 )
|
||||
: newPalette.color( colorGroup, QPalette::Base ).light( 110 );
|
||||
|
||||
newPalette.setColor( colorGroup, QPalette::Dark, dark );
|
||||
newPalette.setColor( colorGroup, QPalette::Mid, mid );
|
||||
newPalette.setColor( colorGroup, QPalette::Light, light );
|
||||
}
|
||||
|
||||
compass->setPalette( newPalette );
|
||||
|
||||
return compass;
|
||||
}
|
11
examples/dials/compass_grid.h
Normal file
11
examples/dials/compass_grid.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <qframe.h>
|
||||
class QwtCompass;
|
||||
|
||||
class CompassGrid: public QFrame
|
||||
{
|
||||
public:
|
||||
CompassGrid( QWidget *parent = NULL );
|
||||
|
||||
private:
|
||||
QwtCompass *createCompass( int pos );
|
||||
};
|
24
examples/dials/dials.cpp
Normal file
24
examples/dials/dials.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <qapplication.h>
|
||||
#include <qtabwidget.h>
|
||||
#include "compass_grid.h"
|
||||
#include "cockpit_grid.h"
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
//
|
||||
// dials.cpp -- A demo program featuring QwtDial and friends
|
||||
//
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
int main ( int argc, char **argv )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
|
||||
QTabWidget tabWidget;
|
||||
tabWidget.addTab( new CompassGrid, "Compass" );
|
||||
tabWidget.addTab( new CockpitGrid, "Cockpit" );
|
||||
|
||||
tabWidget.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
26
examples/dials/dials.pro
Normal file
26
examples/dials/dials.pro
Normal file
|
@ -0,0 +1,26 @@
|
|||
################################################################
|
||||
# Qwt Widget Library
|
||||
# Copyright (C) 1997 Josef Wilgen
|
||||
# Copyright (C) 2002 Uwe Rathmann
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the Qwt License, Version 1.0
|
||||
################################################################
|
||||
|
||||
include( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = dials
|
||||
|
||||
HEADERS = \
|
||||
attitude_indicator.h \
|
||||
speedo_meter.h \
|
||||
cockpit_grid.h \
|
||||
compass_grid.h
|
||||
|
||||
SOURCES = \
|
||||
attitude_indicator.cpp \
|
||||
speedo_meter.cpp \
|
||||
cockpit_grid.cpp \
|
||||
compass_grid.cpp \
|
||||
dials.cpp
|
||||
|
52
examples/dials/speedo_meter.cpp
Normal file
52
examples/dials/speedo_meter.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <qpainter.h>
|
||||
#include <qwt_dial_needle.h>
|
||||
#include <qwt_round_scale_draw.h>
|
||||
#include "speedo_meter.h"
|
||||
|
||||
SpeedoMeter::SpeedoMeter( QWidget *parent ):
|
||||
QwtDial( parent ),
|
||||
d_label( "km/h" )
|
||||
{
|
||||
QwtRoundScaleDraw *scaleDraw = new QwtRoundScaleDraw();
|
||||
scaleDraw->setSpacing( 8 );
|
||||
scaleDraw->enableComponent( QwtAbstractScaleDraw::Backbone, false );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MinorTick, 0 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MediumTick, 4 );
|
||||
scaleDraw->setTickLength( QwtScaleDiv::MajorTick, 8 );
|
||||
setScaleDraw( scaleDraw );
|
||||
|
||||
setWrapping( false );
|
||||
setReadOnly( true );
|
||||
|
||||
setOrigin( 135.0 );
|
||||
setScaleArc( 0.0, 270.0 );
|
||||
|
||||
QwtDialSimpleNeedle *needle = new QwtDialSimpleNeedle(
|
||||
QwtDialSimpleNeedle::Arrow, true, Qt::red,
|
||||
QColor( Qt::gray ).light( 130 ) );
|
||||
setNeedle( needle );
|
||||
}
|
||||
|
||||
void SpeedoMeter::setLabel( const QString &label )
|
||||
{
|
||||
d_label = label;
|
||||
update();
|
||||
}
|
||||
|
||||
QString SpeedoMeter::label() const
|
||||
{
|
||||
return d_label;
|
||||
}
|
||||
|
||||
void SpeedoMeter::drawScaleContents( QPainter *painter,
|
||||
const QPointF ¢er, double radius ) const
|
||||
{
|
||||
QRectF rect( 0.0, 0.0, 2.0 * radius, 2.0 * radius - 10.0 );
|
||||
rect.moveCenter( center );
|
||||
|
||||
const QColor color = palette().color( QPalette::Text );
|
||||
painter->setPen( color );
|
||||
|
||||
const int flags = Qt::AlignBottom | Qt::AlignHCenter;
|
||||
painter->drawText( rect, flags, d_label );
|
||||
}
|
18
examples/dials/speedo_meter.h
Normal file
18
examples/dials/speedo_meter.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <qstring.h>
|
||||
#include <qwt_dial.h>
|
||||
|
||||
class SpeedoMeter: public QwtDial
|
||||
{
|
||||
public:
|
||||
SpeedoMeter( QWidget *parent = NULL );
|
||||
|
||||
void setLabel( const QString & );
|
||||
QString label() const;
|
||||
|
||||
protected:
|
||||
virtual void drawScaleContents( QPainter *painter,
|
||||
const QPointF ¢er, double radius ) const;
|
||||
|
||||
private:
|
||||
QString d_label;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue