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

📄 qcombobox.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		}	    }	}    } else if ( d->usingListBox() && ( object == d->listBox() ||				       object == d->listBox()->viewport() )) {	QMouseEvent *e = (QMouseEvent*)event;	switch( event->type() ) {	case QEvent::MouseMove:	    if ( !d->mouseWasInsidePopup  ) {		QPoint pos = e->pos();		if ( d->listBox()->rect().contains( pos ) )		    d->mouseWasInsidePopup = TRUE;		// Check if arrow button should toggle		// this applies only to windows style		if ( d->arrowPressed ) {		    QPoint comboPos;		    comboPos = mapFromGlobal( d->listBox()->mapToGlobal(pos) );		    if ( arrowRect().contains( comboPos ) ) {			if ( !d->arrowDown  ) {			    d->arrowDown = TRUE;			    repaint( FALSE );			}		    } else {			if ( d->arrowDown  ) {			    d->arrowDown = FALSE;			    repaint( FALSE );			}		    }		}	    } else if ((e->state() & ( RightButton | LeftButton | MidButton ) )		       == 0 && style() == WindowsStyle ){		QWidget *mouseW = QApplication::widgetAt( e->globalPos(), TRUE );		if ( mouseW == d->listBox()->viewport() ) { //###		    QMouseEvent m( QEvent::MouseMove, e->pos(), e->globalPos(),				   0, LeftButton );		    QApplication::sendEvent( object, &m ); //### Evil		    return TRUE;		}	    }	    break;	case QEvent::MouseButtonRelease:	    if ( d->listBox()->rect().contains( e->pos() ) ) {		QMouseEvent tmp( QEvent::MouseButtonDblClick,				 e->pos(), e->button(), e->state() ) ;		// will hide popup		QApplication::sendEvent( object, &tmp );		return TRUE;	    } else {		if ( d->mouseWasInsidePopup ) {		    popDownListBox();		} else {		    d->arrowPressed = FALSE;		    if ( d->arrowDown  ) {			d->arrowDown = FALSE;			repaint( FALSE );		    }		}	    }	    break;	case QEvent::MouseButtonDblClick:	case QEvent::MouseButtonPress:	    if ( !d->listBox()->rect().contains( e->pos() ) ) {#ifdef Q_WS_REPLAYSONPOPDOWN		QPoint globalPos = d->listBox()->mapToGlobal(e->pos());		if ( QApplication::widgetAt( globalPos, TRUE ) == this ) {		    d->discardNextMousePress = TRUE;		    // avoid popping up again		}#endif		popDownListBox();		return TRUE;	    }	    break;	case QEvent::KeyPress:	    switch( ((QKeyEvent *)event)->key() ) {	    case Key_Up:	    case Key_Down:		if ( !(((QKeyEvent *)event)->state() & AltButton) )		    break;	    case Key_F4:	    case Key_Escape:#ifdef QT_KEYPAD_MODE	    case Key_Back:	    case Key_No:#endif		if ( d->poppedUp ) {		    popDownListBox();		    return TRUE;		}		break;#ifdef QT_KEYPAD_MODE	    case Key_Select:#endif	    case Key_Enter:	    case Key_Return:		// work around QDialog's enter handling		return FALSE;	    default:		break;	    }	default:	    break;	}    } else if ( !d->usingListBox() && object == d->popup() ) {	QMouseEvent *e = (QMouseEvent*)event;	switch ( event->type() ) {	case QEvent::MouseButtonRelease:	    if ( d->shortClick ) {		QMouseEvent tmp( QEvent::MouseMove,				 e->pos(), e->button(), e->state() ) ;		// highlight item, but don't pop down:		QApplication::sendEvent( object, &tmp );		return TRUE;	    }	    break;	case QEvent::MouseButtonDblClick:	case QEvent::MouseButtonPress:	    if ( !d->popup()->rect().contains( e->pos() ) ) {		// remove filter, event will take down popup:		d->popup()->removeEventFilter( this );		// ### uglehack!		// call internalHighlight so the highlighed signal		// will be emitted at least as often as necessary.		// it may be called more often than necessary		internalHighlight( d->current );	    }	    break;	default:	    break;	}    }    return QWidget::eventFilter( object, event );}/*!  Returns the current maximum on-screen size of the combo box.  The  default is ten lines.  \sa setSizeLimit() count() maxCount()*/int QComboBox::sizeLimit() const{    return d ? d->sizeLimit : INT_MAX;}/*!  Sets the maximum on-screen size of the combo box to \a lines.  This  is disregarded in Motif 1.x style.  The default limit is ten lines.  If the number of items in the combo box is/grows larger than  \c lines, a list box is added.  \sa sizeLimit() count() setMaxCount()*/void QComboBox::setSizeLimit( int lines ){    d->sizeLimit = lines;}/*!  Returns the current maximum size of the combo box.  By default,  there is no limit, so this function returns INT_MAX.  \sa setMaxCount() count()*/int QComboBox::maxCount() const{    return d ? d->maxCount : INT_MAX;}/*!  Sets the maximum number of items the combo box can hold to \a count.  If \a count is smaller than the current number of items, the list is  truncated at the end.  There is no limit by default.  \sa maxCount() count()*/void QComboBox::setMaxCount( int count ){    int l = this->count();    while( --l > count )	removeItem( l );    d->maxCount = count;}/*!  Returns the current insertion policy of the combo box.  \sa setInsertionPolicy()*/QComboBox::Policy QComboBox::insertionPolicy() const{    return d->p;}/*!  Sets the insertion policy of the combo box to \a policy.  The insertion policy governs where items typed in by the user are  inserted in the list.  The possible values are <ul> <li> \c  NoInsertion: Strings typed by the user aren't inserted anywhere <li>  \c AtTop: Strings typed by the user are inserted above the top item  in the list <li> AtCurrent: Strings typed by the user replace the  last selected item <li> AtBottom: Strings typed by the user are  inserted at the bottom of the list. </ul>  The default insertion policy is \c AtBottom.  \sa insertionPolicy()*/void QComboBox::setInsertionPolicy( Policy policy ){    d->p = policy;}/*!  Internal slot to keep the line editor up to date.*/void QComboBox::returnPressed(){    QString s( d->ed->text() );    if ( s.isEmpty() ) {	d->ed->setText( text( currentItem() ) );	d->ed->selectAll();	return;    }    int c = 0;    bool doInsert = TRUE;    if ( !d->duplicatesEnabled ) {	for ( int i = 0; i < count(); ++i ) {	    if ( s == text( i ) ) {		doInsert = FALSE;		c = i;		break;	    }	}    }    if ( doInsert ) {	if ( insertionPolicy() != NoInsertion ) {	    int cnt = count();	    while ( cnt >= d->maxCount ) {		removeItem( --cnt );	    }	}		switch ( insertionPolicy() ) {	case AtCurrent:	    if ( s != text( currentItem() ) )		changeItem( s, currentItem() );	    emit activated( currentItem() );	    emit activated( s );	    return;	case NoInsertion:	    emit activated( s );	    return;	case AtTop:	    c = 0;	    break;	case AtBottom:	    c = count();	    break;	case BeforeCurrent:	    c = currentItem();	    break;	case AfterCurrent:	    c = currentItem() + 1;	    break;	}	insertItem( s, c );    }    setCurrentItem( c );    emit activated( c );    emit activated( s );}/*! \reimp*/void QComboBox::setEnabled( bool enable ){    QWidget::setEnabled( enable );}/*!  Sets this combo box to be editable only as allowed by \a v.  This function does nothing if the combo is not editable.  \sa validator() clearValidator() QValidator*/void QComboBox::setValidator( const QValidator * v ){    if ( d && d->ed )	d->ed->setValidator( v );}/*!  Returns the validator which constrains editing for this combo  box if there is any, or else 0.  \sa setValidator() clearValidator() QValidator*/const QValidator * QComboBox::validator() const{    return d && d->ed ? d->ed->validator() : 0;}/*!  This slot is equivalent to setValidator( 0 ). */void QComboBox::clearValidator(){    if ( d && d->ed )	d->ed->setValidator( 0 );}/*!  Sets the combo box to use \a newListBox instead of the current  list box or popup.  As a side effect, clears the combo box of its  current contents.  \warning QComboBox assumes that newListBox->text(n) returns  non-null for 0 \<= n \< newListbox->count().  This assumption is  necessary because of the line edit in QComboBox.*/void QComboBox::setListBox( QListBox * newListBox ){    clear();    if ( d->usingListBox() )	delete d->listBox();    else	delete d->popup();    newListBox->reparent( 0, WType_Popup, QPoint(0,0), FALSE );    d->setListBox( newListBox );    d->listBox()->setFont( font() );    d->listBox()->setAutoScrollBar( FALSE );    d->listBox()->setBottomScrollBar( FALSE );    d->listBox()->setAutoBottomScrollBar( FALSE );    d->listBox()->setFrameStyle( QFrame::Box | QFrame::Plain );    d->listBox()->setLineWidth( 1 );    d->listBox()->resize( 100, 10 );    connect( d->listBox(), SIGNAL(selected(int)),	     SLOT(internalActivate(int)) );    connect( d->listBox(), SIGNAL(highlighted(int)),	     SLOT(internalHighlight(int)));}/*!  Returns the current list box, or 0 if there is no list box  currently.  (QComboBox can use QPopupMenu instead of QListBox.)  Provided to match setListBox().  \sa setListBox()*/QListBox * QComboBox::listBox() const{    return d && d->usingListBox() ? d->listBox() : 0;}/*!  Returns the line editor, or 0 if there is no line editor currently.  Only editable listboxes have a line editor. */QLineEdit* QComboBox::lineEdit() const{    return d->ed;}/*!  Clears the line edit without changing the combo's contents.  Does  nothing if the combo isn't editable.  This is particularly handy when using a combo box as a line edit  with history.  For example you can connect the combo's activated()  signal to clearEdit() in order to present the user with a new, empty  line as soon as return is pressed.  \sa setEditText()*/void QComboBox::clearEdit(){    if ( d && d->ed )	d->ed->clear();}/*!  Sets the text in the embedded line edit to \a newText without  changing the combo's contents.  Does nothing if the combo isn't  editable.  This is useful e.g. for providing a good starting point for the  user's editing and entering the change in the combo only when the  user presses enter.  \sa clearEdit() insertItem()*/void QComboBox::setEditText( const QString &newText ){    if ( d && d->ed ) {	d->updateLinedGeometry();	d->ed->setText( newText );    }}/*!  Sets this combo box to offer auto-completion while the user is  editing if \a enable is TRUE, or not to offer auto-completion of \a  enable is FALSE (the default).  The combo box uses the list of items as candidates for completion.  Note: This will only work on editable combo boxes, so make the combo  box editable before you call this function or it will not work.  \sa autoCompletion() setEditText()*/void QComboBox::setAutoCompletion( bool enable ){    d->useCompletion = enable;    d->completeNow = FALSE;}/*!  Returns TRUE if this combo box is in auto-completion mode.  \sa setAutoCompletion()*/bool QComboBox::autoCompletion() const{    return d->useCompletion;}/*!\reimp */void QComboBox::styleChange( QStyle& s ){    d->sizeHint = QSize();  // Invalidate Size Hint    if ( d->ed )	d->updateLinedGeometry();    QWidget::styleChange( s );}/*!  Returns whether the combobox is editable or not.  \sa setEditable() */bool QComboBox::editable() const{    return d->ed != 0;}/*!  Make the input field editable, if \a y is TRUE. Otherwise the user  may only choose one of the items in the combo box.  \sa editable() */void QComboBox::setEditable( bool y ){    if ( y == editable() )	return;    if ( y ) {	if ( !d->usingListBox() )	    setUpListBox();	setUpLineEdit();	d->ed->show();    } else {	delete d->ed;	d->ed = 0;    }    setFocusPolicy( StrongFocus );    updateGeometry();    update();}void QComboBox::setUpListBox(){    d->setListBox( new QListBox( this, "in-combo", WType_Popup ) );    d->listBox()->setFont( font() );    d->listBox()->setAutoScrollBar( FALSE );    d->listBox()->setBottomScrollBar( FALSE );    d->listBox()->setAutoBottomScrollBar( FALSE );    d->listBox()->setFrameStyle( QFrame::Box | QFrame::Plain );    d->listBox()->setLineWidth( 1 );    d->listBox()->resize( 100, 10 );    connect( d->listBox(), SIGNAL(selected(int)),	     SLOT(internalActivate(int)) );    connect( d->listBox(), SIGNAL(highlighted(int)),	     SLOT(internalHighlight(int)));}void QComboBox::setUpLineEdit(){    d->ed = new QLineEdit( this, "combo edit" );    connect (d->ed, SIGNAL( textChanged(const QString&) ),	     this, SIGNAL( textChanged(const QString&) ) );    d->ed->setFrame( FALSE );    d->updateLinedGeometry();    d->ed->installEventFilter( this );    setFocusProxy( d->ed );    connect( d->ed, SIGNAL(returnPressed()), SLOT(returnPressed()) );}#endif // QT_NO_COMBOBOX

⌨️ 快捷键说明

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