[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
participants (1)
-
sh-sh-sh@svn.opensuse.org