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

📄 q3combobox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	case QEvent::Hide:	    popDownListBox();	    break;	default:	    break;	}    } else if ( (!d->usingListBox() || style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) &&		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() ) ) {                d->poppedUp = false;                d->arrowDown = false;		// 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;	case QEvent::Hide:	    d->poppedUp = false;	    break;	default:	    break;	}    }    return QWidget::eventFilter( object, event );}/*!    Returns the index of the first item \e after \a startingAt of    which \a prefix is a case-insensitive prefix. Returns -1 if no    items start with \a prefix.*/int Q3ComboBox::completionIndex( const QString & prefix,				int startingAt = 0 ) const{    int start = startingAt;    if ( start < 0 || start >= count() )	start = 0;    if ( start >= count() )	return -1;    QString match = prefix.lower();    if ( match.length() < 1 )	return start;    QString current;    int i = start;    do {	current = text( i ).lower();	if ( current.startsWith( match ) )	    return i;	i++;	if ( i == count() )	    i = 0;    } while ( i != start );    return -1;}int Q3ComboBox::sizeLimit() const{    return d ? d->sizeLimit : INT_MAX;}void Q3ComboBox::setSizeLimit( int lines ){    d->sizeLimit = lines;}int Q3ComboBox::maxCount() const{    return d ? d->maxCount : INT_MAX;}void Q3ComboBox::setMaxCount( int count ){    int l = this->count();    while( --l > count )	removeItem( l );    d->maxCount = count;}Q3ComboBox::Policy Q3ComboBox::insertionPolicy() const{    return d->p;}void Q3ComboBox::setInsertionPolicy( Policy policy ){    d->p = policy;}/*!  Internal slot to keep the line editor up to date.*/void Q3ComboBox::returnPressed(){    QString s( d->ed->text() );    if ( s.isEmpty() )	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() != NoInsert ) {	    int cnt = count();	    while ( cnt >= d->maxCount ) {		removeItem( --cnt );	    }	}	switch ( insertionPolicy() ) {	case InsertAtCurrent:	    if (count() == 0)		insertItem(s);	    else if ( s != text( currentItem() ) )		changeItem( s, currentItem() );	    emit activated( currentItem() );	    emit activated( s );	    return;	case NoInsert:	    emit activated( s );	    return;	case InsertAtTop:	    c = 0;	    break;	case InsertAtBottom:	    c = count();	    break;	case InsertBeforeCurrent:	    c = currentItem();	    break;	case InsertAfterCurrent:	    c = count() == 0 ? 0 : currentItem() + 1;	    break;	}	insertItem( s, c );    }    setCurrentItem( c );    emit activated( c );    emit activated( s );}/*!  Enables the combobox if \a enable is true; otherwise disables it.  \sa QWidget::enabled*/void Q3ComboBox::setEnabled( bool enable ){    if ( !enable ) {	if ( d->usingListBox() ) {	    popDownListBox();	} else {	    d->popup()->removeEventFilter( this );	    d->popup()->close();	    d->poppedUp = false;	}    }    QWidget::setEnabled( enable );}/*!    Applies the validator \a v to the combobox so that only text which    is valid according to \a v is accepted.    This function does nothing if the combobox is not editable.    \sa validator() clearValidator() QValidator*/void Q3ComboBox::setValidator( const QValidator * v ){    if ( d && d->ed )	d->ed->setValidator( v );}/*!    Returns the validator which constrains editing for this combobox    if there is one; otherwise returns 0.    \sa setValidator() clearValidator() QValidator*/const QValidator * Q3ComboBox::validator() const{    return d && d->ed ? d->ed->validator() : 0;}/*!    This slot is equivalent to setValidator( 0 ).*/void Q3ComboBox::clearValidator(){    if ( d && d->ed )	d->ed->setValidator( 0 );}/*!    Sets the combobox to use \a newListBox instead of the current list    box or popup. As a side effect, it clears the combobox of its    current contents.    \warning Q3ComboBox assumes that newListBox->text(n) returns    non-null for 0 \<= n \< newListbox->count(). This assumption is    necessary because of the line edit in Q3ComboBox.*/void Q3ComboBox::setListBox( Q3ListBox * newListBox ){    clear();    if ( d->usingListBox() ) {	delete d->listBox();    } else {	delete d->popup();        d->setPopupMenu(0, false);    }    newListBox->reparent( this, Qt::WType_Popup, QPoint(0,0), false );    d->setListBox( newListBox );    d->listBox()->setFont( font() );    d->listBox()->setPalette( palette() );    d->listBox()->setVScrollBarMode(Q3ScrollView::AlwaysOff);    d->listBox()->setHScrollBarMode(Q3ScrollView::AlwaysOff);    d->listBox()->setFrameStyle( Q3Frame::Box | Q3Frame::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.    (Q3ComboBox can use QPopupMenu instead of QListBox.) Provided to    match setListBox().    \sa setListBox()*/Q3ListBox * Q3ComboBox::listBox() const{    return d && d->usingListBox() ? d->listBox() : 0;}/*!    Returns the line edit, or 0 if there is no line edit.    Only editable listboxes have a line editor.*/QLineEdit* Q3ComboBox::lineEdit() const{    return d->ed;}/*!    Clears the line edit without changing the combobox's contents.    Does nothing if the combobox isn't editable.    This is particularly useful when using a combobox as a line edit    with history. For example you can connect the combobox's    activated() signal to clearEdit() in order to present the user    with a new, empty line as soon as Enter is pressed.    \sa setEditText()*/void Q3ComboBox::clearEdit(){    if ( d && d->ed )	d->ed->clear();}/*!    Sets the text in the line edit to \a newText without changing the    combobox's contents. Does nothing if the combobox 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 combobox only when    the user presses Enter.    \sa clearEdit() insertItem()*/void Q3ComboBox::setEditText( const QString &newText ){    if ( d && d->ed ) {	d->updateLinedGeometry();	d->ed->setText( newText );    }}void Q3ComboBox::setAutoCompletion( bool enable ){    d->useCompletion = enable;    d->completeNow = false;}bool Q3ComboBox::autoCompletion() const{    return d->useCompletion;}/*!\reimp */void Q3ComboBox::styleChange( QStyle& s ){    d->sizeHint = QSize();		// invalidate size hint...    if ( d->ed )	d->updateLinedGeometry();    QWidget::styleChange( s );}bool Q3ComboBox::editable() const{    return d->ed != 0;}void Q3ComboBox::setEditable( bool y ){    if ( y == editable() )	return;    if ( y ) {	if ( !d->usingListBox() )	    setUpListBox();	setUpLineEdit();	d->ed->show();	if ( currentItem() )	    setEditText( currentText() );    } else {	delete d->ed;	d->ed = 0;    }    setFocusPolicy(Qt::StrongFocus);    updateGeometry();    update();}void Q3ComboBox::setUpListBox(){    d->setListBox( new Q3ListBox( this, "in-combo", Qt::WType_Popup ) );    d->listBox()->setFont( font() );    d->listBox()->setPalette( palette() );    d->listBox()->setVScrollBarMode( Q3ListBox::AlwaysOff );    d->listBox()->setHScrollBarMode( Q3ListBox::AlwaysOff );    d->listBox()->setFrameStyle( Q3Frame::Box | Q3Frame::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 Q3ComboBox::setUpLineEdit(){    if ( !d->ed )	setLineEdit( new QLineEdit( this, "combo edit" ) );}/*!    Sets the line edit to use \a edit instead of the current line edit.*/void Q3ComboBox::setLineEdit( QLineEdit *edit ){    if ( !edit ) {#if defined(QT_CHECK_NULL)	Q_ASSERT( edit != 0 );#endif	return;    }    edit->setText( currentText() );    delete d->ed;    d->ed = edit;    if ( edit->parent() != this )	edit->reparent( this, QPoint(0,0), false );    connect (edit, SIGNAL(textChanged(QString)),	     this, SIGNAL(textChanged(QString)) );    connect( edit, SIGNAL(returnPressed()), SLOT(returnPressed()) );    edit->setFrame( false );    d->updateLinedGeometry();    edit->installEventFilter( this );    setFocusProxy( edit );    setFocusPolicy(Qt::StrongFocus);    setInputMethodEnabled( true );    if ( !d->usingListBox() )	setUpListBox();    if ( isVisible() )	edit->show();    updateGeometry();    update();}/*!  Hides the combobox.  \sa QWidget::hide()*/void Q3ComboBox::hide(){    QWidget::hide();    if (listBox())	listBox()->hide();    else if (d->popup())	d->popup()->hide();}#endif // QT_NO_COMBOBOX

⌨️ 快捷键说明

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