// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "JFJochViewerMagnifier.h" #include #include #include #include JFJochViewerMagnifier::JFJochViewerMagnifier(QWidget *parent) : QWidget(parent) { auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); // Screen pixels per detector pixel and label font size; the labels are sized to fit a // six-digit count inside its pixel. struct Level { const char *name; const char *tooltip; double zoom; int font_px; }; const Level levels[] = { {"\u00d764", "Pixel values in large text", 64.0, 15}, {"\u00d732", "Pixel values in small text", 32.0, 9}, {"\u00d710", "Wider field, no pixel values", 10.0, 0}, }; auto buttons = new QHBoxLayout(); auto group = new QButtonGroup(this); for (const auto &l : levels) { auto b = new QToolButton(this); b->setText(QString::fromUtf8(l.name)); b->setToolTip(l.tooltip); b->setCheckable(true); group->addButton(b); buttons->addWidget(b); connect(b, &QToolButton::toggled, this, [this, l](bool on) { if (on) image_->SetZoom(l.zoom, l.font_px); }); } buttons->addStretch(); pop_out_ = new QToolButton(this); connect(pop_out_, &QToolButton::clicked, this, &JFJochViewerMagnifier::popOutClicked); setPoppedOut(false); buttons->addWidget(pop_out_); layout->addLayout(buttons); image_ = new JFJochFollowerImage(this); image_->setMinimumHeight(200); image_->setToolTip("Move the cursor over the diffraction image with Shift held to move the magnifier"); image_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layout->addWidget(image_, 1); connect(image_, &JFJochFollowerImage::fieldChanged, this, &JFJochViewerMagnifier::fieldChanged); group->buttons().first()->setChecked(true); } void JFJochViewerMagnifier::setPoppedOut(bool on) { pop_out_->setText(on ? "Dock" : "Pop out"); pop_out_->setToolTip(on ? "Put the magnifier back into its panel" : "Show the magnifier in a window of its own"); } void JFJochViewerMagnifier::setFrame(std::shared_ptr frame) { image_->SetFrame(std::move(frame)); } void JFJochViewerMagnifier::setPixelValues(std::shared_ptr image) { image_->SetPixelValues(std::move(image)); } void JFJochViewerMagnifier::centerAt(QPointF scenePos) { image_->CenterAt(scenePos); }