1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
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. *
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. *
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 ***************************************************************************/
23 #ifndef KITEMLISTSELECTIONMANAGER_H
24 #define KITEMLISTSELECTIONMANAGER_H
26 #include <libdolphin_export.h>
28 #include <kitemviews/kitemmodelbase.h>
36 * @brief Allows to select and deselect items of a KItemListView.
38 class LIBDOLPHINPRIVATE_EXPORT KItemListSelectionManager
: public QObject
49 KItemListSelectionManager(QObject
* parent
= 0);
50 virtual ~KItemListSelectionManager();
52 void setCurrentItem(int current
);
53 int currentItem() const;
55 void setSelectedItems(const QSet
<int>& items
);
56 QSet
<int> selectedItems() const;
57 bool isSelected(int index
) const;
58 bool hasSelection() const;
60 void setSelected(int index
, int count
= 1, SelectionMode mode
= Select
);
61 void clearSelection();
63 void beginAnchoredSelection(int anchor
);
64 void endAnchoredSelection();
65 bool isAnchoredSelectionActive() const;
67 KItemModelBase
* model() const;
70 void currentChanged(int current
, int previous
);
71 void selectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
);
74 void setModel(KItemModelBase
* model
);
75 void itemsInserted(const KItemRangeList
& itemRanges
);
76 void itemsRemoved(const KItemRangeList
& itemRanges
);
77 void itemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
81 * Helper method for itemsRemoved. Returns the changed index after removing
82 * the given range. If the index is part of the range, -1 will be returned.
84 int indexAfterRangesRemoving(int index
, const KItemRangeList
& itemRanges
) const;
89 QSet
<int> m_selectedItems
;
90 bool m_isAnchoredSelectionActive
;
92 KItemModelBase
* m_model
;
94 friend class KItemListController
; // Calls setModel()
95 friend class KItemListView
; // Calls itemsInserted() and itemsRemoved()
96 friend class KItemListSelectionManagerTest
;