| 166 | }; |
| 167 | |
| 168 | PlotWidgetBase::PlotWidgetBase(QWidget* parent) : QWidget(parent) { |
| 169 | auto on_view_resized = [this](const QRectF& rect) { emit viewResized(rect); }; |
| 170 | auto on_event = [this](QEvent* event) { |
| 171 | if (auto* drag_enter = dynamic_cast<QDragEnterEvent*>(event)) { |
| 172 | emit dragEnterSignal(drag_enter); |
| 173 | } else if (auto* drag_leave = dynamic_cast<QDragLeaveEvent*>(event)) { |
| 174 | emit dragLeaveSignal(drag_leave); |
| 175 | } else if (auto* drop = dynamic_cast<QDropEvent*>(event)) { |
| 176 | emit dropSignal(drop); |
| 177 | } |
| 178 | }; |
| 179 | |
| 180 | const bool use_opengl = !g_opengl_disabled_override && QSettings().value("Preferences::use_opengl", true).toBool(); |
| 181 | |
| 182 | // TODO(theme): QwtPlotCanvas uses a backing-store paint path that ignores |
| 183 | // QSS background rules, so the canvas needs a solid palette colour here. |
| 184 | // Currently baked to the light-theme ${dark_background} value (#F5F5F5); |
| 185 | // should be wired to react on themeChanged. See resources/visual_guidelines.md §5. |
| 186 | const QColor canvas_bg(0xf5, 0xf5, 0xf5); |
| 187 | |
| 188 | QWidget* abs_canvas = nullptr; |
| 189 | if (use_opengl) { |
| 190 | auto* canvas = new QwtPlotOpenGLCanvas(); |
| 191 | canvas->setFrameStyle(QFrame::Box | QFrame::Plain); |
| 192 | canvas->setLineWidth(1); |
| 193 | canvas->setPalette(canvas_bg); |
| 194 | abs_canvas = canvas; |
| 195 | } else { |
| 196 | auto* canvas = new QwtPlotCanvas(); |
| 197 | canvas->setFrameStyle(QFrame::Box | QFrame::Plain); |
| 198 | canvas->setLineWidth(1); |
| 199 | canvas->setPalette(canvas_bg); |
| 200 | canvas->setPaintAttribute(QwtPlotCanvas::BackingStore, true); |
| 201 | abs_canvas = canvas; |
| 202 | } |
| 203 | abs_canvas->setObjectName("qwtCanvas"); |
| 204 | |
| 205 | plot_ = new QwtPlotPimpl(this, abs_canvas, on_view_resized, on_event); |
| 206 | |
| 207 | auto* layout = new QHBoxLayout(this); |
| 208 | layout->setContentsMargins(0, 0, 0, 0); |
| 209 | layout->addWidget(plot_); |
| 210 | |
| 211 | plot_->setMinimumSize(100, 100); |
| 212 | plot_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 213 | plot_->canvas()->setMouseTracking(true); |
| 214 | // Opaque background: a transparent canvas forces a per-paint alpha-composite of the whole |
| 215 | // canvas (slow in software raster) instead of a fast opaque blit. canvas_bg matches the palette set above. |
| 216 | plot_->setCanvasBackground(canvas_bg); |
| 217 | plot_->setAxisAutoScale(QwtPlot::yLeft, true); |
| 218 | plot_->setAxisAutoScale(QwtPlot::xBottom, true); |
| 219 | plot_->axisScaleEngine(QwtPlot::xBottom)->setAttribute(QwtScaleEngine::Floating, true); |
| 220 | plot_->plotLayout()->setAlignCanvasToScales(true); |
| 221 | plot_->setAxisScale(QwtPlot::xBottom, 0.0, 1.0); |
| 222 | plot_->setAxisScale(QwtPlot::yLeft, 0.0, 1.0); |
| 223 | } |
| 224 | |
| 225 | PlotWidgetBase::~PlotWidgetBase() { |
nothing calls this directly
no test coverage detected