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