123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
-
-
-
-
-
-
-
-
- #include "bird.h"
- #include <QDebug>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Bird::Bird(QWidget *parent) :
- QWidget(parent)
- {
- QString prism[5] = {"green", "blue", "red", "yellow", "white"} ;
- size = randInt(1, 4) * 50 ;
- resize(size+2,size+2) ;
- move(0,0) ;
- eyeBrow = (EyeBrowType)randInt(0,3);
- color = prism[randInt(0,4)] ;
- eColor = prism[randInt(0,4)] ;
- setAttribute(Qt::WA_TranslucentBackground);
- setStyleSheet("background:transparent;");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Bird::Bird(int s, EyeBrowType eb, QString col, QString eye, QWidget *parent):
- QWidget(parent)
- {
- resize(s+2,s+2) ;
- move(0,0) ;
- size = s; eyeBrow = eb; color=col ; eColor = eye ;
- setAttribute(Qt::WA_TranslucentBackground);
- setStyleSheet("background:transparent;");
- }
-
-
-
-
-
-
- QString Bird::getEyeColor() const {
- return eColor ;
- }
-
-
-
-
-
-
- QString Bird::getFaceColor() const {
- return color ;
- }
-
-
-
-
-
-
-
-
- void Bird::setEyeColor(QString eye){
- eColor = eye ;
- }
-
-
-
-
-
-
-
-
- void Bird::setFaceColor(QString col){
- color = col;
- }
-
-
-
-
-
-
- int Bird::getSize() const {
- return size ;
- }
-
-
-
-
-
-
- Bird::EyeBrowType Bird::getEyebrow() const{
- return eyeBrow ;
- }
-
-
-
-
-
-
-
-
- void Bird::setSize(int s){
-
- if(s <= 50) { size = 50; }
- else if (s >= 200) { size = 200; }
- else { size = s; }
-
- resize(size + 2, size + 2) ;
- }
-
-
-
-
-
-
-
-
- void Bird::setEyebrow(EyeBrowType eb){
- if(eb < 0 || eb > 3)
- eyeBrow = UNI ;
- else eyeBrow = eb;
- }
-
-
-
-
-
-
-
-
- Qt::GlobalColor Bird::getColor(QString color) const{
-
- if(color=="red")
- return Qt::red ;
- else if (color == "green")
- return Qt::green ;
- else if (color == "yellow")
- return Qt::yellow ;
- else if(color == "blue")
- return Qt::blue ;
- else
- return Qt::white ;
-
- }
-
-
-
-
-
-
-
-
-
-
- int Bird::randInt(int min, int max){
- return qrand() % ((max +1 )- min) + min ;
- }
-
-
-
-
-
-
-
-
-
-
- void Bird::paintEvent(QPaintEvent *) {
- QPainter p(this);
-
- QPen outlinePen(Qt::black);
- QPen eyebrowsPen(Qt::black) ;
-
- int ball_size = getSize() ;
- float half_ball = ball_size/2.0 ;
- float white_ball = ball_size / 4.0 ;
- float black_ball = white_ball * .5 ;
- float up_gap = ball_size * .10 ;
- float eyebrow_gap = ball_size *.18 ;
-
- outlinePen.setWidth(2);
- eyebrowsPen.setWidth(ball_size *.05);
-
-
- p.setPen(outlinePen) ;
- p.setBrush(getColor(getFaceColor())) ;
- p.drawEllipse(0, 0, ball_size, ball_size);
-
-
- p.setBrush(getColor(getEyeColor())) ;
- p.drawEllipse(half_ball-white_ball,ball_size/2-up_gap,white_ball,white_ball) ;
- p.drawEllipse(half_ball,ball_size/2-up_gap,white_ball,white_ball) ;
-
-
- p.setBrush(Qt::black) ;
- p.drawEllipse(half_ball-black_ball,ball_size/2-up_gap+(white_ball-black_ball)/2.0,black_ball,black_ball) ;
- p.drawEllipse(half_ball,ball_size/2-up_gap+(white_ball-black_ball)/2.0 ,black_ball,black_ball) ;
-
-
-
- p.setPen(eyebrowsPen) ;
-
- if(eyeBrow == UNI){
-
- p.drawLine(white_ball, ball_size/2-eyebrow_gap, 3*white_ball,ball_size/2-eyebrow_gap) ;
- }
- else if(eyeBrow == ANGRY){
-
-
- p.drawLine(white_ball, ball_size/2-eyebrow_gap, 2*white_ball, ball_size/2-eyebrow_gap+up_gap) ;
- p.drawLine(2*white_ball, ball_size/2-eyebrow_gap + up_gap, 3*white_ball,ball_size/2-eyebrow_gap) ;
- }
- else if(eyeBrow == UPSET){
-
- p.drawLine(white_ball, ball_size/2-eyebrow_gap, 2*white_ball, ball_size/2-eyebrow_gap+up_gap/2) ;
- p.drawLine(2*white_ball, ball_size/2-eyebrow_gap + up_gap/2, 3*white_ball,ball_size/2-eyebrow_gap) ;
-
- }
- else{
-
- p.drawLine(white_ball, ball_size/2-eyebrow_gap, 2*white_ball, ball_size/2-eyebrow_gap+up_gap) ;
- p.drawLine(2*white_ball, ball_size/2-eyebrow_gap + up_gap, 3*white_ball,ball_size/2-eyebrow_gap) ;
- p.drawLine(white_ball, ball_size/2-eyebrow_gap, 2*white_ball, ball_size/2-eyebrow_gap+up_gap/2) ;
- p.drawLine(2*white_ball, ball_size/2-eyebrow_gap + up_gap/2, 3*white_ball,ball_size/2-eyebrow_gap) ;
-
- }
-
- }
|