Skip to content

Commit

Permalink
[plugin|qr] Make eci value optional
Browse files Browse the repository at this point in the history
Close #4
  • Loading branch information
IceflowRE committed Sep 11, 2023
1 parent cecb20a commit 453d9dc
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 32 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ QR Code generation either with the included `QRCodeRect` node or use the encodin

- `mode: QRCode.Mode`
- `error_correction: QRCode.ErrorCorrection`
- `use_eci: bool`
Use Extended Channel Interpretation (ECI)
- `eci_value: int`
Extended Channel Interpretation (ECI) Value
- `data: Variant`
Expand Down Expand Up @@ -363,6 +365,8 @@ QRCode class to generate QR Codes.

- `mode: Mode`
- `error_correction: ErrorCorrection`
- `use_eci: bool`
Use Extended Channel Interpretation (ECI)
- `eci_value: int`
Extended Channel Interpretation (ECI) Value
- `auto_version: bool`
Expand Down Expand Up @@ -404,6 +408,10 @@ Shift JIS encoding utility.

### Changelog

#### 0.3.0

- Make ECI value optional

#### 0.2.0

- Added quiet zone size property
Expand Down
2 changes: 1 addition & 1 deletion addons/qr_code/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="QR Code"
description="QR Code generator. - MIT License"
author="Iceflower S"
version="0.2.0"
version="0.3.0"
script="plugin.gd"
14 changes: 11 additions & 3 deletions addons/qr_code/qr_code.gd
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,12 @@ var mode: Mode = Mode.NUMERIC:
## Error Correction
var error_correction: ErrorCorrection = ErrorCorrection.LOW:
set = set_error_correction
## Extended Channel Interpretation (ECI) Value.
## Set to true if you want to specify an ECI value.
var use_eci: bool = false:
set = set_use_eci
## Extended Channel Interpretation (ECI) Value. Is only used if `use_eci` is true.
var eci_value: int = ECI.ISO_8859_1:
set = set_eci_value

## Use automatically the smallest version
var auto_version: bool = true:
set = set_auto_version
Expand Down Expand Up @@ -743,6 +745,12 @@ func set_mode(new_mode: Mode) -> void:
self._input_data = PackedByteArray()
self._clear_cache()

func set_use_eci(new_use_eci: bool) -> void:
if new_use_eci == use_eci:
return
use_eci = new_use_eci
self._clear_cache()

func set_eci_value(new_eci_value: int) -> void:
if new_eci_value == eci_value:
return
Expand Down Expand Up @@ -967,7 +975,7 @@ func _encode_data() -> BitStream:
var stream: BitStream = BitStream.new()

# add ECI header
if self.eci_value != int(ECI.ISO_8859_1):
if self.use_eci:
stream.append(0b0111, 4)
if self.eci_value <= 127:
stream.append(0, 1)
Expand Down
34 changes: 32 additions & 2 deletions addons/qr_code/qr_code_rect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ var _qr: QRCode = QRCode.new()
@export var error_correction: QRCode.ErrorCorrection:
set = set_error_correction,
get = get_error_correction
## Use Extended Channel Interpretation (ECI).
var use_eci: bool:
set = set_use_eci,
get = get_use_eci
## Extended Channel Interpretation (ECI) Value.
@export var eci_value: QRCode.ECI:
var eci_value: int:
set = set_eci_value,
get = get_eci_value
var data: Variant = "":
Expand Down Expand Up @@ -67,6 +71,14 @@ func set_error_correction(new_error_correction: QRCode.ErrorCorrection) -> void:
func get_error_correction() -> QRCode.ErrorCorrection:
return self._qr.error_correction

func set_use_eci(new_use_eci: bool) -> void:
self._qr.use_eci = new_use_eci
self.notify_property_list_changed()
self._update_qr()

func get_use_eci() -> bool:
return self._qr.use_eci

func set_eci_value(new_eci_value: int) -> void:
self._qr.eci_value = new_eci_value
self.notify_property_list_changed()
Expand Down Expand Up @@ -181,6 +193,16 @@ func _set(property: StringName, value: Variant) -> bool:
return false

func _get_property_list() -> Array[Dictionary]:
var eci_value_prop: Dictionary = {
"name": "eci_value",
"type": TYPE_INT,
"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "Code Page 437:2,ISO 8859-1:3,ISO 8859-2:4,ISO 8859-3:5,ISO 8859-4:6,ISO 8859-5:7,ISO 8859-6:8,ISO 8859-7:9,ISO 8859-8:10,ISO 8859-9:11,ISO 8859-10:12,ISO 8859-11:13,ISO 8859-12:14,ISO 8859-13:15,ISO 8859-14:16,ISO 8859-15:17,ISO 8859-16:18,Shift JIS:20,Windows 1250:21,Windows 1251:22,Windows 1252:23,Windows 1256:24,UTF-16:25,UTF-8:26,US ASCII:27,BIG 5:28,GB 18030:29,EUC KR:30"
}
if !self.use_eci:
eci_value_prop["usage"] = (eci_value_prop["usage"] | PROPERTY_USAGE_READ_ONLY) & ~PROPERTY_USAGE_STORAGE

var data_prop: Dictionary = {
"name": "data",
"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE,
Expand Down Expand Up @@ -230,6 +252,12 @@ func _get_property_list() -> Array[Dictionary]:
module_px_size_prop["usage"] = (module_px_size_prop["usage"] | PROPERTY_USAGE_READ_ONLY) & ~PROPERTY_USAGE_STORAGE

return [
{
"name": "use_eci",
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE,
},
eci_value_prop,
data_prop,
{
"name": "auto_version",
Expand Down Expand Up @@ -273,10 +301,12 @@ func _get_property_list() -> Array[Dictionary]:
]

func _property_can_revert(property: StringName) -> bool:
return property in ["auto_version", "auto_mask_pattern", "light_module_color", "dark_module_color", "auto_module_px_size", "quiet_zone_size"]
return property in ["eci_value", "auto_version", "auto_mask_pattern", "light_module_color", "dark_module_color", "auto_module_px_size", "quiet_zone_size"]

func _property_get_revert(property: StringName) -> Variant:
match property:
"eci_value":
return QRCode.ECI.ISO_8859_1
"auto_version":
return true
"auto_mask_pattern":
Expand Down
Binary file modified doc/qr_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 9 additions & 10 deletions examples/qr_code/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ const QRCode = preload("res://addons/qr_code/qr_code.gd")
@export var _input_data_text: TextEdit
@export var _encoding: OptionButton
@export var _error_correction: OptionButton
@export var _eci_indicator: OptionButton
@export var _auto_version: CheckBox
@export var _eci_value: OptionButton
@export var _version: SpinBox
@export var _auto_mask_pattern: CheckBox
@export var _mask_pattern: SpinBox
@export var _light_module_color: ColorPickerButton
@export var _dark_module_color: ColorPickerButton
@export var _auto_module_px_size: CheckBox
@export var _module_px_size: SpinBox
@export var _quiet_zone_size: SpinBox

@export var _qr_rect: QRCodeRect

Expand Down Expand Up @@ -44,8 +38,13 @@ func _on_error_correction_item_selected(_index: int) -> void:
self._qr_rect.error_correction = self._error_correction.get_selected_id() as QRCode.ErrorCorrection
self._update_values()

func _on_eci_indicator_item_selected(_index: int) -> void:
self._qr_rect.eci_value = self._eci_indicator.get_selected_id() as QRCode.ECI
func _on_use_eci_toggled(button_pressed: bool) -> void:
self._qr_rect.use_eci = button_pressed
self._eci_value.disabled = !button_pressed
self._update_values()

func _on_eci_value_item_selected(_index: int) -> void:
self._qr_rect.eci_value = self._eci_value.get_selected_id() as QRCode.ECI
self._update_values()

func _on_auto_version_toggled(button_pressed: bool) -> void:
Expand Down Expand Up @@ -83,6 +82,6 @@ func _on_module_px_size_value_changed(value: float) -> void:
self._qr_rect.module_px_size = int(value)
self._update_values()

func _on_quiet_zone_size_value_changed(value: float):
func _on_quiet_zone_size_value_changed(value: float) -> void:
self._qr_rect.quiet_zone_size = int(value)
self._update_values()
25 changes: 9 additions & 16 deletions examples/qr_code/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://examples/qr_code/main.gd" id="1_55tdt"]
[ext_resource type="Script" path="res://addons/qr_code/qr_code_rect.gd" id="1_t1m1p"]

[node name="HBoxContainer" type="HBoxContainer" node_paths=PackedStringArray("_input_data_text", "_encoding", "_error_correction", "_eci_indicator", "_auto_version", "_version", "_auto_mask_pattern", "_mask_pattern", "_light_module_color", "_dark_module_color", "_auto_module_px_size", "_module_px_size", "_qr_rect")]
[node name="HBoxContainer" type="HBoxContainer" node_paths=PackedStringArray("_input_data_text", "_encoding", "_error_correction", "_eci_value", "_version", "_mask_pattern", "_module_px_size", "_qr_rect")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -13,14 +13,9 @@ script = ExtResource("1_55tdt")
_input_data_text = NodePath("MarginContainer2/VBoxContainer/InputDataText")
_encoding = NodePath("MarginContainer2/VBoxContainer/options/Encoding")
_error_correction = NodePath("MarginContainer2/VBoxContainer/options/ErrorCorrection")
_eci_indicator = NodePath("MarginContainer2/VBoxContainer/options/ECIIndicator")
_auto_version = NodePath("MarginContainer2/VBoxContainer/options/AutoVersion")
_eci_value = NodePath("MarginContainer2/VBoxContainer/options/ECIValue")
_version = NodePath("MarginContainer2/VBoxContainer/options/Version")
_auto_mask_pattern = NodePath("MarginContainer2/VBoxContainer/options/AutoMaskPattern")
_mask_pattern = NodePath("MarginContainer2/VBoxContainer/options/MaskPattern")
_light_module_color = NodePath("MarginContainer2/VBoxContainer/options/LightModuleColor")
_dark_module_color = NodePath("MarginContainer2/VBoxContainer/options/DarkModuleColor")
_auto_module_px_size = NodePath("MarginContainer2/VBoxContainer/options/AutoModulePxSize")
_module_px_size = NodePath("MarginContainer2/VBoxContainer/options/ModulePxSize")
_qr_rect = NodePath("MarginContainer/QRCodeRect")

Expand Down Expand Up @@ -93,17 +88,14 @@ popup/item_3/id = 2

[node name="ECIModeLabel" type="Label" parent="MarginContainer2/VBoxContainer/options"]
layout_mode = 2
text = "ECI Indicator"
text = "ECI Value"

[node name="ECIModeLabelTip" type="Label" parent="MarginContainer2/VBoxContainer/options"]
[node name="UseECI" type="CheckBox" parent="MarginContainer2/VBoxContainer/options"]
layout_mode = 2
tooltip_text = "For ECI other than ISO 8859-1, choose BYTE encoding."
mouse_filter = 0
text = "*"
horizontal_alignment = 1

[node name="ECIIndicator" type="OptionButton" parent="MarginContainer2/VBoxContainer/options"]
[node name="ECIValue" type="OptionButton" parent="MarginContainer2/VBoxContainer/options"]
layout_mode = 2
disabled = true
alignment = 1
item_count = 5
selected = 0
Expand Down Expand Up @@ -220,7 +212,7 @@ stretch_mode = 5
script = ExtResource("1_t1m1p")
mode = 1
error_correction = 1
eci_value = 3
use_eci = false
data = ""
auto_version = true
auto_mask_pattern = true
Expand All @@ -235,7 +227,8 @@ layout_mode = 2
[connection signal="text_changed" from="MarginContainer2/VBoxContainer/InputDataText" to="." method="_on_input_data_text_text_changed"]
[connection signal="item_selected" from="MarginContainer2/VBoxContainer/options/Encoding" to="." method="_on_encoding_item_selected"]
[connection signal="item_selected" from="MarginContainer2/VBoxContainer/options/ErrorCorrection" to="." method="_on_error_correction_item_selected"]
[connection signal="item_selected" from="MarginContainer2/VBoxContainer/options/ECIIndicator" to="." method="_on_eci_indicator_item_selected"]
[connection signal="toggled" from="MarginContainer2/VBoxContainer/options/UseECI" to="." method="_on_use_eci_toggled"]
[connection signal="item_selected" from="MarginContainer2/VBoxContainer/options/ECIValue" to="." method="_on_eci_value_item_selected"]
[connection signal="toggled" from="MarginContainer2/VBoxContainer/options/AutoVersion" to="." method="_on_auto_version_toggled"]
[connection signal="value_changed" from="MarginContainer2/VBoxContainer/options/Version" to="." method="_on_version_value_changed"]
[connection signal="toggled" from="MarginContainer2/VBoxContainer/options/AutoMaskPattern" to="." method="_on_auto_mask_pattern_toggled"]
Expand Down

0 comments on commit 453d9dc

Please sign in to comment.