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