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);
73 YQGenericButton::dialog()
77 YDialog * yDialog = findDialog();
80 _dialog = dynamic_cast<YQDialog *> (yDialog);
82 YUI_CHECK_PTR( _dialog );
90 YQGenericButton::setDefaultButton( bool def )
92 YPushButton::setDefaultButton( def );
94 if ( ! _setDefaultButtonRecursive )
96 _setDefaultButtonRecursive = true;
99 dialog()->setDefaultButton( this );
101 _setDefaultButtonRecursive = true;
106 void YQGenericButton::setEnabled( bool enabled )
109 _qPushButton->setEnabled( enabled );
111 YWidget::setEnabled( enabled );
115 bool YQGenericButton::isEnabled() const
117 return _qPushButton ? _qPushButton->isEnabled() : false;
121 void YQGenericButton::setIcon( const string & iconName )
123 if ( ! _qPushButton )
125 y2error( "NULL button (icon %s)", iconName.c_str() );
129 QString qIconName = fromUTF8( iconName );
131 if ( qIconName.isEmpty() )
133 _qPushButton->setIcon( QIcon() );
137 qIconName = QString( ICONDIR ) + "/" + qIconName;
138 QPixmap icon( qIconName );
141 y2warning( "Can't load icon '%s'", qPrintable(qIconName) );
143 _qPushButton->setIcon( icon );
147 void YQGenericButton::setLabel( const QString & label )
150 _qPushButton->setText( label );
152 y2error( "NULL button '%s'", qPrintable(label) );
154 YPushButton::setLabel( toUTF8( label ) );
158 void YQGenericButton::setLabel( const string & label )
161 _qPushButton->setText( fromUTF8( label ) );
163 y2error( "NULL button '%s'", label.c_str() );
165 YPushButton::setLabel( label );
169 void YQGenericButton::showAsDefault( bool show )
173 _qPushButton->setDefault( show );
174 _qPushButton->update();
179 bool YQGenericButton::isShownAsDefault() const
181 return _qPushButton ? _qPushButton->isDefault() : false;
186 YQGenericButton::text() const
188 return _qPushButton ? _qPushButton->text() : "";
192 void YQGenericButton::activate()
195 _qPushButton->animateClick();
199 bool YQGenericButton::eventFilter( QObject * obj, QEvent * event )
203 if ( event->type() == QEvent::FocusIn )
205 dialog()->gettingFocus( this );
206 return false; // event processed?
208 else if ( event->type() == QEvent::FocusOut )
210 dialog()->losingFocus( this );
211 return false; // event processed?
213 else if ( event->type() == QEvent::MouseButtonRelease )
215 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
217 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
219 y2milestone( "Right click on button detected" );
220 YQUI::ui()->maybeLeftHandedUser();
226 return QObject::eventFilter( obj, event );
230 bool YQGenericButton::setKeyboardFocus()
232 if ( ! _qPushButton )
235 dialog()->gettingFocus( this );
236 _qPushButton->setFocus();
242 #include "YQGenericButton.moc"