⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.ui.h

📁 单片机学习资料 适合初学者进行开发学习
💻 H
字号:
/****************************************************************************** ui.h extension file, included from the uic-generated form implementation.**** If you wish to add, delete or rename functions or slots use** Qt Designer which will update this file, preserving your code. Create an** init() function in place of a constructor, and a destroy() function in** place of a destructor.*****************************************************************************/#include <qpainter.h>#include <qpixmap.h>#include <qtimer.h>#include <qfile.h>#include <qdatetime.h>#include <qtextstream.h>#include <qmessagebox.h>#include "stdio.h"#include "math.h"static int g_x[330];static int g_y[330];static int timer;static int g_run_leavel;void Form1::init(){    int i;    timer = startTimer(200);    g_run_leavel = 0;    for(i = -160; i<161; i++)    {	g_x[i+159] = i + 160;	g_y[i+159] =50 - 40 * sin(3.14 * (i+1)/80);	g_x[i+160] = i + 161;	g_y[i+160] = 50 - 40 * sin(3.14 * (i+1)/80);    }}void Form1::timerEvent(QTimerEvent *e){    if(g_run_leavel == 0)    {}    else    {	rebuild();	redraw();    }}void Form1::rebuild(){    int i;    g_y[325] = g_y[1];    for(i=1; i<321; i++)    {	g_y[i] = g_y[i+1];    }    g_y[320] = g_y[325];}void Form1::redraw(){    int i;     int a,b,c,d;    QPixmap pix(320,100);    QPainter p(&pix);    pix.fill(black);    p.setPen(darkGreen);    for(i=1; i<11; i++)    {	a = 0;	b = i * 10 - 10;	c = 320;	d = b;	p.drawLine(a,b,c,d);    }    for(i=1; i<33; i++)    {	a = i * 10 - 10;	b = 0;	c = a;	d = 100;	p.drawLine(a,b,c,d);    }    p.setPen(white);    p.drawLine(0, 50, 320, 50);    p.drawLine(317, 47, 320, 50);    p.drawLine(317, 53, 320, 50);    p.drawLine(160, 0, 160, 100);    p.drawLine(157, 3, 160, 0);    p.drawLine(163, 3, 160, 0);        p.setPen(yellow);    for(i=-160; i<160; i++)    {	p.drawLine(g_x[i+160], g_y[i+160], g_x[i+161], g_y[i+161]);    }    p.end();    p.begin(pixmapLabel1);    p.drawPixmap(0, 0, pix);    p.end();}    	    void Form1::save(){    int i;    QFile file("data.txt");    QString line, tmp_str;    QString file_msg;    QString now;    QString now_tmp;    if(file.open(IO_ReadWrite))    {	QTextStream stream(&file);	stream>>line;	if(line.isEmpty())	{	    file_msg = "first to save data, done";	}	else	{	    file_msg = "add data, done";	}	QTime now_t = QTime::currentTime();	now_tmp = now_tmp.setNum(now_t.hour());	now.prepend(now_tmp);	now.append(":");	now_tmp = now_tmp.setNum(now_t.minute());	now.append(now_tmp);	now.append(":");	now_tmp = now_tmp.setNum(now_t.second());	now.append(now_tmp);		line.append(0x0d);	line.append(now);	line.append("the data are:");	line.append(0x0d);		for(i=1; i<321; i++)	{	    tmp_str.setNum(g_x[i]);	    line.append(tmp_str);	    line.append(",");	    tmp_str.setNum(g_y[i]);	    line.append(tmp_str);	    line.append(",");	}	stream<<line;	file.close();    }    QMessageBox::warning(this, "message", file_msg);}void Form1::control(){    QString run_msg;    if(g_run_leavel == 0)    {	g_run_leavel = 1;	run_msg = "pause";	start->setText(run_msg);    }    else    {	g_run_leavel = 0;	run_msg = "start";	start->setText(run_msg);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -