1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQGenericButton.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #include <qpushbutton.h>
26 #define y2log_component "qt-ui"
27 #include <ycp/y2log.h>
32 #include "YQGenericButton.h"
36 YQGenericButton::YQGenericButton( YWidget * parent,
37 const string & label )
38 : QWidget( (QWidget *) parent->widgetRep() )
39 , YPushButton( parent, label )
42 , _setDefaultButtonRecursive( false )
48 void YQGenericButton::setQPushButton( QPushButton * pb )
51 _qPushButton->setAutoDefault( true );
52 _qPushButton->installEventFilter( this );
53 _qPushButton->setAutoDefault( true );
55 YPushButton::setLabel( toUTF8 ( _qPushButton->text() ) );
59 YQGenericButton::~YQGenericButton()
61 if ( _dialog ) // If we don't have one any more, don't bother
63 if ( _dialog->focusButton() == this )
64 _dialog->losingFocus( this );
66 if ( _dialog->defaultButton() == this )
67 _dialog->setDefaultButton(0);
72 YQGenericButton::forgetDialog()
78 YQGenericButton::dialog()
82 YDialog * yDialog = findDialog();
85 _dialog = dynamic_cast<YQDialog *> (yDialog);
87 YUI_CHECK_PTR( _dialog );
95 YQGenericButton::setDefaultButton( bool def )
97 YPushButton::setDefaultButton( def );
99 if ( ! _setDefaultButtonRecursive )
101 _setDefaultButtonRecursive = true;
103 if ( _dialog && def )
104 dialog()->setDefaultButton( this );
106 _setDefaultButtonRecursive = true;
111 void YQGenericButton::setEnabled( bool enabled )
114 _qPushButton->setEnabled( enabled );
116 YWidget::setEnabled( enabled );
120 bool YQGenericButton::isEnabled() const
122 return _qPushButton ? _qPushButton->isEnabled() : false;
126 void YQGenericButton::setIcon( const string & iconName )
128 if ( ! _qPushButton )
130 y2error( "NULL button (icon %s)", iconName.c_str() );
134 QString qIconName = fromUTF8( iconName );
136 if ( qIconName.isEmpty() )
138 _qPushButton->setIcon( QIcon() );
142 qIconName = QString( ICONDIR ) + "/" + qIconName;
143 QPixmap icon( qIconName );
146 y2warning( "Can't load icon '%s'", qPrintable(qIconName) );
148 _qPushButton->setIcon( icon );
152 void YQGenericButton::setLabel( const QString & label )
155 _qPushButton->setText( label );
157 y2error( "NULL button '%s'", qPrintable(label) );
159 YPushButton::setLabel( toUTF8( label ) );
163 void YQGenericButton::setLabel( const string & label )
166 _qPushButton->setText( fromUTF8( label ) );
168 y2error( "NULL button '%s'", label.c_str() );
170 YPushButton::setLabel( label );
174 void YQGenericButton::showAsDefault( bool show )
178 _qPushButton->setDefault( show );
179 _qPushButton->update();
184 bool YQGenericButton::isShownAsDefault() const
186 return _qPushButton ? _qPushButton->isDefault() : false;
191 YQGenericButton::text() const
193 return _qPushButton ? _qPushButton->text() : "";
197 void YQGenericButton::activate()
200 _qPushButton->animateClick();
204 bool YQGenericButton::eventFilter( QObject * obj, QEvent * event )
208 if ( event->type() == QEvent::FocusIn )
210 dialog()->gettingFocus( this );
211 return false; // event processed?
213 else if ( event->type() == QEvent::FocusOut )
215 dialog()->losingFocus( this );
216 return false; // event processed?
218 else if ( event->type() == QEvent::MouseButtonRelease )
220 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
222 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
224 y2milestone( "Right click on button detected" );
225 YQUI::ui()->maybeLeftHandedUser();
231 return QObject::eventFilter( obj, event );
235 bool YQGenericButton::setKeyboardFocus()
237 if ( ! _qPushButton )
240 dialog()->gettingFocus( this );
241 _qPushButton->setFocus();
247 #include "YQGenericButton.moc"