Remove this line
[kdeaccessibility.git] / ksayit / src / doctreeviewimpl.h
blob62a30265da8170e6126c1fa14520f2b192b9901c
1 //
2 // C++ Interface: doctreeviewimpl
3 //
4 // Description:
5 //
6 //
7 // Author: Robert Vogl <voglrobe@lapislazuli>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
13 #ifndef DOCTREEVIEWIMPL_H
14 #define DOCTREEVIEWIMPL_H
16 // Qt includes
17 #include <QtXml/qdom.h>
18 #include <QtGui/QContextMenuEvent>
19 #include <QtCore/QTextStream>
21 // KDE includes
22 #include <kurl.h>
23 #include <k3listview.h>
24 #include <kmenu.h>
26 // App specific includes
27 #include "Types.h"
28 #include "DocTreeView.h"
30 // forward declarations
31 class ParaSaxParser;
32 class ContextMenuHandler;
34 /**
35 This class implements the TreeView object.\n
36 It takes a XML/DocBook file, parses it and builds up a hierarchical
37 \p QListView structure corresponding to the structure of the document.
38 The objective of this class is to maintain the document and provide
39 all required methods to access or manipulate its content.
40 @author Robert Vogl
42 class DocTreeViewImpl : public DocTreeView
44 public:
45 DocTreeViewImpl(QWidget* parent=0, const char* name=0, Qt::WFlags fl=0);
47 ~DocTreeViewImpl();
49 /**
50 * Tries to open and parse the given file. If the file is not identified as a
51 * valid XML/DocBook file, it will be packed as a \p CDATA block into a \p para element
52 * of a simple DocBook'ish XML file.
53 * \param url The URL of the file.
55 void openFile(const KUrl &url);
57 /**
58 * Saves the document to a XML file.
60 void saveFile();
62 /**
63 * Saves the document to a XML file and allows the user to define a name.
65 void saveFileAs();
67 /**
68 * Cleans up the interal document data structures.
70 void clear();
72 /**
73 * Creates an empty XML document that conatins one editable DocBook \p Paragraph.
74 * Usually called after clean() and initial startup.
76 void createEmptyDocument();
78 /**
79 * Stores the given text in the current node.
80 * \param text The new content of the current DOM node.
82 void setNodeContent(QString &text);
84 /**
85 * Starting from the current selected node it travels recursively
86 * through all childs and collects the content of all corresponding
87 * DOM nodes. After sending the text to the TTS system the speech synthesis
88 * process will be started.
90 void sayActiveNodeAndChilds();
92 /**
93 * Signals a stop-talking-request from the user.
95 void stop();
97 /**
98 * Controls the Edit Mode.
99 * \param mode If true, Edit Mode ON,\n if false, Edit Mode OFF.
101 void setEditMode(bool mode);
104 * Sets the item active designated by the ID.
105 * \param ID The ID (column 3) of the TreeView item.
106 * \returns <tt>QString()</tt> if the operation was successful,\n
107 * an error message, if the item was not found.
109 QString selectItemByID(const QString &ID, const QString title);
112 * Enables/disables the contextmenus
114 void enableContextMenus( bool enabled );
116 public slots:
117 void slotRenameItem(); // reimplemented from base classes
118 void slotDeleteItem();
119 void slotNewBookInfo();
120 void slotNewChapter();
121 void slotNewKeywordSet();
122 void slotNewKeyword();
123 void slotNewAbstract();
124 void slotNewAuthorGroup();
125 void slotNewAuthor();
126 void slotNewDate();
127 void slotNewReleaseInfo();
128 void slotNewTitle();
129 void slotNewParagraph();
130 void slotNewSection_1();
131 void slotNewSection_2();
132 void slotNewSection_3();
133 void slotNewSection_4();
134 void slotNewSection_5();
136 protected slots:
138 * Reimplemented from base class.
139 * Called whenever the active node has been changed.\n
140 * Makes the former selected item persistent (maybe it has
141 * been changed).\n
142 * Displays the content of the selected Node either in RTF or
143 * plain text format (depending on the Edit Mode flag, childs
144 * present or not).\n
145 * Informs the BookmarkManager about the new item.
147 * \param item The new active item of the TreeView.
149 void slotItemClicked(Q3ListViewItem *item);
152 * Reimplemented from QWidget class.
154 void contextMenuEvent(QContextMenuEvent *e);
156 private: // Methods
157 // a selection of DocBook elements
158 void parseBook(const QDomElement &element, ListViewInterface *item);
159 void parseBookInfo(const QDomElement &element, ListViewInterface *item);
160 void parseAuthorGroup(const QDomElement &element, ListViewInterface *item);
161 void parseAuthor(const QDomElement &element, ListViewInterface *item);
162 void parseKeywordSet(const QDomElement &element, ListViewInterface *item);
163 void parseAbstract(const QDomElement &element, ListViewInterface *item);
164 void parseChapter(const QDomElement &element, ListViewInterface *item);
165 void parseSect1(const QDomElement &element, ListViewInterface *item);
166 void parseSect2(const QDomElement &element, ListViewInterface *item);
167 void parseSect3(const QDomElement &element, ListViewInterface *item);
168 void parseSect4(const QDomElement &element, ListViewInterface *item);
169 void parseSect5(const QDomElement &element, ListViewInterface *item);
170 void parsePara(const QDomElement &element, ListViewInterface *item);
172 // helpers
173 void recursiveTextCollector(ListViewInterface* item, QTextStream &msg, bool header=true);
174 void recursiveSayNodes(ListViewInterface* item);
175 void recursiveBuildItemIdentifier(ListViewInterface* item, QTextStream &idstring);
176 void makeCurrentNodePersistent();
177 int newIndexFirstChild();
178 int newIndexLastChild();
179 void findHighestIndex(ListViewInterface* item, int &index);
180 QString getItemTitle( ListViewInterface *item);
183 private: // Attributes
184 ContextMenuHandler *m_contextmenuhandler;
185 KMenu *m_contextmenu;
186 QDomDocument m_domTree;
187 ListViewInterface *m_rootItem;
188 ListViewInterface *m_currentItem;
189 QString m_changedContent;
190 int m_idCounter;
191 bool m_stopped;
192 KUrl m_url;
193 ParaSaxParser *m_parasaxparser;
194 bool m_editMode;
201 #endif