XFA: numeric edit, barcode edit

This commit is contained in:
Jakub Melka 2022-01-02 17:27:22 +01:00
parent bae777062e
commit 17bf0a7926
1 changed files with 95 additions and 7 deletions

View File

@ -9792,6 +9792,13 @@ private:
size_t paragraphSettingsIndex,
QPainter* painter);
void drawUiNumericEdit(const xfa::XFA_numericEdit* numericEdit,
const NodeValue& value,
QList<PDFRenderError>& errors,
QRectF nominalExtentArea,
size_t paragraphSettingsIndex,
QPainter* painter);
void drawUiPasswordEdit(const xfa::XFA_passwordEdit* passwordEdit,
const NodeValue& value,
QList<PDFRenderError>& errors,
@ -9804,6 +9811,11 @@ private:
QRectF nominalExtentArea,
QPainter* painter);
void drawUiBarcode(const xfa::XFA_barcode* barcode,
QList<PDFRenderError>& errors,
QRectF nominalExtentArea,
QPainter* painter);
void drawUiCheckButton(const xfa::XFA_checkButton* checkButton,
const NodeValue& value,
QRectF nominalExtentArea,
@ -11828,10 +11840,18 @@ void PDFXFAEngineImpl::drawItemValue(const xfa::XFA_value* value,
{
drawUi(ui, nodeValue.value(), errors, nominalContentArea, paragraphSettingsIndex, painter);
}
else
{
drawUi(ui, NodeValue(), errors, nominalContentArea, paragraphSettingsIndex, painter);
}
// TODO: implement draw arc (getArc())
// TODO: implement draw value
}
else
{
drawUi(ui, NodeValue(), errors, nominalContentArea, paragraphSettingsIndex, painter);
}
}
void PDFXFAEngineImpl::drawItemDraw(const xfa::XFA_draw* item,
@ -11973,11 +11993,6 @@ void PDFXFAEngineImpl::drawUi(const xfa::XFA_ui* ui,
size_t paragraphSettingsIndex,
QPainter* painter)
{
if (!value.value.isValid())
{
return;
}
const xfa::XFA_barcode* barcode = nullptr;
const xfa::XFA_button* button = nullptr;
const xfa::XFA_checkButton* checkButton = nullptr;
@ -11992,14 +12007,14 @@ void PDFXFAEngineImpl::drawUi(const xfa::XFA_ui* ui,
if (ui)
{
barcode = ui->getBarcode(); // TODO: implement
barcode = ui->getBarcode();
button = ui->getButton(); // TODO: implement
checkButton = ui->getCheckButton();
choiceList = ui->getChoiceList(); // TODO: implement
dateTimeEdit = ui->getDateTimeEdit(); // TODO: implement
defaultUi = ui->getDefaultUi();
imageEdit = ui->getImageEdit();
numericEdit = ui->getNumericEdit(); // TODO: implement
numericEdit = ui->getNumericEdit();
passwordEdit = ui->getPasswordEdit();
signature = ui->getSignature();
textEdit = ui->getTextEdit();
@ -12022,6 +12037,10 @@ void PDFXFAEngineImpl::drawUi(const xfa::XFA_ui* ui,
{
drawUiImageEdit(imageEdit, value, errors, nominalExtentArea, painter);
}
else if (numericEdit || (isDefaultUi && value.value.type() == QVariant::Double))
{
drawUiNumericEdit(numericEdit, value, errors, nominalExtentArea, paragraphSettingsIndex, painter);
}
else if (signature)
{
drawUiSignature(signature, errors, nominalExtentArea, painter);
@ -12030,6 +12049,10 @@ void PDFXFAEngineImpl::drawUi(const xfa::XFA_ui* ui,
{
drawUiPasswordEdit(passwordEdit, value, errors, nominalExtentArea, paragraphSettingsIndex, painter);
}
else if (barcode)
{
drawUiBarcode(barcode, errors, nominalExtentArea, painter);
}
// TODO: implement all ui
}
@ -12176,6 +12199,59 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
}
}
void PDFXFAEngineImpl::drawUiNumericEdit(const xfa::XFA_numericEdit* numericEdit,
const NodeValue& value,
QList<PDFRenderError>& errors,
QRectF nominalExtentArea,
size_t paragraphSettingsIndex,
QPainter* painter)
{
QRectF nominalExtent = nominalExtentArea;
QRectF nominalContentArea = nominalExtent;
QMarginsF contentMargins = numericEdit ? createMargin(numericEdit->getMargin()) : QMarginsF();
nominalContentArea = nominalExtent.marginsRemoved(contentMargins);
if (numericEdit && numericEdit->getBorder())
{
drawItemBorder(numericEdit->getBorder(), errors, nominalExtentArea, painter);
}
QString text;
if (value.hintFloatFracDigits != -1)
{
text = QString::number(value.value.toDouble(), 'f', value.hintFloatFracDigits);
}
else
{
text = QString::number(value.value.toDouble());
}
if (value.hintFloatLeadDigits != -1)
{
int leadLength = text.indexOf('.');
if (leadLength == -1)
{
leadLength = text.length();
}
while (leadLength < value.hintFloatLeadDigits)
{
++leadLength;
text.prepend('0');
}
}
const xfa::XFA_ParagraphSettings& settings = m_layout.paragraphSettings.at(paragraphSettingsIndex);
painter->setFont(settings.getFont());
int textFlag = int(settings.getAlignment()) | Qt::TextDontClip | Qt::TextSingleLine;
QRectF textRect = nominalContentArea;
textRect = textRect.marginsRemoved(settings.getMargins());
painter->drawText(textRect, textFlag, value.value.toString());
}
void PDFXFAEngineImpl::drawUiPasswordEdit(const xfa::XFA_passwordEdit* passwordEdit,
const NodeValue& value,
QList<PDFRenderError>& errors,
@ -12229,6 +12305,18 @@ void PDFXFAEngineImpl::drawUiSignature(const xfa::XFA_signature* signature,
painter->drawLine(nominalContentArea.bottomLeft(), nominalContentArea.bottomRight());
}
void PDFXFAEngineImpl::drawUiBarcode(const xfa::XFA_barcode* barcode,
QList<PDFRenderError>& errors,
QRectF nominalExtentArea,
QPainter* painter)
{
Q_UNUSED(barcode);
Q_UNUSED(nominalExtentArea);
Q_UNUSED(painter);
errors << PDFRenderError(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Barcode not implemented!"));
}
void PDFXFAEngineImpl::drawUiCheckButton(const xfa::XFA_checkButton* checkButton,
const NodeValue& value,
QRectF nominalExtentArea,