From b28470c21cb8d7d207bbf0fdbd43b2ab11df3e9d Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 26 Nov 2025 10:21:26 +0100 Subject: [PATCH] jfjoch_viewer: Polish UI --- viewer/JFJochViewerWindow.cpp | 6 ++-- viewer/image_viewer/JFJochImage.cpp | 45 +++++++++++++++++------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/viewer/JFJochViewerWindow.cpp b/viewer/JFJochViewerWindow.cpp index 34d98cd5..97c0c687 100644 --- a/viewer/JFJochViewerWindow.cpp +++ b/viewer/JFJochViewerWindow.cpp @@ -100,11 +100,11 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString menuBar->AddWindowEntry(tableWindow, "Image list"); menuBar->AddWindowEntry(spotWindow, "Spot list"); menuBar->AddWindowEntry(reflectionWindow, "Reflection list"); - menuBar->AddWindowEntry(metadataWindow, "Metadata edit"); + menuBar->AddWindowEntry(metadataWindow, "Image metadata"); menuBar->AddWindowEntry(processingWindow, "Image processing settings"); - menuBar->AddWindowEntry(azintWindow, "Azimuthal integration settings"); menuBar->AddWindowEntry(calibrationWindow, "Calibration image viewer"); - menuBar->AddWindowEntry(azintImageWindow, "2D Azimuthal integration image"); + menuBar->AddWindowEntry(azintWindow, "Azimuthal integration settings"); + menuBar->AddWindowEntry(azintImageWindow, "Azimuthal integration 2D image"); if (dbus) { // Create adaptor attached to this window diff --git a/viewer/image_viewer/JFJochImage.cpp b/viewer/image_viewer/JFJochImage.cpp index cc15d683..a69db633 100644 --- a/viewer/image_viewer/JFJochImage.cpp +++ b/viewer/image_viewer/JFJochImage.cpp @@ -305,13 +305,22 @@ static void setClipboardAsJpegAndImage(const QImage &img, int quality = 95) { ba.reserve(img.width() * img.height() * 3 / 2); QBuffer buf(&ba); buf.open(QIODevice::WriteOnly); - img.convertToFormat(QImage::Format_ARGB32); // ensure a known format for encoding - img.save(&buf, "JPEG", quality); + + QImage toSave = img; + // Force 1:1 pixel ratio and standard DPI (96) to avoid scaling in consumer apps + toSave.setDevicePixelRatio(1.0); + constexpr int dotsPerMeter96DPI = 3780; // 96 DPI + toSave.setDotsPerMeterX(dotsPerMeter96DPI); + toSave.setDotsPerMeterY(dotsPerMeter96DPI); + + toSave = toSave.convertToFormat(QImage::Format_ARGB32); // ensure a known format for encoding + toSave.save(&buf, "JPEG", quality); auto *mime = new QMimeData(); mime->setData("image/jpeg", ba); - mime->setImageData(img); // also set as generic bitmap + mime->setImageData(toSave); // also set as generic bitmap QGuiApplication::clipboard()->setMimeData(mime); + } void JFJochImage::copyImageToClipboard() { @@ -319,8 +328,15 @@ void JFJochImage::copyImageToClipboard() { // Use the underlying rendered image (no overlay) QImage img = pixmap.toImage(); + // Ensure 1:1 pixel ratio and 96 DPI metadata + img.setDevicePixelRatio(1.0); + constexpr int dotsPerMeter96DPI = 3780; + img.setDotsPerMeterX(dotsPerMeter96DPI); + img.setDotsPerMeterY(dotsPerMeter96DPI); + setClipboardAsJpegAndImage(img, 95); emit writeStatusBar(tr("Image copied to clipboard"), 2000); + } void JFJochImage::copyImageWithOverlayToClipboard() { @@ -329,6 +345,12 @@ void JFJochImage::copyImageWithOverlayToClipboard() { // Render the entire scene (image + overlay) at native image resolution QImage img(int(W), int(H), QImage::Format_ARGB32_Premultiplied); img.fill(Qt::transparent); + // Ensure 1:1 and 96 DPI before rendering to avoid metadata-based rescaling + img.setDevicePixelRatio(1.0); + constexpr int dotsPerMeter96DPI = 3780; + img.setDotsPerMeterX(dotsPerMeter96DPI); + img.setDotsPerMeterY(dotsPerMeter96DPI); + QPainter p(&img); // Ensure we render the same logical rect as the scene/image coordinates const QRectF sourceRect(0, 0, qreal(W), qreal(H)); @@ -554,22 +576,6 @@ void JFJochImage::Redraw() { void JFJochImage::GeneratePixmap() { - - /* - if (auto_fg || auto_bg) { - auto vec1(image_fp); - std::sort(vec1.begin(), vec1.end()); - - if (auto_fg) { - foreground = vec1[vec1.size() - 1]; - emit foregroundChanged(foreground); - } - if (auto_bg) { - background = vec1[0]; - emit backgroundChanged(background); - } - } */ - QImage qimg(int(W), int(H), QImage::Format_RGB888); image_rgb.resize(W * H); @@ -605,6 +611,7 @@ void JFJochImage::GeneratePixmap() { } pixmap = QPixmap::fromImage(qimg); + pixmap.setDevicePixelRatio(1.0); } void JFJochImage::centerOnSpot(QPointF point) {