/****************************************************************************
** $Id: hello.cpp,v 1.6 1999/08/24 13:08:11 hanord Exp $
**
** 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 "hello.h"
#include <qpushbutton.h>
#include <qtimer.h>
#include <qpainter.h>
#include <qpixmap.h>
/*
Constructs a Hello widget. Starts a 40 ms animation timer.
*/
Hello::Hello( const char *text, QWidget *parent, const char *name )
: QWidget(parent,name), t(text), b(0)
{
QTimer *timer = new QTimer(this);
connect( timer, SIGNAL(timeout()), SLOT(animate()) );
timer->start( 40 );
resize( 260, 130 );
}
/*
This private slot is called each time the timer fires.
*/
void Hello::animate()
{
b = (b + 1) & 15;
repaint( FALSE );
}
/*
Handles mouse button release events for the Hello widget.
We emit the clicked() signal when the mouse is released inside
the widget.
*/
void Hello::mouseReleaseEvent( QMouseEvent *e )
{
if ( rect().contains( e->pos() ) )
emit clicked();
}
/*
Handles paint events for the Hello widget.
Flicker-free update. The text is first drawn in the pixmap and the
pixmap is then blt'ed to the screen.
*/
void Hello::paintEvent( QPaintEvent * )
{
static int sin_tbl[16] = {
0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38};
if ( t.isEmpty() )
return;
// 1: Compute some sizes, positions etc.
QFontMetrics fm = fontMetrics();
int w = fm.width(t) + 20;
int h = fm.height() * 2;
int pmx = width()/2 - w/2;
int pmy = height()/2 - h/2;
// 2: Create the pixmap and fill it with the widget's background
QPixmap pm( w, h );
pm.fill( this, pmx, pmy );
// 3: Paint the pixmap. Cool wave effect
QPainter p;
int x = 10;
int y = h/2 + fm.descent();
int i = 0;
p.begin( &pm );
p.setFont( font() );
while ( !t[i].isNull() ) {
int i16 = (b+i) & 15;
p.setPen( QColor((15-i16)*16,255,255,QColor::Hsv) );
p.drawText( x, y-sin_tbl[i16]*h/800, t.mid(i,1), 1 );
x += fm.width( t[i] );
i++;
}
p.end();
// 4: Copy the pixmap to the Hello widget
bitBlt( this, pmx, pmy, &pm );
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
tmake-1.11.tar.gz (303个子文件)
CHANGES 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 2KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
tmake.conf 1KB
hello.cpp 2KB
main.cpp 1KB
win32app.dsp 7KB
win32app.dsp 4KB
win32dll.dsp 4KB
win32dll.dsp 4KB
win32lib.dsp 3KB
win32lib.dsp 3KB
hello.h 805B
tmake.html 21KB
tmake_ref.html 13KB
m-win32-msvc.html 2KB
m-linux-gcc.html 2KB
LICENSE 440B
hello.pro 115B
progen 6KB
README 345B
generic.t 14KB
vcgeneric.t 10KB
generic.t 10KB
vcgeneric.t 9KB
generic.t 9KB
generic.t 9KB
generic.t 8KB
generic.t 7KB
generic.t 7KB
generic.t 7KB
subdirs.t 1KB
subdirs.t 1KB
vclib.t 529B
vclib.t 529B
vcapp.t 436B
vcapp.t 436B
共 303 条
- 1
- 2
- 3
- 4
资源评论
lhf0921
- 粉丝: 52
- 资源: 80
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功