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

📄 screen.cpp

📁 在ARM9和ARMLinux下利用QT编写的实时数据采集
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "screen.h"//#include <qpainter.h>#include <qevent.h>#include <qrect.h>#include <qsize.h>
#include <qstring.h>//#include <qpixmap.h> #include <iostream>using namespace std;//#include <math.h>#include <qwmatrix.h> #include <qfont.h>
#include <qpen.h>Screen::Screen(  QWidget *parent, const char *name, WFlags flags )    : QFrame( parent, name, flags | WNoAutoErase )  //圚qt3.1版本以䞋可以甚WRepaintNoErase | WResizeNoErase来代替WNoAutoErase{	setLineWidth( FRAMEWIDTH );		setFrameStyle( Panel | Sunken );	setBackgroundMode( PaletteBase );	//QWidget的凜数讟眮窗䜓的背景颜色。	setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );	firstShow = TRUE;	}
/*
void Screen::init()
{
	if ( firstShow )
		initNumber();
	initCordinate( drawPainter );
}
*/
/*void Screen::paintEvent( QPaintEvent * )
{
	if ( firstShow )
		initNumber();
	initCordinate( drawPainter );
}
*/
void Screen::showEvent( QShowEvent *e ){	if ( firstShow )		initNumber();	initCordinate( drawPainter );}
QSize Screen::minimumSize () const
{
	return QSize( 20 * 	SPACEMARGIN,  20 * 	SPACEMARGIN );
}
void Screen::hideEvent( QHideEvent *e ){	firstShow = FALSE;}

void Screen::setXTitle(	QString str )
{
	stringXTitle = str;
}
void Screen::setYTitle( QString str )
{
	stringYTitle = str;
}void Screen::initNumber( ){	//firstShow = FALSE;	saveBuffer.resize( size() );		//set the size and the backcolor of 	saveBuffer.fill( this, 0, 0 );		//those three QPixmaps as same as the Screen	newBuffer.resize( size() );	newBuffer.fill( this, 0, 0 ); 	midBuffer.resize( size() );	midBuffer.fill( this, 0, 0 );

	
	drawPainter.begin(&newBuffer);
	/*We translate the device's coordinate system*/
/*	drawPainter.setWindow( 
		-(int)width() / 2, -(int)height() / 2,
		width(), height() ); 
*/
	QRect newWindow = drawPainter.window();	newY = 0;	oldY =0; 	sec = 0;	min = 0;	hour = 0;

	numX = 0;
	drawDotLine = FALSE;	
	//stringYTitle = QObject::tr( "Operation Value" );
	stringXTitle = QObject::tr( "Time (hh:mm:ss)" );	Yval.push_back( (double)oldY );	//rectCordinate.setRect( 10 * STEP, 10 * STEP,			     //width() - 20 * STEP, height() - 40 * STEP ); //星瀺曲线的矩圢框
	rectCordinate.setRect( 
		newWindow.topLeft().x()+FRAMEWIDTH + 2 * BASEFONTHEIGHT + 2 * BASELINELENGHT, 
		newWindow.topLeft().y()+FRAMEWIDTH + 2 * SPACEMARGIN,
		newWindow.width() - 2 * ( FRAMEWIDTH + BASEFONTHEIGHT + BASELINELENGHT + SPACEMARGIN ),
		newWindow.height() - 2 * ( FRAMEWIDTH + BASEFONTHEIGHT + BASELINELENGHT + SPACEMARGIN ) );	/*comment 2007-8-25*/	/*	if ( 0 != ( rectCordinate.width() % (STEP*STEP) ) )	{		int x = rectCordinate.width() % ( STEP * STEP );	//( (int) sqrt( (float) STEP ) );		rectCordinate.setWidth( rectCordinate.width() - x+1 );	}	if ( 0 != ( rectCordinate.height() % (STEP*STEP) ) )	{		int y = rectCordinate.height() % (STEP*STEP);		//( (int) sqrt( (float)STEP ) );		rectCordinate.setHeight( rectCordinate.height() - y+1 );	}	numXTicks = rectCordinate.width() / STEP;	numYTicks = rectCordinate.height() / STEP;*/
	if ( 0 != ( rectCordinate.width() % (STEP*STEP) ) )
	{
		int x = rectCordinate.width() % ( STEP * STEP );	//( (int) sqrt( (float) STEP ) );
		rectCordinate.setWidth( rectCordinate.width() - x+1 );
	}

	if ( 0 != ( rectCordinate.height() % (STEP/* *STEP */) ) )
	{
		int y = rectCordinate.height() % (STEP/* *STEP */);		//( (int) sqrt( (float)STEP ) );
		rectCordinate.setHeight( rectCordinate.height() - y+1 );
	}
	numXTicks = rectCordinate.width() / STEP;
	numYTicks = rectCordinate.height() / STEP;	//fromSaveRect.setRect( rectCordinate.topLeft().x() + STEP, rectCordinate.topLeft().y()+1,			//rectCordinate.width() - STEP-1, rectCordinate.height()-1+12*STEP );	//toNewRect.setRect( rectCordinate.topLeft().x()+1, rectCordinate.topLeft().y()+1,			//rectCordinate.width() - STEP, rectCordinate.height()+12*STEP  );
	rectYText.setRect( 
		newWindow.topLeft().x() + FRAMEWIDTH,
		newWindow.topLeft().y() + FRAMEWIDTH + 2 * SPACEMARGIN,
		BASEFONTHEIGHT, rectCordinate.height() );
//	drawPainter.drawRect(rectYText);
	rectXText.setRect(
		rectCordinate.bottomLeft().x(), 
		newWindow.bottomLeft().y() - FRAMEWIDTH - BASEFONTHEIGHT,
		rectCordinate.width(), BASEFONTHEIGHT );
//		drawPainter.drawRect(rectXText);
	fromSaveRect.setRect( 
		rectCordinate.topLeft().x() + STEP,
		rectCordinate.topLeft().y() + 1,
		rectCordinate.width() - STEP - 1,
		rectCordinate.height() + 2 * BASELINELENGHT + BASEFONTHEIGHT );
//	drawPainter.drawRect(fromSaveRect);
	toNewRect.setRect(
		rectCordinate.topLeft().x() + 1,
		rectCordinate.topLeft().y() + 1,
		rectCordinate.width() - STEP - 1,
		rectCordinate.height() + 2 * BASELINELENGHT + BASEFONTHEIGHT );
//	drawPainter.drawRect(toNewRect);
		}
void Screen::initCordinate( QPainter &pCordinate ){  if ( firstShow )  {	//	QPainter pCordinate( &newBuffer );
//	pCordinate.setWindow( -(int)width() / 2; -(int)height() / 2,
						//	width(), height() );	pCordinate.setPen( Qt::blue );	pCordinate.drawRect( rectCordinate );		/*draw the Calibration and Calibration values of the y-axis*/	int y0 = rectCordinate.bottomLeft().y();	int x0 = rectCordinate.bottomLeft().x();	int yText = 0;	int xText= 0;	for (int j = 0; j <= numYTicks; j ++ )	{		pCordinate.drawLine( x0 - BASELINELENGHT, y0, x0, y0 );		if (0 == j % STEP )		{			pCordinate.drawLine( x0 - 2 * BASELINELENGHT, y0, x0 - BASELINELENGHT, y0 );
			pCordinate.save();
			pCordinate.setPen( QPen( blue, 1, DotLine) );
			pCordinate.drawLine( x0 , y0, rectCordinate.bottomRight().x(), y0 );
			pCordinate.restore();			pCordinate.setPen( Qt::black );						pCordinate.drawText( 
				x0 - 2 * BASELINELENGHT - BASEFONTHEIGHT,
				y0 - 2 * BASEFONTHEIGHT + 3 * STEP,		//5 * STEP, 
				BASEFONTHEIGHT, BASEFONTHEIGHT + STEP, 				//AlignBottom | Qt::AlignCenter , QString::number( yText) );				AlignCenter , QString::number( yText) );						yText ++;			pCordinate.setPen( Qt::blue );		}		y0 -= STEP;	}		/*write the title of y-axis*/	pCordinate.save();
/*	QRect rectYText( FRAMEWIDTH, rectCordinate.topLeft().y(), 
		rectCordinate.height(), rectCordinate.height() );
	pCordinate.setViewport( rectYText );	QRect rectXViewport = pCordinate.viewport();
	pCordinate.setWindow( -(int)rectYText.width()/2, -(int)rectYText.height()/2,
							rectYText.width(), rectYText.height() );	QRect rectXWindow = pCordinate.window();
	QRect rectText( rectXWindow.topLeft().x(),
					-(int)( rectCordinate.topLeft().x() -5 * STEP - FRAMEWIDTH ) / 2,
					rectXWindow.width(), rectCordinate.topLeft().x() -5 * STEP - FRAMEWIDTH );	pCordinate.rotate(-90.0);
	double dy = ( rectXWindow.width() - rectText.height() ) / 2;
	pCordinate.translate( 0, -dy );
	pCordinate.drawText( rectText.topLeft().x(), rectText.topLeft().y(), 
				rectText.width(), rectText.height(),
				 AlignCenter, "Operation Value" );
 */

/*	QRect tempYText( 
		-(int)rectYText.height() / 2, -(int)rectYText.width() / 2,
		rectYText.height(), rectYText.width() );
	pCordinate.rotate(-90.0);
	double dx = rectYText.topLeft().x() + rectYText.width() / 2;
	double dy = rectYText.topLeft().y() + rectYText.height() / 2;
	dx = dx > 0 ? dx : ( - dx );
	dy = dy > 0 ? dy : ( - dy );

	pCordinate.translate( -dx, -dy );
	pCordinate.drawText( tempYText.topLeft().x(), tempYText.topLeft().y(), 
				tempYText.width(), tempYText.height(),
				 AlignCenter, stringYTitle );
*/
	QRect tempYText( 
		rectYText.topLeft().x(), rectYText.topLeft().y(),
		rectYText.height(), rectYText.height() );
	pCordinate.setViewport( tempYText );
	QRect rectYViewport = pCordinate.viewport();
	pCordinate.setWindow( -(int)rectYViewport.width()/2, -(int)rectYViewport.height()/2,
							rectYViewport.width(), rectYViewport.height() );
	QRect rectYWindow = pCordinate.window();

⌨️ 快捷键说明

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