Fixed the notice about the konsole invocation.
[kdbg.git] / kdbg / ktreeview.h
blob6663bee499e52f6d7cd1edaed40bf06826284e50
1 /*
2 * $Id$
3 *
4 * KTreeView class interface
5 *
6 * Copyright (C) 1997 Johannes Sixt
7 *
8 * based on KTreeList, which is
9 * Copyright (C) 1996 Keith Brown and KtSoft
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details. You should have received a copy
20 * of the GNU General Public License along with this program; if not, write
21 * to the Free Software Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139,
22 * USA.
25 #ifndef KDE_KTREE_VIEW_H
26 #define KDE_KTREE_VIEW_H
28 #include <qpixmap.h> /* used in items */
29 #include <qptrstack.h> /* used to specify tree paths */
30 #include <qstring.h> /* used in items */
31 #include "tableview.h" /* base class for widget */
33 // use stack of strings to represent path information
34 typedef QStack<QString> KPath;
36 class KTreeView; /* forward declaration */
38 /** Items for the KTreeView widget */
39 class KTreeViewItem : public Qt
41 friend class KTreeView;
42 public:
43 /**
44 * Item constructor. While text defaults to a null string, and the
45 * item can be constructed this way, the text has to be non-null when
46 * the item is added to the tree, or it will not be inserted.
48 * The constructor sets the delete-children flag to false. This flag
49 * tells the item whether it shall delete the child items when it is
50 * itself deleted. By default the creator of the item is responsible to
51 * also delete the child items. (However, the versions of @ref
52 * #appendChildItem and @ref #insertChildItem that do not take a
53 * KTreeViewItem set the delete-children flag to true.)
55 * @param text specifies the new item's text
57 KTreeViewItem(const QString& text = QString()); // text can not be null when added to the list!
58 /**
59 * This overloaded constructor allows to specify a pixmap for the new
60 * item.
62 * @param text specifies the item's text
63 * @param pixmap specifies the item's pixmap
65 KTreeViewItem(const QString& text, const QPixmap& pixmap);
67 /**
68 * Destructor. It destroys its children if this item has been marked
69 * with setDeleteChildren(true).
71 virtual ~KTreeViewItem();
73 /**
74 * Appends a new (direct) child item at the end. It does not update
75 * administrative data in newChild except for its parent (which is this
76 * item) and owner.
78 virtual void appendChild(KTreeViewItem* newChild);
80 /**
81 * Returns a pointer to the child item at the given index in this
82 * item's sub tree, or 0 if not found.
84 * @param index specifies the index of the direct child to return
85 * @return the direct child at the specified index
86 */
87 KTreeViewItem* childAt(int index) const;
89 /**
90 * Returns the number of child items in this item's sub tree.
92 uint childCount() const;
94 /**
95 * Returns the index in this items sub tree of the given item or -1 if
96 * the specified item is not a direct child of this item.
98 * @param child specifies the child to look up; must not be 0
99 * @returns the index of the specified direct child
101 int childIndex(KTreeViewItem* child) const;
104 * Determines whether the specified point is inside the expand button.
106 bool expandButtonClicked(const QPoint& coord) const;
109 * Returns a pointer to the first child item in this item's sub tree, or
110 * 0 if none.
112 KTreeViewItem* getChild() const;
115 * Returns a pointer to the parent of this item, or 0 if none.
117 KTreeViewItem* getParent() const;
120 * Returns a reference to this item's pixmap. If there is no pixmap
121 * associated with this item, it will return a reference to a valid,
122 * null QPixmap.
124 const QPixmap& getPixmap() const;
127 * Returns a pointer to the next sibling item in the same branch below this
128 * one, or 0 if this item has no siblings below it.
130 KTreeViewItem* getSibling() const;
133 * Returns this item's text.
135 const QString& getText() const;
138 * Indicates whether this item has any children.
140 bool hasChild() const;
143 * Indicates whether this item has a parent.
145 bool hasParent() const;
148 * Indicates whether this item has a sibling item, that is, an item
149 * that would be displayed below it at the same level as this item.
151 bool hasSibling() const;
154 * Inserts the a new (direct) child in this item before the child at
155 * the specified index (first child is index 0). If there is no child
156 * at the specified index, the item is appended. It does not update
157 * administrative data in newChild except for its parent (which is this
158 * item) and owner.
160 * @param index specifies the index of a direct child of this item
161 * @param newChild specifies the new item to insert
163 virtual void insertChild(int index, KTreeViewItem* newChild);
166 * Indicates whether the item is expanded, that is, whether the child
167 * items (if any) would be visible if this item were visible.
169 * Note: If this function returns true, it does not necessarily indicate
170 * that this item is visible or that this item has any children.
172 bool isExpanded() const;
175 * Returns true if the item is visible. An item is visible if @ref
176 * #isExpanded() returns true for all its ancestors.
178 * Note: If this function returns true, it does not necessarily indicate
179 * that the widget is visible.
181 bool isVisible() const;
184 * Removes the specified (direct) child from this item and returns
185 * true. If it is not a direct child of this item, nothing happens, and
186 * false is returned. This function does not update the owning
187 * KTreeView.
189 virtual bool removeChild(KTreeViewItem* child);
192 * Sets the delayed-expanding flag. If this flag is true, the signal
193 * @ref #expanding is emitted when the item is about to be expanded.
194 * The expand button is always painted for this item, even if it
195 * doesn't have children.
197 void setDelayedExpanding(bool flag);
200 * Tells the item whether it should delete its children when it is
201 * deleted. The default is false, which means that the child items must
202 * be deleted explicitly.
204 void setDeleteChildren(bool flag);
207 * Tells the item whether it should draw the expand button. The default
208 * is true. This function does not update the owning tree widget.
210 virtual void setDrawExpandButton(bool doit);
213 * Tells the item whether it should paint the text. The default is
214 * true. This function does not update the owning tree widget.
216 virtual void setDrawText(bool doit);
219 * Tells the item whether it should draw the tree lines. The default is
220 * true. This function does not update the owning tree widget.
222 virtual void setDrawTree(bool doit);
225 * Tells whether the item is expanded (i.e. whether its children are
226 * visible). The default is false. This function does not update the
227 * owning tree widget.
229 virtual void setExpanded(bool is);
232 * Sets the item pixmap to the given pixmap. It does not redraw the
233 * item or update the owning KTreeView.
235 virtual void setPixmap(const QPixmap& pm);
238 * Sets the item text. This function does not redraw the item or update
239 * the owning KTreeView.
241 virtual void setText(const QString& t);
243 protected:
245 * Returns the bounding rectangle of the item.
247 virtual QRect boundingRect(int indent) const;
250 * Returns the height of the item. The default implementation uses font
251 * metrics of the owning KTreeView widget.
253 virtual int height() const;
256 * Returns the height of the item depending on the passed-in font
257 * metrics.
259 virtual int height(const QFontMetrics& fm) const;
262 * The item is given a chance to process key events before the owning
263 * KTreeView processes the event.
265 * @param ev specifies the key event; use ev->type() to find out whether
266 * this is a key down or up event (see @ref #QEvent).
267 * @return true if the event has been processed, false if it has not
268 * been processed. The default implementation just returns false to
269 * indicate that the event has not been processed.
271 virtual bool keyEvent(QKeyEvent* ev);
274 * The item is given a chance to process mouse events before the owning
275 * KTreeView processes the event.
277 * @param ev specifies the mouse event; use ev->type() to find out whether
278 * this is a mouse press, release, double click, or move event (see
279 * @ref #QEvent).
280 * @param itemCoord specifies the mouse even coordinates relative to this
281 * item (the coordinates in ev are the original coordinates).
282 * @return true if the event has been processed, false if it has not
283 * been processed. The default implementation just returns false to
284 * indicate that the event has not been processed.
286 virtual bool mouseEvent(QMouseEvent* ev, const QPoint& itemCoord);
289 * Paints the item: pixmap, text, expand button, parent branches
291 virtual void paint(QPainter* p, int indent,
292 const QColorGroup& cg, bool highlighted) const;
295 * paints the expand button
297 virtual void paintExpandButton(QPainter* p, int indent, int cellHeight,
298 const QColorGroup& cg) const;
301 * paints the highlighted text
303 virtual void paintHighlight(QPainter* p, int indent,
304 const QColorGroup& cg, bool hasFocus) const;
307 * paints the item's text
309 virtual void paintText(QPainter* p, int indent, int cellHeight,
310 const QColorGroup& cg, bool highlighted) const;
313 * paints the item's tree part.
315 virtual void paintTree(QPainter* p, int indent, int cellHeight,
316 const QColorGroup& cg) const;
319 * Internal function that updates the owner of this item and its
320 * children and siblings (the latter only if requested).
322 void setOwner(KTreeView* newOwner, bool includeSiblings = false);
325 * Internal function that counts the number of child items.
327 void synchNumChildren();
330 * Returns the bounding rectangle of the text.
332 virtual QRect textBoundingRect(int indent) const;
335 * Returns the width of the item taking into account the specified
336 * indentation. The default implementation uses font metrics of the
337 * owning KTreeView widget.
339 virtual int width(int indent) const;
342 * Returns the width of the item depending on the passed-in font
343 * metrics and taking into account the specified indentation.
345 virtual int width(int indent, const QFontMetrics& fm) const;
347 protected:
348 /** The KTreeView that this item belongs to */
349 KTreeView* owner;
350 int numChildren;
351 bool doExpandButton;
352 bool expanded;
353 bool delayedExpanding;
354 bool doTree;
355 bool doText;
356 mutable QRect expandButton; /* is set in paint() */
357 KTreeViewItem* child;
358 KTreeViewItem* parent;
359 KTreeViewItem* sibling;
360 QPixmap pixmap;
361 QString text;
362 bool deleteChildren;
366 * KTreeView is a class that provides a way to display hierarchical data in
367 * a single-inheritance tree, similar to tree controls in Microsoft Windows
368 * and other GUIs. It is most suitable for directory trees or outlines, but
369 * I'm sure other uses will come to mind. It was designed mostly with the
370 * above two functions in mind, but I have tried to make it as flexible as
371 * I can to make it easy to adapt to other uses.
373 * Please read the source code if you have time. I have tried to comment it
374 * adequately and make the source understandable.
376 * The class features the following:
378 * - Displays both text and an optional pixmap supplied by the programmer.
379 * A support class, KTreeViewItem, can be inherited and modified to draw
380 * items as needed by the programmer.
382 * - The list items can be returned by index or logical path and the tree
383 * navigated by parent, child or sibling references contained in them.
384 * Also, item information such as text, pixmap, branch level can be
385 * obtained.
387 * - Items can be inserted, changed and removed either by index in the
388 * visible structure, or by logical paths through the tree hierarchy.
390 * - The logical path through the tree for any item can be obtained with
391 * the index of the item.
393 * - Tree structure display and expanding/collapsing of sub-trees is
394 * handled with no intervention from the programmer.
396 * - entire tree can be expanded or collapsed to a specified sub-level
397 * (handy for outline views)
399 * @short A collapsible treelist widget
400 * @author Johannes Sixt <Johannes.Sixt@telecom.at>, Keith Brown
402 class KTreeView : public TableView
404 friend class KTreeViewItem;
405 Q_OBJECT
406 public:
408 * Widget contructor. All parameters are passed on to base TableView,
409 * and are not used directly.
411 KTreeView(QWidget* parent = 0, const char* name = 0, WFlags f = 0);
414 * Desctructor. Deletes all items from the topmost level that have been
415 * marked with setDeleteChildren(true).
417 virtual ~KTreeView();
420 * Appends a new child item to the item at the specified row. If that
421 * item already has children, the new item is appended below these
422 * children. A KTreeViewItem is created for which the delete-children
423 * flag is set to true.
425 * @param text specifies text for the new item; must not be 0
426 * @param pixmap specifies a pixmap for the new item
427 * @param index specifies the item of which the new item will be a child
429 void appendChildItem(const char* text, const QPixmap& pixmap,
430 int index);
433 * This overloaded function appends a new item to an item, which is
434 * specified by a path.
436 * @param text specifies text for the new item; must not be 0
437 * @param pixmap specifies a pixmap for the new item
438 * @param path specifies the item of which the new item will be a child
439 * @see #appendChildItem
441 void appendChildItem(const char* text, const QPixmap& pixmap,
442 const KPath& path);
445 * Appends the specified item as a child of the item that is at the
446 * specified row. If that item already has children, the new item is
447 * appended below these children.
449 * @param newItem specifies the new item
450 * @param index specifies the item of which the new item will be a child
451 * @see #appendChildItem
453 void appendChildItem(KTreeViewItem* newItem, int index);
456 * This overloaded function appends a new item to an item, which is
457 * specified by a path.
459 * @param newItem specifies the new item
460 * @param path specifies the item of which the new item will be a child
461 * @see #appendChildItem
463 void appendChildItem(KTreeViewItem* newItem, const KPath& path);
466 * Computes coordinates relative to the specified row from the given
467 * coordinates. If the row is invalid, the input coordinates are
468 * returned unchanged.
470 * @param widget specifies widget coordinates (e.g. from a mouse event)
471 * @return coordinates relative to the specified cell
473 virtual QPoint cellCoords(int row, const QPoint& widgetCoord);
476 Changes the text and/or pixmap of the given item at the specified
477 index to the given values and updates the display if auto update
478 enabled. If changing only the text or pixmap, set the other parameter
479 to 0.
481 void changeItem(const char *newText,
482 const QPixmap *newPixmap,
483 int index);
486 Same as above function, except item to change is specified by a path
487 through the tree.
489 void changeItem(const char *newText,
490 const QPixmap *newPixmap,
491 const KPath& thePath);
494 Removes all items from the tree.
497 void clear();
500 Returns the total number of items in the tree, whether visible
501 (expanded sub-trees) or not (collapsed).
503 uint count();
506 Returns the index of the current (highlighted) item. If no current
507 item, returns -1.
509 int currentItem() const;
512 * Collapses the sub-tree at the specified row index. If the index is
513 * out of range, or the item is already collpased, nothing happens.
515 * @param index specifies the row index
516 * @param emitSignal specifies whether the signal @ref #collapsed
517 * should be emitted
519 void collapseItem(int index, bool emitSignal);
522 * Expands the sub-tree at the specified row index. If the index is
523 * out of range, or the item is already expanded, nothing happens.
525 * @param index specifies the row index
526 * @param emitSignal specifies whether the signal @ref #collapsed
527 * should be emitted
529 void expandItem(int index, bool emitSignal);
532 Returns the depth to which all parent items are automatically
533 expanded.
535 int expandLevel() const;
538 * The type of member functions that is called by @ref #forEveryItem and
539 * @ref #forEveryVisibleItem.
541 typedef bool (*KForEveryFunc)(KTreeViewItem*, void*);
544 * Iterates every item in the tree, visible or not, and applies the
545 * function func with a pointer to each item and user data supplied as
546 * parameters. The children of the specified root item are visited
547 * (root itself is not visited!). If root is 0 all items in the tree
548 * are visited. KForEveryFunc is defined as:
550 * typedef bool (KTreeView::*KForEveryFunc)(KTreeViewItem*, void*);
552 * That is, a member function that returns bool and takes a pointer to
553 * a KTreeViewItem and pointer to void as parameters. The traversal
554 * ends earlier if the supplied function returns bool. In this case the
555 * return value is also true.
557 * @param func the member function to call for every visited item
558 * @param user extra data that is passed to func
559 * @param root the root item of the subtree to scan; this item itself
560 * is not scanned
561 * @see #forEveryVisibleItem
563 bool forEveryItem(KForEveryFunc func, void* user,
564 KTreeViewItem* root = 0);
567 * This function is like @ref #forEveryItem, but only iterates visible
568 * items, in order. If the specified root item is invisible no items
569 * are visited.
571 * @param func the member function to call for every visited item
572 * @param user extra data that is passed to func
573 * @param root the root item of the subtree to scan; this item itself
574 * is not scanned
575 * @see #forEveryItem
577 bool forEveryVisibleItem(KForEveryFunc func, void *user,
578 KTreeViewItem* root = 0);
581 Returns a pointer to the current item if there is one, or 0.
583 KTreeViewItem *getCurrentItem();
586 * Returns the number of pixels an item is indented for each level. If,
587 * in a derived class, the levels are indented differently this value
588 * may be ignored.
590 * @return the number of pixels of indentation for a level
592 int indentSpacing();
595 * Inserts an item into the tree with the given text and pixmap either
596 * before or after the item at the given row. The new item is added to
597 * the same branch as the referenced item (that is, the new item will
598 * be sibling of the reference item). If row is -1, the item is simply
599 * appended to the tree at the topmost level. A KTreeViewItem is
600 * created for which the delete-children flag is set to true.
602 * @param text specifies text for the new item; must not be 0
603 * @param pixmap specifies a pixmap for the new item
604 * @param index specifies the insert position
605 * @param prefix if true, the new item is inserted before the reference
606 * item, otherwise after it
607 * @return true if the item has been successfully inserted in the tree,
608 * otherwise false.
610 bool insertItem(const char* text, const QPixmap& pixmap,
611 int row = -1, bool prefix = true);
614 * This overloaded function inserts a new item into the tree, but a
615 * path through the tree specifies the reference insert position. If
616 * there is no item at the specified path, the item is simply appended
617 * to the tree at the topmost level.
619 * @param text specifies text for the new item; must not be 0
620 * @param pixmap specifies a pixmap for the new item
621 * @param path specifies the insert position
622 * @param prefix if true, the new item is inserted before the reference
623 * item, otherwise after it
624 * @return true if the item has been successfully inserted in the tree,
625 * otherwise false.
626 * @see #insertItem
628 bool insertItem(const char* text, const QPixmap& pixmap,
629 const KPath& path, bool prefix = true);
632 * This overloaded function inserts a new item into the tree, but the
633 * new item is specified directly. The reference item is specified as a
634 * row index.
636 * @param newItem specifies the item to insert
637 * @param path specifies the insert position
638 * @param prefix if true, the new item is inserted before the reference
639 * item, otherwise after it
640 * @return true if the item has been successfully inserted in the tree,
641 * otherwise false.
642 * @see #insertItem
644 bool insertItem(KTreeViewItem *newItem,
645 int row = -1, bool prefix = true);
648 * This overloaded function inserts a new item into the tree, but the
649 * new item is specified directly. The reference item is specified by a
650 * path.
652 * @param newItem specifies the item to insert
653 * @param path specifies the insert position
654 * @param prefix if true, the new item is inserted before the reference
655 * item, otherwise after it
656 * @return true if the item has been successfully inserted in the tree,
657 * otherwise false.
658 * @see #insertItem
660 bool insertItem(KTreeViewItem *newItem,
661 const KPath& thePath, bool prefix = true);
664 * Returns a pointer to the item in the specified row, or 0 if the
665 * specified row is outside the limits. This is a cheap operation.
667 * @param row specifies the row index
668 * @return the item at the specified row
669 * @see #itemRow
670 * @see #itemPath
672 KTreeViewItem* itemAt(int row) const;
675 * Returns a pointer to the item at the end of the path, or 0 if there
676 * is no such item.
678 * @param path specifies a path through the tree
679 * @return the item at the end of the specified path
680 * @see #itemRow
681 * @see #itemPath
683 KTreeViewItem* itemAt(const KPath& path);
686 * Looks up the row index at which the specified item is found in the
687 * visible tree or -1 if the item is not visible or not in the tree.
689 * @param specifies the item to search
690 * @return the row index of the item
691 * @see #itemAt
692 * @see #itemPath
694 int itemRow(KTreeViewItem* item);
697 * Fills path with the logical path to the item at the specified row.
698 * The specified path variable should be empty. Any strings popped from
699 * the path must be deleted by the caller. If the row is invalid, path
700 * remains unchanged (i.e. empty).
702 * @param row specifies the row index
703 * @param path receives the path of the specified item
704 * @see #itemAt
705 * @see #itemRow
707 void itemPath(int row, KPath& path);
710 * Outdents the item at the given row one level so that it becomes a
711 * sibling of its parent.
713 void join(int index);
716 * Same as above but uses a path to specify the item.
718 void join(const KPath& path);
721 * Moves the item at the specified row down one row in its current
722 * branch.
724 void lowerItem(int index);
727 * Same as above but uses a path to specify the item.
729 void lowerItem(const KPath& path);
732 * Moves the item at the specified row up one row in its current
733 * branch.
735 void raiseItem(int row);
738 * Same as above but uses a path to specify the item.
740 void raiseItem(const KPath& path);
743 * Removes the item at the specified row.
745 void removeItem(int row);
748 * Same as above except uses path through the tree to find the item.
750 void removeItem(const KPath& thePath);
753 * The specified item is scrolled into view. If the specified item is
754 * already visible, nothing happens, unless children is true, in which
755 * case the display is scrolled such that the item and as many of its
756 * child items as possible are visible.
758 * @param item specifies the item to make visible
759 * @param children specifies whether children should be made visible
761 void scrollVisible(KTreeViewItem* item, bool children);
764 * Makes the item at specifies row the current item and highlights it.
765 * The signal @ref #highlighted is emitted if the current item changes.
767 * @param row specifies the row to make the current item
769 void setCurrentItem(int row);
771 void setExpandButtonDrawing(bool enable);
773 void setExpandLevel(int level);
776 * Sets the indentation stepping, in pixels. If, in a derived class,
777 * the levels are indented differently this value may be ignored.
779 * @param spacing specifies the new indentation spacing, in pixels
781 void setIndentSpacing(int spacing);
784 * If true, removing a top-level item that contains the current item
785 * will move the current item to the following sibling (or to the
786 * previous if there is none). Otherwise, there will not be a current
787 * item.
789 void setMoveCurrentToSibling(bool m = true);
792 If enable is TRUE (default), item text will be displayed, otherwise
793 it will not, and no highlight will be shown in the default widget.
795 void setShowItemText(bool enable);
798 If enable is TRUE (default), lines depicting the structure of the
799 tree will be drawn, otherwise they will not.
801 void setTreeDrawing(bool enable);
804 Indicates whether item text is displayed.
806 bool showItemText() const;
809 * Indents the item at the specified index, creating a new branch.
811 void split(int index);
814 * Same as above but uses a path to specify the item.
816 void split(const KPath& path);
819 * Removes the item at the given index from the tree, but does not
820 * delete it, returning a pointer to the removed item.
822 KTreeViewItem* takeItem(int index);
825 * Same as above but uses a path to specify the item to take.
827 KTreeViewItem* takeItem(const KPath& path);
830 Indicates whether the tree structure is drawn.
832 bool treeDrawing() const;
834 public:
836 * Use numRows() instead.
838 * @return the number of items that are visible (their parents are
839 * expanded).
840 * @deprecated
842 int visibleCount() const { return numRows(); }
844 signals:
846 * This signal is emitted when an item in the tree is collapsed.
847 * The signal is not emitted for items that are invisible.
849 * @param index the row index of the collapsed item
851 void collapsed(int index);
854 * This signal is emitted when an item in the tree is expanded.
855 * The signal is not emitted for items that are invisible.
857 * @param index the row index of the expanded item
859 void expanded(int index);
862 * This signal is emitted when an item that has the delayedExpanding
863 * flag set is about to be expanded. The delayedExpanding flag is not
864 * reset; the slot that the signal is connected to should do so if
865 * necessary. The item being expanded is passed to the slot. The slot
866 * gets the opportunity to insert child items into that item. It should
867 * not change the item any other way. It can disallow the expansion by
868 * setting allow to false; in this case the item is not expanded.
870 * The signal is always emitted, regardless whether the expansion was
871 * triggered by the user or by the program.
873 * @param item specifies the item that is about to be expanded
874 * @param allow can be set to false to disallow expansion; no further
875 * actions are taken then
877 void expanding(KTreeViewItem* item, bool& allow);
880 * This signal is emitted when an item in the tree is highlighted.
882 * @param index the row index of the highlighted item.
884 void highlighted(int index);
887 * This signal is emitted when the user right-clicks.
889 * @param index the row index of where the click occurred; it is -1 if
890 * the click was not on an item.
891 * @param pt the location (in widget coordinates) where the mouse click
892 * happened.
894 void rightPressed(int index, const QPoint& pt);
897 * This signal is emitted when an item in the tree is selected.
899 * @param index the row index of the selected item.
901 void selected(int index);
903 protected:
905 * Appends a new child item to a parent item as a new direct child. All
906 * internal state is updated and the widget is repainted as necessary.
907 * The new child remains invisible if any ancestor of it (including the
908 * parent) is collapsed.
910 * @param parent specifies the parent of which the new item will become
911 * a child
912 * @param child specifies the new child item
913 * @see #appendChildItem
915 void appendChildItem(KTreeViewItem* parent,
916 KTreeViewItem* child);
917 virtual int cellHeight(int row) const;
918 virtual int cellWidth(int col) const;
919 void changeItem(KTreeViewItem* toChange,
920 int itemRow, const char* newText,
921 const QPixmap* newPixmap);
923 * Collapses the specified subtree and updates the display. The
924 * specified item need not be visible. This function does nothing if
925 * the item is already collapsed.
927 * @param item specifies the item to collapse.
928 * @param emitSignal specifies whether the signal @ref #collapsed should be emitted.
930 virtual void collapseSubTree(KTreeViewItem* item, bool emitSignal);
932 /** Internal function used for counting items */
933 static bool countItem(KTreeViewItem* item, void* total);
936 * Expands the specified subtree and updates the display. The specified
937 * item need not be visible. This function does nothing if the item is
938 * already expanded.
940 * @param item specifies the item to expand.
941 * @param emitSignal specifies whether the signal @ref #expanded should be emitted.
943 virtual void expandSubTree(KTreeViewItem* item, bool emitSignal);
944 void fixChildren(KTreeViewItem *parentItem);
945 virtual void focusInEvent(QFocusEvent* e);
946 virtual void focusOutEvent(QFocusEvent* e);
948 /** internal function used to determine maximum item width */
949 static bool getMaxItemWidth(KTreeViewItem* item, void *user);
952 * @param specifies a tree item of this tree
953 * @return the total indentation of the specified item, in pixels
955 virtual int indentation(KTreeViewItem* item) const;
958 * Inserts a new item before or after a reference item. (That is, the
959 * new item will become a sibling of the reference item.) If the
960 * reference item is 0, the new item is appended at the topmost level.
961 * If the reference item is not 0, it must be an item that is already
962 * in this KTreeView. Internal data is updated and the display is
963 * refreshed as necessary. The inserted item may still be invisible if
964 * any of the parents is collapsed.
966 * @param referenceItem specifies the reference item
967 * @param newItem specifies the new item; must not be 0.
968 * @return true if the item has been successfully inserted in the tree,
969 * otherwise false.
970 * @see #insertItem
972 bool insertItem(KTreeViewItem* referenceItem, KTreeViewItem* newItem,
973 bool prefix);
976 * Finds the logical path of the specified item. The specified path
977 * variable should be empty.
979 * @param item specifies the item whose path is to determine
980 * @param path receives the path of the item
981 * @see #itemPath
982 * @see #itemRow
983 * @see #itemAt
985 void itemPath(KTreeViewItem* item, KPath& path) const;
987 void join(KTreeViewItem *item);
990 * Reimplemented for key handling. If there are any items in the
991 * KTreeView, but there is no current item, the topmost item is made
992 * current. The key press event is first forwarded to the current item
993 * by calling @ref #KTreeViewItem::keyEvent.
995 virtual void keyPressEvent(QKeyEvent* e);
998 * The key release event is first forwarded to the current item (if
999 * there is one) by calling @ref #KTreeViewItem::keyEvent.
1001 virtual void keyReleaseEvent(QKeyEvent* e);
1003 int level(KTreeViewItem* item) const;
1004 void lowerItem(KTreeViewItem *item);
1007 * Reimplemented for mouse event handling. The mouse double click event
1008 * is first forwarded to the item that has been clicked on (if there is
1009 * one) by calling @ref #KTreeViewItem::mouseEvent.
1011 virtual void mouseDoubleClickEvent(QMouseEvent* e);
1014 * Reimplemented for mouse event handling. The mouse move event is
1015 * first forwarded to the current item (if there is one) by calling
1016 * @ref #KTreeViewItem::mouseEvent.
1018 virtual void mouseMoveEvent(QMouseEvent* e);
1021 * Reimplemented for mouse event handling. The mouse press event is
1022 * first forwarded to the item that has been clicked on (if there is
1023 * one) by calling @ref #KTreeViewItem::mouseEvent. The clicked on item
1024 * is made the current item.
1026 virtual void mousePressEvent(QMouseEvent* e);
1029 * Reimplemented for mouse event handling. The mouse release event is
1030 * first forwarded to the current item (if there is one) by calling
1031 * @ref #KTreeViewItem::mouseEvent.
1033 virtual void mouseReleaseEvent(QMouseEvent* e);
1035 virtual void paintCell(QPainter *p, int row, int col);
1037 * virtual void paintItem(QPainter *p, KTreeViewItem *item,
1038 * bool highlighted);
1041 * Internal. Needed to make kcontrol's color setup work.
1043 void paletteChange(const QPalette&);
1044 void raiseItem(KTreeViewItem* item);
1047 * Internal function that finds the item at the given path. Returns 0
1048 * if the item cannot be found. The path is destroyed by this function.
1050 KTreeViewItem* recursiveFind(KPath& path);
1052 void setItemExpanded(KTreeViewItem* item);
1053 static bool setItemExpandLevel(KTreeViewItem* item, void*);
1054 static bool setItemExpandButtonDrawing(KTreeViewItem* item, void*);
1055 static bool setItemShowText(KTreeViewItem* item, void*);
1056 static bool setItemTreeDrawing(KTreeViewItem* item, void*);
1057 void split(KTreeViewItem *item);
1058 void takeItem(KTreeViewItem *item);
1059 virtual void updateCellWidth();
1060 virtual void updateVisibleItems();
1061 void updateVisibleItemRec(KTreeViewItem* parent, int& count, int& width);
1063 KTreeViewItem* treeRoot;
1064 bool clearing;
1065 int current;
1066 bool drawExpandButton;
1067 bool drawTree;
1068 int expansion;
1069 bool goingDown;
1070 int itemIndent;
1071 int maxItemWidth;
1072 bool showText;
1073 bool moveCurrentToSibling;
1074 // list of visible items
1075 int itemCapacity; /* for how many items we've space allocated */
1076 KTreeViewItem** visibleItems;
1078 // Rainer Bawidamann: move window in "rubberband" mode
1079 bool rubberband_mode; // true if in "rubberband_mode"
1080 QPoint rubber_startMouse; // where the user pressed the MMB
1081 int rubber_height, rubber_width, // the size if the rubberband rect
1082 rubber_startX, rubber_startY; // the x/yOffset() when the MMB was pressed
1083 void draw_rubberband();
1084 void start_rubberband(const QPoint& where);
1085 void end_rubberband();
1086 void move_rubberband(const QPoint& where);
1089 #endif // KDE_KTREE_VIEW_H