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