First commit
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
#include "QBarCode.h"
|
||||
#include "ui_myBarCode.h"
|
||||
#include "QImage"
|
||||
#include "QFile"
|
||||
#include "QFileInfo"
|
||||
#include "QDebug"
|
||||
#include "stdio.h"
|
||||
|
||||
QBarCode::QBarCode(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::QBarCode)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->BarCodeGenerate,SIGNAL(pressed()),this,SLOT(onEnCodeBar()));
|
||||
|
||||
ui->lineEdit->setText("12345678ABCDEFG");
|
||||
|
||||
//onEnCodeBar();
|
||||
|
||||
}
|
||||
|
||||
QBarCode::~QBarCode()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void QBarCode::onEnCodeBar(){
|
||||
|
||||
QFile f1;
|
||||
//ui->lineEdit->setText("dfdsfdsfdsfdsf");
|
||||
int ps = 1, pcl = 0, oflags;
|
||||
ps = 0; pcl = 0;
|
||||
|
||||
oflags = BARCODE_OUT_PS | BARCODE_OUT_NOHEADERS;
|
||||
|
||||
// char *txt = ui->lineEdit->text.toStdString().c_str();
|
||||
//sprintf(txt,"%s", (char *)ui->lineEdit->text().data());
|
||||
/* and my data as code-128B autodetected */
|
||||
QString txt =ui->lineEdit->text();
|
||||
Barcode_Encode_and_Print((char *)txt.toStdString().c_str(),stdout, 0, 60, 240, 510,
|
||||
oflags);
|
||||
|
||||
/* A few code-39 ones */
|
||||
// Barcode_Encode_and_Print("silly code",stdout, 0, 0, 40, 320,
|
||||
// BARCODE_39 | oflags);
|
||||
|
||||
// Barcode_Encode_and_Print("SAMPLE CODES",stdout, 100, 30, 400, 80,
|
||||
// BARCODE_39 | oflags);
|
||||
|
||||
/* ISBN with add-5 */
|
||||
// Barcode_Encode_and_Print("1-56592-292-1 90000",stdout, 0, 0, 40, 430,
|
||||
// BARCODE_ISBN | oflags);
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* Do it all in one step
|
||||
*/
|
||||
int QBarCode::Barcode_Encode_and_Print(char *text, FILE *f, int wid, int hei,
|
||||
int xoff, int yoff, int flags)
|
||||
{
|
||||
struct Barcode_Item * bc;
|
||||
|
||||
if (!(bc=Barcode_Create(text))) {
|
||||
qDebug()<<"mem less then:";//<< -ENOMEM ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( Barcode_Position(bc, wid, hei, xoff, yoff, 0.0) < 0
|
||||
|| Barcode_Encode(bc, flags) < 0
|
||||
//|| Barcode_Print(bc, f, flags) < 0
|
||||
) {
|
||||
qDebug()<< bc->error;
|
||||
Barcode_Delete(bc);
|
||||
return -1;
|
||||
}
|
||||
//QFile f1;
|
||||
bcText = text;
|
||||
bcTextinfo = bc->textinfo;
|
||||
bcPartial = bc->partial;
|
||||
ui->textEdit->setText(bcPartial);
|
||||
|
||||
Barcode_ToImage(bc);
|
||||
|
||||
Barcode_Delete(bc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 将条形码编码转换成点阵图形
|
||||
int QBarCode::Barcode_ToImage(Barcode_Item * bc ){
|
||||
bc->ascii;
|
||||
bc->partial;
|
||||
bc->textinfo;
|
||||
int len =QString(bc->partial).length();
|
||||
bcWidth =6;
|
||||
for(int i=0;i<len;i++)
|
||||
bcWidth+= (bc->partial[i]&0x0f);
|
||||
//
|
||||
//bcWidth = len;
|
||||
bcHeight = 40;
|
||||
|
||||
QImage image(bcWidth,bcHeight,QImage::Format_ARGB32);
|
||||
//image.dotsPerMeterX()
|
||||
//image.size().setHeight(50);
|
||||
image.fill(0x00ffffff);
|
||||
//QPainter painter(&image);
|
||||
//ui->textEdit->document()->drawContents (&painter, image.rect()); /*将text写到pic*/
|
||||
QString txt = bc->ascii;
|
||||
|
||||
ui->textEdit->setText( QString().sprintf("W:%d,H:%d,Len:%d",ui->BarCodeView->width(),ui->BarCodeView->height(),len));
|
||||
|
||||
//0b1a2a4123221223211221132221231213212223112312131311222314111b3c1a1b
|
||||
//11:12:1 22:12:2 33:12:3 44:12:4 55:12:5 66:12:6 77:12:7 88:12:8
|
||||
//02112141232212232112211322212312132122231123121313112223141112331112
|
||||
|
||||
memset(pointMap,0,sizeof(pointMap));
|
||||
unsigned char *img= image.bits();
|
||||
for(int j=0;j< 20;j++){
|
||||
int i=3;
|
||||
unsigned char p=0;
|
||||
for(int n=0;( n<len);n++)
|
||||
{
|
||||
int c= bc->partial[n];
|
||||
if(c<0x30 || c>127) continue;
|
||||
c = c-0x30;
|
||||
if(n%2==1){
|
||||
for(int r=0;r<c;r++){
|
||||
*( img+j*bcWidth*4+i*4)= 0;
|
||||
*( img+j*bcWidth*4+i*4+1)= 0;
|
||||
*( img+j*bcWidth*4+i*4+2)= 0;
|
||||
*( img+j*bcWidth*4+i*4+3)= 0;
|
||||
i++;
|
||||
// p= (p<<1) | 0x01;
|
||||
// pointMap[j*bcWidth+i]=1;
|
||||
|
||||
}
|
||||
}
|
||||
else i+=c;
|
||||
}
|
||||
}
|
||||
|
||||
QString fileName="\\home\\plg\\doc\\"+ txt + ".BMP" ;
|
||||
|
||||
image.save(fileName);
|
||||
QFileInfo(fileName).fileName();
|
||||
// ui->labBarCode->setPixmap(QPixmap(QString::fromUtf8(".\\imgd.BMP")));
|
||||
|
||||
//ui->widgetPrintTextDisplay->dat = pointMap;
|
||||
|
||||
ShowBarCode(fileName);
|
||||
}
|
||||
|
||||
void QBarCode::ShowBarCode(QString fileName)
|
||||
{
|
||||
/****************界面初始化********************************/
|
||||
|
||||
this->pictureName =fileName ;
|
||||
scene = new QGraphicsScene;
|
||||
scene->setSceneRect( -200,0,bcWidth*4+200,bcHeight);
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
QPixmap pixmap(this->pictureName);
|
||||
pixmap = pixmap.scaledToWidth(2.5*bcWidth);
|
||||
item = scene->addPixmap(pixmap);
|
||||
|
||||
/***************设置view的场景*****************************/
|
||||
ui->BarCodeView->setScene(scene);
|
||||
ui->BarCodeView->setRenderHint(QPainter::Antialiasing);
|
||||
ui->BarCodeView->setCacheMode(QGraphicsView::CacheBackground);
|
||||
ui->BarCodeView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||
ui->BarCodeView->setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
//ui->graphicsView->resize(400,300);
|
||||
|
||||
ui->BarCodeView->setScene(scene);//设置view的场景
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef QBARCODE_H
|
||||
#define QBARCODE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "barcode.h"
|
||||
#include "QGraphicsScene"
|
||||
#include "QGraphicsPixmapItem"
|
||||
|
||||
namespace Ui {
|
||||
class QBarCode;
|
||||
}
|
||||
|
||||
class QBarCode : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QBarCode(QWidget *parent = 0);
|
||||
~QBarCode();
|
||||
unsigned char pointMap[40*1000];
|
||||
QString pictureName;//当前显示的图片
|
||||
private slots:
|
||||
void onEnCodeBar();
|
||||
|
||||
private:
|
||||
void ShowBarCode(QString fileName);
|
||||
int Barcode_Encode_and_Print(char *text, FILE *f, int wid, int hei,
|
||||
int xoff, int yoff, int flags);
|
||||
int Barcode_ToImage(Barcode_Item * bc );
|
||||
|
||||
QGraphicsScene *scene;//声明scene
|
||||
QGraphicsPixmapItem *item;//声明item
|
||||
|
||||
QString bcPartial;
|
||||
QString bcTextinfo;
|
||||
QString bcText;
|
||||
int bcWidth,bcHeight;
|
||||
|
||||
|
||||
private:
|
||||
Ui::QBarCode *ui;
|
||||
};
|
||||
|
||||
#endif // QBARCODE_H
|
||||
@@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QBarCode</class>
|
||||
<widget class="QWidget" name="QBarCode">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>680</width>
|
||||
<height>316</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="7">
|
||||
<widget class="QGraphicsView" name="BarCodeView"/>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>条形码类型</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>字体</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>条形码高度</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>放大等级</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QComboBox" name="BarCodeType"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QComboBox" name="BarCodeFont">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QComboBox" name="BarCodeHeigh"/>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<widget class="QSpinBox" name="BarCodeScale">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="6">
|
||||
<widget class="QPushButton" name="BarCodeInsert">
|
||||
<property name="text">
|
||||
<string>插入文档</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>文本信息</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="7">
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="5" colspan="2">
|
||||
<widget class="QLabel" name="labFileName">
|
||||
<property name="text">
|
||||
<string>FileName</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="5">
|
||||
<widget class="QPushButton" name="pushBtnOpenFile">
|
||||
<property name="text">
|
||||
<string>打开文件</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="5">
|
||||
<widget class="QPushButton" name="BarCodeGenerate">
|
||||
<property name="text">
|
||||
<string>生成条形码</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="6">
|
||||
<widget class="QPushButton" name="pushBtnColse">
|
||||
<property name="text">
|
||||
<string>关闭</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labStatus">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user