22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
27 #include <QToolButton>
28 #include <QDialogButtonBox>
33 #include "qwt_plot_picker.h"
34 #include "qwt_plot_marker.h"
35 #include <qwt_plot_curve.h>
36 #include <qwt_plot_grid.h>
37 #include <qwt_symbol.h>
38 #include <qwt_legend.h>
39 #include <qwt_plot_panner.h>
40 #include <qwt_plot_magnifier.h>
41 #include <qwt_plot_zoomer.h>
46 QDialog(parent, Qt::Window),
48 mKeyboard(piano.getKeyboard())
55 QVBoxLayout *mainLayout =
new QVBoxLayout;
56 mainLayout->setMargin(0);
57 setLayout(mainLayout);
59 QLayout *plotLayout = mainLayout;
61 QToolBar *toolBar =
new QToolBar;
63 toolBar->setIconSize(QSize(iconSize, iconSize));
64 mainLayout->addWidget(toolBar);
66 QHBoxLayout *barLayout =
new QHBoxLayout;
67 barLayout->setMargin(0);
68 mainLayout->addLayout(barLayout);
70 QToolBar *navBar = toolBar;
72 navBar =
new QToolBar;
73 navBar->setIconSize(QSize(iconSize, iconSize));
74 navBar->setOrientation(Qt::Vertical);
76 QHBoxLayout *vTbExtraLayout =
new QHBoxLayout;
77 vTbExtraLayout->setMargin(0);
78 mainLayout->addLayout(vTbExtraLayout);
79 vTbExtraLayout->addWidget(navBar);
81 plotLayout = vTbExtraLayout;
84 auto makeColorIcon = [](QColor c) {
86 QPixmap p(size, size);
91 auto makeToolButton = [&toolBar, &makeColorIcon,
this](QColor c, QString title,
Curves curve) {
93 toolBar->addWidget(b);
94 b->setFocusPolicy(Qt::NoFocus);
95 b->setCheckable(
true);
96 b->setIcon(makeColorIcon(c));
98 b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
106 navBar->addAction(QIcon(
":/media/icons/view-fullscreen.png"), tr(
"Reset view"), plot, SLOT(resetView()));
107 navBar->addAction(QIcon(
":/media/icons/go-first.png"), tr(
"Go first"), plot, SLOT(zoomGoFirst()));
108 navBar->addAction(QIcon(
":/media/icons/go-previous.png"), tr(
"Go previous"), plot, SLOT(zoomGoPrevious()));
109 navBar->addAction(QIcon(
":/media/icons/go-next.png"), tr(
"Go next"), plot, SLOT(zoomGoNext()));
110 navBar->addAction(QIcon(
":/media/icons/go-last.png"), tr(
"Go last"), plot, SLOT(zoomGoLast()));
113 toolBar->addSeparator();
119 makeToolButton(Qt::green, tr(
"Tun."),
CURVE_TUNED);
124 makeToolButton(Qt::green, tr(
"Tuned"),
CURVE_TUNED);
127 toolBar->addSeparator();
129 QDialogButtonBox *buttonBox =
new QDialogButtonBox(QDialogButtonBox::Close);
130 toolBar->addWidget(buttonBox);
131 QObject::connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
135 plot->setCanvasBackground( Qt::white );
137 plot->setAxisTitle(QwtPlot::xBottom, tr(
"Key index"));
140 QwtPlotGrid *grid =
new QwtPlotGrid();
141 grid->setMinorPen(Qt::darkGray, 1);
142 grid->setMajorPen(Qt::black, 1);
143 grid->enableXMin(
true);
144 grid->attach( plot );
147 QwtPlotMarker *marker =
new QwtPlotMarker;
148 marker->setLinePen(Qt::black, 2);
149 marker->setLineStyle(QwtPlotMarker::HLine);
150 marker->setYValue(0);
151 marker->attach(plot);
154 plotLayout->addWidget(plot);
169 mPlotToolButtons[i]->setChecked(s.value(QString(
"plots/curve%1").arg(i), defaultShown).toBool());
172 #if CONFIG_DIALOG_SIZE == 1
174 restoreGeometry(s.value(
"plots/geometry").toByteArray());
175 setWindowState(static_cast<Qt::WindowState>(s.value(
"plots/windowState").toInt()));
187 s.setValue(QString(
"plots/curve%1").arg(i),
mCurves[i]->isVisible());
190 #if CONFIG_DIALOG_SIZE == 1
192 s.setValue(
"plots/geometry", saveGeometry());
193 s.setValue(
"plots/windowState", (
int)windowState());
197 if (curve) {
delete curve;}
203 for (QwtPlotCurve *c :
mCurves) {
205 QwtSymbol *s =
const_cast<QwtSymbol*
>(c->symbol());
207 s->setSize(QSize(d, 1));
221 QwtPlotCurve *c =
mCurves[curve] =
new QwtPlotCurve;
223 auto cents = [] (
double ratio) {
return 1200.0 * log(ratio)/log(2); };
226 c->setStyle(QwtPlotCurve::NoCurve);
232 if (
mKeyboard[i].getMeasuredInharmonicity() > 0) {
236 c->setSamples( points );
238 c->setStyle(QwtPlotCurve::NoCurve);
245 c->setSamples(points);
247 c->setStyle(QwtPlotCurve::NoCurve);
254 c->setSamples(points);
256 c->setStyle(QwtPlotCurve::NoCurve);
263 c->setSamples(points);
273 EptAssert(tb,
"ToolButton has to be PlotToolButton type");
283 mPlot->setAxisTitle(QwtPlot::yLeft, tr(
"Inharmonicity"));
284 mPlot->setAxisScaleEngine(QwtPlot::yLeft,
new QwtLogScaleEngine);
287 mPlot->setAxisTitle(QwtPlot::yLeft, tr(
"Frequency deviation [cent]"));
288 mPlot->setAxisScaleEngine(QwtPlot::yLeft,
new QwtLinearScaleEngine);
const Keyboard & mKeyboard
PlotsDialog(const Piano &piano, QWidget *parent)
std::array< QwtPlotCurve *, CURVE_COUNT > mCurves
double getEqualTempFrequency(int keynumber, double cents=0, double A4=0) const
Function returning the equal temperament.
void prepareCurve(Curves curve)
void updateTickWidth(double d)
int getKeyNumberOfA4() const
void plotToolButtonToggled(bool)
static const std::unique_ptr< DisplaySizeDefines > & getSingleton()
int getNumberOfKeys() const
double currentTickDistanceInPixel() const
std::array< PlotToolButton *, CURVE_COUNT > mPlotToolButtons