libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQDialog.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:       YQDialog.h
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #ifndef YQDialog_h
00027 #define YQDialog_h
00028 
00029 #include <QFrame>
00030 #include <QEvent>
00031 #include <QWidget>
00032 #include <QPalette>
00033 #include <yui/YDialog.h>
00034 
00035 class YQGenericButton;
00036 class YQWizard;
00037 class QEventLoop;
00038 class QTimer;
00039 class QY2StyleEditor;
00040 
00041 
00042 class YQDialog : public QWidget, public YDialog
00043 {
00044     Q_OBJECT
00045 
00046 public:
00047     /**
00048      * Constructor.
00049      *
00050      * 'dialogType' is one of YMainDialog, YWizardDialog, or YPopupDialog.
00051      *
00052      * The Qt UI supports YWizardDialogs. They are handled very much like
00053      * YMainDialogs, except for wizard dialogs that are opened over a wizard
00054      * with a steps panel on the left side, in which case that new wizard
00055      * dialog will be resized and moved so the steps panel from the wizard
00056      * below will remain visible.
00057      *
00058      * 'colorMode' can be set to YDialogWarnColor to use very bright "warning"
00059      * colors or YDialogInfoColor to use more prominent, yet not quite as
00060      * bright as "warning" colors. Use both only very rarely.
00061      **/
00062     YQDialog( YDialogType       dialogType,
00063               YDialogColorMode  colorMode = YDialogNormalColor );
00064 
00065 protected:
00066 
00067     /**
00068      * Destructor.
00069      * Don't delete a dialog directly, use YDialog::deleteTopmostDialog().
00070      **/
00071     virtual ~YQDialog();
00072 
00073 public:
00074     /**
00075      * Interited from QDialog: The window was closed via the window
00076      * manager close button.
00077      **/
00078     void closeEvent( QCloseEvent * ev );
00079 
00080     /**
00081      * Set enabled/disabled state.
00082      *
00083      * Reimplemented from YWidget.
00084      **/
00085     virtual void setEnabled( bool enabled );
00086 
00087     /**
00088      * Preferred width of the widget.
00089      *
00090      * Reimplemented from YWidget.
00091      **/
00092     virtual int preferredWidth();
00093 
00094     /**
00095      * Preferred height of the widget.
00096      *
00097      * Reimplemented from YWidget.
00098      **/
00099     virtual int preferredHeight();
00100 
00101     /**
00102      * Set the new size of the widget.
00103      *
00104      * Reimplemented from YWidget.
00105      **/
00106     virtual void setSize( int newWidth, int newHeight );
00107 
00108     /**
00109      * Return this dialog's (first) default button or 0 if none
00110      **/
00111     YQGenericButton * findDefaultButton();
00112 
00113     /**
00114      * Return 'true' if the user resized this dialog.
00115      **/
00116     bool userResized() { return _userResized; }
00117 
00118     /**
00119      * Returns the button that has the keyboard focus or 0 if no button has
00120      * the keyboard focus.
00121      **/
00122     YQGenericButton * focusButton() const { return _focusButton; }
00123 
00124     /**
00125      * Returns the dialog's default button - the button that is activated with
00126      * [Return] if no button has the keyboard focus.
00127      **/
00128     YQGenericButton * defaultButton() const { return _defaultButton; }
00129 
00130     /**
00131      * Notification that a button loses the keyboard focus.
00132      *
00133      * All pushbuttons are required to call this whenever they lose focus so
00134      * the dialog can keep track of its focusButton.
00135      **/
00136     void losingFocus( YQGenericButton * button );
00137 
00138     /**
00139      * Notification that a button gets the keyboard focus.
00140      *
00141      * All pushbuttons are required to call this whenever they gain focus so
00142      * the dialog can keep track of its focusButton.
00143      **/
00144     void gettingFocus( YQGenericButton * button );
00145 
00146     /**
00147      * Set the dialog's default button - the button that is activated with
00148      * [Return] if no other button has the keyboard focus.
00149      * 'newDefaultButton' may be 0 if the former default button is destroyed.
00150      **/
00151     void setDefaultButton( YPushButton * newDefaultButton );
00152 
00153     /**
00154      * Ensure presence of no more than one single default button.
00155      **/
00156     void ensureOnlyOneDefaultButton();
00157 
00158     /**
00159      * Activate (i.e. click) this dialog's default button, if there is any.
00160      * Issue a warning to the log file if 'warn' is true.
00161      **/
00162     bool activateDefaultButton( bool warn = true );
00163 
00164     /**
00165      * Find the first wizard in that dialog, if there is any.
00166      * Returns 0 if there is none.
00167      **/
00168     YQWizard * findWizard() const;
00169 
00170     /**
00171      * Find a wizard button that would make sense as a default button.
00172      * Return 0 if none can be found.
00173      **/
00174     YQGenericButton * wizardDefaultButton( YQWizard * wizard ) const;
00175 
00176     /**
00177      * Highlight a child widget of this dialog. This is meant for debugging:
00178      * YDialogSpy and similar uses.
00179      *
00180      * No more than one widget can be highlighted at any one time in the same
00181      * dialog. Highlighting another widget un-highlights a previously
00182      * highlighted widget. 0 means 'unhighlight the last highlighted widget,
00183      * but don't highlight any other'.
00184      *
00185      * Implemented from YDialog.
00186      **/
00187     virtual void highlight( YWidget * child );
00188 
00189     /**
00190      * Center a dialog relative to 'parent'.
00191      *
00192      * If 'parent' is 0, the dialog is centered relative to the application's
00193      * main widget. If 'dialog' is the main widget and 'parent' is 0, the
00194      * dialog is centered relative to the desktop.
00195      **/
00196     static void center( QWidget * dialog, QWidget * parent = 0 );
00197 
00198     /**
00199      * Access to this dialog's event loop.
00200      **/
00201     QEventLoop * eventLoop() { return _eventLoop; }
00202 
00203 
00204 protected slots:
00205 
00206     /**
00207      * Timeout during waitForEvent()
00208      **/
00209     void waitForEventTimeout();
00210 
00211 
00212 protected:
00213 
00214     /**
00215      * Choose a parent widget for a dialog of the specified type:
00216      * Either the main window dock (if this is a YMainDialog and the dock
00217      * currently accepts child dialogs) or 0.
00218      **/
00219     static QWidget * chooseParent( YDialogType dialogType );
00220 
00221     /**
00222      * Return the (first) default button between 'begin' and 'end'
00223      * or 0 if there is none.
00224      **/
00225     YQGenericButton * findDefaultButton( YWidgetListConstIterator begin,
00226                                          YWidgetListConstIterator end ) const;
00227 
00228     /**
00229      * Return the (first) wizard widget between 'begin' and 'end'
00230      * or 0 if there is none.
00231      **/
00232     YQWizard * findWizard( YWidgetListConstIterator begin,
00233                            YWidgetListConstIterator end ) const;
00234 
00235     /**
00236      * Helper function for ensureOnlyOneDefaultButton():
00237      * Recursively find all normal and wizard buttons between 'begin' and 'end'
00238      * and make sure that no more than one button is marked as default.
00239      * Return (the first) wizard widget found on the way.
00240      **/
00241     YQWizard * ensureOnlyOneDefaultButton( YWidgetListConstIterator begin,
00242                                            YWidgetListConstIterator end );
00243 
00244     /**
00245      * Internal open() method, called exactly once during the life
00246      * time of the dialog in open().
00247      *
00248      * Implemented from YDialog.
00249      **/
00250     virtual void openInternal();
00251 
00252     /**
00253      * Wait for a user event.
00254      *
00255      * Implemented from YDialog.
00256      **/
00257     virtual YEvent * waitForEventInternal( int timeout_millisec );
00258 
00259     /**
00260      * Check if a user event is pending. If there is one, return it.
00261      * If there is none, do not wait for one - return 0.
00262      *
00263      * Implemented from YDialog.
00264      **/
00265     virtual YEvent * pollEventInternal();
00266 
00267     /**
00268      * Activate this dialog: Make sure that it is shown as the topmost dialog
00269      * of this application and that it can receive input.
00270      *
00271      * Implemented from YDialog.
00272      **/
00273     virtual void activate();
00274 
00275     /**
00276      * Qt event handlers.
00277      *
00278      * All reimplemented from QWidget.
00279      **/
00280     virtual void keyPressEvent  ( QKeyEvent     * event );
00281     virtual void focusInEvent   ( QFocusEvent   * event );
00282     virtual void resizeEvent    ( QResizeEvent  * event );
00283 
00284 
00285     //
00286     // Data members
00287     //
00288 
00289     bool                _userResized;
00290     QSize               _userSize;
00291 
00292     YQGenericButton *   _focusButton;
00293     YQGenericButton *   _defaultButton;
00294 
00295     QTimer *            _waitForEventTimer;
00296     QEventLoop *        _eventLoop;
00297     YWidget *           _highlightedChild;
00298     QPalette            _preHighlightPalette;
00299     bool                _preHighlightAutoFill;
00300     QY2StyleEditor*     _styleEditor;
00301 
00302 };
00303 
00304 
00305 #endif // YQDialog_h
00306 
 All Classes Functions Variables