mirror of https://github.com/status-im/qzxing.git
Merge pull request #95 from igniti-gmbh/imageprovider-size
Always respect requestedSize in QZXingImageProvider
This commit is contained in:
commit
352a77f4ae
|
@ -10,7 +10,8 @@ QZXingImageProvider::QZXingImageProvider() : QQuickImageProvider(QQuickImageProv
|
||||||
QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
||||||
{
|
{
|
||||||
int slashIndex = id.indexOf('/');
|
int slashIndex = id.indexOf('/');
|
||||||
if (slashIndex == -1) {
|
if (slashIndex == -1)
|
||||||
|
{
|
||||||
qWarning() << "Can't parse url" << id << ". Usage is encode?<format>/<data>";
|
qWarning() << "Can't parse url" << id << ". Usage is encode?<format>/<data>";
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
|
@ -23,15 +24,11 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
int customSettingsIndex = id.lastIndexOf('?');
|
|
||||||
|
|
||||||
QString data;
|
QString data;
|
||||||
QImage result;
|
QZXing::EncoderFormat format = QZXing::EncoderFormat_QR_CODE;
|
||||||
QString corretionLevel;
|
QZXing::EncodeErrorCorrectionLevel correctionLevel = QZXing::EncodeErrorCorrectionLevel_L;
|
||||||
QString format;
|
|
||||||
QZXing::EncodeErrorCorrectionLevel correctionLevelEnum =
|
|
||||||
QZXing::EncodeErrorCorrectionLevel_L;
|
|
||||||
|
|
||||||
|
int customSettingsIndex = id.lastIndexOf('?');
|
||||||
if(customSettingsIndex >= 0)
|
if(customSettingsIndex >= 0)
|
||||||
{
|
{
|
||||||
int startOfDataIndex = slashIndex + 1;
|
int startOfDataIndex = slashIndex + 1;
|
||||||
|
@ -41,37 +38,28 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
|
||||||
// it could not recognize the first key-value pair provided
|
// it could not recognize the first key-value pair provided
|
||||||
QUrlQuery optionQuery("options?dummy=&" + id.mid(customSettingsIndex + 1));
|
QUrlQuery optionQuery("options?dummy=&" + id.mid(customSettingsIndex + 1));
|
||||||
|
|
||||||
corretionLevel = optionQuery.queryItemValue("corretionLevel");
|
QString correctionLevelString = optionQuery.queryItemValue("corretionLevel");
|
||||||
format = optionQuery.queryItemValue("format");
|
QString formatString = optionQuery.queryItemValue("format");
|
||||||
|
if(formatString != "qrcode")
|
||||||
if(corretionLevel == "H")
|
|
||||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_H;
|
|
||||||
else if(corretionLevel == "Q")
|
|
||||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_Q;
|
|
||||||
else if(corretionLevel == "M")
|
|
||||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_M;
|
|
||||||
else if(corretionLevel == "L")
|
|
||||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_L;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!corretionLevel.isEmpty() || !format.isEmpty())
|
|
||||||
{
|
|
||||||
if(format != "qrcode")
|
|
||||||
{
|
{
|
||||||
qWarning() << "Format not supported: " << format;
|
qWarning() << "Format not supported: " << formatString;
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
result = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE,
|
if(correctionLevelString == "H")
|
||||||
requestedSize,
|
correctionLevel = QZXing::EncodeErrorCorrectionLevel_H;
|
||||||
correctionLevelEnum);
|
else if(correctionLevelString == "Q")
|
||||||
}
|
correctionLevel = QZXing::EncodeErrorCorrectionLevel_Q;
|
||||||
else
|
else if(correctionLevelString == "M")
|
||||||
|
correctionLevel = QZXing::EncodeErrorCorrectionLevel_M;
|
||||||
|
else if(correctionLevelString == "L")
|
||||||
|
correctionLevel = QZXing::EncodeErrorCorrectionLevel_L;
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
data = id.mid(slashIndex + 1);
|
data = id.mid(slashIndex + 1);
|
||||||
result = QZXing::encodeData(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage result = QZXing::encodeData(data, format, requestedSize, correctionLevel);
|
||||||
*size = result.size();
|
*size = result.size();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue