#include <cannonfield.h>
Inheritance diagram for CannonField:


Definition at line 29 of file cannonfield.h.
Public Slots | |
| void | setAngle (int angle) |
| void | setForce (int force) |
| void | setAngle (int angle) |
| void | setForce (int force) |
| void | shoot () |
| void | setAngle (int angle) |
| void | setForce (int force) |
| void | shoot () |
| void | newTarget () |
| void | setAngle (int angle) |
| void | setForce (int force) |
| void | shoot () |
| void | newTarget () |
| void | setGameOver () |
| void | restartGame () |
| void | setAngle (int angle) |
| void | setForce (int force) |
| void | shoot () |
| void | newTarget () |
| void | setGameOver () |
| void | restartGame () |
| void | setAngle (int angle) |
| void | setAngle (int angle) |
Signals | |
| void | angleChanged (int newAngle) |
| void | forceChanged (int newForce) |
| void | angleChanged (int newAngle) |
| void | forceChanged (int newForce) |
| void | hit () |
| void | missed () |
| void | angleChanged (int newAngle) |
| void | forceChanged (int newForce) |
| void | hit () |
| void | missed () |
| void | angleChanged (int newAngle) |
| void | forceChanged (int newForce) |
| void | canShoot (bool can) |
| void | hit () |
| void | missed () |
| void | angleChanged (int newAngle) |
| void | forceChanged (int newForce) |
| void | canShoot (bool can) |
| void | angleChanged (int newAngle) |
| void | angleChanged (int newAngle) |
Public Member Functions | |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
| int | force () const |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
| int | force () const |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
| int | force () const |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
| int | force () const |
| bool | gameOver () const |
| bool | isShooting () const |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
| int | force () const |
| bool | gameOver () const |
| bool | isShooting () const |
| QSize | sizeHint () const |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
| CannonField (QWidget *parent=0) | |
| int | angle () const |
Protected Member Functions | |
| void | paintEvent (QPaintEvent *event) |
| void | paintEvent (QPaintEvent *event) |
| void | paintEvent (QPaintEvent *event) |
| void | paintEvent (QPaintEvent *event) |
| void | paintEvent (QPaintEvent *event) |
| void | mousePressEvent (QMouseEvent *event) |
| void | mouseMoveEvent (QMouseEvent *event) |
| void | mouseReleaseEvent (QMouseEvent *event) |
| void | paintEvent (QPaintEvent *event) |
| void | paintEvent (QPaintEvent *event) |
Private Slots | |
| void | moveShot () |
| void | moveShot () |
| void | moveShot () |
| void | moveShot () |
Private Member Functions | |
| QRect | cannonRect () const |
| void | paintShot (QPainter &painter) |
| void | paintCannon (QPainter &painter) |
| QRect | cannonRect () const |
| QRect | shotRect () const |
| void | paintShot (QPainter &painter) |
| void | paintTarget (QPainter &painter) |
| void | paintCannon (QPainter &painter) |
| QRect | cannonRect () const |
| QRect | shotRect () const |
| QRect | targetRect () const |
| void | paintShot (QPainter &painter) |
| void | paintTarget (QPainter &painter) |
| void | paintCannon (QPainter &painter) |
| QRect | cannonRect () const |
| QRect | shotRect () const |
| QRect | targetRect () const |
| void | paintShot (QPainter &painter) |
| void | paintTarget (QPainter &painter) |
| void | paintBarrier (QPainter &painter) |
| void | paintCannon (QPainter &painter) |
| QRect | cannonRect () const |
| QRect | shotRect () const |
| QRect | targetRect () const |
| QRect | barrierRect () const |
| bool | barrelHit (const QPoint &pos) const |
Private Attributes | |
| int | currentAngle |
| int | currentForce |
| int | timerCount |
| QTimer * | autoShootTimer |
| float | shootAngle |
| float | shootForce |
| QTimer * | autoShootTimer |
| QPoint | target |
| QTimer * | autoShootTimer |
| bool | gameEnded |
| QTimer * | autoShootTimer |
| bool | barrelPressed |
| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
Definition at line 29 of file cannonfield.cpp.
References currentAngle, currentForce, QWidget::setAutoFillBackground(), and QWidget::setPalette().
00030 : QWidget(parent) 00031 { 00032 currentAngle = 45; 00033 currentForce = 0; 00034 setPalette(QPalette(QColor(250, 250, 200))); 00035 setAutoFillBackground(true); 00036 }
Here is the call graph for this function:

| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
| CannonField::CannonField | ( | QWidget * | parent = 0 |
) |
| int CannonField::angle | ( | ) | const [inline] |
| int CannonField::force | ( | ) | const [inline] |
| void CannonField::setAngle | ( | int | angle | ) | [slot] |
Definition at line 38 of file cannonfield.cpp.
References angleChanged(), cannonRect(), currentAngle, emit, and QWidget::update().
Referenced by mouseMoveEvent().
00039 { 00040 if (angle < 5) 00041 angle = 5; 00042 if (angle > 70) 00043 angle = 70; 00044 if (currentAngle == angle) 00045 return; 00046 currentAngle = angle; 00047 update(cannonRect()); 00048 emit angleChanged(currentAngle); 00049 }
| void CannonField::setForce | ( | int | force | ) | [slot] |
Definition at line 51 of file cannonfield.cpp.
References currentForce, emit, and forceChanged().
00052 { 00053 if (force < 0) 00054 force = 0; 00055 if (currentForce == force) 00056 return; 00057 currentForce = force; 00058 emit forceChanged(currentForce); 00059 }
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
Referenced by setAngle().
| void CannonField::forceChanged | ( | int | newForce | ) | [signal] |
Referenced by setForce().
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
Definition at line 61 of file cannonfield.cpp.
References Qt::blue, currentAngle, QPainter::drawPie(), QPainter::drawRect(), QWidget::height(), Qt::NoPen, QPainter::rotate(), QPainter::setBrush(), QPainter::setPen(), and QPainter::translate().
00062 { 00063 QPainter painter(this); 00064 00065 painter.setPen(Qt::NoPen); 00066 painter.setBrush(Qt::blue); 00067 00068 painter.translate(0, height()); 00069 painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16); 00070 painter.rotate(-currentAngle); 00071 painter.drawRect(QRect(30, -5, 20, 10)); 00072 }
Here is the call graph for this function:

| QRect CannonField::cannonRect | ( | ) | const [private] |
Definition at line 74 of file cannonfield.cpp.
References QRect::moveBottomLeft(), and QWidget::rect().
Referenced by setAngle().
00075 { 00076 QRect result(0, 0, 50, 50); 00077 result.moveBottomLeft(rect().bottomLeft()); 00078 return result; 00079 }
Here is the call graph for this function:

| int CannonField::angle | ( | ) | const [inline] |
| int CannonField::force | ( | ) | const [inline] |
| void CannonField::setAngle | ( | int | angle | ) | [slot] |
| void CannonField::setForce | ( | int | force | ) | [slot] |
| void CannonField::shoot | ( | ) | [slot] |
Definition at line 69 of file cannonfield.cpp.
References autoShootTimer, currentAngle, currentForce, QTimer::isActive(), shootAngle, shootForce, QTimer::start(), and timerCount.
Referenced by GameBoard::fire().
00070 { 00071 if (autoShootTimer->isActive()) 00072 return; 00073 timerCount = 0; 00074 shootAngle = currentAngle; 00075 shootForce = currentForce; 00076 autoShootTimer->start(5); 00077 }
| void CannonField::moveShot | ( | ) | [private, slot] |
Definition at line 79 of file cannonfield.cpp.
References autoShootTimer, QWidget::height(), shotRect(), QTimer::stop(), timerCount, QRegion::unite(), QWidget::update(), QWidget::width(), QRect::x(), and QRect::y().
00080 { 00081 QRegion region = shotRect(); 00082 ++timerCount; 00083 00084 QRect shotR = shotRect(); 00085 00086 if (shotR.x() > width() || shotR.y() > height()) { 00087 autoShootTimer->stop(); 00088 } else { 00089 region = region.unite(shotR); 00090 } 00091 update(region); 00092 }
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
| void CannonField::forceChanged | ( | int | newForce | ) | [signal] |
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
| void CannonField::paintShot | ( | QPainter & | painter | ) | [private] |
Definition at line 103 of file cannonfield.cpp.
References Qt::black, QPainter::drawRect(), Qt::NoPen, QPainter::setBrush(), QPainter::setPen(), and shotRect().
00104 { 00105 painter.setPen(Qt::NoPen); 00106 painter.setBrush(Qt::black); 00107 painter.drawRect(shotRect()); 00108 }
Here is the call graph for this function:

| void CannonField::paintCannon | ( | QPainter & | painter | ) | [private] |
Definition at line 112 of file cannonfield.cpp.
References barrelRect, Qt::blue, currentAngle, QPainter::drawPie(), QPainter::drawRect(), QWidget::height(), Qt::NoPen, QPainter::restore(), QPainter::rotate(), QPainter::save(), QPainter::setBrush(), QPainter::setPen(), and QPainter::translate().
00113 { 00114 painter.setPen(Qt::NoPen); 00115 painter.setBrush(Qt::blue); 00116 00117 painter.save(); 00118 painter.translate(0, height()); 00119 painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16); 00120 painter.rotate(-currentAngle); 00121 painter.drawRect(barrelRect); 00122 painter.restore(); 00123 }
Here is the call graph for this function:

| QRect CannonField::cannonRect | ( | ) | const [private] |
| QRect CannonField::shotRect | ( | ) | const [private] |
Definition at line 132 of file cannonfield.cpp.
References barrelRect, QWidget::height(), QRect::moveCenter(), qRound(), QRect::right(), shootAngle, shootForce, timerCount, QWidget::x(), and QWidget::y().
Referenced by moveShot(), and paintShot().
00133 { 00134 const double gravity = 4; 00135 00136 double time = timerCount / 20.0; 00137 double velocity = shootForce; 00138 double radians = shootAngle * 3.14159265 / 180; 00139 00140 double velx = velocity * cos(radians); 00141 double vely = velocity * sin(radians); 00142 double x0 = (barrelRect.right() + 5) * cos(radians); 00143 double y0 = (barrelRect.right() + 5) * sin(radians); 00144 double x = x0 + velx * time; 00145 double y = y0 + vely * time - 0.5 * gravity * time * time; 00146 00147 QRect result(0, 0, 6, 6); 00148 result.moveCenter(QPoint(qRound(x), height() - 1 - qRound(y))); 00149 return result; 00150 }
Here is the call graph for this function:

| int CannonField::angle | ( | ) | const [inline] |
| int CannonField::force | ( | ) | const [inline] |
| void CannonField::setAngle | ( | int | angle | ) | [slot] |
| void CannonField::setForce | ( | int | force | ) | [slot] |
| void CannonField::shoot | ( | ) | [slot] |
| void CannonField::newTarget | ( | ) | [slot] |
Definition at line 83 of file cannonfield.cpp.
References QTime::currentTime(), qrand(), qsrand(), QTime::secsTo(), target, and QWidget::update().
Referenced by GameBoard::hit(), and GameBoard::newGame().
00084 { 00085 static bool firstTime = true; 00086 00087 if (firstTime) { 00088 firstTime = false; 00089 QTime midnight(0, 0, 0); 00090 qsrand(midnight.secsTo(QTime::currentTime())); 00091 } 00092 target = QPoint(200 + qrand() % 190, 10 + qrand() % 255); 00093 update(); 00094 }
| void CannonField::moveShot | ( | ) | [private, slot] |
| void CannonField::hit | ( | ) | [signal] |
| void CannonField::missed | ( | ) | [signal] |
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
| void CannonField::forceChanged | ( | int | newForce | ) | [signal] |
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
| void CannonField::paintShot | ( | QPainter & | painter | ) | [private] |
| void CannonField::paintTarget | ( | QPainter & | painter | ) | [private] |
Definition at line 132 of file cannonfield.cpp.
References Qt::black, QPainter::drawRect(), Qt::red, QPainter::setBrush(), QPainter::setPen(), and targetRect().
00133 { 00134 painter.setPen(Qt::black); 00135 painter.setBrush(Qt::red); 00136 painter.drawRect(targetRect()); 00137 }
Here is the call graph for this function:

| void CannonField::paintCannon | ( | QPainter & | painter | ) | [private] |
| QRect CannonField::cannonRect | ( | ) | const [private] |
| QRect CannonField::shotRect | ( | ) | const [private] |
| QRect CannonField::targetRect | ( | ) | const [private] |
Definition at line 181 of file cannonfield.cpp.
References QWidget::height(), QRect::moveCenter(), target, QPoint::x(), and QPoint::y().
Referenced by paintTarget().
00182 { 00183 QRect result(0, 0, 20, 10); 00184 result.moveCenter(QPoint(target.x(), height() - 1 - target.y())); 00185 return result; 00186 }
Here is the call graph for this function:

| int CannonField::angle | ( | ) | const [inline] |
| int CannonField::force | ( | ) | const [inline] |
| bool CannonField::gameOver | ( | ) | const [inline] |
Definition at line 40 of file cannonfield.h.
References gameEnded.
Referenced by GameBoard::fire().
00040 { return gameEnded; }
| bool CannonField::isShooting | ( | ) | const |
Definition at line 217 of file cannonfield.cpp.
References autoShootTimer, and QTimer::isActive().
Referenced by GameBoard::fire(), restartGame(), and setGameOver().
00218 { 00219 return autoShootTimer->isActive(); 00220 }
Here is the call graph for this function:

| void CannonField::setAngle | ( | int | angle | ) | [slot] |
| void CannonField::setForce | ( | int | force | ) | [slot] |
| void CannonField::shoot | ( | ) | [slot] |
| void CannonField::newTarget | ( | ) | [slot] |
| void CannonField::setGameOver | ( | ) | [slot] |
Definition at line 98 of file cannonfield.cpp.
References autoShootTimer, gameEnded, isShooting(), QTimer::stop(), and QWidget::update().
Referenced by GameBoard::hit(), and GameBoard::missed().
00099 { 00100 if (gameEnded) 00101 return; 00102 if (isShooting()) 00103 autoShootTimer->stop(); 00104 gameEnded = true; 00105 update(); 00106 }
| void CannonField::restartGame | ( | ) | [slot] |
Definition at line 108 of file cannonfield.cpp.
References autoShootTimer, canShoot(), emit, gameEnded, isShooting(), QTimer::stop(), and QWidget::update().
Referenced by GameBoard::newGame().
00109 { 00110 if (isShooting()) 00111 autoShootTimer->stop(); 00112 gameEnded = false; 00113 update(); 00114 emit canShoot(true); 00115 }
| void CannonField::moveShot | ( | ) | [private, slot] |
| void CannonField::hit | ( | ) | [signal] |
| void CannonField::missed | ( | ) | [signal] |
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
| void CannonField::forceChanged | ( | int | newForce | ) | [signal] |
| void CannonField::canShoot | ( | bool | can | ) | [signal] |
Referenced by restartGame().
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
| void CannonField::paintShot | ( | QPainter & | painter | ) | [private] |
| void CannonField::paintTarget | ( | QPainter & | painter | ) | [private] |
| void CannonField::paintCannon | ( | QPainter & | painter | ) | [private] |
| QRect CannonField::cannonRect | ( | ) | const [private] |
| QRect CannonField::shotRect | ( | ) | const [private] |
| QRect CannonField::targetRect | ( | ) | const [private] |
| int CannonField::angle | ( | ) | const [inline] |
| int CannonField::force | ( | ) | const [inline] |
| bool CannonField::gameOver | ( | ) | const [inline] |
| bool CannonField::isShooting | ( | ) | const |
| QSize CannonField::sizeHint | ( | ) | const [virtual] |
Reimplemented from QWidget.
Definition at line 274 of file cannonfield.cpp.
00275 { 00276 return QSize(400, 300); 00277 }
| void CannonField::setAngle | ( | int | angle | ) | [slot] |
| void CannonField::setForce | ( | int | force | ) | [slot] |
| void CannonField::shoot | ( | ) | [slot] |
| void CannonField::newTarget | ( | ) | [slot] |
| void CannonField::setGameOver | ( | ) | [slot] |
| void CannonField::restartGame | ( | ) | [slot] |
| void CannonField::moveShot | ( | ) | [private, slot] |
| void CannonField::hit | ( | ) | [signal] |
| void CannonField::missed | ( | ) | [signal] |
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
| void CannonField::forceChanged | ( | int | newForce | ) | [signal] |
| void CannonField::canShoot | ( | bool | can | ) | [signal] |
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
| void CannonField::mousePressEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
Reimplemented from QWidget.
Definition at line 141 of file cannonfield.cpp.
References barrelHit(), barrelPressed, QWidget::event(), and Qt::LeftButton.
00142 { 00143 if (event->button() != Qt::LeftButton) 00144 return; 00145 if (barrelHit(event->pos())) 00146 barrelPressed = true; 00147 }
Here is the call graph for this function:

| void CannonField::mouseMoveEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
Reimplemented from QWidget.
Definition at line 149 of file cannonfield.cpp.
References barrelPressed, QWidget::event(), QWidget::height(), QWidget::pos(), qRound(), QWidget::rect(), setAngle(), QPoint::setX(), QPoint::setY(), QPoint::x(), and QPoint::y().
00150 { 00151 if (!barrelPressed) 00152 return; 00153 QPoint pos = event->pos(); 00154 if (pos.x() <= 0) 00155 pos.setX(1); 00156 if (pos.y() >= height()) 00157 pos.setY(height() - 1); 00158 double rad = atan(((double)rect().bottom() - pos.y()) / pos.x()); 00159 setAngle(qRound(rad * 180 / 3.14159265)); 00160 }
Here is the call graph for this function:

| void CannonField::mouseReleaseEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget.
Reimplemented from QWidget.
Definition at line 162 of file cannonfield.cpp.
References barrelPressed, QWidget::event(), and Qt::LeftButton.
00163 { 00164 if (event->button() == Qt::LeftButton) 00165 barrelPressed = false; 00166 }
Here is the call graph for this function:

| void CannonField::paintShot | ( | QPainter & | painter | ) | [private] |
| void CannonField::paintTarget | ( | QPainter & | painter | ) | [private] |
| void CannonField::paintBarrier | ( | QPainter & | painter | ) | [private] |
Definition at line 199 of file cannonfield.cpp.
References barrierRect(), QPainter::drawRect(), QPainter::setBrush(), QPainter::setPen(), and Qt::yellow.
00200 { 00201 painter.setPen(Qt::black); 00202 painter.setBrush(Qt::yellow); 00203 painter.drawRect(barrierRect()); 00204 }
Here is the call graph for this function:

| void CannonField::paintCannon | ( | QPainter & | painter | ) | [private] |
| QRect CannonField::cannonRect | ( | ) | const [private] |
| QRect CannonField::shotRect | ( | ) | const [private] |
| QRect CannonField::targetRect | ( | ) | const [private] |
| QRect CannonField::barrierRect | ( | ) | const [private] |
Definition at line 255 of file cannonfield.cpp.
References QWidget::height().
Referenced by paintBarrier().
Here is the call graph for this function:

| bool CannonField::barrelHit | ( | const QPoint & | pos | ) | const [private] |
Definition at line 260 of file cannonfield.cpp.
References barrelRect, QRect::contains(), currentAngle, QWidget::height(), QMatrix::inverted(), QMatrix::map(), QWidget::pos(), QMatrix::rotate(), and QMatrix::translate().
Referenced by mousePressEvent().
00261 { 00262 QMatrix matrix; 00263 matrix.translate(0, height()); 00264 matrix.rotate(-currentAngle); 00265 matrix = matrix.inverted(); 00266 return barrelRect.contains(matrix.map(pos)); 00267 }
Here is the call graph for this function:

| int CannonField::angle | ( | ) | const [inline] |
| void CannonField::setAngle | ( | int | angle | ) | [slot] |
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
| int CannonField::angle | ( | ) | const [inline] |
| void CannonField::setAngle | ( | int | angle | ) | [slot] |
| void CannonField::angleChanged | ( | int | newAngle | ) | [signal] |
| void CannonField::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.
The background can be set using setBackgroundRole() and setPalette().
From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.
Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:
...
extern void qt_x11_set_global_double_buffer(bool);
qt_x11_set_global_double_buffer(false);
...
Reimplemented from QWidget.
int CannonField::currentAngle [private] |
Definition at line 53 of file cannonfield.h.
Referenced by angle(), barrelHit(), CannonField(), paintCannon(), paintEvent(), setAngle(), and shoot().
int CannonField::currentForce [private] |
Definition at line 54 of file cannonfield.h.
Referenced by CannonField(), force(), setForce(), and shoot().
int CannonField::timerCount [private] |
QTimer* CannonField::autoShootTimer [private] |
Definition at line 66 of file cannonfield.h.
Referenced by isShooting(), moveShot(), restartGame(), setGameOver(), and shoot().
float CannonField::shootAngle [private] |
float CannonField::shootForce [private] |
QTimer* CannonField::autoShootTimer [private] |
Definition at line 71 of file cannonfield.h.
QPoint CannonField::target [private] |
QTimer* CannonField::autoShootTimer [private] |
Definition at line 76 of file cannonfield.h.
bool CannonField::gameEnded [private] |
Definition at line 82 of file cannonfield.h.
Referenced by gameOver(), restartGame(), and setGameOver().
QTimer* CannonField::autoShootTimer [private] |
Definition at line 83 of file cannonfield.h.
bool CannonField::barrelPressed [private] |
Definition at line 90 of file cannonfield.h.
Referenced by mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().
1.5.1