⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qcombobox.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if ( d->usingListBox() )	    d->listBox()->insertItem( *it, index );	else	    d->popup()->insertItem( *it, index, index );	if ( index++ == d->current && d->current < count() ) {	    if ( d->ed ) {		d->ed->setText( text( d->current ) );		d->updateLinedGeometry();	    } else		update();	    currentChanged();	}	++it;    }    if ( index != count() )	reIndex();}/*!  Inserts the array of ASCII strings at the index \e index in the combo box.  The \e numStrings argument is the number of strings.  If \e numStrings is -1 (default), the \e strs array must be  terminated with 0.  Example:  \code    static const char* items[] = { "red", "green", "blue", 0 };    combo->insertStrList( items );  \endcode*/void QComboBox::insertStrList( const char **strings, int numStrings, int index){    if ( !strings ) {#if defined(CHECK_NULL)	ASSERT( strings != 0 );#endif	return;    }    if ( index < 0 )	index = count();    int i = 0;    while ( (numStrings<0 && strings[i]!=0) || i<numStrings ) {	if ( d->usingListBox() )	    d->listBox()->insertItem( QString::fromLatin1(strings[i]), index );	else	    d->popup()->insertItem( QString::fromLatin1(strings[i]), index, index );	i++;	if ( index++ == d->current && d->current < count()  ) {	    if ( d->ed ) {		d->ed->setText( text( d->current ) );		d->updateLinedGeometry();	    } else		update();	    currentChanged();	}    }    if ( index != count() )	reIndex();}/*!  Inserts a text item at position \e index. The item will be appended if  \e index is negative.*/void QComboBox::insertItem( const QString &t, int index ){    int cnt = count();    if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) )	return;    if ( d->usingListBox() )	d->listBox()->insertItem( t, index );    else	d->popup()->insertItem( t, index, index );    if ( index != cnt )	reIndex();    if ( index == d->current && d->current < count()  ) {	if ( d->ed ) {	    d->ed->setText( text( d->current ) );	    d->updateLinedGeometry();	} else	    update();    }    if ( index == d->current )	currentChanged();}/*!  Inserts a pixmap item at position \e index. The item will be appended if  \e index is negative.*/void QComboBox::insertItem( const QPixmap &pixmap, int index ){    int cnt = count();    if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) )	return;    if ( d->usingListBox() )	d->listBox()->insertItem( pixmap, index );    else	d->popup()->insertItem( pixmap, index, index );    if ( index != cnt )	reIndex();    if ( index == d->current && d->current < count()  ) {	if ( d->ed ) {	    d->ed->setText( text( d->current ) );	    d->updateLinedGeometry();	} else	    update();    }    if ( index == d->current )	currentChanged();}/*!  Inserts a pixmap item with additional text \a text at position \e  index. The item will be appended if \e index is negative.*/void QComboBox::insertItem( const QPixmap &pixmap, const QString& text, int index ){    int cnt = count();    if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) )	return;    if ( d->usingListBox() )	d->listBox()->insertItem( pixmap, text, index );    else	d->popup()->insertItem( pixmap, text, index, index );    if ( index != cnt )	reIndex();    if ( index == d->current && d->current < count()  ) {	if ( d->ed ) {	    d->ed->setText( this->text( d->current ) );	    d->updateLinedGeometry();	} else	    update();    }    if ( index == d->current )	currentChanged();}/*!  Removes the item at position \e index.*/void QComboBox::removeItem( int index ){    int cnt = count();    if ( !checkIndex( "removeItem", name(), cnt, index ) )	return;    if ( d->usingListBox() )	d->listBox()->removeItem( index );    else	d->popup()->removeItemAt( index );    if ( index != cnt-1 )	reIndex();    if ( index == d->current ) {	if ( d->ed ) {	    QString s = QString::fromLatin1("");	    if (d->current < cnt - 1)		s = text( d->current );	    d->ed->setText( s );	    d->updateLinedGeometry();	}	else {	    if ( d->usingListBox() )		d->current = d->listBox()->currentItem();	    else {		if (d->current > count()-1 && d->current > 0)		    d->current--;	    }	    update();	}	currentChanged();    }    else {        if ( !d->ed ) {            if (d->current < cnt - 1)                setCurrentItem( d->current );            else                setCurrentItem( d->current - 1 );        }    }}/*!  Removes all combo box items.*/void QComboBox::clear(){    if ( d->usingListBox() ) {	d->listBox()->resize( 0, 0 );	d->listBox()->clear();    } else {	d->popup()->clear();    }    d->current = 0;    if ( d->ed ) {	d->ed->setText( QString::fromLatin1("") );	d->updateLinedGeometry();    }    currentChanged();}/*!  Returns the text item being edited, or the current text item if the combo  box is not editable.  \sa text()*/QString QComboBox::currentText() const{    if ( d->ed )	return d->ed->text();    else if ( d->current < count() )	return text( currentItem() );    else	return QString::null;}/*!  Returns the text item at a given index, or  \link QString::operator!() null string\endlink  if the item is not a string.  \sa currentText()*/QString QComboBox::text( int index ) const{    if ( !checkIndex( "text", name(), count(), index ) )	return QString::null;    if ( d->usingListBox() )	return d->listBox()->text( index );    else	return d->popup()->text( index );}/*!  Returns the pixmap item at a given index, or 0 if the item is not a pixmap.*/const QPixmap *QComboBox::pixmap( int index ) const{    if ( !checkIndex( "pixmap", name(), count(), index ) )	return 0;    if ( d->usingListBox() )	return d->listBox()->pixmap( index );    else	return d->popup()->pixmap( index );}/*!  Replaces the item at position \e index with a text.*/void QComboBox::changeItem( const QString &t, int index ){    if ( !checkIndex( "changeItem", name(), count(), index ) )	return;    if ( d->usingListBox() )	d->listBox()->changeItem( t, index );    else	d->popup()->changeItem( t, index );    if ( index == d->current ) {	if ( d->ed ) {	    d->ed->setText( text( d->current ) );	    d->updateLinedGeometry();	} else	    update();    }}/*!  Replaces the item at position \e index with a pixmap, unless the  combo box is writable.  \sa insertItem()*/void QComboBox::changeItem( const QPixmap &im, int index ){    if ( !checkIndex( "changeItem", name(), count(), index ) )	return;    if ( d->usingListBox() )	d->listBox()->changeItem( im, index );    else	d->popup()->changeItem( im, index );    if ( index == d->current )	update();}/*!  Replaces the item at position \e index with a pixmap plus text.  \sa insertItem()*/void QComboBox::changeItem( const QPixmap &im, const QString &t, int index ){    if ( !checkIndex( "changeItem", name(), count(), index ) )	return;    if ( d->usingListBox() )	d->listBox()->changeItem( im, t, index );    else	d->popup()->changeItem( im, t, index );    if ( index == d->current )	update();}/*!  Returns the index of the current combo box item.  \sa setCurrentItem()*/int QComboBox::currentItem() const{    return d->current;}/*!  Sets the current combo box item.  This is the item to be displayed on the combo box button.  \sa currentItem()*/void QComboBox::setCurrentItem( int index ){    if ( index == d->current && !d->ed ) {	    return;    }    if ( !checkIndex( "setCurrentItem", name(), count(), index ) ) {	return;    }    d->current = index;    if ( d->ed ) {	d->ed->setText( text( index ) );	d->updateLinedGeometry();    }    if ( d->poppedUp && d->usingListBox() && d->listBox() )	d->listBox()->setCurrentItem( index );    else	internalHighlight( index );    currentChanged();}/*! \obsolete  Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing is  disabled.  Auto-resizing is disabled by default.  \sa setAutoResize()*/bool QComboBox::autoResize() const{    return d->autoresize;}/*! \obsolete  Enables auto-resizing if \e enable is TRUE, or disables it if \e enable is  FALSE.  When auto-resizing is enabled, the combo box button will resize itself  whenever the current combo box item change.  \sa autoResize(), adjustSize()*/void QComboBox::setAutoResize( bool enable ){    if ( (bool)d->autoresize != enable ) {	d->autoresize = enable;	if ( enable )	    adjustSize();    }}/*!\reimp*/QSize QComboBox::sizeHint() const{    if ( isVisibleTo(0) && d->sizeHint.isValid() )	return d->sizeHint;    constPolish();    int i, w, h;    QFontMetrics fm = fontMetrics();    int maxW = count() ? 18 : 7 * fm.width(QChar('x')) + 18;    int maxH = QMAX( fm.lineSpacing() + 2, 12 );    for( i = 0; i < count(); i++ ) {	if ( d->usingListBox() ) {	    w = d->listBox()->item( i )->width( d->listBox() );	    h = d->listBox()->item( i )->height( d->listBox() );	}	else {	    h = d->popup()->itemHeight( i );	    w = d->popup()->sizeHint().width() - 2* d->popup()->frameWidth();	}	if ( w > maxW )	    maxW = w;	if ( h > maxH )	    maxH = h;    }    int sw, sh;    if ( d->usingListBox() ) {	int fm = style().pixelMetric(QStyle::ComboBoxFocusMargin); // 1	int hm = style().pixelMetric(QStyle::ComboBoxTextHMargin); // 2	int vm = style().pixelMetric(QStyle::ComboBoxTextVMargin); // 1	int xvm = style().pixelMetric(QStyle::ComboBoxTextVMarginExtra); // 1	sw = (fm+hm+1)*2 + maxW;	sh = (fm+vm+xvm)*2 + 4 + maxH;	QRect cr = style().comboButtonRect( 0, 0, sw, sh );	sw += sw - cr.width();    } else {	//hardcoded values for motif 1.x style	int extraW = 20+5;	sw = 4 + 4 + maxW + extraW;	sh = 5 + 5 + maxH;    }    int il = style().pixelMetric(QStyle::IdealHeightLimit); // 25    int ih = style().pixelMetric(QStyle::IdealHeight); // 22    if ( sh <= il+5 && style() == WindowsStyle || parentWidget() &&	 ( parentWidget()->inherits( "QToolBar" ) ) )	sh = ih;    d->sizeHint = QSize( sw, sh ).expandedTo( QApplication::globalStrut() );    return d->sizeHint;}/*!\reimp*/QSizePolicy QComboBox::sizePolicy() const{    //### removeme 3.0    return QWidget::sizePolicy();}/*!  \internal  Receives activated signals from an internal popup list and emits  the activated() signal.*/void QComboBox::internalActivate( int index ){    if ( d->current != index ) {	d->current = index;	currentChanged();    }    if ( d->usingListBox() )	popDownListBox();    else	d->popup()->removeEventFilter( this );    d->poppedUp = FALSE;    QString t( text( index ) );    if ( d->ed ) {	d->ed->setText( t );	d->updateLinedGeometry();    }    emit activated( index );    emit activated( t );}/*!  \internal  Receives highlighted signals from an internal popup list and emits  the highlighted() signal.*/void QComboBox::internalHighlight( int index ){    emit highlighted( index );    QString t = text( index );    if ( !t.isNull() )	emit highlighted( t );}/*!  \internal  Receives timeouts after a click. Used to decide if a Motif style  popup should stay up or not after a click.*/void QComboBox::internalClickTimeout(){    d->shortClick = FALSE;}/*!  Reimplements QWidget::setBackgroundColor().  Sets the background color for both the combo box button and the  combo box popup list.*/void QComboBox::setBackgroundColor( const QColor &color ){    QWidget::setBackgroundColor( color );    if ( !d->usingListBox() )	d->popup()->setBackgroundColor( color );}/*!  Reimplements QWidget::setPalette().  Sets the palette for both the combo box button and the  combo box popup list.*/void QComboBox::setPalette( const QPalette &palette ){    QWidget::setPalette( palette );    if ( d->usingListBox() )	d->listBox()->setPalette( palette );    else	d->popup()->setPalette( palette );}/*!  Reimplements QWidget::setFont().  Sets the font for both the combo box button and the  combo box popup list.*/void QComboBox::setFont( const QFont &font ){    d->sizeHint = QSize();  // Invalidate Size Hint

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -