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

📄 propertyeditor.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
int PropertyItem::currentIntItemFromObject() const{    return -1;}QString PropertyItem::currentItemFromObject() const{    return QString::null;}void PropertyItem::setFocus( QWidget *w ){    QWorkspace *ws = 0;    QWidget *wid = listview->propertyEditor();    while ( wid ) {	if ( wid->inherits( "QWorkspace" ) )	    break;	wid = wid->parentWidget();    }    if ( !wid )	return;    ws = (QWorkspace*)wid;    if ( ws->activeWindow() == listview->propertyEditor() )	w->setFocus();}// --------------------------------------------------------------PropertyTextItem::PropertyTextItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				    const QString &propName, bool comment, bool multiLine, bool ascii, bool a )    : PropertyItem( l, after, prop, propName ), withComment( comment ),      hasMultiLines( multiLine ), asciiOnly( ascii ), accel( a ){    lin = 0;    box = 0;}QLineEdit *PropertyTextItem::lined(){    if ( lin )	return lin;    if ( hasMultiLines ) {	box = new QHBox( listview->viewport() );	box->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );	box->setLineWidth( 2 );	box->hide();    }    lin = 0;    if ( hasMultiLines )	lin = new QLineEdit( box );    else	lin = new QLineEdit( listview->viewport() );    if ( asciiOnly )	lin->setValidator( new AsciiValidator( lin, "ascii_validator" ) );    if ( !hasMultiLines ) {	lin->hide();    } else {	button = new QPushButton( tr("..."), box );	button->setFixedWidth( 20 );	connect( button, SIGNAL( clicked() ),		 this, SLOT( getText() ) );	lin->setFrame( FALSE );    }    connect( lin, SIGNAL( returnPressed() ),	     this, SLOT( setValue() ) );    connect( lin, SIGNAL( textChanged( const QString & ) ),	     this, SLOT( setValue() ) );    if ( PropertyItem::name() == "name" )	connect( lin, SIGNAL( returnPressed() ),		 listview->propertyEditor()->formWindow()->commandHistory(),		 SLOT( checkCompressedCommand() ) );    lin->installEventFilter( listview );    return lin;}PropertyTextItem::~PropertyTextItem(){    delete (QLineEdit*)lin;    lin = 0;    delete (QHBox*)box;    box = 0;}void PropertyTextItem::setChanged( bool b, bool updateDb ){    PropertyItem::setChanged( b, updateDb );    if ( withComment && childCount() > 0 )	( (PropertyTextItem*)PropertyItem::child( 0 ) )->lined()->setEnabled( b );}bool PropertyTextItem::hasSubItems() const{    return withComment;}void PropertyTextItem::childValueChanged( PropertyItem *child ){    MetaDataBase::setPropertyComment( listview->propertyEditor()->widget(), PropertyItem::name(), child->value().toString() );}static QString to_string( const QVariant &v, bool accel ){    if ( !accel )	return v.toString();    return QAccel::keyToString( v.toInt() );}void PropertyTextItem::showEditor(){    PropertyItem::showEditor();    if ( !lin ) {	lined()->blockSignals( TRUE );	lined()->setText( to_string( value(), accel ) );	lined()->blockSignals( FALSE );    }    QWidget* w;    if ( hasMultiLines )	w = box;    else	w= lined();    placeEditor( w );    if ( !w->isVisible() || !lined()->hasFocus() ) {	w->show();	setFocus( lined() );    }}void PropertyTextItem::createChildren(){    PropertyTextItem *i = new PropertyTextItem( listview, this, this, tr( "comment" ), FALSE, FALSE );    i->lined()->setEnabled( isChanged() );    addChild( i );}void PropertyTextItem::initChildren(){    if ( !childCount() )	return;    PropertyItem *item = PropertyItem::child( 0 );    if ( item )	item->setValue( MetaDataBase::propertyComment( listview->propertyEditor()->widget(), PropertyItem::name() ) );}void PropertyTextItem::hideEditor(){    PropertyItem::hideEditor();    QWidget* w;    if ( hasMultiLines )	w = box;    else	w = lined();    w->hide();}void PropertyTextItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    if ( lin ) {	lined()->blockSignals( TRUE );	int oldCursorPos;	oldCursorPos = lin->cursorPosition();	lined()->setText( to_string( v, accel ) );	lin->setCursorPosition( oldCursorPos );	lined()->blockSignals( FALSE );    }    setText( 1, to_string( v, accel ) );    PropertyItem::setValue( v );}void PropertyTextItem::setValue(){    setText( 1, lined()->text() );    QVariant v;    if ( accel )	v = QAccel::stringToKey( lined()->text() );    else	v = lined()->text();    PropertyItem::setValue( v );    notifyValueChange();}void PropertyTextItem::getText(){    QString txt = TextEditor::getText( listview, value().toString() );    if ( !txt.isEmpty() ) {	setText( 1, txt );	PropertyItem::setValue( txt );	notifyValueChange();	lined()->blockSignals( TRUE );	lined()->setText( txt );	lined()->blockSignals( FALSE );    }}// --------------------------------------------------------------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();}// --------------------------------------------------------------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 ){

⌨️ 快捷键说明

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