1872 lines
64 KiB
C++
1872 lines
64 KiB
C++
/*
|
||
* PicWidget.cpp
|
||
*
|
||
* Created on: Jul 2, 2013
|
||
* Author: yiyu
|
||
* QQ:1036184468
|
||
* Descriptoin:
|
||
|
||
*/
|
||
|
||
#include "PicWidget.h"
|
||
#include <QColor>
|
||
#include <QMessageBox>
|
||
#include <QDebug>
|
||
#include <Qt>
|
||
#include <QEvent>
|
||
#include "LogInfo.h"
|
||
#include <QKeyEvent>
|
||
//#include <QWMatrix>
|
||
|
||
#include "myinclude.h"
|
||
#include<iostream>
|
||
#include<string>
|
||
|
||
PicWidget::PicWidget(QWidget *parent):QWidget(parent){
|
||
memset(pointMap,0,sizeof(pointMap));
|
||
heightPoint = 0;
|
||
widthPoint = 0;
|
||
lineNum=0;
|
||
lineMaxNum=0;
|
||
pEditMode=0;
|
||
memset(linePara,0,sizeof(linePara));
|
||
scale = 16;
|
||
currXpos = 0;
|
||
currYpos = 0;
|
||
altPrint=0;
|
||
zkEditEn=false;
|
||
startCol=0;startRow=0;
|
||
modified = false;
|
||
charPara.DrawGridEn=(Qt::CheckState)true;
|
||
charPara.Bold=0;
|
||
charPara.Font=ST07;
|
||
charPara.CharWidth = 6;
|
||
charPara.CharHeight = 7;
|
||
charPara.Width = 0;
|
||
charPara.CharCurrent=1;
|
||
charPara.CurrentEn =1;
|
||
charPara.LineSpace=1;
|
||
charPara.FontGap=1;
|
||
charPara.LineHeight = 8;
|
||
isInput =0;
|
||
charPara.insertMode=1;
|
||
|
||
/*system("chmod a+x /opt/zk/unitogb");
|
||
unitogb.setFileName ("/opt/zk/unitogb");
|
||
zkAsc.setFileName ("/opt/zk/asc.bin");
|
||
|
||
zkHz07.setFileName ("/opt/zk/HZK7S");
|
||
zkHz09.setFileName ("/opt/zk/ST1010");
|
||
zkHz12.setFileName ("/opt/zk/HZK12S");
|
||
zkHz16.setFileName ("/opt/zk/HZK16S");
|
||
zkHz24.setFileName ("/opt/zk/ST2424");
|
||
zkHz16H.setFileName ("/opt/zk/HZK16H");
|
||
zkHz24H.setFileName ("/opt/zk/HZK24H");*/
|
||
|
||
//cal_currHeightEn=0;
|
||
// qDebug()<<"dfdsfasfsdaf";
|
||
}
|
||
|
||
PicWidget::~PicWidget(){
|
||
if(zkAsc.isOpen ()) zkAsc.close ();
|
||
if(zkHz07.isOpen ()) zkHz07.close ();
|
||
if(zkHz09.isOpen ()) zkHz09.close ();
|
||
if(zkHz12.isOpen ()) zkHz12.close ();
|
||
if(zkHz16.isOpen ()) zkHz16.close ();
|
||
if(zkHz24.isOpen ()) zkHz24.close ();
|
||
}
|
||
|
||
int PicWidget::getVarNum (){
|
||
return varNum;
|
||
}
|
||
void PicWidget::zkEditNow()
|
||
{
|
||
int var[40]={0};
|
||
charPara.DrawEn =0;
|
||
PFONTNAME oldFont=charPara.Font;
|
||
charPara.Font = ST12;
|
||
currXpos =0;
|
||
currYpos =0;
|
||
scale =2;
|
||
zkEditEn=false;
|
||
memset(pointMap,0,40*400);
|
||
|
||
|
||
#ifdef ENGLISH
|
||
inputTxtDot(tr("Please input a char."),var);
|
||
#else
|
||
inputTxtDot(tr("请输入要编辑的字符"),var);
|
||
#endif
|
||
|
||
charPara.Font = oldFont;
|
||
zkEditEn=true;
|
||
modified = false;
|
||
charPara.CharCurrent=0;
|
||
charPara.DrawEn =1;
|
||
charPara.DrawGridEn=1;
|
||
currentEditTxt="";
|
||
}
|
||
void PicWidget::zkEditSave()
|
||
{
|
||
saveZhDot ();
|
||
}
|
||
void PicWidget::disp(){
|
||
|
||
}
|
||
|
||
void PicWidget::paintEvent(QPaintEvent *event){
|
||
QPainter painter(this);
|
||
QRect rect = event->rect(); //重绘部分大小。
|
||
painter.setBrushOrigin(0,40);
|
||
static bool flash=0;
|
||
flash =!flash;
|
||
int x = (int)(rect.x()/scale);
|
||
int y = (int)(rect.y()/scale);
|
||
int x_ = rect.x() + rect.width();
|
||
int y_ = rect.y() + rect.height();
|
||
int last_x = x_/scale;
|
||
int last_y = y_/scale;
|
||
for(int i = x; i < widthPoint && i <= last_x; i++){
|
||
for(int j = y; j < heightPoint && j <= last_y; j++){
|
||
QPen pen;
|
||
int width = 0;
|
||
int YM=heightPoint-1-j;
|
||
if(currXpos == i && charPara.CurrentEn && currYpos+(charPara.DrawEn?0:charPara.CharHeight-1) >= YM && currYpos <= YM ){
|
||
width = (scale>4)?1:1;// biankuang
|
||
if(flash)
|
||
pen.setColor(QColor(Qt::red));
|
||
else{
|
||
width = (scale > 6 && charPara.DrawGridEn)?1:0;
|
||
pen.setColor(QColor(Qt::gray));
|
||
}
|
||
}
|
||
else {
|
||
width = (scale > 6 && charPara.DrawGridEn)?1:0;
|
||
pen.setColor(QColor(Qt::gray));
|
||
}
|
||
|
||
pen.setWidth(width);
|
||
painter.setPen(width?pen:Qt::NoPen);
|
||
if((pointMap[i*MAX_PIC_WIDGET_HEIGHT + YM]&0x01)==1)
|
||
{
|
||
painter.setBrush(QColor(Qt::black));
|
||
}
|
||
else {
|
||
if((pointMap[i*MAX_PIC_WIDGET_HEIGHT + YM]& FLINE0)) painter.setBrush(QColor(Qt::cyan));
|
||
//else if((pointMap[i*MAX_PIC_WIDGET_HEIGHT + YM]& FCOL0 & charPara.checkBoxControlChar)) painter.setBrush(QColor(Qt::yellow)); // magenta, yellow,
|
||
else if((pointMap[i*MAX_PIC_WIDGET_HEIGHT + YM]& FVAR)) painter.setBrush(QColor(Qt::green));
|
||
else painter.setBrush(QColor(Qt::white));
|
||
}
|
||
painter.drawRect(i*scale + width,j*scale + width,scale - 2*width,scale - 2*width); //
|
||
}
|
||
}
|
||
|
||
if(zkEditEn)
|
||
emit rowColChanged(tr("编辑字符:%1").arg (currentEditTxt));
|
||
else
|
||
emit rowColChanged(tr("[%1行,%2列]").arg (heightPoint).arg (widthPoint));
|
||
|
||
emit currXYChanged(tr("光标[%1,%2]").arg (currYpos).arg (currXpos/*/charPara.CharWidth*/)); //label_CURXY
|
||
|
||
emit disp();
|
||
}
|
||
|
||
void PicWidget::resizeWidget(int w,int h){
|
||
if(w > MAX_WIDTH || h > MAX_PIC_WIDGET_HEIGHT){
|
||
QMessageBox::warning(0,tr("警告"),tr("最大支持宽度:%1 高度:%2 当前请求:%3 x %4").arg(MAX_WIDTH).arg(MAX_PIC_WIDGET_HEIGHT).arg(w).arg(h));
|
||
widthPoint = (w > MAX_WIDTH)?MAX_WIDTH:w;
|
||
heightPoint = (h > MAX_PIC_WIDGET_HEIGHT)?MAX_PIC_WIDGET_HEIGHT:h;
|
||
}
|
||
else{
|
||
widthPoint = w;
|
||
heightPoint = h;
|
||
}
|
||
resize(w*scale,h*scale);
|
||
update();
|
||
}
|
||
|
||
void PicWidget::cursorFlash()
|
||
{
|
||
if(pEditMode==0 || zkEditEn )return;
|
||
|
||
movePicView();
|
||
//update ();
|
||
update ();
|
||
if(isInput) emit ShowKeybord ();
|
||
//qDebug()<<"cur runing.";
|
||
}
|
||
|
||
int PicWidget::getFontHeight(int x,int y)
|
||
{ int res=0, xx=x*MAX_HEIGHT+y;
|
||
int font[]={5,7,9,12,16,16,24,24,32};
|
||
unsigned char c=0;
|
||
if( (c=pointMap[xx]) & (FLINE0|FCOL0))
|
||
{
|
||
res = font[(c>>1)& 0x0f] ;
|
||
if(res<line.minFont)line.minFont=res;
|
||
else if(res>line.maxFont)line.maxFont=res;
|
||
//qDebug()<<( (pointMap[xx+CFONT]>>1)& 0x0f)<<xx<< pointMap[xx+CLINESPACE] << res <<"get Height";
|
||
}
|
||
return res;
|
||
}
|
||
|
||
int PicWidget::getLineHeight(int x,int y)
|
||
{ int res=0, xx=x*MAX_HEIGHT+y;
|
||
if( pointMap[xx] & (FLINE0|FCOL0))
|
||
{
|
||
res =getFontHeight(x,y) + ((pointMap[xx+CLINESPACE] & 0x0f) >>1);
|
||
if(res<line.minLineHeight)line.minFont=res;
|
||
else if(res>line.maxLineHeight)line.maxFont=res;
|
||
// qDebug()<<( (pointMap[xx+CFONT]>>1)& 0x0f)<<xx<< pointMap[xx+CLINESPACE] << res <<"get Height";
|
||
}
|
||
return res;
|
||
}
|
||
|
||
int PicWidget::getUpLineStart(int x,int y){
|
||
int x0,x1=0,f0,f1;
|
||
f0 = getFontHeight(x,y);
|
||
// qDebug()<<"f0"<<f0;
|
||
if((f0<=0 || f0> MAX_HEIGHT-1 )&& x==0) return x1;
|
||
if(f0==0 && x>0) {
|
||
x = getPrePos(x,x);
|
||
f0 = getFontHeight(x,y);
|
||
}
|
||
while(x){
|
||
x0=x;
|
||
x = getPrePos(x,x);//32);
|
||
f1 =getFontHeight(x,y);
|
||
if(f0 < f1 ){
|
||
x1=x0;
|
||
break;
|
||
}
|
||
|
||
}
|
||
return x1;
|
||
}
|
||
int PicWidget::isCanDelete(int x,int y){
|
||
int res=0;
|
||
int xx=x*MAX_HEIGHT+y;
|
||
for(int j=4;j<charPara.CharHeight;j++){
|
||
if(pointMap[xx+j] & FLINE0) { res=1;
|
||
break;}
|
||
}
|
||
return res;
|
||
}
|
||
int PicWidget::getInserEnable(int x,int y,int w,int h){
|
||
int res=0,xx=0;
|
||
// qDebug()<<"ioh:"<<y<<h;
|
||
for(int i=0;i<w;i++)
|
||
{
|
||
xx=x*MAX_HEIGHT+y;x++;
|
||
if(( pointMap[xx] & FCOL0) &&((pointMap[xx] & FLINE0)==0))
|
||
{ res=1;break;}
|
||
// if( pointMap[xx] & FCOL0)
|
||
for(int j=4;j<h;j++){
|
||
if(pointMap[xx+j] & FLINE0) { res=1;
|
||
//qDebug()<<"ioo:"<<xx<<x<<y+j<<h<<(pointMap[xx+j] );
|
||
break;}
|
||
}
|
||
if(res)break;
|
||
}
|
||
//qDebug()<<"isEN:"<<res;
|
||
return res;
|
||
}
|
||
|
||
int PicWidget::getLineEnd(int x)
|
||
{
|
||
memset(linePara,0,sizeof(linePara));
|
||
int n=2,h=0;
|
||
while(x<MAX_WIDTH){
|
||
if( pointMap[x*MAX_HEIGHT+currYpos] & FLINE0) {
|
||
if( pointMap[x*MAX_HEIGHT+currYpos] & FCOL0) {
|
||
h=getLineHeight(x,currYpos);
|
||
if( ( linePara[n]<h))
|
||
{
|
||
if(h>linePara[0]){linePara[1]=x; linePara[0]=h;}
|
||
if( linePara[n]) {
|
||
n++;
|
||
linePara[n]=h;
|
||
}
|
||
else linePara[n]=h;
|
||
}
|
||
}
|
||
x++;
|
||
}
|
||
else break;
|
||
}
|
||
//qDebug()<<"LINEH:"<<linePara[0]<<linePara[1]<<linePara[2]<<linePara[3]<<linePara[4];
|
||
if(line.Len<x){
|
||
line.Len = x;
|
||
resizeWidget(x+24,heightPoint);
|
||
}
|
||
return x;
|
||
}
|
||
// Hline 0x40, Vline 0x80
|
||
int PicWidget::getUpLine(int x)
|
||
{ int y0,y;
|
||
y0=y=currYpos;
|
||
while(y<heightPoint-1){ //找横线
|
||
y++;
|
||
if((pointMap[x*MAX_HEIGHT+y]&FLINE0)){y0=y; break;}
|
||
}
|
||
// if(charPara.LineHeight>=5 && y==heightPoint-1){
|
||
// if(y>= currYpos+2*charPara.LineHeight) y=currYpos+charPara.LineHeight;
|
||
// y0=y;
|
||
// }
|
||
//qDebug()<<y;
|
||
return y0;
|
||
}
|
||
int PicWidget::SiteStart(int x){
|
||
if(x<=0) return 0;
|
||
//向左找竖线
|
||
while((pointMap[x*MAX_HEIGHT+currYpos]&FCOL0)==0x00){
|
||
if(x)x--;
|
||
else break;
|
||
}
|
||
return x;
|
||
}
|
||
|
||
int PicWidget::getDownLine(int x)
|
||
{ int y=currYpos-1;
|
||
while(y){
|
||
if((pointMap[x*MAX_HEIGHT+y]&FLINE0)==0x00) y--;
|
||
else break;
|
||
}
|
||
if(charPara.LineHeight>=5){
|
||
if((currYpos-y)>=2*charPara.LineHeight) y=currYpos-charPara.LineHeight;
|
||
}
|
||
|
||
return y;
|
||
}
|
||
|
||
int PicWidget::getNextPos(int x,int n)
|
||
{ int x1=x++,xx=0;
|
||
int varFlag=0;
|
||
if(( pointMap[x*MAX_HEIGHT+currYpos]&FVAR) == FVAR){
|
||
varFlag=1;
|
||
n=widthPoint-x;//124*8;
|
||
while(n--)
|
||
{
|
||
if((( pointMap[x*MAX_HEIGHT+currYpos]&FVAR) == FVAR) &&( pointMap[x*MAX_HEIGHT+currYpos]&FLINE0)) x++;
|
||
else {x++;break;}
|
||
xx++;
|
||
if(x>widthPoint-1)break;
|
||
}
|
||
if(x>=widthPoint) x=widthPoint;//{ x=x1+charPara.CharWidth;}
|
||
if(xx==0) x=x1;
|
||
return x;
|
||
}
|
||
|
||
while(n--)
|
||
{
|
||
if((( pointMap[x*MAX_HEIGHT+currYpos]&FCOL0) == 0x00) &&( pointMap[x*MAX_HEIGHT+currYpos]&FLINE0)) x++;
|
||
else break;
|
||
xx++;
|
||
//qDebug()<<"getNextPos1:"<<x<<n;
|
||
}
|
||
if(x>=widthPoint ) x=widthPoint;//{ x=x1+charPara.CharWidth;}
|
||
if(xx==0) x=x1;
|
||
//qDebug()<<"getNextPos"<<x<<n;
|
||
return x;
|
||
}
|
||
|
||
int PicWidget::getBlandPos(int x,int n)
|
||
{ int xx=0;
|
||
x++;
|
||
if(n>MAX_WIDTH-1)return 1;
|
||
while(n)
|
||
{ if(x>=MAX_WIDTH) break;
|
||
n--;
|
||
if(( pointMap[x*MAX_HEIGHT+currYpos]&(FLINE0 | FCOL0))== 0x00) x++;
|
||
else break;
|
||
// if(xx<30)xx++;else break;
|
||
}
|
||
return (n<=0);
|
||
}
|
||
|
||
int PicWidget::isVar(int x,int y) //isVar
|
||
{
|
||
return (( pointMap[x*MAX_HEIGHT+y]&FVAR) == FVAR) ;
|
||
}
|
||
|
||
int PicWidget::getPrePos(int x,int n)
|
||
{ x--;
|
||
int n0=x;
|
||
n=x;
|
||
while(n--)
|
||
{
|
||
if(x){
|
||
if(( pointMap[x*MAX_HEIGHT+currYpos]&FCOL0)) break;
|
||
x--;
|
||
}
|
||
else break;
|
||
}
|
||
if(( pointMap[x*MAX_HEIGHT+currYpos]&FVAR) == FVAR){
|
||
n=n0;
|
||
while(n--)
|
||
{
|
||
if((( pointMap[x*MAX_HEIGHT+currYpos]&FVAR) == FVAR) &&( pointMap[x*MAX_HEIGHT+currYpos]&FLINE0)) x--;
|
||
else {x++;break;}
|
||
if(x<=0) break;
|
||
|
||
}
|
||
if(x<=0) x=0;
|
||
}
|
||
return x;
|
||
}
|
||
|
||
void PicWidget::mousePressEvent ( QMouseEvent * event ){
|
||
int x = (int )(event->x()/(scale));
|
||
int y = heightPoint -(int )(event->y()/scale)-1;
|
||
static bool r_DrawEn=!charPara.DrawEn;
|
||
|
||
if(x < widthPoint && y < heightPoint){
|
||
int oriX = currXpos;
|
||
int oriY = currYpos;
|
||
|
||
if(charPara.DrawEn)
|
||
{ modified = true;
|
||
|
||
currXpos = x;
|
||
currYpos = y;
|
||
if((pointMap[x*MAX_PIC_WIDGET_HEIGHT + y]&0x1e) ==(unsigned char)(0x00))
|
||
{
|
||
if(pointMap[x*MAX_PIC_WIDGET_HEIGHT + y]&0x01)
|
||
pointMap[x*MAX_PIC_WIDGET_HEIGHT + y] &=0xfe;
|
||
else pointMap[x*MAX_PIC_WIDGET_HEIGHT + y] |=0x01;
|
||
}
|
||
if(r_DrawEn) update(oriX*scale,oriY*scale,scale,scale); //将原来的焦点去掉
|
||
else update(oriX*scale,oriY*scale,scale,scale*(charPara.LineHeight+1)); //将原来的焦点去掉
|
||
update(x*scale,y*scale,scale,scale);
|
||
emit picWidgetModify();
|
||
update();
|
||
//
|
||
}
|
||
else
|
||
{
|
||
currXpos = x;
|
||
currYpos = y;
|
||
|
||
currXpos = SiteStart(currXpos);
|
||
currYpos = getDownLine(currXpos);
|
||
// if(isVar(oriX,currYpos)) getNextPos(oriX,24*8);
|
||
// currXpos = getNextPos(currXpos,charPara.CharWidth);
|
||
|
||
if(currXpos > widthPoint) currXpos=widthPoint;
|
||
if(currXpos<0) currXpos=0;
|
||
if(currYpos<0) currYpos=0;
|
||
|
||
|
||
if(charPara.DrawEn)
|
||
{
|
||
|
||
if(currYpos>=heightPoint) currYpos=heightPoint;
|
||
if(isVar(currXpos,currYpos)){
|
||
currXpos = getNextPos( currXpos,24*8);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(isVar(currXpos,currYpos)){
|
||
currXpos = getNextPos( currXpos,24*8);
|
||
}
|
||
}
|
||
//emit movePicView();
|
||
emit ShowKeybord();
|
||
update(oriX*scale,oriY*scale,scale,scale*(charPara.LineHeight));
|
||
update(currXpos*scale,currYpos*scale,scale,scale*(charPara.LineHeight));
|
||
}
|
||
r_DrawEn=charPara.DrawEn;
|
||
|
||
}
|
||
}
|
||
int PicWidget::isBlankCol()
|
||
{ int cnt=0;
|
||
int x = currXpos*MAX_PIC_WIDGET_HEIGHT;
|
||
for(char i=0;i<charPara.LineHeight;i++)
|
||
{
|
||
cnt +=(pointMap[x+i+currYpos]&0x7f)?1:0;
|
||
if(cnt) break;
|
||
}
|
||
return cnt;
|
||
}
|
||
|
||
void PicWidget::currPositionMove(int shiftX,int shiftY){
|
||
if(widthPoint && heightPoint)
|
||
{
|
||
int oriX = currXpos;
|
||
int oriY = currYpos;
|
||
|
||
if( charPara.DrawEn==0 && charPara.CharCurrent ){
|
||
if(shiftX>0){ // right
|
||
currXpos = getNextPos(oriX,widthPoint-currXpos);
|
||
|
||
}
|
||
else if(shiftX<0){
|
||
if(currXpos)
|
||
currXpos = getPrePos(oriX,currXpos);
|
||
}
|
||
else { }
|
||
|
||
if(shiftY<0){ // UP
|
||
currYpos = getUpLine(oriX);
|
||
if(isVar(oriX,currYpos))
|
||
currXpos = getPrePos(oriX,124*8);
|
||
else currXpos = SiteStart(oriX);
|
||
|
||
}
|
||
else if(shiftY>0){
|
||
if(currYpos)
|
||
currYpos = getDownLine(oriX);
|
||
if(isVar(oriX,currYpos))
|
||
currXpos = getPrePos(oriX,124*8);
|
||
else currXpos = SiteStart(oriX);
|
||
}
|
||
else{ }
|
||
|
||
}
|
||
else {
|
||
|
||
if(shiftX>0) shiftX=1;
|
||
else if(shiftX<0) shiftX=-1;
|
||
else shiftX=0;
|
||
currXpos += shiftX;
|
||
if(currXpos<0)currXpos=0;
|
||
else if(currXpos>=widthPoint-1)currXpos=widthPoint-1;
|
||
|
||
// qDebug()<<"Y0:"<<currYpos<<shiftY;
|
||
if(shiftY>0) shiftY=-1;
|
||
else if(shiftY<0) shiftY=1;
|
||
else shiftY=0;
|
||
currYpos += shiftY;
|
||
if(currYpos<0) currYpos=0;
|
||
if(currYpos>heightPoint-1) currYpos =heightPoint-1;
|
||
// qDebug()<<"Y1:"<<currYpos<<shiftY;
|
||
|
||
|
||
|
||
}
|
||
update();
|
||
}
|
||
}
|
||
|
||
void PicWidget::ensureCurrPos(){
|
||
if(heightPoint && widthPoint && charPara.DrawEn)
|
||
{
|
||
int x = currXpos;
|
||
int y = currYpos;
|
||
if((pointMap[x*MAX_PIC_WIDGET_HEIGHT + y]&FVAR) ==(unsigned char)(0x00))
|
||
{
|
||
if(pointMap[x*MAX_PIC_WIDGET_HEIGHT + y]&0x01) pointMap[x*MAX_PIC_WIDGET_HEIGHT + y] &=0xfe;
|
||
else pointMap[x*MAX_PIC_WIDGET_HEIGHT + y] |=0x01;
|
||
}
|
||
update(x*scale,y*scale,scale,scale);
|
||
modified = true;
|
||
emit picWidgetModify();
|
||
}
|
||
}
|
||
|
||
bool PicWidget::isModified(){
|
||
return modified;
|
||
}
|
||
|
||
void PicWidget::setModified(bool m){
|
||
modified = m;
|
||
}
|
||
|
||
int PicWidget::getHeight(){
|
||
return heightPoint;
|
||
}
|
||
int PicWidget::getPicRealHeight(){
|
||
|
||
int h0= endRow-startRow+1;
|
||
if(h0>40) h0=40;
|
||
if(altPrint){
|
||
h0 = h0/2;
|
||
}
|
||
|
||
return h0;
|
||
}
|
||
|
||
int PicWidget::getWidth(){
|
||
return widthPoint;
|
||
|
||
}
|
||
|
||
int PicWidget::getScaleValue(){
|
||
return scale;
|
||
}
|
||
void PicWidget::bindSysPara(SysPara *sysPara){
|
||
//this->sysPara1 = sysPara;
|
||
}
|
||
void PicWidget::initWidget(int w,int h){
|
||
scale = 30;
|
||
if(parentWidget()){
|
||
startRow=0;
|
||
startCol=0;
|
||
QWidget *widget = parentWidget();
|
||
int width = widget->geometry().width();
|
||
int height = widget->geometry().height();
|
||
int scaleX = w?width/w:width; //不要除零
|
||
int scaleY = h?height/(h):height;
|
||
scaleX = scaleX > 0?scaleX:1; //scale不能小于零
|
||
scaleY = scaleY > 0?scaleY:1;
|
||
scale = scaleY>10?10:scaleY;// > scaleY?scaleX:scaleY;
|
||
if(charPara.DrawEn) scale=(scale<8)?8:scale;
|
||
else scale=(scale>4)?4:scale;
|
||
}
|
||
currXpos = 0;
|
||
currYpos = 0;
|
||
varNum =0;
|
||
charPara.Width = w;
|
||
//emit movePicView(1);
|
||
memset(pointMap,0,sizeof(pointMap));
|
||
resizeWidget(w,h);
|
||
modified = false;
|
||
picSetHome();
|
||
}
|
||
|
||
void PicWidget::enlargeDisplay(){
|
||
if(scale < (1<<10)){
|
||
scale = scale + ((scale>2)?scale/2:1);
|
||
resize(widthPoint*scale,heightPoint*scale);
|
||
update();
|
||
}
|
||
}
|
||
|
||
|
||
void PicWidget::reduceDisplay(){
|
||
if(scale > 1){
|
||
scale = scale - ((scale > 2)?scale/3:1);
|
||
resize(widthPoint*scale,heightPoint*scale);
|
||
update();
|
||
}
|
||
}
|
||
|
||
void PicWidget::setScale(int scale){
|
||
if(scale > 1)
|
||
this->scale = scale;
|
||
else
|
||
scale = 1;
|
||
resize(widthPoint*scale,heightPoint*scale);
|
||
update();
|
||
}
|
||
void PicWidget::insertImage1(QString filename,bool forceSize){
|
||
if((widthPoint == 0 || heightPoint == 0) && forceSize){
|
||
QMessageBox::warning(0,tr("警告"),tr("请新创建建图片"));
|
||
}
|
||
else {
|
||
QImage img(filename);
|
||
if(img.isNull()){
|
||
QMessageBox::warning(0,tr("警告"),tr("文件:%1 无法打开").arg(filename));
|
||
}
|
||
else {
|
||
int w = img.rect().width();
|
||
int h = img.rect().height();
|
||
|
||
|
||
if(widthPoint +w <MAX_WIDTH ) widthPoint +=w;
|
||
else widthPoint =MAX_WIDTH;
|
||
if(heightPoint<h)heightPoint=h;
|
||
unsigned char wRow[32];
|
||
memset(&wRow,0,sizeof(wRow));
|
||
unsigned char temp;
|
||
|
||
|
||
|
||
|
||
if(zkEditEn==0){
|
||
if(h<7) temp=0; //5
|
||
else if(h<9) temp=1;//7
|
||
else if(h<12) temp=2;//9
|
||
else if(h<16) temp=3;//12
|
||
else if(h<24) temp=4;//4,5 =>16
|
||
else temp=6; // 24
|
||
//int font[]={5,7,9,12,16,16,24,24,32};
|
||
wRow[0]=( temp<<1)& 0x1e;
|
||
if(h<7) temp=h-5; //5
|
||
else if(h<9) temp=h-7;//7
|
||
else if(h<12) temp=h-9;//9
|
||
else if(h<16) temp=h-12;//12
|
||
else if(h<24) temp=h-16;//4,5 =>16
|
||
else temp=h-24; // 24
|
||
wRow[1]=( temp <<1)& 0x1e;
|
||
wRow[2]=(charPara.FontGap <<1)& 0x1e;
|
||
wRow[3]=(charPara.Bold <<1)& 0x1e;
|
||
wRow[4]=(charPara.CharWidth <<1)& 0x1e;
|
||
wRow[5]=(charPara.LineHeight <<1)& 0x1e;
|
||
}
|
||
|
||
if(forceSize){
|
||
widthPoint =w;
|
||
heightPoint=h;
|
||
currXpos=0;
|
||
currYpos=0;
|
||
}
|
||
resizeWidget(widthPoint,heightPoint);
|
||
charInsert(w,0);
|
||
|
||
for(int i = 0; i < w;i++){
|
||
if((currXpos+ i)>=MAX_WIDTH) break;
|
||
|
||
for(int j = 0; j < h ; j++){
|
||
if((currYpos + j)>=MAX_PIC_WIDGET_HEIGHT) break; // continue;//
|
||
QRgb argb = img.pixel(i,j);
|
||
|
||
//qDebug() << "i:" << i << "j" << j << " " << QString::number(argb,16);
|
||
if((argb == 0xffffffff) ) //节约时钟周期
|
||
{
|
||
pointMap[(currXpos+i)*MAX_PIC_WIDGET_HEIGHT +(currYpos+h-1-j)] = (i?0:FCOL0) |(j<h-1?0:FLINE0) ;continue;
|
||
}
|
||
// else if((argb & 0xff000000) && (((argb&0xff0000) < 0xe00000)|| ((argb&0xff00) < 0xe000) || ((argb&0xff) < 0xe0))){
|
||
else if((argb & 0xff000000) && (((argb&0xff0000) < 0x800000)|| ((argb&0xff00) < 0x8000) || ((argb&0xff) < 0x80))){
|
||
|
||
pointMap[(currXpos+i)*MAX_PIC_WIDGET_HEIGHT +(currYpos+h-1- j)] = 0x01 |(i?0:FCOL0) |(j<h-1?0:FLINE0) ;continue;
|
||
}
|
||
else{
|
||
pointMap[(currXpos+i)*MAX_PIC_WIDGET_HEIGHT +(currYpos+h-1- j)] = (i?0:FCOL0) |(j<h-1?0:FLINE0) ;continue;
|
||
}
|
||
|
||
}
|
||
}
|
||
for(int j = 0; j < h ; j++){
|
||
pointMap[(currXpos)*MAX_PIC_WIDGET_HEIGHT +currYpos+ j] |=( FCOL0 | wRow[j]) ;
|
||
// wRow[10+my]= pointMap[(currXpos)*MAX_PIC_WIDGET_HEIGHT +currYpos+ my] & 0x1e;
|
||
}
|
||
currXpos+=w;
|
||
if(currXpos>widthPoint)currXpos=widthPoint;
|
||
update();
|
||
}
|
||
}
|
||
}
|
||
|
||
void PicWidget::insertImage(QString filename,bool forceSize){
|
||
|
||
if((widthPoint == 0 || heightPoint == 0) && forceSize){
|
||
QMessageBox::warning(0,tr("警告"),tr("请新创建建图片"));
|
||
}
|
||
else {
|
||
QImage img(filename);
|
||
if(img.isNull()){
|
||
QMessageBox::warning(0,tr("警告"),tr("文件:%1 无法打开").arg(filename));
|
||
}
|
||
else
|
||
{
|
||
int w = img.rect().width();
|
||
int h = img.rect().height();
|
||
bool isToWidth=0;
|
||
|
||
charInsert(w,0);
|
||
|
||
// widthPoint+=w;
|
||
// /* 2014-2-28 修正了插入图片造成死机问题。原因:由于数组下标溢出 */
|
||
// if(widthPoint>MAX_WIDTH){ widthPoint=MAX_WIDTH;}
|
||
// if(heightPoint>MAX_PIC_WIDGET_HEIGHT){ heightPoint=MAX_PIC_WIDGET_HEIGHT;}
|
||
// if(w+currXpos>widthPoint) {w = widthPoint-currXpos;isToWidth=1;}
|
||
// if(h+currYpos>heightPoint){ h =heightPoint-currYpos;isToWidth=1;}
|
||
|
||
// resizeWidget (widthPoint,heightPoint);
|
||
|
||
for(int i = 0; i < w;i++){
|
||
if((currXpos+ i)>=MAX_WIDTH) break;
|
||
uint c=0;uchar cc=0,c1=0;
|
||
|
||
for(int j = 0; j < h ; j++){
|
||
if((currYpos + j)>=MAX_PIC_WIDGET_HEIGHT) break; // continue;//
|
||
QRgb argb = img.pixel(i,j);
|
||
c1 = argb&0xff;
|
||
|
||
//qDebug() << "i:" << i << "j" << j << " " << QString::number(argb,16);
|
||
if((argb == 0xffffffff) ) //节约时钟周期
|
||
{
|
||
pointMap[(currXpos+i)*MAX_PIC_WIDGET_HEIGHT +(currYpos+h-1-j)] = (i?0:FCOL0) |(j<h-1?0:FLINE0) ;continue;
|
||
}
|
||
if(((argb & 0xffffff00)==0xff000000 )
|
||
||((argb & 0xffffff00)==0xffffff00 )) //节约时钟周期
|
||
{
|
||
pointMap[(currXpos+i)*MAX_PIC_WIDGET_HEIGHT +(currYpos+h-1- j)] = c1 |(i?0:FCOL0) |(j<h-1?0:FLINE0) ;continue;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
currXpos+=w;
|
||
if(currXpos>widthPoint)currXpos=widthPoint;
|
||
update();
|
||
}
|
||
}
|
||
}
|
||
void PicWidget::readPng(int x,int y,int w,int h)
|
||
{
|
||
|
||
}
|
||
|
||
void PicWidget::loadImage(QString filename,bool forceSize){
|
||
|
||
if((widthPoint == 0 || heightPoint == 0) && forceSize){
|
||
QMessageBox::warning(0,tr("警告"),tr("请新创建建图片"));
|
||
}
|
||
else {
|
||
QImage img(filename);
|
||
if(img.isNull()){
|
||
QMessageBox::warning(0,tr("警告"),tr("文件:%1 无法打开").arg(filename));
|
||
}
|
||
else
|
||
{
|
||
int w = img.rect().width();
|
||
int h = img.rect().height();
|
||
startRow=0;
|
||
startCol=0;
|
||
varNum =0;
|
||
memset(pointMap,0,sizeof(pointMap));
|
||
if(!forceSize){
|
||
widthPoint = (w > MAX_WIDTH)?MAX_WIDTH:w;
|
||
heightPoint = (h > MAX_PIC_WIDGET_HEIGHT)?MAX_PIC_WIDGET_HEIGHT:h;
|
||
resize(widthPoint*scale,heightPoint*scale);
|
||
}
|
||
// readPng(0,0,w,h);
|
||
for(int i = 0; i < widthPoint;i++){
|
||
uint c=0;uchar cc=0,c1=0;
|
||
for(int j = 0; j < heightPoint ; j++){
|
||
bool pixelVisible = false;
|
||
int init_x = i*w/widthPoint;
|
||
int end_x = (w >= widthPoint)?(i + 1)*w/widthPoint:init_x + 1;
|
||
int init_y = j*h/heightPoint;
|
||
int end_y = (h >= heightPoint)?(j + 1)*h/heightPoint:init_y + 1;
|
||
c=0;
|
||
for(int l = init_x; l < end_x; l++){
|
||
for(int m = init_y; m < end_y; m ++){
|
||
QRgb argb = img.pixel(l,m);
|
||
c1 = argb&0xff;
|
||
|
||
//qDebug() << "i:" << i << "j" << j << " " << QString::number(argb,16);
|
||
if((argb == 0xffffffff) ) //节约时钟周期
|
||
{
|
||
continue;
|
||
}
|
||
if(((argb & 0xffffff00)==0xff000000 )
|
||
||((argb & 0xffffff00)==0xffffff00 )) //节约时钟周期
|
||
{
|
||
c = c1;
|
||
pixelVisible = true;
|
||
break;
|
||
}
|
||
}
|
||
if(pixelVisible || c) break;
|
||
}
|
||
pointMap[i*MAX_PIC_WIDGET_HEIGHT +(heightPoint-1- j)] = c;
|
||
}// one col end
|
||
}
|
||
currXpos=0;
|
||
currYpos=0;
|
||
//currMode = cal_currHeight()>0;
|
||
line.Len=widthPoint;
|
||
charPara.LineHeight =getLineHeight(0,0);
|
||
if( getLineEnd(0)<5) {
|
||
qDebug()<<"FILE TYPE ERROR!";
|
||
}
|
||
update();
|
||
}
|
||
}
|
||
}
|
||
|
||
void PicWidget::getPrintDat(unsigned char *dat,unsigned char alt2,SysPara *sysPara)
|
||
{
|
||
if(!sysPara ) return;
|
||
int res=0;
|
||
res = resizePicRect(alt2);
|
||
|
||
int hStart,hEnd;
|
||
int h= endRow-startRow+1;//
|
||
|
||
hStart= (alt2>1)?h>>1:0;
|
||
hEnd = (alt2==1)?h>>1 :h;
|
||
|
||
for(int i = 0 ; i < widthPoint; i++)
|
||
{
|
||
unsigned char c=0,c1=0;
|
||
int j=0;
|
||
for( j = hStart; j < hEnd; j++)
|
||
{
|
||
c |= (pointMap[(i)*MAX_PIC_WIDGET_HEIGHT+startRow + h-1-j]&0x01)? (1 << (j%8)):0;
|
||
if(j%8==7) { dat[i*5+(j-hStart)/8]=c; c=0; }
|
||
}
|
||
dat[i*5+(j-hStart)/8]=c;
|
||
}
|
||
}
|
||
|
||
/* ===============================================
|
||
040608 121416 242628 32343638 4648 52545658 646668 727476787A 848688 949698
|
||
02 0A 16 22 2A 3A 44 48 52 62 7A 82 8A 92 9A
|
||
02 0A 16 2A 3A 44 48 52 62 7A 82 8A 92 9A
|
||
02 0A 16 2A 343638 42 48 52545658 62646668 78 848688 92 9A
|
||
02 0A 16 28 3A 42 48 5A 62 6A 78 82 8A 9496989A
|
||
02 0A 16 26 3A 424446484A 5A 62 6A 76 82 8A 9A
|
||
03 0B 17 25 3B 49 5B 63 6B 77 83 8B 9B
|
||
050709 131517191B 232527292B 33353739 49 53555759 656769 77 858789 93959799
|
||
=============================================== */
|
||
|
||
void PicWidget::getCharRamData(SysPara *sysPara)
|
||
{
|
||
// 生成字模数据
|
||
if(sysPara->status.variNum)
|
||
{
|
||
int ramAddress = 0;
|
||
if(sysPara->status.variNum>8)sysPara->status.variNum=8;
|
||
|
||
for(int i = 0; i < sysPara->status.variNum; i++){
|
||
|
||
vars_t *p_var = &sysPara->status.vars[i];
|
||
p_var->bassAddr = -1;
|
||
if(p_var->original){ //清除原来的记录
|
||
if(p_var->dat){
|
||
free(p_var->dat);
|
||
}
|
||
p_var->original = false;
|
||
}
|
||
for(int j = 0; j < i; j ++){ //重复检测是否有重复大小的字存在
|
||
if((p_var->height == sysPara->status.vars[j].height)
|
||
&&(p_var->width/p_var->digitalNum == sysPara->status.vars[j].width/sysPara->status.vars[j].digitalNum ))
|
||
{
|
||
p_var->bassAddr = sysPara->status.vars[j].bassAddr;
|
||
p_var->datHeight = sysPara->status.vars[j].datHeight;
|
||
p_var->datWidth = sysPara->status.vars[j].datWidth;
|
||
p_var->rowByteNum = sysPara->status.vars[j].rowByteNum;
|
||
p_var->dat = sysPara->status.vars[j].dat;
|
||
break;
|
||
}
|
||
}
|
||
if(p_var->bassAddr == -1){
|
||
int width = (p_var->digitalNum)?(p_var->width/p_var->digitalNum):5;
|
||
int height = p_var->height;
|
||
if(p_var->digitalNum>8 || p_var->type >9
|
||
|| p_var->digitalNum<2 || p_var->width<5
|
||
|| p_var->height<5 || p_var->height>24
|
||
|| p_var->type <0 ||p_var->letterSpace >5
|
||
|| p_var->letterSpace <0
|
||
)
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 先根据变量高度,选择一种字体,然后读出0~9的字模,然后进行行列转换,存储到p_var->dat
|
||
//char font[]={5,7,9,12,16,16,24,24,32};
|
||
if(p_var->height>=18) charPara.Font=ST24;
|
||
else if(p_var->height>=13) {
|
||
charPara.Font=p_var->width/p_var->digitalNum-p_var->letterSpace==(p_var->bold?24:12)?HT16:ST16;
|
||
}
|
||
else if(p_var->height>=10) charPara.Font=ST12;
|
||
else if(p_var->height>=8) charPara.Font=ST09;
|
||
else if(p_var->height>=6) charPara.Font=ST07;
|
||
else charPara.Font=ST05;
|
||
|
||
width = (p_var->digitalNum)?(10*p_var->width/p_var->digitalNum):12;
|
||
|
||
int zm_width = 11* width;
|
||
int zm_height = p_var->height;
|
||
unsigned char pMap[(zm_width+10)*40]; // >720
|
||
|
||
charPara.LineSpace = p_var->letterSpace;
|
||
//memset(zm,0,sizeof(zm));
|
||
memset(pMap,0,sizeof(pMap));
|
||
inputRamDot (QString("0123456789"),pMap, p_var);// READ DOT FROM ASB.BIN
|
||
|
||
int rowDiff = p_var->endRowPos - p_var->startRowPos;
|
||
int firstValidRow;
|
||
int lastValidRow = 0;
|
||
int firstValidRowDiff;
|
||
if(lastValidRow >= rowDiff){
|
||
firstValidRow = lastValidRow - rowDiff;
|
||
firstValidRowDiff = firstValidRow;
|
||
}
|
||
else {
|
||
firstValidRow = 0;
|
||
firstValidRowDiff = lastValidRow > rowDiff;
|
||
}
|
||
firstValidRow = firstValidRow >= 0?firstValidRow:0; //纠正 第一行位置
|
||
int rowByteNum = rowDiff/8 + ((rowDiff%8)?1:0); // 行数
|
||
|
||
unsigned char *dat = (unsigned char *)calloc(width,rowByteNum);
|
||
|
||
for(int k = zm_height - 1; k >= 0 ; k--){
|
||
for(int j = 0; j < zm_width; j ++){
|
||
if(pMap[j*MAX_PIC_WIDGET_HEIGHT+k]&0x01){
|
||
lastValidRow = k + 1;
|
||
break;
|
||
}
|
||
}
|
||
if(lastValidRow != 0)
|
||
break;
|
||
}
|
||
for(int k = firstValidRow; k < lastValidRow; k++){
|
||
for(int j = 0; j < width; j ++){
|
||
int currRow = k - firstValidRowDiff;
|
||
if(pMap[j*MAX_PIC_WIDGET_HEIGHT+k]&0x01){
|
||
dat[rowByteNum*j + currRow/8] |= (1<<(currRow%8));
|
||
}
|
||
else{
|
||
}
|
||
}
|
||
}
|
||
p_var->bassAddr = ramAddress;
|
||
p_var->datHeight = height;
|
||
p_var->datWidth = width;
|
||
p_var->rowByteNum = rowByteNum;
|
||
p_var->dat = dat;
|
||
p_var->original = true;
|
||
p_var->currVal = -1; //相当于初始化
|
||
ramAddress += rowByteNum * width;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
int PicWidget::readVar(SysPara *sysPara, unsigned char alt2)// alt2 =0,1,2
|
||
{
|
||
if(sysPara)
|
||
{
|
||
varNum=0; // _______SAMW
|
||
altPrint = alt2;
|
||
resizePicRect(alt2);
|
||
|
||
for(int j = 0; j < heightPoint; j++)
|
||
{
|
||
line.maxFont=MAX_HEIGHT;line.minFont =0; // start
|
||
|
||
for(int i = 0 ; i < widthPoint; i++)
|
||
{
|
||
getLineHeight(i,j); // cal min lineHeight, max lineHeight
|
||
|
||
unsigned char c[6];
|
||
unsigned char c1=pointMap[i*MAX_PIC_WIDGET_HEIGHT + j];
|
||
|
||
if((c1 & FCOL0 ) && (c1 & FLINE0) && (c1 & FVAR))
|
||
{ // 定位变量的起点
|
||
// // W0 ==font V1 = type V2 = diginum V3 = width
|
||
c1=(pointMap[(i+VTYPE)*MAX_PIC_WIDGET_HEIGHT + j] >>1)& 0x0f; //type
|
||
c[0]=(pointMap[(i+CFONT)*MAX_PIC_WIDGET_HEIGHT + j] >>1)& 0x0f; //font
|
||
if(c1 > 9 && c1 != 13) continue; //type,cnt3 is 13
|
||
c[1]=c1;
|
||
// qDebug ()<<"C1"<<c1;
|
||
if( VarGetWidth(i,j,c)==0) continue; // digit
|
||
// qDebug ()<<"C2"<<c1;
|
||
if(varNum < MAX_VARI_NUM)
|
||
{
|
||
sysPara->status.vars[varNum].type=c[VTYPE];
|
||
sysPara->status.vars[varNum].digitalNum=c[VDIGIT];
|
||
sysPara->status.vars[varNum].width=c[VWIDTH];
|
||
sysPara->status.vars[varNum].height =getFontHeight(i,j);
|
||
sysPara->status.vars[varNum].startColPos =i;
|
||
sysPara->status.vars[varNum].startRowPos=endRow+1-(j+sysPara->status.vars[varNum].height);
|
||
sysPara->status.vars[varNum].endRowPos=endRow+1-(j);
|
||
c1=(pointMap[(i)*MAX_PIC_WIDGET_HEIGHT + j+ CFONTGAP] >>1)& 0x0f; //font
|
||
sysPara->status.vars[varNum].letterSpace= c1>5?5:c1;
|
||
}
|
||
|
||
varNum++;
|
||
if(varNum>8){
|
||
varNum=8;
|
||
QMessageBox::warning(this,tr("警告"),tr("信息中的变量数超过了最大值(8)!请减小变量数."));
|
||
break;
|
||
}
|
||
i+=c[VWIDTH]-1;
|
||
|
||
}
|
||
|
||
|
||
}
|
||
j+=line.minLineHeight?line.minLineHeight-1:0;
|
||
}
|
||
//startCol =0;
|
||
sysPara->status.variNum=varNum;
|
||
//qDebug()<<"varn:"<<sysPara->status.variNum;
|
||
} // end of if(sysPara)
|
||
return varNum;
|
||
}
|
||
|
||
// resizePicRect();
|
||
int PicWidget::resizePicWidth(bool rowEn)
|
||
{
|
||
//int w=0,Flag=0;
|
||
startCol=0;
|
||
endCol=0;
|
||
for(int j = 0; j < heightPoint; j++){
|
||
{
|
||
for(int i = endCol ; i < widthPoint; i++)
|
||
if(((pointMap[i*MAX_PIC_WIDGET_HEIGHT + j]&0x01))||((pointMap[i*MAX_PIC_WIDGET_HEIGHT + j]&FLINE0)))
|
||
{
|
||
if(endCol<i) endCol=i;
|
||
}
|
||
}
|
||
}
|
||
endCol++;
|
||
widthPoint= endCol<MAX_WIDTH-1? endCol:MAX_WIDTH-1;
|
||
return 0;
|
||
}
|
||
|
||
int PicWidget::resizePicRect(bool alt2)
|
||
{
|
||
|
||
bool Flagy=0;
|
||
int lastLinePos=0,lastLineHeigt=0;
|
||
startRow=0;
|
||
startCol=0;
|
||
endRow=0;
|
||
endCol=0;
|
||
for(int j = 0; j < heightPoint; j++)
|
||
{
|
||
for(int i = 0 ; i < widthPoint; i++)
|
||
{
|
||
if((pointMap[i*MAX_PIC_WIDGET_HEIGHT + j]&0x01)==1)
|
||
{
|
||
if(Flagy==0){
|
||
Flagy=1;
|
||
startRow=j;
|
||
}
|
||
if(endRow<j) endRow=j;
|
||
if(endCol<i) endCol=i;
|
||
}
|
||
if((pointMap[i*MAX_PIC_WIDGET_HEIGHT + j]& FLINE0 )) // 检测行标志
|
||
{
|
||
if(lastLinePos<j) lastLinePos=j;
|
||
}
|
||
}
|
||
}
|
||
if(alt2){
|
||
startRow=0;
|
||
//endRow= heightPoint-1 ;
|
||
}
|
||
else {
|
||
startRow=0;
|
||
//
|
||
if(lastLinePos<endRow) lastLineHeigt=endRow-lastLinePos;
|
||
//qDebug()<<endRow<<lastLinePos<<lastLineHeigt;
|
||
if(lastLineHeigt>21 ) endRow=lastLinePos+23;
|
||
else if(lastLineHeigt>16) ;
|
||
else if(lastLineHeigt>13) endRow=lastLinePos+15;
|
||
else if(lastLineHeigt>10) endRow=lastLinePos+11;
|
||
else if(lastLineHeigt>7) endRow=lastLinePos+8;
|
||
else if(lastLineHeigt>5) endRow=lastLinePos+6;
|
||
|
||
}
|
||
return startRow;
|
||
}
|
||
|
||
/*
|
||
文件格式说明
|
||
1. 在图像文件中,存储变量信息,D0=1表示有点,D0=0表示无点
|
||
2.地址 信息D6~D1
|
||
0 0xaa
|
||
1 varNum
|
||
2 0x68
|
||
3
|
||
3. 变量参数 隐藏在变量占位符中D6~D1
|
||
列编号 变量信息(1~128)
|
||
0 类型+1
|
||
1 位数+1
|
||
2 字符宽度(点)/2 +1
|
||
3 字符高度(点)+1
|
||
4 字符间隔+1
|
||
*/
|
||
|
||
void PicWidget::saveImage(QString filename){
|
||
if(widthPoint == 0 || heightPoint == 0){
|
||
QMessageBox::warning(0,"警告","请新创建图片");
|
||
}
|
||
else {
|
||
update ();
|
||
resizePicWidth(0);
|
||
// resizePicRect(0);
|
||
QSize size(widthPoint,heightPoint);
|
||
QImage image(size,QImage::Format_ARGB32);
|
||
image.fill(qRgba(0,0,0,0xff));
|
||
for(int i = 0 ; i < widthPoint; i++){
|
||
for(int j = 0; j < heightPoint; j++){
|
||
uint c = 0;
|
||
uchar cc= pointMap[( i)*MAX_PIC_WIDGET_HEIGHT +(heightPoint-1- j)];
|
||
if((cc&0x01)==1)
|
||
{
|
||
c=0xff000000 | (cc) ;
|
||
}
|
||
else
|
||
{
|
||
if(cc==0) c=0xffffffff;
|
||
else c = 0xffffff00 | (cc);
|
||
}
|
||
image.setPixel(i,j,c);
|
||
}
|
||
}
|
||
image.save(filename);
|
||
}
|
||
setModified(false);
|
||
}
|
||
|
||
void PicWidget::saveImage1(QString filename){
|
||
if(widthPoint == 0 || heightPoint == 0){
|
||
QMessageBox::warning(0,"警告","请新创建建图片");
|
||
}
|
||
else {
|
||
QSize size(widthPoint,heightPoint);
|
||
QImage image(size,QImage::Format_ARGB32);
|
||
image.fill(qRgba(0,0,0,0xff));
|
||
for(int i = 0 ; i < widthPoint; i++){
|
||
for(int j = 0; j < heightPoint; j++){
|
||
image.setPixel(i,j,pointMap[i*MAX_PIC_WIDGET_HEIGHT +heightPoint-1- j]?0xff000000:0xffffffff);
|
||
}
|
||
}
|
||
filename = DOC_ROOT_DIR+ QFileInfo(filename).baseName()+".jpg";
|
||
image.save( filename );
|
||
}
|
||
setModified(false);
|
||
}
|
||
|
||
int PicWidget::picDelOneChar()
|
||
{
|
||
int posx =currXpos;
|
||
emit picWidgetModify();
|
||
if(zkEditEn)
|
||
{
|
||
memset(pointMap,0,40*40);
|
||
resizeWidget (widthPoint,heightPoint);
|
||
update ();
|
||
return 0;
|
||
}
|
||
|
||
if(posx==0)return 0;
|
||
if(isCanDelete(currXpos,currYpos)) return -1;
|
||
currXpos = getPrePos(posx,posx);//32);
|
||
picDelNextChar( );
|
||
|
||
return 0;
|
||
#if 0
|
||
int posxEnd = getLineEnd(posx);
|
||
int posx2 = getPrePos(posx,32);
|
||
//=========================
|
||
#ifdef FONTMATCH //是否需要匹配字体能操作
|
||
if(getFontHeight(posx2,posy)!=charPara.CharHeight)return posx;
|
||
#endif
|
||
|
||
if(posxEnd>posx && posx2<posx)
|
||
{//13 0 24 30 172
|
||
qDebug()<<"DelPre:"<<linePara[0]<<posx<<posx2<<posxEnd;
|
||
moveDots(posx2,posxEnd,posy,linePara[0],posx2-posx);
|
||
currXpos = posx2;
|
||
}
|
||
else {
|
||
if(posxEnd==posx) {
|
||
|
||
qDebug()<<"DelPre2:"<<getLineHeight(posx2,posy)<<posx<<posx2<<posxEnd;
|
||
delDots(posx2,posxEnd,posy,getLineHeight(posx2,posy));
|
||
currXpos = posx2;
|
||
}
|
||
}
|
||
resizeWidget (widthPoint,heightPoint);
|
||
movePicView();
|
||
modified=true;
|
||
return posx;
|
||
#endif
|
||
}
|
||
|
||
int PicWidget::picDelNextChar()
|
||
{
|
||
int posx =currXpos;
|
||
int posy =currYpos;
|
||
// int i,j;
|
||
emit picWidgetModify();
|
||
if(zkEditEn)
|
||
{
|
||
memset(pointMap,0,40*40);
|
||
resizeWidget (widthPoint,heightPoint);
|
||
update ();
|
||
return 0;
|
||
}
|
||
#ifdef FONTMATCH //是否需要匹配字体能操作
|
||
if(getFontHeight(posx,posy)!=charPara.CharHeight)return posx;
|
||
#endif
|
||
if(isCanDelete(currXpos,currYpos)) return -1;
|
||
int posx1 = getLineEnd(posx);
|
||
int posx2 = getNextPos(posx,widthPoint-1);
|
||
|
||
if(posx1>posx && posx2>posx)
|
||
{//13 0 24 30 172
|
||
//qDebug()<<"DelNext:"<<linePara[0]<<posx<<posx2<<posx1;
|
||
//delDots(posx,posx2,posy,linePara[0]);
|
||
delDots(posx,posx2,posy,getLineHeight(posx,posy));
|
||
moveDots(posx,posx1,posy,linePara[0],posx-posx2);
|
||
}
|
||
else {
|
||
|
||
}
|
||
if(posx1>=line.Len)
|
||
{
|
||
line.Len -=posx-posx2;
|
||
//line.Len;
|
||
resizeWidget(line.Len,heightPoint);
|
||
}
|
||
movePicView();
|
||
update ();
|
||
return posx;
|
||
}
|
||
|
||
void PicWidget::delDots(int x1,int x2,int y1,int h){
|
||
int i,j;
|
||
for(i=x1;i<x2;i++) {
|
||
int xx0=(i)*MAX_PIC_WIDGET_HEIGHT+y1;
|
||
for(j=0;j< h;j++) {
|
||
pointMap[xx0+j]=0x00 ;
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
void PicWidget::moveDots(int x1,int x2,int y1,int h,int w)
|
||
{
|
||
int i=0,j=0;
|
||
int h1=h;
|
||
if(w==0) return ;
|
||
else if(w>0){
|
||
int xMaxPos= linePara[1];//
|
||
for(i=x2-1;i>=x1;i--) {
|
||
|
||
if(i<xMaxPos){
|
||
getLineEnd(x1);
|
||
h=linePara[0];
|
||
xMaxPos= linePara[1];
|
||
}
|
||
for(j=0;j< h;j++) {
|
||
pointMap[(i+w)*MAX_PIC_WIDGET_HEIGHT +y1+j]=
|
||
pointMap[i*MAX_PIC_WIDGET_HEIGHT +y1+j];
|
||
pointMap[i*MAX_PIC_WIDGET_HEIGHT +y1+j]=0;
|
||
}
|
||
|
||
}
|
||
for(i=0;i<w;i++) {
|
||
for(j=0;j< h;j++) {
|
||
// pointMap[ (x1+i) *MAX_PIC_WIDGET_HEIGHT +y1+j] = (j==0)? FLINE0:0;
|
||
}
|
||
}
|
||
}
|
||
else {
|
||
w=-w;
|
||
int xx0,xx1;
|
||
if(x1+w==x2){
|
||
delDots(x1,x2,y1,h);
|
||
}
|
||
|
||
for(i=x1;i<x2-w;i++) {
|
||
xx0=(i)*MAX_PIC_WIDGET_HEIGHT+y1;
|
||
xx1=(i+w)*MAX_PIC_WIDGET_HEIGHT+y1;
|
||
if(( pointMap[xx1] & (FCOL0 | FLINE0))==(FCOL0 | FLINE0)) h1=getLineHeight(i+w,y1);
|
||
for(j=1;j< h1;j++) {
|
||
if(( pointMap[xx0+j]& (FCOL0 | FLINE0))==(FCOL0 | FLINE0)) return;
|
||
}
|
||
|
||
for(j=0;j< h1;j++) {
|
||
pointMap[xx0+j]= pointMap[xx1+j];
|
||
pointMap[xx1+j]=0x00;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
// 插入信息还会有死机。 自动退出,应该是下标溢出。2014021
|
||
int PicWidget::charInsert(int w,bool txtMode)
|
||
{
|
||
emit picWidgetModify();
|
||
if(zkEditEn) {
|
||
widthPoint= (charPara.CharWidth<5)?5:charPara.CharWidth-charPara.FontGap;
|
||
heightPoint =(charPara.CharHeight<5)?5:charPara.CharHeight;
|
||
currXpos=0;
|
||
currYpos=0;
|
||
scale = 160/heightPoint;
|
||
memset(pointMap,0,40*40);
|
||
resizeWidget (widthPoint,heightPoint);
|
||
return 0;
|
||
}
|
||
if(!charPara.insertMode)return 0;
|
||
if(txtMode){
|
||
unsigned char ww=0;
|
||
for(int i=0;i<charPara.Bold+1;i++)ww+=w;
|
||
w=ww;
|
||
}
|
||
int posx1 = getLineEnd(currXpos);
|
||
int posx2 = getBlandPos(posx1,w);
|
||
int posy1 =currYpos;
|
||
// qDebug()<<"INsert:"<<linePara[0]<<currXpos<<posx1<<charPara.CharWidth<<posx2<<w;
|
||
if((pointMap[posx1*MAX_PIC_WIDGET_HEIGHT+posy1] & (FCOL0 | FVAR)) &&((pointMap[posx1*MAX_PIC_WIDGET_HEIGHT+posy1] & FLINE0)==0x00 ))return -1;
|
||
if(isVar(currXpos,currYpos)){
|
||
if(
|
||
(( pointMap[currXpos*MAX_PIC_WIDGET_HEIGHT+posy1] & FCOL0)==0x00)
|
||
||(( pointMap[currXpos*MAX_PIC_WIDGET_HEIGHT+posy1] & FLINE0)==0x00)
|
||
) return -1;
|
||
if(currXpos){
|
||
if((( pointMap[(currXpos-1)*MAX_PIC_WIDGET_HEIGHT+posy1] & FVAR))
|
||
)
|
||
{ getPrePos(currXpos,currYpos); return -1;}
|
||
|
||
}
|
||
}
|
||
if(posx1>currXpos && posx2){
|
||
|
||
moveDots(currXpos,posx1,posy1,linePara[0],w); //
|
||
|
||
}
|
||
else if(posx1==currXpos && posx2){
|
||
if( pointMap[posx1*MAX_PIC_WIDGET_HEIGHT+posy1] & (FCOL0 | FVAR)) {
|
||
// qDebug()<<"INsert1:"<<linePara[0]<<currXpos<<posx1<<charPara.CharWidth<<posx2;
|
||
return -1;
|
||
}
|
||
|
||
}
|
||
else {
|
||
if(posx2-posx1>w){
|
||
// qDebug()<<"INsert2:";
|
||
}
|
||
else{
|
||
//qDebug()<<"INsert3:";
|
||
return -1;
|
||
}
|
||
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
char PicWidget::getZkPic(char *dat)
|
||
{ int n=0;
|
||
QString s="S-",s1;
|
||
for(int i=0;i<charPara.CharHeight;i++)
|
||
{ int j=0;
|
||
for( j=0;j<charPara.CharWidth-charPara.FontGap;j++)
|
||
{
|
||
if((pointMap[j*MAX_PIC_WIDGET_HEIGHT + charPara.CharHeight-1-i ]&0x01)&&(j<charPara.CharWidth))
|
||
dat[n] |=(1<<(7-(j%8)));
|
||
|
||
if((j%8)==7) {//qDebug ()<<"Y"<<j;
|
||
n++; }
|
||
|
||
}
|
||
if(j%8) {
|
||
n++;}
|
||
}
|
||
return n;
|
||
}
|
||
|
||
void PicWidget::saveZhDot()
|
||
{
|
||
if(pzkEditFile->isOpen ()) pzkEditFile->close ();
|
||
pzkEditFile->open (QIODevice::ReadWrite);
|
||
char dot[100];
|
||
///for(int i=0;i<100;i++)dot[i]=0;
|
||
memset(dot,0,sizeof(dot));
|
||
getZkPic(dot); //
|
||
//qDebug ()<<"zk-2-"<<pzkEditFile->fileName ()<<zkOffset<<zkReadNum;
|
||
pzkEditFile->seek(zkOffset);
|
||
pzkEditFile->write(dot,zkReadNum);
|
||
pzkEditFile->close ();
|
||
}
|
||
|
||
void PicWidget::readAscDot(unsigned int asc,char *dot)
|
||
{
|
||
int offset1[]={BIN0805,BIN0808,BIN0810,BIN0812,BIN0816,BIN1616,BIN2424,BIN2424,BIN2424};
|
||
int fontNum[]= {8,8,10,12,16,32,72,72,72 };
|
||
int fontHeight[]={5,7,9,12,16,16,24,24,24 };
|
||
int fontWidth[]= {5,5,7,8,8,12,24,24,24 };
|
||
QFile *pzkFile;
|
||
pzkFile = (QFile * )&zkAsc;
|
||
if(!pzkFile->isOpen ()) pzkFile->open (QIODevice::ReadWrite);
|
||
pzkEditFile = (QFile * )pzkFile;
|
||
charPara.CharHeight = fontHeight[charPara.Font];
|
||
charPara.CharWidth = fontWidth [charPara.Font]+charPara.FontGap;
|
||
charPara.LineHeight = charPara.CharHeight +charPara.LineSpace;
|
||
zkReadNum = fontNum[charPara.Font];
|
||
zkOffset = asc*fontNum[charPara.Font]+offset1[charPara.Font];
|
||
pzkFile->seek(zkOffset);
|
||
pzkFile->read(dot,zkReadNum);
|
||
//qDebug ()<<"EN"<<charPara.CharWidth<<charPara.FontGap<<charPara.LineHeight;
|
||
//pzkFile->close ();
|
||
}
|
||
|
||
void PicWidget::readZhDot(unsigned int ingb,char *dot )
|
||
{
|
||
unsigned int gbCode=0;
|
||
unsigned char gbcode[4];
|
||
if(!unitogb.isOpen ()) unitogb.open (QIODevice::ReadWrite);
|
||
unitogb.seek (ingb);
|
||
unitogb.read ((char*)gbcode,2);
|
||
unitogb.close ();
|
||
gbCode = (gbcode[0]<<8)+gbcode[1];
|
||
|
||
QFile *pzkFile1[]={&zkHz05,&zkHz07,&zkHz09,&zkHz12,&zkHz16,&zkHz16H,&zkHz24,&zkHz24H,&zkHz24H};
|
||
int fontNum[]= {8,16,20,24,32,32,72,72,72 };
|
||
int fontHeight[]={5,8,10,12,16,16,24,24,24 };
|
||
int fontWidth[]= {8,8,9,12,16,16,24,24,24 };
|
||
// qDebug()<<QString().sprintf("%02X",gbcode[0])<<QString().sprintf("%02X",gbcode[1])<<QString().sprintf("%02X",gbCode);
|
||
if((gbcode[0]>=0xa1)&&(gbcode[0]<=0xff))
|
||
{
|
||
//qDebug()<<QString().sprintf("%02X",gbcode[0])<<QString().sprintf("%02X",gbcode[1])<<QString().sprintf("%02X",gbCode);
|
||
charPara.CharWidth = fontWidth[charPara.Font]+charPara.FontGap;
|
||
charPara.CharHeight = fontHeight[charPara.Font];
|
||
charPara.LineHeight = charPara.CharHeight +charPara.LineSpace;
|
||
pzkEditFile = (QFile * )pzkFile1[charPara.Font];
|
||
if(!pzkEditFile->isOpen ())
|
||
pzkEditFile->open (QIODevice::ReadWrite);
|
||
zkReadNum = fontNum[charPara.Font];
|
||
zkOffset =(gbcode[0]-0xa1)*zkReadNum*94+(gbcode[1]-0xa1)*zkReadNum; //区位码=区字节+位字节 16*2
|
||
pzkEditFile->seek(zkOffset);
|
||
pzkEditFile->read(dot,zkReadNum); // write to stderr
|
||
//qDebug ()<<"CH:"<<pzkEditFile->fileName ()<<zkOffset<<zkReadNum;
|
||
}
|
||
}
|
||
|
||
int PicWidget::inputTxtDot (QString txt,int *var)
|
||
{
|
||
char dot[100];
|
||
unsigned int k=0,code_index=0;
|
||
unsigned int len=txt.length ();
|
||
if(len==0) return 0;
|
||
unsigned char txt_code[50];
|
||
|
||
if(zkEditEn && var[0]) return 0;
|
||
|
||
memcpy(&txt_code[0], txt.unicode (),2*len);
|
||
if(var[0]>0 && var[0]<10) {
|
||
if(currYpos){
|
||
if( pointMap[(currXpos)*MAX_PIC_WIDGET_HEIGHT +currYpos-1]&0x1e){
|
||
QMessageBox::warning(this,tr("警告"),tr("两个变量之间至少要空出一个墨点!"));
|
||
return 0;
|
||
}
|
||
|
||
}
|
||
if(varNum<7) varNum++;
|
||
|
||
if(currXpos>5){
|
||
if( pointMap[(currXpos-1)*MAX_PIC_WIDGET_HEIGHT +currYpos]&0x1e) // have cnt?
|
||
{
|
||
QMessageBox::warning(this,tr("警告"),tr("两个变量之间至少要空出一个墨点!"));
|
||
return 0;
|
||
}
|
||
}
|
||
}
|
||
code_index=0;
|
||
currentEditTxt =txt;
|
||
int r_heightPoint =heightPoint;
|
||
int r_widthPoint =widthPoint;
|
||
if( widthPoint>MAX_WIDTH)
|
||
{
|
||
widthPoint=MAX_WIDTH;
|
||
return 0;
|
||
}
|
||
if( currXpos >=MAX_WIDTH )
|
||
{
|
||
currXpos=MAX_WIDTH;
|
||
return 0;
|
||
}
|
||
|
||
while(k<len)
|
||
{
|
||
unsigned int incode = (txt_code[code_index+1]*256)+txt_code[code_index];
|
||
k++;code_index+=2;
|
||
|
||
if(incode>=0x20 && incode<0x80)
|
||
{ // ascii
|
||
zkIncode = (incode & 0x7f)-0x20;
|
||
readAscDot(zkIncode,dot);
|
||
if(getInserEnable(currXpos,currYpos,charPara.CharWidth,charPara.CharHeight)) {
|
||
return -1;
|
||
}
|
||
if(charInsert(charPara.CharWidth,1)<0){
|
||
return -1;
|
||
}
|
||
|
||
if(var[0]) currXpos +=varDotMap(dot,var);
|
||
else currXpos +=charDotMap(dot,1);
|
||
}
|
||
// 先处理特殊功能键
|
||
else if(incode<0x20 )// if(txt.at (0).toLatin1 ()<0x20)
|
||
{
|
||
if( txt.at (0).toLatin1 () =='\n') // enter key key
|
||
{
|
||
zkIncode = (0x30)-0x20;
|
||
readAscDot(zkIncode,dot);
|
||
if( charPara.CharCurrent){
|
||
int h0=getLineHeight(currXpos,currYpos);
|
||
if(h0<charPara.LineHeight) h0=charPara.LineHeight;
|
||
if(( currYpos+h0+charPara.CharHeight<MAX_PIC_WIDGET_HEIGHT))
|
||
{
|
||
currXpos=getUpLineStart(currXpos,currYpos); //??
|
||
//qDebug()<<"EN_X"<<currXpos<<h0;
|
||
currYpos =currYpos+h0;
|
||
//qDebug()<<"EN_X"<<currXpos<<currYpos<<h0;
|
||
heightPoint=(heightPoint < currYpos+charPara.LineHeight)?(currYpos+charPara.LineHeight):heightPoint;
|
||
if(lineNum>=lineMaxNum){ if(lineMaxNum<MAXLINE) lineMaxNum=++lineNum;}
|
||
else lineNum++;
|
||
resizeWidget (widthPoint, heightPoint);
|
||
return 0;
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
else if(incode==178 )
|
||
{
|
||
k++;
|
||
incode = (txt_code[code_index+1]*256)+txt_code[code_index];
|
||
code_index+=2;
|
||
zkIncode =95 ; //95 194-178 = 16
|
||
readAscDot(zkIncode,dot);
|
||
if(getInserEnable(currXpos,currYpos,charPara.CharWidth,charPara.CharHeight)) return -1;
|
||
if(charInsert(charPara.CharWidth,1)<0)return -1;
|
||
currXpos +=charDotMap(dot,1);
|
||
}
|
||
else
|
||
{
|
||
if(incode>=4000)
|
||
{
|
||
zkIncode = (incode-0x0020)*2;
|
||
readZhDot(zkIncode,dot);
|
||
if(getInserEnable(currXpos,currYpos,charPara.CharWidth,charPara.CharHeight)) return -1;
|
||
if(charInsert(charPara.CharWidth,1)<0)return -1;
|
||
currXpos +=charDotMap(dot,0);
|
||
}
|
||
|
||
}
|
||
modified = true;
|
||
emit picWidgetModify();
|
||
if(zkEditEn) return k;
|
||
|
||
} // end of while(k)
|
||
|
||
|
||
if(var[0]){
|
||
var[0]=0;
|
||
VarGapSet(currXpos-1,charPara.CharHeight);
|
||
}
|
||
modified = true;
|
||
|
||
if(charPara.Width<currXpos) charPara.Width = currXpos;
|
||
if(charPara.LineHeight+currYpos>heightPoint)charPara.LineHeight+currYpos>heightPoint;
|
||
|
||
if(widthPoint < currXpos+300) widthPoint = currXpos+300;
|
||
if(widthPoint>MAX_WIDTH) widthPoint=MAX_WIDTH;
|
||
if(heightPoint<currYpos+charPara.LineHeight)heightPoint=currYpos+charPara.LineHeight;
|
||
|
||
if(heightPoint>MAX_HEIGHT) heightPoint=MAX_HEIGHT;
|
||
|
||
|
||
if( r_heightPoint < heightPoint || r_widthPoint <widthPoint)
|
||
resizeWidget (widthPoint,heightPoint);
|
||
emit movePicView();
|
||
update();
|
||
return currXpos;
|
||
}
|
||
|
||
|
||
|
||
|
||
int PicWidget::inputRamDot (QString txt,unsigned char *pMap, vars_t *p_var )
|
||
{
|
||
char dot[100];
|
||
unsigned int k=0,code_index=0;
|
||
unsigned int len=txt.length ();
|
||
if(len==0) return 0;
|
||
unsigned char txt_code[50];
|
||
memcpy(&txt_code[0], txt.unicode (),2*len);
|
||
code_index=0;
|
||
//currentEditTxt =txt;
|
||
//currXpos=0;currYpos=0;
|
||
int x=0;int y=0;
|
||
|
||
int char_width = p_var->width/p_var->digitalNum;
|
||
int char_bold;
|
||
// int num_w ;
|
||
int xx=0;// QString str="----\n";
|
||
while(k<len)
|
||
{
|
||
unsigned int incode = (txt_code[code_index+1]*256)+txt_code[code_index];
|
||
k++;code_index+=2;
|
||
if(incode>=0x20 && incode<0x80)
|
||
{ // ascii
|
||
zkIncode = (incode & 0x7f)-0x20;
|
||
readAscDot(zkIncode,dot);
|
||
char_bold = char_width/(charPara.CharWidth-charPara.FontGap);
|
||
|
||
int w = char_bold;
|
||
|
||
for(int i=0,n=0;i<charPara.LineHeight;i++)
|
||
{ int j=0;
|
||
xx=0;
|
||
for( j=0;j<charPara.CharWidth-charPara.FontGap;j++)
|
||
{
|
||
w = char_bold;
|
||
while(w--)
|
||
{ pMap[(x+xx)*MAX_PIC_WIDGET_HEIGHT +y+ i]=((dot[n]&(1<<(7-j%8)))&&(j<charPara.CharWidth))?1:0;
|
||
xx++;
|
||
}
|
||
if(j%8==7) n++;
|
||
|
||
|
||
}
|
||
if(j%8) n++;
|
||
for(j=xx;j<char_width;j++){
|
||
pMap[(x+xx)*MAX_PIC_WIDGET_HEIGHT +y+ i]=0;
|
||
xx++;
|
||
}
|
||
}
|
||
|
||
}
|
||
x+=xx;
|
||
} // end of while(k)
|
||
// qDebug()<<str;
|
||
|
||
return x;
|
||
}
|
||
|
||
void PicWidget::movePicView()
|
||
{static int r_currXpos;
|
||
if(currXpos!=r_currXpos){
|
||
move (QPoint(-(currXpos*scale > 580 ?currXpos*scale-580 :0),0));
|
||
r_currXpos=currXpos;
|
||
}
|
||
}
|
||
|
||
int PicWidget::charDotMap(char *dot,bool english )
|
||
{
|
||
int mx=0,mxx=0;
|
||
unsigned char wRow[32];
|
||
memset(&wRow,0,sizeof(wRow));
|
||
|
||
if(zkEditEn==0){
|
||
wRow[0]=(charPara.Font <<1)& 0x1e;
|
||
wRow[1]=(charPara.LineSpace <<1)& 0x1e;
|
||
wRow[2]=(charPara.FontGap <<1)& 0x1e;
|
||
wRow[3]=(charPara.Bold <<1)& 0x1e;
|
||
wRow[4]=(charPara.CharWidth <<1)& 0x1e;
|
||
wRow[5]=(charPara.LineHeight <<1)& 0x1e;
|
||
}
|
||
// qDebug()<<"wR:"<<wRow[0]<<wRow[1]<<wRow[2]<<wRow[3]<<wRow[4]<<wRow[5];
|
||
|
||
for(int i=0,n=0;i<charPara.CharHeight;i++)
|
||
{ int j=0;
|
||
int my= charPara.CharHeight-i-1;
|
||
mxx=mx= 0;
|
||
for( j=0;j<charPara.CharWidth-charPara.FontGap;j++)
|
||
{
|
||
for(int b=0;b<charPara.Bold+1;b++){
|
||
pointMap[(currXpos+mx)*MAX_PIC_WIDGET_HEIGHT +currYpos+ my ]
|
||
= (((dot[n]&(1<<(7-j%8)))&&(j<charPara.CharWidth))?1:0) |((my==0 && zkEditEn==0)? FLINE0:0 ) ;
|
||
mx++;
|
||
}
|
||
if(mxx%8==7) n++;
|
||
mxx++;
|
||
}
|
||
if(mxx%8) n++;
|
||
for(;j<charPara.CharWidth;j++){
|
||
for(int b=0;b<charPara.Bold+1;b++){
|
||
pointMap[(currXpos+mx)*MAX_PIC_WIDGET_HEIGHT +currYpos+my]
|
||
=((my==0 && zkEditEn==0)? FLINE0 : 0);
|
||
mx++;
|
||
}
|
||
}
|
||
}
|
||
for(int my=0;my<charPara.CharHeight;my++){
|
||
pointMap[(currXpos)*MAX_PIC_WIDGET_HEIGHT +currYpos+ my] |=( FCOL0 | wRow[my]) ;
|
||
}
|
||
return mx;
|
||
}
|
||
|
||
int PicWidget::varDotMap(char *dot,int *var)
|
||
{
|
||
int mx=0,mxx=0,max=0;
|
||
//unsigned char wRow[32];
|
||
unsigned char wRow[40]; //lich fix
|
||
memset(&wRow,0,sizeof(wRow));
|
||
if(zkEditEn==0){
|
||
wRow[0]=(charPara.Font <<1)& 0x1e;
|
||
wRow[1]=(charPara.LineSpace <<1)& 0x1e;
|
||
wRow[2]=(charPara.FontGap <<1)& 0x1e;
|
||
wRow[3]=(charPara.Bold <<1)& 0x1e;
|
||
wRow[4]=(charPara.CharWidth <<1)& 0x1e;
|
||
wRow[5]=(charPara.LineHeight <<1)& 0x1e;
|
||
}
|
||
//qDebug()<<"wR:"<<wRow[0]<<wRow[1]<<wRow[2]<<wRow[3]<<wRow[4]<<wRow[5];
|
||
for(int i=0,n=0;i<charPara.CharHeight;i++)
|
||
{ int j=0;
|
||
int my=charPara.CharHeight-i-1;
|
||
mx= 0;
|
||
mxx=0;
|
||
for( j=0;j<charPara.CharWidth-charPara.FontGap;j++)
|
||
{
|
||
for(int b=0;b<charPara.Bold+1;b++){
|
||
pointMap[(currXpos+mx)*MAX_PIC_WIDGET_HEIGHT +currYpos+ my ]
|
||
= (((dot[n]&(1<<(7-j%8)))&&(j<charPara.CharWidth))?1:0) |((mx==0)? FCOL0 : ((var[mx]<<1) & 0x1E) ) | ((my==0)? FLINE0:0 ) | FVAR ;
|
||
|
||
mx++;
|
||
}
|
||
|
||
if(mxx%8==7) n++;
|
||
mxx++;
|
||
}
|
||
|
||
if(mxx%8) n++;
|
||
for(;j<charPara.CharWidth;j++){
|
||
for(int b=0;b<charPara.Bold+1;b++){
|
||
pointMap[(currXpos+mx)*MAX_PIC_WIDGET_HEIGHT +currYpos+my]
|
||
=((my==0)? FLINE0 : 0) | FVAR | ((var[0]<<1) & 0x1E);
|
||
mx++;
|
||
}
|
||
|
||
}
|
||
if(max<=mx)max=mx;
|
||
}
|
||
for(int my=0;my<charPara.CharHeight;my++){
|
||
pointMap[(currXpos)*MAX_PIC_WIDGET_HEIGHT +currYpos+ my] |=( FCOL0 | wRow[my]) ;
|
||
wRow[10+my]= pointMap[(currXpos)*MAX_PIC_WIDGET_HEIGHT +currYpos+ my] & 0x1e;
|
||
}
|
||
return max;
|
||
}
|
||
|
||
int PicWidget::VarGetWidth(int x,int y,unsigned char c[])
|
||
{
|
||
int w=1,n=0;
|
||
unsigned char c2, c1=(pointMap[(x+2)*MAX_PIC_WIDGET_HEIGHT + y] >>1)& 0x0f; // 0 font 1 type 2 digit
|
||
while( (c2= pointMap[(x)*MAX_PIC_WIDGET_HEIGHT + y]) & FVAR ){
|
||
if(c2 & FCOL0) n++;
|
||
x++;w++;
|
||
if(x>widthPoint || w>30*8 || n>8 ) {w=0;n=0;break;}
|
||
}
|
||
if(w && c1 ==n){//
|
||
|
||
c[2]=n;c[3]=w;
|
||
}
|
||
return n;
|
||
}
|
||
|
||
void PicWidget::VarGapSet(int x,int h)
|
||
{
|
||
for(int i=0;i<h;i++)
|
||
{
|
||
pointMap[(x)*MAX_PIC_WIDGET_HEIGHT +currYpos+ i] &=~(FVAR);
|
||
//pointMap[(x)*MAX_PIC_WIDGET_HEIGHT +currYpos+ i] |=0xe0;
|
||
}
|
||
|
||
}
|
||
|
||
int PicWidget::picSetHome ()
|
||
{
|
||
currXpos= 0;
|
||
movePicView();
|
||
update ();
|
||
return currXpos;
|
||
}
|
||
|
||
int PicWidget::picSetEnd ()
|
||
{
|
||
currXpos=getLineEnd(currXpos);
|
||
movePicView();
|
||
update ();
|
||
return currXpos;
|
||
}
|
||
|