This commit is contained in:
zhuzichu
2023-08-14 18:10:37 +08:00
parent 7fe71c892b
commit 0b6491e730
7 changed files with 99 additions and 29 deletions

View File

@ -1,4 +1,4 @@
#include "FluQRCode.h"
#include "QRCode.h"
#include "BarcodeFormat.h"
#include "BitMatrix.h"
@ -6,15 +6,17 @@
using namespace ZXing;
FluQRCode::FluQRCode(QQuickItem* parent) : QQuickPaintedItem(parent)
QRCode::QRCode(QQuickItem* parent) : QQuickPaintedItem(parent)
{
color(QColor(0,0,0,255));
bgColor(QColor(255,255,255,255));
size(100);
setWidth(_size);
setHeight(_size);
connect(this,&FluQRCode::textChanged,this,[=]{update();});
connect(this,&FluQRCode::colorChanged,this,[=]{update();});
connect(this,&FluQRCode::sizeChanged,this,[=]{
connect(this,&QRCode::textChanged,this,[=]{update();});
connect(this,&QRCode::colorChanged,this,[=]{update();});
connect(this,&QRCode::bgColorChanged,this,[=]{update();});
connect(this,&QRCode::sizeChanged,this,[=]{
setWidth(_size);
setHeight(_size);
update();
@ -22,7 +24,7 @@ FluQRCode::FluQRCode(QQuickItem* parent) : QQuickPaintedItem(parent)
}
void FluQRCode::paint(QPainter* painter)
void QRCode::paint(QPainter* painter)
{
if(_text.isEmpty()){
return;
@ -31,7 +33,6 @@ void FluQRCode::paint(QPainter* painter)
return;
}
painter->save();
painter->eraseRect(boundingRect());
auto format = ZXing::BarcodeFormatFromString("QRCode");
auto writer = MultiFormatWriter(format);
writer.setMargin(0);
@ -46,6 +47,9 @@ void FluQRCode::paint(QPainter* painter)
if (qRed(pixel) == 0 && qGreen(pixel) == 0 && qBlue(pixel) == 0) {
rgbImage.setPixelColor(x, y, _color);
}
if (qRed(pixel) == 255 && qGreen(pixel) == 255 && qBlue(pixel) == 255) {
rgbImage.setPixelColor(x, y, _bgColor);
}
}
}
painter->drawImage(QRect(0, 0, static_cast<int>(width()), static_cast<int>(height())), rgbImage);

View File

@ -1,22 +1,23 @@
#ifndef FLUQRCODE_H
#define FLUQRCODE_H
#ifndef QRCODE_H
#define QRCODE_H
#include <QQuickItem>
#include <QQuickPaintedItem>
#include <QPainter>
#include "stdafx.h"
class FluQRCode : public QQuickPaintedItem
class QRCode : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY_AUTO(QString,text)
Q_PROPERTY_AUTO(QColor,color)
Q_PROPERTY_AUTO(QColor,bgColor)
Q_PROPERTY_AUTO(int,size);
QML_NAMED_ELEMENT(FluQRCode)
QML_NAMED_ELEMENT(QRCode)
public:
explicit FluQRCode(QQuickItem *parent = nullptr);
explicit QRCode(QQuickItem *parent = nullptr);
void paint(QPainter* painter) override;
};
#endif // FLUQRCODE_H
#endif // QRCODE_H

View File

@ -0,0 +1,23 @@
import QtQuick
import QtQuick.Controls
import FluentUI
Item{
property alias text: qrcode.text
property alias color: qrcode.color
property alias bgColor: qrcode.bgColor
property int size: 50
property int margins: 0
id:control
width: size
height: size
Rectangle{
color: bgColor
anchors.fill: parent
}
QRCode{
id:qrcode
size:control.size-margins
anchors.centerIn: parent
}
}

View File

@ -92,7 +92,7 @@ Item{
wrapMode: Text.WrapAnywhere
horizontalAlignment: isRight ? Qt.AlignRight : Qt.AlignLeft
text: modelData.lable
color: FluTheme.primaryColor.dark
color: FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark
}
}
@ -286,10 +286,7 @@ Item{
}
}
]
}
}
}
}

View File

@ -83,4 +83,5 @@ FluTreeView 1.0 Controls/FluTreeView.qml
FluWindow 1.0 Controls/FluWindow.qml
FluTimeline 1.0 Controls/FluTimeline.qml
FluChart 1.0 Controls/FluChart.qml
FluQRCode 1.0 Controls/FluQRCode.qml
plugin fluentuiplugin