1 // -*- C++ -*-
2 /**
3  * \file ButtonController.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Allan Rae
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11 
12 #ifndef BUTTONCONTROLLER_H
13 #define BUTTONCONTROLLER_H
14 
15 #include "ButtonPolicy.h"
16 
17 class QWidget;
18 class QPushButton;
19 class QLineEdit;
20 class QCheckBox;
21 
22 namespace lyx {
23 namespace frontend {
24 
25 /** General purpose button controller for up to four buttons.
26     Controls the activation of the OK, Apply and Cancel buttons.
27     Actually supports 4 buttons in all and it's up to the user to decide on
28     the activation policy and which buttons correspond to which output of the
29     state machine.
30 */
31 
32 
33 /** \c ButtonController controls the activation of the OK, Apply and
34  *  Cancel buttons.
35  *
36  * It actually supports 4 buttons in all and it's up to the user to decide on
37  * the activation policy and which buttons correspond to which output of the
38  * state machine.
39  */
40 
41 class ButtonController
42 {
43 public:
44 	ButtonController();
45 	~ButtonController();
46 
47 	//@{
48 	/// Methods to set and get the ButtonPolicy.
49 	void setPolicy(ButtonPolicy::Policy policy);
50 	ButtonPolicy const & policy() const;
51 	ButtonPolicy & policy();
52 	//@}
53 
54 	///
55 	void input(ButtonPolicy::SMInput);
56 
57 	//@{
58 	/// Tell the BC that a particular button has been pressed.
59 	void ok();
60 	void apply();
61 	void cancel();
62 	void restore();
63 	void autoApply();
64 	//@}
65 
66 	/// Tell the BC that the dialog is being hidden
67 	void hide();
68 
69 	/**Refresh the activation state of the Ok, Apply, Close and
70 	 * Restore buttons.
71 	 */
72 	void refresh() const;
73 
74 	/** Refresh the activation state of all the widgets under the control
75 	 *  of the BC to reflect the read-only status of the underlying buffer.
76 	 */
77 	void refreshReadOnly() const;
78 
79 	/** Passthrough function -- returns its input value
80 	 *  Tell the BC about the read-only status of the underlying buffer.
81 	 */
82 	bool setReadOnly(bool);
83 
84 	/**
85 	 *  Sets the activation state of the buttons immediately.
86 	 * \param validity Tell the BC that the data is, or is not, valid.
87 	 */
88 	void setValid(bool);
89 
90 	//
91 	// View
92 	//
93 
94 	//@{
95 	/// Store pointers to these widgets.
96 	void setOK(QPushButton * obj);
97 	void setApply(QPushButton * obj);
98 	void setCancel(QPushButton * obj);
99 	void setRestore(QPushButton * obj);
100 	void setAutoApply(QCheckBox * obj);
101 	//@}
102 
103 	/** Add a pointer to the list of widgets whose activation
104 	 *  state is dependent upon the read-only status of the
105 	 *  underlying buffer.
106 	 */
107 	void addReadOnly(QWidget * obj);
108 
109 	/** Add a widget to the list of all widgets whose validity should
110 	 *  be checked explicitly when the buttons are refreshed.
111 	 */
112 	void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
113 
114 private:
115 	/// noncopyable
116 	ButtonController(ButtonController const &);
117 	void operator=(ButtonController const &);
118 
119 	/// pimpl
120 	class Private;
121 	Private * d;
122 };
123 
124 } // namespace frontend
125 } // namespace lyx
126 
127 #endif // BUTTONCONTROLLER_H
128