[Ktutorial-commits] SF.net SVN: ktutorial:[136] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-09 19:45:51
|
Revision: 136 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=136&view=rev Author: danxuliu Date: 2010-03-09 19:45:44 +0000 (Tue, 09 Mar 2010) Log Message: ----------- Add LicenseWidget to set the license of the tutorial. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.h trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.ui trunk/ktutorial/ktutorial-editor/tests/unit/view/LicenseWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 19:16:53 UTC (rev 135) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 19:45:44 UTC (rev 136) @@ -28,6 +28,7 @@ #include "Step.h" #include "Tutorial.h" #include "view/EditionDialog.h" +#include "view/LicenseWidget.h" #include "view/StepCustomCodeWidget.h" #include "view/StepDataWidget.h" #include "view/TreeModel.h" @@ -80,6 +81,13 @@ this, SLOT(setTutorialInformation())); action = new KAction(this); + action->setText(i18nc("@action", "Set license...")); + action->setStatusTip(i18nc("@info:status", "Set the license text of the " +"tutorial.")); + actionCollection()->addAction("setTutorialLicense", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialLicense())); + + action = new KAction(this); action->setText(i18nc("@action", "Set setup code...")); action->setStatusTip(i18nc("@info:status", "Set the custom code to be " "executed when the tutorial starts.")); @@ -163,6 +171,10 @@ showEditionDialog(new TutorialInformationWidget(mTutorial)); } +void KTutorialEditor::setTutorialLicense() { + showEditionDialog(new LicenseWidget(mTutorial)); +} + void KTutorialEditor::setTutorialSetup() { showEditionDialog(new TutorialCustomCodeWidget(mTutorial, TutorialCustomCodeWidget::Setup)); Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 19:16:53 UTC (rev 135) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 19:45:44 UTC (rev 136) @@ -91,6 +91,11 @@ void setTutorialInformation(); /** + * Shows a LicenseWidget for the tutorial. + */ + void setTutorialLicense(); + + /** * Shows a TutorialCustomCodeWidget for the setup code of the tutorial. */ void setTutorialSetup(); Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 19:16:53 UTC (rev 135) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 19:45:44 UTC (rev 136) @@ -6,6 +6,7 @@ <Menu name="editTutorials"> <Text context="@item:inmenu">Tutorial</Text> <Action name="setTutorialInformation"/> + <Action name="setTutorialLicense"/> <Action name="setTutorialSetup"/> <Action name="setTutorialTearDown"/> </Menu> Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 19:16:53 UTC (rev 135) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 19:45:44 UTC (rev 136) @@ -3,6 +3,7 @@ set(ktutorial_editor_view_SRCS EditionDialog.cpp EditionWidget.cpp + LicenseWidget.cpp StepCustomCodeWidget.cpp StepDataWidget.cpp StepTreeItem.cpp @@ -18,6 +19,7 @@ kde4_add_ui_files(ktutorial_editor_view_SRCS CustomCodeWidget.ui + LicenseWidget.ui StepDataWidget.ui TutorialInformationWidget.ui ) Added: trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.cpp 2010-03-09 19:45:44 UTC (rev 136) @@ -0,0 +1,44 @@ +/*************************************************************************** + * 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 "LicenseWidget.h" + +#include "ui_LicenseWidget.h" +#include "../Tutorial.h" + +//public: + +LicenseWidget::LicenseWidget(Tutorial* tutorial, QWidget* parent): + EditionWidget(parent), + mTutorial(tutorial) { + ui = new Ui::LicenseWidget(); + ui->setupUi(this); + + ui->licenseTextEdit->setText(tutorial->licenseText()); +} + +LicenseWidget::~LicenseWidget() { + delete ui; +} + +void LicenseWidget::saveChanges() { + QString licenseText = ui->licenseTextEdit->toPlainText(); + if (mTutorial->licenseText() != licenseText) { + mTutorial->setLicenseText(licenseText); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.h 2010-03-09 19:45:44 UTC (rev 136) @@ -0,0 +1,69 @@ +/*************************************************************************** + * 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 LICENSEWIDGET_H +#define LICENSEWIDGET_H + +#include "EditionWidget.h" + +class Tutorial; + +namespace Ui { +class LicenseWidget; +} + +/** + * Edition widget for the license of a tutorial. + */ +class LicenseWidget: public EditionWidget { +Q_OBJECT +public: + + /** + * Creates a new LicenseWidget for the given Tutorial. + * + * @param tutorial The tutorial to set its license. + * @param parent The parent QWidget. + */ + explicit LicenseWidget(Tutorial* tutorial, QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~LicenseWidget(); + + /** + * Saves the license in the tutorial. + */ + virtual void saveChanges(); + +private: + + /** + * The tutorial to set its license. + */ + Tutorial* mTutorial; + + /** + * The Ui Designer generated class. + */ + Ui::LicenseWidget* ui; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/LicenseWidget.ui 2010-03-09 19:45:44 UTC (rev 136) @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>LicenseWidget</class> + <widget class="QWidget" name="LicenseWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title">Set tutorial license</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Set the license of the tutorial.</para> +<para>The license is copied, commented, to the top of the exported tutorial file. That is, you don't have to worry about how comments are written in the programming language the tutorial will be exported to. Just set the pure text of the license, and the editor will take care of adding the necessary characters in each line to mark them as comments instead of source code.</para></string> + </property> + <layout class="QVBoxLayout" name="LicenseWidgetLayout"> + <item> + <widget class="QGroupBox" name="licenseGroupBox"> + <property name="title"> + <string comment="@title">License text</string> + </property> + <layout class="QVBoxLayout" name="customCodeGroupBoxLayout"> + <item> + <widget class="KTextEdit" name="licenseTextEdit"/> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KTextEdit</class> + <extends>QTextEdit</extends> + <header>ktextedit.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 19:16:53 UTC (rev 135) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 19:45:44 UTC (rev 136) @@ -16,7 +16,7 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(EditionDialog StepCustomCodeWidget StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialCustomCodeWidget TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) +unit_tests(EditionDialog LicenseWidget StepCustomCodeWidget StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialCustomCodeWidget TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -24,4 +24,4 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(EditionDialog StepCustomCodeWidget StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialCustomCodeWidget TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) +mem_tests(EditionDialog LicenseWidget StepCustomCodeWidget StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialCustomCodeWidget TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/LicenseWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/LicenseWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/LicenseWidgetTest.cpp 2010-03-09 19:45:44 UTC (rev 136) @@ -0,0 +1,74 @@ +/*************************************************************************** + * 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 <QtTest> + +#include "LicenseWidget.h" + +#include <KLineEdit> +#include <KTextEdit> + +#include "../Tutorial.h" + +class LicenseWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSaveChanges(); + +private: + + KTextEdit* licenseTextEdit(LicenseWidget* widget) const; + +}; + +void LicenseWidgetTest::testConstructor() { + Tutorial tutorial; + tutorial.setLicenseText("The license"); + + QWidget parent; + LicenseWidget* widget = new LicenseWidget(&tutorial, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QCOMPARE(licenseTextEdit(widget)->toPlainText(), QString("The license")); +} + +void LicenseWidgetTest::testSaveChanges() { + Tutorial tutorial; + tutorial.setLicenseText("The license"); + + LicenseWidget widget(&tutorial); + licenseTextEdit(&widget)->setText("The new license"); + + widget.saveChanges(); + + QCOMPARE(tutorial.licenseText(), QString("The new license")); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +KTextEdit* LicenseWidgetTest::licenseTextEdit(LicenseWidget* widget) const { + return widget->findChild<KTextEdit*>("licenseTextEdit"); +} + +QTEST_MAIN(LicenseWidgetTest) + +#include "LicenseWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/LicenseWidgetTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |