File: shapes.cpp

package info (click to toggle)
qwt 6.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 23,808 kB
  • sloc: cpp: 57,687; xml: 182; makefile: 32
file content (100 lines) | stat: -rw-r--r-- 2,235 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <qapplication.h>
#include <qpainterpath.h>
#include <qwt_plot.h>
#include <qwt_legend.h>
#include <qwt_point_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_shapeitem.h>
#include <qwt_scale_engine.h>

class Plot : public QwtPlot
{
public:
    Plot( QWidget *parent = NULL );

private:
    void populate();
};


Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    setPalette( QColor( 60, 60, 60 ) );
    canvas()->setPalette( Qt::white );

    // panning with the left mouse button
    ( void ) new QwtPlotPanner( canvas() );

    // zoom in/out with the wheel
    ( void ) new QwtPlotMagnifier( canvas() );

    setTitle( "Shapes" );
    insertLegend( new QwtLegend(), QwtPlot::RightLegend );

    // axes
    setAxisTitle( xBottom, "x -->" );
    setAxisTitle( yLeft, "y -->" );
#if 0
    setAxisScaleEngine( xBottom, new QwtLog10ScaleEngine );
    setAxisScaleEngine( yLeft, new QwtLog10ScaleEngine );
#endif

    populate();
}

void Plot::populate()
{
    const double d = 900.0;
    const QRectF rect( 1.0, 1.0, d, d );

    QPainterPath path;
    //path.setFillRule( Qt::WindingFill );
    path.addEllipse( rect );

    const QRectF rect2 = rect.adjusted( 0.2 * d, 0.3 * d, -0.22 * d, 1.5 * d );
    path.addEllipse( rect2 );

#if 0
    QFont font;
    font.setPointSizeF( 200 );
    QPainterPath textPath;
    textPath.addText( rect.center(), font, "Seppi" );

    QTransform transform;
    transform.translate( rect.center().x() - 600, rect.center().y() + 50 );
    transform.rotate( 180.0, Qt::XAxis );

    textPath = transform.map( textPath );

    path.addPath( textPath );
#endif

    QwtPlotShapeItem *item = new QwtPlotShapeItem( "Shape" );
    item->setItemAttribute( QwtPlotItem::Legend, true );
    item->setRenderHint( QwtPlotItem::RenderAntialiased, true );
#if 1
    item->setRenderTolerance( 1.0 );
#endif
    item->setShape( path );
    item->setPen( Qt::yellow );

    QColor c = Qt::darkRed;
    c.setAlpha( 100 );
    item->setBrush( c );

    item->attach( this );
}

int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    Plot plot;
    plot.resize( 600, 400 );
    plot.show();

    return a.exec();
}