Merge 13.11 (cc9bf95); Blur pieces and per-tile clone pieces on its grid sampling (13.16, part two)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-01 18:38:05 -04:00
commit c7e8bdfe8e
30 files changed
+910 -173

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
// Swift's BlurTool extension: what a Blur stroke paints.
public:
// The sharp layer or mask, document-sized; `render` softens parts.
std::optional<BrushStroke::Clone> blurSample(const CanvasDocument &document, bool mask = false) const;
// The stroke's pixels or mask, sharp; `render` softens parts.
std::optional<BrushStroke::Clone> blurSample(const BrushStroke &stroke) const;
+26 -35
View File
@@ -2,7 +2,6 @@
#include "Document/PixelAdjust.h"
#include "IO/ImageExporter.h"
#include "Logging.h"
#include "Rendering/LayerRenderer.h"
#include <cmath>
namespace {
@@ -39,46 +38,38 @@ std::function<QImage(const QRect &)> softened(const QImage &sharp, double sigma,
}
}
// Swift's BlurTool extension: the layer, or its mask, softened.
std::optional<BrushStroke::Clone> EditorSession::blurSample(const CanvasDocument &document, bool mask) const
// Swift's BlurTool extension: the layer's pixels, or mask, softened.
std::optional<BrushStroke::Clone> EditorSession::blurSample(const BrushStroke &stroke) const
{
const std::optional<ImageLayer> layer = activeLayer();
if (!layer)
const ImageLayer &layer = stroke.layer;
const std::optional<ImportedImage> &asset = stroke.isMask ? (layer.mask ? std::optional(layer.mask->asset) : std::nullopt) : layer.asset;
if (!asset)
return std::nullopt;
// The bar's Radius, whatever the brush's size.
const double sigma = std::min(50.0, std::max(0.5, m_brushSettings.blurRadius));
// The bar's Radius, carried into the layer's pixels.
const QTransform &map = stroke.pixelToDocument;
const double perPixel = std::max(1e-6, std::sqrt(std::abs(map.m11() * map.m22() - map.m12() * map.m21())));
const double sidePixels = std::max(stroke.sourceRect.width(), stroke.sourceRect.height());
const double sigma = std::min(std::min(50.0, std::max(0.5, m_brushSettings.blurRadius)) / perPixel, sidePixels / 2);
// Room for the blur to spread past the pixels' edges.
const double margin = std::ceil(3 * sigma);
const QRectF region = stroke.sourceRect.adjusted(-margin, -margin, margin, margin);
// A huge layer's sample is made coarser, within several canvases.
const qint64 canvas = m_document ? qint64(m_document->width) * m_document->height : 0;
const double budget = double(std::min(DocumentLimits::maxSurfacePixels, std::max<qint64>(16'000'000, 4 * canvas)));
const double fit = std::min(1.0, std::sqrt(budget / (region.width() * region.height())));
const int width = std::max(1, int(std::ceil(region.width() * fit))), height = std::max(1, int(std::ceil(region.height() * fit)));
const QRectF placed(margin * fit, margin * fit, stroke.sourceRect.width() * fit, stroke.sourceRect.height() * fit);
try {
if (mask) {
if (!layer->mask)
return std::nullopt;
QImage context = BrushRaster::context(document.width, document.height, true);
// Past its pixels a mask keeps its edge tone.
const int tone = int(std::round(LayerMask::background(layer->mask->asset.thumbnail) * 255));
context.fill(QColor(tone, tone, tone));
QPainter painter(&context);
// Coverage only adds white: the mask's area starts black.
const LayerTransform placement = layer->maskTransform();
painter.save();
QTransform box;
box.translate(placement.center().x(), placement.center().y());
box.rotateRadians(placement.radians());
painter.setTransform(box, true);
painter.fillRect(QRectF(-placement.size.width() / 2, -placement.size.height() / 2, placement.size.width(), placement.size.height()),
Qt::black);
painter.restore();
LayerRenderer::drawCoverage(layer->mask->asset.image(), placement, painter);
painter.end();
return BrushStroke::Clone{context, QSizeF(0, 0), softened(context, sigma, true)};
}
if (!layer->asset)
return std::nullopt;
QImage context = BrushRaster::context(document.width, document.height, false);
QImage context = BrushRaster::context(width, height, stroke.isMask);
// Past its pixels a mask keeps its edge tone.
if (stroke.isMask && layer.mask)
context.fill(int(std::round(LayerMask::background(layer.mask->asset.thumbnail) * 255)));
QPainter painter(&context);
// A painted asset flattens here; the catch covers it too.
const LayerTransform transform = displayedTransform(*layer);
LayerRenderer::draw(layer->asset->image(), transform, transform.center(), painter, {});
BrushRaster::draw(asset->image(), placed, painter);
painter.end();
return BrushStroke::Clone{context, QSizeF(0, 0), softened(context, sigma, false)};
// Sharp; only the parts the brush reaches are softened.
return BrushStroke::Clone{context, region, true, softened(context, sigma * fit, stroke.isMask)};
} catch (const ExportError &error) {
qCWarning(lcApp) << "the Blur tool cannot sample the layer:" << error.what();
return std::nullopt;
+8
View File
@@ -58,6 +58,14 @@ LayerTransform BrushStroke::transform(const QRectF &bounds) const
return result;
}
// Offset into grid pixels, turned and scaled as the layer.
QRectF BrushStroke::gridRect(const QRectF &rect, QSizeF offset) const
{
const QTransform toGrid = pixelToDocument.inverted();
const QPointF shift = toGrid.map(QPointF(offset.width(), offset.height())) - toGrid.map(QPointF(0, 0));
return rect.translated(-shift);
}
// Swift's heal: the painted spot rebuilt from nearby texture.
void BrushStroke::heal()
{
+5 -4
View File
@@ -281,10 +281,11 @@ QImage BrushStroke::clonePixels(qint64 key, const Tile &tile)
if (!m_clone)
return QImage();
const int width = int(tile.rect.width()), height = int(tile.rect.height());
// Tile pixels to clone pixels: grid, document, then offset.
const QTransform toWhole = QTransform::fromTranslate(tile.rect.left(), tile.rect.top()) * pixelToDocument
* QTransform::fromTranslate(m_clone->offset.width(), m_clone->offset.height());
// Swift's clonePiece: the part under the tile, cut once.
// Tile to sample pixels; each tile's piece is cut once.
const QRectF &placed = m_clone->placed;
const QTransform toWhole = QTransform::fromTranslate(tile.rect.left(), tile.rect.top()) * (m_clone->inGrid ? QTransform() : pixelToDocument)
* QTransform::fromTranslate(-placed.left(), -placed.top())
* QTransform::fromScale(m_clone->image.width() / placed.width(), m_clone->image.height() / placed.height());
if (!m_clonePieces.contains(key)) {
const QRect part =
toWhole.mapRect(QRectF(0, 0, width, height)).adjusted(-2, -2, 2, 2).toAlignedRect().intersected(m_clone->image.rect());
+5 -2
View File
@@ -109,10 +109,11 @@ public:
qint64 pixelLimit = DocumentLimits::documentPixelBudget();
// Limits every edit to the document selection; nil when none.
std::optional<SelectionClip> selectionClip;
// Clone Stamp: a document-sized image, and each point's offset.
// Painted through the tip, placed: document or `inGrid` pixels.
struct Clone {
QImage image;
QSizeF offset;
QRectF placed;
bool inGrid;
// Makes a part of `image`: Blur softens piece by piece.
std::function<QImage(const QRect &)> render;
};
@@ -152,6 +153,8 @@ public:
QRectF committedBounds() const;
LayerTransform committedTransform() const;
LayerTransform transform(const QRectF &bounds) const;
// `rect` shifted to copy from `offset` document pixels away.
QRectF gridRect(const QRectF &rect, QSizeF offset) const;
// Spot Healing's end: the painted spot rebuilt from around it.
void heal();
PaintSnapshot paintSnapshot() const;
+2 -2
View File
@@ -6,5 +6,5 @@ public:
std::optional<QSizeF> cloneStrokeOffset(QPointF point) const;
// The source for a brush at `point`: the canvas's crosshair.
std::optional<QPointF> cloneSamplePoint(QPointF point) const;
// What a stroke copies from, document-sized, taken as it starts.
std::optional<QImage> cloneSample(const CanvasDocument &document) const;
// What `stroke` copies, `offset` away: its pixels or the canvas.
std::optional<BrushStroke::Clone> cloneSample(const CanvasDocument &document, const BrushStroke &stroke, QSizeF offset) const;
+9 -10
View File
@@ -1,7 +1,6 @@
#include "Document/EditorSession.h"
#include "IO/ImageExporter.h"
#include "Logging.h"
#include "Rendering/LayerRenderer.h"
#include <cmath>
// Swift's CloneStamp extension: the source, its offset, the sample.
@@ -40,20 +39,20 @@ std::optional<QPointF> EditorSession::cloneSamplePoint(QPointF point) const
return point + QPointF(m_cloneOffset->width(), m_cloneOffset->height());
}
std::optional<QImage> EditorSession::cloneSample(const CanvasDocument &document) const
std::optional<BrushStroke::Clone> EditorSession::cloneSample(const CanvasDocument &document, const BrushStroke &stroke, QSizeF offset) const
{
try {
// A painted asset flattens here; the catch covers it too.
if (!m_cloneSettings.sampleAllLayers) {
if (!stroke.layer.asset)
return std::nullopt;
return BrushStroke::Clone{stroke.layer.asset->image(), stroke.gridRect(stroke.sourceRect, offset), true, {}};
}
QImage context = BrushRaster::context(document.width, document.height, false);
QPainter painter(&context);
// A painted asset flattens here; the catch covers it too.
if (m_cloneSettings.sampleAllLayers) {
drawLiveComposite(document, painter);
} else if (const std::optional<ImageLayer> layer = activeLayer(); layer && layer->asset) {
const LayerTransform transform = displayedTransform(*layer);
LayerRenderer::draw(layer->asset->image(), transform, transform.center(), painter, {});
}
drawLiveComposite(document, painter);
painter.end();
return context;
return BrushStroke::Clone{context, QRectF(-offset.width(), -offset.height(), context.width(), context.height()), false, {}};
} catch (const ExportError &error) {
qCWarning(lcApp) << "Clone Stamp cannot sample the canvas:" << error.what();
return std::nullopt;
+44 -18
View File
@@ -37,6 +37,27 @@ bool EditorSession::canPaint() const
&& (m_isMaskSelected || !layer->adjustment);
}
std::optional<QString> EditorSession::paintRefusal() const
{
const std::optional<ImageLayer> layer = activeLayer();
if (!canEditLayers() || !layer || canPaint())
return std::nullopt;
if (m_selectedLayerIDs.size() > 1)
return QStringLiteral("Several layers are selected. Select just one to paint on it.");
if (layer->isGroup && !m_isMaskSelected)
return QStringLiteral("“%1” is a folder, which has no pixels of its own. Paint on a layer inside it, or on the folder’s mask.").arg(layer->name);
if (!m_document->effectiveVisibleIDs().contains(layer->id))
return QStringLiteral("“%1” is hidden, or inside a hidden folder. Show it to paint on it.").arg(layer->name);
if (m_isMaskSelected && !(layer->mask && layer->mask->isEnabled))
return QStringLiteral("The layer mask is turned off. Shift-click its thumbnail to turn it on, then paint.");
if (!m_isMaskSelected && layer->adjustment)
return QStringLiteral("“%1” is an adjustment layer, with no pixels to paint. Paint on its mask instead.").arg(layer->name);
const std::optional<DocumentSelection> current = selection();
if (current && current->isEmpty())
return QStringLiteral("Nothing is selected, so there’s nowhere to paint. Choose Select › Deselect (Ctrl+D) to paint anywhere.");
return std::nullopt;
}
// A tiled raster edit of pixels or mask, within budget.
std::unique_ptr<BrushStroke> EditorSession::makeRasterEdit(const ImageLayer &layer, const BrushSettings &settings, bool growsMask) const
{
@@ -74,27 +95,20 @@ void EditorSession::beginBrush(QPointF point)
}
// Spot Healing and Clone Stamp rework pixels, never a mask.
const bool paintsMasks = m_tool == NavigationTool::brush || m_tool == NavigationTool::blur;
if ((!paintsMasks && (!isBrushTool(m_tool) || m_isMaskSelected)) || !canPaint())
if (!paintsMasks && (!isBrushTool(m_tool) || m_isMaskSelected))
return;
if (!canPaint()) {
setBrushError(paintRefusal());
return;
}
const ImageLayer layer = activeLayer().value();
std::optional<BrushStroke::Clone> clone;
std::optional<QSizeF> sourceOffset;
if (m_tool == NavigationTool::cloneStamp) {
const std::optional<QSizeF> offset = cloneStrokeOffset(point);
if (!offset) {
sourceOffset = cloneStrokeOffset(point);
if (!sourceOffset) {
setBrushError(QStringLiteral("Alt-click where Clone Stamp should copy from first."));
return;
}
const std::optional<QImage> image = cloneSample(m_document.value());
if (!image)
return;
m_cloneOffset = offset;
clone = BrushStroke::Clone{*image, *offset, {}};
}
// Blur paints a softened copy of the layer, in place.
if (m_tool == NavigationTool::blur) {
clone = blurSample(m_document.value(), m_isMaskSelected);
if (!clone)
return;
}
finishOpacityEdit();
try {
@@ -107,9 +121,21 @@ void EditorSession::beginBrush(QPointF point)
settings.green = settings.red;
settings.blue = settings.red;
}
m_brushStroke = makeRasterEdit(layer, settings, m_tool == NavigationTool::brush);
m_brushStroke->setClone(clone);
m_brushStroke->isBlur = m_tool == NavigationTool::blur;
std::unique_ptr<BrushStroke> stroke = makeRasterEdit(layer, settings, m_tool == NavigationTool::brush);
if (sourceOffset) {
stroke->setClone(cloneSample(m_document.value(), *stroke, *sourceOffset));
if (!stroke->clone())
return;
m_cloneOffset = sourceOffset;
}
// Blur paints a softened copy of the layer, in place.
if (m_tool == NavigationTool::blur) {
stroke->setClone(blurSample(*stroke));
if (!stroke->clone())
return;
}
stroke->isBlur = m_tool == NavigationTool::blur;
m_brushStroke = std::move(stroke);
m_brushStroke->append(point);
m_brushAnchor = point;
m_brushPointer = point;
+2
View File
@@ -1,6 +1,8 @@
// Swift's EditorSession+Brush extension: a stroke from press to commit.
public:
bool canPaint() const;
// Why the target refuses a stroke; none while busy.
std::optional<QString> paintRefusal() const;
std::unique_ptr<BrushStroke> makeRasterEdit(const ImageLayer &layer, const BrushSettings &settings = BrushSettings(), bool growsMask = false) const;
void beginBrush(QPointF point);
void continueBrush(QPointF point);
+6 -1
View File
@@ -35,8 +35,13 @@ void EditorSession::setGradientSettings(const GradientSettings &settings)
void EditorSession::beginGradient(QPointF point)
{
const std::optional<ImageLayer> layer = activeLayer();
if (m_tool != NavigationTool::gradient || !(canPaint() || m_gradientEdit) || !layer)
if (m_tool != NavigationTool::gradient || !layer)
return;
// Swift explains only past this guard, where nothing refuses.
if (!canPaint() && !m_gradientEdit) {
setBrushError(paintRefusal());
return;
}
// A new line on this target replaces the pending one.
if (m_gradientEdit && m_gradientEdit->raster->layer.id == layer->id && m_gradientEdit->raster->isMask == m_isMaskSelected) {
m_gradientEdit->start = point;
+3 -1
View File
@@ -420,5 +420,7 @@ void EditorSession::invertSelection()
const std::optional<DocumentSelection> current = selection();
if (!m_document || !current)
return;
setSelection(DocumentSelection{canvasPath(*m_document).subtracted(current->path), current->antialiased, current->feather}, QStringLiteral("Inverse"));
const DocumentSelection inverse{canvasPath(*m_document).subtracted(current->path), current->antialiased, current->feather};
// The inverse of everything is no selection, as Photoshop's.
setSelection(inverse.isEmpty() ? std::nullopt : std::optional(inverse), QStringLiteral("Inverse"));
}
+2 -3
View File
@@ -229,8 +229,7 @@ void EditorSession::beginWarp(QPointF point)
{
const std::optional<ImageLayer> layer = activeLayer();
if (!canPaint() || m_isMaskSelected || !layer || !layer->asset || !m_document) {
if (m_isMaskSelected)
setBrushError(QStringLiteral("Smudge and Liquify work on a layer's pixels, not its mask."));
setBrushError(m_isMaskSelected ? std::optional(QStringLiteral("Smudge and Liquify work on a layer's pixels, not its mask.")) : paintRefusal());
return;
}
finishOpacityEdit();
@@ -268,7 +267,7 @@ void EditorSession::finishWarp()
settings.hardness = 1;
settings.opacity = 1;
const std::unique_ptr<BrushStroke> stroke = makeRasterEdit(current, settings);
stroke->setClone(BrushStroke::Clone{warp->image(), QSizeF(0, 0), {}});
stroke->setClone(BrushStroke::Clone{warp->image(), QRectF(QPointF(0, 0), warp->image().size()), false, {}});
stroke->replacesWithClone = true;
stroke->editName = rawValue(warp->mode);
// A point every twentieth of the tip covers every dab.
+9 -1
View File
@@ -85,7 +85,15 @@ bool CanvasView::moveSelectionTool(QPointF point, Qt::KeyboardModifiers modifier
{
if (m_pixelDragStart && m_session.document()) {
const QPointF pixel = m_session.viewport.documentPoint(point, m_session.document()->size());
m_session.movePixels(QSizeF(pixel.x() - m_pixelDragStart->x(), pixel.y() - m_pixelDragStart->y()));
QSizeF offset(pixel.x() - m_pixelDragStart->x(), pixel.y() - m_pixelDragStart->y());
// Shift keeps the pixels on a line, the longer way.
if (modifiers.testFlag(Qt::ShiftModifier)) {
if (std::abs(offset.width()) >= std::abs(offset.height()))
offset.setHeight(0);
else
offset.setWidth(0);
}
m_session.movePixels(offset);
updateCursor();
synchronizeDisplay();
return true;
-12
View File
@@ -2,20 +2,10 @@
#include "IO/RecentProjects.h"
#include "Logging.h"
#include "UI/KeyboardShortcuts.h"
#include "UI/NativeLayerList.h"
#include <QApplication>
#include <QMenu>
namespace {
// The layer list holding the keys, as Swift's table.
NativeLayerList *focusedList()
{
for (QWidget *widget = QApplication::focusWidget(); widget; widget = widget->parentWidget())
if (auto *list = qobject_cast<NativeLayerList *>(widget))
return list;
return nullptr;
}
// An entry's name: Hue/Saturation is newHueSaturationAdjustment.
QString adjustmentName(AdjustmentKind kind)
{
@@ -186,8 +176,6 @@ CompositorMenus::CompositorMenus(ProjectWorkspace &workspace, QMenuBar &bar, QWi
m_field->selectAll();
else if (InlineTextEditor *text = typedText())
text->selectAll();
else if (NativeLayerList *list = focusedList())
list->selectAllRows();
else
session().selectAll();
});
+17 -1
View File
@@ -4,6 +4,7 @@
#include <QApplication>
#include <QContextMenuEvent>
#include <QKeyEvent>
#include <QLocale>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
@@ -115,7 +116,7 @@ void LayerCell::configure(const ImageLayer &layer, bool enabled, int depth, bool
m_dimensions->setText(m_editableText ? QStringLiteral("Text · Double-click to edit")
: m_isAdjustment ? QStringLiteral("Adjustment · Double-click to edit")
: layer.isGroup ? QStringLiteral("Folder")
: QStringLiteral("%1 × %2 px").arg(std::lround(layer.size().width())).arg(std::lround(layer.size().height())));
: sizeLabel(layer));
m_dimensions->setToolTip(QString());
if (layer.maskSourceID && session.document()) {
const int source = indexOf(session.document()->layers, layer.maskSourceID);
@@ -335,3 +336,18 @@ bool LayerCell::eventFilter(QObject *watched, QEvent *event)
return false;
return true;
}
QString sizeLabel(const ImageLayer &layer)
{
const QString text = QStringLiteral("%1 × %2 px").arg(std::lround(layer.size().width())).arg(std::lround(layer.size().height()));
const int pixels = layer.asset ? layer.asset->size().width() : 0;
if (pixels <= 0)
return text;
// Across the width, as the Move bar's Scale field.
const double percent = layer.size().width() / pixels * 100;
if (std::abs(percent - 100) < 0.05)
return text;
// Swift's .number to one place at most, ties to even.
const double rounded = std::nearbyint(percent * 10) / 10;
return text + QStringLiteral(" · ") + QLocale().toString(rounded, 'f', rounded == std::trunc(rounded) ? 0 : 1) + QStringLiteral("%");
}
-10
View File
@@ -261,13 +261,3 @@ void NativeLayerList::changeEvent(QEvent *event)
if (event->type() == QEvent::PaletteChange)
QMetaObject::invokeMethod(this, &NativeLayerList::update, Qt::QueuedConnection);
}
void NativeLayerList::selectAllRows()
{
if (m_rows.empty())
return;
QSet<QUuid> ids;
for (const ImageLayer &row : m_rows)
ids.insert(row.id);
m_session.selectLayers(ids, m_rows.front().id);
}
+3 -2
View File
@@ -215,8 +215,6 @@ public:
QString dragToken() const { return m_dragToken; }
EditorSession &session() const { return m_session; }
// The table's Select All: every row, the top one primary.
void selectAllRows();
void update();
std::vector<LayerCell *> cells() const { return m_cells; }
// The row under a point of this list, or -1.
@@ -281,3 +279,6 @@ private:
const QMimeData *m_dragData = nullptr;
Qt::DropActions m_dragActions;
};
// The size on the canvas and, once scaled, how much.
QString sizeLabel(const ImageLayer &layer);
+32 -2
View File
@@ -109,7 +109,8 @@ TransformInspector::TransformInspector(EditorSession &session, QWidget *parent)
m_rotation(new TransformValueField(QStringLiteral("°"), QString(), -360, 360, session, [this] { finish(); }, [this](double number) {
change([number](LayerTransform &value) { value.rotation = std::fmod(number, 360.0); });
})),
m_sampling(new QComboBox(this)), m_cancel(new QPushButton(QStringLiteral("Cancel"), this)), m_apply(new QPushButton(QStringLiteral("Apply"), this))
m_sampling(new QComboBox(this)), m_cancel(new QPushButton(QStringLiteral("Cancel"), this)), m_apply(new QPushButton(QStringLiteral("Apply"), this)),
m_pendingButtons(new QWidget(this)), m_fade(new QGraphicsOpacityEffect(m_pendingButtons)), m_fadeIn(new QPropertyAnimation(m_fade, "opacity", this))
{
m_autoSelect->setObjectName(QStringLiteral("transformAutoSelect"));
m_autoSelect->setToolTip(QStringLiteral("Select layers by clicking the canvas. Hold Ctrl to turn it the other way while you click."));
@@ -176,8 +177,25 @@ TransformInspector::TransformInspector(EditorSession &session, QWidget *parent)
// Swift's configuredNativeShortcut: Return and Escape, as remapped.
NativeShortcut::bind(*this, m_apply, m_cancel);
connect(m_apply, &QPushButton::clicked, this, [this] { m_session.commitTransform(); });
m_pendingButtons->setObjectName(QStringLiteral("pendingTransform"));
auto *pending = new QHBoxLayout(m_pendingButtons);
pending->setContentsMargins(0, 0, 0, 0);
pending->setSpacing(12);
pending->addWidget(m_cancel);
pending->addWidget(m_apply);
// Unseen, not hidden: Return and Escape still reach a drag.
m_pendingButtons->setGraphicsEffect(m_fade);
m_fade->setOpacity(0);
m_pendingButtons->setAttribute(Qt::WA_TransparentForMouseEvents);
m_cancel->setFocusPolicy(Qt::NoFocus);
m_apply->setFocusPolicy(Qt::NoFocus);
// SwiftUI's easeOut over 0.12 seconds.
QEasingCurve easeOut(QEasingCurve::BezierSpline);
easeOut.addCubicBezierSegment(QPointF(0, 0), QPointF(0.58, 1), QPointF(1, 1));
m_fadeIn->setEasingCurve(easeOut);
m_fadeIn->setDuration(120);
// Before the stretch ending the row, in Swift's order.
for (QWidget *widget : std::initializer_list<QWidget *>{m_autoSelect, m_showControls, m_fields, m_cancel, m_apply})
for (QWidget *widget : std::initializer_list<QWidget *>{m_autoSelect, m_showControls, m_fields, m_pendingButtons})
row->insertWidget(row->count() - 1, widget, widget == m_fields ? 1 : 0);
// The scroll view takes the spare room, as SwiftUI's does.
row->setStretch(row->count() - 1, 0);
@@ -301,4 +319,16 @@ void TransformInspector::synchronize()
m_fields->widget()->setEnabled((m_session.canTransform() || editing) && !distorted);
m_cancel->setEnabled(editing);
m_apply->setEnabled(editing);
// Typed values, Ctrl+T, a distortion wait; a handle drag applies.
const bool pending = editing && m_session.transformEdit()->persistent;
if (pending == m_pending)
return;
m_pending = pending;
m_pendingButtons->setAttribute(Qt::WA_TransparentForMouseEvents, !pending);
m_cancel->setFocusPolicy(pending ? Qt::StrongFocus : Qt::NoFocus);
m_apply->setFocusPolicy(pending ? Qt::StrongFocus : Qt::NoFocus);
m_fadeIn->stop();
m_fadeIn->setStartValue(m_fade->opacity());
m_fadeIn->setEndValue(pending ? 1.0 : 0.0);
m_fadeIn->start();
}
+7
View File
@@ -3,7 +3,9 @@
#include "UI/ToolHeaderStyle.h"
#include <QCheckBox>
#include <QComboBox>
#include <QGraphicsOpacityEffect>
#include <QLineEdit>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QScrollArea>
#include <QToolButton>
@@ -80,4 +82,9 @@ private:
QComboBox *const m_sampling;
QPushButton *const m_cancel;
QPushButton *const m_apply;
// Cancel and Apply, seen only while an edit waits.
QWidget *const m_pendingButtons;
QGraphicsOpacityEffect *const m_fade;
QPropertyAnimation *const m_fadeIn;
bool m_pending = false;
};