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 )
47 void YQGenericButton::setQPushButton( QPushButton * pb )
50 _qPushButton->setAutoDefault( true );
51 _qPushButton->installEventFilter( this );
52 _qPushButton->setAutoDefault( true );
54 YPushButton::setLabel( toUTF8 ( _qPushButton->text() ) );
58 YQGenericButton::~YQGenericButton()
60 if ( _dialog ) // If we don't have one any more, don't bother
62 if ( _dialog->focusButton() == this )
63 _dialog->losingFocus( this );
65 if ( _dialog->defaultButton() == this )
66 _dialog->setDefaultButton(0);
71 YQGenericButton::forgetDialog()
77 YQGenericButton::dialog()
81 YDialog * yDialog = findDialog();
84 _dialog = dynamic_cast<YQDialog *> (yDialog);
86 YUI_CHECK_PTR( _dialog );
93 void YQGenericButton::setEnabled( bool enabled )
96 _qPushButton->setEnabled( enabled );
98 YWidget::setEnabled( enabled );
102 bool YQGenericButton::isEnabled() const
104 return _qPushButton ? _qPushButton->isEnabled() : false;
108 void YQGenericButton::setIcon( const string & iconName )
110 if ( ! _qPushButton )
112 y2error( "NULL button (icon %s)", iconName.c_str() );
116 QString qIconName = fromUTF8( iconName );
118 if ( qIconName.isEmpty() )
120 _qPushButton->setIcon( QIcon() );
124 qIconName = QString( ICONDIR ) + "/" + qIconName;
125 QPixmap icon( qIconName );
128 y2warning( "Can't load icon '%s'", qPrintable(qIconName) );
130 _qPushButton->setIcon( icon );
134 void YQGenericButton::setLabel( const QString & label )
137 _qPushButton->setText( label );
139 y2error( "NULL button '%s'", qPrintable(label) );
141 YPushButton::setLabel( toUTF8( label ) );
145 void YQGenericButton::setLabel( const string & label )
148 _qPushButton->setText( fromUTF8( label ) );
150 y2error( "NULL button '%s'", label.c_str() );
152 YPushButton::setLabel( label );
156 void YQGenericButton::showAsDefault( bool show )
160 _qPushButton->setDefault( show );
161 _qPushButton->update();
166 bool YQGenericButton::isShownAsDefault() const
168 return _qPushButton ? _qPushButton->isDefault() : false;
173 YQGenericButton::text() const
175 return _qPushButton ? _qPushButton->text() : "";
179 void YQGenericButton::activate()
182 _qPushButton->animateClick();
186 bool YQGenericButton::eventFilter( QObject * obj, QEvent * event )
190 if ( event->type() == QEvent::FocusIn )
192 dialog()->gettingFocus( this );
193 return false; // event processed?
195 else if ( event->type() == QEvent::FocusOut )
197 dialog()->losingFocus( this );
198 return false; // event processed?
200 else if ( event->type() == QEvent::MouseButtonRelease )
202 QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *> (event);
204 if ( mouseEvent && mouseEvent->button() == Qt::RightButton )
206 y2milestone( "Right click on button detected" );
207 YQUI::ui()->maybeLeftHandedUser();
213 return QObject::eventFilter( obj, event );
217 bool YQGenericButton::setKeyboardFocus()
219 if ( ! _qPushButton )
222 dialog()->gettingFocus( this );
223 _qPushButton->setFocus();
229 #include "YQGenericButton.moc"