26 #include "qwt/src/qwt_painter.h"
34 QPalette palette = parent->palette();
36 palette.setColor(QPalette::Foreground, palette.color(QPalette::Dark));
37 palette.setColor(QPalette::Background, palette.color(QPalette::Light));
39 QwtPainter::setPolylineSplitting(
false);
40 QwtPainter::setRoundingAlignment(
false);
41 setMouseTracking(
true);
43 setMinimumSize(64, 64);
44 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
45 setContentsMargins(6, 0, 0, 0);
47 QFrame *f = qobject_cast<QFrame *>(canvas());
49 f->setFrameStyle(QFrame::Box | QFrame::Plain);
51 f->setPalette(palette);
55 QwtPlotGrid *grid =
new QwtPlotGrid;
56 grid->setMajorPen(QPen(Qt::gray, 0, Qt::DashLine));
57 grid->setMinorPen(QPen(Qt::lightGray, 0, Qt::DotLine));
58 grid->setPen(QPen(Qt::darkGray, 1, Qt::DotLine));
61 roll_elements.
Curve.setRenderHint(QwtPlotCurve::RenderAntialiased);
62 roll_elements.
Curve.setPen(QPen(QColor(41, 128, 185), 1.25, Qt::SolidLine, Qt::FlatCap));
63 roll_elements.
Curve.attach(
this);
65 pitch_elements.
Curve.setRenderHint(QwtPlotCurve::RenderAntialiased);
66 pitch_elements.
Curve.setPen(QPen(QColor(192, 57, 43), 1.25, Qt::SolidLine, Qt::FlatCap));
67 pitch_elements.
Curve.attach(
this);
69 yaw_elements.
Curve.setRenderHint(QwtPlotCurve::RenderAntialiased);
70 yaw_elements.
Curve.setPen(QPen(QColor(39, 174, 96), 1.25, Qt::SolidLine, Qt::FlatCap));
71 yaw_elements.
Curve.attach(
this);
75 QwtLegend *m_legend =
new QwtLegend(
this);
76 m_legend->setDefaultItemMode(QwtLegendData::Checkable);
78 m_legend->setToolTip(tr(
"Click legend to show/hide expo curve"));
83 QPalette pal = m_legend->palette();
84 pal.setColor(m_legend->backgroundRole(), QColor(100, 100, 100));
85 pal.setColor(QPalette::Text, QColor(0, 0, 0));
86 m_legend->setPalette(pal);
87 m_legend->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
89 insertLegend(m_legend, QwtPlot::RightLegend);
92 x_data =
new double[steps];
93 y_data =
new double[steps];
96 double step = 1.0 / (steps - 1);
97 for (
int i = 0;
i < steps;
i++) {
99 x_data[
i] = (
i * step);
106 QFont axis_title_font = this->axisTitle(yLeft).font();
108 axis_title_font.setPointSize(10);
109 axis_title.setFont(axis_title_font);
111 axis_title.setText(tr(
"normalized stick input"));
112 this->setAxisTitle(QwtPlot::xBottom, axis_title);
114 roll_elements.
Curve.setTitle(tr(
"Roll"));
115 pitch_elements.
Curve.setTitle(tr(
"Pitch"));
116 yaw_elements.
Curve.setTitle(tr(
"Yaw"));
118 axis_title.setText(tr(
"rate (deg/s)"));
119 this->setAxisTitle(QwtPlot::yLeft, axis_title);
121 this->axisWidget(QwtPlot::xBottom)->setPalette(palette);
122 this->axisWidget(QwtPlot::yLeft)->setPalette(palette);
141 for (
int i = 0;
i < steps;
i++) {
142 y_data[
i] = max * (x_data[
i] * ((100 - value) / 100.0)
143 + pow(x_data[
i], exponent / 10.0f) * (value / 100.0));
146 plot_elements.
Curve.setSamples(x_data, y_data, steps);
147 plot_elements.
Curve.show();
150 setAxisAutoScale(yLeft,
true);
152 const QwtScaleDiv &div = axisScaleDiv(yLeft);
153 setAxisScale(yLeft, 0, div.upperBound(), 180);
165 plotData(value, max, exponent, this->roll_elements);
175 plotData(value, max, exponent, this->pitch_elements);
185 plotData(value, max, exponent, this->yaw_elements);
199 QwtPlotItem *item = QwtPlot::infoToItem(itemInfo);
201 item->setVisible(!on);
void showCurve(const QVariant &itemInfo, bool on, int index)
Show/Hide a expo curve and markers.
void plotData(int value, int max, int exponent, ExpoPlotElements_t &plot_elements)
Show expo data for one of the stick channels.
void plotDataYaw(int value, int max, int exponent)
Show expo data for yaw.
void plotDataPitch(int value, int max, int exponent)
Show expo data for pitch.
ExpoCurve(QWidget *parent=nullptr)
void plotDataRoll(int value, int max, int exponent)
Show expo data for roll.