]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSelectionManager.h
Typos.
[lyx.git] / src / frontends / qt4 / GuiSelectionManager.h
1 /**
2  * \file GuiSelectionManager.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Richard Heck
7  * \author Et Alia
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUISELECTIONMANAGER_H
13 #define GUISELECTIONMANAGER_H
14
15 #include <QObject>
16
17 class QAbstractListModel;
18 class QModelIndex;
19 class QListView;
20 class QPushButton;
21 class QVariant;
22 template <class T, class U> class QMap;
23
24 namespace lyx {
25 namespace frontend {
26
27 /** Class to manage a collection of widgets that allows selection
28  *  of items from a list of available items. Adapted from code originally
29  *  written for GuiCitationDialog. 
30  *  Note that this is a not a QWidget, though it could be converted to
31  *  one. Rather, the managed widgets---see constructor for descripton 
32  *  of them---should be created independently, and then passed to the
33  *  constructor.
34  */
35 class GuiSelectionManager : public QObject
36 {
37         Q_OBJECT
38
39 public:
40         ///
41         GuiSelectionManager(
42                 QListView * availableLV, 
43                 QListView * selectedLV,
44                 QPushButton * addPB, 
45                 QPushButton * delPB, 
46                 QPushButton * upPB, 
47                 QPushButton * downPB,
48                 QAbstractListModel * availableModel,
49                 QAbstractListModel * selectedModel);
50         /// Sets the state of the various push buttons, depending upon the
51         /// state of the widgets. (E.g., "delete" is enabled only if the
52         /// selection is non-empty.)
53         /// Note: this is separated out into updateAddPB(), etc, below, 
54         /// for easy over-riding of these functions.
55         void update();
56         
57         /// Not strictly a matter of focus, which may be elsewhere, but
58         /// whether selectedLV is `more focused' than availableLV. Intended
59         /// to be used, for example, in displaying information about a
60         /// highlighted item: should it be the highlighted available item
61         /// or the highlighted selected item that is displayed?
62         bool selectedFocused() { return selectedHasFocus_; };
63
64 Q_SIGNALS:
65         /// Emitted when the list of selected items has changed. 
66         void selectionChanged();
67         /// Emitted when something has changed that might lead the containing 
68         /// dialog to want to update---the focused subwidget or selected item.
69         /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
70         /// NOTE: No automatic update of the button state is done here. If you
71         /// just want to do that, connect updateHook() to updateView(). Much of the
72         /// time, though, you will want to do a bit more processing first, so
73         /// you can connect to some other function that itself calls updateView().
74         void updateHook();
75         /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected 
76         /// to an "OK" event in the parent dialog.
77         void okHook();
78
79
80 protected:
81         /// Given a QModelIndex from availableLV, determines whether it has
82         /// been selected (i.e., is also in selectedLV).
83         bool isSelected(const QModelIndex & idx);
84         ///
85         bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
86         ///
87         QListView * availableLV;
88         ///
89         QListView * selectedLV;
90         ///
91         QPushButton * addPB;
92         ///
93         QPushButton * deletePB; 
94         ///
95         QPushButton * upPB;
96         ///
97         QPushButton * downPB;
98         ///
99         QAbstractListModel * availableModel;
100         ///
101         QAbstractListModel * selectedModel;
102
103 protected Q_SLOTS:
104         ///
105         void availableChanged(const QModelIndex & idx, const QModelIndex &);
106         ///
107         void selectedChanged(const QModelIndex & idx, const QModelIndex &);
108         ///
109         virtual void addPB_clicked();
110         ///
111         virtual void deletePB_clicked();
112         ///
113         virtual void upPB_clicked();
114         ///
115         virtual void downPB_clicked();
116         ///
117         void availableLV_clicked(const QModelIndex &);
118         ///
119         void availableLV_doubleClicked(const QModelIndex &);
120         ///
121         void selectedLV_clicked(const QModelIndex &);
122         ///
123         bool eventFilter(QObject *, QEvent *);
124
125 private:
126         ///
127         virtual void updateAddPB();
128         ///
129         virtual void updateDelPB();
130         ///
131         virtual void updateDownPB();
132         ///
133         virtual void updateUpPB();
134         ///
135         bool selectedHasFocus_;
136 };
137
138 } // namespace frontend
139 } // namespace lyx
140
141 #endif  // GUISELECTIONMANAGER