Build Packages / Create release (push) Successful in 24s
Build Packages / build:viewer:macos-arm64:nocuda (push) Successful in 3m29s
Build Packages / build:rugnux:macos-arm64:nocuda (push) Successful in 2m43s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 8m27s
Build Packages / build:rugnux:linux-x86_64:cuda (push) Successful in 9m53s
Build Packages / build:viewer:linux-x86_64:nocuda (push) Successful in 9m58s
Build Packages / build:viewer:linux-x86_64:cuda (push) Successful in 11m22s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 13m39s
Build Packages / build:viewer:windows-x86_64:nocuda (push) Successful in 18m37s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 16m32s
Build Packages / build:viewer:windows-x86_64:cuda (push) Successful in 24m11s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m30s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 19m3s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 20m23s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 19m41s
Build Packages / Generate python client (push) Successful in 50s
Build Packages / Build documentation (push) Successful in 1m16s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 21m0s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 18m38s
Build Packages / build:rugnux:windows-x86_64:cuda (push) Successful in 14m33s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 17m55s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 20m50s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 18m38s
Build Packages / Unit tests (push) Successful in 1h46m14s
* jfjoch_broker: Optional per-dataset authentication - statistics, images and plots can require a bearer token, which jfjoch_viewer supports. * jfjoch_viewer: Dark mode and a theme-matched colour scheme, a magnifier panel, and simpler contrast and background controls. * Rugnux: Multiple performance improvements on GPU and CPU (CPU-only processing up to 40% faster, faster image decoding on ARM), with unchanged results. * Rugnux: `--model` rigid-body refinement runs on the GPU, and the model-validation check is faster and more reliable. * Rugnux: Improved scaling and merging - error model, outlier rejection, absorption correction and French-Wilson amplitudes now agree more closely with XDS and ctruncate. * Rugnux: Improved integration - radial background on powder and ice rings, crowded rotation data keep their reflections, and CPU-only builds integrate large unit cells as GPU builds do. * Rugnux: More robust detector geometry - measured beam centre, X-ray bandwidth and goniometer rate, and geometry refinement accepted only on significant evidence. * Rugnux: Merged files are written in the standard setting, or in the setting of a reference MTZ, structure-factor mmCIF or model, with its free-R flags. * Rugnux: Richer report - ice and powder rings, further lattices, superstructure candidates and mosaicity, with warnings worded as prompts to check. * Rugnux: Clear error messages when a data set needs more GPU or host memory than is available. Reviewed-on: #83 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
258 lines
8.9 KiB
C++
258 lines
8.9 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ToolbarIcons.h"
|
|
#include "../ViewerTheme.h"
|
|
|
|
#include <QIconEngine>
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
#include <QPolygonF>
|
|
#include <cmath>
|
|
#include <functional>
|
|
#include <numbers>
|
|
|
|
namespace {
|
|
constexpr int S = 32;
|
|
const QColor DISABLED("#9AA6B3");
|
|
|
|
using DrawFn = std::function<void(QPainter &, const QColor &)>;
|
|
|
|
// The glyphs are drawn on an S x S canvas; the painter is scaled so they come out sharp at any size.
|
|
QPixmap render(const DrawFn &fn, const QColor &color, const QSize &size) {
|
|
QPixmap pm(size);
|
|
pm.fill(Qt::transparent);
|
|
QPainter p(&pm);
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
p.scale(size.width() / double(S), size.height() / double(S));
|
|
fn(p, color);
|
|
return pm;
|
|
}
|
|
|
|
// Draws the glyph when the icon is painted rather than when it is made, so the ink follows the
|
|
// theme: ink when off, white when on (a toggle on its navy checked background), grey when disabled.
|
|
class InkIconEngine final : public QIconEngine {
|
|
public:
|
|
InkIconEngine(DrawFn fn, bool toggle) : fn_(std::move(fn)), toggle_(toggle) {}
|
|
|
|
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override {
|
|
painter->drawPixmap(rect, pixmap(rect.size(), mode, state));
|
|
}
|
|
|
|
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override {
|
|
QColor color = IconInkColor();
|
|
if (mode == QIcon::Disabled)
|
|
color = DISABLED;
|
|
else if (toggle_ && state == QIcon::On)
|
|
color = Qt::white;
|
|
return render(fn_, color, size);
|
|
}
|
|
|
|
QIconEngine *clone() const override { return new InkIconEngine(fn_, toggle_); }
|
|
|
|
private:
|
|
DrawFn fn_;
|
|
bool toggle_;
|
|
};
|
|
|
|
QIcon toggleIcon(const DrawFn &fn) {
|
|
return QIcon(new InkIconEngine(fn, true));
|
|
}
|
|
|
|
void fillTriangle(QPainter &p, const QColor &c, QPointF a, QPointF b, QPointF tip) {
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawPolygon(QPolygonF({a, b, tip}));
|
|
}
|
|
|
|
void bar(QPainter &p, const QColor &c, double x) {
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawRoundedRect(QRectF(x, 9, 3.2, 14), 1.2, 1.2);
|
|
}
|
|
|
|
// A pair of curved arrows forming a refresh/sync ring.
|
|
void syncArrows(QPainter &p, const QColor &c) {
|
|
QPen pen(c, 2.4, Qt::SolidLine, Qt::RoundCap);
|
|
p.setPen(pen);
|
|
p.setBrush(Qt::NoBrush);
|
|
const QRectF r(9, 9, 14, 14);
|
|
p.drawArc(r, 40 * 16, 230 * 16);
|
|
p.drawArc(r, (40 + 180) * 16, 230 * 16);
|
|
// arrowheads at the two open ends
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawPolygon(QPolygonF({QPointF(22, 7.5), QPointF(22, 13.5), QPointF(17.5, 11)}));
|
|
p.drawPolygon(QPolygonF({QPointF(10, 24.5), QPointF(10, 18.5), QPointF(14.5, 21)}));
|
|
}
|
|
}
|
|
|
|
namespace ToolbarIcons {
|
|
|
|
QIcon first() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
bar(p, c, 9);
|
|
fillTriangle(p, c, {24, 9}, {24, 23}, {14, 16});
|
|
});
|
|
}
|
|
|
|
QIcon prev() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
fillTriangle(p, c, {22, 8}, {22, 24}, {11, 16});
|
|
});
|
|
}
|
|
|
|
QIcon next() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
fillTriangle(p, c, {10, 8}, {10, 24}, {21, 16});
|
|
});
|
|
}
|
|
|
|
QIcon last() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
fillTriangle(p, c, {8, 9}, {8, 23}, {18, 16});
|
|
bar(p, c, 19.8);
|
|
});
|
|
}
|
|
|
|
QIcon movie() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
// Two reels on top of a camera body with a lens barrel — an old-fashioned movie camera.
|
|
p.setBrush(Qt::NoBrush);
|
|
p.setPen(QPen(c, 1.8));
|
|
p.drawEllipse(QPointF(10, 11.5), 3.0, 3.0);
|
|
p.drawEllipse(QPointF(16.5, 11.5), 3.0, 3.0);
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawRoundedRect(QRectF(5, 15, 16, 10), 2, 2);
|
|
p.drawRoundedRect(QRectF(21, 17, 5, 6), 1, 1); // lens barrel
|
|
});
|
|
}
|
|
|
|
QIcon openFile() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
// 3.5" diskette ("save" floppy): square jacket with a cut top-right corner, the metal
|
|
// shutter across the top, and a label panel below.
|
|
p.setPen(QPen(c, 1.8));
|
|
p.setBrush(Qt::NoBrush);
|
|
QPolygonF body({{6, 6}, {20, 6}, {26, 12}, {26, 26}, {6, 26}});
|
|
p.drawPolygon(body); // jacket
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawRect(QRectF(10, 6, 8, 5.5)); // metal shutter (top)
|
|
p.setBrush(Qt::NoBrush);
|
|
p.setPen(QPen(c, 1.6));
|
|
p.drawRect(QRectF(9.5, 15.5, 13, 8.5)); // label panel
|
|
});
|
|
}
|
|
|
|
QIcon reanalyzeImage() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
p.setPen(QPen(c, 2.0));
|
|
p.setBrush(Qt::NoBrush);
|
|
p.drawRoundedRect(QRectF(8, 8, 16, 16), 2.5, 2.5);
|
|
p.setBrush(c);
|
|
p.drawEllipse(QPointF(16, 16), 2.2, 2.2);
|
|
});
|
|
}
|
|
|
|
QIcon reanalyzeDataset() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
p.setPen(QPen(c, 2.0));
|
|
p.setBrush(Qt::NoBrush);
|
|
for (int i = 2; i >= 0; --i)
|
|
p.drawRoundedRect(QRectF(5 + i * 4.0, 5 + i * 4.0, 14, 14), 2.0, 2.0);
|
|
p.setBrush(c);
|
|
p.drawEllipse(QPointF(12, 12), 2.0, 2.0);
|
|
});
|
|
}
|
|
|
|
QIcon linePlot() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
// L-shaped axes + a rising zig-zag data line (a line plot, not bars).
|
|
p.setBrush(Qt::NoBrush);
|
|
p.setPen(QPen(c, 1.6, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
|
p.drawPolyline(QPolygonF({{7, 6}, {7, 25}, {26, 25}}));
|
|
p.setPen(QPen(c, 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
|
p.drawPolyline(QPolygonF({{9, 21}, {14, 13}, {18, 17}, {25, 8}}));
|
|
});
|
|
}
|
|
|
|
QIcon table() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
// Rounded outer frame with two inner row lines and two inner column lines.
|
|
p.setBrush(Qt::NoBrush);
|
|
p.setPen(QPen(c, 1.8));
|
|
p.drawRoundedRect(QRectF(6, 7, 20, 18), 2, 2);
|
|
p.setPen(QPen(c, 1.4));
|
|
p.drawLine(QPointF(6, 13), QPointF(26, 13));
|
|
p.drawLine(QPointF(6, 19), QPointF(26, 19));
|
|
p.drawLine(QPointF(12.7, 7), QPointF(12.7, 25));
|
|
p.drawLine(QPointF(19.3, 7), QPointF(19.3, 25));
|
|
});
|
|
}
|
|
|
|
QIcon halfSun() {
|
|
return toggleIcon([](QPainter &p, const QColor &c) {
|
|
// A sun whose disc is half filled, split along the diagonal: light and dark in one glyph.
|
|
p.setPen(QPen(c, 2.0));
|
|
p.setBrush(Qt::NoBrush);
|
|
p.drawEllipse(QPointF(16, 16), 7, 7);
|
|
QPainterPath disc, half;
|
|
disc.addEllipse(QPointF(16, 16), 7, 7);
|
|
half.addPolygon(QPolygonF({QPointF(32, 0), QPointF(32, 32), QPointF(0, 32)}));
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawPath(disc.intersected(half));
|
|
p.setPen(QPen(c, 2.2, Qt::SolidLine, Qt::RoundCap));
|
|
for (int i = 0; i < 8; i++) {
|
|
const double a = i * std::numbers::pi / 4.0;
|
|
p.drawLine(QPointF(16 + 10.5 * std::cos(a), 16 + 10.5 * std::sin(a)),
|
|
QPointF(16 + 13.5 * std::cos(a), 16 + 13.5 * std::sin(a)));
|
|
}
|
|
});
|
|
}
|
|
|
|
QIcon letterA(int size_step) {
|
|
return toggleIcon([size_step](QPainter &p, const QColor &c) {
|
|
// A bold "A" at 16, 21 or 26 units; all three stand on the same baseline, so side by side
|
|
// they read as a ladder of sizes.
|
|
QFont font;
|
|
font.setBold(true);
|
|
font.setPixelSize(16 + 5 * size_step);
|
|
QPainterPath path;
|
|
path.addText(0, 0, font, "A");
|
|
const QRectF r = path.boundingRect();
|
|
p.setPen(Qt::NoPen);
|
|
p.setBrush(c);
|
|
p.drawPath(path.translated(16 - r.center().x(), 28 - r.bottom()));
|
|
});
|
|
}
|
|
|
|
QIcon httpSync(HttpState state) {
|
|
QColor dot;
|
|
switch (state) {
|
|
case HttpState::Disconnected: dot = QColor("#9AA6B3"); break; // grey
|
|
case HttpState::Live: dot = QColor("#5CB85C"); break; // green
|
|
case HttpState::Frozen: dot = QColor("#E9A23B"); break; // amber
|
|
}
|
|
auto draw = [dot](QPainter &p, const QColor &c) {
|
|
syncArrows(p, c);
|
|
p.setPen(QPen(Qt::white, 1.2));
|
|
p.setBrush(dot);
|
|
p.drawEllipse(QPointF(24, 24), 4.2, 4.2); // status dot
|
|
};
|
|
return QIcon(new InkIconEngine(draw, false));
|
|
}
|
|
|
|
QString buttonStyle() {
|
|
return QString(
|
|
"QToolButton { border:none; border-radius:4px; padding:4px 6px; color:%1;"
|
|
" background:transparent; }"
|
|
" QToolButton:hover { background:rgba(250,114,104,0.20); }"
|
|
" QToolButton:checked { background:%2; color:white; }"
|
|
" QToolButton:disabled { color:#9AA6B3; }").arg(IconInkColor().name(), AccentFillColor().name());
|
|
}
|
|
|
|
} // namespace ToolbarIcons
|