]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSelectionManager.h
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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 "Dialog.h"
16
17 #include <QObject>
18 #include <QKeyEvent>
19 #include <QStringList>
20 #include <QAbstractListModel>
21 #include <QListView>
22 #include <QPushButton>
23
24 #include "support/qstring_helpers.h"
25
26 #include <vector>
27
28 namespace lyx {
29 namespace frontend {
30
31 /** Class to manage a collection of widgets that allows selection
32  *  of items from a list of available items. Adapted from code originally
33  *  written for GuiCitationDialog. 
34  *  Note that this is a not a QWidget, though it could be converted to
35  *  one. Rather, the managed widgets---see constructor for descripton 
36  *  of them---should be created independently, and then passed to the
37  *  constructor.
38  */
39 class GuiSelectionManager : public QObject
40 {
41 Q_OBJECT
42
43 public:
44         ///
45         GuiSelectionManager(
46                 QListView * availableLV, 
47                 QListView * selectedLV,
48                 QPushButton * addPB, 
49                 QPushButton * delPB, 
50                 QPushButton * upPB, 
51                 QPushButton * downPB,
52                 QAbstractListModel * availableModel,
53                 QAbstractListModel * selectedModel);
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() { return selectedHasFocus_; };
67
68 Q_SIGNALS:
69         ///Emitted when the list of selected items has changed. 
70         void selectionChanged();
71         ///Emitted when something has changed that might lead the containing 
72         ///dialog to want to update---the focused subwidget or selected item.
73         ///(Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
74         ///NOTE: No automatic update of the button state is done here. If you
75         ///just want to do that, connect updateHook() to updateView(). Much of the
76         ///time, though, you will want to do a bit more processing first, so
77         ///you can connect to some other function that itself calls updateView().
78         void updateHook();
79         ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected 
80         ///to an "OK" event in the parent dialog.
81         void okHook();
82
83
84 protected:
85         ///Given a QModelIndex from availableLV, determines whether it has
86         ///been selected (i.e., is also in selectedLV).
87         bool isSelected(const QModelIndex & idx);
88         ///
89         bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
90         ///
91         QListView * availableLV;
92         ///
93         QListView * selectedLV;
94         ///
95         QPushButton * addPB;
96         ///
97         QPushButton * deletePB; 
98         ///
99         QPushButton * upPB;
100         ///
101         QPushButton * downPB;
102         ///
103         QAbstractListModel * availableModel;
104         ///
105         QAbstractListModel * selectedModel;
106
107 protected Q_SLOTS:
108         ///
109         void availableChanged(const QModelIndex & idx, const QModelIndex &);
110         ///
111         void selectedChanged(const QModelIndex & idx, const QModelIndex &);
112         ///
113         virtual void addPB_clicked();
114         ///
115         virtual void deletePB_clicked();
116         ///
117         virtual void upPB_clicked();
118         ///
119         virtual void downPB_clicked();
120         ///
121         void availableLV_clicked(const QModelIndex &);
122         ///
123         void availableLV_doubleClicked(const QModelIndex &);
124         ///
125         void selectedLV_clicked(const QModelIndex &);
126         ///
127         bool eventFilter(QObject *, QEvent *);
128
129 private:
130         ///
131         virtual void updateAddPB();
132         ///
133         virtual void updateDelPB();
134         ///
135         virtual void updateDownPB();
136         ///
137         virtual void updateUpPB();
138         ///
139         bool selectedHasFocus_;
140 };
141
142 } // namespace frontend
143 } // namespace lyx
144
145 #endif  // GUISELECTIONMANAGER