[yast-commit] r39107 - in /branches/tmp/sh/mod-ui/qt/src: YQComboBox.cc YQComboBox.h YQMultiSelectionBox.cc YQMultiSelectionBox.h YQSelectionBox.cc YQUI.h YQUI_widgets.cc YQWidgetFactory.cc YQWidgetFactory.h
Author: sh-sh-sh Date: Mon Jul 2 16:32:31 2007 New Revision: 39107 URL: http://svn.opensuse.org/viewcvs/yast?rev=39107&view=rev Log: compiles Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc branches/tmp/sh/mod-ui/qt/src/YQComboBox.h branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.h branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc branches/tmp/sh/mod-ui/qt/src/YQUI.h branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.h Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc Mon Jul 2 16:32:31 2007 @@ -73,9 +73,52 @@ } +string YQComboBox::text() +{ + return toUTF8( _qt_combo_box->currentText() ); +} + + +void YQComboBox::setText( const string & newValue ) +{ + QString text = fromUTF8( newValue ); + + if ( isValidText( text ) ) + { + _qt_combo_box->blockSignals( true ); + _qt_combo_box->setCurrentText( text ); + _qt_combo_box->blockSignals( false ); + } + else + { + y2error( "%s \"%s\": Rejecting invalid value \"%s\"", + widgetClass(), debugLabel().c_str(), newValue.c_str() ); + } +} + + +void YQComboBox::addItem( YItem * item ) +{ + YComboBox::addItem( item ); + _qt_combo_box->insertItem( fromUTF8( item->label() ) ); + + if ( item->selected() ) + setText( item->label() ); +} + + +void YQComboBox::deleteAllItems() +{ + _qt_combo_box->blockSignals( true ); + _qt_combo_box->clear(); + YSelectionWidget::deleteAllItems(); + _qt_combo_box->blockSignals( false ); +} + + void YQComboBox::setLabel( const string & label ) { - _qt_label->setText( fromUTF8(label->value() ) ); + _qt_label->setText( fromUTF8( label ) ); if ( _qt_label->text().isEmpty() ) { @@ -127,86 +170,69 @@ } -int YQComboBox::preferredWidth() +bool YQComboBox::isValidText( const QString & txt ) const { - return sizeHint().width(); -} + if ( ! _validator ) + return true; + int pos = 0; + QString text( txt ); // need a non-const QString & -int YQComboBox::preferredHeight() -{ - return sizeHint().height(); + return _validator->validate( text, pos ) == QValidator::Acceptable; } -void YQComboBox::setSize( int newWidth, int newHeight ) +void YQComboBox::slotSelected( int i ) { - resize( newWidth, newHeight ); -} - + if ( notify() ) + { + if ( ! YQUI::ui()->eventPendingFor( this ) ) + { + // Avoid overwriting a (more important) ValueChanged event with a SelectionChanged event -void YQComboBox::setEnabled( bool enabled ) -{ - _qt_label->setEnabled( enabled ); - _qt_combo_box->setEnabled( enabled ); - YWidget::setEnabled( enabled ); + YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) ); + } + } } -void YQComboBox::itemAdded( const string & label, int index, bool selected ) +void YQComboBox::textChanged( const QString & new_text ) { - _qt_combo_box->insertItem( fromUTF8( label ) ); - - if ( selected ) - setValue( label ); + if ( notify() ) + YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) ); } -int YQComboBox::currentItem() const +void YQComboBox::setInputMaxLength( int len ) { - return _qt_combo_box->currentItem(); + _qt_combo_box->lineEdit()->setMaxLength( len ); + YComboBox::setInputMaxLength( len ); } -string YQComboBox::value() const +int YQComboBox::preferredWidth() { - return toUTF8( _qt_combo_box->currentText() ); + return sizeHint().width(); } -bool YQComboBox::isValidText( const QString & txt ) const +int YQComboBox::preferredHeight() { - if ( ! _validator ) - return true; - - int pos = 0; - QString text( txt ); // need a non-const QString & - - return _validator->validate( text, pos ) == QValidator::Acceptable; + return sizeHint().height(); } -void YQComboBox::setValue( const string & ytext ) +void YQComboBox::setSize( int newWidth, int newHeight ) { - QString text = fromUTF8( ytext->value() ); - - if ( isValidText( text ) ) - { - _qt_combo_box->blockSignals( true ); - _qt_combo_box->setCurrentText( text ); - _qt_combo_box->blockSignals( false ); - } - else - { - y2error( "%s \"%s\": Rejecting invalid value \"%s\"", - widgetClass(), debugLabel().c_str(), ytext->value().c_str() ); - } + resize( newWidth, newHeight ); } -void YQComboBox::setCurrentItem( int index ) +void YQComboBox::setEnabled( bool enabled ) { - _qt_combo_box->setCurrentItem( index ); + _qt_label->setEnabled( enabled ); + _qt_combo_box->setEnabled( enabled ); + YWidget::setEnabled( enabled ); } @@ -218,40 +244,4 @@ } -// slots - -void YQComboBox::slotSelected( int i ) -{ - if ( notify() ) - { - if ( ! YQUI::ui()->eventPendingFor( this ) ) - { - // Avoid overwriting a (more important) ValueChanged event with a SelectionChanged event - - YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) ); - } - } -} - - -void YQComboBox::textChanged( const QString & new_text ) -{ - if ( notify() ) - YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) ); -} - - -void YQComboBox::deleteAllItems() -{ - _qt_combo_box->blockSignals( true ); - _qt_combo_box->clear(); - YSelectionWidget::deleteAllItems(); - _qt_combo_box->blockSignals( false ); -} - -void YQComboBox::setInputMaxLength( const YCPInteger & numberOfChars) -{ - _qt_combo_box->lineEdit()->setMaxLength(numberOfChars->asInteger()->value()); -} - #include "YQComboBox.moc" Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQComboBox.h?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQComboBox.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQComboBox.h Mon Jul 2 16:32:31 2007 @@ -35,7 +35,6 @@ Q_OBJECT public: - /** * Constructor. **/ @@ -47,103 +46,79 @@ ~YQComboBox(); /** - * Inherited from YWidget: Sets the enabled state of the - * widget. All new widgets are enabled per definition. Only - * enabled widgets can take user input. - **/ - void setEnabled( bool enabled ); - - /** - * Preferred width of the widget. + * Add one item. This widget assumes ownership of the item object and will + * delete it in its destructor. * - * Reimplemented from YWidget. - **/ - virtual int preferredWidth(); - - /** - * Preferred height of the widget. - * - * Reimplemented from YWidget. + * Reimplemented from YComboBox. **/ - virtual int preferredHeight(); + virtual void addItem( YItem * item ); /** - * Set the new size of the widget. + * Delete all items. * - * Reimplemented from YWidget. + * Reimplemented from YSelectionWidget. **/ - virtual void setSize( int newWidth, int newHeight ); + virtual void deleteAllItems(); /** * Change the label text. + * + * Reimplemented from YSelectionWidget. **/ - void setLabel( const string & label ); + virtual void setLabel( const string & label ); /** * Change the valid input characters. * - * Reimplemented from @ref YComboBox + * Reimplemented from YComboBox. **/ - void setValidChars( const string & validChars ); + virtual void setValidChars( const string & validChars ); /** - * Returns 'true' if the given text is valid according to the current - * setting of ValidChars. - **/ - bool isValidText( const QString & txt ) const; - - /** - * Notification that a new item has been added. + * Specify the amount of characters which can be inserted. * * Reimplemented from YComboBox. **/ - void itemAdded( const string & itemText, int itemIndex, bool selected ); + virtual void setInputMaxLength( int numberOfChars ); /** - * Inherited from YComboBox: - * Returns the ComboBox value. + * Returns 'true' if the given text is valid according to the current + * setting of ValidChars. **/ - string value() const; + bool isValidText( const QString & txt ) const; /** - * Inherited from YComboBox: - * Sets the ComboBox value to a random value that is not already in - * the item list. Will be called for editable ComboBox widgets only. + * Inherited from YWidget: Sets the enabled state of the + * widget. All new widgets are enabled per definition. Only + * enabled widgets can take user input. **/ - void setValue( const string & newValue ); + virtual void setEnabled( bool enabled ); /** - * Inherited from YComboBox: - * Returns the index of the currently selected item (from 0 on) - * or -1 if no item is selected. - **/ - int currentItem() const; - - /** - * Inherited from YComboBox: - * Selects an item from the list. Notice there intentionally is no - * corresponding getCurrentItem() method - use getValue() instead. + * Preferred width of the widget. + * + * Reimplemented from YWidget. **/ - void setCurrentItem( int index ); + virtual int preferredWidth(); /** - * Accept the keyboard focus. + * Preferred height of the widget. + * + * Reimplemented from YWidget. **/ - virtual bool setKeyboardFocus(); + virtual int preferredHeight(); /** - * Delete all items. + * Set the new size of the widget. * - * Reimplemented from YSelectionWidget. + * Reimplemented from YWidget. **/ - virtual void deleteAllItems(); + virtual void setSize( int newWidth, int newHeight ); /** - * Specify the amount of characters which can be inserted. - * - * Reimplemented from YComboBox. + * Accept the keyboard focus. **/ - void setInputMaxLength( const YCPInteger & numberOfChars ); + virtual bool setKeyboardFocus(); protected slots: @@ -163,6 +138,27 @@ protected: + + /** + * Return this ComboBox's current value as text. + * + * Called internally from value(), selectedItem() and related. + * + * Implemented from YComboBox. + **/ + virtual string text(); + + /** + * + * Set this ComboBox's current value as text. + * + * Called internally whenever the content is to change + * programmatically. Don't call setValue() or selectItem() from here. + * + * Implemented from YComboBox. + **/ + virtual void setText( const string & newText ); + // // Data members Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc Mon Jul 2 16:32:31 2007 @@ -35,221 +35,174 @@ #define SHRINKABLE_VISIBLE_LINES 2 -YQMultiSelectionBox::YQMultiSelectionBox( QWidget * parent, - const YWidgetOpt & opt, - const YCPString & label ) - : QVBox( parent ) - , YMultiSelectionBox( opt, label ) +YQMultiSelectionBox::YQMultiSelectionBox( YWidget * parent, + const string & label ) + : QVBox( (QWidget *) parent->widgetRep() ) + , YMultiSelectionBox( parent, label ) { setWidgetRep( this ); setSpacing( YQWidgetSpacing ); setMargin( YQWidgetMargin ); - _qt_label = new QLabel( fromUTF8(label->value() ), this ); + _qt_label = new QLabel( fromUTF8( label ), this ); _qt_label->setTextFormat( QLabel::PlainText ); - _qt_listview = new QListView( this ); - _qt_listview->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - _qt_listview->addColumn( "" ); // QListView doesn't have one single column by default! - _qt_listview->setSorting( 0, false ); - _qt_listview->header()->hide(); - _qt_label->setBuddy( _qt_listview ); + _qt_listView = new QListView( this ); + _qt_listView->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + _qt_listView->addColumn( "" ); // QListView doesn't have one single column by default! + _qt_listView->setSorting( 0, false ); + _qt_listView->header()->hide(); + _qt_label->setBuddy( _qt_listView ); // Very small default size if specified - _shrinkable = opt.isShrinkable.value(); - connect( _qt_listview, SIGNAL( selectionChanged() ), + connect( _qt_listView, SIGNAL( selectionChanged() ), this, SLOT ( slotSelected() ) ); - + connect( this, SIGNAL( valueChanged() ), this, SLOT ( slotValueChanged() ) ); } -void -YQMultiSelectionBox::setLabel( const YCPString & label ) +YQMultiSelectionBox::~YQMultiSelectionBox() { - _qt_label->setText( fromUTF8(label->value() ) ); - YMultiSelectionBox::setLabel( label ); + // NOP } -int YQMultiSelectionBox::preferredWidth() +void +YQMultiSelectionBox::setLabel( const string & label ) { - int hintWidth = _qt_label->sizeHint().width() + frameWidth(); - - return max( 80, hintWidth ); + _qt_label->setText( fromUTF8( label ) ); + YMultiSelectionBox::setLabel( label ); } -int YQMultiSelectionBox::preferredHeight() +void +YQMultiSelectionBox::addItem( YItem * yItem ) { - int hintHeight = _qt_label->sizeHint().height(); - int visibleLines = _shrinkable ? SHRINKABLE_VISIBLE_LINES : DEFAULT_VISIBLE_LINES; - hintHeight += visibleLines * _qt_listview->fontMetrics().lineSpacing(); - hintHeight += _qt_listview->frameWidth() * 2; + YMultiSelectionBox::addItem( yItem ); // will also check for NULL - return max( 80, hintHeight ); -} + _qt_listView->blockSignals( true ); + YQMultiSelectionBoxItem * msbItem = + new YQMultiSelectionBoxItem( this, _qt_listView, yItem ); -void -YQMultiSelectionBox::setSize( int newWidth, int newHeight ) -{ - resize( newWidth, newHeight ); -} + YUI_CHECK_NEW( msbItem ); + if ( yItem->selected() ) + msbItem->setOn( true ); -void -YQMultiSelectionBox::setEnabled( bool enabled ) + _qt_listView->blockSignals( false ); +} + +void YQMultiSelectionBox::selectItem( YItem * yItem, bool selected ) { - _qt_label->setEnabled( enabled ); - _qt_listview->setEnabled( enabled ); - _qt_listview->triggerUpdate(); - YWidget::setEnabled( enabled ); + YMultiSelectionBox::selectItem( yItem, selected ); + YQMultiSelectionBoxItem * msbItem = findItem( yItem ); + + if ( msbItem ) + msbItem->setOn( selected ); } void -YQMultiSelectionBox::itemAdded( const YCPString & label, int index, bool selected ) +YQMultiSelectionBox::deselectAllItems() { - _qt_listview->blockSignals( true ); - - YQMultiSelectionBoxItem * item = new YQMultiSelectionBoxItem( this, _qt_listview, fromUTF8( label->value() ) ); - - if ( item && selected ) - { - item->setOn( true ); - } + YMultiSelectionBox::deselectAllItems(); - _qt_listview->blockSignals( false ); + _qt_listView->blockSignals( true ); + _qt_listView->clearSelection(); + _qt_listView->blockSignals( false ); } -int -YQMultiSelectionBox::getCurrentItem() +void +YQMultiSelectionBox::deleteAllItems() { - int index = 0; - QListViewItem * child = _qt_listview->firstChild(); + YMultiSelectionBox::deleteAllItems(); - while ( child ) - { - if ( child->isSelected() ) // don't confuse this with isOn() ! - { - return index; - } - index++; - child = child->nextSibling(); - } - - return -1; + _qt_listView->blockSignals( true ); + _qt_listView->clear(); + _qt_listView->blockSignals( false ); } -void -YQMultiSelectionBox::setCurrentItem( int index ) +YItem * +YQMultiSelectionBox::currentItem() { - _qt_listview->blockSignals( true ); - _qt_listview->clearSelection(); - QListViewItem * child = _qt_listview->firstChild(); + QListViewItem * currentQItem = _qt_listView->currentItem(); - for ( int i = 0; i < index; i++ ) + if ( currentQItem ) { - child = child->nextSibling(); + YQMultiSelectionBoxItem * item = dynamic_cast<YQMultiSelectionBoxItem *> (currentQItem); - if ( ! child ) - { - y2error( "Don't have that many items" ); - return; - } + if ( item ) + return item->yItem(); } - child->setSelected( true ); - _qt_listview->blockSignals( false ); + return 0; } -bool -YQMultiSelectionBox::setKeyboardFocus() +void +YQMultiSelectionBox::setCurrentItem( YItem * yItem ) { - _qt_listview->setFocus(); - return true; + YQMultiSelectionBoxItem * msbItem = findItem( yItem ); + + if ( msbItem ) + { + _qt_listView->blockSignals( true ); + _qt_listView->setCurrentItem( msbItem ); + _qt_listView->blockSignals( false ); + } } void -YQMultiSelectionBox::deleteAllItems() +YQMultiSelectionBox::setEnabled( bool enabled ) { - _qt_listview->blockSignals( true ); - _qt_listview->clear(); - YSelectionWidget::deleteAllItems(); - _qt_listview->blockSignals( false ); + _qt_label->setEnabled( enabled ); + _qt_listView->setEnabled( enabled ); + _qt_listView->triggerUpdate(); + YWidget::setEnabled( enabled ); } -bool -YQMultiSelectionBox::itemIsSelected( int index ) +int YQMultiSelectionBox::preferredWidth() { - QListViewItem * child = _qt_listview->firstChild(); + int hintWidth = _qt_label->sizeHint().width() + frameWidth(); - for ( int i = 0; i < index; i++ ) - { - child = child->nextSibling(); + return max( 80, hintWidth ); +} - if ( ! child ) - { - y2error( "Don't have that many items" ); - return false; - } - } - QCheckListItem * item = ( QCheckListItem * ) child; +int YQMultiSelectionBox::preferredHeight() +{ + int hintHeight = _qt_label->sizeHint().height(); + int visibleLines = shrinkable() ? SHRINKABLE_VISIBLE_LINES : DEFAULT_VISIBLE_LINES; + hintHeight += visibleLines * _qt_listView->fontMetrics().lineSpacing(); + hintHeight += _qt_listView->frameWidth() * 2; - return item->isOn(); + return max( 80, hintHeight ); } void -YQMultiSelectionBox::selectItem( int index ) +YQMultiSelectionBox::setSize( int newWidth, int newHeight ) { - _qt_listview->blockSignals( true ); - QListViewItem * child = _qt_listview->firstChild(); - - for ( int i = 0; i < index; i++ ) - { - child = child->nextSibling(); - - if ( ! child ) - { - y2error( "Don't have that many items" ); - return; - } - } - - QCheckListItem * item = ( QCheckListItem * ) child; - - item->setOn( true ); - _qt_listview->blockSignals( false ); + resize( newWidth, newHeight ); } -void -YQMultiSelectionBox::deselectAllItems() +bool +YQMultiSelectionBox::setKeyboardFocus() { - _qt_listview->blockSignals( true ); - - QListViewItem * child = _qt_listview->firstChild(); + _qt_listView->setFocus(); - while ( child ) - { - QCheckListItem * item = ( QCheckListItem * ) child; - item->setOn( false ); - child = child->nextSibling(); - } - - _qt_listview->blockSignals( false ); + return true; } @@ -261,7 +214,7 @@ if ( ! YQUI::ui()->eventPendingFor( this ) ) { // Avoid overwriting a (more important) ValueChanged event with a SelectionChanged event - + YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) ); } } @@ -283,6 +236,27 @@ } +YQMultiSelectionBoxItem * +YQMultiSelectionBox::findItem( YItem * wantedItem ) +{ + QListViewItemIterator it( _qt_listView ); + + while ( *it ) + { + YQMultiSelectionBoxItem * item = dynamic_cast<YQMultiSelectionBoxItem *> (*it); + + if ( item && item->yItem() == wantedItem ) + return item; + + ++it; + } + + return 0; +} + + + + int YQMultiSelectionBoxItem::_item_count = 0; @@ -290,10 +264,13 @@ YQMultiSelectionBoxItem::YQMultiSelectionBoxItem( YQMultiSelectionBox * parent, QListView * listView, - const QString & text ) - : QCheckListItem( listView, text, QCheckListItem::CheckBox ) + YItem * yItem ) + : QCheckListItem( listView, fromUTF8( yItem->label() ), QCheckListItem::CheckBox ) + , _yItem( yItem ) , _multiSelectionBox( parent ) { + YUI_CHECK_PTR( yItem ); + _serial = _item_count++; } @@ -301,6 +278,7 @@ void YQMultiSelectionBoxItem::stateChange( bool newState ) { + _yItem->setSelected( newState ); _multiSelectionBox->sendValueChanged(); QCheckListItem::stateChange( newState ); } @@ -312,7 +290,7 @@ /* * Return a sort key that depends on creation ( i.e. insertion ) order. */ - + static QString sortKey; sortKey.sprintf( "%010d", INT_MAX - _serial ); Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.h?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.h Mon Jul 2 16:32:31 2007 @@ -22,12 +22,13 @@ #include <qvbox.h> #include <qlistview.h> -#include <ycp/YCPString.h> #include "YMultiSelectionBox.h" class QLabel; +class YQMultiSelectionBoxItem; + class YQMultiSelectionBox : public QVBox, public YMultiSelectionBox { @@ -38,117 +39,111 @@ /** * Constructor. **/ - YQMultiSelectionBox( QWidget * parent, - const YWidgetOpt & opt, - const YCPString & label ); + YQMultiSelectionBox( YWidget * parent, const string & label ); /** - * Inherited from YWidget: Sets the enabled state of the - * widget. All new widgets are enabled per definition. Only - * enabled widgets can take user input. + * Destructor. **/ - void setEnabled( bool enabled ); - + ~YQMultiSelectionBox(); + /** - * Preferred width of the widget. + * Change the label text. * - * Reimplemented from YWidget. + * Reimplemented from YSelectionWidget. **/ - virtual int preferredWidth(); + virtual void setLabel( const string & label ); /** - * Preferred height of the widget. + * Add an item. * - * Reimplemented from YWidget. + * Reimplemented from YSelectionWidget. **/ - virtual int preferredHeight(); + virtual void addItem( YItem * item ); /** - * Set the new size of the widget. + * Select or deselect an item. * - * Reimplemented from YWidget. - **/ - virtual void setSize( int newWidth, int newHeight ); - - /** - * Change the label text. + * Reimplemented from YSelectionWidget. **/ - virtual void setLabel( const YCPString & label ); + virtual void selectItem( YItem * item, bool selected = true ); /** - * Notification that a new item has been added. + * Deselect all items. * * Reimplemented from YSelectionWidget. **/ - virtual void itemAdded( const YCPString & itemText, int index, bool selected ); + virtual void deselectAllItems(); /** - * Returns the index of the item that currently has the keyboard focus. + * Delete all items. * - * Reimplemented from YMultiSelectionBox + * Reimplemented from YSelectionWidget. **/ - virtual int getCurrentItem(); - + virtual void deleteAllItems(); + /** - * Set the keyboard focus to one item. + * Return the the item that currently has the keyboard focus + * or 0 if no item currently has the keyboard focus. * - * Reimplemented from YMultiSelectionBox + * Reimplemented from YMultiSelectionBox. **/ - virtual void setCurrentItem( int index ); + virtual YItem * currentItem(); /** - * Accept the keyboard focus. + * Set the keyboard focus to the specified item. + * 0 means clear the keyboard focus. + * + * Reimplemented from YMultiSelectionBox. **/ - virtual bool setKeyboardFocus(); + virtual void setCurrentItem( YItem * item ); /** - * Delete all items. + * Set enabled/disabled state. * - * Reimplemented from YMultiSelectionBox + * Reimplemented from YWidget. **/ - virtual void deleteAllItems(); + virtual void setEnabled( bool enabled ); /** - * Sends a ValueChanged signal. + * Preferred width of the widget. + * + * Reimplemented from YWidget. **/ - void sendValueChanged(); - - -signals: + virtual int preferredWidth(); /** - * Emitted upon when an item changes its state. + * Preferred height of the widget. + * + * Reimplemented from YWidget. **/ - void valueChanged(); - - -protected: + virtual int preferredHeight(); /** - * Check whether or not item #index is selected. + * Set the new size of the widget. * - * Reimplemented from YMultiSelectionBox + * Reimplemented from YWidget. **/ - virtual bool itemIsSelected( int index ); + virtual void setSize( int newWidth, int newHeight ); /** - * Select item #index. - * - * Reimplemented from YMultiSelectionBox + * Accept the keyboard focus. **/ - virtual void selectItem( int index ); + virtual bool setKeyboardFocus(); /** - * Deselect all items. - * - * Reimplemented from YMultiSelectionBox + * Sends a ValueChanged signal. **/ - virtual void deselectAllItems(); + void sendValueChanged(); +signals: + /** + * Emitted upon when an item changes its state. + **/ + void valueChanged(); + protected slots: - /** * Send SelectionChanged event if `opt(`notify) is set. **/ @@ -161,11 +156,14 @@ protected: + /** + * Find the counterpart of 'item'. Return 0 if there is none. + **/ + YQMultiSelectionBoxItem * findItem( YItem * item ); + QLabel * _qt_label; - QListView * _qt_listview; - - bool _shrinkable; + QListView * _qt_listView; }; @@ -178,13 +176,18 @@ **/ YQMultiSelectionBoxItem( YQMultiSelectionBox * parent, QListView * listView, - const QString & text ); + YItem * yItem ); /** * Destructor. **/ virtual ~YQMultiSelectionBoxItem() {} + /** + * Return the corresponding YItem. + **/ + YItem * yItem() const { return _yItem; } + protected: @@ -198,18 +201,17 @@ /** * Returns the sort key for any column. - * Reimplemented from @ref QListViewItem. + * In this case, maintain item creation order. * - * This method is the true reason for this class - a pure QListViewItem is - * too dumb to retain insertion order even if sorting is explicitly - * disabled: It gets sorted in reverse insertion order. :-( + * Reimplemented from QListViewItem. **/ virtual QString key ( int column, bool ascending ) const; // Data members - + + YItem * _yItem; int _serial; YQMultiSelectionBox * _multiSelectionBox; Modified: branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc Mon Jul 2 16:32:31 2007 @@ -42,7 +42,7 @@ YQSelectionBox::YQSelectionBox( YWidget * parent, const string & label ) : QVBox( (QWidget *) parent->widgetRep() ) - , YSelectionBox( opt, label ) + , YSelectionBox( parent, label ) { setWidgetRep( this ); @@ -128,7 +128,7 @@ _qt_listBox->insertItem( icon, fromUTF8( item->label() ) ); } - if ( selected ) + if ( item->selected() ) { _qt_listBox->blockSignals( true ); _qt_listBox->setCurrentItem( item->index() ); @@ -292,11 +292,26 @@ } -void YQSelectionBox::slotActivated( QListBoxItem * item ) +void YQSelectionBox::slotActivated( QListBoxItem * qItem ) { - selectItem( QListBox::index( item ) ); + YItem * item = itemAt( _qt_listBox->index( qItem ) ); - YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) ); + if ( item ) + { +#if 1 + y2debug( "Item %s selected", item->label().c_str() ); +#endif + YSelectionBox::deselectAllItems(); + item->setSelected( true ); + + YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) ); + } + else + { + y2error( "%s: No YItem %s found", + debugLabel().c_str(), + toUTF8( qItem->text() ).c_str() ); + } } Modified: branches/tmp/sh/mod-ui/qt/src/YQUI.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI.h?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI.h Mon Jul 2 16:32:31 2007 @@ -450,14 +450,11 @@ /*** Widget creation methods, all reimplemented from YUI ***/ - YWidget * createComboBox ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); YWidget * createIntField ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int minValue, int maxValue, int initialValue); YWidget * createLogView ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int visibleLines, int maxLines ); YWidget * createMultiLineEdit ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, const YCPString & text); YWidget * createProgressBar ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, const YCPInteger & maxProgress, const YCPInteger & currentProgress ); YWidget * createMenuButton ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); - YWidget * createSelectionBox ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); - YWidget * createMultiSelectionBox ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); YWidget * createTable ( YWidget * parent, YWidgetOpt & opt, vector<string> header); YWidget * createTree ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); Modified: branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc Mon Jul 2 16:32:31 2007 @@ -23,7 +23,6 @@ #include "YQBarGraph.h" #include "YQCheckBox.h" -#include "YQComboBox.h" #include "YQDate.h" #include "YQDialog.h" #include "YQDownloadProgress.h" @@ -33,13 +32,11 @@ #include "YQMenuButton.h" #include "YQMultiLineEdit.h" #include "YQMultiProgressMeter.h" -#include "YQMultiSelectionBox.h" #include "YQPackageSelectorPlugin.h" #include "YQPartitionSplitter.h" #include "YQPatternSelector.h" #include "YQSimplePatchSelector.h" #include "YQProgressBar.h" -#include "YQSelectionBox.h" #include "YQSlider.h" #include "YQTable.h" #include "YQTime.h" @@ -121,26 +118,6 @@ return new YQMultiLineEdit( (QWidget *) ( parent->widgetRep() ), opt, label, initialText); } -YWidget * YQUI::createSelectionBox ( YWidget * parent, - YWidgetOpt & opt, - const YCPString & label ) -{ - return new YQSelectionBox( (QWidget *) ( parent->widgetRep() ), opt, label); -} - -YWidget * YQUI::createMultiSelectionBox( YWidget * parent, - YWidgetOpt & opt, - const YCPString & label ) -{ - return new YQMultiSelectionBox( (QWidget *) ( parent->widgetRep() ), opt, label); -} - -YWidget * YQUI::createComboBox ( YWidget * parent, - YWidgetOpt & opt, - const YCPString & label ) -{ - return new YQComboBox( (QWidget *) ( parent->widgetRep() ), opt, label); -} YWidget * YQUI::createTree ( YWidget * parent, YWidgetOpt & opt, Modified: branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc Mon Jul 2 16:32:31 2007 @@ -150,7 +150,10 @@ YQComboBox * YQWidgetFactory::createComboBox( YWidget * parent, const string & label, bool editable ) { - return 0; // FIXME: TO DO + YQComboBox * comboBox = new YQComboBox( parent, label, editable ); + YUI_CHECK_NEW( comboBox ); + + return comboBox; } @@ -158,7 +161,10 @@ YQSelectionBox * YQWidgetFactory::createSelectionBox( YWidget * parent, const string & label ) { - return 0; // FIXME: TO DO + YQSelectionBox * selectionBox = new YQSelectionBox( parent, label ); + YUI_CHECK_NEW( selectionBox ); + + return selectionBox; } @@ -237,7 +243,6 @@ } - YQLogView * YQWidgetFactory::createLogView( YWidget * parent, const string & label, int visibleLines, int storedLines ) { @@ -246,12 +251,14 @@ -YQSelectionBox * +YQMultiSelectionBox * YQWidgetFactory::createMultiSelectionBox( YWidget * parent, const string & label ) { - return 0; // FIXME: TO DO -} + YQMultiSelectionBox * multiSelectionBox = new YQMultiSelectionBox( parent, label ); + YUI_CHECK_NEW( multiSelectionBox ); + return multiSelectionBox; +} @@ -259,7 +266,7 @@ YQWidgetFactory::createPackageSelector( YWidget * parent, long modeFlags ) { YQUI::ui()->setAutoActivateDialogs( false ); - + YQPackageSelectorPlugin * plugin = YQUI::ui()->packageSelectorPlugin(); if ( plugin ) @@ -269,7 +276,6 @@ } - YWidget * YQWidgetFactory::createPkgSpecial( YWidget * , const string & ) { Modified: branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.h?rev=39107&r1=39106&r2=39107&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.h Mon Jul 2 16:32:31 2007 @@ -37,6 +37,7 @@ #include "YQLogView.h" #include "YQMenuButton.h" #include "YQMultiLineEdit.h" +#include "YQMultiSelectionBox.h" #include "YQPackageSelector.h" #include "YQProgressBar.h" #include "YQPushButton.h" @@ -103,7 +104,7 @@ virtual YQMultiLineEdit * createMultiLineEdit ( YWidget * parent, const string & label ); virtual YQImage * createImage ( YWidget * parent, const string & imageFileName, bool animated = false ); virtual YQLogView * createLogView ( YWidget * parent, const string & label, int visibleLines, int storedLines = 0 ); - virtual YQSelectionBox * createMultiSelectionBox ( YWidget * parent, const string & label ); + virtual YQMultiSelectionBox *createMultiSelectionBox( YWidget * parent, const string & label ); virtual YQPackageSelector * createPackageSelector ( YWidget * parent, long modeFlags = 0 ); virtual YWidget * createPkgSpecial ( YWidget * parent, const string & name ); // NCurses only, will throw exception in the Qt UI -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org