📄 aclock.cpp
字号:
/****************************************************************************** $Id: qt/examples/aclock/aclock.cpp 2.3.7 edited 2001-01-26 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "aclock.h"#include <qtimer.h>#include <qpainter.h>#include <qbitmap.h>#include <stdio.h>#include <stdlib.h>#include <iostream.h>#include <math.h>/* 监控volt值的变化,每0.5秒刷新一次 使用方法: Hwt_trend *m = new Hwt_trend( this, "Hwt_trend" ); m->runDemo(1); //自动演示,正弦变化 定时设置 m->setVol(p); Hwt_trend自动监控volt值的变化, 每0.5秒刷新一次,并显示柱状图及转换 问题: 绿色柱落后白线一格*/Hwt_trend::Hwt_trend( QWidget *parent, const char *name ) : QWidget( parent, name ){ c = 0; flag=1; volt=0.0; demo =0; QTimer *internalTimer = new QTimer( this ); // create internal timer connect( internalTimer, SIGNAL(timeout()), SLOT(timeout()) ); internalTimer->start( 500,false ); setMinimumSize( 396, 220 ); setMaximumSize( 396, 220 ); setBackgroundPixmap( QPixmap("trend0.png") ); int i; pts = new QPointArray(60); for(i=0; i<30; i++){ point[i] = 0; pts->putPoints( 2*i, 1, i*11+45,102 ); pts->putPoints( 2*i+1, 1, i*11+45,102 ); } for(i=1; i<4; i++){ s[i].sprintf( "%d", i*10-30); } s[0] = s[3];}//// The QTimer::timeout() signal is received by this slot.//void Hwt_trend::timeout(){ int t = c%30; if(demo)//test volt = sin(c/2.2)*10; //c%7 - 3.0; //cout<<sin(t)<<endl; point[t] = volt; if(volt >10) point[t] = 10.0; else if (volt <-10) point[t] = -10.0; if(point[t] >= 1) { pts->putPoints( 2*t+1, 1, t*11+45,50); pts->putPoints( (2*t+2)%60, 1, ((t+1)%30)*11+45,50); }else{ pts->putPoints( 2*t+1, 1, t*11+45,102); pts->putPoints( (2*t+2)%60, 1, ((t+1)%30)*11+45,102); } update(); c++;}void Hwt_trend::paintEvent( QPaintEvent * ){ QPainter paint( this ); //paint.setFont( QFont( "simsun", 14, QFont::Normal) ); drawClock( &paint ); }void Hwt_trend::drawClock( QPainter *paint ){ paint->save(); paint->setPen( Qt::red ); paint->drawPolyline( *pts ); int i; paint->setPen( Qt::green ); paint->setBrush( Qt::green ); for(i=0; i<30; i++){ if(i==0) paint->drawRect ( i*11+45, 113, 3, -point[i]*5 ) ; else paint->drawRect ( i*11+43, 113, 6, -point[i]*5 ) ; } paint->setPen( Qt::white ); paint->drawLine( (c%30)*11+45, 43, (c%30)*11+45, 180); paint->setPen( Qt::blue ); s[c%30/10].sprintf( "%d", (c/10)*10); s[3] = s[0]; for(i=0;i<4;i++){ paint->drawText( i*107+45-3*s[i].length(), 205, s[i] ); } paint->restore();}void Hwt_trend::setVol( float pvolt){ if(pvolt > 10.0) volt = 10.0; else if(pvolt < -10.0) volt = -10.0; else volt = pvolt;}void Hwt_trend::runDemo( int t){ if(t==0) demo = 0; else demo = 1;}//end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -