mirror of https://github.com/status-im/qzxing.git
Updated QZXingImageProvider::requestImage implementation to:
- fix bug when '?' is included without correct definition of options - utilize requestedSize for the generated barcode Updated README.md file to reflect changes.
This commit is contained in:
parent
34fb8daa82
commit
9c361587a4
12
README.md
12
README.md
|
@ -204,15 +204,14 @@ Image{
|
|||
}
|
||||
```
|
||||
|
||||
Or use the encoding function with custom settings that are passed like URL query parameters:
|
||||
Or use the encoding function with the optional custom settings that are passed like URL query parameters:
|
||||
|
||||
| attribute name | value | description |
|
||||
| -------------- | ---------- | --------------------------------------------- |
|
||||
| width | int | width in pixels |
|
||||
| height | int | height in pixels |
|
||||
| corretionLevel | L, M, Q, H | the error correction level |
|
||||
| format | qrcode | the encode formatter. Currently only QR Code. |
|
||||
|
||||
the size of the image can be adjusted by using the Image.sourceWidth and Image.sourceHeight properties of Image QML element.
|
||||
|
||||
```qml
|
||||
import QZXing 2.3
|
||||
|
@ -224,11 +223,10 @@ TextField {
|
|||
|
||||
Image{
|
||||
source: "image://QZXing/encode/" + inputField.text +
|
||||
"?width=250" +
|
||||
"&height=250" +
|
||||
"&corretionLevel=M" +
|
||||
"?corretionLevel=M" +
|
||||
"&format=qrcode"
|
||||
cache: false;
|
||||
sourceSize.width: 320
|
||||
sourceSize.height: 320
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ ApplicationWindow {
|
|||
|
||||
minimumWidth: formatGroupBox.width +
|
||||
errorCorrectionlevelGroupBox.width +
|
||||
sizeGroupBox.width +
|
||||
6 * advancedOptions.spacing
|
||||
5 * advancedOptions.spacing
|
||||
|
||||
property bool isAdvancedOptionsEnabled: advancedSwitch.position;
|
||||
|
||||
|
@ -76,57 +75,33 @@ ApplicationWindow {
|
|||
model: ["L", "M", "Q", "H"]
|
||||
}
|
||||
}
|
||||
|
||||
GroupBox {
|
||||
id: sizeGroupBox
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
title: "Size"
|
||||
GridLayout {
|
||||
RadioButton {
|
||||
id: radioButtonSize120
|
||||
text: "120x120"
|
||||
}
|
||||
RadioButton {
|
||||
id: radioButtonSize240
|
||||
checked: true
|
||||
text: "240x240"
|
||||
}
|
||||
RadioButton {
|
||||
id: radioButtonSize320
|
||||
text: "320x320"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: barcodeRectangle
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
border.width: 1
|
||||
border.color: "#bdbebf"
|
||||
clip: true
|
||||
|
||||
property int imageWidth: Math.min(height, width) * 0.7;
|
||||
|
||||
Image{
|
||||
id:resultImage
|
||||
anchors.centerIn: parent
|
||||
sourceSize.width: barcodeRectangle.imageWidth
|
||||
sourceSize.height: barcodeRectangle.imageWidth
|
||||
|
||||
source: mainLayout.getImageRequestString()
|
||||
cache: false;
|
||||
//cache: false;
|
||||
}
|
||||
}
|
||||
|
||||
function getImageRequestString() {
|
||||
if(mainWindow.isAdvancedOptionsEnabled) {
|
||||
var width;
|
||||
var height;
|
||||
if (radioButtonSize120.checked) {width = "120"; height = "120"}
|
||||
else if (radioButtonSize240.checked) {width = "240"; height = "240"}
|
||||
else if (radioButtonSize320.checked) {width = "320"; height = "320"}
|
||||
|
||||
return "image://QZXing/encode/" + inputField.text +
|
||||
"?width="+width+
|
||||
"&height="+height+
|
||||
"&corretionLevel=" + errorCorrectionlevelCombo.currentText +
|
||||
"?corretionLevel=" + errorCorrectionlevelCombo.currentText +
|
||||
"&format=" + formatCombo.currentText
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
TEMPLATE = app
|
||||
|
||||
QT += qml quick
|
||||
|
||||
CONFIG += c++11 qzxing_multimedia
|
||||
|
||||
CONFIG(debug, debug|release) {
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/>
|
||||
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="24"/>
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
|
||||
|
|
|
@ -23,49 +23,48 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
|
|||
return QImage();
|
||||
}
|
||||
|
||||
int optionAreaIndex = id.lastIndexOf('?');
|
||||
int customSettingsIndex = id.lastIndexOf('?');
|
||||
|
||||
QString data;
|
||||
QImage result;
|
||||
if(optionAreaIndex >= 0)
|
||||
QString corretionLevel;
|
||||
QString format;
|
||||
QZXing::EncodeErrorCorrectionLevel correctionLevelEnum =
|
||||
QZXing::EncodeErrorCorrectionLevel_L;
|
||||
|
||||
if(customSettingsIndex >= 0)
|
||||
{
|
||||
int startOfDataIndex = slashIndex + 1;
|
||||
data = id.mid(startOfDataIndex, optionAreaIndex - (startOfDataIndex));
|
||||
data = id.mid(startOfDataIndex, customSettingsIndex - (startOfDataIndex));
|
||||
|
||||
//The dummy option has been added due to a bug(?) of QUrlQuery
|
||||
// it could not recognize the first key-value pair provided
|
||||
QUrlQuery optionQuery("options?dummy=&" + id.mid(optionAreaIndex + 1));
|
||||
QUrlQuery optionQuery("options?dummy=&" + id.mid(customSettingsIndex + 1));
|
||||
|
||||
QString width = optionQuery.queryItemValue("width");
|
||||
QString height = optionQuery.queryItemValue("height");
|
||||
QString corretionLevel = optionQuery.queryItemValue("corretionLevel");
|
||||
QString format = optionQuery.queryItemValue("format");
|
||||
corretionLevel = optionQuery.queryItemValue("corretionLevel");
|
||||
format = optionQuery.queryItemValue("format");
|
||||
|
||||
if(format != "qrcode")
|
||||
{
|
||||
qWarning() << "Format not supported: " << format;
|
||||
return QImage();
|
||||
}
|
||||
|
||||
if(height.isEmpty() && !width.isEmpty())
|
||||
height = width;
|
||||
|
||||
if(width.isEmpty() && height.isEmpty())
|
||||
width = height;
|
||||
|
||||
QZXing::EncodeErrorCorrectionLevel correctionLevelEnum;
|
||||
if(corretionLevel == "H")
|
||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_H;
|
||||
else if(corretionLevel == "Q")
|
||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_Q;
|
||||
else if(corretionLevel == "M")
|
||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_M;
|
||||
else
|
||||
else if(corretionLevel == "L")
|
||||
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_L;
|
||||
}
|
||||
|
||||
if(!corretionLevel.isEmpty() || !format.isEmpty())
|
||||
{
|
||||
if(format != "qrcode")
|
||||
{
|
||||
qWarning() << "Format not supported: " << format;
|
||||
return QImage();
|
||||
}
|
||||
|
||||
result = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE,
|
||||
QSize(width.toInt(), height.toInt()),
|
||||
correctionLevelEnum);
|
||||
requestedSize,
|
||||
correctionLevelEnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue