0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00
LimeReport/limereport/items/lrpageeditor.cpp

116 lines
4.5 KiB
C++
Raw Normal View History

2022-06-13 21:18:57 +03:00
#include "lrpageeditor.h"
#include "ui_lrpageeditor.h"
2022-06-13 21:18:57 +03:00
#include "lrpagedesignintf.h"
2022-10-31 21:20:24 +03:00
#include "lrpageitemdesignintf.h"
2022-06-13 21:18:57 +03:00
#include <QPageSize>
#include <QPushButton>
2022-10-31 21:20:24 +03:00
namespace LimeReport {
PageEditor::PageEditor(QWidget* parent, LimeReport::PageItemDesignIntf* page):
2022-06-13 21:18:57 +03:00
QDialog(parent),
2022-11-01 11:48:47 +03:00
ui(new Ui::PageEditor)
2022-06-13 21:18:57 +03:00
{
ui->setupUi(this);
m_page = page;
// Paper
QMetaEnum pageSizes = page->metaObject()
->property(page->metaObject()->indexOfProperty("pageSize"))
.enumerator();
2022-06-13 21:18:57 +03:00
for (int i = 0; i < pageSizes.keyCount(); i++) {
2022-06-13 21:18:57 +03:00
ui->format->addItem(pageSizes.key(i));
}
ui->format->setCurrentIndex(m_page->pageSize());
2022-10-31 21:20:24 +03:00
ui->width->setValue(m_page->width() / m_page->unitFactor());
ui->height->setValue(m_page->height() / m_page->unitFactor());
2022-06-13 21:18:57 +03:00
ui->portrait->setChecked(m_page->pageOrientation() == LimeReport::PageItemDesignIntf::Portrait);
ui->landscape->setChecked(m_page->pageOrientation()
== LimeReport::PageItemDesignIntf::Landscape);
// Margins
2022-06-13 21:18:57 +03:00
ui->marginTop->setValue(m_page->topMargin());
ui->marginRight->setValue(m_page->rightMargin());
ui->marginLeft->setValue(m_page->leftMargin());
ui->marginBottom->setValue(m_page->bottomMargin());
ui->dropPrinterMargins->setChecked(m_page->dropPrinterMargins());
// Other
2022-06-13 21:18:57 +03:00
ui->endlessHeight->setChecked(m_page->endlessHeight());
ui->extendedHeight->setValue(m_page->extendedHeight());
ui->fullPage->setChecked(m_page->fullPage());
}
PageEditor::~PageEditor() { delete ui; }
2022-06-13 21:18:57 +03:00
2022-10-31 21:20:24 +03:00
void PageEditor::applyChanges()
2022-06-13 21:18:57 +03:00
{
m_page->setPageSize(
static_cast<LimeReport::PageItemDesignIntf::PageSize>(ui->format->currentIndex()));
2022-10-31 21:20:24 +03:00
m_page->setWidth(ui->width->value() * LimeReport::Const::mmFACTOR);
m_page->setHeight(ui->height->value() * LimeReport::Const::mmFACTOR);
m_page->setPageOrientation(ui->portrait->isChecked()
? LimeReport::PageItemDesignIntf::Portrait
: LimeReport::PageItemDesignIntf::Landscape);
2022-06-13 21:18:57 +03:00
m_page->setTopMargin(ui->marginTop->value());
m_page->setBottomMargin(ui->marginBottom->value());
m_page->setRightMargin(ui->marginRight->value());
m_page->setLeftMargin(ui->marginLeft->value());
m_page->setDropPrinterMargins(ui->dropPrinterMargins->isChecked());
ui->endlessHeight->setChecked(ui->endlessHeight->isChecked());
m_page->setExtendedHeight(ui->extendedHeight->value());
2022-10-31 21:20:24 +03:00
ui->width->setValue(m_page->getItemWidth());
ui->height->setValue(m_page->getItemHeight());
2022-06-13 21:18:57 +03:00
}
2022-10-31 21:20:24 +03:00
QSizeF PageEditor::getRectByPageSize(const LimeReport::PageItemDesignIntf::PageSize& size)
2022-06-13 21:18:57 +03:00
{
if (size != PageItemDesignIntf::Custom) {
2022-06-13 21:18:57 +03:00
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
printer.setOrientation(ui->portrait->isChecked() ? QPrinter::Portrait
: QPrinter::Landscape);
2022-06-13 21:18:57 +03:00
printer.setPaperSize((QPrinter::PageSize)size);
2022-10-31 21:20:24 +03:00
return QSizeF(printer.paperSize(QPrinter::Millimeter).width() * m_page->unitFactor(),
printer.paperSize(QPrinter::Millimeter).height() * m_page->unitFactor());
2022-06-13 21:18:57 +03:00
#else
2022-10-31 21:20:24 +03:00
printer.setPageOrientation((QPageLayout::Orientation)m_page->pageOrientation());
printer.setPageSize(QPageSize((QPageSize::PageSizeId)size));
return QSizeF(printer.pageLayout().pageSize().size(QPageSize::Millimeter).width()
* m_page->unitFactor(),
printer.pageLayout().pageSize().size(QPageSize::Millimeter).height()
* m_page->unitFactor());
2022-06-13 21:18:57 +03:00
#endif
2022-10-31 21:20:24 +03:00
} else {
return QSizeF(m_page->getItemWidth(), m_page->getItemHeight());
2022-06-13 21:18:57 +03:00
}
}
2022-11-01 11:48:47 +03:00
2022-10-31 21:20:24 +03:00
void PageEditor::on_format_currentIndexChanged(int index)
2022-06-13 21:18:57 +03:00
{
QPageSize ps = *new QPageSize();
if (ui->format->currentText() != "Custom") {
QSizeF pageSize
= getRectByPageSize(static_cast<LimeReport::PageItemDesignIntf::PageSize>(index));
2022-10-31 21:20:24 +03:00
ui->width->setValue(pageSize.width() / m_page->unitFactor());
ui->height->setValue(pageSize.height() / m_page->unitFactor());
}
}
void PageEditor::on_buttonBox_clicked(QAbstractButton* button)
2022-10-31 21:20:24 +03:00
{
switch (ui->buttonBox->buttonRole(button)) {
case QDialogButtonBox::ApplyRole:
applyChanges();
break;
case QDialogButtonBox::AcceptRole:
applyChanges();
accept();
2022-06-13 21:18:57 +03:00
}
}
} // namespace LimeReport