Add files from zip

This commit is contained in:
2023-10-31 09:22:42 +01:00
parent 6bacdc5f6d
commit 4dae68036f
2788 changed files with 492537 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "AttitudeIndicator.h"
#include <QwtPointPolar>
#include <QwtRoundScaleDraw>
#include <QwtDialNeedle>
#include <QKeyEvent>
#include <QPainter>
#include <QPainterPath>
namespace
{
class Needle : public QwtDialNeedle
{
public:
Needle( const QColor& color )
{
QPalette palette;
palette.setColor( QPalette::Text, color );
setPalette( palette );
}
protected:
virtual void drawNeedle( QPainter* painter,
double length, QPalette::ColorGroup colorGroup ) const QWT_OVERRIDE
{
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 )
, m_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 Needle( color ) );
}
void AttitudeIndicator::setGradient( double gradient )
{
if ( gradient < -1.0 )
gradient = -1.0;
else if ( gradient > 1.0 )
gradient = 1.0;
if ( m_gradient != gradient )
{
m_gradient = gradient;
update();
}
}
void AttitudeIndicator::drawScale( QPainter* painter,
const QPointF& center, 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 );
}
}
#include "moc_AttitudeIndicator.cpp"

View File

@@ -0,0 +1,35 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QwtDial>
class AttitudeIndicator : public QwtDial
{
Q_OBJECT
public:
AttitudeIndicator( QWidget* parent = NULL );
double angle() const { return value(); }
double gradient() const { return m_gradient; }
public Q_SLOTS:
void setGradient( double );
void setAngle( double angle ) { setValue( angle ); }
protected:
virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
virtual void drawScale( QPainter*,
const QPointF& center, double radius ) const QWT_OVERRIDE;
virtual void drawScaleContents( QPainter* painter,
const QPointF& center, double radius ) const QWT_OVERRIDE;
private:
double m_gradient;
};

View File

@@ -0,0 +1,239 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "CockpitGrid.h"
#include "AttitudeIndicator.h"
#include "SpeedoMeter.h"
#include <QwtAnalogClock>
#include <QwtRoundScaleDraw>
#include <QwtDialNeedle>
#include <QLayout>
#include <QTimer>
#include <QTimerEvent>
static QPalette colorTheme( const QColor& base )
{
QPalette palette;
palette.setColor( QPalette::Base, base );
palette.setColor( QPalette::Window, base.darker( 150 ) );
palette.setColor( QPalette::Mid, base.darker( 110 ) );
palette.setColor( QPalette::Light, base.lighter( 170 ) );
palette.setColor( QPalette::Dark, base.darker( 170 ) );
palette.setColor( QPalette::Text, base.darker( 200 ).lighter( 800 ) );
palette.setColor( QPalette::WindowText, base.darker( 200 ) );
return palette;
}
namespace
{
class Clock : public QwtAnalogClock
{
public:
Clock( QWidget* parent = NULL )
: QwtAnalogClock( parent )
{
#if 0
// disable minor ticks
scaleDraw()->setTickLength( QwtScaleDiv::MinorTick, 0 );
#endif
const QColor knobColor = QColor( Qt::gray ).lighter( 130 );
for ( int i = 0; i < QwtAnalogClock::NHands; i++ )
{
QColor handColor = QColor( Qt::gray ).lighter( 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 );
setHand( static_cast< QwtAnalogClock::Hand >( i ), hand );
}
QTimer* timer = new QTimer( this );
timer->connect( timer, SIGNAL(timeout()), this, SLOT(setCurrentTime()) );
timer->start( 1000 );
}
};
class Speedo : public SpeedoMeter
{
public:
Speedo( QWidget* parent = NULL )
: SpeedoMeter( parent )
{
setScaleStepSize( 20.0 );
setScale( 0.0, 240.0 );
scaleDraw()->setPenWidthF( 2 );
m_timerId = startTimer( 50 );
}
protected:
virtual void timerEvent( QTimerEvent* event ) QWT_OVERRIDE
{
if ( event->timerId() == m_timerId )
{
changeSpeed();
return;
}
SpeedoMeter::timerEvent( event );
}
private:
void changeSpeed()
{
static double offset = 0.8;
double speed = 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:
setValue( speed + offset );
}
}
int m_timerId;
};
class AttitudeInstrument : public AttitudeIndicator
{
public:
AttitudeInstrument( QWidget* parent = NULL )
: AttitudeIndicator( parent )
{
scaleDraw()->setPenWidthF( 3 );
m_timerId = startTimer( 100 );
}
protected:
virtual void timerEvent( QTimerEvent* event ) QWT_OVERRIDE
{
if ( event->timerId() == m_timerId )
{
changeAngle();
changeGradient();
return;
}
AttitudeIndicator::timerEvent( event );
}
private:
void changeAngle()
{
static double offset = 0.05;
double angle = this->angle();
if ( angle > 180.0 )
angle -= 360.0;
if ( ( angle < -5.0 && offset < 0.0 ) ||
( angle > 5.0 && offset > 0.0 ) )
{
offset = -offset;
}
setAngle( angle + offset );
}
void changeGradient()
{
static double offset = 0.005;
double gradient = this->gradient();
if ( ( gradient < -0.05 && offset < 0.0 ) ||
( gradient > 0.05 && offset > 0.0 ) )
{
offset = -offset;
}
setGradient( gradient + offset );
}
int m_timerId;
};
}
CockpitGrid::CockpitGrid( QWidget* parent )
: QFrame( parent )
{
setAutoFillBackground( true );
setPalette( colorTheme( QColor( Qt::darkGray ).darker( 150 ) ) );
QGridLayout* layout = new QGridLayout( this );
layout->setSpacing( 5 );
layout->setContentsMargins( QMargins() );
for ( int i = 0; i < 3; i++ )
{
QwtDial* dial = createDial( i );
layout->addWidget( dial, 0, i );
}
for ( int i = 0; i < layout->columnCount(); i++ )
layout->setColumnStretch( i, 1 );
}
QwtDial* CockpitGrid::createDial( int pos )
{
QwtDial* dial = NULL;
switch( pos )
{
case 0:
{
dial = new Clock( this );
break;
}
case 1:
{
dial = new Speedo( this );
break;
}
case 2:
{
dial = new AttitudeInstrument( this );
break;
}
}
if ( dial )
{
dial->setReadOnly( true );
dial->setLineWidth( 4 );
dial->setFrameShadow( QwtDial::Sunken );
}
return dial;
}

View File

@@ -0,0 +1,19 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QFrame>
class QwtDial;
class CockpitGrid : public QFrame
{
public:
CockpitGrid( QWidget* parent = NULL );
private:
QwtDial* createDial( int pos );
};

View File

@@ -0,0 +1,228 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "CompassGrid.h"
#include <QwtCompass>
#include <QwtCompassRose>
#include <QwtDialNeedle>
#include <QLayout>
#include <QMap>
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->setContentsMargins( QMargins() );
for ( int i = 0; i < 6; i++ )
{
QwtCompass* compass = createCompass( i );
layout->addWidget( compass, i / 3, i % 3 );
}
for ( int i = 0; i < layout->columnCount(); i++ )
layout->setColumnStretch( i, 1 );
}
QwtCompass* CompassGrid::createCompass( int pos )
{
QPalette palette0;
for ( int 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() ).lighter( 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 ).darker( 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 ( int d = 0; d < 360; d += 60 )
map.insert( d, QString::number( d ) );
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 ( int 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 ).lighter( 170 );
const QColor dark = newPalette.color( colorGroup, QPalette::Base ).darker( 170 );
const QColor mid = compass->frameShadow() == QwtDial::Raised
? newPalette.color( colorGroup, QPalette::Base ).darker( 110 )
: newPalette.color( colorGroup, QPalette::Base ).lighter( 110 );
newPalette.setColor( colorGroup, QPalette::Dark, dark );
newPalette.setColor( colorGroup, QPalette::Mid, mid );
newPalette.setColor( colorGroup, QPalette::Light, light );
}
compass->setPalette( newPalette );
return compass;
}

View File

@@ -0,0 +1,19 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QFrame>
class QwtCompass;
class CompassGrid : public QFrame
{
public:
CompassGrid( QWidget* parent = NULL );
private:
QwtCompass* createCompass( int pos );
};

View File

@@ -0,0 +1,59 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "SpeedoMeter.h"
#include <QwtDialNeedle>
#include <QwtRoundScaleDraw>
#include <QPainter>
SpeedoMeter::SpeedoMeter( QWidget* parent )
: QwtDial( parent )
, m_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 ).lighter( 130 ) );
setNeedle( needle );
}
void SpeedoMeter::setLabel( const QString& label )
{
m_label = label;
update();
}
QString SpeedoMeter::label() const
{
return m_label;
}
void SpeedoMeter::drawScaleContents( QPainter* painter,
const QPointF& center, 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, m_label );
}

View File

@@ -0,0 +1,25 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QString>
#include <QwtDial>
class SpeedoMeter : public QwtDial
{
public:
SpeedoMeter( QWidget* parent = NULL );
void setLabel( const QString& );
QString label() const;
protected:
virtual void drawScaleContents( QPainter* painter,
const QPointF& center, double radius ) const QWT_OVERRIDE;
private:
QString m_label;
};

22
examples/dials/dials.pro Normal file
View File

@@ -0,0 +1,22 @@
######################################################################
# Qwt Examples - Copyright (C) 2002 Uwe Rathmann
# This file may be used under the terms of the 3-clause BSD License
######################################################################
include( $${PWD}/../examples.pri )
TARGET = dials
HEADERS = \
AttitudeIndicator.h \
SpeedoMeter.h \
CockpitGrid.h \
CompassGrid.h
SOURCES = \
AttitudeIndicator.cpp \
SpeedoMeter.cpp \
CockpitGrid.cpp \
CompassGrid.cpp \
main.cpp

24
examples/dials/main.cpp Normal file
View File

@@ -0,0 +1,24 @@
/*****************************************************************************
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "CompassGrid.h"
#include "CockpitGrid.h"
#include <QApplication>
#include <QTabWidget>
int main( int argc, char* argv[] )
{
QApplication app( argc, argv );
QTabWidget tabWidget;
tabWidget.addTab( new CompassGrid, "Compass" );
tabWidget.addTab( new CockpitGrid, "Cockpit" );
tabWidget.show();
return app.exec();
}