diff options
author | No'am Rosenthal <noam.rosenthal@nokia.com> | 2009-11-26 15:41:45 -0800 |
---|---|---|
committer | No'am Rosenthal <noam.rosenthal@nokia.com> | 2009-11-26 15:41:45 -0800 |
commit | c503509d976ead029dd90d2bff0270309d0e868f (patch) | |
tree | 8907f3414db970644d642abbb43c0042ff683e22 | |
parent | f6d3e022165cb1abd312717a991d826099a2a1ca (diff) |
re-added scc examples
-rw-r--r-- | examples/examples.pro | 2 | ||||
-rw-r--r-- | examples/scc/algotest/algotest.pro | 6 | ||||
-rw-r--r-- | examples/scc/algotest/main.cpp | 56 | ||||
-rw-r--r-- | examples/scc/algotest/test.scxml | 145 | ||||
-rw-r--r-- | examples/scc/animations/animations.pro | 6 | ||||
-rw-r--r-- | examples/scc/animations/animations.scxml | 19 | ||||
-rw-r--r-- | examples/scc/animations/main.cpp | 81 | ||||
-rw-r--r-- | examples/scc/loginmvc/controller.scxml | 105 | ||||
-rw-r--r-- | examples/scc/loginmvc/frame.ui | 123 | ||||
-rw-r--r-- | examples/scc/loginmvc/loginmvc.pro | 8 | ||||
-rw-r--r-- | examples/scc/loginmvc/main.cpp | 193 | ||||
-rw-r--r-- | examples/scc/scc.pro | 2 |
12 files changed, 745 insertions, 1 deletions
diff --git a/examples/examples.pro b/examples/examples.pro index 13a7d6a..7d75832 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += blackjack calc +SUBDIRS += blackjack calc scc diff --git a/examples/scc/algotest/algotest.pro b/examples/scc/algotest/algotest.pro new file mode 100644 index 0000000..e5a1eba --- /dev/null +++ b/examples/scc/algotest/algotest.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +SOURCES += main.cpp +OTHER_FILES += test.scxml +STATECHARTS += test.scxml +CONFIG += scc console +QT -= gui diff --git a/examples/scc/algotest/main.cpp b/examples/scc/algotest/main.cpp new file mode 100644 index 0000000..4fe6364 --- /dev/null +++ b/examples/scc/algotest/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of SCXML on Qt labs +** +** $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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sc_test.h" +#include <QCoreApplication> +#include <QTimer> +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + SMClass_test stateMachine; + stateMachine.setupStateMachine(); + stateMachine.start(); + QObject::connect(stateMachine.state_Test2Sub1,SIGNAL(entered()),&stateMachine,SIGNAL(event_Event2())); + QObject::connect(&stateMachine,SIGNAL(finished()),&a,SLOT(quit())); + QTimer::singleShot(100,&stateMachine,SIGNAL(event_Event1())); + return a.exec(); +} + diff --git a/examples/scc/algotest/test.scxml b/examples/scc/algotest/test.scxml new file mode 100644 index 0000000..e17f9bf --- /dev/null +++ b/examples/scc/algotest/test.scxml @@ -0,0 +1,145 @@ +<?xml version="1.0" encoding="UTF8"?> +<!-- A wrapper state that contains all other states in this file +- it represents the complete state machine --> <scxml xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + initial="Main"> + <state id="Main"> + <!-- its initial state is Test1 --> + <initial> + <transition target="Test1"/> + </initial> + + <!-- Really simple state showing the basic syntax. --> + <state id="Test1"> + <initial> + <transition target="Test1Sub1"/> + </initial> + <!-- Runs before we go into the substate --> + <onentry> + <log expr=""Inside Test1""/> + </onentry> + + <!-- Here is our first substate --> + <state id="Test1Sub1"> + <onentry> + <log expr=""Inside Test1Sub1.""/> + </onentry> + <onexit> + <log expr=""Leaving Test1Sub1""/> + </onexit> + <!-- Go to Sub2 on Event1 --> + <transition event="Event1" target="Test1Sub2"/> + </state> + + <!-- Here is the second substate + It is final, so Test1 is done when we get here --> + <final id="Test1Sub2"/> + + <!-- We get this event when we reach Test1Sub2. --> + <transition event="done.state.Test1" target="Test2"/> + + <!-- We run this on the way out of Test1 --> + <onexit> + <log expr=""Leaving Test1...""/> + </onexit> + </state> + + <state id="Test2"> + <initial> + <transition target="Test2Sub1"/> + </initial> + + <!-- This time we reference a state + defined in an external file. Note that we could have + loaded the entire file by leaving off the #Test2Sub1, + but in that case we would need to rename one of the + Test2Sub1 states (here or in the external file) to + avoid the name collision --> + <state id="Test2Sub1"> + <onentry> + <log expr=""Inside Test2Sub1""/> + </onentry> + <transition event="Event2" target="Test2Sub2"/> + </state> + <final id="Test2Sub2"/> + + <!-- Test2Sub2 is defined as final, so this + event is generated when we reach it --> + <transition event="done.state.Test2" target="Test3"/> + </state> + + <state id="Test3"> + <initial> + <transition target="Test3Sub1"/> + </initial> + + <state id="Test3Sub1"> + <onentry> + <log expr=""Inside Test3Sub1...""/> + <!-- Send our self an event in 5s --> + <send event="Timer" delay="1500"/> + </onentry> + <!-- Transition on to Test4. + This will exit both us and our parent. --> + <transition event="Timer" target="Test4"/> + <onexit> + <log expr=""Leaving Test3Sub1...""/> + </onexit> + </state> + + <onexit> + <log expr=""Leaving Test3...""/> + </onexit> + </state> + + <state id="Test4"> + <onentry> + <log expr=""Inside Test4...""/> + </onentry> + <initial> + <transition target="Test4Sub1"/> + </initial> + + <state id="Test4Sub1"> + <onexit> + <log expr=""Leaving Test4Sub1...""/> + </onexit> + <!-- This transition causes the state to exit immediately + after entering Test4Sub1. The transition has no event + or guard so it is always active --> + <transition target="Test5"/> + </state> + </state> + + <state id="Test5"> + <onentry> + <log expr=""Inside Test5...""/> + </onentry> + <initial> + <transition target="Test5P"/> + </initial> + + <!-- Fire off our parallel states --> + <parallel id="Test5P"> + <final id="Test5PSub1"/> + <final id="Test5PSub2"/> + <onexit> + <log expr=""all parallel states done""/> + </onexit> + </parallel> + + <!-- The parallel states are all final, so this + event is generated immediately. Although not shown, + compound states (i.e., <state>s with content) + are permitted within <parallel> as well. --> + <transition event="done.state.Test5P" target="Done"/> + </state> + + <!-- This final state is an immediate child of Main + - when we get here, done.state.Main is generated. --> + <final id="Done"/> + <!-- End of Main > --> + <transition event="done.state.Main" target="final" /> + </state> + <final id="final"/> +</scxml> diff --git a/examples/scc/animations/animations.pro b/examples/scc/animations/animations.pro new file mode 100644 index 0000000..d501c13 --- /dev/null +++ b/examples/scc/animations/animations.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +OTHER_FILES += animations.scxml +STATECHARTS += animations.scxml +CONFIG += scc console +SOURCES += main.cpp +TARGET = animations diff --git a/examples/scc/animations/animations.scxml b/examples/scc/animations/animations.scxml new file mode 100644 index 0000000..0aabb64 --- /dev/null +++ b/examples/scc/animations/animations.scxml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:Qt="http://www.qtsoftware.com scxml-ext" + initial="hist"> + <datamodel> + <data id="anim" Qt:type="QPropertyAnimation*" expr="NULL" /> + <data id="indicator" Qt:type="QObject*" expr="NULL" /> + </datamodel> + <history id="hist" type="deep"> + <transition target="idle" /> + </history> + <state id="idle"> + <Qt:property object="_data.indicator" property="opacity" value="0" /> + <transition target="active" event="ev1()" Qt:animation="_data.anim" /> + </state> + <state id="active"> + <Qt:property object="_data.indicator" property="opacity" value="1" /> + <transition target="idle" event="ev1()" Qt:animation="_data.anim" /> + </state> +</scxml> diff --git a/examples/scc/animations/main.cpp b/examples/scc/animations/main.cpp new file mode 100644 index 0000000..296e582 --- /dev/null +++ b/examples/scc/animations/main.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of SCXML on Qt labs +** +** $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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sc_animations.h" +#include <QApplication> +#include <QGraphicsView> +#include <QLabel> +#include <QGraphicsProxyWidget> +#include <QShortcut> +#include <QGraphicsScene> +#include <QPushButton> +#include <QVBoxLayout> +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + SMClass_animations stateMachine; + QGraphicsView* gv = new QGraphicsView(); + QPushButton* b = new QPushButton(); + QWidget* w = new QWidget(); + QVBoxLayout* lyt = new QVBoxLayout(); + lyt->addWidget(gv); + lyt->addWidget(b); + b->setText("Push Me"); + QObject::connect(b,SIGNAL(clicked()),&stateMachine,SIGNAL(event_ev1())); + w->setLayout(lyt); + gv->setScene(new QGraphicsScene()); + gv->setInteractive(true); + gv->setFocus(); + QGraphicsProxyWidget* wdg = gv->scene()->addWidget(new QLabel("Hello World!")); + wdg->setOpacity(0); + QPropertyAnimation* anim = new QPropertyAnimation(); + anim->setPropertyName("opacity"); + anim->setTargetObject(wdg); + anim->setDuration(1000); + anim->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic)); + stateMachine.set_indicator(wdg); + stateMachine.set_anim(anim); + stateMachine.setupStateMachine(); + w->show(); + stateMachine.start(); + return a.exec(); +} + diff --git a/examples/scc/loginmvc/controller.scxml b/examples/scc/loginmvc/controller.scxml new file mode 100644 index 0000000..8bffc1a --- /dev/null +++ b/examples/scc/loginmvc/controller.scxml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<scxml xmlns="http://www.w3.org/2005/07/scxml" + xmlns:Qt="http://www.qtsoftware.com scxml-ext" + initial="root"> + <datamodel> + <data id="username" Qt:type="QString" /> + <data id="password" Qt:type="QString" /> + <data id="loginTimeout" Qt:type="int" expr="10000" /> + <data id="firstTime" Qt:type="bool" expr="true" /> + <data id="loginButton" Qt:type="QObject*" expr="NULL" /> + <data id="logoutButton" Qt:type="QObject*" expr="NULL" /> + <data id="cancelButton" Qt:type="QObject*" expr="NULL" /> + </datamodel> + <parallel id="root"> + <state id="business_logic"> + <initial> + <transition target="idle"> + <if cond="_data.firstTime"> + <send event="notify_welcome()" /> + <if cond="!_data.username.isEmpty()"> + <send event="notify_hello(QString)"> + <param expr="_data.username" /> + </send> + </if> + <assign dataid="firstTime" expr="false" /> + </if> + </transition> + </initial> + <state id="idle"> + <onentry><log level="0" label="Info" expr=""Now in Idle"" /><raise event="in_idle" /></onentry> + <onexit><log level="0" label="Info" expr=""Now not in Idle"" /><raise event="not_in_idle" /></onexit> + <transition target="trying_to_login" event="intent_login()" /> + <Qt:property object="_data.cancelButton" property="enabled" value="false" /> + </state> + <state id="trying_to_login"> + <Qt:property object="_data.cancelButton" property="enabled" value="true" /> + <transition event="cancel_login()" target="idle" /> + <transition event="login_timeout()" target="loginTimeout" /> + <onentry> + <log level="0" label="Info" expr=""Trying to log in"" /> + <send event="login_action(QString,QString)"> + <param expr="_data.username" /> + <param expr="_data.password" /> + </send> + <send id="cancel_login_timeout" event="login_timeout()" delay="_data.loginTimeout" /> + </onentry> + <onexit> + <cancel id="cancel_login_timeout" /> + </onexit> + <transition event="login_complete(bool)" cond="_event.data[0].toBool()" target="loggedIn" /> + <transition event="login_complete(bool)" cond="!_event.data[0].toBool()" target="loginError" /> + </state> + <state id="error" initial="loginError"> + <Qt:property object="_data.cancelButton" property="enabled" value="false" /> + <transition event="intent_continue()" target="idle" /> + <onentry> + <raise event="error.login()" /> + </onentry> + <state id="cancelled"> + <onentry> + <send event="notify_cancel()" /> + </onentry> + </state> + <state id="loginError"> + <onentry> + <log label="Error" level="1" expr="_data.username + ' ' + _data.password" /> + <send event="notify_error()" /> + </onentry> + </state> + <state id="loginTimeout"> + <onentry> + <log label="Error" level="1" expr="_data.username + ' ' + _data.password" /> + <send event="notify_timeout()" /> + </onentry> + </state> + </state> + <state id="loggedIn"> + <onentry> + <send event="notify_loggedIn()" /> + </onentry> + <transition event="intent_continue()" target="active" /> + </state> + <state id="active"> + <transition event="intent_logout()" target="idle" /> + <Qt:property object="_data.cancelButton" property="enabled" value="false" /> + </state> + <final id="exit" /> + </state> + <state id="gui" initial="hist"> + <history id="hist" type="deep"> + <transition target="gui_idle" /> + </history> + <state id="gui_idle"> + <Qt:property object="_data.loginButton" property="enabled" value="true" /> + <Qt:property object="_data.logoutButton" property="enabled" value="false" /> + <transition target="gui_active" cond="!In(idle)" /> + </state> + <state id="gui_active"> + <transition target="gui_idle" cond="In(idle)" /> + <Qt:property object="_data.loginButton" property="enabled" value="false" /> + <Qt:property object="_data.logoutButton" property="enabled" value="true" /> + </state> + </state> + </parallel> +</scxml> diff --git a/examples/scc/loginmvc/frame.ui b/examples/scc/loginmvc/frame.ui new file mode 100644 index 0000000..4b57955 --- /dev/null +++ b/examples/scc/loginmvc/frame.ui @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Frame</class> + <widget class="QFrame" name="Frame"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>337</width> + <height>158</height> + </rect> + </property> + <property name="windowTitle"> + <string>Login Workflow</string> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::AllNonFixedFieldsGrow</enum> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Username</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="usernameEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Password</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="passwordEdit"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Timeout</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QSlider" name="timeoutSlider"> + <property name="maximum"> + <number>20000</number> + </property> + <property name="singleStep"> + <number>500</number> + </property> + <property name="pageStep"> + <number>2000</number> + </property> + <property name="value"> + <number>10000</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QWidget" name="widget" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="loginButton"> + <property name="text"> + <string>Log In</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="logoutButton"> + <property name="text"> + <string>Logout</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cancelButton"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="5" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/scc/loginmvc/loginmvc.pro b/examples/scc/loginmvc/loginmvc.pro new file mode 100644 index 0000000..9af965a --- /dev/null +++ b/examples/scc/loginmvc/loginmvc.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +CONFIG += console scc +SOURCES = main.cpp +FORMS += frame.ui +QT += network +STATECHARTS += controller.scxml +OTHER_FILES += controller.scxml +CONFIG -= app_bundle diff --git a/examples/scc/loginmvc/main.cpp b/examples/scc/loginmvc/main.cpp new file mode 100644 index 0000000..a8e9ee9 --- /dev/null +++ b/examples/scc/loginmvc/main.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of SCXML on Qt labs +** +** $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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "sc_controller.h" +#include <QLabel> +#include <QMessageBox> +#include "ui_frame.h" +#include <QNetworkAccessManager> +#include <QNetworkReply> +#include <QSslSocket> +class AbstractModel : public QObject +{ + Q_OBJECT + public: + AbstractModel(QObject* o = NULL) : QObject(o) + { + } + public slots: + virtual void login(const QString & u, const QString & p) = 0; + signals: + void loginComplete(bool); +}; + +class DummyModel : public AbstractModel +{ + Q_OBJECT + public: + DummyModel(QObject* o = NULL) : AbstractModel(o) + { + } + public slots: + void test() + { + emit loginComplete(user == "user" && password == "password"); + } + virtual void login(const QString & u, const QString & p) + { + user = u; password = p; + QTimer::singleShot(5000,this,SLOT(test())); + } + signals: + void loginComplete(bool); + private: + QString user,password; + QNetworkAccessManager netAccess; +}; +class GMailModel : public AbstractModel +{ + Q_OBJECT + public: + GMailModel(QObject* o = NULL) : AbstractModel(o) + { + } + public slots: + void loginFinished() + { + QNetworkReply* rep = qobject_cast<QNetworkReply*>(sender()); + rep->deleteLater(); + qDebug() << rep->error() << rep->errorString(); + emit loginComplete(rep->error() == QNetworkReply::NoError); + } + virtual void login(const QString & u, const QString & p) + { + QNetworkRequest req; + QUrl url("/https://mail.google.com/mail/feed/atom"); + url.setUserName(u); + url.setPassword(p); + req.setUrl(url); + QNetworkReply* reply = netAccess.get(req); + reply->ignoreSslErrors(); + connect(reply,SIGNAL(finished()),this,SLOT(loginFinished())); + } + private: + QNetworkAccessManager netAccess; +}; + +class MyView : public QFrame, public virtual Ui::Frame +{ + Q_OBJECT + public: + QString welcomeText; + MyView(QWidget* o = NULL) : QFrame(o) + { + setupUi(this); + connect(loginButton,SIGNAL(clicked()),this,SIGNAL(loginIntent())); + connect(logoutButton,SIGNAL(clicked()),this,SIGNAL(logoutIntent())); + connect(cancelButton,SIGNAL(clicked()),this,SIGNAL(cancelIntent())); + } + + public slots: + + void notifyLogin() + { + QMessageBox::information(this,"Logged In","You are now logged in!"); + emit contIntent(); + } + void notifyTimeout() + { + QMessageBox::information(this,"Timeout...","Sorry, login has timed out"); + emit contIntent(); + } + void notifyWelcome() + { + QMessageBox::information(this,"Welcome!",welcomeText); + } + void notifyError() + { + qDebug() << "notifyError"; + QMessageBox::warning(this,"Not Logged in","Login has failed..."); + emit contIntent(); + } + + void notifyHello(const QString & name) + { + QMessageBox::information(this,"Welcome",QString("Hello ") + name); + } + + signals: + void loginIntent(); + void logoutIntent(); + void cancelIntent(); + void contIntent(); +}; +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + bool use_gmail = QSslSocket::supportsSsl () && !a.arguments().contains("--dummy"); + AbstractModel* model = use_gmail ? (AbstractModel*)new GMailModel() : (AbstractModel*)new DummyModel(); + MyView* view = new MyView(); + SMClass_controller *controller = new SMClass_controller(); + controller->setupStateMachine(); + controller->set_loginButton(view->loginButton); + controller->set_logoutButton(view->logoutButton); + controller->set_cancelButton(view->cancelButton); + view->welcomeText = (use_gmail ?"Please enter your GMail user/password":"Username=user, Password=password"); + QObject::connect(controller,SIGNAL(event_login_action(QString,QString)),model,SLOT(login(QString,QString))); + QObject::connect(controller,SIGNAL(event_notify_loggedIn()),view,SLOT(notifyLogin())); + QObject::connect(controller,SIGNAL(event_notify_error()),view,SLOT(notifyError())); + QObject::connect(controller,SIGNAL(event_notify_hello(QString)),view,SLOT(notifyHello(QString))); + QObject::connect(controller,SIGNAL(event_notify_welcome()),view,SLOT(notifyWelcome())); + QObject::connect(controller,SIGNAL(event_notify_timeout()),view,SLOT(notifyTimeout())); + QObject::connect(model,SIGNAL(loginComplete(bool)),controller,SIGNAL(event_login_complete(bool))); + QObject::connect(view,SIGNAL(loginIntent()),controller,SIGNAL(event_intent_login())); + QObject::connect(view,SIGNAL(cancelIntent()),controller,SIGNAL(event_cancel_login())); + QObject::connect(view,SIGNAL(logoutIntent()),controller,SIGNAL(event_intent_logout())); + QObject::connect(view,SIGNAL(contIntent()),controller,SIGNAL(event_intent_continue())); + QObject::connect(view->usernameEdit,SIGNAL(textChanged(QString)),controller,SLOT(set_username(QString))); + QObject::connect(view->passwordEdit,SIGNAL(textChanged(QString)),controller,SLOT(set_password(QString))); + QObject::connect(view->timeoutSlider,SIGNAL(valueChanged(int)),controller,SLOT(set_loginTimeout(int))); + controller->start(); + view->show(); + return a.exec(); +} +#include <main.moc> diff --git a/examples/scc/scc.pro b/examples/scc/scc.pro new file mode 100644 index 0000000..39b6dbb --- /dev/null +++ b/examples/scc/scc.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = loginmvc animations algotest |