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

📄 aclock.cpp

📁 qte 2.3.7 下开发的虚拟表盘控件
💻 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>//// Constructs an analog clock widget that uses an internal QTimer.//int c=0;int r=160;int r2= rand()%220+160;   //160~380AnalogClock::AnalogClock( QWidget *parent, const char *name )    : QWidget( parent, name ){    time = QTime::currentTime();		// get current time    QTimer *internalTimer = new QTimer( this );	// create internal timer    connect( internalTimer, SIGNAL(timeout()), SLOT(timeout()) );    internalTimer->start( 50,false );	    setBackgroundPixmap( QPixmap("1.png") );}//// The QTimer::timeout() signal is received by this slot.//void AnalogClock::timeout(){    //if(r==r2) return;    r=r+(r2-r)/3;    if (11 == c) {    	c=0;    	r2= rand()%220+160;    	cout<<"===========new R2="<<r2<<endl;    }else{    	c++;    	if (10 == c) r=r2;    }    cout<<"r="<<r<<"r2="<<r2<<endl;    update();}void AnalogClock::paintEvent( QPaintEvent * ){    if ( autoMask() )	return;    QPainter paint( this );    //paint.setBrush( colorGroup().foreground() );    paint.setBrush( red );    drawClock( &paint );    }// If the clock is transparent, we use updateMask()// instead of paintEvent()void AnalogClock::updateMask()	// paint clock mask{    QBitmap bm( size() );    bm.fill( color0 );			//transparent    QPainter paint;    paint.begin( &bm, this );    paint.setBrush( color1 );		// use non-transparent color    paint.setPen( color1 );    drawClock( &paint );    paint.end();    setMask( bm );}//// The clock is painted using a 1000x1000 square coordinate system, in// the a centered square, as big as possible.  The painter's pen and// brush colors are used.//void AnalogClock::drawClock( QPainter *paint ){    paint->save();    paint->setWindow( -450,-560, 900,900 );    /*QRect v = paint->viewport();    int d = QMIN( v.width(), v.height() );    paint->setViewport( v.left() + (v.width()-d)/2,			v.top() + (v.height()-d)/2, d, d );*/    //time = QTime::currentTime();    QPointArray pts;    /*paint->save();    paint->rotate( 30*(time.hour()%12-3) + time.minute()/2 );    pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );    paint->drawPolygon( pts );    paint->restore();*/    paint->save();    //paint->rotate( (time.minute()-15)*6 );    paint->rotate( r );    pts.setPoints( 6, -15,0, 0,-15, 420,-10, 450,0, 420,10, 0,15 );    paint->drawPolygon( pts );    paint->restore();   /* for ( int i=0; i<6; i++ ) {	paint->drawLine( 440,0, 460,0 );	paint->rotate( 30 );    }*/   paint->restore();}void AnalogClock::setAutoMask(bool b){    if (b)	setBackgroundMode( PaletteForeground );    else	setBackgroundMode( PaletteBackground );    QWidget::setAutoMask(b);}

⌨️ 快捷键说明

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