libyui-qt  2.47.1.1
YQDialog.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQDialog.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQDialog_h
27 #define YQDialog_h
28 
29 #include <QFrame>
30 #include <QEvent>
31 #include <QWidget>
32 #include <QPalette>
33 #include <yui/YDialog.h>
34 
35 class YQGenericButton;
36 class YQWizard;
37 class QEventLoop;
38 class QTimer;
39 class QY2StyleEditor;
40 
41 
42 class YQDialog : public QWidget, public YDialog
43 {
44  Q_OBJECT
45 
46 public:
47  /**
48  * Constructor.
49  *
50  * 'dialogType' is one of YMainDialog, YWizardDialog, or YPopupDialog.
51  *
52  * The Qt UI supports YWizardDialogs. They are handled very much like
53  * YMainDialogs, except for wizard dialogs that are opened over a wizard
54  * with a steps panel on the left side, in which case that new wizard
55  * dialog will be resized and moved so the steps panel from the wizard
56  * below will remain visible.
57  *
58  * 'colorMode' can be set to YDialogWarnColor to use very bright "warning"
59  * colors or YDialogInfoColor to use more prominent, yet not quite as
60  * bright as "warning" colors. Use both only very rarely.
61  **/
62  YQDialog( YDialogType dialogType,
63  YDialogColorMode colorMode = YDialogNormalColor );
64 
65 protected:
66 
67  /**
68  * Destructor.
69  * Don't delete a dialog directly, use YDialog::deleteTopmostDialog().
70  **/
71  virtual ~YQDialog();
72 
73 public:
74  /**
75  * Interited from QDialog: The window was closed via the window
76  * manager close button.
77  **/
78  void closeEvent( QCloseEvent * ev );
79 
80  /**
81  * Set enabled/disabled state.
82  *
83  * Reimplemented from YWidget.
84  **/
85  virtual void setEnabled( bool enabled );
86 
87  /**
88  * Preferred width of the widget.
89  *
90  * Reimplemented from YWidget.
91  **/
92  virtual int preferredWidth();
93 
94  /**
95  * Preferred height of the widget.
96  *
97  * Reimplemented from YWidget.
98  **/
99  virtual int preferredHeight();
100 
101  /**
102  * Set the new size of the widget.
103  *
104  * Reimplemented from YWidget.
105  **/
106  virtual void setSize( int newWidth, int newHeight );
107 
108  /**
109  * Return this dialog's (first) default button or 0 if none
110  **/
112 
113  /**
114  * Return 'true' if the user resized this dialog.
115  **/
116  bool userResized() { return _userResized; }
117 
118  /**
119  * Returns the button that has the keyboard focus or 0 if no button has
120  * the keyboard focus.
121  **/
122  YQGenericButton * focusButton() const { return _focusButton; }
123 
124  /**
125  * Returns the dialog's default button - the button that is activated with
126  * [Return] if no button has the keyboard focus.
127  **/
128  YQGenericButton * defaultButton() const { return _defaultButton; }
129 
130  /**
131  * Notification that a button loses the keyboard focus.
132  *
133  * All pushbuttons are required to call this whenever they lose focus so
134  * the dialog can keep track of its focusButton.
135  **/
136  void losingFocus( YQGenericButton * button );
137 
138  /**
139  * Notification that a button gets the keyboard focus.
140  *
141  * All pushbuttons are required to call this whenever they gain focus so
142  * the dialog can keep track of its focusButton.
143  **/
144  void gettingFocus( YQGenericButton * button );
145 
146  /**
147  * Set the dialog's default button - the button that is activated with
148  * [Return] if no other button has the keyboard focus.
149  * 'newDefaultButton' may be 0 if the former default button is destroyed.
150  **/
151  void setDefaultButton( YPushButton * newDefaultButton );
152 
153  /**
154  * Ensure presence of no more than one single default button.
155  **/
157 
158  /**
159  * Activate (i.e. click) this dialog's default button, if there is any.
160  * Issue a warning to the log file if 'warn' is true.
161  **/
162  bool activateDefaultButton( bool warn = true );
163 
164  /**
165  * Find the first wizard in that dialog, if there is any.
166  * Returns 0 if there is none.
167  **/
168  YQWizard * findWizard() const;
169 
170  /**
171  * Find a wizard button that would make sense as a default button.
172  * Return 0 if none can be found.
173  **/
174  YQGenericButton * wizardDefaultButton( YQWizard * wizard ) const;
175 
176  /**
177  * Highlight a child widget of this dialog. This is meant for debugging:
178  * YDialogSpy and similar uses.
179  *
180  * No more than one widget can be highlighted at any one time in the same
181  * dialog. Highlighting another widget un-highlights a previously
182  * highlighted widget. 0 means 'unhighlight the last highlighted widget,
183  * but don't highlight any other'.
184  *
185  * Implemented from YDialog.
186  **/
187  virtual void highlight( YWidget * child );
188 
189  /**
190  * Center a dialog relative to 'parent'.
191  *
192  * If 'parent' is 0, the dialog is centered relative to the application's
193  * main widget. If 'dialog' is the main widget and 'parent' is 0, the
194  * dialog is centered relative to the desktop.
195  **/
196  static void center( QWidget * dialog, QWidget * parent = 0 );
197 
198  /**
199  * Access to this dialog's event loop.
200  **/
201  QEventLoop * eventLoop() { return _eventLoop; }
202 
203 
204 protected slots:
205 
206  /**
207  * Timeout during waitForEvent()
208  **/
209  void waitForEventTimeout();
210 
211 
212 protected:
213 
214  /**
215  * Choose a parent widget for a dialog of the specified type:
216  * Either the main window dock (if this is a YMainDialog and the dock
217  * currently accepts child dialogs) or 0.
218  **/
219  static QWidget * chooseParent( YDialogType dialogType );
220 
221  /**
222  * Return the (first) default button between 'begin' and 'end'
223  * or 0 if there is none.
224  **/
225  YQGenericButton * findDefaultButton( YWidgetListConstIterator begin,
226  YWidgetListConstIterator end ) const;
227 
228  /**
229  * Return the (first) wizard widget between 'begin' and 'end'
230  * or 0 if there is none.
231  **/
232  YQWizard * findWizard( YWidgetListConstIterator begin,
233  YWidgetListConstIterator end ) const;
234 
235  /**
236  * Helper function for ensureOnlyOneDefaultButton():
237  * Recursively find all normal and wizard buttons between 'begin' and 'end'
238  * and make sure that no more than one button is marked as default.
239  * Return (the first) wizard widget found on the way.
240  **/
241  YQWizard * ensureOnlyOneDefaultButton( YWidgetListConstIterator begin,
242  YWidgetListConstIterator end );
243 
244  /**
245  * Internal open() method, called exactly once during the life
246  * time of the dialog in open().
247  *
248  * Implemented from YDialog.
249  **/
250  virtual void openInternal();
251 
252  /**
253  * Wait for a user event.
254  *
255  * Implemented from YDialog.
256  **/
257  virtual YEvent * waitForEventInternal( int timeout_millisec );
258 
259  /**
260  * Check if a user event is pending. If there is one, return it.
261  * If there is none, do not wait for one - return 0.
262  *
263  * Implemented from YDialog.
264  **/
265  virtual YEvent * pollEventInternal();
266 
267  /**
268  * Activate this dialog: Make sure that it is shown as the topmost dialog
269  * of this application and that it can receive input.
270  *
271  * Implemented from YDialog.
272  **/
273  virtual void activate();
274 
275  /**
276  * Qt event handlers.
277  *
278  * All reimplemented from QWidget.
279  **/
280  virtual void keyPressEvent ( QKeyEvent * event );
281  virtual void focusInEvent ( QFocusEvent * event );
282  virtual void resizeEvent ( QResizeEvent * event );
283 
284 
285  //
286  // Data members
287  //
288 
289  bool _userResized;
290  QSize _userSize;
291 
292  YQGenericButton * _focusButton;
293  YQGenericButton * _defaultButton;
294 
295  QTimer * _waitForEventTimer;
296  QEventLoop * _eventLoop;
297  YWidget * _highlightedChild;
298  QPalette _preHighlightPalette;
299  bool _preHighlightAutoFill;
300  QY2StyleEditor* _styleEditor;
301 
302 };
303 
304 
305 #endif // YQDialog_h
306 
YQGenericButton * findDefaultButton()
Return this dialog&#39;s (first) default button or 0 if none.
Definition: YQDialog.cc:298
Stylesheet Editor Dialog.
virtual void highlight(YWidget *child)
Highlight a child widget of this dialog.
Definition: YQDialog.cc:855
virtual void keyPressEvent(QKeyEvent *event)
Qt event handlers.
Definition: YQDialog.cc:606
YQWizard * findWizard() const
Find the first wizard in that dialog, if there is any.
Definition: YQDialog.cc:426
virtual ~YQDialog()
Destructor.
Definition: YQDialog.cc:126
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQDialog.cc:192
virtual YEvent * waitForEventInternal(int timeout_millisec)
Wait for a user event.
Definition: YQDialog.cc:755
static void center(QWidget *dialog, QWidget *parent=0)
Center a dialog relative to &#39;parent&#39;.
Definition: YQDialog.cc:839
QEventLoop * eventLoop()
Access to this dialog&#39;s event loop.
Definition: YQDialog.h:201
virtual void activate()
Activate this dialog: Make sure that it is shown as the topmost dialog of this application and that i...
Definition: YQDialog.cc:184
YQGenericButton * defaultButton() const
Returns the dialog&#39;s default button - the button that is activated with [Return] if no button has the...
Definition: YQDialog.h:128
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQDialog.cc:254
void gettingFocus(YQGenericButton *button)
Notification that a button gets the keyboard focus.
Definition: YQDialog.cc:590
void setDefaultButton(YPushButton *newDefaultButton)
Set the dialog&#39;s default button - the button that is activated with [Return] if no other button has t...
Definition: YQDialog.cc:495
Abstract base class for push button and similar widgets - all that can become a YQDialog&#39;s "default b...
virtual void openInternal()
Internal open() method, called exactly once during the life time of the dialog in open()...
Definition: YQDialog.cc:174
bool userResized()
Return &#39;true&#39; if the user resized this dialog.
Definition: YQDialog.h:116
YQDialog(YDialogType dialogType, YDialogColorMode colorMode=YDialogNormalColor)
Constructor.
Definition: YQDialog.cc:60
bool activateDefaultButton(bool warn=true)
Activate (i.e.
Definition: YQDialog.cc:535
static QWidget * chooseParent(YDialogType dialogType)
Choose a parent widget for a dialog of the specified type: Either the main window dock (if this is a ...
Definition: YQDialog.cc:151
void losingFocus(YQGenericButton *button)
Notification that a button loses the keyboard focus.
Definition: YQDialog.cc:574
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQDialog.cc:262
YQGenericButton * wizardDefaultButton(YQWizard *wizard) const
Find a wizard button that would make sense as a default button.
Definition: YQDialog.cc:458
virtual YEvent * pollEventInternal()
Check if a user event is pending.
Definition: YQDialog.cc:805
void ensureOnlyOneDefaultButton()
Ensure presence of no more than one single default button.
Definition: YQDialog.cc:401
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQDialog.cc:223
YQGenericButton * focusButton() const
Returns the button that has the keyboard focus or 0 if no button has the keyboard focus...
Definition: YQDialog.h:122
void closeEvent(QCloseEvent *ev)
Interited from QDialog: The window was closed via the window manager close button.
Definition: YQDialog.cc:720
void waitForEventTimeout()
Timeout during waitForEvent()
Definition: YQDialog.cc:825