Table of Contents
This little guide will show you how KTutorial can be used in your own application. First, the general changes to enable KTutorial will be presented, and then it will be shown how to develop a tutorial using the classes provided by the library.
This guide is based on KTutorial test app and the example tutorials in it. The test app is just a basic text editor: it has all the KDE standard menu and toolbars plus a text area and a "Clean" action. For further information, refer to the code of the test application itself.
KTutorial uses XMLGUI technology to merge its menu entry with those of the application using it. So your application must also use XMLGUI. If you don't know if you are using XMLGUI, you are probably doing it, as it is the rule more than the exception in KDE.
If you are using XMLGUI, you will have a applicationnameui.rc file, where
applicationname
is, of course, the name of your application.
This file, combined with a general KDE one, sets the menus and toolbars of your application. In order to show KTutorial in the right place, a little change must be done. Why it can't be done automatically by KTutorial depends on XMLGUI internals and is out of the scope of this document.
KTutorial uses a menu item to show the tutorial manager dialog. This item must appear under menu, but not anywhere. To keep a consistent menu order between applications, the item must be the first item in the area for application specific menu items.
To do this, just define the group ktutorial as the first element in Help menu, like shown in the next example.
Example 3.1. applicationnameui.rc changes
<gui name="applicationname"> ... <MenuBar> ... <Menu name="help" > <DefineGroup name="ktutorial" /> ... </Menu> </MenuBar> </gui>
Now, for the changes in the code of the application. The changes needed are extremely easy to do, although they must be done in the right point in the sequence of initialization of the application.
As you are using XMLGUI, you must have a call to inherited method setupGUI somewhere in the creation of your application main class (the one derived from KXmlGuiWindow).
You must call the method setup in KTutorial class before calling setupGUI.
Once KTutorial is set up, tutorials can be registered with it, and you are done.
Example 3.2. Code changes to setup KTutorial
...
#include <KTutorial.h>
...
ApplicationMainWindow::ApplicationMainWindow(QWidget* parent):
KXmlGuiWindow(parent) {
...
KTutorial::self()->setup(this);
KTutorial::self()->registerTutorial(new TutorialDerivedClass());
...
setupGUI();
}