2 * \file GuiSelectionManager.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef GUISELECTIONMANAGER_H
13 #define GUISELECTIONMANAGER_H
19 #include <QStringList>
20 #include <QAbstractListModel>
22 #include <QPushButton>
24 #include "support/qstring_helpers.h"
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
39 class GuiSelectionManager : public QObject
46 QListView * availableLV,
47 QListView * selectedLV,
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.
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_; };
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().
79 ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected
80 ///to an "OK" event in the parent dialog.
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);
89 bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
91 QListView * availableLV;
93 QListView * selectedLV;
97 QPushButton * deletePB;
101 QPushButton * downPB;
103 QAbstractListModel * availableModel;
105 QAbstractListModel * selectedModel;
109 void availableChanged(const QModelIndex & idx, const QModelIndex &);
111 void selectedChanged(const QModelIndex & idx, const QModelIndex &);
113 virtual void addPB_clicked();
115 virtual void deletePB_clicked();
117 virtual void upPB_clicked();
119 virtual void downPB_clicked();
121 void availableLV_clicked(const QModelIndex &);
123 void availableLV_doubleClicked(const QModelIndex &);
125 void selectedLV_clicked(const QModelIndex &);
127 bool eventFilter(QObject *, QEvent *);
131 virtual void updateAddPB();
133 virtual void updateDelPB();
135 virtual void updateDownPB();
137 virtual void updateUpPB();
139 bool selectedHasFocus_;
142 } // namespace frontend
145 #endif // GUISELECTIONMANAGER