-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
547 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# This file is part of JQTools | ||
# | ||
# Project introduce: https://github.com/188080501/JQTools | ||
# | ||
# Copyright: Jason | ||
# | ||
# Contact email: [email protected] | ||
# | ||
# GitHub: https://github.com/188080501/ | ||
# | ||
|
||
INCLUDEPATH += \ | ||
$$PWD/cpp/ | ||
|
||
HEADERS += \ | ||
$$PWD/cpp/barcodemaker.h | ||
|
||
SOURCES += \ | ||
$$PWD/cpp/barcodemaker.cpp | ||
|
||
RESOURCES += \ | ||
$$PWD/qml/BarcodeMakerQml.qrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
This file is part of JQTools | ||
|
||
Project introduce: https://github.com/188080501/JQTools | ||
|
||
Copyright: Jason | ||
|
||
Contact email: [email protected] | ||
|
||
GitHub: https://github.com/188080501/ | ||
*/ | ||
|
||
#include "barcodemaker.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
This file is part of JQTools | ||
Project introduce: https://github.com/188080501/JQTools | ||
Copyright: Jason | ||
Contact email: [email protected] | ||
GitHub: https://github.com/188080501/ | ||
*/ | ||
|
||
#include "barcodemaker.h" | ||
|
||
// Qt lib import | ||
#include <QDebug> | ||
#include <QQmlApplicationEngine> | ||
#include <QFileDialog> | ||
#include <QStandardPaths> | ||
#include <QPainter> | ||
|
||
// JQLibrary lib import | ||
#include "JQBarcode.h" | ||
|
||
using namespace BarcodeMaker; | ||
|
||
Manage::Manage() | ||
{ | ||
this->qmlApplicationEngine().data()->addImageProvider( "BarcodeMaker", new ImageProvider ); | ||
} | ||
|
||
Manage::~Manage() | ||
{ | ||
this->qmlApplicationEngine().data()->removeImageProvider( "BarcodeMaker" ); | ||
} | ||
|
||
QString Manage::savePng(const QString &string) | ||
{ | ||
auto filePath = QFileDialog::getSaveFileName( | ||
nullptr, | ||
QStringLiteral( "请选择保存图片的路径" ), | ||
QStandardPaths::writableLocation( QStandardPaths::DesktopLocation ), | ||
"*.png" | ||
); | ||
|
||
if ( filePath.isEmpty() ) { return "cancel"; } | ||
|
||
if ( !filePath.toLower().endsWith( ".png" ) ) | ||
{ | ||
filePath += ".png"; | ||
} | ||
|
||
QImage targetImage( QSize( 210, 140 ), QImage::Format_RGB888 ); | ||
targetImage.fill( QColor( "#ffffff" ) ); | ||
|
||
const auto &&barcodeImage = JQBarcode::makeBarcode( string.toLongLong() ); | ||
|
||
if ( ( string.size() == 13 ) && string.toLongLong() && ( string[ 0 ] == '6' ) ) | ||
{ | ||
QPainter painter; | ||
painter.begin( &targetImage ); | ||
painter.drawImage( 10, 10, barcodeImage ); | ||
} | ||
|
||
const auto &&saveSucceed = targetImage.save( filePath ); | ||
if ( !saveSucceed ) | ||
{ | ||
return "error"; | ||
} | ||
|
||
return "OK"; | ||
} | ||
|
||
ImageProvider::ImageProvider(): | ||
QQuickImageProvider( QQuickImageProvider::Image ) | ||
{ } | ||
|
||
QImage ImageProvider::requestImage(const QString &id, QSize *, const QSize &) | ||
{ | ||
if ( ( id.size() == 13 ) && id.toLongLong() && ( id[ 0 ] == '6' ) ) | ||
{ | ||
return JQBarcode::makeBarcode( id.toLongLong() ); | ||
} | ||
else | ||
{ | ||
return { }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
This file is part of JQTools | ||
Project introduce: https://github.com/188080501/JQTools | ||
Copyright: Jason | ||
Contact email: [email protected] | ||
GitHub: https://github.com/188080501/ | ||
*/ | ||
|
||
#ifndef GROUP_MAKEGROUP_BARCODEMAKER_CPP_BARCODEMAKER_H_ | ||
#define GROUP_MAKEGROUP_BARCODEMAKER_CPP_BARCODEMAKER_H_ | ||
|
||
// Qt lib import | ||
#include <QImage> | ||
#include <QQuickImageProvider> | ||
|
||
// JQToolsLibrary import | ||
#include "JQToolsLibrary.h" | ||
|
||
#define BARCODEMAKER_INITIALIZA \ | ||
{ \ | ||
qmlRegisterType< BarcodeMaker::Manage >( "BarcodeMaker", 1, 0, "BarcodeMakerManage" ); \ | ||
} | ||
|
||
namespace BarcodeMaker | ||
{ | ||
|
||
class Manage: public AbstractTool | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(Manage) | ||
|
||
public: | ||
Manage(); | ||
|
||
~Manage(); | ||
|
||
public slots: | ||
QString savePng(const QString &string); | ||
}; | ||
|
||
class ImageProvider: public QQuickImageProvider | ||
{ | ||
public: | ||
ImageProvider(); | ||
|
||
~ImageProvider() = default; | ||
|
||
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); | ||
}; | ||
|
||
} | ||
|
||
#endif//GROUP_MAKEGROUP_BARCODEMAKER_CPP_BARCODEMAKER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
This file is part of JQTools | ||
Project introduce: https://github.com/188080501/JQTools | ||
Copyright: Jason | ||
Contact email: [email protected] | ||
GitHub: https://github.com/188080501/ | ||
*/ | ||
|
||
import QtQuick 2.7 | ||
import QtQuick.Controls 1.4 | ||
import "qrc:/MaterialUI/Interface/" | ||
import BarcodeMaker 1.0 | ||
|
||
Item { | ||
id: qrcodeMaker | ||
width: 620 | ||
height: 540 | ||
|
||
BarcodeMakerManage { | ||
id: barcodeMakerManage | ||
} | ||
|
||
Item { | ||
anchors.centerIn: parent | ||
width: 620 | ||
height: 540 | ||
|
||
MaterialTextField { | ||
id: textFieldForLower | ||
x: 40 | ||
y: 50 | ||
width: 540 | ||
placeholderText: "条形码ID\n目前仅支持EAN-13,并且需要6开头" | ||
text: "6901234567892" | ||
} | ||
|
||
Image { | ||
id: imageForBarcode | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
anchors.horizontalCenterOffset: -100 | ||
anchors.verticalCenter: parent.verticalCenter | ||
anchors.verticalCenterOffset: 50 | ||
width: 250 | ||
height: 250 | ||
fillMode: Image.PreserveAspectFit | ||
source: "image://BarcodeMaker/" + textFieldForLower.text | ||
|
||
MaterialButton { | ||
anchors.left: parent.right | ||
anchors.leftMargin: 50 | ||
anchors.verticalCenter: parent.verticalCenter | ||
text: "保存为PNG" | ||
|
||
onClicked: { | ||
materialUI.showLoading(); | ||
|
||
var reply = barcodeMakerManage.savePng( | ||
textFieldForLower.text | ||
); | ||
|
||
materialUI.hideLoading(); | ||
|
||
switch ( reply ) | ||
{ | ||
case "cancel": materialUI.showSnackbarMessage( "取消保存" ); break; | ||
case "error": materialUI.showSnackbarMessage( "保存失败" ); break; | ||
case "OK": materialUI.showSnackbarMessage( "保存成功" ); break; | ||
default: break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/BarcodeMaker"> | ||
<file>BarcodeMaker.qml</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.