QPrintPreviewDialog: Improve i18n for percent value

This fixes the initial percent value being in the wrong format
for languages that have a different format set. Also enables
locale-aware decimals separator.

Change-Id: I77db487635284e58ed47ed3807fe4390d8d97123
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Emir SARI 2025-03-15 22:35:47 +03:00
parent 1e10ede244
commit bfb7a47e13

View File

@ -141,6 +141,7 @@ public:
void layoutPages(); void layoutPages();
void setupActions(); void setupActions();
void updateNavActions(); void updateNavActions();
QString formattedZoomFactor(double value);
void setFitting(bool on); void setFitting(bool on);
bool isFitting(); bool isFitting();
void updatePageNumLabel(); void updatePageNumLabel();
@ -223,7 +224,7 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
zoomFactor->setLineEdit(zoomEditor); zoomFactor->setLineEdit(zoomEditor);
static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 }; static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 };
for (auto factorX2 : factorsX2) for (auto factorX2 : factorsX2)
zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorX2 / 2.0)); zoomFactor->addItem(formattedZoomFactor(factorX2 / 2.0));
QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()), QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()),
q, SLOT(_q_zoomFactorChanged())); q, SLOT(_q_zoomFactorChanged()));
QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)), QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)),
@ -436,6 +437,12 @@ void QPrintPreviewDialogPrivate::setFitting(bool on)
} }
} }
QString QPrintPreviewDialogPrivate::formattedZoomFactor(double value)
{
//: Zoom factor percentage value, % is the percent sign
return QPrintPreviewDialog::tr("%1%").arg(QLocale().toString(value, 'f', 1));
}
void QPrintPreviewDialogPrivate::updateNavActions() void QPrintPreviewDialogPrivate::updateNavActions()
{ {
int curPage = preview->currentPage(); int curPage = preview->currentPage();
@ -464,7 +471,7 @@ void QPrintPreviewDialogPrivate::updatePageNumLabel()
void QPrintPreviewDialogPrivate::updateZoomFactor() void QPrintPreviewDialogPrivate::updateZoomFactor()
{ {
zoomFactor->lineEdit()->setText(QString::asprintf("%.1f%%", preview->zoomFactor()*100)); zoomFactor->lineEdit()->setText(formattedZoomFactor(preview->zoomFactor() * 100));
} }
void QPrintPreviewDialogPrivate::_q_fit(QAction* action) void QPrintPreviewDialogPrivate::_q_fit(QAction* action)
@ -601,7 +608,7 @@ void QPrintPreviewDialogPrivate::_q_zoomFactorChanged()
factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor)); factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor));
if (ok) { if (ok) {
preview->setZoomFactor(factor/100.0); preview->setZoomFactor(factor/100.0);
zoomFactor->setEditText(QString::fromLatin1("%1%").arg(factor)); zoomFactor->setEditText(formattedZoomFactor(factor));
setFitting(false); setFitting(false);
} }
} }