]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQGenericButton.h
moved default button handling to base class
[duncan/yast2-qt4.git] / src / YQGenericButton.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQGenericButton.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQGenericButton_h
21 #define YQGenericButton_h
22
23 #include <qwidget.h>
24
25 #include "YPushButton.h"
26
27
28 class QPushButton;
29 class QObject;
30 class YQDialog;
31
32 using std::string;
33
34 /**
35  * Abstract base class for push button and similar widgets -
36  * all that can become a YQDialog's "default button".
37  **/
38 class YQGenericButton : public QWidget, public YPushButton
39 {
40     friend class YQDialog;
41
42     Q_OBJECT
43     
44 protected:
45     
46     /**
47      * Constructor.
48      **/
49     YQGenericButton( YWidget *          parent,
50                      const string &     label );
51
52 public:
53     
54     /**
55      * Destructor.
56      **/
57     virtual ~YQGenericButton();
58
59     /**
60      * Set enabled/disabled state.
61      *
62      * Reimplemented from YWidget.
63      **/
64     virtual void setEnabled( bool enabled );
65
66     /**
67      * Returns 'true' if this button is enabled, 'false' otherwise.
68      **/
69     bool isEnabled() const;
70
71     /**
72      * Changes the label (the text) of the button.
73      **/
74     void setLabel( const QString & label );
75
76     /**
77      * Changes the label (the text) of the button.
78      *
79      * Reimplemented from YWidget.
80      **/
81     virtual void setLabel( const string & label );
82
83     /**
84      * Show this button as the dialog's default button. The button never calls
85      * this by itself - the parent dialog is responsible for that.
86      **/
87     void showAsDefault( bool show = true );
88
89     /**
90      * Returns 'true' if this button is shown as a default button - which may
91      * mean that this really is the dialogs's default button or it is the
92      * dialog's focus button (a button that currently has the keyboard focus).
93      *
94      * Don't confuse this with YPushButton::isDefaultButton()!
95      **/
96     bool isShownAsDefault() const;
97
98     /**
99      * Accept the keyboard focus.
100      **/
101     virtual bool setKeyboardFocus();
102
103     /**
104      * Set this button's icon.
105      *
106      * Reimplemented from YPushButton.
107      **/
108     virtual void setIcon( const string & iconName );
109
110     /**
111      * Returns the button's text (label) - useful for log messages etc.
112      **/
113     QString text() const;
114     
115     /**
116      * Returns the internal Qt PushButton.
117      **/
118     QPushButton * qPushButton() const { return _qPushButton; }
119
120     /**
121      * Returns the internal parent dialog.
122      **/
123     YQDialog * yQDialog() const { return _dialog; }
124
125     
126 public slots:
127
128     /**
129      * Activate (animated) this button.
130      **/
131     void activate();
132
133     
134 protected:
135
136     /**
137      * Set the corresponding QPushButton.
138      **/
139     void setQPushButton( QPushButton * pb );
140     
141     /**
142      * Redirect events from the _qPushButton member to this object.
143      *
144      * Overwritten from QObject.
145      **/
146     bool eventFilter( QObject * obj, QEvent * event );
147
148     /**
149      * Returns the corresponding YQDialog.
150      * Throws an exception if there is none.
151      **/
152     YQDialog * dialog();
153
154     void forgetDialog();
155  
156 private:
157     
158     YQDialog *          _dialog;
159     QPushButton *       _qPushButton;
160 };
161
162 #endif // YQGenericButton_h