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 void keyboardSearch(const QString
& search
);
45 virtual QRegion
visualRegionForSelection(const QItemSelection
& selection
) const;
49 * @return True, if the item with the index \p index accepts a drop. In this
50 * case a visual feedback for the user is given during dragging. Per
51 * default false is returned.
53 virtual bool acceptsDrop(const QModelIndex
& index
) const;
55 virtual bool event(QEvent
* event
);
56 virtual void mousePressEvent(QMouseEvent
* event
);
57 virtual void mouseMoveEvent(QMouseEvent
* event
);
58 virtual void mouseReleaseEvent(QMouseEvent
* event
);
59 virtual void startDrag(Qt::DropActions supportedActions
);
60 virtual void dragEnterEvent(QDragEnterEvent
* event
);
61 virtual void dragMoveEvent(QDragMoveEvent
* event
);
62 virtual void dragLeaveEvent(QDragLeaveEvent
* event
);
63 virtual void paintEvent(QPaintEvent
* event
);
64 virtual void setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags command
);
65 virtual void scrollTo(const QModelIndex
& index
, ScrollHint hint
= EnsureVisible
);
69 * If the elastic band is currently shown, update the elastic band based on
70 * the current mouse position and ensure that the selection is the set of items
73 void updateElasticBandSelection();
76 * Updates the destination \a destination from
77 * the elastic band to the current mouse position and triggers
80 void updateElasticBand();
83 * Returns the rectangle for the elastic band dependent from the
84 * origin \a origin, the current destination
85 * \a destination and the viewport position.
87 QRect
elasticBandRect() const;
91 * Returns true, if \a pos is within the expanding toggle of a tree.
93 bool isAboveExpandingToggle(const QPoint
& pos
) const;
96 bool m_expandingTogglePressed
;
97 bool m_useDefaultIndexAt
; // true, if QTreeView::indexAt() should be used
98 bool m_ignoreScrollTo
; // true if calls to scrollTo(...) should do nothing.
106 // Elastic band origin and destination coordinates are relative to t
107 // he origin of the view, not the viewport.
112 // Optimization mechanisms for use with elastic band selection.
113 // Basically, allow "incremental" updates to the selection based
114 // on the last elastic band shape.
115 QPoint lastSelectionOrigin
;
116 QPoint lastSelectionDestination
;
118 // If true, compute the set of selected elements from scratch (slower)
121 // Edges of the filenames that are closest to the edges of oldSelectionRect.
122 // Used to decide whether horizontal changes in the elastic band are likely
123 // to require us to re-check which items are selected.
124 int outsideNearestLeftEdge
;
125 int outsideNearestRightEdge
;
126 int insideNearestLeftEdge
;
127 int insideNearestRightEdge
;
128 // The set of items that were selected at the time this band was shown.
129 // NOTE: Unless CTRL was pressed when the band was created, this is always empty.
130 QItemSelection originalSelection
;