propertyeditor.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 2,457 行 · 第 1/5 页

CPP
2,457
字号
    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, bool isIconSet )    : PropertyItem( l, after, prop, propName ), iconSet( isIconSet ){    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();	listView()->viewport()->setFocus();    }}void PropertyPixmapItem::hideEditor(){    PropertyItem::hideEditor();    box->hide();}void PropertyPixmapItem::setValue( const QVariant &v ){    QString s;    if ( !iconSet )	pixPrev->setPixmap( v.toPixmap() );    else	pixPrev->setPixmap( v.toIconSet().pixmap() );    PropertyItem::setValue( v );    repaint();}void PropertyPixmapItem::getPixmap(){    QPixmap pix = qChoosePixmap( listview, listview->propertyEditor()->formWindow(), value().toPixmap() );    if ( !pix.isNull() ) {	if ( !iconSet )	    setValue( pix );	else	    setValue( QIconSet( pix ) );	notifyValueChange();    }}bool PropertyPixmapItem::hasCustomContents() const{    return TRUE;}void PropertyPixmapItem::drawCustomContents( QPainter *p, const QRect &r ){    QPixmap pix( (!iconSet ? value().toPixmap() : value().toIconSet().pixmap()) );    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();	listView()->viewport()->setFocus();    }}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 );    }}void PropertyFontItem::hideEditor(){    PropertyItem::hideEditor();    box->hide();}void PropertyFontItem::setValue( const QVariant &v ){    if ( value() == v )	return;    setText( 1, v.toFont().family() + "-" + QString::number( v.toFont().pointSize() ) );    lined->setText( v.toFont().family() + "-" + QString::number( v.toFont().pointSize() ) );    PropertyItem::setValue( v );}void PropertyFontItem::getFont(){    bool ok = FALSE;    QFont f = QFontDialog::getFont( &ok, val.toFont(), listview );    if ( ok && f != val.toFont() ) {	setValue( f );	notifyValueChange();    }}bool PropertyFontItem::hasSubItems() const{    return TRUE;}void PropertyFontItem::childValueChanged( PropertyItem *child ){    QFont f = val.toFont();    if ( child->name() == tr( "Family" ) )	f.setFamily( ( (PropertyListItem*)child )->currentItem() );    else if ( child->name() == tr( "Point Size" ) )	f.setPointSize( child->value().toInt() );    else if ( child->name() == tr( "Bold" ) )	f.setBold( child->value().toBool() );    else if ( child->name() == tr( "Italic" ) )	f.setItalic( child->value().toBool() );    else if ( child->name() == tr( "Underline" ) )	f.setUnderline( child->value().toBool() );    else if ( child->name() == tr( "Strikeout" ) )	f.setStrikeOut( child->value().toBool() );    setValue( f );    notifyValueChange();}// --------------------------------------------------------------PropertyDatabaseItem::PropertyDatabaseItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,					    const QString &propName, bool wField )    : PropertyItem( l, after, prop, propName ), withField( wField ){    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 );}void PropertyDatabaseItem::createChildren(){    PropertyItem *i = this;    i = new PropertyListItem( listview, i, this, tr( "Connection" ), TRUE );    addChild( i );    i = new PropertyListItem( listview, i, this, tr( "Table" ), TRUE );    addChild( i );    if ( withField ) {	i = new PropertyListItem( listview, i, this, tr( "Field" ), TRUE );	addChild( i );    }}void PropertyDatabaseItem::initChildren(){#ifndef QT_NO_SQL    PropertyItem *item = 0;    QStringList lst = value().toStringList();    QString conn, table;    for ( int i = 0; i < childCount(); ++i ) {	item = PropertyItem::child( i );	if ( item->name() == tr( "Connection" ) ) {	    QStringList cl = listview->propertyEditor()->formWindow()->project()->databaseConnectionList();	    if ( !cl.isEmpty() )		item->setValue( cl );	    else if ( lst.count() > 0 )		item->setValue( QStringList( lst[ 0 ] ) );	    else if ( withField )		item->setValue( QStringList( MetaDataBase::fakeProperty( listview->propertyEditor()->formWindow()->mainContainer(),									 "database" ).toStringList()[ 0 ] ) );	    if ( lst.count() > 0 && !lst[ 0 ].isEmpty() )		item->setCurrentItem( lst[ 0 ] );	    else if ( !isChanged() && withField )		item->setCurrentItem( MetaDataBase::fakeProperty( listview->propertyEditor()->formWindow()->mainContainer(),								  "database" ).toStringList()[ 0 ] );	    else		item->setCurrentItem( 0 );	    conn = item->currentItem();	} else if ( item->name() == tr( "Table" ) ) {	    QStringList cl = listview->propertyEditor()->formWindow()->project()->databaseTableList( conn );	    if ( !cl.isEmpty() )		item->setValue( cl );	    else if ( lst.count() > 1 )		item->setValue( QStringList( lst[ 1 ] ) );	    else if ( withField ) {		QStringList fakeLst = MetaDataBase::fakeProperty( listview->propertyEditor()->formWindow()->mainContainer(), "database" ).toStringList();		if ( fakeLst.count() > 1 )		    item->setValue( fakeLst[ 1 ] );	    }	    if ( lst.count() > 1 && !lst[ 1 ].isEmpty() )		item->setCurrentItem( lst[ 1 ] );	    else if ( !isChanged() && withField ) {		QStringList fakeLst = MetaDataBase::fakeProperty( listview->propertyEditor()->formWindow()->mainContainer(), "database" ).toStringList();		if ( fakeLst.count() > 1 )		    item->setCurrentItem( fakeLst[ 1 ] );	        else	            item->setCurrentItem( 0 );	    } else		item->setCurrentItem( 0 );	    table = item->currentItem();	} else if ( item->name() == tr( "Field" ) ) {	    QStringList cl = listview->propertyEditor()->formWindow()->project()->databaseFieldList( conn, table );	    if ( !cl.isEmpty() )		item->setValue( cl );	    else if ( lst.count() > 2 )		item->setValue( QStringList( lst[ 2 ] ) );	    if ( lst.count() > 2 && !lst[ 2 ].isEmpty() )		item->setCurrentItem( lst[ 2 ] );	    else		item->setCurrentItem( 0 );	}    }#endif}PropertyDatabaseItem::~PropertyDatabaseItem(){    delete (QHBox*)box;}void PropertyDatabaseItem::showEditor(){    PropertyItem::showEditor();

⌨️ 快捷键说明

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