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