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