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

📄 propertyeditor.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }}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();}// --------------------------------------------------------------PropertySizePolicyItem::PropertySizePolicyItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,						const QString &propName )    : PropertyItem( l, after, prop, propName ){    lin = 0;}QLineEdit *PropertySizePolicyItem::lined(){    if ( lin )	return lin;    lin = new QLineEdit( listview->viewport() );    lin->hide();    lin->setReadOnly( TRUE );    return lin;}void PropertySizePolicyItem::createChildren(){    QStringList lst;    lst << "Fixed" << "Minimum" << "Maximum" << "Preferred" << "MinimumExpanding" << "Expanding";    PropertyItem *i = this;    i = new PropertyListItem( listview, i, this, tr( "hSizeType" ), FALSE );    i->setValue( lst );    addChild( i );    i = new PropertyListItem( listview, i, this, tr( "vSizeType" ), FALSE );    i->setValue( lst );    addChild( i );}void PropertySizePolicyItem::initChildren(){    PropertyItem *item = 0;    QSizePolicy sp = val.toSizePolicy();    for ( int i = 0; i < childCount(); ++i ) {	item = PropertyItem::child( i );	if ( item->name() == tr( "hSizeType" ) )	    ( (PropertyListItem*)item )->setCurrentItem( size_type_to_int( sp.horData() ) );	else if ( item->name() == tr( "vSizeType" ) )	    ( (PropertyListItem*)item )->setCurrentItem( size_type_to_int( sp.verData() ) );    }}PropertySizePolicyItem::~PropertySizePolicyItem(){    delete (QLineEdit*)lin;}void PropertySizePolicyItem::showEditor(){    PropertyItem::showEditor();    placeEditor( lined() );    if ( !lined()->isVisible() || !lined()->hasFocus() )	lined()->show();}void PropertySizePolicyItem::hideEditor(){    PropertyItem::hideEditor();    lined()->hide();}void PropertySizePolicyItem::setValue( const QVariant &v ){    if ( value() == v )	return;    QString s = tr( "%1/%2" );    s = s.arg( size_type_to_string( v.toSizePolicy().horData() ) ).	arg( size_type_to_string( v.toSizePolicy().verData() ) );    setText( 1, s );    lined()->setText( s );    PropertyItem::setValue( v );}void PropertySizePolicyItem::childValueChanged( PropertyItem *child ){    QSizePolicy sp = val.toSizePolicy();    if ( child->name() == tr( "hSizeType" ) )	sp.setHorData( int_to_size_type( ( ( PropertyListItem*)child )->currentIntItem() ) );    else if ( child->name() == tr( "vSizeType" ) )	sp.setVerData( int_to_size_type( ( ( PropertyListItem*)child )->currentIntItem() ) );    setValue( sp );    notifyValueChange();}bool PropertySizePolicyItem::hasSubItems() const{    return TRUE;}// --------------------------------------------------------------PropertyPaletteItem::PropertyPaletteItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,				      const QString &propName )    : PropertyItem( l, after, prop, propName ){    box = new QHBox( listview->viewport() );    box->hide();    palettePrev = new QLabel( box );    button = new QPushButton( "...", box );    button->setFixedWidth( 20 );    box->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );    box->setLineWidth( 2 );    palettePrev->setFrameStyle( QFrame::NoFrame );    box->installEventFilter( listview );    connect( button, SIGNAL( clicked() ),	     this, SLOT( getPalette() ) );}PropertyPaletteItem::~PropertyPaletteItem(){    delete (QHBox*)box;}void PropertyPaletteItem::showEditor(){    PropertyItem::showEditor();    placeEditor( box );    if ( !box->isVisible() )	box->show();}void PropertyPaletteItem::hideEditor(){    PropertyItem::hideEditor();    box->hide();}void PropertyPaletteItem::setValue( const QVariant &v ){    QString s;    palettePrev->setPalette( v.toPalette() );    PropertyItem::setValue( v );    repaint();}void PropertyPaletteItem::getPalette(){    bool ok = FALSE;    QWidget *w = listview->propertyEditor()->widget();    if ( w->inherits( "QScrollView" ) )	w = ( (QScrollView*)w )->viewport();    QPalette pal = PaletteEditor::getPalette( &ok, val.toPalette(),#if defined(QT_NON_COMMERCIAL)					      w->backgroundMode(), listview->topLevelWidget(),#else					      w->backgroundMode(), listview,#endif 					      "choose_palette", listview->propertyEditor()->formWindow() );    if ( !ok )	return;    setValue( pal );    notifyValueChange();}bool PropertyPaletteItem::hasCustomContents() const{    return TRUE;}void PropertyPaletteItem::drawCustomContents( QPainter *p, const QRect &r ){    QPalette pal( value().toPalette() );    p->save();    p->setClipRect( QRect( QPoint( (int)(p->worldMatrix().dx() + r.x()),				   (int)(p->worldMatrix().dy() + r.y()) ),			   r.size() ) );    QRect r2( r );    r2.setX( r2.x() + 2 );    r2.setY( r2.y() + 2 );    r2.setWidth( r2.width() - 3 );    r2.setHeight( r2.height() - 3 );    p->setPen( QPen( black, 1 ) );    p->setBrush( pal.active().background() );    p->drawRect( r2 );    p->restore();}// --------------------------------------------------------------PropertyCursorItem::PropertyCursorItem( PropertyList *l, PropertyItem *after, PropertyItem *prop,					const QString &propName )    : PropertyItem( l, after, prop, propName ){    comb = 0;}QComboBox *PropertyCursorItem::combo(){    if ( comb )	return comb;    comb = new QComboBox( FALSE, listview->viewport() );    comb->hide();    QBitmap cur;    cur = QBitmap(arrow_width, arrow_height, arrow_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Arrow"), ArrowCursor);    cur = QBitmap(uparrow_width, uparrow_height, uparrow_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Up-Arrow"), UpArrowCursor );    cur = QBitmap(cross_width, cross_height, cross_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Cross"), CrossCursor );    cur = QBitmap(wait_width, wait_height, wait_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Waiting"), WaitCursor );    cur = QBitmap(ibeam_width, ibeam_height, ibeam_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("iBeam"), IbeamCursor );    cur = QBitmap(sizev_width, sizev_height, sizev_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Vertical"), SizeVerCursor );    cur = QBitmap(sizeh_width, sizeh_height, sizeh_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Horizontal"), SizeHorCursor );    cur = QBitmap(sizef_width, sizef_height, sizef_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Slash"), SizeBDiagCursor );    cur = QBitmap(sizeb_width, sizeb_height, sizeb_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Backslash"), SizeFDiagCursor );    cur = QBitmap(sizeall_width, sizeall_height, sizeall_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size All"), SizeAllCursor );    cur = QBitmap( 25, 25, 1 );    cur.setMask( cur );    comb->insertItem( cur, tr("Blank"), BlankCursor );    cur = QBitmap(vsplit_width, vsplit_height, vsplit_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Split Vertical"), SplitVCursor );    cur = QBitmap(hsplit_width, hsplit_height, hsplit_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Split Horizontal"), SplitHCursor );    cur = QBitmap(hand_width, hand_height, hand_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Pointing Hand"), PointingHandCursor );    cur = QBitmap(no_width, no_height, no_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Forbidden"), ForbiddenCursor );    connect( comb, SIGNAL( activated( int ) ),	     this, SLOT( setValue() ) );    comb->installEventFilter( listview );    return comb;}PropertyCursorItem::~PropertyCursorItem(){    delete (QComboBox*)comb;}void PropertyCursorItem::showEditor(){    PropertyItem::showEditor();    if ( !comb ) {	combo()->blockSignals( TRUE );	combo()->setCurrentItem( (int)value().toCursor().shape() );	combo()->blockSignals( FALSE );    }    placeEditor( combo() );    if ( !combo()->isVisible() || !combo()->hasFocus() ) {	combo()->show();	setFocus( combo() );    }}void PropertyCursorItem::hideEditor(){    PropertyItem::hideEditor();    combo()->hide();}void PropertyCursorItem::setValue( const QVariant &v ){    if ( ( !hasSubItems() || !isOpen() )	 && value() == v )	return;    combo()->blockSignals( TRUE );    combo()->setCurrentItem( (int)v.toCursor().shape() );    combo()->blockSignals( FALSE );    setText( 1, combo()->currentText() );    PropertyItem::setValue( v );}void PropertyCursorItem::setValue(){    if ( !comb )	return;    if ( QVariant( QCursor( combo()->currentItem() ) ) == val )	return;    setText( 1, combo()->currentText() );    PropertyItem::setValue( QCursor( combo()->currentItem() ) );    notifyValueChange();}// --------------------------------------------------------------/*!  \class PropertyList propertyeditor.h  \brief PropertyList is a QListView derived class which is used for editing widget properties  This class is used for widget properties. It has to be child of a  PropertyEditor.  To initialize it for editing a widget call setupProperties() which  iterates through the properties of the current widget (see  PropertyEditor::widget()) and builds the list.  To update the item values, refetchData() can be called.  If the value of an item has been changed by the user, and this  change should be applied to the widget's property, valueChanged()  has to be called.  To set the value of an item, setPropertyValue() has to be called.*/PropertyList::PropertyList( PropertyEditor *e )    : QListView( e ), editor( e ){    header()->setMovingEnabled( FALSE );    viewport()->setBackgroundMode( PaletteBackground );    setResizePolicy( QScrollView::Manual );    addColumn( tr( "Property" ) );    addColumn( tr( "Value" ) );    connect( header(), SIGNAL( sizeChange( int, int, int ) ),	     this, SLOT( updateEditorSize() ) );    disconnect( header(), SIGNAL( sectionClicked( int ) ),		this, SLOT( changeSortColumn( int ) ) );    connect( this, SIGNAL( pressed( QListViewItem *, const QPoint &, int ) ),	     this, SLOT( itemPressed( QListViewItem *, const QPoint &, int ) ) );    connect( this, SIGNAL( doubleClicked( QListViewItem * ) ),	     this, SLOT( toggleOpen( QListViewItem * ) ) );    setSorting( -1 );    setHScrollBarMode( AlwaysOff );}void PropertyList::resizeEvent( QResizeEvent *e ){    QListView::resizeEvent( e );    QSize vs = viewportSize( 0, contentsHeight() );    int os = header()->sectionSize( 1 );    int ns = vs.width() - header()->sectionSize( 0 );    if ( ns < 16 )	ns = 16;	    header()->resizeSection( 1, ns );    header()->repaint( header()->width() - header()->sectionSize( 1 ), 0, header()->sectionSize( 1 ), header()->height() );    int elipsis = fontMetrics().width("...") + 10;    viewport()->repaint( header()->sectionPos(1) + os - elipsis, 0, elipsis, viewport()->height(), FALSE );    if ( currentItem() )	( ( PropertyItem* )currentItem() )->showEditor();}static QVariant::Type type_to_variant( const QString &s ){    if ( s == "Invalid " )	return QVariant::Invalid;    if ( s == "Map" )	return QVariant::Map;    if ( s == "List" )	return QVariant::List;    if ( s == "String" )	return QVariant::String;    if ( s == "StringList" )	return QVariant::StringList;    if ( s == "Font" )	return QVariant::Font;    if ( s == "Pixmap" )	return QVariant::Pixmap;    if ( s == "Brush" )	return QVariant::Brush;    if ( s == "Rect" )	return QVariant::Rect;    if ( s == "Size" )	return QVariant::Size;    if ( s == "Color" )	return QVariant::Color;    if ( s == "Palette" )	return QVariant::Palette;    if ( s == "ColorGroup" )	return QVariant::ColorGroup;    if ( s == "IconSet" )	return QVariant::IconSet;    if ( s == "Point" )	return QVariant::Point;    if ( s == "Image" )	return QVariant::Image;    if ( s == "Int" )	return QVariant::Int;    if ( s == "UInt" )	return QVariant::UInt;    if ( s == "Bool" )	return QVariant::Bool;    if ( s == "Double" )	return QVariant::Double;    if ( s == "CString" )	return QVariant::CString;

⌨️ 快捷键说明

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