1
/**************************************************************************
3
* Copyright 2014 Canonical Ltd.
4
* Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* File: dirselection.h
22
#ifndef DIRSELECTION_H
23
#define DIRSELECTION_H
25
#include "diriteminfo.h"
28
#include <QStringList>
31
class DirItemAbstractListModel;
33
class DirSelection : public QObject
37
explicit DirSelection(DirItemAbstractListModel *parent, DirItemInfoList *listItems);
38
explicit DirSelection(QObject *parent = 0);
41
void selectRange(int indexClicked);
44
void toggleIndex(int index);
45
void setIndex(int index, bool selected);
46
void setMultiSelection(bool enable);
55
Q_PROPERTY(int counter READ counter NOTIFY selectionChanged)
56
Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged)
57
Q_INVOKABLE QStringList selectedNames() const;
58
Q_INVOKABLE void setMode(Mode m);
59
Q_INVOKABLE QStringList selectedAbsFilePaths() const; //full path
60
Q_INVOKABLE QList<int> selectedIndexes() const;
66
* It allows to pass Control Modifiers directly to perform the most common selection behaviour.
69
* \li 1 When selecting an item with Shit key pressed it selects the rage calling \ref selectRange()
70
* \li 2 When selecting an item with Crtl key pressed it temporarily forces Multi Selection Mode
71
* calling \ref toggleIndex() instead of \ref setIndex();
73
* \param range when true it calls \ref selectRange() and does not consider the \a multiSelection parameter
75
* \param multiSelection when \a false it respects the current selection mode: calls \ref setIndex()
76
* for \ref Single selection mode or \ref toggleIndex() for \ref Multi selection mode.
77
* When \a true it calls \ref toggleIndex()
81
* property FolderListSelection selectionManager: pageModel.selectionObject()
85
* anchors.fill: parent
87
* selectionManager.select(model.index,
88
* (mouse.modifiers & Qt.ShiftModifier),
89
* (mouse.modifiers & Qt.ControlModifier) );
95
Q_INVOKABLE void select(int index, bool range, bool multiSelection );
98
void itemGoingToBeRemoved(const DirItemInfo& item);
99
void itemGoingToBeReplaced(const DirItemInfo& oldItemInfo, const DirItemInfo& newItemInfo);
103
void notifyChanges();
104
bool priv_setIndex(int index, bool selected);
107
void selectionChanged(int);
108
void modeChanged(int);
111
int m_selectedCounter;
112
DirItemAbstractListModel* m_model;
113
DirItemInfoList * m_listItems;
115
int m_lastSelectedItem;
118
#endif // DIRSELECTION_H