?? cannon.cpp
字號:
#include "cannon.h"#include <qpainter.h>#include <qtimer.h>#include <math.h>CannonField::CannonField( QWidget *parent, const char *name ) :QWidget( parent, name ){ ang = 45; timerCount = 0 ; autoShootTimer = new QTimer ( this, "movement handler" ); connect( autoShootTimer,SIGNAL( timeout() ), this, SLOT( timerTest() ) ); setPalette( QPalette( QColor( 250, 250, 200) ) ); }void CannonField::setAngle( int degrees ){ if ( degrees < 5 ) degrees = 5; if ( degrees > 70 ) degrees = 70; if (ang == degrees ) return; ang =degrees; repaint(); emit angleChanged ( ang );}void CannonField::paintEvent( QPaintEvent * ){ QString s = "K=" + QString::number( ang ); QPainter p( this ); p.drawLine( 0,height()-20,width()-10,height()-20 ); p.drawLine( width()-10,height()-20,width()-16,height()-16 ); p.drawLine( width()-10,height()-20,width()-16,height()-24 ); p.drawLine( 10,height(),10,20); p.drawLine( 10,20,6,24); p.drawLine( 10,20,14,24); p.drawText( 3,height()-10, "O"); p.drawText( 30,height()-10, "1"); p.drawText( 50,height()-10, "2"); p.drawText( 70,height()-10, "3"); p.drawText( width()-30, height()-30, "t/sec"); p.drawText( 16,height()-50, "100"); p.drawText( 16,height()-80, "200"); p.drawText( 16,height()-110, "300"); p.drawText( 5, 10, "p/mpa"); p.drawText( width()-40, 30, s );}void CannonField::paintSet(){ QPainter p( this ); p.drawLine( 10, height()-20, 30, height()-ang-70 ); p.drawLine( 30, height()-ang-70, 50, height()-ang-70 ); p.drawLine( 50, height()-ang-70, 70, height()-20 );}void CannonField::simulate(){ if(autoShootTimer->isActive()) return; timerCount = 0 ; autoShootTimer->start(200);}void CannonField::timerTest(){ timerCount++;// if ( timerCount >10 ){ // QString s = "K=" + QString::number( sin(ang*3.14/180) ); QPainter p( this ); p.setPen( red ); // p.drawText( width()-40, 10, s ); if( timerCount <=10 ) p.drawLine( 10, height()-20,10+timerCount*2, qRound( height()-20-timerCount*20*sin(ang*3.14/180) ) ); else if( timerCount <= 20 ) p.drawLine( 30, qRound( height()-20-10*20*sin(ang*3.14/180) ), 10+timerCount*2, qRound( height()-20-10*20*sin (ang*3.14/180) ) ); else if( timerCount <= 30 ) p.drawLine( 50, qRound( height()-20-10*20*sin(ang*3.14/180) ), 10+timerCount*2, qRound( height()-20- 10*20*sin(ang*3.14/180) + (timerCount-20)*20*sin(ang*3.14/180) ) ) ; else // if ( timerCount > 30 ) autoShootTimer->stop( ); //return;}QSizePolicy CannonField::sizePolicy() const{ return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -