summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/klistview.h
Unidiff
Diffstat (limited to 'microkde/kdeui/klistview.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/klistview.h1033
1 files changed, 1033 insertions, 0 deletions
diff --git a/microkde/kdeui/klistview.h b/microkde/kdeui/klistview.h
new file mode 100644
index 0000000..f7d9f85
--- a/dev/null
+++ b/microkde/kdeui/klistview.h
@@ -0,0 +1,1033 @@
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20#ifndef KLISTVIEW_H
21#define KLISTVIEW_H
22
23#include <qlistview.h>
24
25#include <qptrlist.h>
26
27//US
28class QDropEvent;
29class QDragLeaveEvent;
30class QDragMoveEvent;
31class QDragEnterEvent;
32
33class QDragObject;
34class KConfig;
35class KLineEdit;
36/**
37 * This Widget extends the functionality of QListView to honor the system
38 * wide settings for Single Click/Double Click mode, AutoSelection and
39 * ChangeCursorOverLink (TM).
40 *
41 * There is a new signal executed(). It gets connected to either
42 * @ref QListView::clicked() or @ref QListView::doubleClicked() depending on the KDE
43 * wide Single Click/Double Click settings. It is strongly recommended that
44 * you use this signal instead of the above mentioned. This way you dont
45 * need to care about the current settings.
46 * If you want to get informed when the user selects something connect to the
47 * QListView::selectionChanged() signal.
48 *
49 * Drag-and-Drop is supported with the signal @ref #dropped(), just @ref #setAcceptDrops(true)
50 * and connect it to a suitable slot.
51 * To see where you are dropping, @ref setDropVisualizer(true).
52 * And also you'll need @ref acceptDrag(QDropEvent*)
53 *
54 * KListView is drag-enabled, too: to benefit from that you've got derive from it.
55 * Reimplement @ref dragObject() and (possibly) @ref startDrag(),
56 * and @ref setDragEnabled(true).
57 *
58 * @version $Id$
59 */
60class KListView : public QListView
61{
62 Q_OBJECT
63 Q_ENUMS( SelectionModeExt )
64 Q_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth )
65 Q_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable )
66 Q_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable )
67 Q_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled )
68 Q_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen )
69 Q_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer )
70//US Q_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn )
71 Q_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth )
72 Q_PROPERTY( QColor alternateBackground READ alternateBackground WRITE setAlternateBackground )
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 QListView::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 explicitely.
105 *
106 * This way e.g. SHIFT+up/PgUp then SHIFT+down/PgDn leaves no item selected
107 */
108 enum SelectionModeExt {
109 Single = QListView::Single,
110 Multi = QListView::Multi,
111 Extended = QListView::Extended,
112 NoSelection = QListView::NoSelection,
113 FileManager
114 };
115 void repaintContents( bool erase = true )
116 {
117 QScrollView::repaintContents( contentsX(), contentsY(),
118 visibleWidth(), visibleHeight(), erase );
119 };
120 /**
121 * Constructor.
122 *
123 * The parameters @p parent and @p name are handled by
124 * @ref QListView, as usual.
125 */
126 KListView (QWidget *parent = 0, const char *name = 0);
127
128 /**
129 * Destructor.
130 */
131 virtual ~KListView();
132
133 /**
134 * Reimplemented for internal reasons.
135 * Further reimplementations should call this function or else
136 * some features may not work correctly.
137 *
138 * The API is unaffected.
139 */
140 virtual void setAcceptDrops (bool);
141
142 /**
143 * This function determines whether the given coordinates are within the
144 * execute area. The execute area is the part of a @ref QListViewItem where mouse
145 * clicks or double clicks respectively generate a @ref #executed() signal.
146 * Depending on @ref QListView::allColumnsShowFocus() this is either the
147 * whole item or only the first column.
148 * @return true if point is inside execute area of an item, false in all
149 * other cases including the case that it is over the viewport.
150 */
151 virtual bool isExecuteArea( const QPoint& point );
152
153 /**
154 * Same thing, but from an x coordinate only. This only checks if x is in
155 * the first column (if all columns don't show focus), without testing if
156 * the y coordinate is over an item or not.
157 */
158 bool isExecuteArea( int x );
159
160 /**
161 * @return a list containing the currently selected items.
162 */
163 QPtrList<QListViewItem> selectedItems() const; // ### BIC: KDE 4: use an implicitly shared class! (QValueList?)
164
165 /**
166 * Arbitrarily move @p item to @p parent, positioned immediately after item @p after.
167 */
168 void moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after);
169
170 /**
171 * @return the last item (not child!) of this listview.
172 *
173 * @see lastChild()
174 */
175 QListViewItem *lastItem() const;
176
177 /**
178 * @return the last child of this listview.
179 *
180 * @see lastItem()
181 */
182 QListViewItem* lastChild () const;
183
184 /**
185 * @return the lineedit used for inline renaming.
186 * Use that to setup a @ref KCompletion or @ref QValidator for the lineedit
187 *
188 * @since 3.2
189 */
190 KLineEdit* renameLineEdit() const;
191
192 /**
193 * @returns if it is legal to move items in the list view. True by default.
194 *
195 * @see #setDragEnabled()
196 * @see #setItemsMovable()
197 */
198 bool itemsMovable() const;
199
200 /**
201 * @return whether inplace-renaming has been enabled. False by default.
202 *
203 * @see #setItemsRenameable()
204 */
205 bool itemsRenameable() const;
206
207 /**
208 * @return whether dragging is enabled. False by default.
209 *
210 * @see #setDragEnabled()
211 */
212 bool dragEnabled() const;
213
214 /**
215 * @return true if AutoOpen is enabled (not implemented currently).
216 *
217 * @see #setAutoOpen()
218 */
219 bool autoOpen() const;
220
221 /**
222 * @return true if @p column is renamable.
223 *
224 * @see #setRenameable()
225 */
226 bool isRenameable (int column) const;
227
228 /**
229 * @return true if drawing of the drop-visualizer has been enabled. True by default.
230 *
231 * @see #setDropVisualizer()
232 */
233 bool dropVisualizer() const;
234
235 /**
236 * @return the column for which tooltips are displayed (or -1 if none set).
237 *
238 * @see #setTooltipColumn()
239 */
240 int tooltipColumn() const;
241
242 /**
243 * For future expansions.
244 *
245 * Do not use.
246 * @deprecated
247 */
248 bool createChildren() const;
249
250 /**
251 * @return true if drawing of the drop-highlighter has been enabled. False by default.
252 *
253 * @see #setDropHighlighter()
254 */
255 bool dropHighlighter() const;
256
257 /**
258 * The dropVisualizerWidth defaults to 4.
259 *
260 * @see #setDropVisualizerWidth()
261 * @return the current width of the drop-visualizer.
262 */
263 int dropVisualizerWidth () const;
264
265 /**
266 * @return the "extended" selection mode of this listview.
267 *
268 * @see SelectionModeExt
269 * @see setSelectionModeExt
270 */
271 SelectionModeExt selectionModeExt () const;
272
273 /**
274 * Returns the index of @p item within the item tree or -1 if
275 * @p item doesn't exist in this list view. This function takes
276 * all items into account not only the visible ones.
277 */
278 int itemIndex( const QListViewItem *item ) const;
279
280 /**
281 * Returns the item of @p index within the item tree or 0 if
282 * @p index doesn't exist in this list view. This function takes
283 * all items into account not only the visible ones.
284 */
285 QListViewItem* itemAtIndex(int index);
286
287 /**
288 * @deprecated
289 * @see #setFullWidth()
290 */
291 void setFullWidth();
292
293 /**
294 * Let the last column fit exactly all the available width.
295 *
296 * @see #fullWidth()
297 */
298 void setFullWidth(bool fullWidth);
299
300 /**
301 * Returns whether the last column is set to fit the available width.
302 *
303 * @see #setFullWidth()
304 */
305 bool fullWidth() const;
306
307 /**
308 * Reimplemented for full width support
309 *
310 * @see #removeColumn()
311 */
312 virtual int addColumn(const QString& label, int width = -1);
313 /**
314 * Reimplemented for full width support
315 */
316 virtual int addColumn(const QIconSet& iconset, const QString& label, int width = -1);
317 /**
318 * Reimplemented for full width support
319 *
320 * @see #addColumn()
321 */
322 virtual void removeColumn(int index);
323
324 /**
325 * sets the alternate background background color.
326 * This only has an effect if the items are KListViewItems
327 *
328 * @param c the color to use for every other item. Set to an invalid
329 * colour to disable alternate colours.
330 *
331 * @see #alternateBackground()
332 **/
333 void setAlternateBackground(const QColor &c);
334 /**
335 * @return the alternate background color
336 *
337 * @see #setAlternateBackground()
338 */
339 const QColor &alternateBackground() const;
340
341 /**
342 * Saves the list view's layout (column widtsh, column order, sort column)
343 * to a KConfig group
344 *
345 * @param config the @ref KConfig object to write to
346 * @param group the config group to use
347 */
348 void saveLayout(KConfig *config, const QString &group) const;
349 /**
350 * Reads the list view's layout from a KConfig group as stored with
351 * @ref #saveLayout
352 *
353 * @param config the @ref KConfig object to read from
354 * @param group the config group to use
355 */
356 void restoreLayout(KConfig *config, const QString &group);
357 /**
358 * Reimplemented to remember the current sort column and order.
359 * @param column is the column to be sorted, or -1 to sort in order of
360 * insertion
361 * @param whether to sort ascending (or descending)
362 */
363 virtual void setSorting(int column, bool ascending = true);
364
365 /**
366 * @return the currently sorted column, or -1 if none is sorted
367 */
368 int columnSorted(void) const;
369
370 /**
371 * @return whether the current sort is ascending (or descending)
372 */
373 bool ascendingSort(void) const;
374
375signals:
376
377 /**
378 * This signal is emitted whenever the user executes an listview item.
379 * That means depending on the KDE wide Single Click/Double Click
380 * setting the user clicked or double clicked on that item.
381 * @param item is the pointer to the executed listview item.
382 *
383 * Note that you may not delete any @ref QListViewItem objects in slots
384 * connected to this signal.
385 */
386 void executed( QListViewItem *item );
387
388 /**
389 * This signal is emitted whenever the user executes an listview item.
390 * That means depending on the KDE wide Single Click/Double Click
391 * setting the user clicked or double clicked on that item.
392 * @param item is the pointer to the executed listview item.
393 * @param pos is the position where the user has clicked
394 * @param c is the column into which the user clicked.
395 *
396 * Note that you may not delete any @ref QListViewItem objects in slots
397 * connected to this signal.
398 */
399 void executed( QListViewItem *item, const QPoint &pos, int c );
400
401 /**
402 * This signal gets emitted whenever the user double clicks into the
403 * listview.
404 * @param item is the pointer to the clicked listview item.
405 * @param pos is the position where the user has clicked, and
406 * @param c is the column into which the user clicked.
407 *
408 * Note that you may not delete any @ref QListViewItem objects in slots
409 * connected to this signal.
410 *
411 * This signal is more or less here for the sake of completeness.
412 * You should normally not need to use this. In most cases its better
413 * to use @ref #executed() instead.
414 */
415 void doubleClicked( QListViewItem *item, const QPoint &pos, int c );
416
417 /**
418 * This signal gets emitted whenever something acceptable is
419 * dropped onto the listview.
420 *
421 * @param e is the drop event itself (it has already been accepted)
422 * @param after is the item after which the drop occured (or 0L, if
423 * the drop was above all items)
424 *
425 * @see #acceptDrop()
426 */
427 void dropped (QDropEvent * e, QListViewItem *after);
428
429 /**
430 * This signal gets emitted whenever something acceptable is
431 * dropped onto the listview.
432 *
433 * This is an overloaded version of the above (provided to simplify
434 * processing drops outside of the class).
435 *
436 * @param list is the listview
437 * @param e is the drop event itself (it has already been accepted)
438 * @param after is the item after which the drop occured (or 0L, if
439 * the drop was above all items
440 */
441 void dropped (KListView* list, QDropEvent* e, QListViewItem* after);
442
443 /**
444 * This signal gets emitted whenever something acceptable is
445 * dropped onto the listview.
446 *
447 * This function also provides a parent, in the event that your listview
448 * is a tree
449 * @param list is the listview
450 * @param e is the drop event itself (it has already been accepted)
451 * @param parent the item that is to be the parent of the new item
452 * @param after is the item after which the drop occured (or 0L, if
453 * the drop was above all items
454 */
455 void dropped (KListView* list, QDropEvent* e, QListViewItem* parent, QListViewItem* after);
456
457 /**
458 * This signal gets emitted whenever something acceptable is
459 * dropped onto the listview.
460 *
461 * This function also provides a parent, in the event that your listview
462 * is a tree
463 * @param e is the drop event itself (it has already been accepted)
464 * @param parent the item that is to be the parent of the new item
465 * @param after is the item after which the drop occured (or 0L, if
466 * the drop was above all items
467 */
468 void dropped (QDropEvent* e, QListViewItem* parent, QListViewItem* after);
469
470 /**
471 * This signal is emitted when ever the user moves an item in the list via
472 * DnD.
473 * If more than one item is moved at the same time, this signal is only emitted
474 * once.
475 */
476 void moved();
477
478 /**
479 * Connect to this signal if you want to do some preprocessing before
480 * a move is made, for example, to disable sorting
481 *
482 * This is sent only once per each groups of moves. That is, for each
483 * drop that is a move this will be emitted once, before KListView calls
484 * @see moveItem()
485 */
486 void aboutToMove();
487
488 /**
489 * This signal is emitted when ever the user moves an item in the list via
490 * DnD.
491 * If more than one item is moved at the same time, @p afterFirst and
492 * @p afterNow will reflect what was true before the move.
493 * This differs from @ref moved(), so be careful. All the items will have been
494 * moved before @ref moved() is emitted, which is not true in this method. // FIXME
495 * @param item the item that was moved
496 * @param afterFirst the item that parameter item was in before the move, in the list
497 * @param afterNow the item it's currently after.
498 */
499 void moved (QListViewItem *item, QListViewItem *afterFirst, QListViewItem *afterNow);
500
501
502 /**
503 * This signal is emitted after all the items have been moved. It reports info for
504 * each and every item moved, in order. The first element in @p items associates
505 * with the first of afterFirst and afterNow.
506 */
507 void moved(QPtrList<QListViewItem> &items, QPtrList<QListViewItem> &afterFirst, QPtrList<QListViewItem> &afterNow);
508
509 /**
510 * This signal gets emitted when an item is renamed via in-place renaming.
511 *
512 * @param item is the renamed item.
513 * @param str is the new value of column @p col.
514 * @param col is the renamed column.
515 */
516 void itemRenamed(QListViewItem* item, const QString &str, int col);
517
518 /**
519 * Same as above, but without the extra information.
520 */
521 void itemRenamed(QListViewItem* item);
522 void signalDelete();
523
524 /**
525 * This signal is emitted when the shortcut key for popup-menus is pressed.
526 *
527 * Normally you should not use this, just connect a slot to signal
528 * @ref contextMenu (KListView*, QListViewItem*, const QPoint&) to correctly
529 * handle showing context menus regardless of settings.
530 *
531 * @param list is this listview.
532 * @param item is the @ref currentItem() at the time the key was pressed. May be 0L.
533 */
534 void menuShortCutPressed (KListView* list, QListViewItem* item);
535
536 /**
537 * This signal is emitted whenever a context-menu should be shown for item @p i.
538 * It automatically adjusts for all settings involved (Menu key, showMenuOnPress/Click).
539 *
540 * @param l is this listview.
541 * @param i is the item for which the menu should be shown. May be 0L.
542 * @param p is the point at which the menu should be shown.
543 */
544 void contextMenu (KListView* l, QListViewItem* i, const QPoint& p);
545
546public slots:
547 /**
548 * Rename column @p c of @p item.
549 */
550 virtual void rename(QListViewItem *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 KListView,
559 * and override @ref 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 * For future expansions.
622 *
623 * Do not use.
624 * @deprecated
625 */
626 virtual void setCreateChildren(bool b);
627
628 /**
629 * Set the selection mode.
630 *
631 * A different name was chosen to avoid API-clashes with @ref QListView::setSelectionMode().
632 */
633 void setSelectionModeExt (SelectionModeExt mode);
634
635 /**
636 * Enable/disable tabbing between editable cells
637 * @since 3.1
638 */
639 void setTabOrderedRenaming(bool b);
640
641 /**
642 * Returns whether tab ordered renaming is enabled
643 * @since 3.1
644 */
645 bool tabOrderedRenaming() const;
646
647protected:
648 /**
649 * Determine whether a drop on position @p p would count as
650 * being above or below the QRect @p rect.
651 *
652 * @param rect is the rectangle we examine.
653 * @param p is the point located in the rectangle, p is assumed to be in
654 * viewport coordinates.
655 */
656 inline bool below (const QRect& rect, const QPoint& p)
657 {
658 return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2));
659 }
660
661 /**
662 * An overloaded version of below(const QRect&, const QPoint&).
663 *
664 * It differs from the above only in what arguments it takes.
665 *
666 * @param i the item whose rect() is passed to the above function.
667 * @param p is translated from contents coordinates to viewport coordinates
668 * before being passed to the above function.
669 */
670 inline bool below (QListViewItem* i, const QPoint& p)
671 {
672 return below (itemRect(i), contentsToViewport(p));
673 }
674
675 /**
676 * Reimplemented to reload the alternate background in palette changes.
677 * @internal
678 */
679 virtual bool event( QEvent * );
680
681 /**
682 * Emit signal @ref #executed.
683 * @internal
684 */
685 void emitExecute( QListViewItem *item, const QPoint &pos, int c );
686
687 /**
688 * Reimplemented for internal reasons.
689 * Further reimplementations should call this function or else
690 * some features may not work correctly.
691 *
692 * The API is unaffected.
693 */
694 virtual void focusInEvent(QFocusEvent* fe);
695
696 /**
697 * Reimplemented for internal reasons.
698 * Further reimplementations should call this function or else
699 * some features may not work correctly.
700 *
701 * The API is unaffected.
702 */
703 virtual void focusOutEvent( QFocusEvent *fe );
704
705 /**
706 * Reimplemented for internal reasons.
707 * Further reimplementations should call this function or else
708 * some features may not work correctly.
709 *
710 * The API is unaffected.
711 */
712 virtual void leaveEvent( QEvent *e );
713
714 /**
715 * @return the tooltip for @p column of @p item.
716 */
717 virtual QString tooltip(QListViewItem* item, int column) const;
718
719 /**
720 * @return whether the tooltip for @p column of @p item shall be shown at point @p pos.
721 */
722 virtual bool showTooltip(QListViewItem *item, const QPoint &pos, int column) const;
723
724 /**
725 * Reimplemented for internal reasons.
726 * Further reimplementations should call this function or else
727 * some features may not work correctly.
728 *
729 * The API is unaffected.
730 */
731 virtual void contentsDragMoveEvent (QDragMoveEvent *event);
732
733 /**
734 * Reimplemented for internal reasons.
735 * Further reimplementations should call this function or else
736 * some features may not work correctly.
737 *
738 * The API is unaffected.
739 */
740 virtual void contentsMousePressEvent( QMouseEvent *e );
741
742 /**
743 * Reimplemented for internal reasons.
744 * Further reimplementations should call this function or else
745 * some features may not work correctly.
746 *
747 * The API is unaffected.
748 */
749 virtual void contentsMouseMoveEvent( QMouseEvent *e );
750
751 /**
752 * Reimplemented for internal reasons.
753 * Further reimplementations should call this function or else
754 * some features may not work correctly.
755 *
756 * The API is unaffected.
757 */
758 virtual void contentsMouseDoubleClickEvent ( QMouseEvent *e );
759
760 /**
761 * Reimplemented for internal reasons.
762 * Further reimplementations should call this function or else
763 * some features may not work correctly.
764 *
765 * The API is unaffected.
766 */
767 virtual void contentsDragLeaveEvent (QDragLeaveEvent *event);
768
769 /**
770 * Reimplemented for internal reasons.
771 * Further reimplementations should call this function or else
772 * some features may not work correctly.
773 *
774 * The API is unaffected.
775 */
776 virtual void contentsMouseReleaseEvent (QMouseEvent*);
777
778 /**
779 * Reimplemented for internal reasons.
780 * Further reimplementations should call this function or else
781 * some features may not work correctly.
782 *
783 * The API is unaffected.
784 */
785 virtual void contentsDropEvent (QDropEvent*);
786
787 /**
788 * Reimplemented for internal reasons.
789 * Further reimplementations should call this function or else
790 * some features may not work correctly.
791 *
792 * The API is unaffected.
793 */
794 virtual void contentsDragEnterEvent (QDragEnterEvent *);
795
796 /**
797 * @return a dragobject encoding the current selection.
798 *
799 * @see setDragEnabled()
800 */
801 virtual QDragObject *dragObject();
802
803 /**
804 * @return true if the @p event provides some acceptable
805 * format.
806 * A common mistake is to forget the "const" in your reimplementation
807 */
808 virtual bool acceptDrag (QDropEvent* event) const;
809
810 /**
811 * Paint the drag line. If painter is null, don't try to :)
812 *
813 * If after == 0 then the marker should be drawn at the top.
814 *
815 * @return the rectangle that you painted to.
816 */
817 virtual QRect drawDropVisualizer (QPainter *p, QListViewItem *parent, QListViewItem *after);
818
819 /**
820 * Paint the drag rectangle. If painter is null, don't try to :)
821 *
822 *
823 * @return the rectangle that you painted to.
824 */
825 virtual QRect drawItemHighlighter(QPainter *painter, QListViewItem *item);
826
827 /**
828 * This method calls @ref dragObject() and starts the drag.
829 *
830 * Reimplement it to do fancy stuff like setting a pixmap or
831 * using a non-default DragMode
832 */
833 virtual void startDrag();
834
835 /**
836 * Reimplemented for internal reasons.
837 * Further reimplementations should call this function or else
838 * some features may not work correctly.
839 *
840 * The API is unaffected.
841 */
842 virtual void keyPressEvent (QKeyEvent*);
843
844 /**
845 * Reimplemented for internal reasons.
846 * Further reimplementations should call this function or else
847 * some features may not work correctly.
848 *
849 * The API is unaffected.
850 */
851 virtual void viewportPaintEvent(QPaintEvent*);
852
853 /**
854 * In FileManager selection mode: explicitely activate the mode
855 * in which the current item is automatically selected.
856 */
857 void activateAutomaticSelection();
858 /**
859 * In FileManager selection mode: explicitely deactivate the mode
860 * in which the current item is automatically selected.
861 */
862 void deactivateAutomaticSelection();
863 /**
864 * In FileManager selection mode: return whether it is currently in the mode
865 * where the current item is selected automatically.
866 * Returns false if items were selected explicitely, e.g. using the mouse.
867 */
868 bool automaticSelection() const;
869
870 /**
871 * Reimplemented for setFullWidth()
872 */
873 virtual void viewportResizeEvent(QResizeEvent* e);
874
875protected slots:
876 /**
877 * Update internal settings whenever the global ones change.
878 * @internal
879 */
880 void slotSettingsChanged(int);
881
882 void slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c );
883 void doneEditing(QListViewItem *item, int row);
884
885 /**
886 * Repaint the rect where I was drawing the drop line.
887 */
888 void cleanDropVisualizer();
889
890 /**
891 * Repaint the rect where I was drawing the drop rectangle.
892 */
893 void cleanItemHighlighter();
894
895 /**
896 * Emit the @ref contextMenu signal. This slot is for mouse actions.
897 */
898 void emitContextMenu (QListViewItem*, const QPoint&, int);
899
900 /**
901 * Emit the @ref #contextMenu signal. This slot is for key presses.
902 */
903 void emitContextMenu (KListView*, QListViewItem*);
904
905 /**
906 * Accessory slot for AutoSelect
907 * @internal
908 */
909 void slotOnItem( QListViewItem *item );
910
911 /**
912 * Accessory slot for AutoSelect/ChangeCursorOverItem
913 * @internal
914 */
915 void slotOnViewport();
916
917 /**
918 * Process AutoSelection.
919 * @internal
920 */
921 void slotAutoSelect();
922
923 void slotDragExpand();
924
925 /**
926 * Reacts to header changes in full width mode
927 * @internal
928 */
929 void slotHeaderChanged();
930
931protected:
932 /**
933 * Handle dropEvent when itemsMovable() is set to true.
934 */
935 virtual void movableDropEvent (QListViewItem* parent, QListViewItem* afterme);
936
937 /**
938 * Where is the nearest QListViewItem that I'm going to drop?
939 *
940 * FIXME KDE 4.0: Make this method const so it can be called from an
941 * acceptDrag method without ugly casts
942 */
943 virtual void findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after);
944
945 /**
946 * A special keyPressEvent (for FileManager selection mode).
947 */
948 void fileManagerKeyPressEvent (QKeyEvent*);
949
950 /**
951 * Convert the depth of an item into its indentation in pixels
952 */
953 int depthToPixels( int depth );
954
955private:
956 class Tooltip;
957protected:
958 virtual void virtual_hook( int id, void* data );
959private:
960 class KListViewPrivate;
961 KListViewPrivate *d;
962};
963
964/**
965 * A listview item with support for alternate background colours. It is
966 * a drop-in replacement for @ref QListViewItem
967 *
968 * @short listview item with alternate background colour support
969 */
970class KListViewItem : public QListViewItem
971{
972public:
973 /**
974 * constructors. The semantics remain as in @ref QListViewItem.
975 * Although they accept a @ref QListViewItem as parent, please
976 * don't mix KListViewItem (or subclasses) with QListViewItem
977 * (or subclasses).
978 */
979 KListViewItem(QListView *parent);
980 KListViewItem(QListViewItem *parent);
981 KListViewItem(QListView *parent, QListViewItem *after);
982 KListViewItem(QListViewItem *parent, QListViewItem *after);
983
984 KListViewItem(QListView *parent,
985 QString, QString = QString::null,
986 QString = QString::null, QString = QString::null,
987 QString = QString::null, QString = QString::null,
988 QString = QString::null, QString = QString::null);
989
990 KListViewItem(QListViewItem *parent,
991 QString, QString = QString::null,
992 QString = QString::null, QString = QString::null,
993 QString = QString::null, QString = QString::null,
994 QString = QString::null, QString = QString::null);
995
996 KListViewItem(QListView *parent, QListViewItem *after,
997 QString, QString = QString::null,
998 QString = QString::null, QString = QString::null,
999 QString = QString::null, QString = QString::null,
1000 QString = QString::null, QString = QString::null);
1001
1002 KListViewItem(QListViewItem *parent, QListViewItem *after,
1003 QString, QString = QString::null,
1004 QString = QString::null, QString = QString::null,
1005 QString = QString::null, QString = QString::null,
1006 QString = QString::null, QString = QString::null);
1007
1008 virtual ~KListViewItem();
1009
1010 /**
1011 * retuns true if this item is to be drawn with the alternate background
1012 */
1013 bool isAlternate();
1014 /**
1015 * returns the background colour for this item
1016 */
1017 const QColor &backgroundColor();
1018
1019 virtual void paintCell(QPainter *p, const QColorGroup &cg,
1020 int column, int width, int alignment);
1021
1022private:
1023 void init();
1024
1025private:
1026 uint m_odd : 1;
1027 uint m_known : 1;
1028 uint m_unused : 30;
1029};
1030
1031#endif
1032
1033// vim: ts=2 sw=2 et