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

📄 propertyeditor.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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::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;}// --------------------------------------------------------------PropertyCoordItem::PropertyCoordItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				    const QString &propName, Type t )    : PropertyItem( l, after, prop, propName ), typ( t ){    lin = 0;}QLineEdit *PropertyCoordItem::lined(){    if ( lin )	return lin;    lin = new QLineEdit( listview->viewport() );    lin->setReadOnly( TRUE );    lin->installEventFilter( listview );    lin->hide();    return lin;}void PropertyCoordItem::createChildren(){    PropertyItem *i = this;    if ( typ == Rect || typ == Point ) {	i = new PropertyIntItem( listview, i, this, tr( "x" ), TRUE );	addChild( i );	i = new PropertyIntItem( listview, i, this, tr( "y" ), TRUE );	addChild( i );    }    if ( typ == Rect || typ == Size ) {	i = new PropertyIntItem( listview, i, this, tr( "width" ), TRUE );	addChild( i );	i = new PropertyIntItem( listview, i, this, tr( "height" ), TRUE );	addChild( i );    }}void PropertyCoordItem::initChildren(){    PropertyItem *item = 0;    for ( int i = 0; i < childCount(); ++i ) {	item = PropertyItem::child( i );	if ( item->name() == tr( "x" ) ) {	    if ( typ == Rect )		item->setValue( val.toRect().x() );	    else if ( typ == Point )		item->setValue( val.toPoint().x() );	} else if ( item->name() == tr( "y" ) ) {	    if ( typ == Rect )		item->setValue( val.toRect().y() );	    else if ( typ == Point )		item->setValue( val.toPoint().y() );	} else if ( item->name() == tr( "width" ) ) {	    if ( typ == Rect )		item->setValue( val.toRect().width() );	    else if ( typ == Size )		item->setValue( val.toSize().width() );	} else if ( item->name() == tr( "height" ) ) {	    if ( typ == Rect )		item->setValue( val.toRect().height() );	    else if ( typ == Size )		item->setValue( val.toSize().height() );	}    }}PropertyCoordItem::~PropertyCoordItem(){    delete (QLineEdit*)lin;    lin = 0;}void PropertyCoordItem::showEditor(){    PropertyItem::showEditor();    if ( !lin )	lined()->setText( text( 1 ) );    placeEditor( lined() );    if ( !lined()->isVisible() || !lined()->hasFocus()  ) {	lined()->show();	setFocus( lined() );    }}void PropertyCoordItem::hideEditor(){    PropertyItem::hideEditor();    lined()->hide();}void PropertyCoordItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    QString s;    if ( typ == Rect )	s = "[ " + QString::number( v.toRect().x() ) + ", " + QString::number( v.toRect().y() ) + ", " +	    QString::number( v.toRect().width() ) + ", " + QString::number( v.toRect().height() ) + " ]";    else if ( typ == Point )	s = "[ " + QString::number( v.toPoint().x() ) + ", " +	    QString::number( v.toPoint().y() ) + " ]";    else if ( typ == Size )	s = "[ " + QString::number( v.toSize().width() ) + ", " +	    QString::number( v.toSize().height() ) + " ]";    setText( 1, s );    if ( lin )	lined()->setText( s );    PropertyItem::setValue( v );}bool PropertyCoordItem::hasSubItems() const{    return TRUE;}void PropertyCoordItem::childValueChanged( PropertyItem *child ){    if ( typ == Rect ) {	QRect r = value().toRect();	if ( child->name() == tr( "x" ) )	    r.setX( child->value().toInt() );	else if ( child->name() == tr( "y" ) )	    r.setY( child->value().toInt() );	else if ( child->name() == tr( "width" ) )	    r.setWidth( child->value().toInt() );	else if ( child->name() == tr( "height" ) )	    r.setHeight( child->value().toInt() );	setValue( r );    } else if ( typ == Point ) {	QPoint r = value().toPoint();	if ( child->name() == tr( "x" ) )	    r.setX( child->value().toInt() );	else if ( child->name() == tr( "y" ) )	    r.setY( child->value().toInt() );	setValue( r );    } else if ( typ == Size ) {	QSize r = value().toSize();	if ( child->name() == tr( "width" ) )	    r.setWidth( child->value().toInt() );	else if ( child->name() == tr( "height" ) )	    r.setHeight( child->value().toInt() );	setValue( r );    }    notifyValueChange();}// --------------------------------------------------------------PropertyPixmapItem::PropertyPixmapItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				      const QString &propName )    : PropertyItem( l, after, prop, propName ){    box = new QHBox( listview->viewport() );    box->hide();    pixPrev = new QLabel( box );    pixPrev->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ) );    pixPrev->setBackgroundColor( pixPrev->colorGroup().color( QColorGroup::Base ) );    button = new QPushButton( "...", box );    button->setFixedWidth( 20 );    box->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );    box->setLineWidth( 2 );    pixPrev->setFrameStyle( QFrame::NoFrame );    box->installEventFilter( listview );    connect( button, SIGNAL( clicked() ),	     this, SLOT( getPixmap() ) );}PropertyPixmapItem::~PropertyPixmapItem(){    delete (QHBox*)box;}void PropertyPixmapItem::showEditor(){    PropertyItem::showEditor();    placeEditor( box );    if ( !box->isVisible() )	box->show();}void PropertyPixmapItem::hideEditor(){    PropertyItem::hideEditor();    box->hide();}void PropertyPixmapItem::setValue( const QVariant &v ){    QString s;    pixPrev->setPixmap( v.toPixmap() );    PropertyItem::setValue( v );    repaint();}void PropertyPixmapItem::getPixmap(){    QPixmap pix = qChoosePixmap( listview, listview->propertyEditor()->formWindow(), value().toPixmap() );    if ( !pix.isNull() ) {	setValue( pix );	notifyValueChange();    }}bool PropertyPixmapItem::hasCustomContents() const{    return TRUE;}void PropertyPixmapItem::drawCustomContents( QPainter *p, const QRect &r ){    QPixmap pix( value().toPixmap() );    if ( !pix.isNull() ) {	p->save();	p->setClipRect( QRect( QPoint( (int)(p->worldMatrix().dx() + r.x()),				       (int)(p->worldMatrix().dy() + r.y()) ),			       r.size() ) );	p->drawPixmap( r.x(), r.y() + ( r.height() - pix.height() ) / 2, pix );	p->restore();    }}// --------------------------------------------------------------PropertyColorItem::PropertyColorItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				      const QString &propName, bool children )    : PropertyItem( l, after, prop, propName ), withChildren( children ){    box = new QHBox( listview->viewport() );    box->hide();    colorPrev = new QFrame( box );    button = new QPushButton( "...", box );    button->setFixedWidth( 20 );    box->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );    box->setLineWidth( 2 );    colorPrev->setFrameStyle( QFrame::Plain | QFrame::Box );    colorPrev->setLineWidth( 2 );    QPalette pal = colorPrev->palette();    QColorGroup cg = pal.active();    cg.setColor( QColorGroup::Foreground, cg.color( QColorGroup::Base ) );    pal.setActive( cg );    pal.setInactive( cg );    pal.setDisabled( cg );    colorPrev->setPalette( pal );    box->installEventFilter( listview );    connect( button, SIGNAL( clicked() ),	     this, SLOT( getColor() ) );}void PropertyColorItem::createChildren(){    PropertyItem *i = this;    i = new PropertyIntItem( listview, i, this, tr( "Red" ), TRUE );    addChild( i );    i = new PropertyIntItem( listview, i, this, tr( "Green" ), TRUE );    addChild( i );    i = new PropertyIntItem( listview, i, this, tr( "Blue" ), TRUE );    addChild( i );}void PropertyColorItem::initChildren(){    PropertyItem *item = 0;    for ( int i = 0; i < childCount(); ++i ) {	item = PropertyItem::child( i );	if ( item->name() == tr( "Red" ) )	    item->setValue( val.toColor().red() );	else if ( item->name() == tr( "Green" ) )	    item->setValue( val.toColor().green() );	else if ( item->name() == tr( "Blue" ) )	    item->setValue( val.toColor().blue() );    }}PropertyColorItem::~PropertyColorItem(){    delete (QHBox*)box;}void PropertyColorItem::showEditor(){    PropertyItem::showEditor();    placeEditor( box );    if ( !box->isVisible() )	box->show();}void PropertyColorItem::hideEditor(){    PropertyItem::hideEditor();    box->hide();}void PropertyColorItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    QString s;    setText( 1, v.toColor().name() );    colorPrev->setBackgroundColor( v.toColor() );    PropertyItem::setValue( v );}bool PropertyColorItem::hasSubItems() const{    return withChildren;}void PropertyColorItem::childValueChanged( PropertyItem *child ){    QColor c( val.toColor() );    if ( child->name() == tr( "Red" ) )	c.setRgb( child->value().toInt(), c.green(), c.blue() );    else if ( child->name() == tr( "Green" ) )	c.setRgb( c.red(), child->value().toInt(), c.blue() );    else if ( child->name() == tr( "Blue" ) )	c.setRgb( c.red(), c.green(), child->value().toInt() );    setValue( c );    notifyValueChange();}void PropertyColorItem::getColor(){    QColor c = QColorDialog::getColor( val.asColor(), listview );    if ( c.isValid() ) {	setValue( c );	notifyValueChange();    }}bool PropertyColorItem::hasCustomContents() const{    return TRUE;}void PropertyColorItem::drawCustomContents( QPainter *p, const QRect &r ){    p->save();    p->setPen( QPen( black, 1 ) );    p->setBrush( val.toColor() );    p->drawRect( r.x() + 2, r.y() + 2, r.width() - 5, r.height() - 5 );    p->restore();}// --------------------------------------------------------------PropertyFontItem::PropertyFontItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName )    : PropertyItem( l, after, prop, propName ){    box = new QHBox( listview->viewport() );    box->hide();    lined = new QLineEdit( box );    button = new QPushButton( "...", box );    button->setFixedWidth( 20 );    box->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );    box->setLineWidth( 2 );    lined->setFrame( FALSE );    lined->setReadOnly( TRUE );    box->setFocusProxy( lined );    box->installEventFilter( listview );    lined->installEventFilter( listview );    button->installEventFilter( listview );    connect( button, SIGNAL( clicked() ),	     this, SLOT( getFont() ) );}void PropertyFontItem::createChildren(){    PropertyItem *i = this;    i = new PropertyListItem( listview, i, this, tr( "Family" ), FALSE );    addChild( i );    i = new PropertyIntItem( listview, i, this, tr( "Point Size" ), TRUE );    addChild( i );    i = new PropertyBoolItem( listview, i, this, tr( "Bold" ) );    addChild( i );    i = new PropertyBoolItem( listview, i, this, tr( "Italic" ) );    addChild( i );    i = new PropertyBoolItem( listview, i, this, tr( "Underline" ) );    addChild( i );    i = new PropertyBoolItem( listview, i, this, tr( "Strikeout" ) );    addChild( i );}void PropertyFontItem::initChildren(){    PropertyItem *item = 0;    for ( int i = 0; i < childCount(); ++i ) {	item = PropertyItem::child( i );	if ( item->name() == tr( "Family" ) ) {	    ( (PropertyListItem*)item )->setValue( getFontList() );	    ( (PropertyListItem*)item )->setCurrentItem( val.toFont().family() );	} else if ( item->name() == tr( "Point Size" ) )	    item->setValue( val.toFont().pointSize() );	else if ( item->name() == tr( "Bold" ) )	    item->setValue( QVariant( val.toFont().bold(), 0 ) );	else if ( item->name() == tr( "Italic" ) )	    item->setValue( QVariant( val.toFont().italic(), 0 ) );	else if ( item->name() == tr( "Underline" ) )	    item->setValue( QVariant( val.toFont().underline(), 0 ) );	else if ( item->name() == tr( "Strikeout" ) )	    item->setValue( QVariant( val.toFont().strikeOut(), 0 ) );    }}PropertyFontItem::~PropertyFontItem(){    delete (QHBox*)box;}void PropertyFontItem::showEditor(){    PropertyItem::showEditor();    placeEditor( box );    if ( !box->isVisible() || !lined->hasFocus() ) {	box->show();	setFocus( lined );

⌨️ 快捷键说明

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