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

📄 categoryselect.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    setCategories( vl, appName, visibleName );}/*!  \overload  This constructor accepts an array \a vl of integers representing Categories.  \a appName is used as the visible name string.    \a width is an integer used as the fixed width of the widget.    The \a parent and \a name parameters are the standard Qt parent parameters.*/CategorySelect::CategorySelect( const QArray<int> &vl,				const QString &appName, QWidget *parent,				const char *name ,int width)    : QHBox( parent, name ),      cmbCat( 0 ),      cmdCat( 0 ),      d( 0 ){    init(width);    setCategories( vl, appName, appName );}/*!  Constructs a category selector with parent \a parent, name \a name and  fixed width \a width.  This constructor is provided to make integration with Qt Designer easier.*/CategorySelect::CategorySelect( QWidget *parent, const char *name,int width)    : QHBox( parent, name ),      cmbCat( 0 ),      cmdCat( 0 ),      d( 0 ){    init(width);}/*!  Destructs a CategorySelect widget.*/CategorySelect::~CategorySelect(){}// ===========================================================================class EditDlg : public QDialog{    Q_OBJECTpublic:    EditDlg(QWidget *parent, const char *name, bool modal,	    const QArray<int> &vlRecs, const QString &appName, const QString &visibleName)	: QDialog(parent, name, modal)    {	setCaption( tr("Categories") );	QVBoxLayout *vb = new QVBoxLayout( this );	ce = new CategoryEdit( vlRecs, appName, visibleName, this );	vb->addWidget( ce );#ifdef QTOPIA_DESKTOP	QWidget *buttons = new QWidget( this );	QGridLayout *gl = new QGridLayout( buttons );	QSpacerItem *spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding );	QPushButton *ok = new QPushButton( tr("OK"), buttons );	QPushButton *cancel = new QPushButton( tr("Cancel"), buttons );	gl->addItem( spacer, 0, 0 );	gl->addWidget( ok, 0, 1 );	gl->addWidget( cancel, 0, 2 );	vb->addWidget( buttons );	connect( ok, SIGNAL(clicked()), this, SLOT(accept()) );	connect( cancel, SIGNAL(clicked()), this, SLOT(reject()) );	setCaption( tr("Edit Categories") );#endif    }    QArray<int> newCategories() { return ce->newCategories(); };protected:    void accept()    {	if ( !ce->tryAccept() )	    return;	QDialog::accept();    }private:    CategoryEdit *ce;};// ===========================================================================/*!  This slot is called when the user pushes the button to edit Categories.*/void CategorySelect::slotDialog(){#ifdef QTOPIA_DESKTOP    emit editCategoriesClicked(this);    categoriesChanged();#else    EditDlg editDlg( this, "categories", TRUE, d->mChosen, mStrAppName, d->mVisibleName ); // No tr    editDlg.showMaximized();    d->editMode = TRUE;    if ( editDlg.exec() ) {	d->mChosen = editDlg.newCategories();	if ( d->type == ComboBox ) {	    cmbCat->initCombo( d->mChosen, mStrAppName, d->mVisibleName );	    if ( d->usingAll ) {		cmbCat->insertItem( tr( "All" ), cmbCat->count() );	    } else {		if ( d->mChosen.count() > 1 ) {		    cmbCat->insertItem( tr( "(multi) ..." ), cmbCat->count() );		    d->setComboItem( cmbCat, cmbCat->count() - 1 );		} else		    cmbCat->insertItem( tr( "..." ), cmbCat->count() );	    }	    d->lastCat = cmbCat->currentItem();	} else {	    QArray<int> t = d->mChosen;	    d->cats.load( categoryFileName() );	    d->pruneDeletedCats(t);	    d->reloadCatSelector( t );	}    } else if ( !d->usingAll ) {	d->setComboItem( cmbCat, d->lastCat );    }#endif}/*!  This slot is called when the available Categories have been changed.*/void CategorySelect::categoriesChanged(){    if ( d->editMode ) {	//only one can edit at a time, so if we're the one we can ignore this signal	// as it will be handled in slotDialog	d->editMode = FALSE;    } else {	if ( d->type == ComboBox ) {	    int prevCat = cmbCat->currentCategory();	    cmbCat->initComboWithRefind( d->mChosen, mStrAppName );	    if ( d->usingAll ) {		cmbCat->insertItem( tr( "All" ), cmbCat->count() );	    } else {		if ( d->mChosen.count() > 1 ) {		    cmbCat->insertItem( tr( "(multi) ..." ), cmbCat->count() );		    d->setComboItem( cmbCat, cmbCat->count() - 1 );		} else		    cmbCat->insertItem( tr( "..." ), cmbCat->count() );	    }	    cmbCat->setCurrentCategory( prevCat );	    // Test if category is still valid.  If it isn't we need to inform our parent about a selection change	    if ( cmbCat->currentCategory() != prevCat ) {		cmbCat->setCurrentCategory(-1);		emit signalSelected( cmbCat->currentCategory() );	    }	}	else {	    QArray<int> t = d->mChosen;	    d->cats.load( categoryFileName() );	    d->pruneDeletedCats(t);	    d->reloadCatSelector( t );	}    }}/*!  This slot is called when a new Category is available,  passing the \a newUid created.*/void CategorySelect::slotNewCat( int newUid ){    if ( !d->usingAll ) {	// This is for handling the '...' entry	if ( newUid == -2 ) {	    if ( d->pendingCategorySets == 0 ) {		slotDialog();	    }	    return;	}	d->lastCat = cmbCat->currentItem();    }    if ( newUid != -1 && newUid != -2 ) {	bool alreadyIn = false;	for ( uint it = 0; it < d->mChosen.count(); ++it ) {	    if ( d->mChosen[(int)it] == newUid ) {		alreadyIn = true;		break;	    }	}	if ( !alreadyIn ) {	    d->mChosen.resize( 1 );	    d->mChosen[ 0 ] = newUid;	}    } else    d->mChosen.resize(0);  // now Unfiled.    emit signalSelected( currentCategory() );}/*!  \overload  Resets the CategorySelect to select \a cats as  the Categories associated with \a appName.  This function should only be called if <i>filtering</i>  on Categories and not selecting and therefore possibly  allowing the user to edit Categories.*/QString CategorySelect::setCategories( const QArray<int> &cats,				    const QString &appName ){    return setCategories( cats, appName, appName );}/*!  Resets the CategorySelect to select the \a cals for  the Categories assoicated with \a appName and displays  the \a visibleName if the user is selecting and therefore editing  new Categories. */QString CategorySelect::setCategories( const QArray<int> &cals,				    const QString &appName,				    const QString &visibleName ){    d->mVisibleName = visibleName;    mStrAppName = appName;    d->appName = appName;    if ( d->type == ComboBox ) {	d->mChosen = cmbCat->initComboWithRefind( cals, appName );	if ( d->usingAll ) {	    cmbCat->insertItem( tr( "All" ), cmbCat->count() );	} else {	    if ( d->mChosen.count() > 1 ) {		cmbCat->insertItem( tr( "(multi) ..." ), cmbCat->count() );		d->setComboItem( cmbCat, cmbCat->count() - 1 );	    } else		cmbCat->insertItem( tr( "..." ), cmbCat->count() );	}	d->lastCat = cmbCat->currentItem();    } else {	d->mChosen = cals.copy();	d->reloadCatSelector();    }    return Qtopia::Record::idsToString(d->mChosen);}void CategorySelect::init(int width){    if ( d ) {	delete d->layout;	delete d->container;	d->setType();    } else {	d = new CategorySelectPrivate( this );    }    d->container = new QWidget( this ); // No tr    if ( d->type == ComboBox ) {	d->layout = new QGridLayout( d->container );	cmbCat = new CategoryCombo( d->container, 0, width); // No tr	d->layout->addWidget( cmbCat, 0, 0 );	QObject::connect( cmbCat, SIGNAL(sigCatChanged(int)),			  this, SLOT(slotNewCat(int)) );	if ( d->canEdit && d->usingAll ) {	    cmdCat = new QToolButton( d->container ); // No tr	    d->layout->addWidget( cmdCat, 0, 1 );	    cmdCat->setTextLabel( "...", FALSE );	    cmdCat->setFocusPolicy( TabFocus );	    cmdCat->setFixedHeight( cmbCat->sizeHint().height() );	    cmdCat->setUsesTextLabel( true );	    QObject::connect( cmdCat, SIGNAL(clicked()), this, SLOT(slotDialog()) );	}    } else {	d->layout = new QGridLayout( d->container, 2, 2 );	d->cats.load( categoryFileName() );	d->catSelector = new QListView( d->container, "catSelector" );	d->catSelector->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );	d->catSelector->addColumn( tr("Categories") );	d->catSelector->setSelectionMode( QListView::NoSelection );	d->catSelector->header()->hide();	d->layout->addMultiCellWidget( d->catSelector, 0, 0, 0, 1 );	QSpacerItem *horiSpacer = new QSpacerItem( 1, 1, QSizePolicy::Expanding,						   QSizePolicy::Expanding );	d->layout->addItem( horiSpacer, 1, 0 );	d->editButton = new QPushButton( tr("Edit Categories"), d->container );	d->layout->addWidget( d->editButton, 1, 1 );	connect( d->catSelector, SIGNAL( clicked(QListViewItem*) ), d, SLOT( itemClicked(QListViewItem*) ) );	connect( d->catSelector, SIGNAL( spacePressed(QListViewItem*) ), d, SLOT( itemClicked(QListViewItem*) ) );	connect( d->editButton, SIGNAL( clicked() ), SLOT( slotDialog() ) );    }#ifndef QTOPIA_DESKTOP    connect(qApp, SIGNAL( categoriesChanged() ), this, SLOT( categoriesChanged() ) );#endif    d->fixedWidth = width;}/*!  Return the value of the currently selected category. */int CategorySelect::currentCategory() const{    if ( d->type == ComboBox )	return cmbCat->currentCategory();    return currentCategories()[0];}void CategorySelect::setCurrentCategory( int newCatUid ){    if ( d->type == ComboBox ) {	cmbCat->setCurrentCategory( newCatUid );    } else {	CategoryCheckListItem *i = (CategoryCheckListItem*)d->catSelector->firstChild();	while (i) {	    if ( i->id == newCatUid ) {		i->setOn(TRUE);		break;	    }	    i = (CategoryCheckListItem*)i->nextSibling();	}    }}/*!  Returns a shallow copy of the categories in this CategorySelect. */const QArray<int> &CategorySelect::currentCategories() const{    return d->mChosen;}/*!  Hides the edit section of the CategorySelect widget if \a remove is TRUE. */void CategorySelect::setRemoveCategoryEdit( bool remove ){    d->canEdit = !remove;    if ( !cmdCat )	return;    if ( remove ) {	cmdCat->setEnabled( FALSE );	cmdCat->hide();    } else {	cmdCat->setEnabled( TRUE );	cmdCat->show();    }}/*!  Changes this CategorySelect to the All category if \a all is TRUE. */void CategorySelect::setAllCategories( bool all ){    // if showing all category, then that means the    // user isn't just selecting    bool createCmb = FALSE;    bool reinit = FALSE;    if ( d->usingAll != all ) {	reinit = TRUE;	if ( d->catSelector )	    createCmb = TRUE;    }    if ( reinit ) {	d->usingAll = all;	init( d->fixedWidth );	setCategories( d->mChosen, d->appName, d->mVisibleName );    }    if ( cmdCat ) {	QString qpe_translateLabel(const QString&);	QString allcat = qpe_translateLabel("_All");	if ( all ) {	    cmbCat->insertItem( allcat, cmbCat->count() );	} else if ( !createCmb && cmbCat->text( cmbCat->count()-1) == allcat ) { // ugly	    cmbCat->removeItem( cmbCat->count() - 1 );	}    }    if ( all )	cmbCat->setCurrentItem( cmbCat->count() - 1 );}// 01.12.21 added/*!  Sets the fixed width of the widget to \a width.  */void CategorySelect::setFixedWidth(int width){    if ( d->type == ComboBox ) {	width -= cmdCat->width();	cmbCat->setFixedWidth(width);    }    else  d->catSelector->setFixedWidth( width );    d->fixedWidth = width;}#include "categoryselect.moc"

⌨️ 快捷键说明

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