Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# cannonfield.cpp Example File
tutorial/t9/cannonfield.cpp

        /****************************************************************
        **
        ** Implementation CannonField class, Qt tutorial 9
        **
        ****************************************************************/

        #include <QPainter>

        #include "cannonfield.h"

        CannonField::CannonField(QWidget *parent)
            : QWidget(parent)
        {
            ang = 45;
            setPalette(QPalette(QColor(250, 250, 200)));
        }

        void CannonField::setAngle(int angle)
        {
            if (angle < 5)
                angle = 5;
            if (angle > 70)
                angle = 70;
            if (ang == angle)
                return;
            ang = angle;
            update();
            emit angleChanged(ang);
        }

        void CannonField::paintEvent(QPaintEvent * /* event */)
        {
            QPainter painter(this);

            painter.setPen(Qt::NoPen);
            painter.setBrush(Qt::blue);

            painter.translate(0, rect().height());
            painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16);
            painter.rotate(-ang);
            painter.drawRect(QRect(33, -4, 15, 8));
        }