View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0018017 | Scribus | Usability | public | 2026-10-16 07:59 | 2026-10-29 17:09 |
| Reporter | buttar | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | N/A |
| Status | new | Resolution | open | ||
| Platform | Linux | OS | Fedora Workstation | OS Version | 44 |
| Product Version | 1.7.4.svn | ||||
| Target Version | 1.7.5.svn | ||||
| Summary | 0018017: [patch] Adapt frames after page geometry changes | ||||
| Description | Changing page margins or dimensions leaves existing frames at their previous positions and sizes, requiring manual readjustment. This series introduces optional adaptation that preserves previous frame-to-margin alignments. Dependency: r27888 + FMA1.patch (from 0018016) ## fma2-margin-adaptation-foundation-v1.02.patch - Introduces dedicated margin-adaptation geometry logic. - Captures previous page/frame geometry and detects margin-aligned edges. - Calculates horizontal and vertical adjustments independently. - Handles facing pages, alignment tolerances and stale geometry. ## fma3-adapt-frames-to-margins-v1.12.patch - Integrates adaptation with Page Properties and Document Setup. - Offers "Adapt frames" or "Keep layout" after page geometry changes. - Adds: Page > Adapt to new geometry… for deferred adaptation. - Provides page-range and alignment controls with input validation. - Maintains session-scoped adaptation state, eligibility checks and grouped undo/redo. ## fma4-preview-reporting-hardening-v1.16.patch - Adds live canvas preview of current and adapted frame bounds. - Supports scrolling, zooming and panning while preventing document edits during preview. - Reports affected/skipped frames and newly introduced text overflow. - Hardens dialog lifetime, event handling and document-switching safety. - Refines dialog layout, validation feedback and preview presentation. No SLA format changes. | ||||
| Tags | No tags attached. | ||||
| Attached Files | fma2-margin-adaptation-foundation-v1.02.patch (7,582 bytes)
Index: scribus/CMakeLists_Sources.txt
===================================================================
--- scribus/CMakeLists_Sources.txt (revision 27888)
+++ scribus/CMakeLists_Sources.txt (working copy)
@@ -96,6 +96,7 @@
fpoint.cpp
fpointarray.cpp
framelinkrouter.cpp
+ framemarginadapt.cpp
framemarginfit.cpp
gtaction.cpp
gtfont.cpp
Index: scribus/framemarginadapt.cpp
===================================================================
--- scribus/framemarginadapt.cpp (nonexistent)
+++ scribus/framemarginadapt.cpp (working copy)
@@ -0,0 +1,166 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadapt.h"
+
+#include <cmath>
+
+#include <QHash>
+
+#include "framemarginfit.h"
+#include "pageitem.h"
+#include "scpage.h"
+#include "scribusdoc.h"
+
+namespace
+{
+QRectF localBounds(const PageItem* item, const ScPage* page)
+{
+ return QRectF(item->xPos() - page->xOffset(), item->yPos() - page->yOffset(),
+ item->width(), item->height());
+}
+
+bool validBounds(const QRectF& bounds)
+{
+ return std::isfinite(bounds.left()) && std::isfinite(bounds.top()) &&
+ std::isfinite(bounds.width()) && std::isfinite(bounds.height()) &&
+ bounds.width() > FrameMarginAdapt::kGeometryTolerance && bounds.height() > FrameMarginAdapt::kGeometryTolerance;
+}
+}
+
+namespace FrameMarginAdapt
+{
+bool near(double a, double b, double tolerance)
+{
+ return std::abs(a - b) <= tolerance;
+}
+
+bool sameBounds(const QRectF& a, const QRectF& b)
+{
+ return near(a.x(), b.x()) && near(a.y(), b.y()) &&
+ near(a.width(), b.width()) && near(a.height(), b.height());
+}
+
+QRectF marginBounds(const ScPage* page)
+{
+ return QRectF(page->leftMargin(), page->topMargin(),
+ page->width() - page->leftMargin() - page->rightMargin(),
+ page->height() - page->topMargin() - page->bottomMargin());
+}
+
+Snapshot capture(const ScribusDoc* doc)
+{
+ Snapshot result;
+ if (!doc || !doc->Pages || doc->masterPageMode() || doc->symbolEditMode() || doc->inlineEditMode())
+ return result;
+
+ result.document = doc;
+ result.pages.reserve(doc->Pages->size());
+ for (const ScPage* page : *doc->Pages)
+ {
+ PageSnapshot snapshot;
+ if (page)
+ {
+ snapshot.page = page;
+ snapshot.margins = FrameMarginAdapt::marginBounds(page);
+ }
+ result.pages.append(snapshot);
+ }
+
+ for (const PageItem* item : doc->DocItems)
+ {
+ if (!FrameMarginFit::isEligible(doc, item))
+ continue;
+ const int pageIndex = item->OwnPage;
+ const PageSnapshot& pageSnapshot = result.pages.at(pageIndex);
+ if (!pageSnapshot.page || !validBounds(pageSnapshot.margins))
+ continue;
+
+ FrameSnapshot frame;
+ frame.itemId = item->uniqueNr;
+ frame.pageIndex = pageIndex;
+ frame.bounds = localBounds(item, pageSnapshot.page);
+ frame.left = near(frame.bounds.left(), pageSnapshot.margins.left(), kEdgeTolerance);
+ frame.right = near(frame.bounds.right(), pageSnapshot.margins.right(), kEdgeTolerance);
+ frame.top = near(frame.bounds.top(), pageSnapshot.margins.top(), kEdgeTolerance);
+ frame.bottom = near(frame.bounds.bottom(), pageSnapshot.margins.bottom(), kEdgeTolerance);
+ if (frame.left || frame.right || frame.top || frame.bottom)
+ result.frames.append(frame);
+ }
+ return result;
+}
+
+QVector<Change> plan(const Snapshot& before, const ScribusDoc* doc, bool horizontal, bool vertical)
+{
+ QVector<Change> changes;
+ if (!doc || !doc->Pages || before.document != doc ||
+ doc->Pages->size() != before.pages.size() || (!horizontal && !vertical))
+ return changes;
+
+ QHash<uint, const PageItem*> currentItems;
+ currentItems.reserve(doc->DocItems.size());
+ for (const PageItem* item : doc->DocItems)
+ {
+ if (item)
+ currentItems.insert(item->uniqueNr, item);
+ }
+
+ for (const FrameSnapshot& old : before.frames)
+ {
+ if (!(horizontal && (old.left || old.right)) &&
+ !(vertical && (old.top || old.bottom)))
+ continue;
+ if (old.pageIndex < 0 || old.pageIndex >= doc->Pages->size())
+ continue;
+ const ScPage* page = doc->Pages->at(old.pageIndex);
+ if (!page || page != before.pages.at(old.pageIndex).page)
+ continue;
+ const QRectF newMargins = marginBounds(page);
+ const QRectF& oldMargins = before.pages.at(old.pageIndex).margins;
+ if (!validBounds(newMargins) || sameBounds(newMargins, oldMargins))
+ continue;
+
+ const PageItem* item = currentItems.value(old.itemId, nullptr);
+ if (!item || item->OwnPage != old.pageIndex || !FrameMarginFit::isEligible(doc, item))
+ continue;
+ const QRectF current = localBounds(item, page);
+ // A pending notification must not reposition a frame edited in the meantime.
+ if (!sameBounds(current, old.bounds))
+ continue;
+
+ double x = current.x();
+ double y = current.y();
+ double width = current.width();
+ double height = current.height();
+ if (horizontal)
+ {
+ if (old.left && old.right)
+ {
+ x = newMargins.left();
+ width = newMargins.width();
+ }
+ else if (old.left)
+ x = newMargins.left();
+ else if (old.right)
+ x = newMargins.right() - width;
+ }
+ if (vertical)
+ {
+ if (old.top && old.bottom)
+ {
+ y = newMargins.top();
+ height = newMargins.height();
+ }
+ else if (old.top)
+ y = newMargins.top();
+ else if (old.bottom)
+ y = newMargins.bottom() - height;
+ }
+
+ const QRectF target(x, y, width, height);
+ if (validBounds(target) && !sameBounds(target, current))
+ changes.append({old.itemId, old.pageIndex, target});
+ }
+ return changes;
+}
+}
Index: scribus/framemarginadapt.h
===================================================================
--- scribus/framemarginadapt.h (nonexistent)
+++ scribus/framemarginadapt.h (working copy)
@@ -0,0 +1,62 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPT_H
+#define FRAMEMARGINADAPT_H
+
+#include <QRectF>
+#include <QVector>
+
+class ScPage;
+class ScribusDoc;
+
+// One-shot planning only. No document mutation and no retained PageItem pointers.
+namespace FrameMarginAdapt
+{
+ inline constexpr double kGeometryTolerance = 0.0001; // document points
+ inline constexpr double kEdgeTolerance = 0.25; // allowance for UI rounding
+
+ bool near(double first, double second, double tolerance = kGeometryTolerance);
+ bool sameBounds(const QRectF& first, const QRectF& second);
+ QRectF marginBounds(const ScPage* page);
+ struct PageSnapshot
+ {
+ const ScPage* page {nullptr}; // Identity only; not dereferenced after capture.
+ QRectF margins; // Page-local margin rectangle.
+ };
+
+ struct FrameSnapshot
+ {
+ uint itemId {0};
+ int pageIndex {-1};
+ QRectF bounds; // Page-local frame bounds.
+ bool left {false};
+ bool right {false};
+ bool top {false};
+ bool bottom {false};
+ };
+
+ struct Snapshot
+ {
+ const ScribusDoc* document {nullptr};
+ QVector<PageSnapshot> pages;
+ QVector<FrameSnapshot> frames;
+ };
+
+ struct Change
+ {
+ uint itemId {0};
+ int pageIndex {-1};
+ QRectF bounds; // Proposed page-local bounds.
+ };
+
+ // Capture before a margin/page-size change. Eligible frames are recorded for later planning.
+ Snapshot capture(const ScribusDoc* doc);
+
+ // Call after page geometry changes. Rechecks identity, eligibility and frame geometry.
+ // The caller may choose one axis without affecting the other.
+ QVector<Change> plan(const Snapshot& before, const ScribusDoc* doc,
+ bool horizontal = true, bool vertical = true);
+}
+
+#endif
fma3-adapt-frames-to-margins-v1.12.patch (28,859 bytes)
Index: scribus/CMakeLists_Sources.txt
===================================================================
--- scribus/CMakeLists_Sources.txt (revision 27888)
+++ scribus/CMakeLists_Sources.txt (working copy)
@@ -97,6 +97,7 @@
fpointarray.cpp
framelinkrouter.cpp
framemarginadapt.cpp
+ framemarginadaptworkflow.cpp
framemarginfit.cpp
gtaction.cpp
gtfont.cpp
@@ -351,6 +352,7 @@
ui/extimageprops.cpp
ui/filedialogeventcatcher.cpp
ui/flopwidget.cpp
+ ui/framemarginadaptdialog.cpp
ui/fontcombo.cpp
ui/fontembeddingcombo.cpp
ui/fontembeddingmodel.cpp
Index: scribus/actionmanager.cpp
===================================================================
--- scribus/actionmanager.cpp (revision 27888)
+++ scribus/actionmanager.cpp (working copy)
@@ -475,6 +475,8 @@
name = QLatin1String(action);
scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
}
+ name = "itemAdaptFramesToMargins";
+ scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
name = "itemExtendedImageProperties";
scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
name = "itemToggleInlineImage";
@@ -1708,6 +1710,7 @@
(*scrActions)["itemFitToMarginsWidth"]->setTexts(tr("Width"));
(*scrActions)["itemFitToMarginsHeight"]->setTexts(tr("Height"));
(*scrActions)["itemFitToMarginsBoth"]->setTexts(tr("Width and Height"));
+ (*scrActions)["itemAdaptFramesToMargins"]->setTexts(tr("Adapt to new geometry…"));
(*scrActions)["itemToggleInlineImage"]->setTexts( tr("Embed Image"));
(*scrActions)["itemExtendedImageProperties"]->setTexts( tr("Extended Image Properties..."));
(*scrActions)["itemPreviewFull"]->setTexts( tr("&Full Resolution"));
Index: scribus/framemarginadaptworkflow.cpp
===================================================================
--- scribus/framemarginadaptworkflow.cpp (nonexistent)
+++ scribus/framemarginadaptworkflow.cpp (working copy)
@@ -0,0 +1,312 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadaptworkflow.h"
+
+#include <QDialog>
+#include <QHash>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QPointer>
+#include <QPushButton>
+#include <QRectF>
+#include <QSet>
+#include <QStatusBar>
+#include <QVBoxLayout>
+
+#include "framemarginfit.h"
+#include "pageitem.h"
+#include "scpage.h"
+#include "scraction.h"
+#include "scribus.h"
+#include "scribusdoc.h"
+#include "ui/framemarginadaptdialog.h"
+#include "undomanager.h"
+
+namespace
+{
+constexpr auto kPendingName = "frameMarginPendingAdaptation";
+constexpr auto kActionName = "itemAdaptFramesToMargins";
+
+// Each document owns at most one pending, session-only adaptation. Closing the
+// document destroys its snapshot, without storing anything in the SLA file.
+struct PendingAdaptation : QObject
+{
+ explicit PendingAdaptation(ScribusDoc* doc) : QObject(doc), document(doc)
+ {
+ setObjectName(QString::fromLatin1(kPendingName));
+ }
+
+ QPointer<ScribusDoc> document;
+ FrameMarginAdapt::Snapshot before;
+ QVector<QRectF> newMarginBounds;
+};
+
+PendingAdaptation* pendingFor(ScribusDoc* doc)
+{
+ if (!doc)
+ return nullptr;
+ return static_cast<PendingAdaptation*>(
+ doc->findChild<QObject*>(QString::fromLatin1(kPendingName), Qt::FindDirectChildrenOnly));
+}
+
+bool stillCurrent(const ScribusMainWindow* window, const PendingAdaptation* pending)
+{
+ if (!window || !pending)
+ return false;
+ ScribusDoc* doc = pending->document.data();
+ if (!doc || window->doc != doc || !doc->Pages || doc->masterPageMode() ||
+ doc->symbolEditMode() || doc->inlineEditMode() ||
+ doc->Pages->size() != pending->before.pages.size() ||
+ doc->Pages->size() != pending->newMarginBounds.size())
+ return false;
+
+ for (int i = 0; i < doc->Pages->size(); ++i)
+ {
+ const ScPage* page = doc->Pages->at(i);
+ if (!page || page != pending->before.pages.at(i).page)
+ return false;
+ const QRectF now = FrameMarginAdapt::marginBounds(page);
+ const QRectF& expected = pending->newMarginBounds.at(i);
+ if (!FrameMarginAdapt::sameBounds(now, expected))
+ return false;
+ }
+ return true;
+}
+
+bool geometryChanged(const FrameMarginAdapt::Snapshot& before, const ScribusDoc* doc)
+{
+ if (!doc || before.document != doc || !doc->Pages ||
+ before.pages.size() != doc->Pages->size())
+ return true;
+ for (int i = 0; i < doc->Pages->size(); ++i)
+ {
+ const ScPage* page = doc->Pages->at(i);
+ const QRectF& old = before.pages.at(i).margins;
+ if (!page || page != before.pages.at(i).page)
+ return true;
+ const QRectF now = FrameMarginAdapt::marginBounds(page);
+ if (!FrameMarginAdapt::sameBounds(old, now))
+ return true;
+ }
+ return false;
+}
+
+bool hasCandidates(const ScribusMainWindow* window, const PendingAdaptation* pending)
+{
+ return stillCurrent(window, pending) &&
+ !FrameMarginAdapt::plan(pending->before, pending->document.data()).isEmpty();
+}
+
+bool apply(ScribusDoc* doc, const QVector<FrameMarginAdapt::Change>& changes,
+ const QSet<int>& selectedPages)
+{
+ if (!doc || changes.isEmpty() || selectedPages.isEmpty())
+ return false;
+
+ QHash<uint, PageItem*> items;
+ items.reserve(doc->DocItems.size());
+ for (PageItem* item : doc->DocItems)
+ {
+ if (item)
+ items.insert(item->uniqueNr, item);
+ }
+
+ UndoTransaction transaction;
+ PageItem* firstChanged = nullptr;
+ for (const FrameMarginAdapt::Change& change : changes)
+ {
+ if (!selectedPages.contains(change.pageIndex) || change.pageIndex < 0 ||
+ change.pageIndex >= doc->Pages->size())
+ continue;
+ PageItem* item = items.value(change.itemId, nullptr);
+ if (!FrameMarginFit::isEligible(doc, item) || item->OwnPage != change.pageIndex)
+ continue;
+ const ScPage* page = doc->Pages->at(change.pageIndex);
+ const double x = page->xOffset() + change.bounds.x();
+ const double y = page->yOffset() + change.bounds.y();
+ const bool reposition = !FrameMarginAdapt::near(x, item->xPos()) || !FrameMarginAdapt::near(y, item->yPos());
+ const bool resize = !FrameMarginAdapt::near(change.bounds.width(), item->width()) ||
+ !FrameMarginAdapt::near(change.bounds.height(), item->height());
+ if (!reposition && !resize)
+ continue;
+
+ if (!firstChanged)
+ {
+ firstChanged = item;
+ if (UndoManager::undoEnabled())
+ transaction = UndoManager::instance()->beginTransaction(Um::SelectionGroup, Um::IGroup,
+ ScribusDoc::tr("Adapt frames to new page geometry"), QString(), Um::IResize);
+ }
+ if (reposition)
+ doc->moveItem(x - item->xPos(), y - item->yPos(), item);
+ if (resize)
+ doc->sizeItem(change.bounds.width(), change.bounds.height(), item);
+ item->invalid = true;
+ item->checkChanges();
+ }
+ if (!firstChanged)
+ return false;
+ if (transaction)
+ transaction.commit();
+ doc->regionsChanged()->update(QRectF());
+ doc->changed();
+ doc->changedPagePreview();
+ firstChanged->emitAllToGUI();
+ return true;
+}
+
+void openDialog(ScribusMainWindow* window, QPointer<PendingAdaptation> pending)
+{
+ if (!hasCandidates(window, pending.data()))
+ return;
+ // Only one adaptation dialog can be active for this main window.
+ if (auto* existing = window->findChild<FrameMarginAdaptDialog*>(QStringLiteral("frameMarginAdaptDialog")))
+ {
+ existing->raise();
+ existing->activateWindow();
+ return;
+ }
+ ScribusDoc* doc = pending->document.data();
+ const auto horizontal = FrameMarginAdapt::plan(pending->before, doc, true, false);
+ const auto vertical = FrameMarginAdapt::plan(pending->before, doc, false, true);
+ if (horizontal.isEmpty() && vertical.isEmpty())
+ return;
+
+ FrameMarginAdaptDialog dialog(horizontal, vertical, doc->Pages->size(), window);
+ dialog.setObjectName(QStringLiteral("frameMarginAdaptDialog"));
+ if (dialog.exec() != QDialog::Accepted || !hasCandidates(window, pending.data()))
+ return; // Cancel retains the snapshot for later adaptation.
+
+ // Replan after user confirmation; frames edited since capture are skipped.
+ const auto changes = FrameMarginAdapt::plan(pending->before, doc,
+ dialog.adaptHorizontal(), dialog.adaptVertical());
+ QSet<uint> previousOverflows;
+ for (const PageItem* item : doc->DocItems)
+ {
+ if (item && item->isTextFrame() && item->frameOverflows())
+ previousOverflows.insert(item->uniqueNr);
+ }
+ const bool didAdapt = apply(doc, changes, dialog.selectedPages());
+ if (didAdapt)
+ {
+ for (PageItem* item : doc->DocItems)
+ {
+ if (item && item->isTextFrame() && item->invalid)
+ item->layout();
+ }
+ int newOverflows = 0;
+ for (const PageItem* item : doc->DocItems)
+ {
+ if (item && item->isTextFrame() && item->frameOverflows() &&
+ !previousOverflows.contains(item->uniqueNr))
+ ++newOverflows;
+ }
+ if (newOverflows > 0)
+ {
+ const QString message = newOverflows == 1
+ ? QDialog::tr("1 text frame now has overflow. Review in Preflight.")
+ : QDialog::tr("%1 text frames now have overflow. Review in Preflight.").arg(newOverflows);
+ window->statusBar()->showMessage(message, 8000);
+ }
+ delete pending.data(); // A successful adaptation completes this opportunity.
+ }
+ FrameMarginAdaptWorkflow::refreshAction(window);
+}
+
+}
+
+namespace FrameMarginAdaptWorkflow
+{
+void closeDialog(ScribusMainWindow* window)
+{
+ if (!window)
+ return;
+ if (auto* dialog = window->findChild<FrameMarginAdaptDialog*>(QStringLiteral("frameMarginAdaptDialog")))
+ dialog->reject();
+}
+
+void refreshAction(ScribusMainWindow* window)
+{
+ if (!window)
+ return;
+ ScrAction* action = window->scrActions.value(QLatin1String(kActionName)).data();
+ if (!action)
+ return;
+ const bool enabled = hasCandidates(window, pendingFor(window->doc));
+ action->setEnabled(enabled);
+ const QString tip = enabled
+ ? ScribusMainWindow::tr("Adjust previously margin-aligned frames to the new page size or margins.")
+ : ScribusMainWindow::tr("Available after changing page margins or page size.");
+ action->setToolTip(tip);
+ action->setStatusTip(tip);
+}
+
+void reopen(ScribusMainWindow* window)
+{
+ if (!window)
+ return;
+ openDialog(window, pendingFor(window->doc));
+ refreshAction(window);
+}
+
+void offer(ScribusMainWindow* window, ScribusDoc* doc,
+ const FrameMarginAdapt::Snapshot& before)
+{
+ if (!window)
+ return;
+
+ // Unrelated Document Setup changes must not discard an existing opportunity.
+ if (!geometryChanged(before, doc))
+ {
+ refreshAction(window);
+ return;
+ }
+ // A new geometry operation supersedes any older one for this document.
+ closeDialog(window);
+ if (QDialog* prompt = window->findChild<QDialog*>(QStringLiteral("frameMarginAdaptPrompt")))
+ prompt->close();
+ delete pendingFor(doc);
+ if (!doc || window->doc != doc || FrameMarginAdapt::plan(before, doc).isEmpty())
+ {
+ refreshAction(window);
+ return;
+ }
+
+ auto* pending = new PendingAdaptation(doc);
+ pending->before = before;
+ pending->newMarginBounds.reserve(doc->Pages->size());
+ for (const ScPage* page : *doc->Pages)
+ pending->newMarginBounds.append(FrameMarginAdapt::marginBounds(page));
+ refreshAction(window);
+
+ auto* prompt = new QDialog(window, Qt::Tool);
+ prompt->setObjectName(QStringLiteral("frameMarginAdaptPrompt"));
+ prompt->setAttribute(Qt::WA_DeleteOnClose);
+ prompt->setWindowModality(Qt::NonModal);
+ prompt->setWindowTitle(QDialog::tr("Page geometry changed"));
+ QVBoxLayout* layout = new QVBoxLayout(prompt);
+ auto* description = new QLabel(QDialog::tr("Some frames were aligned with the previous margins. "
+ "Adapt them to the new page geometry?"), prompt);
+ description->setWordWrap(true);
+ layout->addWidget(description);
+ QHBoxLayout* buttons = new QHBoxLayout;
+ buttons->addStretch();
+ auto* keep = new QPushButton(QDialog::tr("Keep layout"), prompt);
+ auto* adapt = new QPushButton(QDialog::tr("Adapt frames…"), prompt);
+ buttons->addWidget(keep);
+ buttons->addWidget(adapt);
+ layout->addLayout(buttons);
+ prompt->setMinimumWidth(380);
+
+ QPointer<PendingAdaptation> safePending(pending);
+ QObject::connect(doc, &QObject::destroyed, prompt, &QDialog::close);
+ QObject::connect(keep, &QPushButton::clicked, prompt, &QDialog::close);
+ QObject::connect(adapt, &QPushButton::clicked, prompt, [window, prompt, safePending]()
+ {
+ prompt->close();
+ openDialog(window, safePending);
+ });
+ prompt->show();
+}
+}
Index: scribus/framemarginadaptworkflow.h
===================================================================
--- scribus/framemarginadaptworkflow.h (nonexistent)
+++ scribus/framemarginadaptworkflow.h (working copy)
@@ -0,0 +1,28 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPTWORKFLOW_H
+#define FRAMEMARGINADAPTWORKFLOW_H
+
+#include "framemarginadapt.h"
+
+class ScribusMainWindow;
+class ScribusDoc;
+
+namespace FrameMarginAdaptWorkflow
+{
+ // Show a non-modal offer only when the page change produced adaptable frames.
+ // The snapshot was captured immediately before the page geometry changed.
+ void offer(ScribusMainWindow* window, ScribusDoc* doc,
+ const FrameMarginAdapt::Snapshot& before);
+
+ // Reopen an unapplied adaptation from the current document session.
+ void reopen(ScribusMainWindow* window);
+ // Dismiss an active preview before switching/closing the document; keep
+ // its session-only pending adaptation for a possible later retry.
+ void closeDialog(ScribusMainWindow* window);
+ // Update the menu action when the document or its geometry changes.
+ void refreshAction(ScribusMainWindow* window);
+}
+
+#endif
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 27888)
+++ scribus/scribus.cpp (working copy)
@@ -30,6 +30,7 @@
#include <QColorDialog>
#include <QCursor>
#include <QDomDocument>
+#include <QDialog>
#include <QDrag>
#include <QDragEnterEvent>
#include <QDropEvent>
@@ -48,6 +49,7 @@
#include <QLocale>
#include <QMdiArea>
#include <QMdiSubWindow>
+#include <QMenu>
#include <QMessageBox>
#include <QMouseEvent>
#include <QMultiMap>
@@ -114,6 +116,8 @@
#include "documentlogmanager.h"
#include "fileloader.h"
#include "filewatcher.h"
+#include "framemarginadapt.h"
+#include "framemarginadaptworkflow.h"
#include "fpoint.h"
#include "fpointarray.h"
#include "gtgettext.h"
@@ -1289,6 +1293,12 @@
scrMenuMgr->addMenuItemString("pageCopyToMasterPage", "Page");
scrMenuMgr->addMenuItemString("pageManageGuides", "Page");
scrMenuMgr->addMenuItemString("pageManageProperties", "Page");
+ scrMenuMgr->addMenuItemString("itemAdaptFramesToMargins", "Page");
+ connect(scrActions["itemAdaptFramesToMargins"], &QAction::triggered, this, [this]()
+ {
+ FrameMarginAdaptWorkflow::reopen(this);
+ });
+ scrActions["itemAdaptFramesToMargins"]->setEnabled(false);
scrMenuMgr->addMenuItemString("SEPARATOR", "Page");
scrMenuMgr->addMenuItemString("viewSnapToGrid", "Page");
scrMenuMgr->addMenuItemString("viewSnapToGuides", "Page");
@@ -1414,6 +1424,12 @@
scrMenuMgr->addMenuItemStringsToMenuBar("Insert", scrActions);
scrMenuMgr->addMenuStringToMenuBar("Page");
scrMenuMgr->addMenuItemStringsToMenuBar("Page", scrActions);
+ QMenu* pageMenu = scrMenuMgr->getLocalPopupMenu("Page");
+ pageMenu->setToolTipsVisible(true);
+ connect(pageMenu, &QMenu::aboutToShow, this, [this]()
+ {
+ FrameMarginAdaptWorkflow::refreshAction(this);
+ });
scrMenuMgr->addMenuStringToMenuBar("ItemTable");
scrMenuMgr->addMenuItemStringsToMenuBar("ItemTable", scrActions);
scrMenuMgr->addMenuStringToMenuBar("Extras");
@@ -2487,6 +2503,8 @@
}
if (scw == ActWin)
return;
+ if (doc && (doc != scw->doc() || view != scw->view()))
+ FrameMarginAdaptWorkflow::closeDialog(this);
ActWin = scw;
if (ActWin->doc() == nullptr)
return;
@@ -2650,6 +2668,11 @@
void ScribusMainWindow::SwitchWin()
{
+ FrameMarginAdaptWorkflow::closeDialog(this);
+ // Dismiss the old document's offer; its pending adaptation remains with that document.
+ if (QDialog* prompt = findChild<QDialog*>(QStringLiteral("frameMarginAdaptPrompt")))
+ prompt->close();
+ FrameMarginAdaptWorkflow::refreshAction(this);
updateActiveWindowCaption(doc->documentFileName());
propertiesPalette->setDoc(doc);
contentPalette->setDoc(doc);
@@ -2696,6 +2719,10 @@
void ScribusMainWindow::HaveNewDoc()
{
+ FrameMarginAdaptWorkflow::closeDialog(this);
+ if (QDialog* prompt = findChild<QDialog*>(QStringLiteral("frameMarginAdaptPrompt")))
+ prompt->close();
+ FrameMarginAdaptWorkflow::refreshAction(this);
appModeHelper->mainWindowHasNewDoc(doc, (ScMimeData::clipboardHasScribusData()) || (scrapbookPalette->tempHasContents()));
//Update palettes
@@ -6297,6 +6324,7 @@
if (!dia->exec())
return;
+ const auto previousMarginGeometry = FrameMarginAdapt::capture(doc);
int orientation = dia->getPageOrientation();
double pageHeight = dia->getPageHeight();
double pageWidth = dia->getPageWidth();
@@ -6310,6 +6338,7 @@
if (!doc->masterPageMode() && dia->masterPage() != currPageMasterPageName)
Apply_MasterPage(dia->masterPage(), doc->currentPage()->pageNr());
doc->updateEndnotesFrames();
+ FrameMarginAdaptWorkflow::offer(this, doc, previousMarginGeometry);
}
void ScribusMainWindow::setItemFontSize(int fontSize)
@@ -6767,6 +6796,7 @@
if (prefsResult != QDialog::Accepted)
return;
+ const auto previousMarginGeometry = FrameMarginAdapt::capture(doc);
struct ApplicationPrefs newDocPrefs(prefsDialog.prefs());
bool resizePages, resizeMasterPages, resizePageMargins, resizeMasterPageMargins;
prefsDialog.getResizeDocumentPages(resizePages, resizeMasterPages, resizePageMargins, resizeMasterPageMargins);
@@ -6823,6 +6853,7 @@
emit UpdateRequest(reqCmsOptionsUpdate);
doc->changed();
modeToolBar->setDoc(doc);
+ FrameMarginAdaptWorkflow::offer(this, doc, previousMarginGeometry);
}
int ScribusMainWindow::ShowSubs()
Index: scribus/ui/framemarginadaptdialog.cpp
===================================================================
--- scribus/ui/framemarginadaptdialog.cpp (nonexistent)
+++ scribus/ui/framemarginadaptdialog.cpp (working copy)
@@ -0,0 +1,244 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadaptdialog.h"
+
+#include <QAbstractButton>
+#include <QCheckBox>
+#include <QDialogButtonBox>
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QRadioButton>
+#include <QRegularExpression>
+#include <QStyle>
+#include <QVBoxLayout>
+
+namespace
+{
+// Be strict: unlike the print/export range parser, a typo must not silently skip pages.
+enum class PageRangeError { Invalid, OutOfRange };
+
+bool parsePages(const QString& text, int pageCount, QSet<int>& result, PageRangeError* error = nullptr)
+{
+ static const QRegularExpression entry(R"(^\s*(\d+)\s*(?:-\s*(\d+))?\s*$)");
+ const QStringList entries = text.split(',', Qt::KeepEmptyParts);
+ if (entries.isEmpty())
+ return false;
+ for (const QString& part : entries)
+ {
+ const QRegularExpressionMatch match = entry.match(part);
+ if (!match.hasMatch())
+ return false;
+ bool startOk = false;
+ bool endOk = true;
+ const int first = match.captured(1).toInt(&startOk);
+ const int last = match.captured(2).isEmpty() ? first : match.captured(2).toInt(&endOk);
+ if (!startOk || !endOk || first > last)
+ return false;
+ if (first < 1 || last > pageCount)
+ {
+ if (error)
+ *error = PageRangeError::OutOfRange;
+ return false;
+ }
+ for (int page = first; page <= last; ++page)
+ result.insert(page - 1);
+ }
+ return !result.isEmpty();
+}
+
+// A trailing comma or unfinished range is not yet an error while typing.
+bool isIncompleteRange(const QString& text)
+{
+ static const QRegularExpression trailingComma(
+ R"(^\s*(?:\d+\s*(?:-\s*\d+)?\s*,\s*)+$)");
+ static const QRegularExpression trailingDash(
+ R"(^\s*(?:\d+\s*(?:-\s*\d+)?\s*,\s*)*\d+\s*-\s*$)");
+ return trailingComma.match(text).hasMatch() || trailingDash.match(text).hasMatch();
+}
+}
+
+FrameMarginAdaptDialog::FrameMarginAdaptDialog(const QVector<FrameMarginAdapt::Change>& horizontal,
+ const QVector<FrameMarginAdapt::Change>& vertical,
+ int totalPages, QWidget* parent)
+ : QDialog(parent), m_horizontal(horizontal), m_vertical(vertical),
+ m_totalPages(totalPages)
+{
+ setWindowTitle(tr("Adapt Frames to New Page Geometry"));
+ setMinimumWidth(370);
+ QVBoxLayout* layout = new QVBoxLayout(this);
+
+ m_pagesGroup = new QGroupBox(tr("Pages"), this);
+ QVBoxLayout* pageLayout = new QVBoxLayout(m_pagesGroup);
+ m_allPages = new QRadioButton(tr("All affected pages"), m_pagesGroup);
+ m_specificPages = new QRadioButton(tr("Specific pages:"), m_pagesGroup);
+ m_allPages->setChecked(true);
+ pageLayout->addWidget(m_allPages);
+ m_pageRange = new QLineEdit(m_pagesGroup);
+ m_pageRange->setPlaceholderText(tr("e.g. 2, 4-7"));
+ m_pageRange->setAccessibleName(tr("Specific page numbers or ranges"));
+ // Keep the warning directly beneath the input, not beneath the radio label.
+ QGridLayout* entryLayout = new QGridLayout;
+ entryLayout->setContentsMargins(0, 0, 0, 0);
+ entryLayout->addWidget(m_specificPages, 0, 0);
+ entryLayout->addWidget(m_pageRange, 0, 1);
+ entryLayout->setColumnStretch(1, 1);
+ m_pageRangeWarningRow = new QWidget(m_pagesGroup);
+ auto* warningLayout = new QHBoxLayout(m_pageRangeWarningRow);
+ warningLayout->setContentsMargins(0, 0, 0, 0);
+ const auto warningIcon = style()->standardIcon(QStyle::SP_MessageBoxWarning);
+ auto* warningSymbol = new QLabel(m_pageRangeWarningRow);
+ warningSymbol->setPixmap(warningIcon.pixmap(16, 16));
+ m_pageRangeWarningLabel = new QLabel(m_pageRangeWarningRow);
+ m_pageRangeWarningLabel->setWordWrap(true);
+ warningLayout->addWidget(warningSymbol, 0, Qt::AlignTop);
+ warningLayout->addWidget(m_pageRangeWarningLabel, 1);
+ entryLayout->addWidget(m_pageRangeWarningRow, 1, 1);
+ m_pageRangeWarningRow->hide();
+ pageLayout->addLayout(entryLayout);
+ layout->addWidget(m_pagesGroup);
+
+ QGroupBox* adjustGroup = new QGroupBox(tr("Adjust"), this);
+ QVBoxLayout* adjustLayout = new QVBoxLayout(adjustGroup);
+ m_adjustHorizontal = new QCheckBox(tr("Horizontal alignment"), adjustGroup);
+ m_adjustVertical = new QCheckBox(tr("Vertical alignment"), adjustGroup);
+ m_adjustHorizontal->setChecked(true);
+ m_adjustVertical->setChecked(true);
+ adjustLayout->addWidget(m_adjustHorizontal);
+ adjustLayout->addWidget(m_adjustVertical);
+ layout->addWidget(adjustGroup);
+
+ // Page scope is determined by the original candidate set, not the selected axes.
+ QSet<int> initialPages;
+ for (const auto& change : m_horizontal)
+ initialPages.insert(change.pageIndex);
+ for (const auto& change : m_vertical)
+ initialPages.insert(change.pageIndex);
+ m_hasPageScope = initialPages.size() > 1;
+ m_pagesGroup->setVisible(m_hasPageScope);
+
+ m_validationText = new QLabel(this);
+ m_validationText->setWordWrap(true);
+ layout->addWidget(m_validationText);
+ // Keep the groups compact and top-aligned even when the dialog grows.
+ layout->addStretch();
+ m_buttons = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
+ m_buttons->addButton(tr("Adapt frames"), QDialogButtonBox::AcceptRole);
+ layout->addWidget(m_buttons);
+
+ connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
+ for (QRadioButton* radio : {m_allPages, m_specificPages})
+ connect(radio, &QRadioButton::toggled, this, [this]() { validateSelection(); });
+ connect(m_adjustHorizontal, &QCheckBox::toggled, this, [this]() { validateSelection(); });
+ connect(m_adjustVertical, &QCheckBox::toggled, this, [this]() { validateSelection(); });
+ connect(m_pageRange, &QLineEdit::textChanged, this, [this]()
+ {
+ const QString value = m_pageRange->text().trimmed();
+ m_showRangeError = !value.isEmpty() && !isIncompleteRange(value);
+ validateSelection();
+ });
+ connect(m_pageRange, &QLineEdit::editingFinished, this, [this]()
+ {
+ m_showRangeError = !m_pageRange->text().trimmed().isEmpty();
+ validateSelection();
+ });
+ connect(m_specificPages, &QRadioButton::toggled, this, [this](bool checked)
+ {
+ if (checked && m_pagesGroup->isEnabled())
+ m_pageRange->setFocus(Qt::OtherFocusReason);
+ });
+ validateSelection();
+}
+
+bool FrameMarginAdaptDialog::adaptHorizontal() const { return m_adjustHorizontal->isChecked(); }
+bool FrameMarginAdaptDialog::adaptVertical() const { return m_adjustVertical->isChecked(); }
+
+QSet<int> FrameMarginAdaptDialog::affectedPages() const
+{
+ QSet<int> pages;
+ if (adaptHorizontal())
+ {
+ for (const auto& change : m_horizontal)
+ pages.insert(change.pageIndex);
+ }
+ if (adaptVertical())
+ {
+ for (const auto& change : m_vertical)
+ pages.insert(change.pageIndex);
+ }
+ return pages;
+}
+
+QSet<int> FrameMarginAdaptDialog::selectedPages() const
+{
+ const QSet<int> available = affectedPages();
+ if (!m_hasPageScope || m_allPages->isChecked())
+ return available;
+ QSet<int> requested;
+ if (!parsePages(m_pageRange->text(), m_totalPages, requested))
+ return {};
+ for (int page : requested)
+ {
+ if (!available.contains(page))
+ return {};
+ }
+ return requested;
+}
+
+void FrameMarginAdaptDialog::validateSelection()
+{
+ const QSet<int> pages = affectedPages();
+ // Keep the original page scope and radio selection stable when axes change.
+ m_pagesGroup->setEnabled(!pages.isEmpty());
+ m_pageRange->setEnabled(!pages.isEmpty() && m_specificPages->isChecked());
+
+ QString message;
+ QString rangeError;
+ QSet<int> selected;
+ if (pages.isEmpty())
+ message = tr("No frames match the selected alignments.");
+ else if (!m_hasPageScope || m_allPages->isChecked())
+ selected = pages;
+ else
+ {
+ const QString text = m_pageRange->text().trimmed();
+ if (!text.isEmpty())
+ {
+ QSet<int> requested;
+ PageRangeError error = PageRangeError::Invalid;
+ if (!parsePages(text, m_totalPages, requested, &error))
+ {
+ rangeError = error == PageRangeError::OutOfRange
+ ? tr("Page number out of range (1–%1).").arg(m_totalPages)
+ : tr("Enter valid page numbers or ranges.");
+ }
+ else
+ {
+ for (int page : requested)
+ {
+ if (!pages.contains(page))
+ {
+ rangeError = tr("Select only pages with frames to adapt.");
+ break;
+ }
+ }
+ if (rangeError.isEmpty())
+ selected = requested;
+ }
+ }
+ }
+ m_pageRangeWarningLabel->setText(rangeError);
+ m_pageRangeWarningRow->setVisible(m_showRangeError && !rangeError.isEmpty() &&
+ m_hasPageScope && m_specificPages->isChecked() && !pages.isEmpty());
+
+ m_validationText->setText(message);
+ for (QAbstractButton* button : m_buttons->buttons())
+ {
+ if (m_buttons->buttonRole(button) == QDialogButtonBox::AcceptRole)
+ button->setEnabled(!selected.isEmpty());
+ }
+}
Index: scribus/ui/framemarginadaptdialog.h
===================================================================
--- scribus/ui/framemarginadaptdialog.h (nonexistent)
+++ scribus/ui/framemarginadaptdialog.h (working copy)
@@ -0,0 +1,55 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPTDIALOG_H
+#define FRAMEMARGINADAPTDIALOG_H
+
+#include <QDialog>
+#include <QSet>
+#include <QVector>
+
+#include "framemarginadapt.h"
+
+class QCheckBox;
+class QLabel;
+class QLineEdit;
+class QRadioButton;
+class QDialogButtonBox;
+class QGroupBox;
+
+// Only collects the user's choices; it never changes document geometry.
+class FrameMarginAdaptDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FrameMarginAdaptDialog(const QVector<FrameMarginAdapt::Change>& horizontal,
+ const QVector<FrameMarginAdapt::Change>& vertical,
+ int totalPages, QWidget* parent = nullptr);
+
+ bool adaptHorizontal() const;
+ bool adaptVertical() const;
+ QSet<int> selectedPages() const;
+
+private:
+ void validateSelection();
+ QSet<int> affectedPages() const;
+
+ QVector<FrameMarginAdapt::Change> m_horizontal;
+ QVector<FrameMarginAdapt::Change> m_vertical;
+ int m_totalPages {0};
+ bool m_hasPageScope {false};
+ QGroupBox* m_pagesGroup {nullptr};
+ QRadioButton* m_allPages {nullptr};
+ QRadioButton* m_specificPages {nullptr};
+ QLineEdit* m_pageRange {nullptr};
+ QWidget* m_pageRangeWarningRow {nullptr};
+ QLabel* m_pageRangeWarningLabel {nullptr};
+ bool m_showRangeError {false};
+ QCheckBox* m_adjustHorizontal {nullptr};
+ QCheckBox* m_adjustVertical {nullptr};
+ QLabel* m_validationText {nullptr};
+ QDialogButtonBox* m_buttons {nullptr};
+};
+
+#endif
fma4-preview-reporting-hardening-v1.16.patch (35,343 bytes)
Index: scribus/CMakeLists_Sources.txt
===================================================================
--- scribus/CMakeLists_Sources.txt (revision 27888)
+++ scribus/CMakeLists_Sources.txt (working copy)
@@ -97,6 +97,9 @@
fpointarray.cpp
framelinkrouter.cpp
framemarginadapt.cpp
+ framemarginadaptnavigation.cpp
+ framemarginadaptpreview.cpp
+ framemarginadaptreport.cpp
framemarginadaptworkflow.cpp
framemarginfit.cpp
gtaction.cpp
Index: scribus/framemarginadaptnavigation.cpp
===================================================================
--- scribus/framemarginadaptnavigation.cpp (nonexistent)
+++ scribus/framemarginadaptnavigation.cpp (working copy)
@@ -0,0 +1,147 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadaptnavigation.h"
+
+#include <QAbstractScrollArea>
+#include <QApplication>
+#include <QDialog>
+#include <QEvent>
+#include <QMouseEvent>
+#include <QScrollBar>
+#include <QWidget>
+#include <QWindow>
+
+#include "framemarginadaptpreview.h"
+#include "scribus.h"
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "ui/pagepalette.h"
+#include "ui/pagepalette_widgets.h"
+#include "ui/pageselector.h"
+#include "ui/scrspinbox.h"
+
+FrameMarginAdaptNavigation::FrameMarginAdaptNavigation(ScribusMainWindow* window, QDialog* dialog, QWidget* preview)
+ : QObject(dialog), m_window(window), m_document(window ? window->doc : nullptr),
+ m_view(window ? window->view : nullptr), m_dialog(dialog), m_preview(preview)
+{
+ if (window && window->pagePalette)
+ m_pageGrid = window->pagePalette->findChild<PageGrid*>();
+ qApp->installEventFilter(this);
+}
+
+FrameMarginAdaptNavigation::~FrameMarginAdaptNavigation()
+{
+ qApp->removeEventFilter(this);
+}
+
+bool FrameMarginAdaptNavigation::inWidget(const QWidget* widget, const QWidget* parent) const
+{
+ return widget && parent && (widget == parent || parent->isAncestorOf(widget));
+}
+
+bool FrameMarginAdaptNavigation::eventFilter(QObject* watched, QEvent* event)
+{
+ if (!m_window || !m_dialog)
+ return QObject::eventFilter(watched, event);
+ // A document/view switch must release the filter outside event dispatch.
+ if (!m_document || m_window->doc != m_document || m_window->view != m_view)
+ {
+ if (!m_rejectQueued)
+ {
+ m_rejectQueued = true;
+ QMetaObject::invokeMethod(m_dialog.data(), "reject", Qt::QueuedConnection);
+ }
+ return false;
+ }
+
+ // Platform-window events must reach Qt widget dispatch; only widgets are guarded.
+ if (qobject_cast<QWindow*>(watched))
+ return false;
+
+ switch (event->type())
+ {
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ case QEvent::Shortcut:
+ case QEvent::ShortcutOverride:
+ case QEvent::InputMethod:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseButtonDblClick:
+ case QEvent::MouseMove:
+ case QEvent::Wheel:
+ case QEvent::ContextMenu:
+ case QEvent::DragEnter:
+ case QEvent::DragMove:
+ case QEvent::Drop:
+ break;
+ case QEvent::Close:
+ return watched == m_window ? true : QObject::eventFilter(watched, event);
+ default:
+ return QObject::eventFilter(watched, event);
+ }
+
+ auto* widget = qobject_cast<QWidget*>(watched);
+ if (inWidget(widget, m_dialog))
+ return false;
+
+ // Zoom and page-number entry use existing Scribus navigation controls.
+ if (inWidget(widget, m_window->pageSelector) || inWidget(widget, m_window->zoomSpinBox))
+ return false;
+ if (inWidget(widget, m_window->zoomInToolbarButton) ||
+ inWidget(widget, m_window->zoomOutToolbarButton) ||
+ inWidget(widget, m_window->zoomDefaultToolbarButton))
+ return false;
+
+ // The canvas overlay accepts gestures but only pans/zooms, never edits.
+ if (widget == m_preview)
+ return false;
+ // QScrollArea handles wheel navigation through its viewport, not the
+ // outer ScribusView widget. Allow only wheel events here; the guard
+ // continues blocking editing input on the document viewport.
+ if (widget == m_window->view->viewport() && event->type() == QEvent::Wheel)
+ return false; // Forwarded by the preview overlay.
+
+ if (auto* scrollbar = qobject_cast<QScrollBar*>(widget))
+ {
+ if (inWidget(scrollbar, m_window->view) ||
+ inWidget(scrollbar, m_window->pagePalette))
+ return false;
+ }
+
+ // The Arrange Pages grid accepts a plain left click for page navigation,
+ // but not dragging, master assignment, deletion or context menus.
+ if (widget == m_pageGrid)
+ {
+ if (event->type() == QEvent::MouseButtonPress)
+ {
+ auto* mouse = static_cast<QMouseEvent*>(event);
+ if (mouse->button() == Qt::LeftButton && mouse->modifiers() == Qt::NoModifier)
+ {
+ m_pagePress = mouse->pos();
+ m_pagePressed = true;
+ return false;
+ }
+ }
+ if (event->type() == QEvent::MouseButtonRelease)
+ {
+ auto* mouse = static_cast<QMouseEvent*>(event);
+ const bool click = m_pagePressed && mouse->button() == Qt::LeftButton &&
+ (mouse->pos() - m_pagePress).manhattanLength() <= 4;
+ m_pagePressed = false;
+ if (click)
+ return false;
+ }
+ if (event->type() == QEvent::Wheel)
+ return false;
+ }
+ // Scroll the Arrange Pages thumbnail viewport, not its editing controls.
+ if (event->type() == QEvent::Wheel && widget && m_window->pagePalette &&
+ inWidget(widget, m_window->pagePalette))
+ {
+ if (auto* area = qobject_cast<QAbstractScrollArea*>(widget->parentWidget()))
+ return !inWidget(area, m_window->pagePalette);
+ }
+ return true;
+}
Index: scribus/framemarginadaptnavigation.h
===================================================================
--- scribus/framemarginadaptnavigation.h (nonexistent)
+++ scribus/framemarginadaptnavigation.h (working copy)
@@ -0,0 +1,42 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPTNAVIGATION_H
+#define FRAMEMARGINADAPTNAVIGATION_H
+
+#include <QObject>
+#include <QPointer>
+#include <QPoint>
+
+class QDialog;
+class QWidget;
+class ScribusMainWindow;
+class PageGrid;
+class ScribusDoc;
+class ScribusView;
+
+// Preview-only input filter: allows navigation while blocking mutating UI,
+// menus, shortcuts, canvas editing and drag/drop until Apply or Cancel.
+class FrameMarginAdaptNavigation final : public QObject
+{
+public:
+ FrameMarginAdaptNavigation(ScribusMainWindow* window, QDialog* dialog, QWidget* preview);
+ ~FrameMarginAdaptNavigation() override;
+
+protected:
+ bool eventFilter(QObject* watched, QEvent* event) override;
+
+private:
+ bool inWidget(const QWidget* widget, const QWidget* parent) const;
+ QPointer<ScribusMainWindow> m_window;
+ QPointer<ScribusDoc> m_document;
+ QPointer<ScribusView> m_view;
+ QPointer<QDialog> m_dialog;
+ QPointer<QWidget> m_preview;
+ QPointer<PageGrid> m_pageGrid;
+ QPoint m_pagePress;
+ bool m_pagePressed {false};
+ bool m_rejectQueued {false};
+};
+
+#endif
Index: scribus/framemarginadaptpreview.cpp
===================================================================
--- scribus/framemarginadaptpreview.cpp (nonexistent)
+++ scribus/framemarginadaptpreview.cpp (working copy)
@@ -0,0 +1,152 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadaptpreview.h"
+
+#include <QColor>
+#include <QEvent>
+#include <QCoreApplication>
+#include <QMouseEvent>
+#include <QWheelEvent>
+#include <QPainter>
+#include <QPen>
+#include <QScrollBar>
+
+#include "canvas.h"
+#include "scribusview.h"
+
+FrameMarginAdaptPreview::FrameMarginAdaptPreview(ScribusView* view)
+ : QWidget(view->viewport()), m_view(view), m_canvas(qobject_cast<Canvas*>(view->widget()))
+{
+ setCursor(Qt::OpenHandCursor);
+ setAttribute(Qt::WA_NoSystemBackground);
+ setAttribute(Qt::WA_TranslucentBackground);
+ setGeometry(parentWidget()->rect());
+ parentWidget()->installEventFilter(this);
+ if (m_canvas)
+ m_canvas->installEventFilter(this);
+ connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, this, [this](int) { update(); });
+ connect(view->verticalScrollBar(), &QScrollBar::valueChanged, this, [this](int) { update(); });
+ show();
+ raise();
+}
+
+void FrameMarginAdaptPreview::setOutlines(const QVector<FrameMarginAdaptReport::Outline>& outlines, bool show)
+{
+ m_outlines = outlines;
+ // Always cover the viewport to prevent editing, even with preview off.
+ setVisible(true);
+ m_showOutlines = show && m_canvas && !m_outlines.isEmpty();
+ raise();
+ update();
+}
+
+bool FrameMarginAdaptPreview::eventFilter(QObject* watched, QEvent* event)
+{
+ if (watched == parentWidget() && event->type() == QEvent::Resize)
+ setGeometry(parentWidget()->rect());
+ if (watched == m_canvas && (event->type() == QEvent::Paint ||
+ event->type() == QEvent::Resize || event->type() == QEvent::Move))
+ update();
+ return QWidget::eventFilter(watched, event);
+}
+
+void FrameMarginAdaptPreview::paintEvent(QPaintEvent*)
+{
+ if (!m_canvas || !m_showOutlines)
+ return;
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ // Cosmetic pens remain legible at any document zoom level.
+ // Paint the original last, so overlapping proposed edges cannot hide it.
+ // A dashed light under-stroke keeps the dark original visible over content.
+ constexpr qreal kOriginalStroke = 1.5;
+ constexpr qreal kProposedStroke = 2.0;
+ constexpr qreal kHaloExtension = 1.0;
+ QPen originalHalo(QColor(255, 255, 255, 235), kOriginalStroke + 2 * kHaloExtension, Qt::DashLine);
+ originalHalo.setCosmetic(true);
+ originalHalo.setDashPattern({4.0, 3.0});
+ QPen originalPen(QColor(55, 65, 81), kOriginalStroke, Qt::DashLine);
+ originalPen.setCosmetic(true);
+ originalPen.setDashPattern({4.0, 3.0});
+ QPen proposedHalo(QColor(255, 255, 255, 235), kProposedStroke + 2 * kHaloExtension);
+ proposedHalo.setCosmetic(true);
+ QPen proposedPen(QColor(217, 119, 6), kProposedStroke);
+ proposedPen.setCosmetic(true);
+ const QPoint offset = m_canvas->mapTo(parentWidget(), QPoint(0, 0));
+ painter.setBrush(Qt::NoBrush);
+ for (const FrameMarginAdaptReport::Outline& outline : m_outlines)
+ {
+ const QRectF before = m_canvas->canvasToLocalF(outline.original).translated(offset);
+ const QRectF after = m_canvas->canvasToLocalF(outline.proposed).translated(offset);
+ if (!before.intersects(rect()) && !after.intersects(rect()))
+ continue;
+ painter.setPen(proposedHalo);
+ painter.drawRect(after);
+ painter.setPen(proposedPen);
+ painter.drawRect(after);
+ painter.setPen(originalHalo);
+ painter.drawRect(before);
+ painter.setPen(originalPen);
+ painter.drawRect(before);
+ }
+}
+
+void FrameMarginAdaptPreview::mousePressEvent(QMouseEvent* event)
+{
+ if (event->button() == Qt::LeftButton || event->button() == Qt::MiddleButton)
+ {
+ m_panning = true;
+ m_dragStart = event->pos();
+ m_scrollStart = QPoint(m_view->horizontalScrollBar()->value(),
+ m_view->verticalScrollBar()->value());
+ setCursor(Qt::ClosedHandCursor);
+ }
+ event->accept(); // No canvas selection/edit gesture may pass through.
+}
+
+void FrameMarginAdaptPreview::mouseMoveEvent(QMouseEvent* event)
+{
+ if (m_panning && (event->buttons() & (Qt::LeftButton | Qt::MiddleButton)))
+ {
+ const QPoint distance = event->pos() - m_dragStart;
+ m_view->horizontalScrollBar()->setValue(m_scrollStart.x() - distance.x());
+ m_view->verticalScrollBar()->setValue(m_scrollStart.y() - distance.y());
+ }
+ event->accept();
+}
+
+void FrameMarginAdaptPreview::mouseReleaseEvent(QMouseEvent* event)
+{
+ m_panning = false;
+ setCursor(Qt::OpenHandCursor);
+ event->accept();
+}
+
+void FrameMarginAdaptPreview::wheelEvent(QWheelEvent* event)
+{
+ // Dispatching the overlay's wheel event to a QScrollArea doesn't reliably
+ // reach ScribusView's Ctrl+wheel handler. Use its existing zoom operations
+ // directly, preserving the document point under the mouse cursor.
+ if (event->modifiers() == Qt::ControlModifier)
+ {
+ const int direction = event->angleDelta().y();
+ if (direction != 0 && m_canvas)
+ {
+ const FPoint point = m_canvas->globalToCanvas(event->globalPosition());
+ if (direction > 0)
+ m_view->slotZoomIn(point.x(), point.y(), true);
+ else
+ m_view->slotZoomOut(point.x(), point.y(), true);
+ }
+ }
+ else
+ {
+ // QAbstractScrollArea dispatches wheel events through its viewport.
+ // Forward there so ScribusView::wheelEvent handles normal scrolling,
+ // including its wheel-jump preference and modifier behaviour.
+ QCoreApplication::sendEvent(m_view->viewport(), event);
+ }
+ event->accept();
+}
Index: scribus/framemarginadaptpreview.h
===================================================================
--- scribus/framemarginadaptpreview.h (nonexistent)
+++ scribus/framemarginadaptpreview.h (working copy)
@@ -0,0 +1,42 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPTPREVIEW_H
+#define FRAMEMARGINADAPTPREVIEW_H
+
+#include "framemarginadaptreport.h"
+#include <QVector>
+#include <QWidget>
+
+class Canvas;
+class QMouseEvent;
+class QWheelEvent;
+class ScribusView;
+
+// Temporary viewport overlay: draws geometry and captures gestures for
+// navigation only, never sending mouse edits to the Scribus canvas.
+class FrameMarginAdaptPreview final : public QWidget
+{
+public:
+ explicit FrameMarginAdaptPreview(ScribusView* view);
+ void setOutlines(const QVector<FrameMarginAdaptReport::Outline>& outlines, bool show);
+
+protected:
+ bool eventFilter(QObject* watched, QEvent* event) override;
+ void paintEvent(QPaintEvent* event) override;
+ void mousePressEvent(QMouseEvent* event) override;
+ void mouseMoveEvent(QMouseEvent* event) override;
+ void mouseReleaseEvent(QMouseEvent* event) override;
+ void wheelEvent(QWheelEvent* event) override;
+
+private:
+ ScribusView* m_view {nullptr};
+ Canvas* m_canvas {nullptr};
+ bool m_panning {false};
+ bool m_showOutlines {false};
+ QPoint m_dragStart;
+ QPoint m_scrollStart;
+ QVector<FrameMarginAdaptReport::Outline> m_outlines;
+};
+
+#endif
Index: scribus/framemarginadaptreport.cpp
===================================================================
--- scribus/framemarginadaptreport.cpp (nonexistent)
+++ scribus/framemarginadaptreport.cpp (working copy)
@@ -0,0 +1,134 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadaptreport.h"
+
+#include <QHash>
+
+#include "pageitem.h"
+#include "scpage.h"
+#include "scribusdoc.h"
+
+namespace
+{
+bool differs(double a, double b)
+{
+ return !FrameMarginAdapt::near(a, b);
+}
+}
+
+namespace FrameMarginAdaptReport
+{
+Result evaluate(const FrameMarginAdapt::Snapshot& before, const ScribusDoc* doc,
+ const QVector<FrameMarginAdapt::Change>& changes,
+ const QSet<int>& selectedPages, bool horizontal, bool vertical)
+{
+ Result result;
+ if (!doc || before.document != doc || !doc->Pages ||
+ before.pages.size() != doc->Pages->size())
+ return result;
+
+ QHash<uint, const PageItem*> items;
+ items.reserve(doc->DocItems.size());
+ for (const PageItem* item : doc->DocItems)
+ {
+ if (item)
+ items.insert(item->uniqueNr, item);
+ }
+ QSet<uint> planned;
+ for (const auto& change : changes)
+ {
+ if (!selectedPages.contains(change.pageIndex) || change.pageIndex < 0 ||
+ change.pageIndex >= doc->Pages->size())
+ continue;
+ const PageItem* item = items.value(change.itemId, nullptr);
+ if (!item || item->OwnPage != change.pageIndex)
+ continue;
+ const ScPage* page = doc->Pages->at(change.pageIndex);
+ if (!page)
+ continue;
+ const QRectF original(item->xPos(), item->yPos(), item->width(), item->height());
+ const QRectF proposed(change.bounds.x() + page->xOffset(),
+ change.bounds.y() + page->yOffset(),
+ change.bounds.width(), change.bounds.height());
+ const bool moved = differs(original.x(), proposed.x()) || differs(original.y(), proposed.y());
+ const bool resized = differs(original.width(), proposed.width()) ||
+ differs(original.height(), proposed.height());
+ if (moved && resized)
+ ++result.movedAndResized;
+ else if (moved)
+ ++result.moved;
+ else if (resized)
+ ++result.resized;
+ planned.insert(change.itemId);
+ result.outlines.append({original, proposed});
+ }
+
+ for (const auto& old : before.frames)
+ {
+ if (!selectedPages.contains(old.pageIndex) || old.pageIndex < 0 ||
+ old.pageIndex >= doc->Pages->size() || planned.contains(old.itemId))
+ continue;
+ const ScPage* page = doc->Pages->at(old.pageIndex);
+ if (!page || page != before.pages.at(old.pageIndex).page)
+ continue;
+ const QRectF& previous = before.pages.at(old.pageIndex).margins;
+ const double left = page->leftMargin();
+ const double right = page->width() - page->rightMargin();
+ const double top = page->topMargin();
+ const double bottom = page->height() - page->bottomMargin();
+ const bool shouldMoveHorizontally = horizontal &&
+ ((old.left && differs(previous.left(), left)) ||
+ (old.right && differs(previous.right(), right)));
+ const bool shouldMoveVertically = vertical &&
+ ((old.top && differs(previous.top(), top)) ||
+ (old.bottom && differs(previous.bottom(), bottom)));
+ if (shouldMoveHorizontally || shouldMoveVertically)
+ ++result.skipped;
+ }
+
+ return result;
+}
+
+int newlyOverflowingTextFrames(ScribusDoc* doc, const QSet<uint>& changedIds,
+ const QSet<uint>& previousOverflows)
+{
+ if (!doc || changedIds.isEmpty())
+ return 0;
+
+ QSet<PageItem*> visited;
+ QVector<PageItem*> affected;
+ for (PageItem* item : doc->DocItems)
+ {
+ if (!item || !item->isTextFrame() || !changedIds.contains(item->uniqueNr))
+ continue;
+ // Include entire linked chains; changes to one frame can move overflow
+ // downstream. Cycle guards also avoid looping on a malformed chain.
+ QSet<PageItem*> seenBackwards;
+ PageItem* first = item;
+ while (first->prevInChain() && !seenBackwards.contains(first))
+ {
+ seenBackwards.insert(first);
+ first = first->prevInChain();
+ }
+ for (PageItem* frame = first; frame && !visited.contains(frame); frame = frame->nextInChain())
+ {
+ visited.insert(frame);
+ if (frame->isTextFrame())
+ affected.append(frame);
+ }
+ }
+ for (PageItem* frame : affected)
+ {
+ if (frame->invalid)
+ frame->layout();
+ }
+ int newOverflows = 0;
+ for (const PageItem* frame : affected)
+ {
+ if (frame->frameOverflows() && !previousOverflows.contains(frame->uniqueNr))
+ ++newOverflows;
+ }
+ return newOverflows;
+}
+}
Index: scribus/framemarginadaptreport.h
===================================================================
--- scribus/framemarginadaptreport.h (nonexistent)
+++ scribus/framemarginadaptreport.h (working copy)
@@ -0,0 +1,44 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPTREPORT_H
+#define FRAMEMARGINADAPTREPORT_H
+
+#include <QSet>
+#include <QVector>
+
+#include "framemarginadapt.h"
+
+class ScribusDoc;
+
+namespace FrameMarginAdaptReport
+{
+struct Outline
+{
+ QRectF original; // Canvas/document coordinates.
+ QRectF proposed;
+};
+
+struct Result
+{
+ int moved {0};
+ int resized {0};
+ int movedAndResized {0};
+ int skipped {0};
+ QVector<Outline> outlines;
+};
+
+// Compute counts and canvas outlines from FMA2's already-validated plan.
+// "Skipped" counts only original eligible candidates that no longer qualify.
+// Movement-only, resize-only and combined counts are mutually exclusive.
+Result evaluate(const FrameMarginAdapt::Snapshot& before, const ScribusDoc* doc,
+ const QVector<FrameMarginAdapt::Change>& changes,
+ const QSet<int>& selectedPages, bool horizontal, bool vertical);
+
+// Recompose only text chains affected by adapted text frames, then compare
+// overflow state with the pre-adaptation snapshot (including linked frames).
+int newlyOverflowingTextFrames(ScribusDoc* doc, const QSet<uint>& changedIds,
+ const QSet<uint>& previousOverflows);
+}
+
+#endif
Index: scribus/framemarginadaptworkflow.cpp
===================================================================
--- scribus/framemarginadaptworkflow.cpp (revision 27888)
+++ scribus/framemarginadaptworkflow.cpp (working copy)
@@ -14,12 +14,16 @@
#include <QStatusBar>
#include <QVBoxLayout>
+#include "framemarginadaptpreview.h"
+#include "framemarginadaptnavigation.h"
+#include "framemarginadaptreport.h"
#include "framemarginfit.h"
#include "pageitem.h"
#include "scpage.h"
#include "scraction.h"
#include "scribus.h"
#include "scribusdoc.h"
+#include "scribusview.h"
#include "ui/framemarginadaptdialog.h"
#include "undomanager.h"
@@ -99,7 +103,7 @@
}
bool apply(ScribusDoc* doc, const QVector<FrameMarginAdapt::Change>& changes,
- const QSet<int>& selectedPages)
+ const QSet<int>& selectedPages, QSet<uint>& changedTextIds)
{
if (!doc || changes.isEmpty() || selectedPages.isEmpty())
return false;
@@ -144,6 +148,8 @@
doc->sizeItem(change.bounds.width(), change.bounds.height(), item);
item->invalid = true;
item->checkChanges();
+ if (item->isTextFrame())
+ changedTextIds.insert(item->uniqueNr);
}
if (!firstChanged)
return false;
@@ -173,45 +179,87 @@
if (horizontal.isEmpty() && vertical.isEmpty())
return;
- FrameMarginAdaptDialog dialog(horizontal, vertical, doc->Pages->size(), window);
- dialog.setObjectName(QStringLiteral("frameMarginAdaptDialog"));
- if (dialog.exec() != QDialog::Accepted || !hasCandidates(window, pending.data()))
- return; // Cancel retains the snapshot for later adaptation.
-
- // Replan after user confirmation; frames edited since capture are skipped.
- const auto changes = FrameMarginAdapt::plan(pending->before, doc,
- dialog.adaptHorizontal(), dialog.adaptVertical());
- QSet<uint> previousOverflows;
- for (const PageItem* item : doc->DocItems)
- {
- if (item && item->isTextFrame() && item->frameOverflows())
- previousOverflows.insert(item->uniqueNr);
- }
- const bool didAdapt = apply(doc, changes, dialog.selectedPages());
- if (didAdapt)
- {
- for (PageItem* item : doc->DocItems)
- {
- if (item && item->isTextFrame() && item->invalid)
- item->layout();
- }
- int newOverflows = 0;
+ QPointer<ScribusDoc> safeDoc(doc);
+ auto* dialog = new FrameMarginAdaptDialog(horizontal, vertical,
+ doc->Pages->size(), window);
+ dialog->setObjectName(QStringLiteral("frameMarginAdaptDialog"));
+ dialog->setWindowFlag(Qt::Tool);
+ dialog->setWindowModality(Qt::NonModal);
+
+ // Preview remains a viewport child and never changes item geometry. The
+ // navigation guard blocks editing inputs while keeping page/zoom controls.
+ QPointer<FrameMarginAdaptPreview> preview;
+ if (window->view && window->view->viewport())
+ preview = new FrameMarginAdaptPreview(window->view);
+ auto* navigation = new FrameMarginAdaptNavigation(window, dialog, preview.data());
+
+ auto refreshPreview = [window, safeDoc, pending, dialog, preview]()
+ {
+ if (!safeDoc || !hasCandidates(window, pending.data()))
+ {
+ if (preview)
+ preview->setOutlines({}, false);
+ dialog->setPreviewSummary(0, 0, 0, 0);
+ return;
+ }
+ const auto changes = FrameMarginAdapt::plan(pending->before, safeDoc.data(),
+ dialog->adaptHorizontal(), dialog->adaptVertical());
+ const auto report = FrameMarginAdaptReport::evaluate(pending->before, safeDoc.data(), changes,
+ dialog->selectedPages(),
+ dialog->adaptHorizontal(), dialog->adaptVertical());
+ dialog->setPreviewSummary(report.moved, report.resized, report.movedAndResized, report.skipped);
+ if (preview)
+ preview->setOutlines(report.outlines, dialog->previewOnCanvas());
+ };
+ QObject::connect(dialog, &FrameMarginAdaptDialog::optionsChanged, dialog, refreshPreview);
+ QObject::connect(doc, &QObject::destroyed, dialog, &QDialog::reject);
+ QObject::connect(dialog, &QDialog::finished, dialog,
+ [window, safeDoc, pending, dialog, preview, navigation](int result)
+ {
+ // Release all navigation restrictions BEFORE modifying any document.
+ delete navigation;
+ delete preview.data();
+ dialog->setObjectName(QString());
+ if (result != QDialog::Accepted || !safeDoc || !hasCandidates(window, pending.data()))
+ {
+ FrameMarginAdaptWorkflow::refreshAction(window);
+ dialog->deleteLater();
+ return; // Cancel retains the saved geometry for later reopening.
+ }
+
+ ScribusDoc* doc = safeDoc.data();
+ const auto changes = FrameMarginAdapt::plan(pending->before, doc,
+ dialog->adaptHorizontal(), dialog->adaptVertical());
+ QSet<uint> previousOverflows;
for (const PageItem* item : doc->DocItems)
{
- if (item && item->isTextFrame() && item->frameOverflows() &&
- !previousOverflows.contains(item->uniqueNr))
- ++newOverflows;
- }
- if (newOverflows > 0)
- {
- const QString message = newOverflows == 1
- ? QDialog::tr("1 text frame now has overflow. Review in Preflight.")
- : QDialog::tr("%1 text frames now have overflow. Review in Preflight.").arg(newOverflows);
- window->statusBar()->showMessage(message, 8000);
- }
- delete pending.data(); // A successful adaptation completes this opportunity.
- }
- FrameMarginAdaptWorkflow::refreshAction(window);
+ if (item && item->isTextFrame() && item->frameOverflows())
+ previousOverflows.insert(item->uniqueNr);
+ }
+ QSet<uint> changedTextIds;
+ const bool didAdapt = apply(doc, changes, dialog->selectedPages(), changedTextIds);
+ if (didAdapt)
+ {
+ const int newOverflows = FrameMarginAdaptReport::newlyOverflowingTextFrames(
+ doc, changedTextIds, previousOverflows);
+ if (newOverflows > 0)
+ {
+ const QString message = newOverflows == 1
+ ? QDialog::tr("1 text frame now has overflow. Review in Preflight.")
+ : QDialog::tr("%1 text frames now have overflow. Review in Preflight.").arg(newOverflows);
+ window->statusBar()->showMessage(message, 8000);
+ }
+ }
+ // If no eligible frame was actually changed, keep the opportunity for a
+ // later retry. Accepting a real (including partial) adaptation completes it.
+ if (didAdapt)
+ delete pending.data();
+ FrameMarginAdaptWorkflow::refreshAction(window);
+ dialog->deleteLater();
+ });
+ refreshPreview();
+ dialog->show(); // No nested modal event loop: zoom, scroll and page selection work.
+ dialog->raise();
}
}
Index: scribus/ui/framemarginadaptdialog.cpp
===================================================================
--- scribus/ui/framemarginadaptdialog.cpp (revision 27888)
+++ scribus/ui/framemarginadaptdialog.cpp (working copy)
@@ -11,9 +11,16 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
+#include <QPalette>
+#include <QPushButton>
#include <QRadioButton>
+#include <QFont>
#include <QRegularExpression>
+#include <QResizeEvent>
+#include <QShowEvent>
#include <QStyle>
+#include <QStringList>
+#include <QTimer>
#include <QVBoxLayout>
namespace
@@ -68,7 +75,6 @@
m_totalPages(totalPages)
{
setWindowTitle(tr("Adapt Frames to New Page Geometry"));
- setMinimumWidth(370);
QVBoxLayout* layout = new QVBoxLayout(this);
m_pagesGroup = new QGroupBox(tr("Pages"), this);
@@ -80,6 +86,13 @@
m_pageRange = new QLineEdit(m_pagesGroup);
m_pageRange->setPlaceholderText(tr("e.g. 2, 4-7"));
m_pageRange->setAccessibleName(tr("Specific page numbers or ranges"));
+ m_pageRange->setToolTip(tr("Enter page numbers or ranges separated by commas (e.g. 2, 4-7). "
+ "Only pages affected by the geometry change can be adapted."));
+ // Some Qt styles ignore the disabled Base palette role and retain a white
+ // field. Use palette-relative colours for the disabled state only.
+ m_pageRange->setStyleSheet(QStringLiteral(
+ "QLineEdit:disabled { background-color: palette(window); "
+ "color: palette(mid); border: 1px solid palette(midlight); }"));
// Keep the warning directly beneath the input, not beneath the radio label.
QGridLayout* entryLayout = new QGridLayout;
entryLayout->setContentsMargins(0, 0, 0, 0);
@@ -109,7 +122,29 @@
m_adjustVertical->setChecked(true);
adjustLayout->addWidget(m_adjustHorizontal);
adjustLayout->addWidget(m_adjustVertical);
+ adjustLayout->addStretch();
layout->addWidget(adjustGroup);
+
+ m_previewOnCanvas = new QCheckBox(tr("Preview changes"), this);
+ m_previewOnCanvas->setChecked(true);
+ auto* legend = new QLabel(tr("(Grey dashed = before · Orange = after)"), this);
+ legend->setForegroundRole(QPalette::PlaceholderText);
+ QFont legendFont = legend->font();
+ if (legendFont.pointSizeF() > 0)
+ {
+ legendFont.setPointSizeF(legendFont.pointSizeF() * 0.9);
+ legend->setFont(legendFont);
+ }
+ QHBoxLayout* previewLayout = new QHBoxLayout;
+ previewLayout->setContentsMargins(0, 0, 0, 0);
+ previewLayout->addWidget(m_previewOnCanvas);
+ previewLayout->addWidget(legend);
+ previewLayout->addStretch();
+ QVBoxLayout* footerLayout = new QVBoxLayout;
+ footerLayout->setContentsMargins(0, 0, 0, 0);
+ footerLayout->setSpacing(8);
+ footerLayout->addLayout(previewLayout);
+ connect(m_previewOnCanvas, &QCheckBox::toggled, legend, &QWidget::setVisible);
// Page scope is determined by the original candidate set, not the selected axes.
QSet<int> initialPages;
@@ -122,12 +157,14 @@
m_validationText = new QLabel(this);
m_validationText->setWordWrap(true);
- layout->addWidget(m_validationText);
- // Keep the groups compact and top-aligned even when the dialog grows.
- layout->addStretch();
+ footerLayout->addWidget(m_validationText);
+ m_summaryText = new QLabel(this);
+ m_summaryText->setWordWrap(true);
+ footerLayout->addWidget(m_summaryText);
m_buttons = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
m_buttons->addButton(tr("Adapt frames"), QDialogButtonBox::AcceptRole);
- layout->addWidget(m_buttons);
+ footerLayout->addWidget(m_buttons);
+ layout->addLayout(footerLayout);
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
@@ -151,11 +188,99 @@
if (checked && m_pagesGroup->isEnabled())
m_pageRange->setFocus(Qt::OtherFocusReason);
});
+ connect(m_previewOnCanvas, &QCheckBox::toggled, this, &FrameMarginAdaptDialog::optionsChanged);
validateSelection();
+ // Retain the initial width when the preview legend or warnings disappear.
+ // Height is content-driven; only horizontal resizing is useful here.
+ setMinimumWidth(500);
+ resize(500, sizeHint().height());
+}
+
+void FrameMarginAdaptDialog::fitHeightToContents()
+{
+ // Let Qt settle show/hide and word-wrap changes before fixing the height.
+ QTimer::singleShot(0, this, [this]()
+ {
+ if (!isVisible())
+ return;
+ QLayout* dialogLayout = layout();
+ dialogLayout->activate();
+ const int preferredHeight = dialogLayout->hasHeightForWidth()
+ ? dialogLayout->heightForWidth(width())
+ : dialogLayout->sizeHint().height();
+ setFixedHeight(qMax(preferredHeight, dialogLayout->minimumSize().height()));
+ });
+}
+
+void FrameMarginAdaptDialog::showEvent(QShowEvent* event)
+{
+ QDialog::showEvent(event);
+ fitHeightToContents();
+}
+
+void FrameMarginAdaptDialog::resizeEvent(QResizeEvent* event)
+{
+ QDialog::resizeEvent(event);
+ if (event->size().width() != event->oldSize().width())
+ fitHeightToContents();
}
bool FrameMarginAdaptDialog::adaptHorizontal() const { return m_adjustHorizontal->isChecked(); }
bool FrameMarginAdaptDialog::adaptVertical() const { return m_adjustVertical->isChecked(); }
+bool FrameMarginAdaptDialog::previewOnCanvas() const { return m_previewOnCanvas->isChecked(); }
+
+void FrameMarginAdaptDialog::setPreviewSummary(int moved, int resized, int both, int skipped)
+{
+ if (!m_validationText->text().isEmpty() ||
+ (m_hasPageScope && m_specificPages->isChecked() && selectedPages().isEmpty()))
+ {
+ m_summaryText->clear();
+ m_summaryText->hide();
+ fitHeightToContents();
+ return;
+ }
+ const int total = moved + resized + both;
+ QString summary;
+ if (total == 1)
+ {
+ if (both)
+ summary = tr("1 frame will move and resize");
+ else if (moved)
+ summary = tr("1 frame will move");
+ else
+ summary = tr("1 frame will be resized");
+ }
+ else if (total > 1)
+ {
+ if (both == total)
+ summary = tr("%1 frames will move and resize").arg(total);
+ else if (moved == total)
+ summary = tr("%1 frames will move").arg(total);
+ else if (resized == total)
+ summary = tr("%1 frames will be resized").arg(total);
+ else
+ {
+ // Disjoint categories: a frame is counted only once.
+ QStringList details;
+ if (moved)
+ details << tr("%1 move").arg(moved);
+ if (resized)
+ details << tr("%1 resize").arg(resized);
+ if (both)
+ details << tr("%1 move and resize").arg(both);
+ summary = tr("%1 frames will change (%2)").arg(total).arg(details.join(tr(", ")));
+ }
+ }
+ if (skipped)
+ {
+ if (!summary.isEmpty())
+ summary += tr("; ");
+ summary += skipped == 1 ? tr("1 frame skipped") : tr("%1 frames skipped").arg(skipped);
+ }
+ m_summaryText->setText(summary.isEmpty() ? tr("No frames can be adapted.") : summary + QLatin1Char('.'));
+ m_summaryText->show();
+ fitHeightToContents();
+}
QSet<int> FrameMarginAdaptDialog::affectedPages() const
{
@@ -236,9 +361,12 @@
m_hasPageScope && m_specificPages->isChecked() && !pages.isEmpty());
m_validationText->setText(message);
+ m_validationText->setVisible(!message.isEmpty());
for (QAbstractButton* button : m_buttons->buttons())
{
if (m_buttons->buttonRole(button) == QDialogButtonBox::AcceptRole)
button->setEnabled(!selected.isEmpty());
}
-}
+ emit optionsChanged();
+ fitHeightToContents();
+}
Index: scribus/ui/framemarginadaptdialog.h
===================================================================
--- scribus/ui/framemarginadaptdialog.h (revision 27888)
+++ scribus/ui/framemarginadaptdialog.h (working copy)
@@ -16,6 +16,8 @@
class QRadioButton;
class QDialogButtonBox;
class QGroupBox;
+class QResizeEvent;
+class QShowEvent;
// Only collects the user's choices; it never changes document geometry.
class FrameMarginAdaptDialog : public QDialog
@@ -29,9 +31,19 @@
bool adaptHorizontal() const;
bool adaptVertical() const;
+ bool previewOnCanvas() const;
+ void setPreviewSummary(int moved, int resized, int both, int skipped);
QSet<int> selectedPages() const;
+signals:
+ void optionsChanged();
+
+protected:
+ void showEvent(QShowEvent* event) override;
+ void resizeEvent(QResizeEvent* event) override;
+
private:
+ void fitHeightToContents();
void validateSelection();
QSet<int> affectedPages() const;
@@ -48,6 +60,8 @@
bool m_showRangeError {false};
QCheckBox* m_adjustHorizontal {nullptr};
QCheckBox* m_adjustVertical {nullptr};
+ QCheckBox* m_previewOnCanvas {nullptr};
+ QLabel* m_summaryText {nullptr};
QLabel* m_validationText {nullptr};
QDialogButtonBox* m_buttons {nullptr};
};
| ||||
| Patch | Yes | ||||
|
|
I would not do the popup when page geometry changed. But resizing what touches the margins (and the bleeds; and the guides that move) can be a very welcome feature! (And moving the guides to the left, to the right, or according to the center...) From yesterday discussions with utnik, "automatically" changing the size of frames can have surprising results for people who are no layout experts. But can also be a time saver for those who know what they do! (À propos: scaling the content might also be an option: as an example for the case somebody resizes from A4 to A5; even more dangerous... but...) |
|
|
Only the frames that fit the margins earlier (before page size/margins changed) are refit to the new ones. The frames that aligned to the margins on any side (without fitting the margins) are aligned to the new ones as well (without resizing them). The frames that did not touch any margins on any side are left alone. This imo reduces a lot of surprises that come as a result of automatic resizing/change. On top of that, there is a live preview, and an option to do it on specific page(s). However, I am looking forward to your suggestion on if we not show the popup as soon as the geometry changed? Did you mean keep it in Page > Adapt to new geometry… (as per fma2)? That does not remain there forever (currently). |
|
|
I did not try it out, but if this feature is implemented, I would expect to have options to check at the place where I can change the margins. Right there, not in a following up dialog that shows up after pressing Ok. I'm not sure that asking for confirmations on each frame is a good idea: if there are only a few frames, you can do it / undo it manually; if there are a lot of frames, there will be a lot of confirmations and it will be tedious. Also, modifying the page size, not only changes the margins but also the bleeds: there should be an option to resize items that touch them. |
|
|
> I would expect to have options to check at the place where I can change the margins. This is good @ale. But you then wouldnt see any previews before comitting. > I'm not sure that asking for confirmations on each frame is a good idea. There is no such thing. It is one confirmation for the entire doc change. With the dialog (the first screenshot here) open, you can scroll to check the whole doc to see the preview on each page. And undo/redo is also a single operation for the entire doc. > modifying the page size, not only changes the margins but also the bleeds Yes, bleed option can be explored. I will see. |
|
|
I don't think it needs confirmation. It's a dangerous action, but I don't see how a confirmation can help here. What we could have is a warning that appears below the checkbox when you click it. Something like: """ Resizing frames can modify the text flow. Please carefully check your layout for overflows, underflows, wrong line and frame breaks, and redo the hyphenation. """ |
|
|
Yes, that is my point as well. That warning will not help because the dialog where you change the the page size and margins does not allow interaction with the doc/app behind it. User will still be going blind. With a confirmation dialog one can see what will happen and have the option to CANCEL the adaption (still keeping the resized page/margins). |
|
|
I think you are right when you said (in chat) that confirmation dialog/preview is not needed as one can always undo/redo. I see your point. However, I remember when testing this series, the undo/redo will work only on the frame changes and not the page size and margins changes. I think that needs to be fixed first. The page and margins changes are not recorded in Action History. I will see that. |
|
|
If the undo does not work correctly, that should be fixed. A confirmation popup is not an alternative to the broken undo : - ) |
|
|
No, no. I dropped the popup idea already. I was just getting your opinion on if page size/margin/bleed change should be recorded in the Action History. |
|
|
Baseline: 27910 + FMA1 (from 0018016) + the following in order. ## FMA2: v1.02 → v1.06 - Extended geometry capture and planning to master pages and master-page frames. - Removed the normal selection-mode restriction from automatic adaptation. - Improved handling of page reflow, including objects moving with their pages or remaining at their original document coordinates. - Added stronger finite-value, frame-identity and geometry validation. - Removed horizontal/vertical planning options associated with the retired adaptation dialog. - Reused FMA1's shared eligibility checks, reducing duplication. ## FMA3: v1.12 → `fma3-adapt-frames-directly-v1.04.patch` - Replaced the post-change confirmation and adaptation dialogs with an Adapt margin-aligned frames checkbox in Page Properties and both relevant Document Setup tabs. - Adaptation now runs directly when geometry changes are applied. - Added automatic checkbox availability, synchronisation, context-sensitive tooltips and a conditional text-flow advisory. - Extended adaptation to master-page frames, respecting normal/master-page propagation settings. - Improved master-frame handling and Undo/Redo integration. - Removed the session-only pending-adaptation state and Page > Adapt to new geometry… command. - Removed separate page-range and horizontal/vertical adaptation controls. ## FMA4: v1.16 → RETIRED [ X ] - Removed the live canvas preview and before/after frame outlines. - Removed the non-modal preview dialog's navigation and event-filtering infrastructure. - Removed detailed adaptation reporting, including affected/skipped frame counts and overflow feedback. - Replaced the reporting workflow with a concise advisory beside the new checkbox. - Retained relevant application and safety checks in the revised FMA2/FMA3 implementation. So 4 patches reduced to 3, with automatic adaptation integrated directly into the existing geometry dialogs instead of using a separate confirmation, preview and deferred-adaptation workflow. fma2-margin-adaptation-foundation-v1.06.patch (9,284 bytes)
Index: scribus/CMakeLists_Sources.txt
===================================================================
--- scribus/CMakeLists_Sources.txt (revision 27910)
+++ scribus/CMakeLists_Sources.txt (working copy)
@@ -96,6 +96,7 @@
fpoint.cpp
fpointarray.cpp
framelinkrouter.cpp
+ framemarginadapt.cpp
framemarginfit.cpp
gtaction.cpp
gtfont.cpp
Index: scribus/framemarginadapt.cpp
===================================================================
--- scribus/framemarginadapt.cpp (nonexistent)
+++ scribus/framemarginadapt.cpp (working copy)
@@ -0,0 +1,191 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#include "framemarginadapt.h"
+
+#include <cmath>
+
+#include <QHash>
+
+#include "framemarginfit.h"
+#include "pageitem.h"
+#include "scpage.h"
+#include "scribusdoc.h"
+
+namespace
+{
+QRectF localBounds(const PageItem* item, const ScPage* page)
+{
+ return QRectF(item->xPos() - page->xOffset(), item->yPos() - page->yOffset(),
+ item->width(), item->height());
+}
+
+bool validBounds(const QRectF& bounds)
+{
+ return std::isfinite(bounds.left()) && std::isfinite(bounds.top()) &&
+ std::isfinite(bounds.width()) && std::isfinite(bounds.height()) &&
+ bounds.width() > FrameMarginAdapt::kGeometryTolerance &&
+ bounds.height() > FrameMarginAdapt::kGeometryTolerance;
+}
+
+using Source = FrameMarginAdapt::Source;
+using Snapshot = FrameMarginAdapt::Snapshot;
+using PageSnapshot = FrameMarginAdapt::PageSnapshot;
+using FrameSnapshot = FrameMarginAdapt::FrameSnapshot;
+using Change = FrameMarginAdapt::Change;
+
+void capturePages(const QList<ScPage*>& pages, QVector<PageSnapshot>& output)
+{
+ output.reserve(pages.size());
+ for (const ScPage* page : pages)
+ {
+ PageSnapshot snapshot;
+ if (page)
+ {
+ snapshot.page = page;
+ snapshot.margins = FrameMarginAdapt::marginBounds(page);
+ snapshot.offset = QPointF(page->xOffset(), page->yOffset());
+ }
+ output.append(snapshot);
+ }
+}
+
+void captureFrames(const ScribusDoc* doc, const QList<PageItem*>& items,
+ const QVector<PageSnapshot>& pages, Source source, Snapshot& result)
+{
+ for (const PageItem* item : items)
+ {
+ if (!FrameMarginFit::isSupportedFrame(doc, item) || item->OwnPage < 0 || item->OwnPage >= pages.size())
+ continue;
+ const PageSnapshot& page = pages.at(item->OwnPage);
+ if (!page.page || !validBounds(page.margins))
+ continue;
+
+ FrameSnapshot frame;
+ frame.source = source;
+ frame.itemId = item->uniqueNr;
+ frame.pageIndex = item->OwnPage;
+ frame.bounds = localBounds(item, page.page);
+ if (!validBounds(frame.bounds))
+ continue;
+ frame.left = FrameMarginAdapt::near(frame.bounds.left(), page.margins.left(), FrameMarginAdapt::kEdgeTolerance);
+ frame.right = FrameMarginAdapt::near(frame.bounds.right(), page.margins.right(), FrameMarginAdapt::kEdgeTolerance);
+ frame.top = FrameMarginAdapt::near(frame.bounds.top(), page.margins.top(), FrameMarginAdapt::kEdgeTolerance);
+ frame.bottom = FrameMarginAdapt::near(frame.bounds.bottom(), page.margins.bottom(), FrameMarginAdapt::kEdgeTolerance);
+ if (frame.left || frame.right || frame.top || frame.bottom)
+ result.frames.append(frame);
+ }
+}
+
+void planFrames(const Snapshot& before, const ScribusDoc* doc, Source source,
+ const QList<ScPage*>& pages, const QVector<PageSnapshot>& previousPages,
+ const QList<PageItem*>& items, QVector<Change>& changes)
+{
+ if (pages.size() != previousPages.size())
+ return;
+ QHash<uint, const PageItem*> currentItems;
+ currentItems.reserve(items.size());
+ for (const PageItem* item : items)
+ {
+ if (item)
+ currentItems.insert(item->uniqueNr, item);
+ }
+
+ for (const FrameSnapshot& old : before.frames)
+ {
+ if (old.source != source || old.pageIndex < 0 || old.pageIndex >= pages.size())
+ continue;
+ const PageSnapshot& previousPage = previousPages.at(old.pageIndex);
+ const ScPage* page = pages.at(old.pageIndex);
+ if (!page || page != previousPage.page)
+ continue;
+ const QRectF newMargins = FrameMarginAdapt::marginBounds(page);
+ if (!validBounds(newMargins) || FrameMarginAdapt::sameBounds(newMargins, previousPage.margins))
+ continue;
+
+ const PageItem* item = currentItems.value(old.itemId, nullptr);
+ if (!item || item->OwnPage != old.pageIndex || !FrameMarginFit::isSupportedFrame(doc, item))
+ continue;
+ const QRectF current = localBounds(item, page);
+ // Reflow may shift a frame with its page or leave it at its document coordinates.
+ const QPointF offsetChange = previousPage.offset - QPointF(page->xOffset(), page->yOffset());
+ if (!FrameMarginAdapt::sameBounds(current, old.bounds) &&
+ !FrameMarginAdapt::sameBounds(current, old.bounds.translated(offsetChange)))
+ continue;
+
+ double x = current.x();
+ double y = current.y();
+ double width = current.width();
+ double height = current.height();
+ if (old.left && old.right)
+ {
+ x = newMargins.left();
+ width = newMargins.width();
+ }
+ else if (old.left)
+ x = newMargins.left();
+ else if (old.right)
+ x = newMargins.right() - width;
+
+ if (old.top && old.bottom)
+ {
+ y = newMargins.top();
+ height = newMargins.height();
+ }
+ else if (old.top)
+ y = newMargins.top();
+ else if (old.bottom)
+ y = newMargins.bottom() - height;
+
+ const QRectF target(x, y, width, height);
+ if (validBounds(target) && !FrameMarginAdapt::sameBounds(target, current))
+ changes.append({source, old.itemId, old.pageIndex, current, target});
+ }
+}
+}
+
+namespace FrameMarginAdapt
+{
+bool near(double a, double b, double tolerance)
+{
+ return std::isfinite(a) && std::isfinite(b) && std::abs(a - b) <= tolerance;
+}
+
+bool sameBounds(const QRectF& a, const QRectF& b)
+{
+ return near(a.x(), b.x()) && near(a.y(), b.y()) &&
+ near(a.width(), b.width()) && near(a.height(), b.height());
+}
+
+QRectF marginBounds(const ScPage* page)
+{
+ return QRectF(page->leftMargin(), page->topMargin(),
+ page->width() - page->leftMargin() - page->rightMargin(),
+ page->height() - page->topMargin() - page->bottomMargin());
+}
+
+Snapshot capture(const ScribusDoc* doc)
+{
+ Snapshot result;
+ if (!doc || doc->symbolEditMode() || doc->inlineEditMode())
+ return result;
+
+ result.document = doc;
+ capturePages(doc->DocPages, result.pages);
+ capturePages(doc->MasterPages, result.masterPages);
+ captureFrames(doc, doc->DocItems, result.pages, Source::Document, result);
+ captureFrames(doc, doc->MasterItems, result.masterPages, Source::Master, result);
+ return result;
+}
+
+QVector<Change> plan(const Snapshot& before, const ScribusDoc* doc)
+{
+ QVector<Change> changes;
+ if (!doc || before.document != doc || doc->symbolEditMode() || doc->inlineEditMode())
+ return changes;
+ planFrames(before, doc, Source::Document, doc->DocPages, before.pages, doc->DocItems, changes);
+ planFrames(before, doc, Source::Master, doc->MasterPages, before.masterPages, doc->MasterItems, changes);
+ return changes;
+}
+
+}
Index: scribus/framemarginadapt.h
===================================================================
--- scribus/framemarginadapt.h (nonexistent)
+++ scribus/framemarginadapt.h (working copy)
@@ -0,0 +1,70 @@
+/*
+For general Scribus copyright and licensing information please refer to COPYING.
+*/
+#ifndef FRAMEMARGINADAPT_H
+#define FRAMEMARGINADAPT_H
+
+#include <QPointF>
+#include <QRectF>
+#include <QVector>
+
+class ScPage;
+class ScribusDoc;
+
+namespace FrameMarginAdapt
+{
+ inline constexpr double kGeometryTolerance = 0.0001; // Document points.
+ inline constexpr double kEdgeTolerance = 0.25; // Account for UI rounding.
+
+ bool near(double first, double second, double tolerance = kGeometryTolerance);
+ bool sameBounds(const QRectF& first, const QRectF& second);
+ QRectF marginBounds(const ScPage* page);
+
+ struct PageSnapshot
+ {
+ const ScPage* page {nullptr}; // Used only to verify page identity after reflow; never dereferenced.
+ QRectF margins; // Page-local margin rectangle.
+ QPointF offset; // Original page origin in document coordinates.
+ };
+
+ enum class Source { Document, Master };
+
+ struct FrameSnapshot
+ {
+ Source source {Source::Document};
+ uint itemId {0};
+ int pageIndex {-1};
+ QRectF bounds; // Page-local frame rectangle.
+ bool left {false};
+ bool right {false};
+ bool top {false};
+ bool bottom {false};
+ };
+
+ struct Snapshot
+ {
+ const ScribusDoc* document {nullptr};
+ QVector<PageSnapshot> pages;
+ QVector<PageSnapshot> masterPages;
+ QVector<FrameSnapshot> frames;
+ };
+
+ struct Change
+ {
+ Source source {Source::Document};
+ uint itemId {0};
+ int pageIndex {-1};
+ QRectF expectedBounds; // Geometry immediately after page reflow.
+ QRectF bounds; // Target page-local frame rectangle.
+ };
+
+ // Capture immediately before page dimensions or margins are changed.
+ Snapshot capture(const ScribusDoc* doc);
+
+ // Plan once after page reflow, before applying any frame adaptations.
+ // Identity, geometry and eligibility are rechecked; this never mutates the document.
+ QVector<Change> plan(const Snapshot& before, const ScribusDoc* doc);
+
+}
+
+#endif
fma3-adapt-frames-directly-v1.04.patch (30,512 bytes)
Index: scribus/framemarginadapt.cpp
===================================================================
--- scribus/framemarginadapt.cpp (revision 27910)
+++ scribus/framemarginadapt.cpp (working copy)
@@ -188,4 +188,87 @@
return changes;
}
-}
+void apply(ScribusDoc* doc, const QVector<Change>& changes)
+{
+ if (!doc || changes.isEmpty())
+ return;
+
+ QHash<uint, PageItem*> documentItems;
+ QHash<uint, PageItem*> masterItems;
+ documentItems.reserve(doc->DocItems.size());
+ masterItems.reserve(doc->MasterItems.size());
+ for (PageItem* item : doc->DocItems)
+ {
+ if (item)
+ documentItems.insert(item->uniqueNr, item);
+ }
+ for (PageItem* item : doc->MasterItems)
+ {
+ if (item)
+ masterItems.insert(item->uniqueNr, item);
+ }
+
+ // Move/resize recompute OwnPage from the active page list; master frames
+ // must be edited in master mode to preserve their association for Undo/Redo.
+ const bool previousMasterMode = doc->masterPageMode();
+ ScPage* previousPage = doc->currentPage();
+ PageItem* firstChangedDocumentItem = nullptr;
+ bool changedAny = false;
+ for (const Change& change : changes)
+ {
+ const bool isMaster = change.source == Source::Master;
+ const auto& pages = isMaster ? doc->MasterPages : doc->DocPages;
+ if (change.pageIndex < 0 || change.pageIndex >= pages.size())
+ continue;
+ ScPage* page = pages.at(change.pageIndex);
+ if (!page)
+ continue;
+ PageItem* item = (isMaster ? masterItems : documentItems).value(change.itemId, nullptr);
+ if (!item || item->OwnPage != change.pageIndex ||
+ isMaster != !item->OnMasterPage.isEmpty() ||
+ (isMaster && item->OnMasterPage != page->pageName()) ||
+ !FrameMarginFit::isSupportedFrame(doc, item) ||
+ !sameBounds(localBounds(item, page), change.expectedBounds))
+ continue;
+
+ const QRectF target = change.bounds.translated(page->xOffset(), page->yOffset());
+ const double dx = target.x() - item->xPos();
+ const double dy = target.y() - item->yPos();
+ const bool move = !near(dx, 0.0) || !near(dy, 0.0);
+ const bool resize = !near(target.width(), item->width()) || !near(target.height(), item->height());
+ if (!move && !resize)
+ continue;
+
+ if (doc->masterPageMode() != isMaster)
+ doc->setMasterPageMode(isMaster);
+ // Only master-frame edits require switching the current page. Normal-page
+ // adaptation need not refresh the page and guide palettes for every frame.
+ if (isMaster && doc->currentPage() != page)
+ doc->setCurrentPage(page);
+
+ if (move)
+ doc->moveItem(dx, dy, item);
+ if (resize)
+ doc->sizeItem(target.width(), target.height(), item);
+ item->invalid = true;
+ item->checkChanges();
+ changedAny = true;
+ if (!isMaster && !firstChangedDocumentItem)
+ firstChangedDocumentItem = item;
+ }
+ if (doc->masterPageMode() != previousMasterMode)
+ doc->setMasterPageMode(previousMasterMode);
+ if (doc->currentPage() != previousPage)
+ doc->setCurrentPage(previousPage);
+
+ if (changedAny)
+ {
+ doc->regionsChanged()->update(QRectF());
+ doc->changed();
+ doc->changedPagePreview();
+ // Do not expose master items in the normal-page properties palette.
+ if (firstChangedDocumentItem && !previousMasterMode)
+ firstChangedDocumentItem->emitAllToGUI();
+ }
+}
+}
Index: scribus/framemarginadapt.h
===================================================================
--- scribus/framemarginadapt.h (revision 27910)
+++ scribus/framemarginadapt.h (working copy)
@@ -65,6 +65,8 @@
// Identity, geometry and eligibility are rechecked; this never mutates the document.
QVector<Change> plan(const Snapshot& before, const ScribusDoc* doc);
+ // Execute a validated plan. The caller owns the undo transaction, if any.
+ void apply(ScribusDoc* doc, const QVector<Change>& changes);
}
#endif
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 27910)
+++ scribus/scribus.cpp (working copy)
@@ -114,6 +114,7 @@
#include "documentlogmanager.h"
#include "fileloader.h"
#include "filewatcher.h"
+#include "framemarginadapt.h"
#include "fpoint.h"
#include "fpointarray.h"
#include "gtgettext.h"
@@ -6304,11 +6305,21 @@
int lp=0;
if (doc->masterPageMode() && doc->pagePositioning() != singlePage)
lp = dia->pageOrder();
+ const bool adaptFrames = dia->adaptMarginAlignedFrames();
+ const auto beforeGeometry = adaptFrames ? FrameMarginAdapt::capture(doc) : FrameMarginAdapt::Snapshot();
+ UndoTransaction geometryTransaction;
+ if (adaptFrames && UndoManager::undoEnabled())
+ geometryTransaction = m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup,
+ tr("Change Page Properties"), QString(), Um::IResize);
doc->changePageProperties(dia->top(), dia->bottom(), dia->left(), dia->right(),
pageHeight, pageWidth, pageHeight, pageWidth, orientation,
pageSizeName, dia->getMarginPreset(), dia->getMoveObjects(), doc->currentPage()->pageNr(), lp);
if (!doc->masterPageMode() && dia->masterPage() != currPageMasterPageName)
Apply_MasterPage(dia->masterPage(), doc->currentPage()->pageNr());
+ if (adaptFrames)
+ FrameMarginAdapt::apply(doc, FrameMarginAdapt::plan(beforeGeometry, doc));
+ if (geometryTransaction)
+ geometryTransaction.commit();
doc->updateEndnotesFrames();
}
@@ -6770,6 +6781,8 @@
struct ApplicationPrefs newDocPrefs(prefsDialog.prefs());
bool resizePages, resizeMasterPages, resizePageMargins, resizeMasterPageMargins;
prefsDialog.getResizeDocumentPages(resizePages, resizeMasterPages, resizePageMargins, resizeMasterPageMargins);
+ const bool adaptFrames = prefsDialog.adaptMarginAlignedFrames();
+ const auto beforeGeometry = adaptFrames ? FrameMarginAdapt::capture(doc) : FrameMarginAdapt::Snapshot();
doc->setNewPrefs(newDocPrefs, oldDocPrefs, resizePages, resizeMasterPages, resizePageMargins, resizeMasterPageMargins);
slotChangeUnit(doc->unitIndex(), false);
@@ -6817,6 +6830,20 @@
view->reformPages();
doc->setMasterPageMode(false);
view->reformPages();
+ if (adaptFrames)
+ {
+ const auto changes = FrameMarginAdapt::plan(beforeGeometry, doc);
+ if (!changes.isEmpty())
+ {
+ UndoTransaction adaptTransaction;
+ if (UndoManager::undoEnabled())
+ adaptTransaction = m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup,
+ tr("Adapt Frames to New Page Geometry"), QString(), Um::IResize);
+ FrameMarginAdapt::apply(doc, changes);
+ if (adaptTransaction)
+ adaptTransaction.commit();
+ }
+ }
view->GotoPage(doc->currentPage()->pageNr());
view->DrawNew();
pagePalette->rebuildPages();
Index: scribus/ui/pagepropertiesdialog.cpp
===================================================================
--- scribus/ui/pagepropertiesdialog.cpp (revision 27910)
+++ scribus/ui/pagepropertiesdialog.cpp (working copy)
@@ -4,22 +4,26 @@
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
+#include "pagepropertiesdialog.h"
+
#include <QCheckBox>
#include <QColorDialog>
#include <QComboBox>
#include <QGridLayout>
+#include <QGroupBox>
#include <QHBoxLayout>
-#include <QGroupBox>
#include <QLabel>
+#include <QPalette>
#include <QPixmap>
#include <QPushButton>
+#include <QSignalBlocker>
#include <QVBoxLayout>
#include "commonstrings.h"
+#include "framemarginadapt.h"
#include "iconmanager.h"
+#include "manager/pagepreset_manager.h"
#include "newmarginwidget.h"
-#include "pagepropertiesdialog.h"
-#include "manager/pagepreset_manager.h"
#include "pagestructs.h"
#include "scpage.h"
#include "scribusdoc.h"
@@ -29,6 +33,7 @@
PagePropertiesDialog::PagePropertiesDialog( QWidget* parent, ScribusDoc* doc )
: QDialog( parent),
+ m_doc(doc),
m_unitRatio(doc->unitRatio())
{
setModal(true);
@@ -109,6 +114,29 @@
marginWidget->setMarginPreset(doc->currentPage()->marginPreset);
dialogLayout->addWidget( marginWidget );
+ m_originalWidth = doc->currentPage()->width();
+ m_originalHeight = doc->currentPage()->height();
+ m_originalOrientation = doc->currentPage()->orientation();
+ m_originalMargins = doc->currentPage()->initialMargins;
+ m_originalPageOrder = Links ? Links->currentIndex() : -1;
+ m_adaptFrames = new QCheckBox(tr("Adapt margin-aligned frames"), this);
+ dialogLayout->addWidget(m_adaptFrames);
+ m_adaptInfo = new QWidget(this);
+ auto* adaptInfoLayout = new QHBoxLayout(m_adaptInfo);
+ adaptInfoLayout->setContentsMargins(22, 0, 0, 0);
+ adaptInfoLayout->setSpacing(6);
+ auto* adaptIcon = new QLabel(m_adaptInfo);
+ adaptIcon->setPixmap(IconManager::instance().loadPixmap("information", 16));
+ adaptIcon->setFixedSize(16, 16);
+ adaptInfoLayout->addWidget(adaptIcon, 0, Qt::AlignTop);
+ auto* adaptNote = new QLabel(tr("Frame adaptation may alter text flow, line breaks and hyphenation. "
+ "Review the layout for overflow and unintended changes."), m_adaptInfo);
+ adaptNote->setWordWrap(true);
+ adaptNote->setForegroundRole(QPalette::PlaceholderText);
+ adaptInfoLayout->addWidget(adaptNote, 1);
+ m_adaptInfo->hide();
+ dialogLayout->addWidget(m_adaptInfo);
+
groupMaster = new QGroupBox( this );
groupMaster->setTitle( tr( "Other Settings" ) );
masterLayout = new QHBoxLayout( groupMaster );
@@ -126,11 +154,12 @@
for (auto it = doc->MasterNames.cbegin(); it != doc->MasterNames.cend(); ++it)
{
in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
- masterPageComboBox->addItem(in);
+ masterPageComboBox->addItem(in, it.key());
if (in == na)
masterPageComboBox->setCurrentIndex(cc);
++cc;
}
+ m_originalMasterIndex = masterPageComboBox->currentIndex();
masterLayout->addWidget( masterPageComboBox );
}
dialogLayout->addWidget( groupMaster );
@@ -149,7 +178,6 @@
cancelButton->setDefault( false );
okCancelLayout->addWidget(cancelButton);
dialogLayout->addLayout( okCancelLayout );
- setMaximumSize(sizeHint());
m_pageWidth = widthSpinBox->value() / m_unitRatio;
m_pageHeight = heightSpinBox->value() / m_unitRatio;
@@ -164,6 +192,20 @@
connect(pageSizeSelector, SIGNAL(pageSizeChanged(QString)), this, SLOT(setPageSize()));
connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
+ connect(m_adaptFrames, &QCheckBox::toggled, this, [this](bool checked) {
+ m_adaptWanted = checked;
+ m_adaptInfo->setVisible(checked && m_adaptFrames->isEnabled());
+ adjustSize();
+ });
+ connect(widthSpinBox, &ScrSpinBox::valueChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
+ connect(heightSpinBox, &ScrSpinBox::valueChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
+ connect(pageSizeSelector, &PageSizeSelector::pageSizeChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
+ connect(orientationQComboBox, &QComboBox::currentIndexChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
+ connect(marginWidget, &NewMarginWidget::valuesChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
+ if (Links)
+ connect(Links, &QComboBox::currentIndexChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
+ if (masterPageComboBox)
+ connect(masterPageComboBox, &QComboBox::currentIndexChanged, this, &PagePropertiesDialog::updateAdaptAvailability);
//tooltips
pageSizeSelector->setToolTip( tr( "Size of the inserted pages, either a standard or custom size" ) );
@@ -174,8 +216,8 @@
setPageSize();
setMinimumSize(minimumSizeHint());
- setMaximumSize(minimumSizeHint());
resize(minimumSizeHint());
+ updateAdaptAvailability();
}
void PagePropertiesDialog::setPageWidth(double)
@@ -268,6 +310,7 @@
m_pageHeight = heightSpinBox->value() / m_unitRatio;
connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
+ updateAdaptAvailability();
}
int PagePropertiesDialog::pageOrder() const
@@ -304,6 +347,52 @@
return prefsPageSizeName;
}
+bool PagePropertiesDialog::adaptMarginAlignedFrames() const
+{
+ return m_adaptFrames && m_adaptFrames->isEnabled() && m_adaptFrames->isChecked();
+}
+
+void PagePropertiesDialog::updateAdaptAvailability()
+{
+ if (!m_adaptFrames)
+ return;
+ constexpr double tolerance = 0.0001;
+ const MarginStruct& margins = marginWidget->margins();
+ const bool marginChanged = qAbs(margins.left() - m_originalMargins.left()) > tolerance ||
+ qAbs(margins.right() - m_originalMargins.right()) > tolerance ||
+ qAbs(margins.top() - m_originalMargins.top()) > tolerance ||
+ qAbs(margins.bottom() - m_originalMargins.bottom()) > tolerance;
+ const bool sizeChanged = qAbs(m_pageWidth - m_originalWidth) > tolerance ||
+ qAbs(m_pageHeight - m_originalHeight) > tolerance ||
+ orientationQComboBox->currentIndex() != m_originalOrientation;
+ const bool typeChanged = Links && Links->currentIndex() != m_originalPageOrder;
+ bool masterGeometryChanged = false;
+ if (masterPageComboBox && m_doc && masterPageComboBox->currentIndex() != m_originalMasterIndex)
+ {
+ const QString name = masterPageComboBox->currentData().toString();
+ const int index = m_doc->MasterNames.value(name, -1);
+ if (index >= 0 && index < m_doc->MasterPages.size())
+ {
+ const ScPage* master = m_doc->MasterPages.at(index);
+ const ScPage* current = m_doc->currentPage();
+ masterGeometryChanged = master && current &&
+ (!FrameMarginAdapt::sameBounds(FrameMarginAdapt::marginBounds(master),
+ FrameMarginAdapt::marginBounds(current)) ||
+ master->orientation() != current->orientation());
+ }
+ }
+ const bool available = sizeChanged || marginChanged || typeChanged || masterGeometryChanged;
+ m_adaptFrames->setEnabled(available);
+ m_adaptFrames->setToolTip(available
+ ? tr("Adapts frames aligned with the previous page margins to the new geometry.")
+ : tr("Available when page geometry changes, including through a different master page."));
+ {
+ QSignalBlocker blocker(m_adaptFrames);
+ m_adaptFrames->setChecked(available && m_adaptWanted);
+ }
+ m_adaptInfo->setVisible(available && m_adaptWanted);
+}
+
bool PagePropertiesDialog::getMoveObjects() const
{
return moveObjects->isChecked();
Index: scribus/ui/pagepropertiesdialog.h
===================================================================
--- scribus/ui/pagepropertiesdialog.h (revision 27910)
+++ scribus/ui/pagepropertiesdialog.h (working copy)
@@ -11,6 +11,7 @@
#include <QDialog>
#include "widgets/pagesizeselector.h"
+#include "margins.h"
class QGroupBox;
class QLabel;
@@ -53,6 +54,7 @@
/*! \brief Bool value of moveObjects "property"
\retval bool true for moving */
bool getMoveObjects() const;
+ bool adaptMarginAlignedFrames() const;
/*! \brief Returns prefsPageSizeName value
\retval QString prefsPageSizeName property */
QString getPrefsPageSizeName() const;
@@ -90,8 +92,10 @@
It's called from width spinbox.
\param v new height */
void setPageHeight(double v);
+ void updateAdaptAvailability();
private:
+ ScribusDoc* m_doc {nullptr};
NewMarginWidget* marginWidget { nullptr };
QGroupBox* dsGroupBox7 { nullptr };
QGroupBox* groupMaster { nullptr };
@@ -108,6 +112,15 @@
QComboBox* Links { nullptr };
QLabel* TextLabel3 { nullptr };
QCheckBox* moveObjects { nullptr };
+ QCheckBox* m_adaptFrames { nullptr };
+ QWidget* m_adaptInfo { nullptr };
+ bool m_adaptWanted {false};
+ double m_originalWidth {0.0};
+ double m_originalHeight {0.0};
+ int m_originalOrientation {0};
+ MarginStruct m_originalMargins;
+ int m_originalPageOrder {0};
+ int m_originalMasterIndex {-1};
QPushButton* pageFillColorButton { nullptr };
QPushButton* cancelButton { nullptr };
QPushButton* okButton { nullptr };
Index: scribus/ui/preferences/preferencesdialog.cpp
===================================================================
--- scribus/ui/preferences/preferencesdialog.cpp (revision 27910)
+++ scribus/ui/preferences/preferencesdialog.cpp (working copy)
@@ -430,6 +430,11 @@
}
}
+bool PreferencesDialog::adaptMarginAlignedFrames() const
+{
+ return prefs_DocumentSetup && prefs_DocumentSetup->adaptMarginAlignedFrames();
+}
+
void PreferencesDialog::getResizeDocumentPages(bool &resizePages, bool &resizeMasterPages, bool &resizePageMargins, bool &resizeMasterPageMargins)
{
prefs_DocumentSetup->getResizeDocumentPages(resizePages, resizeMasterPages, resizePageMargins, resizeMasterPageMargins);
Index: scribus/ui/preferences/preferencesdialog.h
===================================================================
--- scribus/ui/preferences/preferencesdialog.h (revision 27910)
+++ scribus/ui/preferences/preferencesdialog.h (working copy)
@@ -64,6 +64,7 @@
ApplicationPrefs prefs() const { return localPrefs; }
void getResizeDocumentPages(bool &resizePages, bool &resizeMasterPages, bool &resizePageMargins, bool &resizeMasterPageMargins);
+ bool adaptMarginAlignedFrames() const;
public slots:
/// \brief Overridden to emit accepted(), which plugin panels use
Index: scribus/ui/preferences/prefs_documentsetup.cpp
===================================================================
--- scribus/ui/preferences/prefs_documentsetup.cpp (revision 27910)
+++ scribus/ui/preferences/prefs_documentsetup.cpp (working copy)
@@ -8,8 +8,12 @@
#include <QButtonGroup>
#include <QFileDialog>
+#include <QPalette>
+#include <QPixmap>
+#include <QSignalBlocker>
#include "commonstrings.h"
+#include "iconmanager.h"
#include "langmgr.h"
#include "manager/pagepreset_manager.h"
#include "prefsfile.h"
@@ -40,6 +44,10 @@
applySizesToAllMasterPagesCheckBox->hide();
applyMarginsToAllPagesCheckBox->hide();
applyMarginsToAllMasterPagesCheckBox->hide();
+ adaptFramesSizeCheckBox->hide();
+ adaptFramesSizeInfo->hide();
+ adaptFramesMarginsCheckBox->hide();
+ adaptFramesMarginsInfo->hide();
pageSizeLinkToolButton->hide(); //temp
// connect(pageSizeLinkToolButton, SIGNAL(clicked()), this, SLOT(emitSectionChange()));
}
@@ -71,6 +79,33 @@
pageHeightSpinBox->setMaximum(16777215);
languageChange();
+ // Two views of one operation-wide choice, not independent settings.
+ connect(adaptFramesSizeCheckBox, &QCheckBox::toggled,
+ adaptFramesMarginsCheckBox, &QCheckBox::setChecked);
+ connect(adaptFramesMarginsCheckBox, &QCheckBox::toggled,
+ adaptFramesSizeCheckBox, &QCheckBox::setChecked);
+
+ const QPixmap infoPixmap = IconManager::instance().loadPixmap("information", 16);
+ for (QLabel* icon : {adaptFramesSizeIcon, adaptFramesMarginsIcon})
+ {
+ icon->setPixmap(infoPixmap);
+ icon->setFixedSize(16, 16);
+ }
+ for (QLabel* note : {adaptFramesSizeNote, adaptFramesMarginsNote})
+ note->setForegroundRole(QPalette::PlaceholderText);
+ adaptFramesSizeInfo->hide();
+ adaptFramesMarginsInfo->hide();
+ connect(adaptFramesSizeCheckBox, &QCheckBox::toggled, this, [this](bool checked) {
+ m_adaptWanted = checked;
+ adaptFramesSizeInfo->setVisible(checked && adaptFramesSizeCheckBox->isEnabled());
+ adaptFramesMarginsInfo->setVisible(checked && adaptFramesMarginsCheckBox->isEnabled());
+ });
+ connect(adaptFramesMarginsCheckBox, &QCheckBox::toggled, this, [this](bool checked) {
+ m_adaptWanted = checked;
+ adaptFramesSizeInfo->setVisible(checked && adaptFramesSizeCheckBox->isEnabled());
+ adaptFramesMarginsInfo->setVisible(checked && adaptFramesMarginsCheckBox->isEnabled());
+ });
+
connect(pageSizeSelector, SIGNAL(pageSizeChanged(QString)), this, SLOT(setPageSize()));
connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setPageOrientation(int)));
connect(pageWidthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
@@ -79,6 +114,21 @@
connect(pageUnitsComboBox, SIGNAL(activated(int)), this, SLOT(unitChange()));
connect(undoCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotUndo(bool)));
connect(changeAutoDir, SIGNAL(clicked()), this, SLOT(changeAutoDocDir()));
+
+ // Geometry fields can update each other programmatically; examine the final values.
+ connect(pageWidthSpinBox, &ScrSpinBox::valueChanged, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(pageHeightSpinBox, &ScrSpinBox::valueChanged, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(pageSizeSelector, &PageSizeSelector::pageSizeChanged, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(pageOrientationComboBox, &QComboBox::currentIndexChanged, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(marginsWidget, &NewMarginWidget::valuesChanged, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(applySizesToAllPagesCheckBox, &QCheckBox::toggled, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(applySizesToAllMasterPagesCheckBox, &QCheckBox::toggled, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(applyMarginsToAllPagesCheckBox, &QCheckBox::toggled, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(applyMarginsToAllMasterPagesCheckBox, &QCheckBox::toggled, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(pageLayoutButtonGroup, &QButtonGroup::idClicked, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(bindingDirectionButtonGroup, &QButtonGroup::idClicked, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ connect(layoutFirstPageIsComboBox, &QComboBox::currentIndexChanged, this, &Prefs_DocumentSetup::updateAdaptAvailability);
+ updateAdaptAvailability();
}
void Prefs_DocumentSetup::unitChange()
@@ -224,6 +274,15 @@
else
undoLengthSpinBox->setValue(undoLength);
unitChange();
+ m_originalWidth = prefsData->docSetupPrefs.pageWidth;
+ m_originalHeight = prefsData->docSetupPrefs.pageHeight;
+ m_originalOrientation = prefsData->docSetupPrefs.pageOrientation;
+ m_originalPositioning = prefsData->docSetupPrefs.pagePositioning;
+ m_originalBinding = prefsData->docSetupPrefs.bindingDirection;
+ m_originalFirstPage = prefsData->pageSets[m_originalPositioning].FirstPage;
+ m_originalMargins = prefsData->docSetupPrefs.margins;
+ m_adaptWanted = false;
+ updateAdaptAvailability();
}
void Prefs_DocumentSetup::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
@@ -348,6 +407,7 @@
pageH = pageHeightSpinBox->value() / unitRatio;
pageWidthSpinBox->blockSignals(false);
pageHeightSpinBox->blockSignals(false);
+ updateAdaptAvailability();
}
void Prefs_DocumentSetup::setPageSize()
@@ -392,6 +452,44 @@
resizeMasterPageMargins = applyMarginsToAllMasterPagesCheckBox->isChecked();
}
+bool Prefs_DocumentSetup::adaptMarginAlignedFrames() const
+{
+ return m_doc && adaptFramesSizeCheckBox->isEnabled() && adaptFramesSizeCheckBox->isChecked();
+}
+
+void Prefs_DocumentSetup::updateAdaptAvailability()
+{
+ if (!m_doc)
+ return;
+ constexpr double tolerance = 0.0001;
+ const MarginStruct& margins = marginsWidget->margins();
+ const bool marginChanged = qAbs(margins.left() - m_originalMargins.left()) > tolerance ||
+ qAbs(margins.right() - m_originalMargins.right()) > tolerance ||
+ qAbs(margins.top() - m_originalMargins.top()) > tolerance ||
+ qAbs(margins.bottom() - m_originalMargins.bottom()) > tolerance;
+ const bool sizeChanged = qAbs(pageW - m_originalWidth) > tolerance ||
+ qAbs(pageH - m_originalHeight) > tolerance ||
+ pageOrientationComboBox->currentIndex() != m_originalOrientation;
+ const bool layoutChanged = pageLayoutButtonGroup->checkedId() != m_originalPositioning ||
+ bindingDirectionButtonGroup->checkedId() != m_originalBinding ||
+ layoutFirstPageIsComboBox->currentIndex() != m_originalFirstPage;
+ const bool sizeApplied = applySizesToAllPagesCheckBox->isChecked() || applySizesToAllMasterPagesCheckBox->isChecked();
+ const bool marginApplied = applyMarginsToAllPagesCheckBox->isChecked() || applyMarginsToAllMasterPagesCheckBox->isChecked();
+ const bool available = (sizeChanged && sizeApplied) || (marginChanged && marginApplied) || layoutChanged;
+ const QString toolTip = available
+ ? tr("Adapts frames aligned with the previous page margins to the new geometry.")
+ : tr("Available when page size, orientation, margins or page layout are changed.");
+ for (QCheckBox* check : {adaptFramesSizeCheckBox, adaptFramesMarginsCheckBox})
+ {
+ check->setEnabled(available);
+ check->setToolTip(toolTip);
+ QSignalBlocker blocker(check);
+ check->setChecked(available && m_adaptWanted);
+ }
+ adaptFramesSizeInfo->setVisible(available && m_adaptWanted);
+ adaptFramesMarginsInfo->setVisible(available && m_adaptWanted);
+}
+
void Prefs_DocumentSetup::changeAutoDocDir()
{
QString s = QFileDialog::getExistingDirectory(this, tr("Choose a Directory"), autosaveDirEdit->text());
Index: scribus/ui/preferences/prefs_documentsetup.h
===================================================================
--- scribus/ui/preferences/prefs_documentsetup.h (revision 27910)
+++ scribus/ui/preferences/prefs_documentsetup.h (working copy)
@@ -12,6 +12,7 @@
#include "prefs_pane.h"
#include "scribusapi.h"
#include "scribusstructs.h"
+#include "margins.h"
class ScribusDoc;
@@ -27,6 +28,8 @@
void saveGuiToPrefs(struct ApplicationPrefs *prefsData) const override;
void getResizeDocumentPages(bool &resizePages, bool &resizeMasterPages, bool &resizePageMargins, bool &resizeMasterPageMargins);
+ bool adaptMarginAlignedFrames() const;
+ void updateAdaptAvailability();
void setupPageSizes(struct ApplicationPrefs *prefsData);
public slots:
@@ -67,6 +70,16 @@
double pageW { 1.0 };
double pageH { 1.0 };
QString prefsPageSizeName;
+
+ // Initial values for this dialog session; adaptation is not a stored preference.
+ double m_originalWidth {0.0};
+ double m_originalHeight {0.0};
+ int m_originalOrientation {0};
+ int m_originalPositioning {0};
+ int m_originalBinding {0};
+ int m_originalFirstPage {0};
+ MarginStruct m_originalMargins;
+ bool m_adaptWanted {false};
QList<PageSet> pageSets;
signals:
Index: scribus/ui/preferences/prefs_documentsetupbase.ui
===================================================================
--- scribus/ui/preferences/prefs_documentsetupbase.ui (revision 27910)
+++ scribus/ui/preferences/prefs_documentsetupbase.ui (working copy)
@@ -207,6 +207,47 @@
</widget>
</item>
<item>
+ <widget class="QCheckBox" name="adaptFramesSizeCheckBox">
+ <property name="text">
+ <string>Adapt margin-aligned frames</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="adaptFramesSizeInfo">
+ <layout class="QHBoxLayout" name="adaptFramesSizeInfoLayout">
+ <property name="leftMargin">
+ <number>22</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item alignment="Qt::AlignTop">
+ <widget class="QLabel" name="adaptFramesSizeIcon"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="adaptFramesSizeNote">
+ <property name="text">
+ <string>Frame adaptation may alter text flow, line breaks and hyphenation. Review the layout for overflow and unintended changes.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
@@ -476,6 +517,47 @@
<property name="text">
<string>Apply changes to all master pages</string>
</property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="adaptFramesMarginsCheckBox">
+ <property name="text">
+ <string>Adapt margin-aligned frames</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="adaptFramesMarginsInfo">
+ <layout class="QHBoxLayout" name="adaptFramesMarginsInfoLayout">
+ <property name="leftMargin">
+ <number>22</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item alignment="Qt::AlignTop">
+ <widget class="QLabel" name="adaptFramesMarginsIcon"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="adaptFramesMarginsNote">
+ <property name="text">
+ <string>Frame adaptation may alter text flow, line breaks and hyphenation. Review the layout for overflow and unintended changes.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
<item>
|
|
|
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-10-16 07:59 | buttar | New Issue | |
| 2026-10-16 07:59 | buttar | File Added: fma2-margin-adaptation-foundation-v1.02.patch | |
| 2026-10-16 07:59 | buttar | File Added: fma3-adapt-frames-to-margins-v1.12.patch | |
| 2026-10-16 07:59 | buttar | File Added: fma4-preview-reporting-hardening-v1.16.patch | |
| 2026-10-16 07:59 | buttar | File Added: adapt-frames-dialog.png | |
| 2026-10-16 07:59 | buttar | File Added: keep-layout-or-adap-frames.png | |
| 2026-10-16 20:21 | cbradney | Target Version | => 1.8 Milestone |
| 2026-10-17 13:21 | ale | Note Added: 0054538 | |
| 2026-10-17 14:02 | buttar | Note Added: 0054540 | |
| 2026-10-17 15:21 | ale | Note Added: 0054542 | |
| 2026-10-18 03:54 | buttar | Note Added: 0054546 | |
| 2026-10-18 08:15 | ale | Note Added: 0054547 | |
| 2026-10-18 08:51 | buttar | Note Added: 0054548 | |
| 2026-10-18 11:45 | buttar | Note Added: 0054554 | |
| 2026-10-18 15:10 | ale | Note Added: 0054556 | |
| 2026-10-18 15:42 | buttar | Note Added: 0054558 | |
| 2026-10-22 13:06 | buttar | Note Added: 0054592 | |
| 2026-10-22 13:06 | buttar | File Added: fma2-margin-adaptation-foundation-v1.06.patch | |
| 2026-10-22 13:06 | buttar | File Added: fma3-adapt-frames-directly-v1.04.patch | |
| 2026-10-23 05:28 | buttar | Note Added: 0054601 | |
| 2026-10-23 05:28 | buttar | File Added: source2.sla | |
| 2026-10-23 05:28 | buttar | File Deleted: source2.sla | |
| 2026-10-29 17:09 | cbradney | Target Version | 1.8 Milestone => 1.7.5.svn |