#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->horizontalSlider->setMaximum(100);
ui->horizontalSlider->setMinimum(0);
connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(hSliderValueChangdedSlot(int)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent *event){
double R = this->width()/3;
double r = R * 0.95;
QPainter p(this);
p.translate(this->width()/2,this->height()/2);
p.setPen(Qt::NoPen);
QBrush brush;
//dayuan
brush.setColor(QColor(90,90,90));
brush.setStyle(Qt::SolidPattern);
p.setBrush(brush);
p.drawEllipse(-R,-R,2*R,2*R);
//xiaoyuan
brush.setColor(QColor(10,10,10));
p.setBrush(brush);
p.drawEllipse(-r,-r,r*2,r*2);
//
brush.setColor(QColor(77,220,255));
p.setBrush(brush);
p.drawEllipse(-100,-100,200,200);
//
brush.setColor(QColor(0,0,0));
p.setBrush(brush);
p.drawEllipse(-60,-60,120,120);
//
QPen pen;pen.setColor(QColor(200,200,120 ));pen.setWidth(5);pen.setStyle(Qt::SolidLine);
p.setPen(pen);
p.save();
int keduValue = 0;
p.rotate(120);
for(int i=0;i<=50;i++){
pen.setColor(QColor(200,255-i*5,10 ));
p.setPen(pen);
if(i%5 == 0){
p.drawLine(0.8*r,0, 0.9*r,0);
//绘制文字
QString str = QString("%1").arg(keduValue);
p.drawText(0.7*r,0, str );
keduValue+=10;
}else {
p.drawLine(0.85*r,0, 0.9*r,0);
}
p.rotate(6);
}
p.restore();
p.rotate(120+3*ui->horizontalSlider->value());
pen.setColor(QColor(255,255,0));
p.setPen(pen);
QPoint pi[3]; pi[0].setX(0); pi[0].setY(-5);pi[1].setX(0); pi[1].setY(5);
pi[2].setX(r*0.8); pi[2].setY(0);
p.drawConvexPolygon(pi, 3);
//xiaoxiaoyuan
brush.setColor(QColor(255,128,10));
p.setBrush(brush);
p.drawEllipse(-10,-10,20,20);
}
void Widget::hSliderValueChangdedSlot(int)
{
qDebug()<<__func__;
//通知,整个窗口重绘
this->update();
}