📄 main.cpp
字号:
#include <qapplication.h>#include <qwidget.h>#include <qpushbutton.h>#include <qpainter.h>#include <qpixmap.h>#include <qimage.h>#include <qtextcodec.h>#include <qgbkcodec.h>#include <errno.h>#include <qpicture.h>#include <qtimer.h>#include <qmessagebox.h>#include <netinet/in.h>#include <arpa/inet.h>#include <sys/ioctl.h>#include <sys/time.h>#include <net/if.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <syslog.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <termios.h>#include <sys/socket.h>#include <pthread.h>#include "mytypes.h"#include <semaphore.h>#include <time.h>//related to msg list#include <sys/ipc.h>#include <sys/shm.h>#include <sys/msg.h>#define PACKSIZE 1024//#define PRINT(a...) printf(a...)#define PRINT( x... ) printf("aa " ##x)void* udpclient(void *);void* BeginServer(void*);void* PicManageThread(void*);void* ClientServerThread(void*);void ClosePicManageThread();void WritePicManageCmd(long);void ClearPipeBuff();void* PicPlayThread(void*);int ParsePrj(char* ); void MessageBox(char*);void MessageBox(int);int recvprj(int ,int );class CMyMainWnd;CMyMainWnd* mainwindow;typedef struct _PICITEM{ PICBODY* ppicbody; QPixmap* pixmap;}PICITEM,*PPIITEM;PICBODY** ppicbodyarr=NULL;//the picprj name saved on diskchar* prjfilename="pic.prj";//the pipe used to send pic control commandchar* picpipename="picpipe";//sem used to control pic playsem_t gsem,gsemonline,gsemlabel;int onlineusrcount=0;//array used to save History indexint historyarr[100];int historyindex=-1;int gShowLbl=0;//local ipchar localip[30];//msg list idint msglistid;typedef struct _PICPLAYCONTROL{ bool blhasfile; bool blplaying; bool blpausing; int iposx; int iposy; int inumber; int ipiccount; int iplaytype; pthread_t threadid; }PICPLAYCONTROL;struct message{ long msgtype;};PICPLAYCONTROL picctrl={false,false,false,0,0,-1,0,0,0};int testid=0;PICLABELLIST *listhead;const char STR_MOUSEDOWN[]={199,235,199,243,210,209,204,225,189,187,0};class CMyMainWnd:public QWidget { //Q_OBJECTprivate: bool clicked; bool blisrefresh; int timerid; void paintEvent(QPaintEvent* ); void PaintLabels(QPainter*); //void mouseDoubleClickEvent( QMouseEvent * ); void mousePressEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e); char * filename; sem_t semfilename; char * statestr; QPixmap pixhand,pixauto,pixno; void MoveinFromLeft(char* chfile); void MoveinFromRight(char* chfile); void MoveinFromTop(char* chfile); void MoveinFromBottom(char* chfile); void MoveinBlindHori(char* chfile); void MoveinBlindVert(char* chfile);public: void SetStateStr(char* chstate); void SetCurrentFileName(char* ch); void ResetPaint(); void ShowPic(char* chfile,int intype); CMyMainWnd(); ~CMyMainWnd();protected: void timerEvent(QTimerEvent * e);private : void timeout();};void CMyMainWnd::timerEvent(QTimerEvent* e){ printf("set cliecked false\n"); clicked=false; killTimer(timerid); if(!blisrefresh) { repaint(); //repaint(width()-200,height()-80,width(),height(),true); } printf("timer event\n");}void CMyMainWnd::timeout(){ printf("timeOut\n");}/*void CMyMainWnd::mouseReleaseEvent(QMouseEvent *e){ if(!blisrefresh) { PICLABELLIST* q=listhead; PICLABELLIST* p=NULL; while(q) { if( q->piclabel.Left<e->x()&&q->piclabel.Top<e->y() \ && q->piclabel.Left+q->piclabel.Width>e->x() && q->piclabel.Top+q->piclabel.Height>e->y()) { p=q; break; } q=q->next; } if(p) { QPainter painter; painter.begin(this); painter.drawWinFocusRect(q->piclabel.Left,q->piclabel.Top,\ q->piclabel.Width,q->piclabel.Height); painter.drawWinFocusRect(q->piclabel.Left+1,q->piclabel.Top+1,\ q->piclabel.Width-1,q->piclabel.Height-1); painter.end(); } }}*/void CMyMainWnd::mouseReleaseEvent(QMouseEvent *e){ if(!blisrefresh) { PICLABELLIST* q=listhead; PICLABELLIST* p=NULL; while(q) { if( q->piclabel.Left<e->x()&&q->piclabel.Top<e->y() \ && q->piclabel.Left+q->piclabel.Width>e->x() && q->piclabel.Top+q->piclabel.Height>e->y()) { p=q; break; } q=q->next; } if(p) { repaint(p->piclabel.Left,p->piclabel.Top,p->piclabel.Width+2,\ p->piclabel.Height+2,false); } }}void CMyMainWnd::mousePressEvent(QMouseEvent *e){ sem_wait(&gsem); picctrl.iposx=e->x(); picctrl.iposy=e->y(); PRINT("qt printf .....:x:%d,y:%d\n",e->x(),e->y()); clicked=true; //dhc 2008-1-1 alter codes relative to click events //if(timerid>0) killTimer(timerid); //repaint(); if(!blisrefresh) { PICLABELLIST* q=listhead; PICLABELLIST* p=NULL; while(q) { if( q->piclabel.Left<e->x()&&q->piclabel.Top<e->y() \ && q->piclabel.Left+q->piclabel.Width>e->x() && q->piclabel.Top+q->piclabel.Height>e->y()) { p=q; break; } q=q->next; } if(p) { QPainter painter; painter.begin(this); FILE* tempfile=fopen("templbl","w+b"); fwrite(p->piclabel.BmpFile,1,p->piclabel.BmpSize,tempfile); fclose(tempfile); QPixmap img("templbl"); if(img.isNull()) { printf("cant load bmp\n"); } else painter.drawPixmap(p->piclabel.Left+2,p->piclabel.Top+2,img); //painter.drawWinFocusRect(p->piclabel.Left,p->piclabel.Top,\ p->piclabel.Width,p->piclabel.Height); //painter.drawWinFocusRect(p->piclabel.Left+1,p->piclabel.Top+1,\ p->piclabel.Width-1,p->piclabel.Height-1); painter.end(); } repaint(width()-200,height()-80,width(),height(),true); } //dhc 2008-1-1 alter codes relative to click events //timerid=startTimer(2000); sem_post(&gsem); return;}void CMyMainWnd::SetStateStr(char* chstate){ sem_wait(&semfilename); strcpy(statestr,chstate); sem_post(&semfilename); repaint();}void CMyMainWnd::MoveinFromLeft(char* chfile){ QPixmap* image=new QPixmap(); if (!image->load(chfile)) printf("error when load file\n"); int iWidth=width(); int iHeight=height(); QPainter painter; QPixmap tempimage(QSize(iWidth,iHeight)); //move in from left painter.begin(&tempimage); painter.fillRect(QRect(0,0,iWidth,iHeight),QBrush(white)); painter.drawPixmap(QPoint(0,0),*image); painter.end(); for(int i=0;i<iWidth;) { bitBlt(this,QPoint(i-iWidth,0),&tempimage); i+=4; } delete image;}void CMyMainWnd::MoveinFromRight(char* chfile){ QPixmap* image=new QPixmap(); if (!image->load(chfile)) printf("error when load file\n"); int iWidth=width(); int iHeight=height(); QPainter painter; QPixmap tempimage(QSize(iWidth,iHeight)); //move in from left painter.begin(&tempimage); painter.fillRect(QRect(0,0,iWidth,iHeight),QBrush(white)); painter.drawPixmap(QPoint(0,0),*image); painter.end(); for(int i=0;i<iWidth;) { bitBlt(this,QPoint(iWidth-i,0),&tempimage); i+=4; } delete image;}void CMyMainWnd::MoveinFromTop(char* chfile){ QPixmap* image=new QPixmap(); if (!image->load(chfile)) printf("error when load file\n"); int iWidth=width(); int iHeight=height(); QPainter painter; QPixmap tempimage(QSize(iWidth,iHeight)); //move in from left painter.begin(&tempimage); painter.fillRect(QRect(0,0,iWidth,iHeight),QBrush(white)); painter.drawPixmap(QPoint(0,0),*image); painter.end(); for(int i=0;i<iHeight;) { bitBlt(this,QPoint(0,i-iHeight),&tempimage); i+=4; } delete image;}void CMyMainWnd::MoveinFromBottom(char* chfile){ QPixmap* image=new QPixmap(); if (!image->load(chfile)) printf("error when load file\n"); int iWidth=width(); int iHeight=height(); QPainter painter; QPixmap tempimage(QSize(iWidth,iHeight)); //move in from left painter.begin(&tempimage); painter.fillRect(QRect(0,0,iWidth,iHeight),QBrush(white)); painter.drawPixmap(QPoint(0,0),*image); painter.end(); for(int i=0;i<iHeight;) { bitBlt(this,QPoint(0,iHeight-i),&tempimage); i+=4; } delete image;}void CMyMainWnd::MoveinBlindHori(char* chfile){ QPixmap* image=new QPixmap(); if (!image->load(chfile)) printf("error when load file\n"); int iWidth=width(); int iHeight=height(); QPainter painter; QPixmap tempimage(QSize(iWidth,iHeight)); int iPart=iWidth/20; for(int i=0;i<iPart;) { painter.begin(&tempimage); for(int j=0;j<20;j++) { painter.drawPixmap(j*iPart+i,0,*image,j*iPart+i,0,1,iHeight); } painter.end(); bitBlt(this,QPoint(0,0),&tempimage); i+=1; } delete image;}void CMyMainWnd::MoveinBlindVert(char* chfile){ QPixmap* image=new QPixmap(); if (!image->load(chfile)) printf("error when load file\n"); int iWidth=width(); int iHeight=height(); QPainter painter; QPixmap tempimage(QSize(iWidth,iHeight)); int iPart=iHeight/20; for(int i=0;i<iPart;) { painter.begin(&tempimage); for(int j=0;j<20;j++) { painter.drawPixmap(0,j*iPart+i,*image,0,j*iPart+i,iWidth,1); } painter.end(); bitBlt(this,QPoint(0,0),&tempimage); i+=1; } delete image;}void CMyMainWnd::ResetPaint(){ SetCurrentFileName("main.bmp"); repaint(true);}CMyMainWnd::~CMyMainWnd(){ sem_destroy(&semfilename); delete filename; delete statestr;}void CMyMainWnd::SetCurrentFileName(char* ch){ sem_wait(&semfilename); strcpy(filename,ch); printf("current file name :%s\n",filename); sem_post(&semfilename);}void CMyMainWnd::ShowPic(char* chfile,int intype){ blisrefresh=true; switch(intype) { case 0:break; case 1:MoveinFromLeft(chfile); break; case 2:MoveinFromRight(chfile); break; case 3:MoveinFromTop(chfile); break; case 4:MoveinFromBottom(chfile); break; case 5:MoveinBlindHori(chfile); break; case 6:MoveinBlindVert(chfile); break; } printf("set current file........\n"); SetCurrentFileName(chfile); /*painter.begin(&tempimage); painter.fillRect(QRect(0,0,iWidth,iHeight),QBrush(white)); painter.drawPixmap(QPoint(0,0),*image); painter.end(); bitBlt(this,QPoint(0,0),&tempimage);*/ printf("invoke repaint\n"); repaint(); blisrefresh=false; return;}CMyMainWnd::CMyMainWnd(){ //中国人的 sem_init(&semfilename,0,0); sem_post(&semfilename); setGeometry(0,0,640,480); setBackgroundMode(NoBackground); filename=new char[50]; statestr=new char[50]; memset(statestr,0,50); pixhand.load("hand.bmp"); pixauto.load("auto.bmp"); pixno.load("nopic.bmp"); SetCurrentFileName("main.bmp"); //innerTimer=new QTimer(this); //connect(innerTimer,SIGNAL(timeout()),SLOT(timeout())); //innerTimer->start(1000); timerid=0; clicked=false; blisrefresh=false;}/*void CMyMainWnd::mouseDoubleClickEvent( QMouseEvent * e){ QPixmap image("/root/dhc/1.bmp"); //QPixmap image("/root/dhc/2.bmp"); MessageBox(e->x());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -