2020-10-06 21:41:23 +02:00
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include "units.h"
|
|
|
|
#include "marginswidget.h"
|
|
|
|
|
|
|
|
MarginsWidget::MarginsWidget(QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
_top = new QSpinBox();
|
|
|
|
_bottom = new QSpinBox();
|
|
|
|
_left = new QSpinBox();
|
|
|
|
_right = new QSpinBox();
|
|
|
|
|
2020-10-07 00:23:24 +02:00
|
|
|
_top->setMaximumWidth(_top->sizeHint().width());
|
|
|
|
_bottom->setMaximumWidth(_bottom->sizeHint().width());
|
|
|
|
_left->setMaximumWidth(_left->sizeHint().width());
|
|
|
|
_right->setMaximumWidth(_right->sizeHint().width());
|
|
|
|
|
2020-10-06 21:41:23 +02:00
|
|
|
QGridLayout *layout = new QGridLayout();
|
|
|
|
layout->addWidget(_top, 0, 0, 1, 2, Qt::AlignCenter);
|
|
|
|
layout->addWidget(_left, 1, 0, 1, 1, Qt::AlignRight);
|
|
|
|
layout->addWidget(_right, 1, 1, 1, 1, Qt::AlignLeft);
|
|
|
|
layout->addWidget(_bottom, 2, 0, 1, 2, Qt::AlignCenter);
|
|
|
|
|
2020-10-07 00:23:24 +02:00
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2020-10-06 21:41:23 +02:00
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarginsWidget::setValue(const QMargins &value)
|
|
|
|
{
|
|
|
|
_top->setValue(value.top());
|
|
|
|
_bottom->setValue(value.bottom());
|
|
|
|
_left->setValue(value.left());
|
|
|
|
_right->setValue(value.right());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarginsWidget::setUnits(const QString &units)
|
|
|
|
{
|
|
|
|
_top->setSuffix(UNIT_SPACE + units);
|
|
|
|
_bottom->setSuffix(UNIT_SPACE + units);
|
|
|
|
_left->setSuffix(UNIT_SPACE + units);
|
|
|
|
_right->setSuffix(UNIT_SPACE + units);
|
2020-10-07 08:57:24 +02:00
|
|
|
|
|
|
|
_top->setMaximumWidth(_top->sizeHint().width());
|
|
|
|
_bottom->setMaximumWidth(_bottom->sizeHint().width());
|
|
|
|
_left->setMaximumWidth(_left->sizeHint().width());
|
|
|
|
_right->setMaximumWidth(_right->sizeHint().width());
|
2020-10-06 21:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QMargins MarginsWidget::value() const
|
|
|
|
{
|
|
|
|
return QMargins(_left->value(), _top->value(), _right->value(),
|
|
|
|
_bottom->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MarginsFWidget::MarginsFWidget(QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
_top = new QDoubleSpinBox();
|
|
|
|
_bottom = new QDoubleSpinBox();
|
|
|
|
_left = new QDoubleSpinBox();
|
|
|
|
_right = new QDoubleSpinBox();
|
|
|
|
|
2020-10-07 00:23:24 +02:00
|
|
|
_top->setMaximumWidth(_top->sizeHint().width());
|
|
|
|
_bottom->setMaximumWidth(_bottom->sizeHint().width());
|
|
|
|
_left->setMaximumWidth(_left->sizeHint().width());
|
|
|
|
_right->setMaximumWidth(_right->sizeHint().width());
|
|
|
|
|
2020-10-06 21:41:23 +02:00
|
|
|
QGridLayout *layout = new QGridLayout();
|
|
|
|
layout->addWidget(_top, 0, 0, 1, 2, Qt::AlignCenter);
|
|
|
|
layout->addWidget(_left, 1, 0, 1, 1, Qt::AlignRight);
|
|
|
|
layout->addWidget(_right, 1, 1, 1, 1, Qt::AlignLeft);
|
|
|
|
layout->addWidget(_bottom, 2, 0, 1, 2, Qt::AlignCenter);
|
|
|
|
|
2020-10-07 00:23:24 +02:00
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2020-10-06 21:41:23 +02:00
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
void MarginsFWidget::setValue(const QMarginsF &value)
|
2020-10-06 21:41:23 +02:00
|
|
|
{
|
|
|
|
_top->setValue(value.top());
|
|
|
|
_bottom->setValue(value.bottom());
|
|
|
|
_left->setValue(value.left());
|
|
|
|
_right->setValue(value.right());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarginsFWidget::setUnits(const QString &units)
|
|
|
|
{
|
|
|
|
_top->setSuffix(UNIT_SPACE + units);
|
|
|
|
_bottom->setSuffix(UNIT_SPACE + units);
|
|
|
|
_left->setSuffix(UNIT_SPACE + units);
|
|
|
|
_right->setSuffix(UNIT_SPACE + units);
|
2020-10-07 08:57:24 +02:00
|
|
|
|
|
|
|
_top->setMaximumWidth(_top->sizeHint().width());
|
|
|
|
_bottom->setMaximumWidth(_bottom->sizeHint().width());
|
|
|
|
_left->setMaximumWidth(_left->sizeHint().width());
|
|
|
|
_right->setMaximumWidth(_right->sizeHint().width());
|
2020-10-06 21:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MarginsFWidget::setSingleStep(qreal step)
|
|
|
|
{
|
|
|
|
_top->setSingleStep(step);
|
|
|
|
_bottom->setSingleStep(step);
|
|
|
|
_left->setSingleStep(step);
|
|
|
|
_right->setSingleStep(step);
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
QMarginsF MarginsFWidget::value() const
|
2020-10-06 21:41:23 +02:00
|
|
|
{
|
2020-12-22 22:09:09 +01:00
|
|
|
return QMarginsF(_left->value(), _top->value(), _right->value(),
|
2020-10-06 21:41:23 +02:00
|
|
|
_bottom->value());
|
|
|
|
}
|