Skip to content

Commit

Permalink
0.2024.08.22: margins: split into external and internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Aug 22, 2024
1 parent 98693e1 commit c270e0f
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/stages/page_layout/CacheDrivenTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CacheDrivenTask::process(

m_ptrNextTask->process(
page_info, adjusted_transform,
page_layout.innerRect(), page_layout.outerRect(), collector
page_layout.innerRect(), page_layout.extraRect(), collector
);
return;
}
Expand Down
22 changes: 15 additions & 7 deletions src/stages/page_layout/ImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ImageView::ImageView(
affine_transformed_image.xform().transform(),
affine_transformed_image.xform().transformedCropArea()
),
QMarginsF(5.0, 5.0, 5.0, 5.0)
QMarginsF(0.0, 0.0, 0.0, 0.0)
),
m_dragHandler(*this),
m_zoomHandler(*this),
Expand Down Expand Up @@ -312,11 +312,12 @@ ImageView::aggregateHardSizeChanged()
void
ImageView::onPaint(QPainter& painter, InteractionState const& interaction)
{
QRectF centerRectV = QRectF((m_outerRect.right() + m_outerRect.left()) * 0.5f, m_outerRect.top(), 0.0f, (m_outerRect.bottom() - m_outerRect.top()));
QRectF centerRectH = QRectF(m_outerRect.left(), (m_outerRect.bottom() + m_outerRect.top()) * 0.5f, (m_outerRect.right() - m_outerRect.left()), 0.0f);
QRectF centerRectV = QRectF((m_extraRect.right() + m_extraRect.left()) * 0.5f, m_extraRect.top(), 0.0f, (m_extraRect.bottom() - m_extraRect.top()));
QRectF centerRectH = QRectF(m_extraRect.left(), (m_extraRect.bottom() + m_extraRect.top()) * 0.5f, (m_extraRect.right() - m_extraRect.left()), 0.0f);

QPainterPath outer_outline;
outer_outline.addPolygon(m_outerRect);
// outer_outline.addPolygon(m_outerRect);
outer_outline.addPolygon(m_extraRect);

QPainterPath content_outline;
content_outline.addPolygon(m_innerRect);
Expand Down Expand Up @@ -632,6 +633,7 @@ ImageView::recalcBoxesAndFit(RelativeMargins const& margins)
m_innerRect = page_layout.innerRect();
m_middleRect = page_layout.middleRect();
m_outerRect = page_layout.outerRect();
m_extraRect = page_layout.extraRect();

AffineImageTransform scaled_transform(m_unscaledAffineTransform);
page_layout.absorbScalingIntoTransform(scaled_transform);
Expand All @@ -642,7 +644,7 @@ ImageView::recalcBoxesAndFit(RelativeMargins const& margins)

setZoomLevel(1.0);
updateTransformAndFixFocalPoint(
ImagePresentation(scaled_transform.transform(), m_outerRect),
ImagePresentation(scaled_transform.transform(), m_extraRect),
CENTER_IF_FITS
);
}
Expand All @@ -658,13 +660,13 @@ ImageView::updatePresentationTransform(FitMode const fit_mode)
{
if (fit_mode == DONT_FIT)
{
updateTransformPreservingScale(ImagePresentation(imageToVirtual(), m_outerRect));
updateTransformPreservingScale(ImagePresentation(imageToVirtual(), m_extraRect));
}
else
{
setZoomLevel(1.0);
updateTransformAndFixFocalPoint(
ImagePresentation(imageToVirtual(), m_outerRect), CENTER_IF_FITS
ImagePresentation(imageToVirtual(), m_extraRect), CENTER_IF_FITS
);
}
}
Expand Down Expand Up @@ -725,6 +727,12 @@ ImageView::recalcOuterRect()
-soft_margins.left(), -soft_margins.top(),
soft_margins.right(), soft_margins.bottom()
);

float const basew = m_outerRect.width();
float const baseh = m_outerRect.height();
float const extraw = basew * 0.08f;
float const extrah = baseh * 0.08f;
m_extraRect = m_outerRect.adjusted(-extraw, -extrah, extraw, extrah);
}

ImageView::AggregateSizeChanged
Expand Down
1 change: 1 addition & 0 deletions src/stages/page_layout/ImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public slots:
* size with other pages.
*/
QRectF m_outerRect;
QRectF m_extraRect;

/**
* \brief Aggregate (max_width, max_height) hard page size in pixels.
Expand Down
3 changes: 2 additions & 1 deletion src/stages/page_layout/OptionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace page_layout
OptionsWidget::OptionsWidget(
IntrusivePtr<Settings> const& settings,
PageSelectionAccessor const& page_selection_accessor)
: m_ptrSettings(settings),
: m_ptrSettings(settings),
m_pageSelectionAccessor(page_selection_accessor),
m_ignoreMarginChanges(0),
m_ignoreMatchSizeModeChanges(0),
Expand Down Expand Up @@ -421,6 +421,7 @@ OptionsWidget::updateMarginsDisplay()
{
ScopedIncDec<int> const ignore_scope(m_ignoreMarginChanges);

bottomMarginSpinBox->setValue(m_margins.bottom() * 100.0);
topMarginSpinBox->setValue(m_margins.top() * 100.0);
bottomMarginSpinBox->setValue(m_margins.bottom() * 100.0);
leftMarginSpinBox->setValue(m_margins.left() * 100.0);
Expand Down
11 changes: 11 additions & 0 deletions src/stages/page_layout/PageLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class PageLayout
return m_outerRect;
}

QRectF const extraRect() const
{
float const basew = m_outerRect.width();
float const baseh = m_outerRect.height();
float const extraw = basew * 0.08f;
float const extrah = baseh * 0.08f;
QRectF const extra = m_outerRect.adjusted(-extraw, -extrah, extraw, extrah);

return extra;
}

/**
* If match_size_mode passed into the constructor was set to SCALE,
* the 3 rectangles already incorporate the appropriate scaling factor.
Expand Down
2 changes: 1 addition & 1 deletion src/stages/page_layout/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Settings : public RefCountable

static RelativeMargins defaultHardMargins()
{
return RelativeMargins(0.05, 0.05, 0.05, 0.05);
return RelativeMargins(0.0, 0.0, 0.0, 0.0);
}

Settings();
Expand Down
2 changes: 1 addition & 1 deletion src/stages/page_layout/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Task::process(

return m_ptrNextTask->process(
status, accel_ops, orig_image, gray_orig_image_factory, adjusted_transform,
page_layout.innerRect(), page_layout.outerRect()
page_layout.innerRect(), page_layout.extraRect()
);
}
else if (m_ptrFilter->optionsWidget())
Expand Down
5 changes: 3 additions & 2 deletions src/stages/page_layout/Thumbnail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Thumbnail::Thumbnail(
AbstractImageTransform const& full_size_image_transform, PageLayout const& page_layout)
: ThumbnailBase(
thumbnail_cache, max_display_size, page_id,
full_size_image_transform, page_layout.outerRect()
full_size_image_transform, page_layout.extraRect()
)
, m_params(params)
, m_pageLayout(page_layout)
Expand All @@ -59,6 +59,7 @@ Thumbnail::paintOverImage(

QRectF const inner_rect(transformed_to_display.mapRect(m_pageLayout.innerRect()));
QRectF const outer_rect(transformed_to_display.mapRect(m_pageLayout.outerRect()));
QRectF const extra_rect(transformed_to_display.mapRect(m_pageLayout.extraRect()));

// Fill the transparent (that is not covered by the thumbnail) portions
// of outer_rect with "window" color. That's done because we are going to
Expand All @@ -67,7 +68,7 @@ Thumbnail::paintOverImage(
// which is typically of dark color. Introducing the "window" color
// in those areas will make margins more visible.
painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
painter.fillRect(outer_rect, qApp->palette().window());
painter.fillRect(extra_rect, qApp->palette().window());

QPainterPath outer_outline;
outer_outline.addPolygon(outer_rect);
Expand Down
79 changes: 69 additions & 10 deletions src/stages/page_layout/ui/PageLayoutOptionsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,73 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="labelExtra">
<property name="text">
<string>Extra</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="extraWMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.0</double>
</property>
<property name="maximum">
<double>999.5</double>
</property>
<property name="singleStep">
<double>0.5</double>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labelExtraW">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="extraHMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.0</double>
</property>
<property name="maximum">
<double>999.5</double>
</property>
<property name="singleStep">
<double>0.5</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="labelExtraH">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Top</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="topMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
Expand All @@ -63,7 +122,7 @@
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<item row="2" column="2" rowspan="2">
<widget class="QToolButton" name="topBottomLink">
<property name="minimumSize">
<size>
Expand All @@ -90,14 +149,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Bottom</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="bottomMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
Expand All @@ -116,14 +175,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="leftMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
Expand All @@ -142,7 +201,7 @@
</property>
</widget>
</item>
<item row="2" column="2" rowspan="2">
<item row="4" column="2" rowspan="2">
<widget class="QToolButton" name="leftRightLink">
<property name="minimumSize">
<size>
Expand Down Expand Up @@ -172,14 +231,14 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="rightMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#define SCANTAILOR_VERSION_H_

#define STFAMILY "experimental"
#define VERSION "0.2024.08.21" // Must be "x.x.x.x" or an empty string.
#define VERSION "0.2024.08.22" // Must be "x.x.x.x" or an empty string.

#endif

0 comments on commit c270e0f

Please sign in to comment.