1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2000 Charles Samuels <charles@kde.org>
4 Copyright (C) 2000 Peter Putzer <putzer@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20#ifndef KLISTVIEW_H
21#define KLISTVIEW_H
22
23class QColorGroup;
24
25#include <kde3support_export.h>
26
27#include <Qt3Support/Q3ListView>
28#include <Qt3Support/Q3PtrList>
29
30class Q3DragObject;
31class KConfig;
32class KLineEdit;
33class KConfigGroup;
34
35/**
36 * This Widget extends the functionality of Q3ListView to honor the system
37 * wide settings for Single Click/Double Click mode, AutoSelection and
38 * ChangeCursorOverLink (TM).
39 *
40 * There is a new signal executed(). It gets connected to either
41 * Q3ListView::clicked() or Q3ListView::doubleClicked() depending on the KDE
42 * wide Single Click/Double Click settings. It is strongly recommended that
43 * you use this signal instead of the above mentioned. This way you don't
44 * need to care about the current settings.
45 * If you want to get informed when the user selects something connect to the
46 * Q3ListView::selectionChanged() signal.
47 *
48 * Drag-and-Drop is supported with the signal dropped(), just setAcceptDrops(true)
49 * and connect it to a suitable slot.
50 * To see where you are dropping, setDropVisualizer(true).
51 * And also you'll need acceptDrag(QDropEvent*)
52 *
53 * K3ListView is drag-enabled, too: to benefit from that you have to derive from it.
54 * Reimplement dragObject() and (possibly) startDrag(),
55 * and setDragEnabled(true).
56 */
57class KDE3SUPPORT_EXPORT K3ListView : public Q3ListView
58{
59 friend class K3ListViewItem;
60
61 Q_OBJECT
62 Q_ENUMS( SelectionModeExt )
63 Q_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth )
64 Q_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable )
65 Q_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable )
66 Q_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled )
67 Q_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen )
68 Q_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer )
69 Q_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn )
70 Q_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth )
71 Q_PROPERTY( QColor alternateBackground READ alternateBackground WRITE setAlternateBackground )
72 Q_PROPERTY( bool shadeSortColumn READ shadeSortColumn WRITE setShadeSortColumn )
73
74 Q_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE setSelectionModeExt )
75
76public:
77 /**
78 * Possible selection modes.
79 *
80 * The first four correspond directly to Q3ListView::SelectionMode, while
81 * the FileManager selection mode is defined as follows:
82 * @li home: move to the first
83 * @li end: move to the last
84 * @li PgUp/PgDn: move one page up/down
85 * @li up/down: move one item up/down
86 * @li insert: toggle selection of current and move to the next
87 * @li space: toggle selection of the current
88 * @li CTRL+up: move to the previous item and toggle selection of this one
89 * @li CTRL+down: toggle selection of the current item and move to the next
90 * @li CTRL+end: toggle selection from (including) the current
91 * item to (including) the last item
92 * @li CTRL+home: toggle selection from (including) the current
93 * item to the (including) the first item
94 * @li CTRL+PgDn: toggle selection from (including) the current
95 * item to (excluding) the item one page down
96 * @li CTRL+PgUp: toggle selection from (excluding) the current
97 * item to (including) the item one page up
98 *
99 * The combinations work the same with SHIFT instead of CTRL, except
100 * that if you start selecting something using SHIFT everything selected
101 * before will be deselected first.
102 *
103 * Additionally the current item is always selected automatically when
104 * navigating using the keyboard, except other items were selected explicitly.
105 *
106 * This way e.g. SHIFT+up/PgUp then SHIFT+down/PgDn leaves no item selected
107 */
108 enum SelectionModeExt {
109 Single = Q3ListView::Single,
110 Multi = Q3ListView::Multi,
111 Extended = Q3ListView::Extended,
112 NoSelection = Q3ListView::NoSelection,
113 FileManager
114 };
115
116 /**
117 * Constructor.
118 *
119 * The parameter @p parent is handled by Q3ListView, as usual.
120 */
121 explicit K3ListView ( QWidget *parent = 0 );
122
123 /**
124 * Destructor.
125 */
126 virtual ~K3ListView();
127
128 /**
129 * Reimplemented for internal reasons.
130 * Further reimplementations should call this function or else
131 * some features may not work correctly.
132 *
133 * The API is unaffected.
134 */
135 virtual void setAcceptDrops (bool);
136
137 /**
138 * This function determines whether the given coordinates are within the
139 * execute area. The execute area is the part of a Q3ListViewItem where mouse
140 * clicks or double clicks respectively generate a executed() signal.
141 * Depending on Q3ListView::allColumnsShowFocus() this is either the
142 * whole item or only the first column.
143 * @return true if point is inside execute area of an item, false in all
144 * other cases including the case that it is over the viewport.
145 */
146 virtual bool isExecuteArea( const QPoint& point );
147
148 /**
149 * Same thing, but from an x coordinate only. This only checks if x is in
150 * the first column (if all columns don't show focus), without testing if
151 * the y coordinate is over an item or not.
152 */
153 bool isExecuteArea( int x );
154
155
156 /**
157 * @return a list containing the currently selected items.
158 *
159 * @param includeHiddenItems Set to true to return all items regardless of
160 * visibility. Set to false to only return items that are isVisible().
161 *
162 * @return a list of all selected listview items
163 */
164 QList<Q3ListViewItem *> selectedItems(bool includeHiddenItems = true ) const;
165
166 /**
167 * Arbitrarily move @p item to @p parent, positioned immediately after item @p after.
168 * If after is 0, @p item is made the first child of @p parent.
169 *
170 * (Un-deprecated in kde-3.4)
171 */
172 void moveItem(Q3ListViewItem *item, Q3ListViewItem *parent, Q3ListViewItem *after);
173
174 /**
175 * @return the last item (not child!) of this listview.
176 *
177 * @see lastChild()
178 */
179 Q3ListViewItem *lastItem() const;
180
181 /**
182 * @return the last child of this listview.
183 *
184 * @see lastItem()
185 */
186 Q3ListViewItem* lastChild () const;
187
188 /**
189 * @return the lineedit used for inline renaming.
190 * Use that to setup a KCompletion or QValidator for the lineedit
191 */
192 KLineEdit* renameLineEdit() const;
193
194 /**
195 * @returns if it is legal to move items in the list view. True by default.
196 *
197 * @see setDragEnabled()
198 * @see setItemsMovable()
199 */
200 bool itemsMovable() const;
201
202 /**
203 * @return whether inplace-renaming has been enabled. False by default.
204 *
205 * @see setItemsRenameable()
206 */
207 bool itemsRenameable() const;
208
209 /**
210 * @return whether dragging is enabled. False by default.
211 *
212 * @see setDragEnabled()
213 */
214 bool dragEnabled() const;
215
216 /**
217 * @return true if AutoOpen is enabled (not implemented currently).
218 *
219 * @see setAutoOpen()
220 */
221 bool autoOpen() const;
222
223 /**
224 * @return true if @p column is renamable.
225 *
226 * @see setRenameable()
227 */
228 bool isRenameable (int column) const;
229
230 /**
231 * @return true if drawing of the drop-visualizer has been enabled. True by default.
232 *
233 * @see setDropVisualizer()
234 */
235 bool dropVisualizer() const;
236
237 /**
238 * @return the column for which tooltips are displayed (or -1 if none set).
239 *
240 * @see setTooltipColumn()
241 */
242 int tooltipColumn() const;
243
244 /**
245 * @return true if drawing of the drop-highlighter has been enabled. False by default.
246 *
247 * @see setDropHighlighter()
248 */
249 bool dropHighlighter() const;
250
251 /**
252 * The dropVisualizerWidth defaults to 4.
253 *
254 * @see setDropVisualizerWidth()
255 * @return the current width of the drop-visualizer.
256 */
257 int dropVisualizerWidth () const;
258
259 /**
260 * @return the "extended" selection mode of this listview.
261 *
262 * @see SelectionModeExt
263 * @see setSelectionModeExt
264 */
265 SelectionModeExt selectionModeExt () const;
266
267 /**
268 * Returns the index of @p item within the item tree or -1 if
269 * @p item doesn't exist in this list view. This function takes
270 * all items into account not only the visible ones.
271 */
272 int itemIndex( const Q3ListViewItem *item ) const;
273
274 /**
275 * Returns the item of @p index within the item tree or 0 if
276 * @p index doesn't exist in this list view. This function takes
277 * all items into account not only the visible ones.
278 */
279 Q3ListViewItem* itemAtIndex(int index);
280
281 /**
282 * @deprecated
283 * @see setFullWidth()
284 */
285 KDE_DEPRECATED void setFullWidth();
286
287 /**
288 * Let the last column fit exactly all the available width.
289 *
290 * @see fullWidth()
291 */
292 void setFullWidth(bool fullWidth);
293
294 /**
295 * Returns whether the last column is set to fit the available width.
296 *
297 * @see setFullWidth()
298 */
299 bool fullWidth() const;
300
301 /**
302 * Reimplemented for full width support
303 *
304 * @see removeColumn()
305 */
306 virtual int addColumn(const QString& label, int width = -1);
307 /**
308 * Reimplemented for full width support
309 */
310 virtual int addColumn(const QIcon& iconset, const QString& label, int width = -1);
311 /**
312 * Reimplemented for full width support
313 *
314 * @see addColumn()
315 */
316 virtual void removeColumn(int index);
317
318 /**
319 * sets the alternate background background color.
320 * This only has an effect if the items are K3ListViewItems
321 *
322 * @param c the color to use for every other item. Set to an invalid
323 * color to disable alternate colors.
324 *
325 * @see alternateBackground()
326 **/
327 void setAlternateBackground(const QColor &c);
328 /**
329 * @return the alternate background color
330 *
331 * @see setAlternateBackground()
332 */
333 const QColor &alternateBackground() const;
334
335 /**
336 * Saves the list view's layout (column widtsh, column order, sort column)
337 * to a KConfig group
338 *
339 * @param config the KConfig object to write to
340 * @param group the config group to use
341 */
342 void saveLayout(KConfig *config, const QString &group) const;
343 void saveLayout(KConfigGroup & cg) const;
344 /**
345 * Reads the list view's layout from a KConfig group as stored with
346 * saveLayout
347 *
348 * @param config the KConfig object to read from
349 * @param group the config group to use
350 */
351 void restoreLayout(KConfig *config, const QString &group);
352
353 void restoreLayout(KConfigGroup & cg);
354
355 /**
356 * Reimplemented to remember the current sort column and order.
357 * @param column is the column to be sorted, or -1 to sort in order of
358 * insertion
359 * @param ascending whether to sort ascending (or descending)
360 */
361 virtual void setSorting(int column, bool ascending = true);
362
363 /**
364 * @return the currently sorted column, or -1 if none is sorted
365 */
366 int columnSorted(void) const;
367
368 /**
369 * @return whether the current sort is ascending (or descending)
370 */
371 bool ascendingSort(void) const;
372
373 /**
374 * Reimplemented for internal reasons.
375 */
376 virtual void takeItem(Q3ListViewItem *i);
377
378 /**
379 * Set to true if the currently sorted column should be drawn shaded. Defaults to true
380 * @param shadeSortColumn True if sort column should be shaded.
381 */
382 void setShadeSortColumn(bool shadeSortColumn);
383
384 /**
385 * See if the sort column should be drawn shaded
386 * @return true if the sort column should be shaded
387 */
388 bool shadeSortColumn(void) const;
389Q_SIGNALS:
390
391 /**
392 * This signal is emitted whenever the user executes an listview item.
393 * That means depending on the KDE wide Single Click/Double Click
394 * setting the user clicked or double clicked on that item.
395 * @param item is the pointer to the executed listview item.
396 *
397 * Note that you may not delete any Q3ListViewItem objects in slots
398 * connected to this signal.
399 */
400 void executed( Q3ListViewItem *item );
401
402 /**
403 * This signal is emitted whenever the user executes an listview item.
404 * That means depending on the KDE wide Single Click/Double Click
405 * setting the user clicked or double clicked on that item.
406 * @param item is the pointer to the executed listview item.
407 * @param pos is the position where the user has clicked
408 * @param c is the column into which the user clicked.
409 *
410 * Note that you may not delete any Q3ListViewItem objects in slots
411 * connected to this signal.
412 */
413 void executed( Q3ListViewItem *item, const QPoint &pos, int c );
414
415 /**
416 * This signal gets emitted whenever something acceptable is
417 * dropped onto the listview.
418 *
419 * @param e is the drop event itself (it has already been accepted)
420 * @param after is the item after which the drop occurred (or 0L, if
421 * the drop was above all items)
422 *
423 * @see acceptDrop()
424 */
425 void dropped (QDropEvent * e, Q3ListViewItem *after);
426
427 /**
428 * This signal gets emitted whenever something acceptable is
429 * dropped onto the listview.
430 *
431 * This is an overloaded version of the above (provided to simplify
432 * processing drops outside of the class).
433 *
434 * @param list is the listview
435 * @param e is the drop event itself (it has already been accepted)
436 * @param after is the item after which the drop occurred (or 0L, if
437 * the drop was above all items
438 */
439 void dropped (K3ListView* list, QDropEvent* e, Q3ListViewItem* after);
440
441 /**
442 * This signal gets emitted whenever something acceptable is
443 * dropped onto the listview.
444 *
445 * This function also provides a parent, in the event that your listview
446 * is a tree
447 * @param list is the listview
448 * @param e is the drop event itself (it has already been accepted)
449 * @param parent the item that is to be the parent of the new item
450 * @param after is the item after which the drop occurred (or 0L, if
451 * the drop was above all items
452 */
453 void dropped (K3ListView* list, QDropEvent* e, Q3ListViewItem* parent, Q3ListViewItem* after);
454
455 /**
456 * This signal gets emitted whenever something acceptable is
457 * dropped onto the listview.
458 *
459 * This function also provides a parent, in the event that your listview
460 * is a tree
461 * @param e is the drop event itself (it has already been accepted)
462 * @param parent the item that is to be the parent of the new item
463 * @param after is the item after which the drop occurred (or 0L, if
464 * the drop was above all items
465 */
466 void dropped (QDropEvent* e, Q3ListViewItem* parent, Q3ListViewItem* after);
467
468 /**
469 * This signal is emitted when ever the user moves an item in the list via
470 * DnD.
471 * If more than one item is moved at the same time, this signal is only emitted
472 * once.
473 */
474 void moved();
475
476 /**
477 * Connect to this signal if you want to do some preprocessing before
478 * a move is made, for example, to disable sorting
479 *
480 * This is sent only once per each groups of moves. That is, for each
481 * drop that is a move this will be emitted once, before K3ListView calls
482 * @see moveItem()
483 */
484 void aboutToMove();
485
486 /**
487 * This signal is emitted when ever the user moves an item in the list via
488 * DnD.
489 * If more than one item is moved at the same time, @p afterFirst and
490 * @p afterNow will reflect what was true before the move.
491 * This differs from moved(), so be careful. All the items will have been
492 * moved before moved() is emitted, which is not true in this method. // FIXME
493 * @param item the item that was moved
494 * @param afterFirst the item that parameter item was in before the move, in the list
495 * @param afterNow the item it's currently after.
496 */
497 void moved (Q3ListViewItem *item, Q3ListViewItem *afterFirst, Q3ListViewItem *afterNow);
498
499
500 /**
501 * This signal is emitted after all the items have been moved. It reports info for
502 * each and every item moved, in order. The first element in @p items associates
503 * with the first of afterFirst and afterNow.
504 */
505 void moved(Q3PtrList<Q3ListViewItem> &items, Q3PtrList<Q3ListViewItem> &afterFirst, Q3PtrList<Q3ListViewItem> &afterNow);
506
507 /**
508 * This signal gets emitted when an item is renamed via in-place renaming.
509 *
510 * @param item is the renamed item.
511 * @param str is the new value of column @p col.
512 * @param col is the renamed column.
513 */
514 void itemRenamed(Q3ListViewItem* item, const QString &str, int col);
515
516 /**
517 * Same as above, but without the extra information.
518 */
519 void itemRenamed(Q3ListViewItem* item);
520
521 /**
522 * This signal is emitted when the shortcut key for popup-menus is pressed.
523 *
524 * Normally you should not use this, just connect a slot to signal
525 * contextMenu (K3ListView*, Q3ListViewItem*, const QPoint&) to correctly
526 * handle showing context menus regardless of settings.
527 *
528 * @param list is this listview.
529 * @param item is the currentItem() at the time the key was pressed. May be 0L.
530 */
531 void menuShortCutPressed (K3ListView* list, Q3ListViewItem* item);
532
533 /**
534 * This signal is emitted whenever a context-menu should be shown for item @p i.
535 * It automatically adjusts for all settings involved (Menu key, showMenuOnPress/Click).
536 *
537 * @param l is this listview.
538 * @param i is the item for which the menu should be shown. May be 0L.
539 * @param p is the point at which the menu should be shown.
540 */
541 void contextMenu (K3ListView* l, Q3ListViewItem* i, const QPoint& p);
542
543 void itemAdded(Q3ListViewItem *item);
544 void itemRemoved(Q3ListViewItem *item);
545
546public Q_SLOTS:
547 /**
548 * Rename column @p c of @p item.
549 */
550 virtual void rename(Q3ListViewItem *item, int c);
551
552 /**
553 * By default, if you called setItemsRenameable(true),
554 * only the first column is renameable.
555 * Use this function to enable the feature on other columns.
556 *
557 * If you want more intelligent (dynamic) selection,
558 * you'll have to derive from K3ListView,
559 * and override rename() and call only call it
560 * if you want the item to be renamed.
561 */
562 void setRenameable (int column, bool yesno=true);
563
564 /**
565 * Set whether items in the list view can be moved.
566 * It is enabled by default.
567 *
568 * @see itemsMovable()
569 */
570 virtual void setItemsMovable(bool b);
571
572 /**
573 * Enables inplace-renaming of items.
574 * It is disabled by default.
575 *
576 * @see itemsRenameable()
577 * @see setRenameable()
578 */
579 virtual void setItemsRenameable(bool b);
580
581 /**
582 * Enable/Disable the dragging of items.
583 * It is disabled by default.
584 */
585 virtual void setDragEnabled(bool b);
586
587 /**
588 * Enable/Disable AutoOpen (not implemented currently).
589 */
590 virtual void setAutoOpen(bool b);
591
592 /**
593 * Enable/Disable the drawing of a drop-visualizer
594 * (a bar that shows where a dropped item would be inserted).
595 * It is enabled by default, if dragging is enabled
596 */
597 virtual void setDropVisualizer(bool b);
598
599 /**
600 * Set the width of the (default) drop-visualizer.
601 * If you don't call this method, the width is set to 4.
602 */
603 void setDropVisualizerWidth (int w);
604
605 /**
606 * Set which column should be used for automatic tooltips.
607 *
608 * @param column is the column for which tooltips will be shown.
609 * Set -1 to disable this feature.
610 */
611 virtual void setTooltipColumn(int column);
612
613 /**
614 * Enable/Disable the drawing of a drop-highlighter
615 * (a rectangle around the item under the mouse cursor).
616 * It is disabled by default.
617 */
618 virtual void setDropHighlighter(bool b);
619
620 /**
621 * Set the selection mode.
622 *
623 * A different name was chosen to avoid API-clashes with Q3ListView::setSelectionMode().
624 */
625 void setSelectionModeExt (SelectionModeExt mode);
626
627 /**
628 * Enable/disable tabbing between editable cells
629 */
630 void setTabOrderedRenaming(bool b);
631
632 /**
633 * Returns whether tab ordered renaming is enabled
634 */
635 bool tabOrderedRenaming() const;
636
637protected:
638 /**
639 * Determine whether a drop on position @p p would count as
640 * being above or below the QRect @p rect.
641 *
642 * @param rect is the rectangle we examine.
643 * @param p is the point located in the rectangle, p is assumed to be in
644 * viewport coordinates.
645 */
646 bool below (const QRect& rect, const QPoint& p);
647
648 /**
649 * An overloaded version of below(const QRect&, const QPoint&).
650 *
651 * It differs from the above only in what arguments it takes.
652 *
653 * @param i the item whose rect() is passed to the above function.
654 * @param p is translated from contents coordinates to viewport coordinates
655 * before being passed to the above function.
656 */
657 bool below (Q3ListViewItem* i, const QPoint& p);
658
659 /**
660 * Reimplemented to reload the alternate background in palette changes.
661 * @internal
662 */
663 virtual bool event( QEvent * );
664
665 /**
666 * Emit signal executed.
667 * @internal
668 */
669 void emitExecute( Q3ListViewItem *item, const QPoint &pos, int c );
670
671 /**
672 * Reimplemented for internal reasons.
673 * Further reimplementations should call this function or else
674 * some features may not work correctly.
675 *
676 * The API is unaffected.
677 */
678 virtual void focusInEvent(QFocusEvent* fe);
679
680 /**
681 * Reimplemented for internal reasons.
682 * Further reimplementations should call this function or else
683 * some features may not work correctly.
684 *
685 * The API is unaffected.
686 */
687 virtual void focusOutEvent( QFocusEvent *fe );
688
689 /**
690 * Reimplemented for internal reasons.
691 * Further reimplementations should call this function or else
692 * some features may not work correctly.
693 *
694 * The API is unaffected.
695 */
696 virtual void leaveEvent( QEvent *e );
697
698 /**
699 * @return the tooltip for @p column of @p item.
700 */
701 virtual QString tooltip(Q3ListViewItem* item, int column) const;
702
703 /**
704 * @return whether the tooltip for @p column of @p item shall be shown at point @p pos.
705 */
706 virtual bool showTooltip(Q3ListViewItem *item, const QPoint &pos, int column) const;
707
708 /**
709 * Reimplemented for internal reasons.
710 * Further reimplementations should call this function or else
711 * some features may not work correctly.
712 *
713 * The API is unaffected.
714 */
715 virtual void contentsDragMoveEvent (QDragMoveEvent *event);
716
717 /**
718 * Reimplemented for internal reasons.
719 * Further reimplementations should call this function or else
720 * some features may not work correctly.
721 *
722 * The API is unaffected.
723 */
724 virtual void contentsMousePressEvent( QMouseEvent *e );
725
726 /**
727 * Reimplemented for internal reasons.
728 * Further reimplementations should call this function or else
729 * some features may not work correctly.
730 *
731 * The API is unaffected.
732 */
733 virtual void contentsMouseMoveEvent( QMouseEvent *e );
734
735 /**
736 * Reimplemented for internal reasons.
737 * Further reimplementations should call this function or else
738 * some features may not work correctly.
739 *
740 * The API is unaffected.
741 */
742 virtual void contentsMouseDoubleClickEvent ( QMouseEvent *e );
743
744 /**
745 * Reimplemented for internal reasons.
746 * Further reimplementations should call this function or else
747 * some features may not work correctly.
748 *
749 * The API is unaffected.
750 */
751 virtual void contentsDragLeaveEvent (QDragLeaveEvent *event);
752
753 /**
754 * Reimplemented for internal reasons.
755 * Further reimplementations should call this function or else
756 * some features may not work correctly.
757 *
758 * The API is unaffected.
759 */
760 virtual void contentsMouseReleaseEvent (QMouseEvent*);
761
762 /**
763 * Reimplemented for internal reasons.
764 * Further reimplementations should call this function or else
765 * some features may not work correctly.
766 *
767 * The API is unaffected.
768 */
769 virtual void contentsDropEvent (QDropEvent*);
770
771 /**
772 * Reimplemented for internal reasons.
773 * Further reimplementations should call this function or else
774 * some features may not work correctly.
775 *
776 * The API is unaffected.
777 */
778 virtual void contentsDragEnterEvent (QDragEnterEvent *);
779
780 /**
781 * Reimplemented for internal reasons.
782 * Further reimplementations should call this function or else
783 * some features may not work correctly.
784 *
785 * The API is unaffected.
786 */
787 virtual void contentsContextMenuEvent ( QContextMenuEvent * );
788
789 /**
790 * @return a dragobject encoding the current selection.
791 *
792 * @see setDragEnabled()
793 */
794 virtual Q3DragObject *dragObject();
795
796 /**
797 * @return true if the @p event provides some acceptable
798 * format.
799 * A common mistake is to forget the "const" in your reimplementation
800 */
801 virtual bool acceptDrag (QDropEvent* event) const;
802
803 /**
804 * Paint the drag line. If painter is null, don't try to :)
805 *
806 * If after == 0 then the marker should be drawn at the top.
807 *
808 * @return the rectangle that you painted to.
809 */
810 virtual QRect drawDropVisualizer (QPainter *p, Q3ListViewItem *parent, Q3ListViewItem *after);
811
812 /**
813 * Paint the drag rectangle. If painter is null, don't try to :)
814 *
815 *
816 * @return the rectangle that you painted to.
817 */
818 virtual QRect drawItemHighlighter(QPainter *painter, Q3ListViewItem *item);
819
820 /**
821 * This method calls dragObject() and starts the drag.
822 *
823 * Reimplement it to do fancy stuff like setting a pixmap or
824 * using a non-default DragMode
825 */
826 virtual void startDrag();
827
828 /**
829 * Reimplemented for internal reasons.
830 * Further reimplementations should call this function or else
831 * some features may not work correctly.
832 *
833 * The API is unaffected.
834 */
835 virtual void keyPressEvent (QKeyEvent*);
836
837 /**
838 * Reimplemented for internal reasons.
839 * Further reimplementations should call this function or else
840 * some features may not work correctly.
841 *
842 * The API is unaffected.
843 */
844 virtual void viewportPaintEvent(QPaintEvent*);
845
846 /**
847 * In FileManager selection mode: explicitly activate the mode
848 * in which the current item is automatically selected.
849 */
850 void activateAutomaticSelection();
851 /**
852 * In FileManager selection mode: explicitly deactivate the mode
853 * in which the current item is automatically selected.
854 */
855 void deactivateAutomaticSelection();
856 /**
857 * In FileManager selection mode: return whether it is currently in the mode
858 * where the current item is selected automatically.
859 * Returns false if items were selected explicitly, e.g. using the mouse.
860 */
861 bool automaticSelection() const;
862
863 /**
864 * Reimplemented for setFullWidth()
865 */
866 virtual void viewportResizeEvent(QResizeEvent* e);
867
868 /**
869 * Disable AutoSelection. This overrides the system wide setting for
870 * AutoSelection. Please don't call this unless you have good reasons to
871 * override the system wide setting for AutoSelection.
872 * @see resetAutoSelection()
873 */
874 void disableAutoSelection();
875
876 /**
877 * Reset AutoSelection to the system wide setting.
878 * @see disableAutoSelection()
879 */
880 void resetAutoSelection();
881
882 /**
883 * @deprecated This is just here for binary compatibility. Use the signal
884 * in Q3ListView instead.
885 */
886 // KDE 4: remove
887 void doubleClicked( Q3ListViewItem *item, const QPoint &pos, int c );
888
889protected Q_SLOTS:
890 /**
891 * Update internal settings whenever the global ones change.
892 * @internal
893 */
894 void slotSettingsChanged(int);
895
896 void slotMouseButtonClicked( int btn, Q3ListViewItem *item, const QPoint &pos, int c );
897 void doneEditing(Q3ListViewItem *item, int row);
898
899 /**
900 * Repaint the rect where I was drawing the drop line.
901 */
902 void cleanDropVisualizer();
903
904 /**
905 * Repaint the rect where I was drawing the drop rectangle.
906 */
907 void cleanItemHighlighter();
908
909 /**
910 * Emit the contextMenu signal. This slot is for mouse actions.
911 */
912 void emitContextMenu (Q3ListViewItem*, const QPoint&, int);
913
914 /**
915 * Emit the contextMenu signal. This slot is for key presses.
916 */
917 void emitContextMenu (K3ListView*, Q3ListViewItem*);
918
919 /**
920 * Accessory slot for AutoSelect
921 * @internal
922 */
923 void slotOnItem( Q3ListViewItem *item );
924
925 /**
926 * Accessory slot for AutoSelect/ChangeCursorOverItem
927 * @internal
928 */
929 void slotOnViewport();
930
931 /**
932 * Process AutoSelection.
933 * @internal
934 */
935 void slotAutoSelect();
936
937 void slotDragExpand();
938
939 /**
940 * Reacts to header changes in full width mode
941 * @internal
942 */
943 void slotHeaderChanged();
944
945protected:
946 /**
947 * Handle dropEvent when itemsMovable() is set to true.
948 */
949 virtual void movableDropEvent (Q3ListViewItem* parent, Q3ListViewItem* afterme);
950
951 /**
952 * Where is the nearest Q3ListViewItem that I'm going to drop?
953 *
954 * FIXME KDE 4.0: Make this method const so it can be called from an
955 * acceptDrag method without ugly casts
956 */
957 virtual void findDrop(const QPoint &pos, Q3ListViewItem *&parent, Q3ListViewItem *&after);
958
959 /**
960 * A special keyPressEvent (for FileManager selection mode).
961 */
962 void fileManagerKeyPressEvent (QKeyEvent*);
963
964 /**
965 * Convert the depth of an item into its indentation in pixels
966 */
967 int depthToPixels( int depth );
968
969#if 0
970private:
971 class Tooltip;
972#endif
973
974private:
975 class K3ListViewPrivate;
976 K3ListViewPrivate* const d;
977 bool isExecuteArea( int x, Q3ListViewItem* item );
978};
979
980/**
981 * A listview item with support for alternate background colors. It is
982 * a drop-in replacement for Q3ListViewItem
983 *
984 * @short listview item with alternate background color support
985 */
986class KDE3SUPPORT_EXPORT K3ListViewItem : public Q3ListViewItem
987{
988 friend class K3ListView;
989public:
990 /**
991 * constructors. The semantics remain as in Q3ListViewItem.
992 * Although they accept a Q3ListViewItem as parent, please
993 * don't mix K3ListViewItem (or subclasses) with Q3ListViewItem
994 * (or subclasses).
995 */
996 K3ListViewItem(Q3ListView *parent);
997 K3ListViewItem(Q3ListViewItem *parent);
998 K3ListViewItem(Q3ListView *parent, Q3ListViewItem *after);
999 K3ListViewItem(Q3ListViewItem *parent, Q3ListViewItem *after);
1000
1001 K3ListViewItem(Q3ListView *parent,
1002 const QString& label1, const QString& label2 = QString(),
1003 const QString& label3 = QString(), const QString& label4 = QString(),
1004 const QString& label5 = QString(), const QString& label6 = QString(),
1005 const QString& labem7 = QString(), const QString& label7 = QString());
1006
1007 K3ListViewItem(Q3ListViewItem *parent,
1008 const QString& label1, const QString& label2 = QString(),
1009 const QString& label3 = QString(), const QString& label4 = QString(),
1010 const QString& label5 = QString(), const QString& label6 = QString(),
1011 const QString& labem7 = QString(), const QString& label7 = QString());
1012
1013 K3ListViewItem(Q3ListView *parent, Q3ListViewItem *after,
1014 const QString& label1, const QString& label2 = QString(),
1015 const QString& label3 = QString(), const QString& label4 = QString(),
1016 const QString& label5 = QString(), const QString& label6 = QString(),
1017 const QString& labem7 = QString(), const QString& label7 = QString());
1018
1019 K3ListViewItem(Q3ListViewItem *parent, Q3ListViewItem *after,
1020 const QString& label1, const QString& label2 = QString(),
1021 const QString& label3 = QString(), const QString& label4 = QString(),
1022 const QString& label5 = QString(), const QString& label6 = QString(),
1023 const QString& labem7 = QString(), const QString& label7 = QString());
1024
1025
1026 virtual ~K3ListViewItem();
1027
1028 virtual void insertItem(Q3ListViewItem *item);
1029 virtual void takeItem(Q3ListViewItem *item);
1030 /**
1031 * returns true if this item is to be drawn with the alternate background
1032 */
1033 bool isAlternate();
1034 /**
1035 * returns the background color for this item
1036 */
1037 KDE_DEPRECATED const QColor &backgroundColor(); // #### should be removed in 4.0; use below instead
1038
1039 /**
1040 * returns the background color for this item at given column
1041 * This can be different in the column which is sorted due to shading
1042 * ### could be merged with above (column = -1) to be source compatible
1043 * ### but will only work if sort-shading is not used or the listView has
1044 * ### only 1 column
1045 */
1046 QColor backgroundColor(int column);
1047
1048 virtual void paintCell(QPainter *p, const QColorGroup &cg,
1049 int column, int width, int alignment);
1050
1051private:
1052 void init();
1053
1054private:
1055 uint m_odd : 1;
1056 uint m_known : 1;
1057 uint m_unused : 30;
1058};
1059
1060#endif
1061
1062// vim: ts=2 sw=2 et
1063