#include "iko.h"#include "math.h"//---------------------------------------------------- лПОУФТХЛФПТ------------/** 1A **/clock::clock(QWidget* parent=0, QString pathName="./"){ currentSpeed = 60; cSectorNumber = 999; cSectorSmall = 360.0 / (cSectorNumber+1);//----------------------------------------------------йОЙГЙБМЙЪБГЙС----------/**/ currentSector = 0; angle = 0; xR = 193; yR = 193; centerX = 260; // 260 centerY = 260; // 260 colorSecond = qRgba(0,0,0xFF,0xFF); colorBack = qRgba(0,0,0,0); roundTimer = new QTimer(this); connect(roundTimer, SIGNAL(timeout()),this, SLOT(stepUp())); roundTimer->start(currentSpeed,false);//-----------------------------------------------------пФТЙУПЧЛБ ЖПОБ--------/**/ setGeometry(0, 0, 520, 520); setFixedSize(520,520); QPixmap pm(pathName+QString("main.png")); if (pm.size()!=this->size()){ QWMatrix m; m.scale((double)width()/pm.width(), (double)height()/pm.height()); pm = pm.xForm(m); } mainMap = pm;//-------------------------------------------------------рБТБНЕФТЩ НБУЛЙ---------//**// QBitmap mask(520,520, false, QPixmap::DefaultOptim); mask.fill(color1); painter = new QPainter(&mask); painter->setPen(color0); painter->setBrush(color0); painter->drawEllipse(60,60,400,400); painter->end(); painter = new QPainter(this); painter->setPen(QPen(colorSecond, 1, SolidLine)); pX = (xR * cos(-M_PI/2) ) + centerX; pY = (yR * sin(-M_PI/2) ) + centerY;}//-----------------------------------------------------//void clock::paintEvent(QPaintEvent *event){ painter->setClipping(false); painter->drawPixmap(0, 0, mainMap); QRegion region(60,60,400,400, QRegion::Ellipse); painter->setClipRegion(region); painter->setClipping(true);// painter->drawPie( QRect(60, 60, 400, 400), angle, 3); }//---------------------------------------------------//void clock::clearLast(){// ------------------------------------------------------ уФЙТБЕН РТПЫМПЕ --// painter -> setBrush(Qt::black); painter->setPen(QPen(black, 1, SolidLine)); painter->drawLine(centerX, centerY, pX, pY);}//----------------------------------------------------------- STEP UP ------//void clock::stepUp(){ if(currentSector == cSectorNumber) currentSector = 0; else currentSector++; angle = ((currentSector * cSectorSmall -90) * M_PI)/180; clearLast();//-------------------------------------------------------- рЕТЕУЮЕФ ЛППТДЙОБФ УФТЕМЛЙ -----// pX = (xR * cos(angle)) + centerX; pY = (yR * sin(angle)) + centerY;//---------------------------------------------------- мЙОЙС УФТЕМЛЙ ----------------------// painter->setPen(QPen(colorSecond, 1, SolidLine)); painter->drawLine(centerX, centerY, pX, pY);}void clock::mousePressEvent( QMouseEvent* e){ QMessageBox::information(this, " ", QString::number(e->x())+" "+QString::number(e->y()));}
#ifndef CLOCK_H#define CLOCK_H#include <qwidget.h>#include <qtimer.h>#include <qpixmap.h>#include <qbitmap.h>#include <qpainter.h>#include <qmsgbox.h>#include <stdio.h>#include <fstream.h>class clock : public QWidget{Q_OBJECT QPixmap mainMap; // жПОПЧПЕ ЙЪПВТБЦЕОЙЕ (ЖПФПЗТБЖЙС) QTimer *roundTimer; // чТБЭБАЭЙК ФБКНЕТ int currentSpeed; // уЛПТПУФШ ЧТБЭЕОЙС int currentSector; // оБРТБЧМЕОЙЕ УФТЕМЛЙ (УЕЛФПТ) QPainter *painter; // иХДПЦОЙЛ int pX; // рПЪЙГЙС ЛПОГБ УФТЕМЛЙ int pY; //------------------// int centerX; // рПЪЙГЙС ОБЮБМБ УФТЕМЛЙ int centerY; //------------------// int xR; // дМЙОБ УФТЕМЛЙ РП и int yR; // дМЙОБ УФТЕМЛЙ РП х float angle; // оБРТБЧМЕОЙЕ УФТЕМЛЙ (ХЗПМ)//--------------------------------------------------------------- гЧЕФБ ----// QRgb colorBack; // гЧЕФ ЖПОБ QRgb colorSecond; // гЧЕФ УФТЕМЛЙ int cSectorNumber; // лПМЙЮЕУФЧП ХЮБУФЛПЧ, ОБ ЛПФПТЩЕ ДЕМЙФУС ЛТХЗ float cSectorSmall; // тБЪНЕТ ФБЛПЗП ХЮБУФЛБpublic: clock(QWidget* parent=0, QString pathName="./"); void clearLast();////////////////////////////////////protected: void mousePressEvent( QMouseEvent* ); void paintEvent(QPaintEvent *event);public slots: void stepUp(); // пЮЕТЕДОПК ФЙЛ};#endif
test::test(){ pos = 0;}void test::paintEvent(QPaintEvent *event){ painter = new QPainter(this); QRegion region(60,60,400,400, QRegion::Ellipse); painter->setClipRegion(region); painter->setClipping(true); painter->begin(this); painter->drawLine(0+pos,0+pos,450-pos,340-pos); painter->end(); if (pos>430) pos=0; else pos+=10;}void test::mousePressEvent( QMouseEvent* e){QMessageBox::information(this, " ", QString::number(e->x())+" "+QString::number(e->y()));}