[Ktutorial-commits] SF.net SVN: ktutorial:[131] trunk/ktutorial/ktutorial-editor/src
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-09 08:05:31
|
Revision: 131 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=131&view=rev Author: danxuliu Date: 2010-03-09 08:05:23 +0000 (Tue, 09 Mar 2010) Log Message: ----------- -Add actions to set the tutorial information, the step data, add steps and remove steps. -Enable or disable some actions based on the selected step. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 05:25:28 UTC (rev 130) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 08:05:23 UTC (rev 131) @@ -23,24 +23,129 @@ #include <KAction> #include <KActionCollection> #include <KApplication> +#include <KLocalizedString> +#include "Step.h" +#include "Tutorial.h" +#include "view/EditionDialog.h" +#include "view/StepDataWidget.h" +#include "view/TreeModel.h" +#include "view/TutorialInformationWidget.h" +#include "view/TutorialTreeItem.h" +#include "view/TutorialTreeSelectionManager.h" + //public: KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0) { - QTreeView* treeView = new QTreeView(); - treeView->setObjectName("centralTreeView"); - treeView->setHeaderHidden(true); + mTreeView = new QTreeView(); + mTreeView->setObjectName("centralTreeView"); + setCentralWidget(mTreeView); - setCentralWidget(treeView); + setupTutorialToBeEdited(); setupActions(); - //Don't use a status bar (which is setupGUI default behavior) - setupGUI(ToolBar | Keys | Save | Create); + setupGUI(); } //private: +void KTutorialEditor::setupTutorialToBeEdited() { + mTutorial = new Tutorial(this); + + TutorialTreeItem* tutorialTreeItem = new TutorialTreeItem(mTutorial); + TreeModel* model = new TreeModel(tutorialTreeItem, mTreeView); + + QAbstractItemModel* oldModel = mTreeView->model(); + mTreeView->setModel(model); + delete oldModel; + + TutorialTreeSelectionManager* selectionManager = + new TutorialTreeSelectionManager(mTreeView->selectionModel(), this); + connect(selectionManager, SIGNAL(stepSelected(Step*)), + this, SLOT(selectStep(Step*))); +} + void KTutorialEditor::setupActions() { KStandardAction::quit(kapp, SLOT(quit()), actionCollection()); + + KAction* action = new KAction(this); + action->setText(i18nc("@action", "Set information...")); + action->setStatusTip(i18nc("@info:status", "Set the name and description " +"of the tutorial.")); + actionCollection()->addAction("setTutorialInformation", action); + connect(action, SIGNAL(triggered(bool)), + this, SLOT(setTutorialInformation())); + + action = new KAction(this); + action->setText(i18nc("@action", "Add step...")); + action->setStatusTip(i18nc("@info:status", "Add a new step to the " +"tutorial.")); + actionCollection()->addAction("addStep", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(addStep())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set data...")); + action->setStatusTip(i18nc("@info:status", "Set the name and text of the " +"currently selected step.")); + action->setEnabled(false); + actionCollection()->addAction("setStepData", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepData())); + + action = new KAction(this); + action->setText(i18nc("@action", "Remove step")); + action->setStatusTip(i18nc("@info:status", "Removes the currently selected " +"step from the tutorial.")); + action->setEnabled(false); + actionCollection()->addAction("removeStep", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(removeStep())); } + +void KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { + EditionDialog* dialog = new EditionDialog(editionWidget, this); + dialog->setObjectName("editionDialog"); + dialog->exec(); + dialog->deleteLater(); +} + +//private slots: + +void KTutorialEditor::selectStep(Step* step) { + mCurrentStep = step; + + if (mCurrentStep) { + actionCollection()->action("setStepData")->setEnabled(true); + actionCollection()->action("removeStep")->setEnabled(true); + } else { + actionCollection()->action("setStepData")->setEnabled(false); + actionCollection()->action("removeStep")->setEnabled(false); + } +} + +void KTutorialEditor::setTutorialInformation() { + showEditionDialog(new TutorialInformationWidget(mTutorial)); +} + +void KTutorialEditor::addStep() { + Step* step = new Step(); + mTutorial->addStep(step); + + showEditionDialog(new StepDataWidget(step)); +} + +void KTutorialEditor::setStepData() { + Q_ASSERT(mCurrentStep); + + showEditionDialog(new StepDataWidget(mCurrentStep)); +} + +void KTutorialEditor::removeStep() { + Q_ASSERT(mCurrentStep); + + //When the step is removed, mCurrentStep is changed because the selected + //item in the tree view changes. As mCurrentStep is one of the valid steps + //in the tutorial, deleting it leads to a crash the next time it is used. + Step* stepToRemove = mCurrentStep; + mTutorial->removeStep(stepToRemove); + stepToRemove->deleteLater(); +} Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 05:25:28 UTC (rev 130) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 08:05:23 UTC (rev 131) @@ -21,6 +21,11 @@ #include <KXmlGuiWindow> +class EditionWidget; +class QTreeView; +class Step; +class Tutorial; + /** * KTutorial editor main window. * It wires up all the components in the application. @@ -37,10 +42,69 @@ private: /** + * The main tree view that shows the tutorial. + */ + QTreeView* mTreeView; + + /** + * The tutorial being edited. + */ + Tutorial* mTutorial; + + /** + * The currently selected step. + */ + Step* mCurrentStep; + + /** + * Sets up the tutorial to be edited. + * It creates a new tutorial, prepares the tree view to represent it and + * handles the selection of items. + */ + void setupTutorialToBeEdited(); + + /** * Sets up all the actions used in the application. */ void setupActions(); + /** + * Shows an EditionDialog for the given EditionWidget. + * + * @param editionWidget The EditionWidget to wrap. + */ + void showEditionDialog(EditionWidget* editionWidget); + +private Q_SLOTS: + + /** + * Sets the current step and enables or disables the actions that depend on + * a step as needed. + * + * @param step The step to select, or null to deselect the current one. + */ + void selectStep(Step* step); + + /** + * Shows a TutorialInformationWidget for the tutorial. + */ + void setTutorialInformation(); + + /** + * Adds a new step to the tutorial and shows a StepDataWidget for it. + */ + void addStep(); + + /** + * Shows a StepDataWidget for the current step. + */ + void setStepData(); + + /** + * Removes the current step from the tutorial. + */ + void removeStep(); + }; #endif Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 05:25:28 UTC (rev 130) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 08:05:23 UTC (rev 131) @@ -1,4 +1,18 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <gui name="ktutorial-editor" version="1"> + <MenuBar> + <Menu name="edit"> + <Menu name="editTutorials"> + <Text>Tutorial</Text> + <Action name="setTutorialInformation"/> + </Menu> + <Menu name="editSteps"> + <Text>Step</Text> + <Action name="addStep"/> + <Action name="setStepData"/> + <Action name="removeStep"/> + </Menu> + </Menu> + </MenuBar> </gui> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |