]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistselectionmanager.h
Initial support for anchored selections in the selection manager
[dolphin.git] / src / kitemviews / kitemlistselectionmanager.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
22
23 #ifndef KITEMLISTSELECTIONMANAGER_H
24 #define KITEMLISTSELECTIONMANAGER_H
25
26 #include <libdolphin_export.h>
27
28 #include <kitemviews/kitemmodelbase.h>
29
30 #include <QObject>
31 #include <QSet>
32
33 class KItemModelBase;
34
35 /**
36 * @brief Allows to select and deselect items of a KItemListView.
37 */
38 class LIBDOLPHINPRIVATE_EXPORT KItemListSelectionManager : public QObject
39 {
40 Q_OBJECT
41
42 public:
43 enum SelectionMode {
44 Select,
45 Deselect,
46 Toggle
47 };
48
49 KItemListSelectionManager(QObject* parent = 0);
50 virtual ~KItemListSelectionManager();
51
52 void setCurrentItem(int current);
53 int currentItem() const;
54
55 void setSelectedItems(const QSet<int>& items);
56 QSet<int> selectedItems() const;
57 bool hasSelection() const;
58
59 void setSelected(int index, int count = 1, SelectionMode mode = Select);
60 void clearSelection();
61
62 void beginAnchoredSelection(int anchor, SelectionMode mode = Select);
63 void endAnchoredSelection();
64 void setAnchorItem(int anchor);
65 int anchorItem() const;
66
67 bool isAnchoredSelectionActive() const;
68 void setAnchoredSelectionActive(bool active);
69 SelectionMode anchoredSelectionMode() const;
70 void setAnchoredSelectionMode(SelectionMode mode);
71
72 KItemModelBase* model() const;
73
74 signals:
75 void currentChanged(int current, int previous);
76 void selectionChanged(const QSet<int>& current, const QSet<int>& previous);
77 void anchorChanged(int anchor, int previous);
78
79 private:
80 void setModel(KItemModelBase* model);
81 void itemsInserted(const KItemRangeList& itemRanges);
82 void itemsRemoved(const KItemRangeList& itemRanges);
83
84 private:
85 int m_currentItem;
86 int m_anchorItem;
87 QSet<int> m_selectedItems;
88 bool m_isAnchoredSelectionActive;
89 SelectionMode m_anchoredSelectionMode;
90
91 KItemModelBase* m_model;
92
93 friend class KItemListController; // Calls setModel()
94 friend class KItemListView; // Calls itemsInserted() and itemsRemoved()
95 friend class KItemListSelectionManagerTest;
96 };
97
98 #endif