]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQDialog.h
126046488e83e28e0d5b9d72df0ac87463b86b34
[duncan/yast2-qt4.git] / src / YQDialog.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQDialog.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQDialog_h
21 #define YQDialog_h
22
23 #include <Qt3Support/q3frame.h>
24 #include <qevent.h>
25 #include <qwidget.h>
26 #include "YDialog.h"
27
28
29 class YQGenericButton;
30 class YQWizard;
31 class Q3Frame;
32
33
34 class YQDialog : public QWidget, public YDialog
35 {
36     Q_OBJECT
37
38 public:
39     /**
40      * Constructor: Constructor.
41      **/
42     YQDialog( const YWidgetOpt &        opt,
43               QWidget *                 qt_parent       = 0,
44               bool                      default_size    = false );
45
46     /**
47      * Destructor: Cleans up.
48      **/
49     ~YQDialog();
50
51     /**
52      * Makes this dialog         active or inactive
53      **/
54     void activate( bool active );
55
56     /**
57      * Interited from QDialog: The window was closed via the window
58      * manager close button.
59      **/
60     void closeEvent( QCloseEvent * ev );
61
62     /**
63      * Set enabled/disabled state.
64      *
65      * Reimplemented from YWidget.
66      **/
67     virtual void setEnabled( bool enabled );
68
69     /**
70      * Preferred width of the widget.
71      *
72      * Reimplemented from YWidget.
73      **/
74     virtual int preferredWidth();
75
76     /**
77      * Preferred height of the widget.
78      *
79      * Reimplemented from YWidget.
80      **/
81     virtual int preferredHeight();
82
83     /**
84      * Set the new size of the widget.
85      *
86      * Reimplemented from YWidget.
87      **/
88     virtual void setSize( int newWidth, int newHeight );
89
90     /**
91      * Returns the size of (artificial) window manager decorations, depending
92      * on the value of YDialog::isDecorated().
93      **/
94     int decorationWidth();
95
96     /**
97      * Return this dialog's (first) default button or 0 if none
98      **/
99     YQGenericButton * findDefaultButton();
100
101     /**
102      * Returns whether or not the user has resized this dialog.
103      **/
104     bool userResized() { return _userResized; }
105
106     /**
107      * Returns the button that has the keyboard focus or 0 if no button has
108      * the keyboard focus.
109      **/
110     YQGenericButton * focusButton() const { return _focusButton; }
111
112     /**
113      * Returns the dialog's default button - the button that is activated with
114      * [Return] if no button has the keyboard focus.
115      **/
116     YQGenericButton * defaultButton() const { return _defaultButton; }
117
118     /**
119      * Notification that a button loses the keyboard focus.
120      *
121      * All pushbuttons are required to call this whenever they lose focus so
122      * the dialog can keep track of its focusButton.
123      **/
124     void losingFocus( YQGenericButton * button );
125
126     /**
127      * Notification that a button gets the keyboard focus.
128      *
129      * All pushbuttons are required to call this whenever they gain focus so
130      * the dialog can keep track of its focusButton.
131      **/
132     void gettingFocus( YQGenericButton * button );
133
134     /**
135      * Set the dialog's default button - the button that is activated with
136      * [Return] if no other button has the keyboard focus.
137      * 'newDefaultButton' may be 0 if the former default button is destroyed.
138      **/
139     void setDefaultButton( YQGenericButton * newDefaultButton );
140
141     /**
142      * Ensure presence of no more than one single default button.
143      **/
144     void ensureOnlyOneDefaultButton();
145
146     /**
147      * Activate ( i.e. click ) this dialog's default button, if there is any.
148      * Issue a warning to the log file if 'warn' is true.
149      **/
150     bool activateDefaultButton( bool warn = true );
151
152     /**
153      * Find the first wizard in that dialog, if there is any.
154      * Returns 0 if there is none.
155      **/
156     YQWizard * findWizard() const;
157
158     /**
159      * Find a wizard button that would make sense as a default button.
160      * Return 0 if none can be found.
161      **/
162     YQGenericButton * wizardDefaultButton( YQWizard * wizard ) const;
163
164     /**
165      * Center a dialog relative to 'parent'.
166      *
167      * If 'parent' is 0, the dialog is centered relative to the application's
168      * main widget. If 'dialog' is the main widget and 'parent' is 0, the
169      * dialog is centered relative to the desktop.
170      **/
171     static void center( QWidget * dialog, QWidget * parent = 0 );
172
173
174 protected:
175
176     /**
177      * Return the (first) default button between 'begin' and 'end'
178      * or 0 if there is none.
179      **/
180     YQGenericButton * findDefaultButton( YWidgetListConstIterator begin,
181                                          YWidgetListConstIterator end ) const;
182
183     /**
184      * Return the (first) wizard widget between 'begin' and 'end'
185      * or 0 if there is none.
186      **/
187     YQWizard * findWizard( YWidgetListConstIterator begin,
188                            YWidgetListConstIterator end ) const;
189
190     /**
191      * Helper function for ensureOnlyOneDefaultButton():
192      * Recursively find all normal and wizard buttons between 'begin' and 'end'
193      * and make sure that no more than one button is marked as default.
194      * Return (the first) wizard widget found on the way.
195      **/
196     YQWizard * ensureOnlyOneDefaultButton( YWidgetListConstIterator begin,
197                                            YWidgetListConstIterator end );
198
199     /**
200      * Event handler for keyboard input.
201      * Only very special keys are processed here.
202      *
203      * Inherited from QWidget.
204      **/
205     void keyPressEvent( QKeyEvent * e );
206
207
208     /**
209      * Event handler for focusIn event.
210      *
211      * Inherited from QWidget.
212      **/
213     void focusInEvent( QFocusEvent * event );
214
215     /**
216      * Event handler for window resize.
217      *
218      * Inherited from QWidget.
219      **/
220     void resizeEvent ( QResizeEvent * ev );
221
222
223     /**
224      * Inherited from QWidget: Called when the dialog is shown.
225      **/
226     void show();
227
228
229     //
230     // Data members
231     //
232
233     Q3Frame *           _qFrame;
234
235     bool                _userResized;
236     QSize               _userSize;
237
238     YQGenericButton *   _focusButton;
239     YQGenericButton *   _defaultButton;
240 };
241
242
243 #endif // YQDialog_h
244