1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2008 by Simon St. James <kdedevel@etotheipiplusone.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program 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 *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #ifndef DOLPHINTREEVIEW_H
22 #define DOLPHINTREEVIEW_H
25 #include <libdolphin_export.h>
28 * @brief Extends QTreeView by a custom selection- and hover-mechanism.
30 * QTreeView does not respect the width of a cell for the hover-feedback
31 * and when selecting items. DolphinTreeView improves this by respecting the
32 * content-width of the first column. The selection-mechanism also
33 * respects the content-width.
35 class LIBDOLPHINPRIVATE_EXPORT DolphinTreeView
: public QTreeView
40 explicit DolphinTreeView(QWidget
* parent
= 0);
41 virtual ~DolphinTreeView();
43 virtual QModelIndex
indexAt (const QPoint
& point
) const;
44 virtual QRegion
visualRegionForSelection(const QItemSelection
& selection
) const;
48 * @return True, if the item with the index \p index accepts a drop. In this
49 * case a visual feedback for the user is given during dragging. Per
50 * default false is returned.
52 virtual bool acceptsDrop(const QModelIndex
& index
) const;
54 virtual bool event(QEvent
* event
);
55 virtual void mousePressEvent(QMouseEvent
* event
);
56 virtual void mouseMoveEvent(QMouseEvent
* event
);
57 virtual void mouseReleaseEvent(QMouseEvent
* event
);
58 virtual void startDrag(Qt::DropActions supportedActions
);
59 virtual void dragEnterEvent(QDragEnterEvent
* event
);
60 virtual void dragMoveEvent(QDragMoveEvent
* event
);
61 virtual void dragLeaveEvent(QDragLeaveEvent
* event
);
62 virtual void paintEvent(QPaintEvent
* event
);
63 virtual void keyPressEvent(QKeyEvent
* event
);
64 virtual void keyReleaseEvent(QKeyEvent
* event
);
65 virtual void currentChanged(const QModelIndex
& current
, const QModelIndex
& previous
);
66 virtual void setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags command
);
67 virtual void scrollTo(const QModelIndex
& index
, ScrollHint hint
= EnsureVisible
);
71 * If the elastic band is currently shown, update the elastic band based on
72 * the current mouse position and ensure that the selection is the set of items
75 void updateElasticBandSelection();
78 * Updates the destination \a destination from
79 * the elastic band to the current mouse position and triggers
82 void updateElasticBand();
85 * Returns the rectangle for the elastic band dependent from the
86 * origin \a origin, the current destination
87 * \a destination and the viewport position.
89 QRect
elasticBandRect() const;
93 * Returns true, if \a pos is within the expanding toggle of a tree.
95 bool isAboveExpandingToggle(const QPoint
& pos
) const;
98 bool m_keyPressed
; // true if a key is pressed currently; info used by currentChanged()
99 bool m_expandingTogglePressed
;
100 bool m_useDefaultIndexAt
; // true, if QTreeView::indexAt() should be used
101 bool m_ignoreScrollTo
; // true if calls to scrollTo(...) should do nothing.
109 // Elastic band origin and destination coordinates are relative to t
110 // he origin of the view, not the viewport.
115 // Optimization mechanisms for use with elastic band selection.
116 // Basically, allow "incremental" updates to the selection based
117 // on the last elastic band shape.
118 QPoint lastSelectionOrigin
;
119 QPoint lastSelectionDestination
;
121 // If true, compute the set of selected elements from scratch (slower)
124 // Edges of the filenames that are closest to the edges of oldSelectionRect.
125 // Used to decide whether horizontal changes in the elastic band are likely
126 // to require us to re-check which items are selected.
127 int outsideNearestLeftEdge
;
128 int outsideNearestRightEdge
;
129 int insideNearestLeftEdge
;
130 int insideNearestRightEdge
;
131 // The set of items that were selected at the time this band was shown.
132 // NOTE: Unless CTRL was pressed when the band was created, this is always empty.
133 QItemSelection originalSelection
;