Skip to content

Commit

Permalink
0.2024.08.10: margins: modify RelativeMargins for base size
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Aug 10, 2024
1 parent 56b068b commit cb736af
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 29 deletions.
57 changes: 48 additions & 9 deletions src/foundation/RelativeMargins.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,52 @@
class FOUNDATION_EXPORT RelativeMargins
{
public:
RelativeMargins() : m_top(), m_bottom(), m_left(), m_right() {}
RelativeMargins() : m_top(), m_bottom(), m_left(), m_right(), m_base() {}

RelativeMargins(double left, double top, double right, double bottom)
: m_top(top), m_bottom(bottom), m_left(left), m_right(right) {}
RelativeMargins(double left, double top, double right, double bottom, double base = 0.0)
: m_top(top), m_bottom(bottom), m_left(left), m_right(right), m_base(base) {}

double getBaseRect(QRectF const& rect) const
{
double scale;
if (m_base > 0.0)
{
scale = m_base;
}
else
{
double const scalex = rect.width();
double const scaley = rect.height() * 0.7071067811865475244;
scale = (scalex < scaley) ? scaley : scalex;
}
return scale;
}

QRectF extendContentRect(QRectF const& rect) const
{
double const scalex = rect.width();
double const scaley = rect.height() * 0.7071067811865475244;
double const scale = (scalex < scaley) ? scaley : scalex;
double const scale = getBaseRect(rect);
return rect.adjusted(-m_left * scale, -m_top * scale, m_right * scale, m_bottom * scale);
}

double getBaseSize(QSizeF const& size) const
{
double scale;
if (m_base > 0.0)
{
scale = m_base;
}
else
{
double const scalex = size.width();
double const scaley = size.height() * 0.7071067811865475244;
scale = (scalex < scaley) ? scaley : scalex;
}
return scale;
}

QSizeF extendContentSize(QSizeF const& size) const
{
double const scalex = size.width();
double const scaley = size.height() * 0.7071067811865475244;
double const scale = (scalex < scaley) ? scaley : scalex;
double const scale = getBaseSize(size);
return QSizeF(
size.width() + (m_left + m_right) * scale,
size.height() + (m_top + m_bottom) * scale
Expand Down Expand Up @@ -96,6 +124,16 @@ class FOUNDATION_EXPORT RelativeMargins
m_right = val;
}

double getBase() const
{
return m_base;
}

void setBase(double val)
{
m_base = val;
}

bool horizontalMarginsApproxEqual() const
{
return std::lround(std::abs(m_right - m_left) * 100.0) == 0;
Expand All @@ -110,6 +148,7 @@ class FOUNDATION_EXPORT RelativeMargins
double m_bottom;
double m_left;
double m_right;
double m_base;
};

#endif
38 changes: 19 additions & 19 deletions src/stages/page_layout/ui/PageLayoutOptionsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="topMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-49.5</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" rowspan="2">
<widget class="QToolButton" name="topBottomLink">
<property name="minimumSize">
Expand Down Expand Up @@ -179,25 +198,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="topMarginSpinBox">
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-49.5</double>
</property>
<property name="maximum">
<double>999.5</double>
</property>
<property name="singleStep">
<double>0.5</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
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.08" // Must be "x.x.x.x" or an empty string.
#define VERSION "0.2024.08.10" // Must be "x.x.x.x" or an empty string.

#endif

0 comments on commit cb736af

Please sign in to comment.