]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQGenericButton.h
disabling the style for now as the theming causes terrible
[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     Q_OBJECT
41     
42 protected:
43     
44     /**
45      * Constructor.
46      **/
47     YQGenericButton( YWidget *          parent,
48                      const string &     label );
49
50 public:
51     
52     /**
53      * Destructor.
54      **/
55     virtual ~YQGenericButton();
56
57     /**
58      * Set enabled/disabled state.
59      *
60      * Reimplemented from YWidget.
61      **/
62     virtual void setEnabled( bool enabled );
63
64     /**
65      * Returns 'true' if this button is enabled, 'false' otherwise.
66      **/
67     bool isEnabled() const;
68
69     /**
70      * Changes the label (the text) of the button.
71      **/
72     void setLabel( const QString & label );
73
74     /**
75      * Changes the label (the text) of the button.
76      *
77      * Reimplemented from YWidget.
78      **/
79     virtual void setLabel( const string & label );
80
81     /**
82      * Show this button as the dialog's default button. The button never calls
83      * this by itself - the parent dialog is responsible for that.
84      **/
85     void showAsDefault( bool show = true );
86
87     /**
88      * Returns 'true' if this button is shown as a default button - which may
89      * mean that this really is the dialogs's default button or it is the
90      * dialog's focus button (a button that currently has the keyboard focus).
91      *
92      * Don't confuse this with YPushButton::isDefaultButton()!
93      **/
94     bool isShownAsDefault() const;
95
96     /**
97      * Set this button's default button state.
98      *
99      * Reimplemented from YPushButton.
100      **/
101     virtual void setDefaultButton( bool def = true );
102
103     /**
104      * Accept the keyboard focus.
105      **/
106     virtual bool setKeyboardFocus();
107
108     /**
109      * Set this button's icon.
110      *
111      * Reimplemented from YPushButton.
112      **/
113     virtual void setIcon( const string & iconName );
114
115     /**
116      * Returns the button's text (label) - useful for log messages etc.
117      **/
118     QString text() const;
119     
120     /**
121      * Returns the internal Qt PushButton.
122      **/
123     QPushButton * qPushButton() const { return _qPushButton; }
124
125     /**
126      * Returns the internal parent dialog.
127      **/
128     YQDialog * yQDialog() const { return _dialog; }
129
130     
131 public slots:
132
133     /**
134      * Activate (animated) this button.
135      **/
136     void activate();
137
138     
139 protected:
140
141     /**
142      * Set the corresponding QPushButton.
143      **/
144     void setQPushButton( QPushButton * pb );
145     
146     /**
147      * Redirect events from the _qPushButton member to this object.
148      *
149      * Overwritten from QObject.
150      **/
151     bool eventFilter( QObject * obj, QEvent * event );
152
153     /**
154      * Returns the corresponding YQDialog.
155      * Throws an exception if there is none.
156      **/
157     YQDialog * dialog();
158
159
160 private:
161     
162     YQDialog *          _dialog;
163     QPushButton *       _qPushButton;
164     bool                _setDefaultButtonRecursive;
165 };
166
167 #endif // YQGenericButton_h