]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSelectionManager.h
Rationalize the handling of makeTextClass().
[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 <QStringListModel>
21 #include <QListView>
22 #include <QPushButton>
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                 QStringListModel * availableModel,
49                 QStringListModel * 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         void update();
54         
55         /// Not strictly a matter of focus, which may be elsewhere, but
56         /// whether selectedLV is `more focused' than availableLV. Intended
57         /// to be used, for example, in displaying information about a
58         /// highlighted item: should it be the highlighted available item
59         /// or the highlighted selected item that is displayed?
60         bool selectedFocused() { return selectedHasFocus_; };
61
62 Q_SIGNALS:
63         ///Emitted when the list of selected items has changed. 
64         void selectionChanged();
65         ///Emitted when something has changed that might lead the containing 
66         ///dialog to want to update---the focused subwidget or selected item.
67         ///(Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
68         ///NOTE: No automatic update of the button state is done here. If you
69         ///just want to do that, connect updateHook() to updateView(). Much of the
70         ///time, though, you will want to do a bit more processing first, so
71         ///you can connect to some other function that itself calls updateView().
72         void updateHook();
73         ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected 
74         ///to an "OK" event in the parent dialog.
75         void okHook();
76
77
78 protected:
79         ///Given a QModelIndex from availableLV, determines whether it has
80         ///been selected (i.e., is also in selectedLV).
81         bool isSelected(const QModelIndex & idx);
82
83 protected Q_SLOTS:
84         ///
85         void availableChanged(const QModelIndex & idx, const QModelIndex &);
86         ///
87         void selectedChanged(const QModelIndex & idx, const QModelIndex &);
88         ///
89         void addPB_clicked();
90         ///
91         void deletePB_clicked();
92         ///
93         void upPB_clicked();
94         ///
95         void downPB_clicked();
96         ///
97         void availableLV_clicked(const QModelIndex &);
98         ///
99         void availableLV_doubleClicked(const QModelIndex &);
100         ///
101         void selectedLV_clicked(const QModelIndex &);
102         ///
103         bool eventFilter(QObject *, QEvent *);
104
105 private:
106         QListView * availableLV;
107         QListView * selectedLV;
108         QPushButton * addPB;
109         QPushButton * deletePB; 
110         QPushButton * upPB;
111         QPushButton * downPB;
112         QStringListModel * availableModel;
113         QStringListModel * selectedModel;
114         //Dialog::View * dialog;
115         
116         bool selectedHasFocus_;
117 };
118
119 } // namespace frontend
120 } // namespace lyx
121
122 #endif  // GUISELECTIONMANAGER