~ubuntu-filemanager-dev/ubuntu-filemanager-app/trunk

« back to all changes in this revision

Viewing changes to src/plugin/folderlistmodel/dirselection.h

  • Committer: Bileto Bot
  • Date: 2017-04-04 17:06:41 UTC
  • mfrom: (588.1.19 fix-desktop-file)
  • Revision ID: ci-train-bot@canonical.com-20170404170641-1p15lmx8wodlx2ut
* Rename binary file to ubuntu-filemanager-app
* Join plugin packages into the main package 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 *
 
3
 * Copyright 2014 Canonical Ltd.
 
4
 * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 *
 
18
 * File: dirselection.h
 
19
 * Date: 29/01/2014
 
20
 */
 
21
 
 
22
#ifndef DIRSELECTION_H
 
23
#define DIRSELECTION_H
 
24
 
 
25
#include "diriteminfo.h"
 
26
 
 
27
#include <QObject>
 
28
#include <QStringList>
 
29
 
 
30
 
 
31
class DirItemAbstractListModel;
 
32
 
 
33
class DirSelection : public QObject
 
34
{
 
35
    Q_OBJECT
 
36
public:
 
37
    explicit DirSelection(DirItemAbstractListModel *parent,  DirItemInfoList *listItems);
 
38
    explicit DirSelection(QObject *parent = 0);
 
39
 
 
40
public slots:
 
41
        void        selectRange(int indexClicked);
 
42
        void        selectAll();
 
43
        void        clear();      
 
44
        void        toggleIndex(int index);     
 
45
        void        setIndex(int index, bool selected);
 
46
        void        setMultiSelection(bool enable);
 
47
 
 
48
public:
 
49
        Q_ENUMS(Mode)
 
50
        enum Mode
 
51
        {
 
52
            Single,
 
53
            Multi
 
54
        };
 
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;
 
61
        int                      counter()            const;
 
62
        Mode                     mode()               const;
 
63
 
 
64
public:
 
65
       /*!
 
66
        *   It allows to pass Control Modifiers directly to perform the  most common selection behaviour.
 
67
        *
 
68
        *   Usage Example:
 
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();
 
72
        *
 
73
        * \param range when true it calls \ref selectRange() and does not consider the \a multiSelection parameter
 
74
        *
 
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()
 
78
        *
 
79
        * QML example:
 
80
        *  \code
 
81
        *       property FolderListSelection selectionManager: pageModel.selectionObject()
 
82
        *       ...
 
83
        *
 
84
        *       MouseArea   {
 
85
        *           anchors.fill: parent
 
86
        *           onClicked: {
 
87
        *               selectionManager.select(model.index,
 
88
        *                                       (mouse.modifiers & Qt.ShiftModifier),
 
89
        *                                       (mouse.modifiers & Qt.ControlModifier) );
 
90
        *           }
 
91
        *       }
 
92
        *  \endcode
 
93
        *
 
94
        */
 
95
        Q_INVOKABLE  void        select(int index, bool range, bool multiSelection );
 
96
 
 
97
public:
 
98
        void        itemGoingToBeRemoved(const DirItemInfo& item);
 
99
        void        itemGoingToBeReplaced(const DirItemInfo& oldItemInfo, const DirItemInfo& newItemInfo);
 
100
 
 
101
private:      
 
102
        bool        priv_clear();
 
103
        void        notifyChanges();
 
104
        bool        priv_setIndex(int index, bool selected);
 
105
 
 
106
signals:
 
107
        void        selectionChanged(int);
 
108
        void        modeChanged(int);
 
109
 
 
110
private:
 
111
        int                        m_selectedCounter;
 
112
        DirItemAbstractListModel*  m_model;
 
113
        DirItemInfoList *          m_listItems;
 
114
        Mode                       m_mode;       
 
115
        int                        m_lastSelectedItem;
 
116
};
 
117
 
 
118
#endif // DIRSELECTION_H