输入点阵字体

首先,该软件并不完善,中间因需求打断了。所以只写了删除操作,其他操作还没有添加,看明白的朋友有空可以添加。


一:程序截图:
(1) 输入字母和数字,以点阵形式显示,有光标。


(2) 移动光标,删除其中的字(现在只能删除,其他操作没有写,程序中已经提供了API)





二:软件分析:

(1) 架构分析



(2)图元分析




(三)代码概略

(1)逻辑层:一些重要的数据结构

//矩阵方位数据结构
QPoint m_MatrixPoint; //x 为行号,y为列号 从0行0列开始
//! 控制全局所有图元的区域
QList < QList<QRect> >m_Matrix;
//! 记录光标所有的位置,主要是为了根据当前光标返回所在的行号和列号
QList < QList<QPoint> > m_cursorMatrix;
//! 记录该图元是否是可以改变,x:行号 y:列号
QList < QPoint > m_changeAreaList;

QRect m_deleteArea; //删除区域,根据当前光标找到前一个位置,然后返回该区域
QRect m_insertArea; //插入区域:根据当前光标进行插入的区域,和m_rowEndArea共用
QRect m_EnterArea; //换行区域:每次都到下一行的起始断,并且修改矩阵,和m_rowListArea共用
QRect m_rowEndArea; //当前行某一列到该行行末的区域
QRect m_rowListArea; //换行前,下一行到末尾所有的区域
QList<QRect> m_rowAreaList;



(2)数据层:比较简单,就是实际画布

void DataImage::setImage(QImage dataImage)
{
this->m_dataImage = dataImage;
this->update();
}


(3)背景层: 代码里是视图层,但逻辑上我把它分成背景,主要是画光标和网格

/*! ******************************************
* 视图层:从数据image获取数据后,根据其像素点分别画在视图上
*******************************************/
/*!
* 画面大小
*/
void EditScene::initSize(QGraphicsView *view, int iWidth, int iHeight )
{
this->initColor();
this->m_iCustXCnt = iWidth;
this->m_iCustYCnt = iHeight;
this->m_dataImage = QImage( iWidth, iHeight , QImage::Format_Mono );

this->m_dataImage.fill( m_backColor.rgb() );

this->m_iSize = view->size().height()/this->m_iCustYCnt;
// view->setGeometry( view->geometry().x(), view->geometry().y(),
// WIDTH, HEIGHT*m_iSize +SPACE);

this->setSceneRect(0, 0, iWidth*m_iSize, iHeight*m_iSize);
qDebug() << m_iCustXCnt*m_iSize<< m_iCustYCnt*m_iSize <<__FILE__<<__LINE__;
m_backImage = QImage( m_iCustXCnt*m_iSize, m_iCustYCnt*m_iSize, QImage::Format_Mono );
m_backImage.fill( m_backColor.rgb() );
}


/*!
* 初始化颜色
*/
void EditScene::initColor()
{
m_backLineColor = Qt::darkYellow; //网格颜色
m_pointColor = Qt::black; //画圆
m_backColor = Qt::white; //背景白色
}

/*!
* 画网格
*/
void EditScene::setGrid(bool enable)
{

qDebug() << m_iSize << m_iCustXCnt<< m_iCustYCnt <<this->height()<< this->width()
<<m_iCustXCnt*m_iSize<<m_iCustYCnt*m_iSize<<__FILE__<<__LINE__;
QPainter painter( &m_backImage );

if ( enable ) {
QPen pen(this->m_backLineColor, 0); //虚线的颜色
pen.setStyle( Qt::DotLine); //虚线的类型
painter.setPen( pen );

for( int i = 1; i < this->m_iCustXCnt; ++i ) {
int x = m_iSize*i;
painter.drawLine( x, 0, x, this->height() );
}

for ( int j = 1; j < this->m_iCustYCnt; ++j ) {
int y = m_iSize*j;
painter.drawLine(0, y, this->width(), y );
}
}
m_backImage.save("/home/lbs/1.bmp");
this->setBackgroundBrush( this->m_backImage );

}



(4)视图层:根据像素画点

/*!
*判断是否画点
*/
bool EditScene::isDrawPoint( int icustx,int icusty )
{
//int gray = DataImage.pixel( QPoint(icustx,icusty) );
int gray = qGray( this->m_dataImage.pixel(QPoint(icustx,icusty)) );

if( gray == 0 ){
return true;
}else{
return false;
}
}

/*!
* 清除某点
*/
void EditScene::ClearPoint( int icustx, int icusty )
{
QPainter painter( &m_backImage );

painter.setPen( QPen( Qt::transparent, 0 ) );
painter.setBrush( QBrush( m_backColor, Qt::SolidPattern ) );
painter.drawRect( icustx*m_iSize+1, icusty*m_iSize+1 , m_iSize-2, m_iSize-2 );
this->setBackgroundBrush( m_backImage );

ClearDataImagePoint( icustx, icusty );
}

/*!
* 清除数据图像上的某点
*/
void EditScene::ClearDataImagePoint( int icustx ,int icusty )
{
this->m_dataImage.setPixel( icustx, icusty , 1 );
}


(5)动作事件:接受键盘动作

/*! ******************************************
* 事件层:接收命令,下发动作
*******************************************/
void EditScene::keyPressEvent(QKeyEvent *event)
{
switch( event->key() ) {
//操作
case Qt::Key_Up:
emit this->sendCursorMove( Location::Up);
break;
。。。。。。。。。
}
/*!
* 插入操作
*/
void EditScene::insertOpeSlot()
{
emit this->sendCursorMove( Location::Insert );
}

/*!
* 根据按键输入不一样的字符
*/
void EditScene::setKeyText(QString minStr, QString maxStr)
{
QString sendStr;
if ( this->m_capsEnabel ) {
//! 大写数据
sendStr = maxStr;
}else {
//! 小写数据
sendStr = minStr;
}
emit this->sendText( sendStr );

}

/*!
* 重绘
*/
void EditScene::Redraw(QRect sourceArea ,QPoint newTopLeft)
{

qDebug() <<sourceArea<< newTopLeft<<__FILE__<<__LINE__;
QImage m_oldImage = m_dataImage.copy( sourceArea );
this->cleanRect( sourceArea );
m_cursorTopLeft = newTopLeft;

//画点
if( !m_oldImage.isNull() ){
for( int i = 0; i < m_oldImage.height(); ++i ){
for ( int j = 0; j < m_oldImage.width(); ++j ){
int gray = qGray( m_oldImage.pixel( QPoint(j,i) ) );
if( gray == 0 ){
//! 要加入 光标的位置 m_cursorTopLeft
DrawPoint( m_cursorTopLeft.x()+ j,m_cursorTopLeft.y()+ i );
}
}
}
}
this->m_displayerImage->setImage( this->m_dataImage);

}

/*!
* 加载镜像,并提出灰度,并画点
*/
void EditScene::LoadPointByImage( QImage * img )
{
if( !img->isNull() ){
for( int i = 0; i < img->height(); ++i ){
for ( int j = 0; j < img->width(); ++j ){
int gray = qGray( img->pixel( QPoint(j,i) ) );
if( gray == 0 ){
//! 要加入 光标的位置 m_cursorTopLeft
DrawPoint( m_cursorTopLeft.x()+ j,m_cursorTopLeft.y()+ i );
}
}
}
}
this->m_displayerImage->setImage( this->m_dataImage);
//移动光标
emit this->sendNewUnit();
emit this->sendCursorMove( Location::Right);

}
/*!
* 获取清除区域范围
*/
void EditScene::cleanRect(QRect rect)
{
//移动光标
// emit this->sendCursorMove( Location::Left);
// QSize cleanSize = rect.size();
// QImage cleanImage = this->m_dataImage.scaled( cleanSize,Qt::KeepAspectRatio,Qt::FastTransformation);
m_cleanTopLeft = rect.topLeft();
qDebug() << rect.topLeft() <<__FILE__<<__LINE__;
this->cleanPointByImage( &m_dataImage.copy( rect ) );

}

/*!
* 清除区域内所有点
*/
void EditScene::cleanPointByImage(QImage *img)
{

if( !img->isNull() ){
for( int i = 0; i < img->height(); ++i ){
for ( int j = 0; j < img->width(); ++j ){
int gray = qGray( img->pixel( QPoint(j,i) ) );
if( gray == 0 ){
//! 要加入 光标的位置 m_cursorTopLeft

this->ClearPoint(j+m_cleanTopLeft.x(),i+ m_cleanTopLeft.y());
}
}
}
}
this->m_displayerImage->setImage( this->m_dataImage);

}

代码下载请到下面地址:

代码

http://download.csdn.net/detail/lbsljn/4979869
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分别为: Hz.txt 为取模后的点阵字模数据。和程序窗口中的内容一样。但程序窗口中的字模数据不能大于64K。 Tempchar.txt 为记录用户输入的字符文件 zimuo.bin 为取模后的二进制字模文件,可以直接烧到FLASH中。 功能说明 1、16*16: 能对汉字或字符进行取模。取模数据为16*16的点阵。字符也为16*16的点阵 2、8*16: 能对字符进行取模。取模的数据为8*16的字模,两个字符合成一个16*16的点阵,不能对汉字取模 3、黑白反转:能对字模进行调整。将0调为1,1调为0。显示效果为镂空的字符。 4、左右对调:能对字模进行调整,将16位的点阵数据左右对调。第0位调到第15位,第1位调到第14位.... 5、横向取模:对字符进行横向取模。 6、纵向取模:对字符进行纵向取模。(暂无此功能) 7、2008-3-22日增加串口下载功能,可将字模数据通过串口下载到单片机中。单片机电路必须支持外接存贮器。 8、串口协义方式为:所先由单片机向上位机程序发送字符“S”(大写),上位机发到“S”后说明与单片机连接成功,并发送“S”字符 到单片机。单片机收到“S”后,等待上位机发送字模数据。单片机与PC连接成功后就可向发送字模数据,发送字模数据的大小取决于 下位机程序和单片机的RAM大小。PC发送字模数据后,在连续发送三个“s”(小字)。用于断开单片机的连接。 9、单片机电路和程存请参考本软件附带的文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值