Make toolbar visible again.
[kdbg.git] / kdbg / ktreeview.h
blob032ea9f1819ffdc1caf432f207d57c15dd34bfd0
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 <qstack.h> /* used to specify tree paths */
30 #include <qstring.h> /* used in items */
31 #include <qtableview.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
40 #if QT_VERSION >= 200
41 : public Qt
42 #endif
44 friend class KTreeView;
45 public:
46 /**
47 * Item constructor. While text defaults to a null string, and the
48 * item can be constructed this way, the text has to be non-null when
49 * the item is added to the tree, or it will not be inserted.
51 * The constructor sets the delete-children flag to false. This flag
52 * tells the item whether it shall delete the child items when it is
53 * itself deleted. By default the creator of the item is responsible to
54 * also delete the child items. (However, the versions of @ref
55 * #appendChildItem and @ref #insertChildItem that do not take a
56 * KTreeViewItem set the delete-children flag to true.)
58 * @param text specifies the new item's text
60 KTreeViewItem(const QString& text = QString()); // text can not be null when added to the list!
61 /**
62 * This overloaded constructor allows to specify a pixmap for the new
63 * item.
65 * @param text specifies the item's text
66 * @param pixmap specifies the item's pixmap
68 KTreeViewItem(const QString& text, const QPixmap& pixmap);
70 /**
71 * Destructor. It destroys its children if this item has been marked
72 * with setDeleteChildren(true).
74 virtual ~KTreeViewItem();
76 /**
77 * Appends a new (direct) child item at the end. It does not update
78 * administrative data in newChild except for its parent (which is this
79 * item) and owner.
81 virtual void appendChild(KTreeViewItem* newChild);
83 /**
84 * Returns a pointer to the child item at the given index in this
85 * item's sub tree, or 0 if not found.
87 * @param index specifies the index of the direct child to return
88 * @return the direct child at the specified index
89 */
90 KTreeViewItem* childAt(int index) const;
92 /**
93 * Returns the number of child items in this item's sub tree.
95 uint childCount() const;
97 /**
98 * Returns the index in this items sub tree of the given item or -1 if
99 * the specified item is not a direct child of this item.
101 * @param child specifies the child to look up; must not be 0
102 * @returns the index of the specified direct child
104 int childIndex(KTreeViewItem* child) const;
107 * Determines whether the specified point is inside the expand button.
109 bool expandButtonClicked(const QPoint& coord) const;
112 * Returns a pointer to the first child item in this item's sub tree, or
113 * 0 if none.
115 KTreeViewItem* getChild() const;
118 * Returns a pointer to the parent of this item, or 0 if none.
120 KTreeViewItem* getParent() const;
123 * Returns a reference to this item's pixmap. If there is no pixmap
124 * associated with this item, it will return a reference to a valid,
125 * null QPixmap.
127 const QPixmap& getPixmap() const;
130 * Returns a pointer to the next sibling item in the same branch below this
131 * one, or 0 if this item has no siblings below it.
133 KTreeViewItem* getSibling() const;
136 * Returns this item's text.
138 const QString& getText() const;
141 * Indicates whether this item has any children.
143 bool hasChild() const;
146 * Indicates whether this item has a parent.
148 bool hasParent() const;
151 * Indicates whether this item has a sibling item, that is, an item
152 * that would be displayed below it at the same level as this item.
154 bool hasSibling() const;
157 * Inserts the a new (direct) child in this item before the child at
158 * the specified index (first child is index 0). If there is no child
159 * at the specified index, the item is appended. It does not update
160 * administrative data in newChild except for its parent (which is this
161 * item) and owner.
163 * @param index specifies the index of a direct child of this item
164 * @param newChild specifies the new item to insert
166 virtual void insertChild(int index, KTreeViewItem* newChild);
169 * Indicates whether the item is expanded, that is, whether the child
170 * items (if any) would be visible if this item were visible.
172 * Note: If this function returns true, it does not necessarily indicate
173 * that this item is visible or that this item has any children.
175 bool isExpanded() const;
178 * Returns true if the item is visible. An item is visible if @ref
179 * #isExpanded() returns true for all its ancestors.
181 * Note: If this function returns true, it does not necessarily indicate
182 * that the widget is visible.
184 bool isVisible() const;
187 * Removes the specified (direct) child from this item and returns
188 * true. If it is not a direct child of this item, nothing happens, and
189 * false is returned. This function does not update the owning
190 * KTreeView.
192 virtual bool removeChild(KTreeViewItem* child);
195 * Sets the delayed-expanding flag. If this flag is true, the signal
196 * @ref #expanding is emitted when the item is about to be expanded.
197 * The expand button is always painted for this item, even if it
198 * doesn't have children.
200 void setDelayedExpanding(bool flag);
203 * Tells the item whether it should delete its children when it is
204 * deleted. The default is false, which means that the child items must
205 * be deleted explicitly.
207 void setDeleteChildren(bool flag);
210 * Tells the item whether it should draw the expand button. The default
211 * is true. This function does not update the owning tree widget.
213 virtual void setDrawExpandButton(bool doit);
216 * Tells the item whether it should paint the text. The default is
217 * true. This function does not update the owning tree widget.
219 virtual void setDrawText(bool doit);
222 * Tells the item whether it should draw the tree lines. The default is
223 * true. This function does not update the owning tree widget.
225 virtual void setDrawTree(bool doit);
228 * Tells whether the item is expanded (i.e. whether its children are
229 * visible). The default is false. This function does not update the
230 * owning tree widget.
232 virtual void setExpanded(bool is);
235 * Sets the item pixmap to the given pixmap. It does not redraw the
236 * item or update the owning KTreeView.
238 virtual void setPixmap(const QPixmap& pm);
241 * Sets the item text. This function does not redraw the item or update
242 * the owning KTreeView.
244 virtual void setText(const QString& t);
246 protected:
248 * Returns the bounding rectangle of the item.
250 virtual QRect boundingRect(int indent) const;
253 * Returns the height of the item. The default implementation uses font
254 * metrics of the owning KTreeView widget.
256 virtual int height() const;
259 * Returns the height of the item depending on the passed-in font
260 * metrics.
262 virtual int height(const QFontMetrics& fm) const;
265 * The item is given a chance to process key events before the owning
266 * KTreeView processes the event.
268 * @param ev specifies the key event; use ev->type() to find out whether
269 * this is a key down or up event (see @ref #QEvent).
270 * @return true if the event has been processed, false if it has not
271 * been processed. The default implementation just returns false to
272 * indicate that the event has not been processed.
274 virtual bool keyEvent(QKeyEvent* ev);
277 * The item is given a chance to process mouse events before the owning
278 * KTreeView processes the event.
280 * @param ev specifies the mouse event; use ev->type() to find out whether
281 * this is a mouse press, release, double click, or move event (see
282 * @ref #QEvent).
283 * @param itemCoord specifies the mouse even coordinates relative to this
284 * item (the coordinates in ev are the original coordinates).
285 * @return true if the event has been processed, false if it has not
286 * been processed. The default implementation just returns false to
287 * indicate that the event has not been processed.
289 virtual bool mouseEvent(QMouseEvent* ev, const QPoint& itemCoord);
292 * Paints the item: pixmap, text, expand button, parent branches
294 virtual void paint(QPainter* p, int indent,
295 const QColorGroup& cg, bool highlighted) const;
298 * paints the expand button
300 virtual void paintExpandButton(QPainter* p, int indent, int cellHeight,
301 const QColorGroup& cg) const;
304 * paints the highlighted text
306 virtual void paintHighlight(QPainter* p, int indent,
307 const QColorGroup& cg, bool hasFocus,
308 GUIStyle style) const;
311 * paints the item's text
313 virtual void paintText(QPainter* p, int indent, int cellHeight,
314 const QColorGroup& cg, bool highlighted) const;
317 * paints the item's tree part.
319 virtual void paintTree(QPainter* p, int indent, int cellHeight,
320 const QColorGroup& cg) const;
323 * Internal function that updates the owner of this item and its
324 * children and siblings (the latter only if requested).
326 void setOwner(KTreeView* newOwner, bool includeSiblings = false);
329 * Internal function that counts the number of child items.
331 void synchNumChildren();
334 * Returns the bounding rectangle of the text.
336 virtual QRect textBoundingRect(int indent) const;
339 * Returns the width of the item taking into account the specified
340 * indentation. The default implementation uses font metrics of the
341 * owning KTreeView widget.
343 virtual int width(int indent) const;
346 * Returns the width of the item depending on the passed-in font
347 * metrics and taking into account the specified indentation.
349 virtual int width(int indent, const QFontMetrics& fm) const;
351 protected:
352 /** The KTreeView that this item belongs to */
353 KTreeView* owner;
354 int numChildren;
355 bool doExpandButton;
356 bool expanded;
357 bool delayedExpanding;
358 bool doTree;
359 bool doText;
360 mutable QRect expandButton; /* is set in paint() */
361 KTreeViewItem* child;
362 KTreeViewItem* parent;
363 KTreeViewItem* sibling;
364 QPixmap pixmap;
365 QString text;
366 bool deleteChildren;
370 * KTreeView is a class that provides a way to display hierarchical data in
371 * a single-inheritance tree, similar to tree controls in Microsoft Windows
372 * and other GUIs. It is most suitable for directory trees or outlines, but
373 * I'm sure other uses will come to mind. It was designed mostly with the
374 * above two functions in mind, but I have tried to make it as flexible as
375 * I can to make it easy to adapt to other uses.
377 * Please read the source code if you have time. I have tried to comment it
378 * adequately and make the source understandable.
380 * The class features the following:
382 * - Displays both text and an optional pixmap supplied by the programmer.
383 * A support class, KTreeViewItem, can be inherited and modified to draw
384 * items as needed by the programmer.
386 * - The list items can be returned by index or logical path and the tree
387 * navigated by parent, child or sibling references contained in them.
388 * Also, item information such as text, pixmap, branch level can be
389 * obtained.
391 * - Items can be inserted, changed and removed either by index in the
392 * visible structure, or by logical paths through the tree hierarchy.
394 * - The logical path through the tree for any item can be obtained with
395 * the index of the item.
397 * - Tree structure display and expanding/collapsing of sub-trees is
398 * handled with no intervention from the programmer.
400 * - entire tree can be expanded or collapsed to a specified sub-level
401 * (handy for outline views)
403 * @short A collapsible treelist widget
404 * @author Johannes Sixt <Johannes.Sixt@telecom.at>, Keith Brown
406 class KTreeView : public QTableView
408 friend class KTreeViewItem;
409 Q_OBJECT
410 public:
412 * Widget contructor. All parameters are passed on to base QTableView,
413 * and are not used directly.
415 KTreeView(QWidget* parent = 0, const char* name = 0, WFlags f = 0);
418 * Desctructor. Deletes all items from the topmost level that have been
419 * marked with setDeleteChildren(true).
421 virtual ~KTreeView();
424 * Appends a new child item to the item at the specified row. If that
425 * item already has children, the new item is appended below these
426 * children. A KTreeViewItem is created for which the delete-children
427 * flag is set to true.
429 * @param text specifies text for the new item; must not be 0
430 * @param pixmap specifies a pixmap for the new item
431 * @param index specifies the item of which the new item will be a child
433 void appendChildItem(const char* text, const QPixmap& pixmap,
434 int index);
437 * This overloaded function appends a new item to an item, which is
438 * specified by a path.
440 * @param text specifies text for the new item; must not be 0
441 * @param pixmap specifies a pixmap for the new item
442 * @param path specifies the item of which the new item will be a child
443 * @see #appendChildItem
445 void appendChildItem(const char* text, const QPixmap& pixmap,
446 const KPath& path);
449 * Appends the specified item as a child of the item that is at the
450 * specified row. If that item already has children, the new item is
451 * appended below these children.
453 * @param newItem specifies the new item
454 * @param index specifies the item of which the new item will be a child
455 * @see #appendChildItem
457 void appendChildItem(KTreeViewItem* newItem, int index);
460 * This overloaded function appends a new item to an item, which is
461 * specified by a path.
463 * @param newItem specifies the new item
464 * @param path specifies the item of which the new item will be a child
465 * @see #appendChildItem
467 void appendChildItem(KTreeViewItem* newItem, const KPath& path);
470 Returns a bool value indicating whether the list will display a
471 horizontal scrollbar if one of the displayed items is wider than can
472 be displayed at the current width of the view.
474 bool autoBottomScrollBar() const;
477 Returns a bool value indicating whether the list will display a
478 vertical scrollbar if the number of displayed items is more than can
479 be displayed at the current height of the view.
481 bool autoScrollBar() const;
484 Returns a bool value indicating whether the list will update
485 immediately on changing the state of the widget in some way.
487 bool autoUpdate() const;
490 Returns a bool value indicating whether the list has currently has a
491 horizontal scroll bar.
493 bool bottomScrollBar() const;
496 * Computes coordinates relative to the specified row from the given
497 * coordinates. If the row is invalid, the input coordinates are
498 * returned unchanged.
500 * @param widget specifies widget coordinates (e.g. from a mouse event)
501 * @return coordinates relative to the specified cell
503 virtual QPoint cellCoords(int row, const QPoint& widgetCoord);
506 Changes the text and/or pixmap of the given item at the specified
507 index to the given values and updates the display if auto update
508 enabled. If changing only the text or pixmap, set the other parameter
509 to 0.
511 void changeItem(const char *newText,
512 const QPixmap *newPixmap,
513 int index);
516 Same as above function, except item to change is specified by a path
517 through the tree.
519 void changeItem(const char *newText,
520 const QPixmap *newPixmap,
521 const KPath& thePath);
524 Removes all items from the tree.
527 void clear();
530 Returns the total number of items in the tree, whether visible
531 (expanded sub-trees) or not (collapsed).
533 uint count();
536 Returns the index of the current (highlighted) item. If no current
537 item, returns -1.
539 int currentItem() const;
542 * Collapses the sub-tree at the specified row index. If the index is
543 * out of range, or the item is already collpased, nothing happens.
545 * @param index specifies the row index
546 * @param emitSignal specifies whether the signal @ref #collapsed
547 * should be emitted
549 void collapseItem(int index, bool emitSignal);
552 * Expands the sub-tree at the specified row index. If the index is
553 * out of range, or the item is already expanded, nothing happens.
555 * @param index specifies the row index
556 * @param emitSignal specifies whether the signal @ref #collapsed
557 * should be emitted
559 void expandItem(int index, bool emitSignal);
562 Returns the depth to which all parent items are automatically
563 expanded.
565 int expandLevel() const;
568 * The type of member functions that is called by @ref #forEveryItem and
569 * @ref #forEveryVisibleItem.
571 typedef bool (*KForEveryFunc)(KTreeViewItem*, void*);
574 * Iterates every item in the tree, visible or not, and applies the
575 * function func with a pointer to each item and user data supplied as
576 * parameters. The children of the specified root item are visited
577 * (root itself is not visited!). If root is 0 all items in the tree
578 * are visited. KForEveryFunc is defined as:
580 * typedef bool (KTreeView::*KForEveryFunc)(KTreeViewItem*, void*);
582 * That is, a member function that returns bool and takes a pointer to
583 * a KTreeViewItem and pointer to void as parameters. The traversal
584 * ends earlier if the supplied function returns bool. In this case the
585 * return value is also true.
587 * @param func the member function to call for every visited item
588 * @param user extra data that is passed to func
589 * @param root the root item of the subtree to scan; this item itself
590 * is not scanned
591 * @see #forEveryVisibleItem
593 bool forEveryItem(KForEveryFunc func, void* user,
594 KTreeViewItem* root = 0);
597 * This function is like @ref #forEveryItem, but only iterates visible
598 * items, in order. If the specified root item is invisible no items
599 * are visited.
601 * @param func the member function to call for every visited item
602 * @param user extra data that is passed to func
603 * @param root the root item of the subtree to scan; this item itself
604 * is not scanned
605 * @see #forEveryItem
607 bool forEveryVisibleItem(KForEveryFunc func, void *user,
608 KTreeViewItem* root = 0);
611 Returns a pointer to the current item if there is one, or 0.
613 KTreeViewItem *getCurrentItem();
616 * Returns the number of pixels an item is indented for each level. If,
617 * in a derived class, the levels are indented differently this value
618 * may be ignored.
620 * @return the number of pixels of indentation for a level
622 int indentSpacing();
625 * Inserts an item into the tree with the given text and pixmap either
626 * before or after the item at the given row. The new item is added to
627 * the same branch as the referenced item (that is, the new item will
628 * be sibling of the reference item). If row is -1, the item is simply
629 * appended to the tree at the topmost level. A KTreeViewItem is
630 * created for which the delete-children flag is set to true.
632 * @param text specifies text for the new item; must not be 0
633 * @param pixmap specifies a pixmap for the new item
634 * @param index specifies the insert position
635 * @param prefix if true, the new item is inserted before the reference
636 * item, otherwise after it
637 * @return true if the item has been successfully inserted in the tree,
638 * otherwise false.
640 bool insertItem(const char* text, const QPixmap& pixmap,
641 int row = -1, bool prefix = true);
644 * This overloaded function inserts a new item into the tree, but a
645 * path through the tree specifies the reference insert position. If
646 * there is no item at the specified path, the item is simply appended
647 * to the tree at the topmost level.
649 * @param text specifies text for the new item; must not be 0
650 * @param pixmap specifies a pixmap for the new item
651 * @param path specifies the insert position
652 * @param prefix if true, the new item is inserted before the reference
653 * item, otherwise after it
654 * @return true if the item has been successfully inserted in the tree,
655 * otherwise false.
656 * @see #insertItem
658 bool insertItem(const char* text, const QPixmap& pixmap,
659 const KPath& path, bool prefix = true);
662 * This overloaded function inserts a new item into the tree, but the
663 * new item is specified directly. The reference item is specified as a
664 * row index.
666 * @param newItem specifies the item to insert
667 * @param path specifies the insert position
668 * @param prefix if true, the new item is inserted before the reference
669 * item, otherwise after it
670 * @return true if the item has been successfully inserted in the tree,
671 * otherwise false.
672 * @see #insertItem
674 bool insertItem(KTreeViewItem *newItem,
675 int row = -1, bool prefix = true);
678 * This overloaded function inserts a new item into the tree, but the
679 * new item is specified directly. The reference item is specified by a
680 * path.
682 * @param newItem specifies the item to insert
683 * @param path specifies the insert position
684 * @param prefix if true, the new item is inserted before the reference
685 * item, otherwise after it
686 * @return true if the item has been successfully inserted in the tree,
687 * otherwise false.
688 * @see #insertItem
690 bool insertItem(KTreeViewItem *newItem,
691 const KPath& thePath, bool prefix = true);
694 * Returns a pointer to the item in the specified row, or 0 if the
695 * specified row is outside the limits. This is a cheap operation.
697 * @param row specifies the row index
698 * @return the item at the specified row
699 * @see #itemRow
700 * @see #itemPath
702 KTreeViewItem* itemAt(int row);
705 * Returns a pointer to the item at the end of the path, or 0 if there
706 * is no such item.
708 * @param path specifies a path through the tree
709 * @return the item at the end of the specified path
710 * @see #itemRow
711 * @see #itemPath
713 KTreeViewItem* itemAt(const KPath& path);
716 * Looks up the row index at which the specified item is found in the
717 * visible tree or -1 if the item is not visible or not in the tree.
719 * @param specifies the item to search
720 * @return the row index of the item
721 * @see #itemAt
722 * @see #itemPath
724 int itemRow(KTreeViewItem* item);
727 * Fills path with the logical path to the item at the specified row.
728 * The specified path variable should be empty. Any strings popped from
729 * the path must be deleted by the caller. If the row is invalid, path
730 * remains unchanged (i.e. empty).
732 * @param row specifies the row index
733 * @param path receives the path of the specified item
734 * @see #itemAt
735 * @see #itemRow
737 void itemPath(int row, KPath& path);
740 * Outdents the item at the given row one level so that it becomes a
741 * sibling of its parent.
743 void join(int index);
746 * Same as above but uses a path to specify the item.
748 void join(const KPath& path);
751 * Moves the item at the specified row down one row in its current
752 * branch.
754 void lowerItem(int index);
757 * Same as above but uses a path to specify the item.
759 void lowerItem(const KPath& path);
762 * Moves the item at the specified row up one row in its current
763 * branch.
765 void raiseItem(int row);
768 * Same as above but uses a path to specify the item.
770 void raiseItem(const KPath& path);
773 * Removes the item at the specified row.
775 void removeItem(int row);
778 * Same as above except uses path through the tree to find the item.
780 void removeItem(const KPath& thePath);
783 Returns bool value indicating whether the list currently displays a
784 vertical scroll bar.
786 bool scrollBar() const;
789 * The specified item is scrolled into view. If the specified item is
790 * already visible, nothing happens, unless children is true, in which
791 * case the display is scrolled such that the item and as many of its
792 * child items as possible are visible.
794 * @param item specifies the item to make visible
795 * @param children specifies whether children should be made visible
797 void scrollVisible(KTreeViewItem* item, bool children);
800 If enable is TRUE (default), enables auto update, else disables it.
802 void setAutoUpdate(bool enable);
805 If enable is TRUE, displays a horizontal scroll bar, else hides it.
807 void setBottomScrollBar(bool enable);
810 * Makes the item at specifies row the current item and highlights it.
811 * The signal @ref #highlighted is emitted if the current item changes.
813 * @param row specifies the row to make the current item
815 void setCurrentItem(int row);
817 void setExpandButtonDrawing(bool enable);
819 void setExpandLevel(int level);
822 * Sets the indentation stepping, in pixels. If, in a derived class,
823 * the levels are indented differently this value may be ignored.
825 * @param spacing specifies the new indentation spacing, in pixels
827 void setIndentSpacing(int spacing);
830 * If true, removing a top-level item that contains the current item
831 * will move the current item to the following sibling (or to the
832 * previous if there is none). Otherwise, there will not be a current
833 * item.
835 void setMoveCurrentToSibling(bool m = true);
838 If enable is TRUE, displays a vertical scroll bar, else hides it.
840 void setScrollBar(bool enable);
843 If enable is TRUE (default), item text will be displayed, otherwise
844 it will not, and no highlight will be shown in the default widget.
846 void setShowItemText(bool enable);
849 If enable is TRUE, enables smooth scrolling, else disables
850 it (default).
852 void setSmoothScrolling(bool enable);
855 If enable is TRUE (default), lines depicting the structure of the
856 tree will be drawn, otherwise they will not.
858 void setTreeDrawing(bool enable);
861 Indicates whether item text is displayed.
863 bool showItemText() const;
866 Returns a bool value indicating whether smooth scrolling is enabled.
868 bool smoothScrolling() const;
871 * Indents the item at the specified index, creating a new branch.
873 void split(int index);
876 * Same as above but uses a path to specify the item.
878 void split(const KPath& path);
881 * Removes the item at the given index from the tree, but does not
882 * delete it, returning a pointer to the removed item.
884 KTreeViewItem* takeItem(int index);
887 * Same as above but uses a path to specify the item to take.
889 KTreeViewItem* takeItem(const KPath& path);
892 Indicates whether the tree structure is drawn.
894 bool treeDrawing() const;
896 public:
898 * Use numRows() instead.
900 * @return the number of items that are visible (their parents are
901 * expanded).
902 * @deprecated
904 int visibleCount() const { return numRows(); }
906 signals:
908 * This signal is emitted when an item in the tree is collapsed.
909 * The signal is not emitted for items that are invisible.
911 * @param index the row index of the collapsed item
913 void collapsed(int index);
916 * This signal is emitted when an item in the tree is expanded.
917 * The signal is not emitted for items that are invisible.
919 * @param index the row index of the expanded item
921 void expanded(int index);
924 * This signal is emitted when an item that has the delayedExpanding
925 * flag set is about to be expanded. The delayedExpanding flag is not
926 * reset; the slot that the signal is connected to should do so if
927 * necessary. The item being expanded is passed to the slot. The slot
928 * gets the opportunity to insert child items into that item. It should
929 * not change the item any other way. It can disallow the expansion by
930 * setting allow to false; in this case the item is not expanded.
932 * The signal is always emitted, regardless whether the expansion was
933 * triggered by the user or by the program.
935 * @param item specifies the item that is about to be expanded
936 * @param allow can be set to false to disallow expansion; no further
937 * actions are taken then
939 void expanding(KTreeViewItem* item, bool& allow);
942 * This signal is emitted when an item in the tree is highlighted.
944 * @param index the row index of the highlighted item.
946 void highlighted(int index);
949 * This signal is emitted when the user right-clicks.
951 * @param index the row index of where the click occurred; it is -1 if
952 * the click was not on an item.
953 * @param pt the location (in widget coordinates) where the mouse click
954 * happened.
956 void rightPressed(int index, const QPoint& pt);
959 * This signal is emitted when an item in the tree is selected.
961 * @param index the row index of the selected item.
963 void selected(int index);
965 protected:
967 * Appends a new child item to a parent item as a new direct child. All
968 * internal state is updated and the widget is repainted as necessary.
969 * The new child remains invisible if any ancestor of it (including the
970 * parent) is collapsed.
972 * @param parent specifies the parent of which the new item will become
973 * a child
974 * @param child specifies the new child item
975 * @see #appendChildItem
977 void appendChildItem(KTreeViewItem* parent,
978 KTreeViewItem* child);
979 virtual int cellHeight(int row);
980 virtual int cellWidth(int col);
981 void changeItem(KTreeViewItem* toChange,
982 int itemRow, const char* newText,
983 const QPixmap* newPixmap);
985 * Collapses the specified subtree and updates the display. The
986 * specified item need not be visible. This function does nothing if
987 * the item is already collapsed.
989 * @param item specifies the item to collapse.
990 * @param emitSignal specifies whether the signal @ref #collapsed should be emitted.
992 virtual void collapseSubTree(KTreeViewItem* item, bool emitSignal);
994 /** Internal function used for counting items */
995 static bool countItem(KTreeViewItem* item, void* total);
998 * Expands the specified subtree and updates the display. The specified
999 * item need not be visible. This function does nothing if the item is
1000 * already expanded.
1002 * @param item specifies the item to expand.
1003 * @param emitSignal specifies whether the signal @ref #expanded should be emitted.
1005 virtual void expandSubTree(KTreeViewItem* item, bool emitSignal);
1006 void fixChildren(KTreeViewItem *parentItem);
1007 virtual void focusInEvent(QFocusEvent* e);
1008 virtual void focusOutEvent(QFocusEvent* e);
1010 /** internal function used to determine maximum item width */
1011 static bool getMaxItemWidth(KTreeViewItem* item, void *user);
1014 * @param specifies a tree item of this tree
1015 * @return the total indentation of the specified item, in pixels
1017 virtual int indentation(KTreeViewItem* item) const;
1020 * Inserts a new item before or after a reference item. (That is, the
1021 * new item will become a sibling of the reference item.) If the
1022 * reference item is 0, the new item is appended at the topmost level.
1023 * If the reference item is not 0, it must be an item that is already
1024 * in this KTreeView. Internal data is updated and the display is
1025 * refreshed as necessary. The inserted item may still be invisible if
1026 * any of the parents is collapsed.
1028 * @param referenceItem specifies the reference item
1029 * @param newItem specifies the new item; must not be 0.
1030 * @return true if the item has been successfully inserted in the tree,
1031 * otherwise false.
1032 * @see #insertItem
1034 bool insertItem(KTreeViewItem* referenceItem, KTreeViewItem* newItem,
1035 bool prefix);
1038 * Finds the logical path of the specified item. The specified path
1039 * variable should be empty.
1041 * @param item specifies the item whose path is to determine
1042 * @param path receives the path of the item
1043 * @see #itemPath
1044 * @see #itemRow
1045 * @see #itemAt
1047 void itemPath(KTreeViewItem* item, KPath& path) const;
1049 void join(KTreeViewItem *item);
1052 * Reimplemented for key handling. If there are any items in the
1053 * KTreeView, but there is no current item, the topmost item is made
1054 * current. The key press event is first forwarded to the current item
1055 * by calling @ref #KTreeViewItem::keyEvent.
1057 virtual void keyPressEvent(QKeyEvent* e);
1060 * The key release event is first forwarded to the current item (if
1061 * there is one) by calling @ref #KTreeViewItem::keyEvent.
1063 virtual void keyReleaseEvent(QKeyEvent* e);
1065 int level(KTreeViewItem* item) const;
1066 void lowerItem(KTreeViewItem *item);
1069 * Reimplemented for mouse event handling. The mouse double click event
1070 * is first forwarded to the item that has been clicked on (if there is
1071 * one) by calling @ref #KTreeViewItem::mouseEvent.
1073 virtual void mouseDoubleClickEvent(QMouseEvent* e);
1076 * Reimplemented for mouse event handling. The mouse move event is
1077 * first forwarded to the current item (if there is one) by calling
1078 * @ref #KTreeViewItem::mouseEvent.
1080 virtual void mouseMoveEvent(QMouseEvent* e);
1083 * Reimplemented for mouse event handling. The mouse press event is
1084 * first forwarded to the item that has been clicked on (if there is
1085 * one) by calling @ref #KTreeViewItem::mouseEvent. The clicked on item
1086 * is made the current item.
1088 virtual void mousePressEvent(QMouseEvent* e);
1091 * Reimplemented for mouse event handling. The mouse release event is
1092 * first forwarded to the current item (if there is one) by calling
1093 * @ref #KTreeViewItem::mouseEvent.
1095 virtual void mouseReleaseEvent(QMouseEvent* e);
1097 virtual void paintCell(QPainter *p, int row, int col);
1099 * virtual void paintItem(QPainter *p, KTreeViewItem *item,
1100 * bool highlighted);
1103 * Internal. Needed to make kcontrol's color setup work.
1105 void paletteChange(const QPalette&);
1106 void raiseItem(KTreeViewItem* item);
1109 * Internal function that finds the item at the given path. Returns 0
1110 * if the item cannot be found. The path is destroyed by this function.
1112 KTreeViewItem* recursiveFind(KPath& path);
1114 void setItemExpanded(KTreeViewItem* item);
1115 static bool setItemExpandLevel(KTreeViewItem* item, void*);
1116 static bool setItemExpandButtonDrawing(KTreeViewItem* item, void*);
1117 static bool setItemShowText(KTreeViewItem* item, void*);
1118 static bool setItemTreeDrawing(KTreeViewItem* item, void*);
1119 void split(KTreeViewItem *item);
1120 void takeItem(KTreeViewItem *item);
1121 virtual void updateCellWidth();
1122 virtual void updateVisibleItems();
1123 void updateVisibleItemRec(KTreeViewItem* parent, int& count, int& width);
1125 KTreeViewItem* treeRoot;
1126 bool clearing;
1127 int current;
1128 bool drawExpandButton;
1129 bool drawTree;
1130 int expansion;
1131 bool goingDown;
1132 int itemIndent;
1133 int maxItemWidth;
1134 bool showText;
1135 bool moveCurrentToSibling;
1136 // list of visible items
1137 int itemCapacity; /* for how many items we've space allocated */
1138 KTreeViewItem** visibleItems;
1140 // Rainer Bawidamann: move window in "rubberband" mode
1141 bool rubberband_mode; // true if in "rubberband_mode"
1142 QPoint rubber_startMouse; // where the user pressed the MMB
1143 int rubber_height, rubber_width, // the size if the rubberband rect
1144 rubber_startX, rubber_startY; // the x/yOffset() when the MMB was pressed
1145 void draw_rubberband();
1146 void start_rubberband(const QPoint& where);
1147 void end_rubberband();
1148 void move_rubberband(const QPoint& where);
1151 #endif // KDE_KTREE_VIEW_H