Thread: [Ktutorial-commits] SF.net SVN: ktutorial:[94] trunk/ktutorial/ktutorial-library/src
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-02-23 16:43:49
|
Revision: 94 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=94&view=rev Author: danxuliu Date: 2010-02-23 16:43:06 +0000 (Tue, 23 Feb 2010) Log Message: ----------- Add a bundled tutorial that shows how tutorials are used. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/KTutorial.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-library/src/tutorials/ trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-23 16:20:14 UTC (rev 93) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-02-23 16:43:06 UTC (rev 94) @@ -3,6 +3,7 @@ add_definitions("-fPIC") add_subdirectory(scripting) +add_subdirectory(tutorials) add_subdirectory(view) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/view ${KDE4_INCLUDES}) @@ -28,7 +29,7 @@ # (needed in KTutorial.cpp as it includes view/TutorialManagerDialog.h) add_dependencies(ktutorial ktutorial_view) -target_link_libraries(ktutorial ktutorial_scripting ktutorial_view) +target_link_libraries(ktutorial ktutorial_scripting ktutorial_tutorials ktutorial_view) ####### Install the library ####### Modified: trunk/ktutorial/ktutorial-library/src/KTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-02-23 16:20:14 UTC (rev 93) +++ trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-02-23 16:43:06 UTC (rev 94) @@ -25,6 +25,7 @@ #include "TutorialInformation.h" #include "scripting/ScriptingModule.h" #include "scripting/ScriptManager.h" +#include "tutorials/UsingKTutorial.h" #include "view/StepWidget.h" #include "view/TutorialManagerDialog.h" @@ -68,6 +69,8 @@ mParent = window; + registerTutorial(new UsingKTutorial()); + ScriptManager().loadTutorials(mTutorialmanager); } Added: trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt 2010-02-23 16:43:06 UTC (rev 94) @@ -0,0 +1,7 @@ +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../view ${KDE4_INCLUDES}) + +set(ktutorial_tutorials_SRCS + UsingKTutorial.cpp +) + +kde4_add_library(ktutorial_tutorials ${ktutorial_tutorials_SRCS}) Property changes on: trunk/ktutorial/ktutorial-library/src/tutorials/CMakeLists.txt ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp 2010-02-23 16:43:06 UTC (rev 94) @@ -0,0 +1,406 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "UsingKTutorial.h" + +#include <QMouseEvent> +#include <QTextEdit> + +#include <KLocalizedString> + +#include "../KTutorial.h" +#include "../Option.h" +#include "../Step.h" +#include "../TutorialInformation.h" +#include "../WaitForSignal.h" +#include "../view/StepWidget.h" + +class ClearTextStep: public Step { +public: + + ClearTextStep(UsingKTutorial* usingKTutorial): + Step("clearText"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QTextEdit* textEdit = new QTextEdit(KTutorial::self()->parentWidget()); + textEdit->setAttribute(Qt::WA_DeleteOnClose); + textEdit->setWindowFlags(Qt::Window); + textEdit->setObjectName("usingKTutorialTextEdit"); + textEdit->setText(i18nc("Plain text in a QTextEdit", + "Look at me! I am the text area!")); + textEdit->show(); + + mWaitForTextChanged = new WaitForSignal(textEdit, + SIGNAL(textChanged())); + addWaitFor(mWaitForTextChanged, + mUsingKTutorial, SLOT(clearTextTextModified())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForTextChanged); + delete mWaitForTextChanged; + } + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForTextChanged; + +}; + +class CloseTextEditStep: public Step { +Q_OBJECT +public: + + CloseTextEditStep(UsingKTutorial* usingKTutorial): + Step("closeTextEdit"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QTextEdit* textEdit = KTutorial::self()->findObject<QTextEdit*>( + "usingKTutorialTextEdit"); + //The filter is removed when the text edit is deleted, that is, when it + //is closed. + textEdit->installEventFilter(this); + + mWaitForWidgetClosed = new WaitForSignal(this, + SIGNAL(textEditClosed())); + addWaitFor(mWaitForWidgetClosed, + mUsingKTutorial, SLOT(closeTextEditDone())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForWidgetClosed); + delete mWaitForWidgetClosed; + } + + bool eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::Close) { + emit textEditClosed(); + } + + return false; + } + +Q_SIGNALS: + + void textEditClosed(); + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForWidgetClosed; + +}; + +class MoveWidgetPressStep: public Step { +Q_OBJECT +public: + + MoveWidgetPressStep(UsingKTutorial* usingKTutorial): + Step("moveWidgetPress"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QWidget* mStepWidget = KTutorial::self()-> + findObject<view::StepWidget*>("ktutorial_StepWidget"); + //The filter is removed when the widget is deleted, that is, when the + //tutorial is closed. + mStepWidget->installEventFilter(this); + + mWaitForMousePressed = new WaitForSignal(this, + SIGNAL(mousePressedOnWidget())); + addWaitFor(mWaitForMousePressed, + mUsingKTutorial, SLOT(moveWidgetPressDone())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForMousePressed); + delete mWaitForMousePressed; + } + + bool eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); + if (mouseEvent->button() == Qt::LeftButton) { + emit mousePressedOnWidget(); + } + } + + return false; + } + +Q_SIGNALS: + + void mousePressedOnWidget(); + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForMousePressed; + +}; + +class MoveWidgetReleaseStep: public Step { +Q_OBJECT +public: + + MoveWidgetReleaseStep(UsingKTutorial* usingKTutorial): + Step("moveWidgetRelease"), + mUsingKTutorial(usingKTutorial) { + } + + virtual void setup() { + QWidget* mStepWidget = KTutorial::self()-> + findObject<view::StepWidget*>("ktutorial_StepWidget"); + //The filter is removed when the widget is deleted, that is, when the + //tutorial is closed. + mStepWidget->installEventFilter(this); + + mWaitForMouseReleased = new WaitForSignal(this, + SIGNAL(mouseReleasedOnWidget())); + addWaitFor(mWaitForMouseReleased, + mUsingKTutorial, SLOT(moveWidgetReleaseDone())); + } + + virtual void tearDown() { + removeWaitFor(mWaitForMouseReleased); + delete mWaitForMouseReleased; + } + + bool eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::MouseButtonRelease) { + emit mouseReleasedOnWidget(); + } + + return false; + } + +Q_SIGNALS: + + void mouseReleasedOnWidget(); + +private: + + UsingKTutorial* mUsingKTutorial; + WaitFor* mWaitForMouseReleased; + +}; + +//public: + +UsingKTutorial::UsingKTutorial(): Tutorial(0) { + mTutorialInformation = new TutorialInformation("usingKTutorial"); + mTutorialInformation->setName(i18n("Using KTutorial")); + mTutorialInformation->setDescription(i18n("This tutorial shows how the " + "tutorial system works")); + + //Step start + Step* startStep = new Step("start"); + startStep->setText(i18nc("@info", +"<para>Welcome to the tutorial to learn how to use tutorials ;)</para>" +"<para>But, what is a tutorial? A tutorial is a little guide to help you to " +"learn how to use an application. For example, it shows you how some feature " +"works, or how to accomplish some task.</para>")); + + startStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(startDone())); + + addStep(startStep); + + //Step singleOption + Step* singleOptionStep = new Step("singleOption"); + singleOptionStep->setText(i18nc("@info", +"<para>A tutorial is composed of several steps, each one containing a bit of " +"information.</para>" +"<para>There are several ways to advance from one step to another. For " +"example, clicking on the button below will change to the next step.</para>")); + + singleOptionStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(singleOptionDone())); + + addStep(singleOptionStep); + + //Step severalOptions + Step* severalOptionsStep = new Step("severalOptions"); + severalOptionsStep->setText(i18nc("@info", +"<para>In other steps you may have more than one option to select. This can be " +"used, for example, to follow one path or another in the tutorial, skip some " +"part of the tutorial, etcetera. Which option do you prefer?</para>")); + + severalOptionsStep->addOption(new Option(i18nc("@action", "Option 1")), + this, SLOT(severalOptionsOption1Selected())); + severalOptionsStep->addOption(new Option(i18nc("@action", "Option 2")), + this, SLOT(severalOptionsOption2Selected())); + + addStep(severalOptionsStep); + + //Step option1Selected + Step* option1SelectedStep = new Step("option1Selected"); + option1SelectedStep->setText(i18nc("@info", +"<para>You have selected <emphasis>%1</emphasis>. Don't worry, as this is just " +"an example, selecting one option or the other makes no difference.</para>" +"<para>In the next step you will learn the last way to advance from one step " +"to another. To show this to you I will open a new window where text can be " +"written.</para>", i18nc("@action", "Option 1"))); + + option1SelectedStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(optionSelectedDone())); + + addStep(option1SelectedStep); + + //Step option2Selected + Step* option2SelectedStep = new Step("option2Selected"); + option2SelectedStep->setText(i18nc("@info", +"<para>You have selected <emphasis>%1</emphasis>. Don't worry, as this is just " +"an example, selecting one option or the other makes no difference.</para>" +"<para>In the next step you will learn the last way to advance from one step " +"to another. To show this to you I will open a new window where text can be " +"written.</para>", i18nc("@action", "Option 2"))); + + option2SelectedStep->addOption(new Option(i18nc("@action", "Continue")), + this, SLOT(optionSelectedDone())); + + addStep(option2SelectedStep); + + //Step clearText + Step* clearTextStep = new ClearTextStep(this); + clearTextStep->setText(i18nc("@info", +"<para>Do you see the new window that has appeared? Yes, the one that says " +"that it is a text area. Well, the last way to advance from one step to " +"another is just doing what you are asked for.</para>" +"<para>In this case, empty the text area erasing all its text and once you " +"have done it look again to the tutorial.</para>")); + + //WaitFor is added in step setup, as it has to create a QTextEdit when the + //step is activated + + addStep(clearTextStep); + + //Step closeTextEdit + Step* closeTextEditStep = new CloseTextEditStep(this); + closeTextEditStep->setText(i18nc("@info", +"<para>Do you see? You are in a new step, but you didn't tell the tutorial to " +"continue to the next step, and neither you had to select between several " +"options. The tutorial advanced automatically when you erased the text as " +"requested. This will be the most common way to advance from one step to " +"another.</para>" +"<para>Ok, close the window with the text area to continue with the " +"tutorial.</para>")); + + //WaitFor is added in step setup, as it uses an object that isn't available + //when the tutorial is created + + addStep(closeTextEditStep); + + //Step moveWidgetPress + Step* moveWidgetPressStep = new MoveWidgetPressStep(this); + moveWidgetPressStep->setText(i18nc("@info", +"<para>You may have noticed that the tutorial window has no border. Does that " +"mean that it can't be moved? Not at all. It can be dragged using the mouse " +"like any other window, but pressing in a different place. Let's see " +"how.</para>" +"<para>Above these paragraphs you can see an empty space, next to the button " +"at the corner. Press with the left button of your mouse on it. Just press, " +"don't release the button yet.</para>")); + + //WaitFor is added in step setup, as it uses an object that isn't available + //when the tutorial is created + + addStep(moveWidgetPressStep); + + //Step moveWidgetRelease + Step* moveWidgetReleaseStep = new MoveWidgetReleaseStep(this); + moveWidgetReleaseStep->setText(i18nc("@info", +"<para>Now, and without releasing the button, move the mouse and the window " +"will be moved. Once you release the button, the window will be kept in the " +"place it was. Of course, you can move it again dragging it like you " +"have just done.</para>")); + + //WaitFor is added in step setup, as it uses an object that isn't available + //when the tutorial is created + + addStep(moveWidgetReleaseStep); + + //Step end + Step* endStep = new Step("end"); + endStep->setText(i18nc("@info", +"<para>And that's all. You can now close the tutorial. In fact, you could have " +"closed the tutorial in any other of the previous steps, but if you do that " +"when the tutorial is started again it won't remember what you did. It will " +"start from the beginning again.</para>" +"<para>But how do you close the tutorial? Well, do you see that button above " +"this text, in the corner, with an icon that looks like a close icon? Do you " +"guess what it does? ;) Just click on it and you will return to the tutorial " +"selection dialog. Bye!</para>")); + + addStep(endStep); +} + +//public slots: + +void UsingKTutorial::startDone() { + nextStep("singleOption"); +} + +void UsingKTutorial::singleOptionDone() { + nextStep("severalOptions"); +} + +void UsingKTutorial::severalOptionsOption1Selected() { + nextStep("option1Selected"); +} + +void UsingKTutorial::severalOptionsOption2Selected() { + nextStep("option2Selected"); +} + +void UsingKTutorial::optionSelectedDone() { + nextStep("clearText"); +} + +void UsingKTutorial::clearTextTextModified() { + QTextEdit* textEdit = KTutorial::self()-> + findObject<QTextEdit*>("usingKTutorialTextEdit"); + + if (textEdit->toPlainText().isEmpty()) { + nextStep("closeTextEdit"); + } +} + +void UsingKTutorial::closeTextEditDone() { + nextStep("moveWidgetPress"); +} + +void UsingKTutorial::moveWidgetPressDone() { + nextStep("moveWidgetRelease"); +} + +void UsingKTutorial::moveWidgetReleaseDone() { + nextStep("end"); +} + +#include "moc_UsingKTutorial.cpp" +#include "UsingKTutorial.moc" Property changes on: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.cpp ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h 2010-02-23 16:43:06 UTC (rev 94) @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef USINGKTUTORIAL_H +#define USINGKTUTORIAL_H + +#include "../Tutorial.h" + +class UsingKTutorial: public Tutorial { +Q_OBJECT +public: + + UsingKTutorial(); + +public Q_SLOTS: + + void startDone(); + + void singleOptionDone(); + + void severalOptionsOption1Selected(); + + void severalOptionsOption2Selected(); + + void optionSelectedDone(); + + void clearTextTextModified(); + + void closeTextEditDone(); + + void moveWidgetPressDone(); + + void moveWidgetReleaseDone(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/tutorials/UsingKTutorial.h ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2011-07-06 19:35:44
|
Revision: 331 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=331&view=rev Author: danxuliu Date: 2011-07-06 19:35:38 +0000 (Wed, 06 Jul 2011) Log Message: ----------- Fix being unable to call setProperty(QObject*, QString, QVariant) from Ruby scripts. A new method, setPropertyToWaitFor, had to be added to avoid the name clash with setProperty(QObject*, QString). Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp trunk/ktutorial/ktutorial-library/src/WaitForProperty.h Modified: trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp 2011-06-21 15:24:13 UTC (rev 330) +++ trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp 2011-07-06 19:35:38 UTC (rev 331) @@ -69,6 +69,12 @@ this, SLOT(checkPropertyValueToEndTheWait())); } +void WaitForProperty::setPropertyToWaitFor(QObject* object, + const QString& propertyName, + const QVariant& value) { + setProperty(object, propertyName, value); +} + bool WaitForProperty::conditionMet() const { if (!mObject) { return false; Modified: trunk/ktutorial/ktutorial-library/src/WaitForProperty.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/WaitForProperty.h 2011-06-21 15:24:13 UTC (rev 330) +++ trunk/ktutorial/ktutorial-library/src/WaitForProperty.h 2011-07-06 19:35:38 UTC (rev 331) @@ -100,10 +100,28 @@ * @param propertyName The name of the property. * @param value The value of the property to wait for. */ - Q_INVOKABLE void setProperty(QObject* sender, const QString& propertyName, + Q_INVOKABLE void setProperty(QObject* object, const QString& propertyName, const QVariant& value); /** + * setProperty(QObject*, const QString&, const QVariant&) version to be used + * in Ruby scripts. + * Ruby backend calls setProperty(const char*, const QVariant&) method + * instead of the aforementioned one. This method just offers a non + * overloaded name and delegates the call in the method from + * WaitForProperty. + * + * @param object The object that contains the property. + * @param propertyName The name of the property. + * @param value The value of the property to wait for. + * @todo Remove when Ruby backend gets proper support for overloaded + * methods. + */ + Q_INVOKABLE void setPropertyToWaitFor(QObject* object, + const QString& propertyName, + const QVariant& value); + + /** * Returns true if the property has the expected value, false otherwise. * Note that it will return true even if the property got the expected value * when this WaitForProperty was inactive. That is, as long as the property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |