void graphics::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if(mode == 2) HinhTron(painter);
if(mode == 3) HinhVuong(painter);
if(mode == 4) {HinhTron(painter); HinhVuong(painter);}
if(mode == 5) HinhTC(painter);
if(mode == 6) Venha(painter);
}
void graphics::HinhTron(QPainter& painter)
{
painter.setPen(Qt::green);
int w,h;
w=width();
h=height();
QPoint A(w/2,h/2);
painter.drawEllipse(A,100,100);
}
void graphics::HinhVuong(QPainter& painter)
{
painter.setPen(Qt::blue);
int w,h;
float x,y;
w=width();
h=height();
x=w/2-50*sqrt(2);
y=h/2-50*sqrt(2);
painter.drawRect(x,y,200/sqrt(2),200/sqrt(2));
}
void graphics::HinhTC(QPainter& painter)
{
painter.setPen(Qt::red);
int w,h;
w=width();
h=height();
QPoint A(w/2,h/2);
painter.drawEllipse(A,100,100);
QPoint B(w/2+50,h/2);
QPoint C(w/2-50,h/2);
painter.drawEllipse(B,10,10);
painter.drawEllipse(C,10,10);
painter.drawArc(w/2-100,h/2-50,100,100,0,-180*16);
painter.drawArc(w/2,h/2-50,100,100,0,180*16);
}
void graphics::Venha(QPainter& painter)
{
painter.setPen(Qt::blue);
int w,h;
w=width();
h=height();
QPolygon nha;
nha<<QPoint(100,200)<<QPoint(200,200)<<QPoint(200,100)<<QPoint(150,50)<<QPoint(1
00,100);
painter.drawPolygon(nha);
QPolygon cuachinh;
cuachinh<<QPoint(125,200)<<QPoint(125,160)<<QPoint(150,160)<<QPoint(150,200);
painter.drawPolyline(cuachinh);
QPolygon cuaso;
cuaso<<QPoint(160,140)<<QPoint(180,140)<<QPoint(180,120)<<QPoint(160,120);
painter.drawPolygon(cuaso);
QPolygon ongkhoi;
ongkhoi<<QPoint(110,90)<<QPoint(110,50)<<QPoint(120,50)<<QPoint(120,80);
painter.drawPolyline(ongkhoi);