Skip to content

Commit e38cb42

Browse files
committed
feat(page_layout): lock aggregate size reference for matching (#85)
Add optional frozen aggregate hard size in Settings and a Margins panel checkbox so the match-size target does not jump when switching pages.
1 parent fe18144 commit e38cb42

5 files changed

Lines changed: 74 additions & 4 deletions

File tree

src/core/filters/page_layout/OptionsWidget.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void OptionsWidget::preUpdateUI(const PageInfo& pageInfo, const Margins& margins
8282
}
8383

8484
alignWithOthersCB->setChecked(!alignment.isNull());
85+
freezeAggregateHardSizeCb->setChecked(m_settings->isAggregateHardSizeFrozen());
8586

8687
if (alignment.horizontal() == Alignment::HAUTO) {
8788
hAlignmentModeCB->setCurrentIndex(0);
@@ -376,6 +377,11 @@ void OptionsWidget::matchSizeToAllPages() {
376377
emit aggregateHardSizeChanged();
377378
}
378379

380+
void OptionsWidget::freezeAggregateHardSizeToggled(const bool checked) {
381+
m_settings->setAggregateHardSizeFrozen(checked);
382+
emit aggregateHardSizeChanged();
383+
}
384+
379385
void OptionsWidget::updateMarginsDisplay() {
380386
auto block = m_connectionManager.getScopedBlock();
381387

@@ -444,6 +450,7 @@ void OptionsWidget::setupUiConnections() {
444450
CONNECT(alignWithOthersCB, SIGNAL(toggled(bool)), this, SLOT(alignWithOthersToggled()));
445451
CONNECT(applyAlignmentBtn, SIGNAL(clicked()), this, SLOT(showApplyAlignmentDialog()));
446452
CONNECT(matchSizeToAllBtn, SIGNAL(clicked()), this, SLOT(matchSizeToAllPages()));
453+
CONNECT(freezeAggregateHardSizeCb, SIGNAL(clicked(bool)), this, SLOT(freezeAggregateHardSizeToggled(bool)));
447454
for (const auto& kv : m_alignmentByButton) {
448455
CONNECT(kv.first, SIGNAL(clicked()), this, SLOT(alignmentButtonClicked()));
449456
}

src/core/filters/page_layout/OptionsWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class OptionsWidget : public FilterOptionsWidget, public UnitsListener, private
8989

9090
void matchSizeToAllPages();
9191

92+
void freezeAggregateHardSizeToggled(bool checked);
93+
9294
void onFixDpiClicked();
9395

9496
void applyMargins(const std::set<PageId>& pages,

src/core/filters/page_layout/OptionsWidget.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,16 @@ QToolButton:pressed {
717717
</item>
718718
</layout>
719719
</item>
720+
<item>
721+
<widget class="QCheckBox" name="freezeAggregateHardSizeCb">
722+
<property name="toolTip">
723+
<string>Keep the aggregate page size used for matching fixed while you switch pages, so the reference dimensions do not jump.</string>
724+
</property>
725+
<property name="text">
726+
<string>Lock aggregate size for matching</string>
727+
</property>
728+
</widget>
729+
</item>
720730
<item>
721731
<layout class="QHBoxLayout" name="horizontalLayout_6">
722732
<item>

src/core/filters/page_layout/Settings.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/multi_index/ordered_index.hpp>
1515
#include <boost/multi_index/sequenced_index.hpp>
1616
#include <boost/multi_index_container.hpp>
17+
#include <optional>
1718
#include <utility>
1819

1920
#include "AbstractRelinker.h"
@@ -146,8 +147,14 @@ class Settings::Impl {
146147

147148
QSizeF getAggregateHardSizeMMLocked() const;
148149

150+
QSizeF computeAggregateHardSizeMMLocked() const;
151+
149152
QSizeF getAggregateHardSizeMM(const PageId& pageId, const QSizeF& hardSizeMm, const Alignment& alignment) const;
150153

154+
void setAggregateHardSizeFrozen(bool frozen);
155+
156+
bool isAggregateHardSizeFrozen() const;
157+
151158
bool isPageAutoMarginsEnabled(const PageId& pageId);
152159

153160
void setPageAutoMarginsEnabled(const PageId& pageId, bool state);
@@ -199,6 +206,8 @@ class Settings::Impl {
199206
DeviationProvider<PageId> m_deviationProvider;
200207
std::vector<Guide> m_guides;
201208
bool m_showMiddleRect;
209+
210+
std::optional<QSizeF> m_frozenAggregateHardSizeMm;
202211
};
203212

204213

@@ -276,6 +285,14 @@ QSizeF Settings::getAggregateHardSizeMM(const PageId& pageId,
276285
return m_impl->getAggregateHardSizeMM(pageId, hardSizeMm, alignment);
277286
}
278287

288+
void Settings::setAggregateHardSizeFrozen(const bool frozen) {
289+
m_impl->setAggregateHardSizeFrozen(frozen);
290+
}
291+
292+
bool Settings::isAggregateHardSizeFrozen() const {
293+
return m_impl->isAggregateHardSizeFrozen();
294+
}
295+
279296
bool Settings::isPageAutoMarginsEnabled(const PageId& pageId) {
280297
return m_impl->isPageAutoMarginsEnabled(pageId);
281298
}
@@ -368,6 +385,7 @@ void Settings::Impl::clear() {
368385
const QMutexLocker locker(&m_mutex);
369386
m_items.clear();
370387
m_deviationProvider.clear();
388+
m_frozenAggregateHardSizeMm.reset();
371389
}
372390

373391
void Settings::Impl::performRelinking(const AbstractRelinker& relinker) {
@@ -586,7 +604,7 @@ QSizeF Settings::Impl::getAggregateHardSizeMM() const {
586604
return getAggregateHardSizeMMLocked();
587605
}
588606

589-
QSizeF Settings::Impl::getAggregateHardSizeMMLocked() const {
607+
QSizeF Settings::Impl::computeAggregateHardSizeMMLocked() const {
590608
if (m_items.empty()) {
591609
return QSizeF(0.0, 0.0);
592610
}
@@ -599,14 +617,38 @@ QSizeF Settings::Impl::getAggregateHardSizeMMLocked() const {
599617
return QSizeF(width, height);
600618
}
601619

620+
QSizeF Settings::Impl::getAggregateHardSizeMMLocked() const {
621+
if (m_frozenAggregateHardSizeMm) {
622+
return *m_frozenAggregateHardSizeMm;
623+
}
624+
return computeAggregateHardSizeMMLocked();
625+
}
626+
627+
void Settings::Impl::setAggregateHardSizeFrozen(const bool frozen) {
628+
const QMutexLocker locker(&m_mutex);
629+
if (frozen) {
630+
m_frozenAggregateHardSizeMm = computeAggregateHardSizeMMLocked();
631+
} else {
632+
m_frozenAggregateHardSizeMm.reset();
633+
}
634+
}
635+
636+
bool Settings::Impl::isAggregateHardSizeFrozen() const {
637+
const QMutexLocker locker(&m_mutex);
638+
return m_frozenAggregateHardSizeMm.has_value();
639+
}
640+
602641
QSizeF Settings::Impl::getAggregateHardSizeMM(const PageId& pageId,
603642
const QSizeF& hardSizeMm,
604643
const Alignment& alignment) const {
605-
if (alignment.isNull()) {
606-
return getAggregateHardSizeMM();
644+
const QMutexLocker locker(&m_mutex);
645+
if (m_frozenAggregateHardSizeMm) {
646+
return *m_frozenAggregateHardSizeMm;
607647
}
608648

609-
const QMutexLocker locker(&m_mutex);
649+
if (alignment.isNull()) {
650+
return computeAggregateHardSizeMMLocked();
651+
}
610652

611653
if (m_items.empty()) {
612654
return QSizeF(0.0, 0.0);

src/core/filters/page_layout/Settings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ class Settings {
141141
*/
142142
QSizeF getAggregateHardSizeMM(const PageId& pageId, const QSizeF& hardSizeMm, const Alignment& alignment) const;
143143

144+
/**
145+
* \brief When frozen, getAggregateHardSizeMM() returns a fixed reference size
146+
* until unfrozen, so the "match size" target does not change when
147+
* switching pages.
148+
*/
149+
void setAggregateHardSizeFrozen(bool frozen);
150+
151+
bool isAggregateHardSizeFrozen() const;
152+
144153
bool isPageAutoMarginsEnabled(const PageId& pageId);
145154

146155
void setPageAutoMarginsEnabled(const PageId& pageId, bool state);

0 commit comments

Comments
 (0)