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