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

📄 propertyeditor.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void PropertyTimeItem::setValue(){    setText( 1, lined()->time().toString( ::Qt::ISODate ) );    QVariant v;    v = lined()->time();    PropertyItem::setValue( v );    notifyValueChange();}// --------------------------------------------------------------PropertyDateTimeItem::PropertyDateTimeItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName )    : PropertyItem( l, after, prop, propName ){    lin = 0;}QDateTimeEdit *PropertyDateTimeItem::lined(){    if ( lin )	return lin;    lin = new QDateTimeEdit( listview->viewport() );    connect( lin, SIGNAL( valueChanged( const QDateTime & ) ),	     this, SLOT( setValue() ) );    QObjectList *l = lin->queryList( "QLineEdit" );    for ( QObject *o = l->first(); o; o = l->next() )	o->installEventFilter( listview );    delete l;    return lin;}PropertyDateTimeItem::~PropertyDateTimeItem(){    delete (QDateTimeEdit*)lin;    lin = 0;}void PropertyDateTimeItem::showEditor(){    PropertyItem::showEditor();    if ( !lin ) {	lined()->blockSignals( TRUE );	lined()->setDateTime( value().toDateTime() );	lined()->blockSignals( FALSE );    }    placeEditor( lin );    if ( !lin->isVisible() ) {	lin->show();	setFocus( lin );    }}void PropertyDateTimeItem::hideEditor(){    PropertyItem::hideEditor();    if ( lin )	lin->hide();}void PropertyDateTimeItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    if ( lin ) {	lined()->blockSignals( TRUE );	if ( lined()->dateTime() != v.toDateTime() )	    lined()->setDateTime( v.toDateTime() );	lined()->blockSignals( FALSE );    }    setText( 1, v.toDateTime().toString( ::Qt::ISODate ) );    PropertyItem::setValue( v );}void PropertyDateTimeItem::setValue(){    setText( 1, lined()->dateTime().toString( ::Qt::ISODate ) );    QVariant v;    v = lined()->dateTime();    PropertyItem::setValue( v );    notifyValueChange();}// --------------------------------------------------------------PropertyBoolItem::PropertyBoolItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName )    : PropertyItem( l, after, prop, propName ){    comb = 0;}QComboBox *PropertyBoolItem::combo(){    if ( comb )	return comb;    comb = new QComboBox( FALSE, listview->viewport() );    comb->hide();    comb->insertItem( tr( "False" ) );    comb->insertItem( tr( "True" ) );    connect( comb, SIGNAL( activated( int ) ),	     this, SLOT( setValue() ) );    comb->installEventFilter( listview );    return comb;}PropertyBoolItem::~PropertyBoolItem(){    delete (QComboBox*)comb;    comb = 0;}void PropertyBoolItem::toggle(){    bool b = value().toBool();    setValue( QVariant( !b, 0 ) );    setValue();}void PropertyBoolItem::showEditor(){    PropertyItem::showEditor();    if ( !comb ) {	combo()->blockSignals( TRUE );	if ( value().toBool() )	    combo()->setCurrentItem( 1 );	else	    combo()->setCurrentItem( 0 );	combo()->blockSignals( FALSE );    }    placeEditor( combo() );    if ( !combo()->isVisible()  || !combo()->hasFocus() ) {	combo()->show();	setFocus( combo() );    }}void PropertyBoolItem::hideEditor(){    PropertyItem::hideEditor();    combo()->hide();}void PropertyBoolItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    if ( comb ) {	combo()->blockSignals( TRUE );	if ( v.toBool() )	    combo()->setCurrentItem( 1 );	else	    combo()->setCurrentItem( 0 );	combo()->blockSignals( FALSE );    }    QString tmp = tr( "True" );    if ( !v.toBool() )	tmp = tr( "False" );    setText( 1, tmp );    PropertyItem::setValue( v );}void PropertyBoolItem::setValue(){    if ( !comb )	return;    setText( 1, combo()->currentText() );    bool b = combo()->currentItem() == 0 ? (bool)FALSE : (bool)TRUE;    PropertyItem::setValue( QVariant( b, 0 ) );    notifyValueChange();}// --------------------------------------------------------------PropertyIntItem::PropertyIntItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				  const QString &propName, bool s )    : PropertyItem( l, after, prop, propName ), signedValue( s ){    spinBx = 0;}QSpinBox *PropertyIntItem::spinBox(){    if ( spinBx )	return spinBx;    if ( signedValue )	spinBx = new QSpinBox( -INT_MAX, INT_MAX, 1, listview->viewport() );    else	spinBx = new QSpinBox( 0, INT_MAX, 1, listview->viewport() );    spinBx->hide();    spinBx->installEventFilter( listview );    QObjectList *ol = spinBx->queryList( "QLineEdit" );    if ( ol && ol->first() )	ol->first()->installEventFilter( listview );    delete ol;    connect( spinBx, SIGNAL( valueChanged( int ) ),	     this, SLOT( setValue() ) );    return spinBx;}PropertyIntItem::~PropertyIntItem(){    delete (QSpinBox*)spinBx;    spinBx = 0;}void PropertyIntItem::showEditor(){    PropertyItem::showEditor();    if ( !spinBx ) {	spinBox()->blockSignals( TRUE );	if ( signedValue )	    spinBox()->setValue( value().toInt() );	else	    spinBox()->setValue( value().toUInt() );	spinBox()->blockSignals( FALSE );    }    placeEditor( spinBox() );    if ( !spinBox()->isVisible()  || !spinBox()->hasFocus()  ) {	spinBox()->show();	setFocus( spinBox() );    }}void PropertyIntItem::hideEditor(){    PropertyItem::hideEditor();    spinBox()->hide();}void PropertyIntItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    if ( spinBx ) {	spinBox()->blockSignals( TRUE );	if ( signedValue )	    spinBox()->setValue( v.toInt() );	else	    spinBox()->setValue( v.toUInt() );	spinBox()->blockSignals( FALSE );    }    if ( signedValue )	    setText( 1, QString::number( v.toInt() ) );    else	    setText( 1, QString::number( v.toUInt() ) );    PropertyItem::setValue( v );}void PropertyIntItem::setValue(){    if ( !spinBx )	return;    setText( 1, QString::number( spinBox()->value() ) );    if ( signedValue )	PropertyItem::setValue( spinBox()->value() );    else	PropertyItem::setValue( (uint)spinBox()->value() );    notifyValueChange();}// --------------------------------------------------------------PropertyLayoutItem::PropertyLayoutItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,		  const QString &propName )    : PropertyItem( l, after, prop, propName ){    spinBx = 0;}PropertyLayoutItem::~PropertyLayoutItem(){    delete (QSpinBox*)spinBx;    spinBx = 0;}QSpinBox* PropertyLayoutItem::spinBox(){    if ( spinBx )	return spinBx;    spinBx = new QSpinBox( -1, INT_MAX, 1, listview->viewport() );    spinBx->setSpecialValueText( tr( "default" ) );    spinBx->hide();    spinBx->installEventFilter( listview );    QObjectList *ol = spinBx->queryList( "QLineEdit" );    if ( ol && ol->first() )	ol->first()->installEventFilter( listview );    delete ol;    connect( spinBx, SIGNAL( valueChanged( int ) ),	     this, SLOT( setValue() ) );    return spinBx;}void PropertyLayoutItem::showEditor(){    PropertyItem::showEditor();    if ( !spinBx ) {	spinBox()->blockSignals( TRUE );	spinBox()->setValue( value().toInt() );	spinBox()->blockSignals( TRUE );    }    placeEditor( spinBox() );    if ( !spinBox()->isVisible() || !spinBox()->hasFocus() ) {	spinBox()->show();	setFocus( spinBox() );    }}void PropertyLayoutItem::hideEditor(){    PropertyItem::hideEditor();    spinBox()->hide();}void PropertyLayoutItem::setValue( const QVariant &v ){    if ( spinBx ) {	spinBox()->blockSignals( TRUE );	spinBox()->setValue( v.toInt() );	spinBox()->blockSignals( FALSE );    }    QString s = v.toString();    if ( v.toInt() == -1 )	s = spinBox()->specialValueText();    setText( 1, s );    PropertyItem::setValue( v );}void PropertyLayoutItem::setValue(){    if ( !spinBx )	return;    PropertyItem::setValue( spinBox()->value() );    notifyValueChange();}// --------------------------------------------------------------PropertyListItem::PropertyListItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				    const QString &propName, bool e )    : PropertyItem( l, after, prop, propName ), editable( e ){    comb = 0;    oldInt = -1;}QComboBox *PropertyListItem::combo(){    if ( comb )	return comb;    comb = new QComboBox( editable, listview->viewport() );    comb->hide();    connect( comb, SIGNAL( activated( int ) ),	     this, SLOT( setValue() ) );    comb->installEventFilter( listview );    if ( editable ) {	QObjectList *ol = comb->queryList( "QLineEdit" );	if ( ol && ol->first() )	    ol->first()->installEventFilter( listview );	delete ol;    }    return comb;}PropertyListItem::~PropertyListItem(){    delete (QComboBox*)comb;    comb = 0;}void PropertyListItem::showEditor(){    PropertyItem::showEditor();    if ( !comb ) {	combo()->blockSignals( TRUE );	combo()->clear();	combo()->insertStringList( value().toStringList() );	combo()->blockSignals( FALSE );    }    placeEditor( combo() );    if ( !combo()->isVisible()  || !combo()->hasFocus() ) {	combo()->show();	setFocus( combo() );    }}void PropertyListItem::hideEditor(){    PropertyItem::hideEditor();    combo()->hide();}void PropertyListItem::setValue( const QVariant &v ){    if ( comb ) {	combo()->blockSignals( TRUE );	combo()->clear();	combo()->insertStringList( v.toStringList() );	combo()->blockSignals( FALSE );    }    setText( 1, v.toStringList().first() );    PropertyItem::setValue( v );}void PropertyListItem::setValue(){    if ( !comb )	return;    setText( 1, combo()->currentText() );    QStringList lst;    for ( uint i = 0; i < combo()->listBox()->count(); ++i )	lst << combo()->listBox()->item( i )->text();    PropertyItem::setValue( lst );    notifyValueChange();    oldInt = currentIntItem();    oldString = currentItem();}QString PropertyListItem::currentItem() const{    return ( (PropertyListItem*)this )->combo()->currentText();}void PropertyListItem::setCurrentItem( const QString &s ){    if ( comb && currentItem().lower() == s.lower() )	return;    if ( !comb ) {	combo()->blockSignals( TRUE );	combo()->clear();	combo()->insertStringList( value().toStringList() );	combo()->blockSignals( FALSE );    }    for ( uint i = 0; i < combo()->listBox()->count(); ++i ) {	if ( combo()->listBox()->item( i )->text().lower() == s.lower() ) {	    combo()->setCurrentItem( i );	    setText( 1, combo()->currentText() );	    break;	}    }    oldInt = currentIntItem();    oldString = currentItem();}void PropertyListItem::addItem( const QString &s ){    combo()->insertItem( s );}void PropertyListItem::setCurrentItem( int i ){    if ( comb && i == combo()->currentItem() )	return;    if ( !comb ) {	combo()->blockSignals( TRUE );	combo()->clear();	combo()->insertStringList( value().toStringList() );	combo()->blockSignals( FALSE );    }    combo()->setCurrentItem( i );    setText( 1, combo()->currentText() );    oldInt = currentIntItem();    oldString = currentItem();}int PropertyListItem::currentIntItem() const{    return ( (PropertyListItem*)this )->combo()->currentItem();}int PropertyListItem::currentIntItemFromObject() const{    return oldInt;}QString PropertyListItem::currentItemFromObject() const{    return oldString;}// --------------------------------------------------------------

⌨️ 快捷键说明

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