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