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