diff --git a/.gitmodules b/.gitmodules
index c0a13474..fa200d64 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "framelesshelper"]
path = framelesshelper
- url = https://github.com/zhuzichu520/framelesshelper.git
\ No newline at end of file
+ url = https://github.com/zhuzichu520/framelesshelper.git
+[submodule "zxing-cpp"]
+ path = zxing-cpp
+ url = https://github.com/zhuzichu520/zxing-cpp.git
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index afa0aae8..5272470a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,8 @@ if (FLUENTUI_BUILD_FRAMELESSHEPLER)
add_subdirectory(framelesshelper)
endif ()
+add_subdirectory(zxing-cpp)
+
message("------------------------ FluentUI ------------------------")
message("Build FluentUI demo applications.: ${FLUENTUI_BUILD_EXAMPLES}")
message("Build FramelessHelper.: ${FLUENTUI_BUILD_FRAMELESSHEPLER}")
diff --git a/example/qml/component/CodeExpander.qml b/example/qml/component/CodeExpander.qml
index 5073d9a6..0ff675af 100644
--- a/example/qml/component/CodeExpander.qml
+++ b/example/qml/component/CodeExpander.qml
@@ -133,7 +133,8 @@ FluExpander{
"FluSpinBox",
"FluHttp",
"FluWatermark",
- "FluTour"
+ "FluTour",
+ "FluQRCode"
];
code = code.replace(/\n/g, "
");
code = code.replace(/ /g, " ");
diff --git a/example/qml/global/ItemsOriginal.qml b/example/qml/global/ItemsOriginal.qml
index 320e8ac5..60eddd54 100644
--- a/example/qml/global/ItemsOriginal.qml
+++ b/example/qml/global/ItemsOriginal.qml
@@ -331,6 +331,12 @@ FluObject{
FluPaneItemExpander{
title:lang.other
icon:FluentIcons.Shop
+ FluPaneItem{
+ title:"QRCode"
+ onTap:{
+ navigationView.push("qrc:/example/qml/page/T_QRCode.qml")
+ }
+ }
FluPaneItem{
title:"Tour"
onTap:{
diff --git a/example/qml/page/T_QRCode.qml b/example/qml/page/T_QRCode.qml
new file mode 100644
index 00000000..ec5fe15d
--- /dev/null
+++ b/example/qml/page/T_QRCode.qml
@@ -0,0 +1,75 @@
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtQuick.Window
+import FluentUI
+import Qt5Compat.GraphicalEffects
+import "qrc:///example/qml/component"
+
+FluScrollablePage{
+
+ title:"QRCode"
+
+ FluQRCode{
+ id:qrcode
+ Layout.topMargin: 20
+ size:slider_size.value
+ text:text_box.text
+ color:color_picker.colorValue
+ Layout.preferredWidth: size
+ Layout.preferredHeight: size
+ }
+
+ RowLayout{
+ spacing: 10
+ Layout.topMargin: 20
+ FluText{
+ text:"text:"
+ Layout.alignment: Qt.AlignVCenter
+ }
+ FluTextBox{
+ id:text_box
+ text:"会磨刀的小猪"
+ }
+ }
+
+ RowLayout{
+ spacing: 10
+ Layout.topMargin: 10
+ FluText{
+ text:"color:"
+ Layout.alignment: Qt.AlignVCenter
+ }
+ FluColorPicker{
+ id:color_picker
+ Component.onCompleted: {
+ setColor(Qt.rgba(0,0,0,1))
+ }
+ }
+ }
+
+ RowLayout{
+ spacing: 10
+ FluText{
+ text:"size:"
+ Layout.alignment: Qt.AlignVCenter
+ }
+ FluSlider{
+ id:slider_size
+ from:60
+ to:200
+ value: 120
+ }
+ }
+
+ CodeExpander{
+ Layout.fillWidth: true
+ Layout.topMargin: 20
+ code:'FluQRCode{
+ color:"red"
+ text:"会磨刀的小猪"
+ size:100
+}'
+ }
+
+}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a7783ad0..173c4d08 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -83,6 +83,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
Qt::CorePrivate
Qt::QuickPrivate
Qt::QmlPrivate
+ ZXing
)
#安装
diff --git a/src/FluQRCode.cpp b/src/FluQRCode.cpp
new file mode 100644
index 00000000..ef0ccbf7
--- /dev/null
+++ b/src/FluQRCode.cpp
@@ -0,0 +1,53 @@
+#include "FluQRCode.h"
+
+#include "BarcodeFormat.h"
+#include "BitMatrix.h"
+#include "MultiFormatWriter.h"
+
+using namespace ZXing;
+
+FluQRCode::FluQRCode(QQuickItem* parent) : QQuickPaintedItem(parent)
+{
+ color(QColor(0,0,0,255));
+ size(100);
+ setWidth(_size);
+ setHeight(_size);
+ connect(this,&FluQRCode::textChanged,this,[=]{update();});
+ connect(this,&FluQRCode::colorChanged,this,[=]{update();});
+ connect(this,&FluQRCode::sizeChanged,this,[=]{
+ setWidth(_size);
+ setHeight(_size);
+ update();
+ });
+}
+
+
+void FluQRCode::paint(QPainter* painter)
+{
+ if(_text.isEmpty()){
+ return;
+ }
+ if(_text.length()>1108){
+ return;
+ }
+ painter->save();
+ painter->eraseRect(boundingRect());
+ auto format = ZXing::BarcodeFormatFromString("QRCode");
+ auto writer = MultiFormatWriter(format);
+ writer.setMargin(0);
+ writer.setEncoding(ZXing::CharacterSet::UTF8);
+ auto matrix = writer.encode(_text.toUtf8().constData(), 0, 0);
+ auto bitmap = ToMatrix(matrix);
+ auto image = QImage(bitmap.data(), bitmap.width(), bitmap.height(), bitmap.width(), QImage::Format::Format_Grayscale8).copy();
+ QImage rgbImage = image.convertToFormat(QImage::Format_ARGB32);
+ for (int y = 0; y < rgbImage.height(); ++y) {
+ for (int x = 0; x < rgbImage.width(); ++x) {
+ QRgb pixel = rgbImage.pixel(x, y);
+ if (qRed(pixel) == 0 && qGreen(pixel) == 0 && qBlue(pixel) == 0) {
+ rgbImage.setPixelColor(x, y, _color);
+ }
+ }
+ }
+ painter->drawImage(QRect(0, 0, static_cast(width()), static_cast(height())), rgbImage);
+ painter->restore();
+}
diff --git a/src/FluQRCode.h b/src/FluQRCode.h
new file mode 100644
index 00000000..f36c37c4
--- /dev/null
+++ b/src/FluQRCode.h
@@ -0,0 +1,22 @@
+#ifndef FLUQRCODE_H
+#define FLUQRCODE_H
+
+#include
+#include
+#include
+#include "stdafx.h"
+
+class FluQRCode : public QQuickPaintedItem
+{
+ Q_OBJECT
+ Q_PROPERTY_AUTO(QString,text)
+ Q_PROPERTY_AUTO(QColor,color)
+ Q_PROPERTY_AUTO(int,size);
+ QML_NAMED_ELEMENT(FluQRCode)
+public:
+ explicit FluQRCode(QQuickItem *parent = nullptr);
+ void paint(QPainter* painter) override;
+
+};
+
+#endif // FLUQRCODE_H
diff --git a/zxing-cpp b/zxing-cpp
new file mode 160000
index 00000000..079944e2
--- /dev/null
+++ b/zxing-cpp
@@ -0,0 +1 @@
+Subproject commit 079944e235a63fd7956e1ed71ea66ac638dc44e7