diff options
Diffstat (limited to 'examples/statemachine')
40 files changed, 950 insertions, 1077 deletions
diff --git a/examples/statemachine/citizenquartz/citizenquartz.pro b/examples/statemachine/citizenquartz/citizenquartz.pro deleted file mode 100644 index 58039a0..0000000 --- a/examples/statemachine/citizenquartz/citizenquartz.pro +++ /dev/null @@ -1,20 +0,0 @@ -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -SOURCES += main.cpp \ - clock.cpp \ - clockbutton.cpp \ - clockdisplay.cpp \ - propertyaddstate.cpp \ - -HEADERS += clock.h \ - clockbutton.h \ - clockdisplay.h \ - propertyaddstate.h \ - timeperiod.h \ - -RESOURCES += citizenquartz.qrc -CONFIG += console diff --git a/examples/statemachine/citizenquartz/citizenquartz.qrc b/examples/statemachine/citizenquartz/citizenquartz.qrc deleted file mode 100644 index fc09ef9..0000000 --- a/examples/statemachine/citizenquartz/citizenquartz.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource> - <file>sound/alarm.wav</file> - <file>images/alarm.png</file> -</qresource> -</RCC>
\ No newline at end of file diff --git a/examples/statemachine/citizenquartz/clock.cpp b/examples/statemachine/citizenquartz/clock.cpp deleted file mode 100644 index 1b2b21e..0000000 --- a/examples/statemachine/citizenquartz/clock.cpp +++ /dev/null @@ -1,390 +0,0 @@ -#include "clock.h" -#include "clockbutton.h" -#include "clockdisplay.h" -#include "propertyaddstate.h" -#include "timeperiod.h" - -#include <QStateMachine> -#include <QState> -#include <QHistoryState> - -#include <QPainter> -#include <QTimer> -#include <QSound> - -Clock::Clock(QGraphicsItem *parent) - : QGraphicsItem(parent), - m_stateMachine(0), - m_clockDisplay(0), - m_buttonA(0), - m_buttonB(0), - m_buttonC(0), - m_buttonD(0), - m_alarmState(0), - m_timeState(0), - m_updateState(0), - m_regularState(0), - m_displaysHistoryState(0), - m_alarmSound(new QSound(":/sound/alarm.wav", this)) -{ -} - -void Clock::initializeUi() -{ - QPainterPath path = shape(); - QPointF pap; - qreal aap; - - m_buttonA = new ClockButton("Button A", this); - pap = path.pointAtPercent(0.05); - aap = path.angleAtPercent(0.05); - m_buttonA->translate(pap.x(), pap.y()); - m_buttonA->rotate(-aap); - connect(m_buttonA, SIGNAL(pressed()), this, SIGNAL(anyButtonPressed())); - - m_buttonB = new ClockButton("Button B", this); - pap = path.pointAtPercent(0.77); - aap = path.angleAtPercent(0.77); - m_buttonB->translate(pap.x(), pap.y()); - m_buttonB->rotate(-aap); - connect(m_buttonB, SIGNAL(pressed()), this, SIGNAL(anyButtonPressed())); - - m_buttonC = new ClockButton("Button C", this); - pap = path.pointAtPercent(0.67); - aap = path.angleAtPercent(0.67); - m_buttonC->translate(pap.x(), pap.y()); - m_buttonC->rotate(-aap); - connect(m_buttonC, SIGNAL(pressed()), this, SIGNAL(anyButtonPressed())); - - m_buttonD = new ClockButton("Button D", this); - pap = path.pointAtPercent(0.57); - aap = path.angleAtPercent(0.57); - m_buttonD->translate(pap.x(), pap.y()); - m_buttonD->rotate(-aap); - connect(m_buttonD, SIGNAL(pressed()), this, SIGNAL(anyButtonPressed())); - - QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); - label->setText("CITIZEN"); - label->setPos(0.0 - label->boundingRect().width() / 2.0, -100.0); - - m_clockDisplay = new ClockDisplay(this); - m_clockDisplay->setCurrentTime(QDateTime::currentDateTime()); - - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(updateTime())); - timer->setInterval(1); - timer->start(); - m_time.start(); -} - -void Clock::initializeStateMachine() -{ - m_stateMachine = new QStateMachine; - - QState *displays = new QState(m_stateMachine->rootState()); - displays->setObjectName("displays"); - initializeDisplaysState(displays); - - QState *alarmsBeepState = new QState(m_stateMachine->rootState()); - alarmsBeepState->setObjectName("alarmsBeep"); - alarmsBeepState->invokeMethodOnEntry(this, "playSound"); - alarmsBeepState->invokeMethodOnExit(this, "stopSound"); - - QTimer *alarmTimeOut = new QTimer(alarmsBeepState); - alarmTimeOut->setInterval(30000); - alarmsBeepState->invokeMethodOnEntry(alarmTimeOut, "start"); - alarmsBeepState->invokeMethodOnExit(alarmTimeOut, "stop"); - - displays->addTransition(m_clockDisplay, SIGNAL(alarmTriggered()), alarmsBeepState); - alarmsBeepState->addTransition(this, SIGNAL(anyButtonPressed()), m_displaysHistoryState); - alarmsBeepState->addTransition(alarmTimeOut, SIGNAL(timeout()), m_displaysHistoryState); - - m_stateMachine->setInitialState(displays); - m_stateMachine->start(); -} - -void Clock::initializeUpdateState(QState *updateState) -{ - QState *sec = new QState(updateState); - sec->setObjectName("sec"); - sec->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditSecondMode); - updateState->setInitialState(sec); - - PropertyAddState *secIncrease = new PropertyAddState(updateState); - secIncrease->setObjectName("sec ++"); - secIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setSeconds(1)); - sec->addTransition(m_buttonD, SIGNAL(pressed()), secIncrease); - secIncrease->addTransition(sec); - - QState *oneMin = new QState(updateState); - oneMin->setObjectName("1 min"); - oneMin->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditMinuteMode); - sec->addTransition(m_buttonC, SIGNAL(pressed()), oneMin); - - PropertyAddState *oneMinIncrease = new PropertyAddState(updateState); - oneMinIncrease->setObjectName("1 min ++"); - oneMinIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setMinutes(1)); - oneMin->addTransition(m_buttonD, SIGNAL(pressed()), oneMinIncrease); - oneMinIncrease->addTransition(oneMin); - - QState *tenMin = new QState(updateState); - tenMin->setObjectName("10 min"); - tenMin->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditMinuteMode); - oneMin->addTransition(m_buttonC, SIGNAL(pressed()), tenMin); - - PropertyAddState *tenMinIncrease = new PropertyAddState(updateState); - tenMinIncrease->setObjectName("10 min ++"); - tenMinIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setMinutes(10)); - tenMin->addTransition(m_buttonD, SIGNAL(pressed()), tenMinIncrease); - tenMinIncrease->addTransition(tenMin); - - QState *hr = new QState(updateState); - hr->setObjectName("hr"); - hr->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditHourMode); - tenMin->addTransition(m_buttonC, SIGNAL(pressed()), hr); - - PropertyAddState *hrIncrease = new PropertyAddState(updateState); - hrIncrease->setObjectName("hr ++"); - hrIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setHours(1)); - hr->addTransition(m_buttonD, SIGNAL(pressed()), hrIncrease); - hrIncrease->addTransition(hr); - - QState *mon = new QState(updateState); - mon->setObjectName("mon"); - mon->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditMonthMode); - hr->addTransition(m_buttonC, SIGNAL(pressed()), mon); - - PropertyAddState *monIncrease = new PropertyAddState(updateState); - monIncrease->setObjectName("mon ++"); - monIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setMonths(1)); - mon->addTransition(m_buttonD, SIGNAL(pressed()), monIncrease); - monIncrease->addTransition(mon); - - QState *day = new QState(updateState); - day->setObjectName("day"); - day->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditDayMode); - mon->addTransition(m_buttonC, SIGNAL(pressed()), day); - - PropertyAddState *dayIncrease = new PropertyAddState(updateState); - dayIncrease->setObjectName("day ++"); - dayIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setDays(1)); - day->addTransition(m_buttonD, SIGNAL(pressed()), dayIncrease); - dayIncrease->addTransition(day); - - QState *year = new QState(updateState); - year->setObjectName("year"); - year->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditYearMode); - day->addTransition(m_buttonC, SIGNAL(pressed()), year); - - PropertyAddState *yearIncrease = new PropertyAddState(updateState); - yearIncrease->setObjectName("year ++"); - yearIncrease->addToProperty(m_clockDisplay, "currentTime", TimePeriod().setYears(1)); - year->addTransition(m_buttonD, SIGNAL(pressed()), yearIncrease); - yearIncrease->addTransition(year); - year->addTransition(m_buttonC, SIGNAL(pressed()), m_timeState); -} - -void Clock::initializeRegularState(QState *regular) -{ - m_timeState = new QState(regular); - m_timeState->setObjectName("time"); - m_timeState->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::CurrentTimeMode); - - QState *date = new QState(regular); - date->setObjectName("date"); - date->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::CurrentDateMode); - - QState *dateTimerState = new QState(date); - dateTimerState->setObjectName("dateTimerState"); - - // Date state exits after 2 m - QTimer *dateTimer = new QTimer(dateTimerState); - dateTimer->setSingleShot(true); - dateTimer->setInterval(2*60000); - dateTimerState->invokeMethodOnEntry(dateTimer, "start"); - dateTimerState->invokeMethodOnExit(dateTimer, "stop"); - - date->setInitialState(dateTimerState); - - m_updateState = new QState(regular); - m_updateState->setObjectName("update"); - - // Update state exits after 2 m - QTimer *updateTimer = new QTimer(m_updateState); - updateTimer->setSingleShot(true); - updateTimer->setInterval(2 * 60000); - m_updateState->invokeMethodOnEntry(updateTimer, "start"); - m_updateState->invokeMethodOnExit(updateTimer, "stop"); - - initializeUpdateState(m_updateState); - - m_timeState->addTransition(m_buttonD, SIGNAL(pressed()), date); - date->addTransition(m_buttonD, SIGNAL(pressed()), m_timeState); - date->addTransition(dateTimer, SIGNAL(timeout()), m_timeState); - - m_updateState->addTransition(updateTimer, SIGNAL(timeout()), m_timeState); - m_updateState->addTransition(m_buttonB, SIGNAL(pressed()), m_timeState); - - regular->setInitialState(m_timeState); -} - -void Clock::initializeAlarmUpdateState(QState *update) -{ - QState *hr = new QState(update); - hr->setObjectName("hr"); - hr->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditAlarmHourMode); - - PropertyAddState *hrInc = new PropertyAddState(update); - hrInc->setObjectName("hr ++"); - hrInc->addToProperty(m_clockDisplay, "alarm", TimePeriod().setHours(1)); - hr->addTransition(m_buttonD, SIGNAL(pressed()), hrInc); - hrInc->addTransition(hr); - - QState *tenMin = new QState(update); - tenMin->setObjectName("10 min"); - tenMin->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditAlarmTenMinuteMode); - hr->addTransition(m_buttonC, SIGNAL(pressed()), tenMin); - - PropertyAddState *tenMinInc = new PropertyAddState(update); - tenMinInc->setObjectName("10 min ++"); - tenMinInc->addToProperty(m_clockDisplay, "alarm", TimePeriod().setMinutes(10)); - tenMin->addTransition(m_buttonD, SIGNAL(pressed()), tenMinInc); - tenMinInc->addTransition(tenMin); - - QState *oneMin = new QState(update); - oneMin->setObjectName("1 min"); - oneMin->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::EditAlarmMinuteMode); - tenMin->addTransition(m_buttonC, SIGNAL(pressed()), oneMin); - - PropertyAddState *oneMinInc = new PropertyAddState(update); - oneMinInc->setObjectName("1 min ++"); - oneMinInc->addToProperty(m_clockDisplay, "alarm", TimePeriod().setMinutes(1)); - oneMin->addTransition(m_buttonD, SIGNAL(pressed()), oneMinInc); - oneMinInc->addTransition(oneMin); - - oneMin->addTransition(m_buttonC, SIGNAL(pressed()), m_alarmState); - m_alarmState->addTransition(m_buttonC, SIGNAL(pressed()), hr); -} - -void Clock::initializeOutState(QState *out) -{ - m_alarmState = new QState(out); - m_alarmState->setObjectName("alarmState"); - m_alarmState->setPropertyOnEntry(m_clockDisplay, "displayMode", ClockDisplay::AlarmMode); - initializeAlarmState(m_alarmState); - out->setInitialState(m_alarmState); - - QState *alarmUpdate = new QState(out); - alarmUpdate->setObjectName("alarmUpdate"); - initializeAlarmUpdateState(alarmUpdate); - - alarmUpdate->addTransition(m_buttonB, SIGNAL(pressed()), m_alarmState); - m_alarmState->addTransition(m_buttonA, SIGNAL(pressed()), m_regularState); -} - -void Clock::initializeDisplaysState(QState *displays) -{ - m_regularState = new QState(displays); - m_regularState->setObjectName("regular"); - initializeRegularState(m_regularState); - displays->setInitialState(m_regularState); - - QState *out = new QState(displays); - out->setObjectName("out"); - - QTimer *outTimer = new QTimer(out); - outTimer->setSingleShot(true); - outTimer->setInterval(2 * 60000); - out->invokeMethodOnEntry(outTimer, "start"); - out->invokeMethodOnExit(outTimer, "stop"); - - initializeOutState(out); - - QState *wait = new QState(displays); - wait->setObjectName("wait"); - - QTimer *waitTimer = new QTimer(wait); - waitTimer->setSingleShot(true); - waitTimer->setInterval(2000); - wait->invokeMethodOnEntry(waitTimer, "start"); - wait->invokeMethodOnExit(waitTimer, "stop"); - - m_displaysHistoryState = displays->addHistoryState(QState::DeepHistory); - - m_timeState->addTransition(m_buttonC, SIGNAL(pressed()), wait); - wait->addTransition(waitTimer, SIGNAL(timeout()), m_updateState); - wait->addTransition(m_buttonC, SIGNAL(released()), m_timeState); - m_timeState->addTransition(m_buttonA, SIGNAL(pressed()), m_alarmState); - out->addTransition(outTimer, SIGNAL(timeout()), m_regularState); -} - -void Clock::initializeAlarmState(QState *alarmState) -{ - QState *offState = new QState(alarmState); - offState->setObjectName("alarmOff"); - offState->setPropertyOnEntry(m_clockDisplay, "alarmEnabled", false); - - QState *onState = new QState(alarmState); - onState->setObjectName("alarmOn"); - onState->setPropertyOnEntry(m_clockDisplay, "alarmEnabled", true); - - QHistoryState *history = alarmState->addHistoryState(); - history->setObjectName("alarmHistory"); - history->setDefaultState(offState); - - offState->addTransition(m_buttonD, SIGNAL(pressed()), onState); - onState->addTransition(m_buttonD, SIGNAL(pressed()), offState); - - QState *intermediate = new QState(alarmState); - intermediate->addTransition(history); - - alarmState->setInitialState(intermediate); -} - -QRectF Clock::boundingRect() const -{ - return shape().boundingRect(); -} - -QPainterPath Clock::shape() const -{ - QPainterPath path; - path.addRoundedRect(QRectF(-140.0, -100.0, 280.0, 200.0), 50.0, 50.0, Qt::RelativeSize); - - return path; -} - -void Clock::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - painter->setPen(Qt::black); - painter->setBrush(Qt::NoBrush); - - // Clock face - painter->drawPath(shape()); -} - -void Clock::updateTime() -{ - int elapsed = m_time.elapsed(); - if (elapsed > 0) { - m_time.restart(); - QDateTime currentTime = m_clockDisplay->currentTime(); - m_clockDisplay->setCurrentTime(currentTime.addMSecs(elapsed)); - - update(); - } -} - -void Clock::playSound() -{ - qDebug("playing sound"); - m_alarmSound->stop(); - m_alarmSound->play(); -} - -void Clock::stopSound() -{ - qDebug("stopping sound"); - m_alarmSound->stop(); -} - diff --git a/examples/statemachine/citizenquartz/clock.h b/examples/statemachine/citizenquartz/clock.h deleted file mode 100644 index afd6433..0000000 --- a/examples/statemachine/citizenquartz/clock.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef CLOCK_H -#define CLOCK_H - -#include <QGraphicsItem> -#include <QTime> - -class ClockButton ; -class ClockDisplay ; -class QStateMachine ; -class QState ; -class QTimerState ; -class QSound ; -class QHistoryState ; - -class Clock: public QObject, public QGraphicsItem -{ - Q_OBJECT -public: - Clock(QGraphicsItem *parent = 0); - - void initializeUi(); - void initializeStateMachine(); - - virtual QRectF boundingRect() const; - virtual QPainterPath shape() const; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - -signals: - void anyButtonPressed(); - -public slots: - void updateTime(); - void playSound(); - void stopSound(); - -private: - void initializeDisplaysState(QState *displays); - void initializeAlarmState(QState *alarmState); - void initializeRegularState(QState *regular); - void initializeUpdateState(QState *update); - void initializeOutState(QState *out); - void initializeAlarmUpdateState(QState *update); - - QStateMachine *m_stateMachine; - ClockDisplay *m_clockDisplay; - ClockButton *m_buttonA; - ClockButton *m_buttonB; - ClockButton *m_buttonC; - ClockButton *m_buttonD; - - QState *m_alarmState; - QState *m_timeState; - QState *m_updateState; - QState *m_regularState; - - QHistoryState *m_displaysHistoryState; - - QSound *m_alarmSound; - QTime m_time; -}; - -#endif // CLOCK_H diff --git a/examples/statemachine/citizenquartz/clockbutton.cpp b/examples/statemachine/citizenquartz/clockbutton.cpp deleted file mode 100644 index 7b86891..0000000 --- a/examples/statemachine/citizenquartz/clockbutton.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "clockbutton.h" - -#include <QPainter> - -ClockButton::ClockButton(const QString &name, QGraphicsItem *parent) : QGraphicsItem(parent) -{ - setObjectName(name); - setToolTip(name); - setAcceptedMouseButtons(Qt::LeftButton); -} - -QRectF ClockButton::boundingRect() const -{ - return QRectF(-10.0, -10.0, 20.0, 20.0); -} - -QPainterPath ClockButton::shape() const -{ - QPainterPath path; - path.addRoundedRect(boundingRect(), 15.0, 15.0, Qt::RelativeSize); - - return path; -} - -void ClockButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - painter->setBrush(Qt::black); - painter->drawPath(shape()); -} - -void ClockButton::mousePressEvent(QGraphicsSceneMouseEvent *) -{ - emit pressed(); -} - -void ClockButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - emit released(); -}
\ No newline at end of file diff --git a/examples/statemachine/citizenquartz/clockbutton.h b/examples/statemachine/citizenquartz/clockbutton.h deleted file mode 100644 index 02a7ccd..0000000 --- a/examples/statemachine/citizenquartz/clockbutton.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef CLOCKBUTTON_H -#define CLOCKBUTTON_H - -#include <QGraphicsItem> - -class ClockButton: public QObject, public QGraphicsItem -{ - Q_OBJECT -public: - ClockButton(const QString &name, QGraphicsItem *parent = 0); - - virtual QRectF boundingRect() const; - virtual QPainterPath shape() const; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); - -protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent *); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - -signals: - void pressed(); - void released(); -}; - -#endif //CLOCKBUTTON_H diff --git a/examples/statemachine/citizenquartz/clockdisplay.cpp b/examples/statemachine/citizenquartz/clockdisplay.cpp deleted file mode 100644 index db026f5..0000000 --- a/examples/statemachine/citizenquartz/clockdisplay.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "clockdisplay.h" - -#include <QPainter> -#include <QTimer> - -ClockDisplay::ClockDisplay(QGraphicsItem *parent) - : QGraphicsItem(parent), - m_displayMode(CurrentTimeMode), - m_currentTime(QDate(1970, 1, 1), QTime(0, 0)), - m_alarm(0, 0), - m_alarmEnabled(false), - m_blink(false) - -{ - m_text = new QGraphicsTextItem(this); - - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(toggleBlinkFlag())); - timer->start(500); - - QFont font = m_text->font(); - font.setPointSizeF(20.0); - m_text->setFont(font); - - m_text->translate(-100.0, -20.0); - - QPixmap pm(":/images/alarm.png"); - m_alarmSymbol = new QGraphicsPixmapItem(pm, this); - m_alarmSymbol->translate(-100.0, -60.0); - m_alarmSymbol->setOffset(5.0, 5.0); - m_alarmSymbol->scale(0.5, 0.5); -} - -ClockDisplay::~ClockDisplay() -{ -} - -void ClockDisplay::toggleBlinkFlag() -{ - m_blink = !m_blink; - update(); -} - -void ClockDisplay::updateText() -{ - switch (m_displayMode) { - case EditSecondMode: - if (m_blink) { - m_text->setHtml(m_currentTime.toString("hh:mm:'<font color=\"transparent\">'ss'</font>'")); - break; - } - // fall throoough - case EditMinuteMode: - if (m_blink) { - m_text->setHtml(m_currentTime.toString("hh:'<font color=\"transparent\">'mm'</font>':ss")); - break; - } - - // fall throoough - case EditHourMode: - if (m_blink) { - m_text->setHtml(m_currentTime.toString("'<font color=\"transparent\">'hh'</font>':mm:ss")); - break; - } - - // fall throoough - case CurrentTimeMode: - m_text->setHtml(m_currentTime.toString("hh:mm:ss")); - break; - - case EditMonthMode: - if (m_blink) { - m_text->setHtml(m_currentTime.toString("yyyy.'<font color=\"transparent\">'MM'</font>'.dd")); - break; - } - - // fall throoough - case EditDayMode: - if (m_blink) { - m_text->setHtml(m_currentTime.toString("yyyy.MM.'<font color=\"transparent\">'dd'</font>'")); - break; - } - - // fall throoough - case EditYearMode: - if (m_blink) { - m_text->setHtml(m_currentTime.toString("'<font color=\"transparent\">'yyyy'</font>'.MM.dd")); - break; - } - - // fall throoough - case CurrentDateMode: - m_text->setHtml(m_currentTime.toString("yyyy.MM.dd")); - break; - - case EditAlarmHourMode: - if (m_blink) { - m_text->setHtml(m_alarm.toString("'<font color=\"transparent\">'hh'</font>':mm")); - break; - } - - // fall throooough - case EditAlarmTenMinuteMode: - case EditAlarmMinuteMode: - if (m_blink) { - m_text->setHtml(m_alarm.toString("hh:'<font color=\"transparent\">'mm'</font>'")); - break; - } - - // fall throoough - case AlarmMode: - m_text->setHtml(m_alarm.toString("hh:mm")); - break; - - default: - m_text->setHtml("Not implemented"); - }; -} - -QRectF ClockDisplay::boundingRect() const -{ - return QRectF(-100.0, -60.0, 200.0, 120.0); -} - -void ClockDisplay::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - m_alarmSymbol->setVisible(m_alarmEnabled); - - updateText(); - - // Screen - painter->drawRoundedRect(boundingRect(), 15.0, 15.0, Qt::RelativeSize); - - // Button grid - painter->drawLine(QPointF(-100.0, -20.0), QPointF(100.0, -20.0)); - painter->drawLine(QPointF(-50.0, -60.0), QPointF(-50.0, -20.0)); - painter->drawLine(QPointF(0.0, -60.0), QPointF(0.0, -20.0)); - painter->drawLine(QPointF(50.0, -60.0), QPointF(50.0, -20.0)); -} diff --git a/examples/statemachine/citizenquartz/clockdisplay.h b/examples/statemachine/citizenquartz/clockdisplay.h deleted file mode 100644 index ec86509..0000000 --- a/examples/statemachine/citizenquartz/clockdisplay.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef CLOCKDISPLAY_H -#define CLOCKDISPLAY_H - -#include <QObject> -#include <QGraphicsItem> -#include <QDateTime> - -class ClockDisplay: public QObject, public QGraphicsItem -{ - Q_OBJECT - Q_ENUMS(DisplayMode) - Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode) - Q_PROPERTY(QDateTime currentTime READ currentTime WRITE setCurrentTime) - Q_PROPERTY(QTime alarm READ alarm WRITE setAlarm) - Q_PROPERTY(bool alarmEnabled READ alarmEnabled WRITE setAlarmEnabled) -public: - enum DisplayMode { - CurrentTimeMode, - EditSecondMode, - EditMinuteMode, - EditHourMode, - - CurrentDateMode, - EditMonthMode, - EditDayMode, - EditYearMode, - - AlarmMode, - EditAlarmHourMode, - EditAlarmTenMinuteMode, - EditAlarmMinuteMode, - - ChimeMode, - StopWatchMode, - ModeCount - }; - - ClockDisplay(QGraphicsItem *parent = 0); - virtual ~ClockDisplay(); - - void setDisplayMode(DisplayMode displayMode) { m_displayMode = displayMode; update(); } - DisplayMode displayMode() const { return m_displayMode; } - - QDateTime currentTime() const { return m_currentTime; } - void setCurrentTime(const QDateTime &time) - { - if (m_alarmEnabled && !alarmMatches(m_currentTime) && alarmMatches(time)) - emit alarmTriggered(); - m_currentTime = time; - update(); - } - - QTime alarm() const { return m_alarm; } - void setAlarm(const QTime &time) { m_alarm = time; update(); } - - bool alarmEnabled() const { return m_alarmEnabled; } - void setAlarmEnabled(bool enabled) { m_alarmEnabled = enabled; update(); } - - virtual QRectF boundingRect() const; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); - -signals: - void alarmTriggered(); - -private slots: - void toggleBlinkFlag(); - -private: - void updateText(); - - bool alarmMatches(const QDateTime &dt) - { - return (dt.time().hour() == m_alarm.hour() && dt.time().minute() == m_alarm.minute()); - } - - DisplayMode m_displayMode; - - QDateTime m_currentTime; - QTime m_alarm; - - QGraphicsTextItem *m_text; - QGraphicsPixmapItem *m_alarmSymbol; - - uint m_alarmEnabled : 1; - uint m_blink : 1; - uint m_reserved : 30; -}; - -#endif diff --git a/examples/statemachine/citizenquartz/images/alarm.png b/examples/statemachine/citizenquartz/images/alarm.png Binary files differdeleted file mode 100644 index a19778d..0000000 --- a/examples/statemachine/citizenquartz/images/alarm.png +++ /dev/null diff --git a/examples/statemachine/citizenquartz/main.cpp b/examples/statemachine/citizenquartz/main.cpp deleted file mode 100644 index 2c6b14c..0000000 --- a/examples/statemachine/citizenquartz/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include <QApplication> -#include <QGraphicsScene> -#include <QGraphicsView> - -#include "clock.h" - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - QGraphicsScene scene; - - Clock *clock = new Clock; - clock->initializeUi(); - clock->initializeStateMachine(); - scene.addItem(clock); - - QGraphicsView view(&scene); - view.setRenderHint(QPainter::Antialiasing); - view.show(); - - return app.exec(); -} diff --git a/examples/statemachine/citizenquartz/propertyaddstate.cpp b/examples/statemachine/citizenquartz/propertyaddstate.cpp deleted file mode 100644 index dd23948..0000000 --- a/examples/statemachine/citizenquartz/propertyaddstate.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "PropertyAddState.h" -#include "timeperiod.h" - -#include <QDateTime> -#include <QDebug> - -PropertyAddState::PropertyAddState(QState *parent) - : QState(parent) -{ -} - -void PropertyAddState::addToProperty(QObject *object, const char *propertyName, - const QVariant &valueToAdd) -{ - m_propertyAdditions.append(PropertyAdder(object, propertyName, valueToAdd)); -} - -QVariant PropertyAddState::addProperties(const QVariant ¤t, const QVariant &toAdd) const -{ - QVariant result; - switch (current.type()) { - case QVariant::DateTime: - result = current.toDateTime() + qvariant_cast<TimePeriod>(toAdd); - break; - case QVariant::Time: - result = current.toTime() + qvariant_cast<TimePeriod>(toAdd); - break; - default: - qWarning("PropertyAddState::addProperties: QVariant type '%s' not supported", - current.typeName()); - }; - - return result; -} - -void PropertyAddState::onEntry() -{ - foreach (PropertyAdder propertyAdder, m_propertyAdditions) { - QObject *object = propertyAdder.object; - QByteArray propertyName = propertyAdder.propertyName; - QVariant toAdd = propertyAdder.valueToAdd; - QVariant current = object->property(propertyName); - - object->setProperty(propertyName, addProperties(current, toAdd)); - } -} diff --git a/examples/statemachine/citizenquartz/propertyaddstate.h b/examples/statemachine/citizenquartz/propertyaddstate.h deleted file mode 100644 index 4d28055..0000000 --- a/examples/statemachine/citizenquartz/propertyaddstate.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef PropertyAddState_H -#define PropertyAddState_H - -#include <qstate.h> - -#include <QVariant> -#include <QList> - -class PropertyAddState: public QState -{ -public: - PropertyAddState(QState *parent = 0); - - void addToProperty(QObject *object, const char *propertyName, const QVariant &valueToAdd); - virtual void onEntry(); - -private: - QVariant addProperties(const QVariant ¤t, const QVariant &toAdd) const; - - struct PropertyAdder { - PropertyAdder(QObject *_object, const char *_propertyName, const QVariant &_valueToAdd) - : object(_object), propertyName(_propertyName), valueToAdd(_valueToAdd) - { - } - - QObject *object; - QByteArray propertyName; - QVariant valueToAdd; - }; - QList<PropertyAdder> m_propertyAdditions; -}; - -#endif // PropertyAddState_H diff --git a/examples/statemachine/citizenquartz/sound/alarm.wav b/examples/statemachine/citizenquartz/sound/alarm.wav Binary files differdeleted file mode 100644 index 1d9486f..0000000 --- a/examples/statemachine/citizenquartz/sound/alarm.wav +++ /dev/null diff --git a/examples/statemachine/citizenquartz/timeperiod.h b/examples/statemachine/citizenquartz/timeperiod.h deleted file mode 100644 index c5a3a16..0000000 --- a/examples/statemachine/citizenquartz/timeperiod.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef TIMEPERIOD_H -#define TIMEPERIOD_H - -#include <QDateTime> -#include <QTime> -#include <QDebug> - -class TimePeriod -{ -public: - TimePeriod() : m_seconds(0), m_minutes(0), m_hours(0), m_days(0), m_months(0), m_years(0) - { - } - - TimePeriod &setSeconds(int seconds) { m_seconds = seconds; return *this; } - int seconds() const { return m_seconds; } - - TimePeriod &setMinutes(int minutes) { m_minutes = minutes; return *this; } - int minutes() const { return m_minutes; } - - TimePeriod &setHours(int hours) { m_hours = hours; return *this; } - int hours() const { return m_hours; } - - TimePeriod &setDays(int days) { m_days = days; return *this; } - int days() const { return m_days; } - - TimePeriod &setMonths(int months) { m_months = months; return *this; } - int months() const { return m_months; } - - TimePeriod &setYears(int years) { m_years = years; return *this; } - int years() const { return m_years; } - - operator QVariant() const - { - QVariant v; - qVariantSetValue<TimePeriod>(v, *this); - return v; - } - -private: - int m_seconds; - int m_minutes; - int m_hours; - int m_days; - int m_months; - int m_years; -}; - -inline void operator+=(QDateTime &dateTime, const TimePeriod &timePeriod) -{ - dateTime = dateTime.addSecs(timePeriod.seconds()); - dateTime = dateTime.addSecs(timePeriod.minutes() * 60); - dateTime = dateTime.addSecs(timePeriod.hours() * 3600); - dateTime = dateTime.addDays(timePeriod.days()); - dateTime = dateTime.addMonths(timePeriod.months()); - dateTime = dateTime.addYears(timePeriod.years()); -} - -inline QDateTime operator+(const QDateTime &dateTime, const TimePeriod &timePeriod) -{ - QDateTime result(dateTime); - result += timePeriod; - - return result; -} - -inline void operator+=(QTime &time, const TimePeriod &timePeriod) -{ - time = time.addSecs(timePeriod.seconds()); - time = time.addSecs(timePeriod.minutes() * 60); - time = time.addSecs(timePeriod.hours() * 3600); -} - -inline QTime operator+(const QTime &time, const TimePeriod &timePeriod) -{ - QTime result(time); - result += timePeriod; - - return result; -} - -Q_DECLARE_METATYPE(TimePeriod) - -#endif \\ TIMEPERIOD_H diff --git a/examples/statemachine/eventtransitions/eventtransitions.pro b/examples/statemachine/eventtransitions/eventtransitions.pro index 6a976cb..7e92cf2 100644 --- a/examples/statemachine/eventtransitions/eventtransitions.pro +++ b/examples/statemachine/eventtransitions/eventtransitions.pro @@ -1,7 +1,7 @@ -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . +SOURCES = main.cpp -# Input -SOURCES += main.cpp +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/eventtransitions +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS eventtransitions.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/eventtransitions +INSTALLS += target sources diff --git a/examples/statemachine/factorial/factorial.pro b/examples/statemachine/factorial/factorial.pro index ac79117..14a6833 100644 --- a/examples/statemachine/factorial/factorial.pro +++ b/examples/statemachine/factorial/factorial.pro @@ -1,10 +1,11 @@ -TEMPLATE = app -TARGET = QT = core win32: CONFIG += console mac:CONFIG -= app_bundle -DEPENDPATH += . -INCLUDEPATH += . -# Input SOURCES += main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/factorial +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS factorial.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/factorial +INSTALLS += target sources diff --git a/examples/statemachine/pingpong/pingpong.pro b/examples/statemachine/pingpong/pingpong.pro index bff9cb8..42eab6c 100644 --- a/examples/statemachine/pingpong/pingpong.pro +++ b/examples/statemachine/pingpong/pingpong.pro @@ -1,10 +1,11 @@ QT = core -TEMPLATE = app -TARGET = win32: CONFIG += console mac:CONFIG -= app_bundle -DEPENDPATH += . -INCLUDEPATH += . -# Input -SOURCES += main.cpp +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/pingpong +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS pingpong.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/pingpong +INSTALLS += target sources diff --git a/examples/statemachine/tankgame/gameitem.cpp b/examples/statemachine/tankgame/gameitem.cpp index 1a2af71..ad8b37c 100644 --- a/examples/statemachine/tankgame/gameitem.cpp +++ b/examples/statemachine/tankgame/gameitem.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "gameitem.h" #include <QGraphicsScene> diff --git a/examples/statemachine/tankgame/gameitem.h b/examples/statemachine/tankgame/gameitem.h index 43b8785..90b0a6c 100644 --- a/examples/statemachine/tankgame/gameitem.h +++ b/examples/statemachine/tankgame/gameitem.h @@ -1,9 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef GAMEITEM_H #define GAMEITEM_H #include <QGraphicsItem> +QT_BEGIN_NAMESPACE class QLineF; +QT_END_NAMESPACE class GameItem: public QObject, public QGraphicsItem { Q_OBJECT diff --git a/examples/statemachine/tankgame/gameovertransition.cpp b/examples/statemachine/tankgame/gameovertransition.cpp index cec786e..360e902 100644 --- a/examples/statemachine/tankgame/gameovertransition.cpp +++ b/examples/statemachine/tankgame/gameovertransition.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "gameovertransition.h" #include "tankitem.h" @@ -8,7 +49,7 @@ GameOverTransition::GameOverTransition(QAbstractState *targetState) : QSignalTransition(new QSignalMapper(), SIGNAL(mapped(QObject*))) { setTargetState(targetState); - + QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject()); mapper->setParent(this); } @@ -36,4 +77,4 @@ bool GameOverTransition::eventTest(QEvent *e) } else { return false; } -}
\ No newline at end of file +} diff --git a/examples/statemachine/tankgame/gameovertransition.h b/examples/statemachine/tankgame/gameovertransition.h index 9a86b83..5e99a75 100644 --- a/examples/statemachine/tankgame/gameovertransition.h +++ b/examples/statemachine/tankgame/gameovertransition.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef GAMEOVERTRANSITION_H #define GAMEOVERTRANSITION_H diff --git a/examples/statemachine/tankgame/main.cpp b/examples/statemachine/tankgame/main.cpp index 26fc1bb..185ad68 100644 --- a/examples/statemachine/tankgame/main.cpp +++ b/examples/statemachine/tankgame/main.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include <QApplication> #include "mainwindow.h" diff --git a/examples/statemachine/tankgame/mainwindow.cpp b/examples/statemachine/tankgame/mainwindow.cpp index fcc0325..46e0db3 100644 --- a/examples/statemachine/tankgame/mainwindow.cpp +++ b/examples/statemachine/tankgame/mainwindow.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "mainwindow.h" #include "tankitem.h" #include "rocketitem.h" @@ -97,7 +138,7 @@ void MainWindow::init() addWall(QRectF(centerOfMap - QPointF(-50.0, -60.0), centerOfMap - QPointF(50.0, -50.0))); addWall(QRectF(centerOfMap + QPointF(-50.0, -50.0), centerOfMap + QPointF(-40.0, 50.0))); addWall(QRectF(centerOfMap - QPointF(-50.0, -50.0), centerOfMap - QPointF(-40.0, 50.0))); - + addWall(QRectF(sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, -10.0), sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, 100.0))); addWall(QRectF(sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, 10.0), @@ -108,18 +149,18 @@ void MainWindow::init() sceneRect.topRight() + QPointF(-100.0, sceneRect.height() / 2.0 + 5.0))); - QAction *addTankAction = menuBar()->addAction("&Add tank"); - QAction *runGameAction = menuBar()->addAction("&Run game"); + QAction *addTankAction = menuBar()->addAction("&Add tank"); + QAction *runGameAction = menuBar()->addAction("&Run game"); runGameAction->setObjectName("runGameAction"); - QAction *stopGameAction = menuBar()->addAction("&Stop game"); + QAction *stopGameAction = menuBar()->addAction("&Stop game"); menuBar()->addSeparator(); QAction *quitAction = menuBar()->addAction("&Quit"); - + connect(addTankAction, SIGNAL(triggered()), this, SLOT(addTank())); connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - - m_machine = new QStateMachine(this); - QState *stoppedState = new QState(m_machine->rootState()); + + m_machine = new QStateMachine(this); + QState *stoppedState = new QState(m_machine->rootState()); stoppedState->setObjectName("stoppedState"); stoppedState->assignProperty(runGameAction, "enabled", true); stoppedState->assignProperty(stopGameAction, "enabled", false); @@ -127,19 +168,19 @@ void MainWindow::init() m_machine->setInitialState(stoppedState); //! [5] - QState *spawnsAvailable = new QState(stoppedState); + QState *spawnsAvailable = new QState(stoppedState); spawnsAvailable->assignProperty(addTankAction, "enabled", true); - QState *noSpawnsAvailable = new QState(stoppedState); + QState *noSpawnsAvailable = new QState(stoppedState); noSpawnsAvailable->assignProperty(addTankAction, "enabled", false); -//! [5] +//! [5] spawnsAvailable->setObjectName("spawnsAvailable"); noSpawnsAvailable->setObjectName("noSpawnsAvailable"); spawnsAvailable->addTransition(this, SIGNAL(mapFull()), noSpawnsAvailable); //! [3] - QHistoryState *hs = new QHistoryState(stoppedState); + QHistoryState *hs = new QHistoryState(stoppedState); hs->setDefaultState(spawnsAvailable); //! [3] hs->setObjectName("hs"); @@ -158,7 +199,7 @@ void MainWindow::init() gameOverState->setObjectName("gameOverState"); gameOverState->assignProperty(stopGameAction, "enabled", false); connect(gameOverState, SIGNAL(entered()), this, SLOT(gameOver())); - + stoppedState->addTransition(runGameAction, SIGNAL(triggered()), m_runningState); m_runningState->addTransition(stopGameAction, SIGNAL(triggered()), stoppedState); @@ -168,12 +209,12 @@ void MainWindow::init() QTimer *timer = new QTimer(this); timer->setInterval(100); connect(timer, SIGNAL(timeout()), this, SLOT(runStep())); - connect(m_runningState, SIGNAL(entered()), timer, SLOT(start())); + connect(m_runningState, SIGNAL(entered()), timer, SLOT(start())); connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop())); m_machine->start(); m_time.start(); -} +} void MainWindow::runStep() { @@ -201,12 +242,12 @@ void MainWindow::gameOver() TankItem *lastTankStanding = 0; foreach (QGraphicsItem *item, items) { if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(item)) { - if (lastTankStanding = qobject_cast<TankItem *>(gameItem)) + if ((lastTankStanding = qobject_cast<TankItem *>(gameItem)) != 0) break; } } - QMessageBox::information(this, "Game over!", + QMessageBox::information(this, "Game over!", QString::fromLatin1("The tank played by '%1' has won!").arg(lastTankStanding->objectName())); } @@ -216,7 +257,7 @@ void MainWindow::addRocket() if (tankItem != 0) { RocketItem *rocketItem = new RocketItem; - QPointF s = tankItem->mapToScene(QPointF(tankItem->boundingRect().right() + 10.0, + QPointF s = tankItem->mapToScene(QPointF(tankItem->boundingRect().right() + 10.0, tankItem->boundingRect().center().y())); rocketItem->setPos(s); rocketItem->setDirection(tankItem->direction()); @@ -264,10 +305,10 @@ void MainWindow::addTank() bool ok; //! [1] - QString selectedName = QInputDialog::getItem(this, "Select a tank type", "Tank types", + QString selectedName = QInputDialog::getItem(this, "Select a tank type", "Tank types", itemNames, 0, false, &ok); //! [1] - + if (ok && !selectedName.isEmpty()) { int idx = itemNames.indexOf(selectedName); if (Plugin *plugin = idx >= 0 ? items.at(idx) : 0) { @@ -280,7 +321,7 @@ void MainWindow::addTank() emit mapFull(); m_gameOverTransition->addTankItem(tankItem); - + QState *region = new QState(m_runningState); region->setObjectName(QString::fromLatin1("region%1").arg(m_spawns.size())); //! [2] diff --git a/examples/statemachine/tankgame/mainwindow.h b/examples/statemachine/tankgame/mainwindow.h index 40e1595..4ae8f7a 100644 --- a/examples/statemachine/tankgame/mainwindow.h +++ b/examples/statemachine/tankgame/mainwindow.h @@ -1,14 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QTime> +QT_BEGIN_NAMESPACE class QGraphicsScene; class QStateMachine; class QState; +QT_END_NAMESPACE class GameOverTransition; class TankItem; + class MainWindow: public QMainWindow { Q_OBJECT @@ -34,14 +78,14 @@ private: void addWall(const QRectF &wall); QGraphicsScene *m_scene; - + QStateMachine *m_machine; QState *m_runningState; GameOverTransition *m_gameOverTransition; QList<TankItem *> m_spawns; QTime m_time; - + bool m_started : 1; }; diff --git a/examples/statemachine/tankgame/plugin.h b/examples/statemachine/tankgame/plugin.h index 2b48d43..ddd10b7 100644 --- a/examples/statemachine/tankgame/plugin.h +++ b/examples/statemachine/tankgame/plugin.h @@ -1,9 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef PLUGIN_H #define PLUGIN_H #include <QtPlugin> +QT_BEGIN_NAMESPACE class QState; +QT_END_NAMESPACE class Plugin { public: @@ -12,6 +55,8 @@ public: virtual QState *create(QState *parentState, QObject *tank) = 0; }; +QT_BEGIN_NAMESPACE Q_DECLARE_INTERFACE(Plugin, "TankPlugin") +QT_END_NAMESPACE #endif diff --git a/examples/statemachine/tankgame/rocketitem.cpp b/examples/statemachine/tankgame/rocketitem.cpp index c324980..3ace8e8 100644 --- a/examples/statemachine/tankgame/rocketitem.cpp +++ b/examples/statemachine/tankgame/rocketitem.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "rocketitem.h" #include "tankitem.h" @@ -53,7 +94,7 @@ void RocketItem::idle(qreal elapsed) if (tankItem != 0) tankItem->hitByRocket(); } - + scene()->removeItem(this); delete this; } diff --git a/examples/statemachine/tankgame/rocketitem.h b/examples/statemachine/tankgame/rocketitem.h index 189a1dd..31146a6 100644 --- a/examples/statemachine/tankgame/rocketitem.h +++ b/examples/statemachine/tankgame/rocketitem.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef ROCKETITEM_H #define ROCKETITEM_H @@ -12,7 +53,7 @@ public: virtual void idle(qreal elapsed); qreal speed() const { return 100.0; } void setDirection(qreal direction) { m_direction = direction; } - + protected: virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; @@ -22,5 +63,4 @@ private: qreal m_distance; }; - #endif diff --git a/examples/statemachine/tankgame/tankgame.pro b/examples/statemachine/tankgame/tankgame.pro index 46cfe2e..59415be 100644 --- a/examples/statemachine/tankgame/tankgame.pro +++ b/examples/statemachine/tankgame/tankgame.pro @@ -1,13 +1,19 @@ -###################################################################### -# Automatically generated by qmake (2.01a) on 22. apr 14:11:33 2009 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += C:/dev/kinetic/examples/statemachine/tankgame/. . - -# Input -HEADERS += mainwindow.h plugin.h tankitem.h rocketitem.h gameitem.h gameovertransition.h -SOURCES += main.cpp mainwindow.cpp tankitem.cpp rocketitem.cpp gameitem.cpp gameovertransition.cpp +HEADERS += mainwindow.h \ + plugin.h \ + tankitem.h \ + rocketitem.h \ + gameitem.h \ + gameovertransition.h +SOURCES += main.cpp \ + mainwindow.cpp \ + tankitem.cpp \ + rocketitem.cpp \ + gameitem.cpp \ + gameovertransition.cpp CONFIG += console + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgame.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame +INSTALLS += target sources diff --git a/examples/statemachine/tankgame/tankitem.cpp b/examples/statemachine/tankgame/tankitem.cpp index c322d21..393d65f 100644 --- a/examples/statemachine/tankgame/tankitem.cpp +++ b/examples/statemachine/tankgame/tankitem.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "tankitem.h" #include <QPainter> @@ -35,15 +76,15 @@ public: m_reverse = m_distance < 0.0; } - bool apply(qreal timeDelta) + bool apply(qreal timeDelta) { qreal dist = timeDelta * item()->speed() * (m_reverse ? -1.0 : 1.0); - bool done = false; - if (qAbs(m_distance) < qAbs(dist)) { + bool done = false; + if (qAbs(m_distance) < qAbs(dist)) { done = true; dist = m_distance; - } + } m_distance -= dist; qreal a = item()->direction() * M_PI / 180.0; @@ -69,14 +110,14 @@ public: m_reverse = m_distance < 0.0; } - bool apply(qreal timeDelta) + bool apply(qreal timeDelta) { qreal dist = timeDelta * item()->angularSpeed() * (m_reverse ? -1.0 : 1.0); - bool done = false; + bool done = false; if (qAbs(m_distance) < qAbs(dist)) { done = true; dist = m_distance; - } + } m_distance -= dist; item()->setDirection(item()->direction() + dist); @@ -88,7 +129,7 @@ private: bool m_reverse; }; -TankItem::TankItem(QObject *parent) +TankItem::TankItem(QObject *parent) : GameItem(parent), m_currentAction(0), m_currentDirection(0.0), m_enabled(true) { connect(this, SIGNAL(cannonFired()), this, SIGNAL(actionCompleted())); @@ -106,7 +147,7 @@ void TankItem::idle(qreal elapsed) QGraphicsItem *item = 0; qreal distance = distanceToObstacle(&item); if (TankItem *tankItem = qgraphicsitem_cast<TankItem *>(item)) - emit tankSpotted(tankItem->direction(), distance); + emit tankSpotted(tankItem->direction(), distance); } } } @@ -119,7 +160,7 @@ void TankItem::hitByRocket() void TankItem::setAction(Action *newAction) { - if (m_currentAction != 0) + if (m_currentAction != 0) delete m_currentAction; m_currentAction = newAction; @@ -184,9 +225,9 @@ void TankItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge QRectF cannonBase = brect.adjusted(10.0, 6.0, -12.0, -6.0); painter->drawEllipse(cannonBase); - painter->drawRect(QRectF(QPointF(cannonBase.center().x(), cannonBase.center().y() - 2.0), + painter->drawRect(QRectF(QPointF(cannonBase.center().x(), cannonBase.center().y() - 2.0), QPointF(brect.right(), cannonBase.center().y() + 2.0))); - + // left track painter->setBrush(QBrush(Qt::black, Qt::VerPattern)); QRectF leftTrackRect = QRectF(brect.topLeft(), QPointF(brect.right() - 2.0, brect.top() + 4.0)); @@ -223,7 +264,7 @@ qreal TankItem::direction() const void TankItem::setDirection(qreal newDirection) { - int fullRotations = int(newDirection) / 360; + int fullRotations = int(newDirection) / 360; newDirection -= fullRotations * 360.0; qreal diff = newDirection - m_currentDirection; @@ -245,8 +286,8 @@ qreal TankItem::distanceToObstacle(QGraphicsItem **obstacle) const QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem); if (collidedItem != 0) { if (obstacle != 0) - *obstacle = collidedItem; - + *obstacle = collidedItem; + QPointF d = nextPosition - pos(); return sqrt(pow(d.x(), 2) + pow(d.y(), 2)); } else { @@ -259,5 +300,3 @@ qreal TankItem::distanceToObstacle() const return distanceToObstacle(0); } - - diff --git a/examples/statemachine/tankgame/tankitem.h b/examples/statemachine/tankgame/tankitem.h index 9475397..942fca8 100644 --- a/examples/statemachine/tankgame/tankitem.h +++ b/examples/statemachine/tankgame/tankitem.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef TANKITEM_H #define TANKITEM_H @@ -12,9 +53,9 @@ class TankItem: public GameItem Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) Q_PROPERTY(qreal direction READ direction WRITE turnTo) Q_PROPERTY(qreal distanceToObstacle READ distanceToObstacle) -public: +public: TankItem(QObject *parent = 0); - + void setColor(const QColor &color) { m_color = color; } QColor color() const { return m_color; } @@ -53,7 +94,7 @@ public slots: //! [0] protected: - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); private: diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp index c196247..d360de9 100644 --- a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp +++ b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "random_ai_plugin.h" #include <QState> diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h index f5e3b6f..9faeeac 100644 --- a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h +++ b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef RANDOM_AI_PLUGIN_H #define RANDOM_AI_PLUGIN_H @@ -19,7 +60,7 @@ signals: void moveForwardsSelected(); void moveBackwardsSelected(); void turnSelected(); - + protected: void onEntry(QEvent *) { diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp index 2fb05d4..6aae015 100644 --- a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp +++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "seek_ai.h" QState *SeekAi::create(QState *parentState, QObject *tank) @@ -12,10 +53,10 @@ QState *SeekAi::create(QState *parentState, QObject *tank) QState *lookForNearestWall = new SearchState(tank, seek); lookForNearestWall->setObjectName("lookForNearestWall"); seek->setInitialState(lookForNearestWall); - + QState *driveToFirstObstacle = new QState(seek); driveToFirstObstacle->setObjectName("driveToFirstObstacle"); - lookForNearestWall->addTransition(lookForNearestWall, SIGNAL(nearestObstacleStraightAhead()), + lookForNearestWall->addTransition(lookForNearestWall, SIGNAL(nearestObstacleStraightAhead()), driveToFirstObstacle); QState *drive = new QState(driveToFirstObstacle); @@ -23,25 +64,25 @@ QState *SeekAi::create(QState *parentState, QObject *tank) driveToFirstObstacle->setInitialState(drive); connect(drive, SIGNAL(entered()), tank, SLOT(moveForwards())); connect(drive, SIGNAL(exited()), tank, SLOT(stop())); - + // Go in loop QState *finishedDriving = new QState(driveToFirstObstacle); finishedDriving->setObjectName("finishedDriving"); drive->addTransition(tank, SIGNAL(actionCompleted()), finishedDriving); finishedDriving->addTransition(drive); - + QState *turnTo = new QState(seek); turnTo->setObjectName("turnTo"); driveToFirstObstacle->addTransition(new CollisionTransition(tank, turnTo)); - + turnTo->addTransition(tank, SIGNAL(actionCompleted()), driveToFirstObstacle); ChaseState *chase = new ChaseState(tank, topLevel); - chase->setObjectName("chase"); - seek->addTransition(new TankSpottedTransition(tank, chase)); + chase->setObjectName("chase"); + seek->addTransition(new TankSpottedTransition(tank, chase)); chase->addTransition(chase, SIGNAL(finished()), driveToFirstObstacle); chase->addTransition(new TankSpottedTransition(tank, chase)); - + return topLevel; } diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h index 9d4aabc..e44ad07 100644 --- a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h +++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef SEEK_AI_H #define SEEK_AI_H @@ -15,18 +56,18 @@ class SearchState: public QState { Q_OBJECT public: - SearchState(QObject *tank, QState *parentState = 0) - : QState(parentState), - m_tank(tank), - m_distanceToTurn(360.0), + SearchState(QObject *tank, QState *parentState = 0) + : QState(parentState), + m_tank(tank), + m_distanceToTurn(360.0), m_nearestDistance(-1.0), - m_directionOfNearestObstacle(0.0) + m_directionOfNearestObstacle(0.0) { } public slots: void turnAlittle() - { + { qreal dist = m_tank->property("distanceToObstacle").toDouble(); if (m_nearestDistance < 0.0 || dist < m_nearestDistance) { @@ -72,7 +113,7 @@ private: class CollisionTransition: public QSignalTransition { public: - CollisionTransition(QObject *tank, QState *turnTo) + CollisionTransition(QObject *tank, QState *turnTo) : QSignalTransition(tank, SIGNAL(collision(QLineF))), m_tank(tank), m_turnTo(turnTo) @@ -99,7 +140,7 @@ protected: if (qrand() % 2 == 0) newDirection = angleOfWall; else - newDirection = angleOfWall - 180.0; + newDirection = angleOfWall - 180.0; m_turnTo->assignProperty(m_tank, "direction", newDirection); } @@ -115,7 +156,7 @@ class ChaseState: public QState class GoToLocationState: public QState { public: - GoToLocationState(QObject *tank, QState *parentState = 0) + GoToLocationState(QObject *tank, QState *parentState = 0) : QState(parentState), m_tank(tank), m_distance(0.0) { } @@ -123,7 +164,7 @@ class ChaseState: public QState void setDistance(qreal distance) { m_distance = distance; } protected: - void onEntry() + void onEntry() { QMetaObject::invokeMethod(m_tank, "moveForwards", Q_ARG(qreal, m_distance)); } diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp index de95f41..581a6b2 100644 --- a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp +++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "spin_ai.h" #include <QtPlugin> @@ -5,24 +46,24 @@ QState *SpinAi::create(QState *parentState, QObject *tank) { QState *topLevel = new QState(parentState); - QState *spinState = new SpinState(tank, topLevel); + QState *spinState = new SpinState(tank, topLevel); topLevel->setInitialState(spinState); // When tank is spotted, fire two times and go back to spin state QState *fireState = new QState(topLevel); QState *fireOnce = new QState(fireState); - fireState->setInitialState(fireOnce); + fireState->setInitialState(fireOnce); connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon())); QState *fireTwice = new QState(fireState); connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon())); - + fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice); fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState); - + spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState); - + return topLevel; } diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h index d8d3d73..652e8b8 100644 --- a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h +++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef SPIN_AI_H #define SPIN_AI_H @@ -16,7 +57,7 @@ public: } public slots: - void spin() + void spin() { m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0); } @@ -25,7 +66,7 @@ protected: void onEntry(QEvent *) { connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); - spin(); + spin(); } void onExit(QEvent *) diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp index 5499ba3..19137b2 100644 --- a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp +++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "spin_ai_with_error.h" #include <QtPlugin> @@ -5,7 +46,7 @@ QState *SpinAiWithError::create(QState *parentState, QObject *tank) { QState *topLevel = new QState(parentState); - QState *spinState = new SpinState(tank, topLevel); + QState *spinState = new SpinState(tank, topLevel); topLevel->setInitialState(spinState); // When tank is spotted, fire two times and go back to spin state @@ -17,12 +58,12 @@ QState *SpinAiWithError::create(QState *parentState, QObject *tank) QState *fireTwice = new QState(fireState); connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon())); - + fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice); fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState); - + spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState); - + return topLevel; } diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h index 456ba01..e040bf2 100644 --- a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h +++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef SPIN_AI_WITH_ERROR_H #define SPIN_AI_WITH_ERROR_H @@ -16,7 +57,7 @@ public: } public slots: - void spin() + void spin() { m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0); } @@ -25,7 +66,7 @@ protected: void onEntry(QEvent *) { connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); - spin(); + spin(); } void onExit(QEvent *) diff --git a/examples/statemachine/trafficlight/trafficlight.pro b/examples/statemachine/trafficlight/trafficlight.pro index 730bd75..684575a 100644 --- a/examples/statemachine/trafficlight/trafficlight.pro +++ b/examples/statemachine/trafficlight/trafficlight.pro @@ -1,9 +1,4 @@ -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -SOURCES += main.cpp +SOURCES = main.cpp # install target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/trafficlight diff --git a/examples/statemachine/twowaybutton/twowaybutton.pro b/examples/statemachine/twowaybutton/twowaybutton.pro index 6a976cb..f6cbc57 100644 --- a/examples/statemachine/twowaybutton/twowaybutton.pro +++ b/examples/statemachine/twowaybutton/twowaybutton.pro @@ -1,7 +1,7 @@ -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . +SOURCES = main.cpp -# Input -SOURCES += main.cpp +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/twowaybutton +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS twowaybutton.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/twowaybutton +INSTALLS += target sources |