jfjoch_viewer: Polish UI

This commit is contained in:
2025-11-26 10:21:26 +01:00
parent 2b28aa3a46
commit b28470c21c
2 changed files with 29 additions and 22 deletions

View File

@@ -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

View File

@@ -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) {