diff --git a/AGENTS.md b/AGENTS.md index 86f986f..7ca73f5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -186,7 +186,7 @@ Platform adaptations, each forced by a missing Qt analog: - New Canvas in units, at a DPI, on a background (14.3, Swift 1.4.6: `b0b4f01`, `ab9779a`, `a00d8b6`): `NewCanvasUnit` and `NewCanvasBackground` (in `NewCanvasSheet.h`, Swift's file) are enums with free functions for Swift's members (`rawValue`, `name`, `next`, `pixels`, `text`; `title`, `next`, `color`). `pixels` trims Foundation's `.whitespaces` (`trimmedWhitespaces`), reads a comma as the point and parses as Swift's `Double(text)` (the whole text through `strtod_l` in the C locale, a leading white space refused), takes a positive number, turns a print size into pixels at the DPI rounded half away from zero, and wants a whole count from 1 to 30,000; Swift's `isFinite` term is dead (infinity fails the range, NaN the whole number) and left out. `text` prints whole pixels, or a print size to two decimals with none trailing, rounded as Foundation's format style rounds: the shortest decimal that reads back as the double (`QLocale::FloatingPointShortest`), then halves to even on its digits (1.905 cm prints 1.9, 3.175 prints 3.18, where rounding the binary value gives 1.91 and 3.17); checked once against Swift 6.0.3 for 1 to 4,000 pixels in every unit at 72 and 300 DPI, all 24,000 alike. The sheet starts in pixels at 72 DPI on a clear canvas each time (`a00d8b6`), and its three settings are Swift's `CyclePill`s, `QAbstractButton`s that paint their text in `PlaceholderText` at 12 pixels and, hovered, a capsule of the text colour at 10% (macOS's quaternary label): the background (Transparent, White, Black canvas), the unit (switching rewrites both fields in the new unit when both read, else leaves them) and the DPI (72 or 300; in a print unit its tooltip adds the pixels it makes). The fields' units follow the unit; the note shows only for a size that does not read, in the unit's words; presets and the clipboard's size are written in the unit. `createNewProject` and `createDocument` take the resolution (1 to 9,600, else 72) and the background; `firstLayer` makes a Background layer of that colour at full size with its thumbnail, or a blank Layer 1, and a background that cannot be allocated logs on `omaphoto.app` and falls back to the blank layer, Swift's `try?` (untested: only starvation reaches it). Tests: `NewCanvasUnitTests` (Swift's four; rounding, trimming, the DPI's ends, the thumbnail), `NewCanvasSheetTests` (the pills, the units, the DPI's tooltip, presets in units, Swift's number parsing). - Rotate Canvas 90° (14.4, Swift 1.4.6: `754f188`): `Document/CanvasRotation.cpp` twins Swift's file, `CanvasRotation+Session.h` its session half; `LayerTransform::quarterTurned` and `CanvasGuide::quarterTurned` are declared in their own headers and defined there, as `mirrored` is. `rotateCanvas` commits a transform edit and drops a crop frame first, asks `canEditLayers`, then turns every layer and placed mask about the canvas (the middle carried, the angle by ±90 through `fmod`, which keeps Swift's sign), swaps the sides in place, turns the guides and the selection's path (its feather and antialiasing kept), fits the view, one `Rotate Canvas 90° Clockwise` or `Counterclockwise` step; Swift's `finishOpacityEdit` is dead (`commitTransform` runs it, as `flipCanvas` notes) and left out. `restore` fits the view when the canvas changes size too. The Image menu lists both entries before the flips, enabled by `canEditLayers`. A fix the item's exact test found: QPainter turned a layer through `rotateRadians`, whose cos(π/2) is 6e-17, so a turned edge missed its pixel boundary and antialiasing shaved it, and its fixed-point bilinear fetch strayed a level or two (40 read 39) where CoreGraphics' low quality copies a pixel-aligned turn exactly. Every layer placement now turns through `LayerTransform::degrees()` and `QTransform::rotate`, which Qt builds exactly at ±90, ±270 and 180 and as `rotateRadians` elsewhere, and `LayerRenderer::upright` keeps Swift's upright (no turn) and adds a draw that takes image pixels onto device pixels one to one: the whole map from the image's pixels through its target rect, the placement and the painter's device transform is a signed permutation (no stretch on either axis, no shear, no perspective, the painter's own turn counted), within a thousandth of a pixel across the image, with the image's corner on a whole device pixel. Such a draw takes no filter; a turn half a pixel off, a stretched side or a turned painter still filters, as CoreGraphics' low quality blends them. Equivalent mutants: `degrees()` in `BrushStroke`'s grid map, `Distort` and `LayerMask` (the two matrices differ by 1e-16 there; the change keeps every placement one turn). Tests: `CanvasRotationTests` (Swift's four, a turned layer and a placed mask, the crop frame, the refit, refusals and steps), `SharpCanvasTests::aQuarterTurnOnWholePixelsCopiesAcross` (the rule's edges: every quarter, a nudge on either axis, a stretched side, a 30,000-pixel side leaning 0.0001°, painters turned, sheared and in perspective; plain and painted layers exact on whole pixels and filtered half off or stretched), `everyLayerAndEveryPlacedMaskTurns`, `anOpenEditClosesBeforeTheTurn` (an opacity drag and a pending transform each their own step), the menu in `ImageMenuTests`. - The command palette (14.6, Swift 1.4.6–1.4.9: `cb139a1`, `384632d`, `07b8b1e`, `94b57f7`, `bba92dc`, `088a5c1`, `720c121`): `UI/CommandPalette.h/.cpp` twin Swift's `CommandPalette.swift`: `CommandPaletteEntry` (an aggregate, `title` given beside `id`), `CommandPaletteSearch` (`score` and `rank`, a stable sort), `CommandPaletteMenu` (`entries` of a `QMenuBar`, `plain` for a title without its mnemonic, `&&` read as one ampersand), `CommandPaletteCommands` (`layerCommands`, `tools`, Swift's statics on the entry) and `CommandPaletteModel`. Scores work on graphemes (`QTextBoundaryFinder`) of the NFC text, Swift's Characters, which compare canonically (a decomposed accent in a recent project's name matches a composed one); `isLetter` and `isNumber` read the first code point's general category (`QChar`), where Swift reads its Alphabetic and numeric-type properties (known difference: marks and numeric ideographs). `CommandPaletteTests::scoresAreSwiftsOwn` pins scores Swift 6.0.3 computed with v1.4.9's own code. An entry holds a `QPointer` to its `QAction` and triggers it, where Swift finds the item again by its path (SwiftUI rebuilds menus; the twin's actions live with the window, and Open Recent's rebuilt entries become a warning on `omaphoto.app`, Swift's beep); Swift's app-menu skip has no twin (no app menu on Linux), and the menus are current already, synchronized on every `changed()`. Shortcuts print as `QKeySequence` native text. `UI/CommandPaletteView.h/.cpp` twin the view and controller: View › Search Commands… (Ctrl+F, first in View, `Search Commands` in `ShortcutDefinition::all` after Fit Canvas) toggles a `Qt::Popup` of 460 by 290 centred on the window's frame, so a click elsewhere puts it away (Swift's `resignKey`) and Wayland places it relative to its window; the menu's action is added to the popup, so its key, remapped too, closes it from inside. The field (17 pixels, 16 and 13 of margin) takes Up and Down (wrapping, the row scrolled into view), Return and Enter; Escape is the popup's own. The rows (`CommandPaletteRows`, painted: 13 pixels, the chosen row in the accent at 35% rounded 6, a drawn checkmark twelve points with six after for a toggle that is on, the key in a 12-pixel fixed font in `PlaceholderText`, a disabled entry in the disabled `WindowText`) run on a left release; "No commands match" shows over an empty list. Running closes the popup, activates the window and posts the entry to the event loop; a disabled entry warns and keeps it open. A hidden popup clears the focus it held: Qt returns focus only to a window's own focus widget, so the menus would otherwise keep the hidden field as the one whose undo Undo drives. Equivalent mutants: `score`'s `words.size() > 1` (one word is the phrase, which the tier before tried) and `rank`'s `!query.isEmpty()` (an empty query scores every entry 0). Tests: `CommandPaletteTests` (Swift's four model tests and Swift's scores, the model, a hand-built bar's paths, mnemonics, sections, hidden entries, numbering and a gone action, the real bar's entries and a toggle run through them, the mask commands, every tool and each named mode reached from its sibling, a refused tool), `CommandPaletteWindowTests` (Ctrl+F in the window, place, focus, Ctrl+F inside, ranking and wrapping with scrolling, Return and Enter running the chosen row once the loop is free, a disabled row, Escape, clicks in and out, the checkmark's room, a key drawn at the row's end with an elided title six points before it, the empty words). -- Canvas Only (14.7, Swift 1.4.6–1.4.7: `ad4bddf`, `088a5c1`, `720c121`): the session keeps `canvasOnly` (a getter and a setter that notifies), `escapeHasNothingToCancel` and `canToggleCanvasOnly` (Swift's terms). `ProjectWorkspaceView::toggleCanvasOnly` is Swift's delegate's: it keeps the window's state, hides the menu bar (Swift hides macOS's menu bar and Dock; the twin's menu bar is in the window) and the toolbar, and makes the window fullscreen, which on Linux also covers the desktop's own bars; again, it shows both and puts the state back. A window already fullscreen keeps the screen and hides only its toolbar, as Swift's. Swift's black frame over the window's rounded corners and rim has no twin: a fullscreen Linux window has neither. View › Toggle Fullscreen (after Search Commands, checkable, a plain F, Swift's unconfigured key; its definition joins the canvas group first, as Swift's) rests while `canToggleCanvasOnly` does not hold; a `QLineEdit` takes a plain letter through `ShortcutOverride`, so a field types its F, Swift's monitor that hands an F to an `NSText` first, and open text holds the entry resting. A hidden `QMenuBar` disables its actions' keys (Qt's shortcut context reads the bar's visibility), so every menu action is also added to the window, which keeps them live. Escape leaves (an application event filter, Swift's local monitor) when it carries no Ctrl, Alt, Meta or Shift, the window is active, nothing is left to cancel and the focus is neither a `QLineEdit` nor inside a `QDialog`, so a docked panel keeps its Escape (Swift's docked panel is a window of its own). `ContentView` hides the tool bar, the rail, the rulers, the layers panel and its edge, the status bar and their dividers (`m_panels`); `showHeader` clears `m_header` after deleting it, since a new bar's constructor signals and `synchronize` then finds no bar. The canvas's surround is black, and `DisplayState` carries the flag so it repaints. Tests: `CanvasOnlySessionTests` (the flag's signal, each gate term and each Escape term), `CanvasOnlyWindowTests` (F in and out with every bar, keys through the hidden menus, black, Escape after a cancel and with held keys, a field's F, a docked panel's and another window's Escape, an already fullscreen or maximised window, the entry resting under text, a picker and no document). +- Canvas Only (14.7, Swift 1.4.6–1.4.7: `ad4bddf`, `088a5c1`, `720c121`): the session keeps `canvasOnly` (a getter and a setter that notifies), `escapeHasNothingToCancel` and `canToggleCanvasOnly` (Swift's terms). `ProjectWorkspaceView::toggleCanvasOnly` is Swift's delegate's: it keeps the window's state, hides the menu bar (Swift hides macOS's menu bar and Dock; the twin's menu bar is in the window) and the toolbar, and makes the window fullscreen, which on Linux also covers the desktop's own bars; again, it shows both and puts the state back. A window already fullscreen keeps the screen and hides only its toolbar, as Swift's. Swift's black frame over the window's rounded corners and rim has no twin: a fullscreen Linux window has neither. View › Toggle Fullscreen (after Search Commands, checkable, a plain F, Swift's unconfigured key; its definition joins the canvas group first, as Swift's) rests while `canToggleCanvasOnly` does not hold; a `QLineEdit` takes a plain letter through `ShortcutOverride`, so a field types its F, Swift's monitor that hands an F to an `NSText` first, and open text holds the entry resting. A hidden `QMenuBar` disables its actions' keys (Qt's shortcut context reads the bar's visibility), so every menu action is also added to the window, which keeps them live. Escape leaves (an application event filter, Swift's local monitor) when it carries no Ctrl, Alt, Meta or Shift, the window is active, nothing is left to cancel and the focus is neither a `QLineEdit` nor inside a `QDialog`, so a docked panel keeps its Escape (Swift's docked panel is a window of its own). `ContentView` hides the tool bar, the rail, the rulers, the layers panel and its edge, the status bar and their dividers (`m_panels`); `showHeader` clears `m_header` after deleting it, since a new bar's constructor signals and `synchronize` then finds no bar. The canvas's surround is black, and `DisplayState` carries the flag so it repaints. Tests: `CanvasOnlySessionTests` (the flag's signal, each gate term and each Escape term), the definitions' place in `KeyboardShortcutsTests`, `CanvasOnlyWindowTests` (F in and out with every bar and the layers edge, the canvas filling the window, keys through the hidden menus, black, Escape after a cancel and with held keys, a field's F, a docked panel's and another window's Escape, an already fullscreen or maximised window, the entry resting under text, a picker and no document). - Drops between projects: `ProjectWorkspace::draggedLayerSource` finds the tab whose document holds the dragged id (Swift reads the drag pasteboard; the twin reads the drag's `QMimeData`, which every drop target has), `canReceiveDrag(data, destination)` refuses only a layer's own tab, and `receiveProviders` copies several ids one after another, as Swift awaits each provider, so a two-row drop on the New button opens two tabs as Swift's does. `ContentView` takes such a drop over its whole area (`setWorkspace` hands it the workspace; `acceptsDrop` keeps Swift's guards: busy, the sheet, the importer, a rename; `levels` arrives with 9.x), shows the 3-point accent ring inside the canvas while targeted and hands the drop's document point on when it fell on the canvas. `ProjectTabButton` takes drops for its tab (accent fill and rim, "Add to "), and `NewCanvasButton`, the toolbar's New canvas button with the action as its default, for a fresh tab ("Open in a new project tab"), both refusing an Alt drag, which duplicates in the panel; Swift's transient `NewTabDropSlot` in the strip has no twin, the New canvas button is `NewProjectDropTarget` already. Files and pictures arrived with 10.4. - `CanvasThumbnail` draws a layer or a mask inside the canvas's box at `backingScale` 2 (the panel's pixmaps carry that ratio); a mask's ground is `LayerMask::background`, white or black by its edge's majority, as the canvas treats it (Swift's `edgeTone` mean went with 12.12b). `LayerIcons` draws the panel's SF Symbols as paths, in one palette colour, like `ToolIcons`. `BlendModePicker` is a `QComboBox` whose popup previews the highlighted mode through `previewBlendMode` for the layer it opened on (Qt calls `hidePopup` before `activated`, so the preview, the target and the highlight are cleared from the event loop, after a choice had its chance) and refuses a choice once another layer is active. `LayerAppearanceControls` is Swift's blend and opacity row: the slider's press and release are one opacity drag (the release is watched application-wide while the slider is down, so a popup opened mid-drag cannot keep the step open), the percent field applies once through its `FocusOut`, which Return and Escape cause (Swift's `releasesFocusOnCommit`), and steps with Up and Down (Swift's `isFinite` test and the steps' clamp are left out: `setLayerOpacity` refuses a value that is no finite number and clamps the rest), and another active layer makes the controls anew, as Swift's `.id` does. - `ProjectWorkspaceView` is the `QMainWindow`: the front tab's `ContentView` as its central widget, made anew when another tab comes to the front, as SwiftUI's `.id` rebuilds it, and disabled while the workspace manages; the window holds the shown tab (`std::shared_ptr`) until the old editor is deleted, as Swift's views hold their session, so a replaced or closed tab's session never ends under its editor (`ProjectWorkspace::tab` is public for this); a `QToolBar` with the New canvas action, the `ProjectTabStrip` (which takes the toolbar's free width) and the four zoom actions, since SwiftUI's `.toolbar` modifier lives in `ContentView` but the toolbar belongs to the window. Its actions follow the front session's `changed()`, and on that signal the window syncs every tab's button as well, because a busy front tab dims the other tabs' buttons, which their own sessions' signals do not reach; the strip syncs its buttons on the workspace's signal, each button on its own session's. The window's title is the front tab's, with Qt's `[*]` placeholder, so `setWindowModified` can show the mark that `isDocumentEdited` shows; `setWindowFilePath` carries `representedURL`. The editor's own minimum size is cleared inside the window, which owns the 800 × 520 minimum for the whole, toolbar included. Closing the window ignores the event and asks the workspace (`closeWindow`), which confirms tab by tab and then closes the window again with the property `closeConfirmed` set, since the workspace may not include `UI/` headers; a confirmed close is accepted and the mark cleared, so a window shown again asks again. `ProjectTabStrip` is a plain `QWidget` whose buttons are kept for the tabs that stay, made for new tabs and deleted for tabs that went, and placed by hand from `projectTabOverflow` (13.14): every button at its own size hint, so no title is squeezed below Swift's 35 points, laid out again when the strip is resized, the workspace changes or any tab's session changes; it fills no background, so the toolbar shows through (a stylesheet would do the same but freezes the widgets' palette, so a theme switch would pass them by); the unsaved dot is a character before the title. Files named on the command line go to `ProjectWorkspace::receive`, as Finder's Open With reaches the delegate. Layer drops on tabs and the New canvas button are 4.7's; file and picture drops arrived with 10.4. diff --git a/tests/CanvasOnlyWindowTests.cpp b/tests/CanvasOnlyWindowTests.cpp index ca56ea3..0a9b4c7 100644 --- a/tests/CanvasOnlyWindowTests.cpp +++ b/tests/CanvasOnlyWindowTests.cpp @@ -23,7 +23,8 @@ struct Shown : Bar { QList<bool> chrome() { return {window.menuBar()->isVisible(), named("toolbar").isVisible(), named("toolRail").isVisible(), named("statusBar").isVisible(), - named("toolHeader").isVisible(), window.findChild<LayersPanel *>()->isVisible(), window.findChild<CanvasRulerView *>()->isVisible()}; + named("toolHeader").isVisible(), window.findChild<LayersPanel *>()->isVisible(), named("layersPanelEdge").isVisible(), + window.findChild<CanvasRulerView *>()->isVisible()}; } void press(Qt::Key key, Qt::KeyboardModifiers modifiers = {}) { @@ -48,12 +49,14 @@ void CanvasOnlyWindowTests::fPutsEveryBarAwayAndBringsThemBack() Shown shown; QAction &entry = shown.action("toggleFullscreen"); QVERIFY(entry.text() == "Toggle Fullscreen" && entry.isCheckable() && !entry.isChecked() && entry.shortcut() == QKeySequence(Qt::Key_F)); - QCOMPARE(shown.chrome(), (QList<bool>{true, true, true, true, true, true, true})); + QCOMPARE(shown.chrome(), (QList<bool>{true, true, true, true, true, true, true, true})); shown.canvas().setFocus(); shown.press(Qt::Key_F); QVERIFY(shown.session().canvasOnly() && entry.isChecked()); QVERIFY(shown.window.windowState().testFlag(Qt::WindowFullScreen)); - QCOMPARE(shown.chrome(), (QList<bool>{false, false, false, false, false, false, false})); + QCOMPARE(shown.chrome(), (QList<bool>{false, false, false, false, false, false, false, false})); + // Nothing else is left: the canvas fills the window. + QTRY_COMPARE(QRect(shown.canvas().mapTo(&shown.window, QPoint(0, 0)), shown.canvas().size()), shown.window.rect()); // A new tool's bar stays away too. shown.session().selectTool(NavigationTool::brush); QVERIFY(!shown.named("toolHeader").isVisible()); @@ -67,7 +70,7 @@ void CanvasOnlyWindowTests::fPutsEveryBarAwayAndBringsThemBack() shown.press(Qt::Key_F); QVERIFY(!shown.session().canvasOnly() && !entry.isChecked()); QVERIFY(!shown.window.windowState().testFlag(Qt::WindowFullScreen)); - QCOMPARE(shown.chrome(), (QList<bool>{true, true, true, true, true, true, true})); + QCOMPARE(shown.chrome(), (QList<bool>{true, true, true, true, true, true, true, true})); } void CanvasOnlyWindowTests::theCanvasSitsOnBlack() @@ -113,7 +116,7 @@ void CanvasOnlyWindowTests::escapeLeavesOnceNothingIsLeftToCancel() } shown.press(Qt::Key_Escape); QVERIFY(!shown.session().canvasOnly() && !shown.action("toggleFullscreen").isChecked()); - QCOMPARE(shown.chrome(), (QList<bool>{true, true, true, true, true, true, true})); + QCOMPARE(shown.chrome(), (QList<bool>{true, true, true, true, true, true, true, true})); // Out of Canvas Only, Escape is the canvas's alone. shown.press(Qt::Key_Escape); QVERIFY(!shown.session().canvasOnly()); diff --git a/tests/KeyboardShortcutsTests.cpp b/tests/KeyboardShortcutsTests.cpp index 6dac073..ff8c9d7 100644 --- a/tests/KeyboardShortcutsTests.cpp +++ b/tests/KeyboardShortcutsTests.cpp @@ -109,6 +109,16 @@ void KeyboardShortcutsTests::theListIsSwiftsWithoutHide() QCOMPARE(named("Increase leading by 10").original, ShortcutChord(QString(QChar(0xf701)), 10)); QCOMPARE(named("Toggle Levels preview").group, QString("Canvas & Layers")); QCOMPARE(named("Undo").id(), QString("Menus:Undo")); + // Swift 1.4.7: Search Commands, then Fullscreen first in Canvas. + const auto at = [&](const QString &title) { + return std::ranges::find_if(all, [&](const ShortcutDefinition &d) { return d.title == title; }) - all.begin(); + }; + QCOMPARE(named("Search Commands").original, ShortcutChord("f", 1)); + QVERIFY(named("Search Commands").isMenu() && at("Search Commands") == at("Fit Canvas") + 1); + const ShortcutDefinition fullscreen = named("Toggle Fullscreen: the canvas alone on black (Esc also leaves)"); + QCOMPARE(fullscreen.original, ShortcutChord("f")); + QCOMPARE(fullscreen.group, QString("Canvas & Layers")); + QCOMPARE(std::ranges::find_if(all, [](const ShortcutDefinition &d) { return !d.isMenu(); })->title, fullscreen.title); // Swift's defaults hold together. QVERIFY(!ShortcutSettings::problem({})); }