propertyeditor.cpp

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

CPP
2,457
字号
    placeEditor( box );    if ( !box->isVisible() || !lined->hasFocus() ) {	box->show();	setFocus( lined );    }}void PropertyDatabaseItem::hideEditor(){    PropertyItem::hideEditor();    box->hide();}void PropertyDatabaseItem::setValue( const QVariant &v ){    if ( value() == v )	return;    QStringList lst = v.toStringList();    QString s = lst.join( "." );    setText( 1, s );    lined->setText( s );    PropertyItem::setValue( v );}bool PropertyDatabaseItem::hasSubItems() const{    return TRUE;}void PropertyDatabaseItem::childValueChanged( PropertyItem *c ){#ifndef QT_NO_SQL    QStringList lst;    lst << ( (PropertyListItem*)PropertyItem::child( 0 ) )->currentItem()	<< ( (PropertyListItem*)PropertyItem::child( 1 ) )->currentItem();    if ( withField )	lst << ( (PropertyListItem*)PropertyItem::child( 2 ) )->currentItem();    if ( c == PropertyItem::child( 0 ) ) { // if the connection changed	lst[ 0 ] = ( (PropertyListItem*)c )->currentItem();	PropertyItem::child( 1 )->setValue( listview->propertyEditor()->formWindow()->project()->databaseTableList( lst[ 0 ] ) );	if ( withField )	    PropertyItem::child( 2 )->setValue( listview->propertyEditor()->formWindow()->project()->databaseFieldList( lst[ 0 ], lst[ 1 ] ) );    } else if ( withField && c == PropertyItem::child( 1 ) ) { // if the table changed	lst[ 1 ] = ( (PropertyListItem*)c )->currentItem();	if ( withField )	    PropertyItem::child( 2 )->setValue( listview->propertyEditor()->formWindow()->project()->databaseFieldList( lst[ 0 ], lst[ 1 ] ) );    }    lst.clear();    lst << ( (PropertyListItem*)PropertyItem::child( 0 ) )->currentItem()	<< ( (PropertyListItem*)PropertyItem::child( 1 ) )->currentItem();    if ( withField )	lst << ( (PropertyListItem*)PropertyItem::child( 2 ) )->currentItem();    setValue( lst );    notifyValueChange();#else    Q_UNUSED( c );#endif}// --------------------------------------------------------------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" << "Ignored";    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 );    i = new PropertyIntItem( listview, i, this, tr( "horizontalStretch" ), TRUE );    addChild( i );    i = new PropertyIntItem( listview, i, this, tr( "verticalStretch" ), TRUE );    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() ) );	else if ( item->name() == tr( "horizontalStretch" ) )	    ( (PropertyIntItem*)item )->setValue( sp.horStretch() );	else if ( item->name() == tr( "verticalStretch" ) )	    ( (PropertyIntItem*)item )->setValue( sp.verStretch() );    }}PropertySizePolicyItem::~PropertySizePolicyItem(){    delete (QLineEdit*)lin;}void PropertySizePolicyItem::showEditor(){    PropertyItem::showEditor();    placeEditor( lined() );    if ( !lined()->isVisible() || !lined()->hasFocus() ) {	lined()->show();	listView()->viewport()->setFocus();    }}void PropertySizePolicyItem::hideEditor(){    PropertyItem::hideEditor();    lined()->hide();}void PropertySizePolicyItem::setValue( const QVariant &v ){    if ( value() == v )	return;    QString s = tr( "%1/%2/%2/%2" );    s = s.arg( size_type_to_string( v.toSizePolicy().horData() ) ).	arg( size_type_to_string( v.toSizePolicy().verData() ) ).	arg( v.toSizePolicy().horStretch() ).	arg( v.toSizePolicy().verStretch() );    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() ) );    else if ( child->name() == tr( "horizontalStretch" ) )	sp.setHorStretch( ( ( PropertyIntItem*)child )->value().toInt() );    else if ( child->name() == tr( "verticalStretch" ) )	sp.setVerStretch( ( ( PropertyIntItem*)child )->value().toInt() );    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();	listView()->viewport()->setFocus();    }}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(){    if ( !listview->propertyEditor()->widget()->isWidgetType() )	return;    bool ok = FALSE;    QWidget *w = (QWidget*)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"), QObject::ArrowCursor);    cur = QBitmap(uparrow_width, uparrow_height, uparrow_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Up-Arrow"), QObject::UpArrowCursor );    cur = QBitmap(cross_width, cross_height, cross_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Cross"), QObject::CrossCursor );    cur = QBitmap(wait_width, wait_height, wait_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Waiting"), QObject::WaitCursor );    cur = QBitmap(ibeam_width, ibeam_height, ibeam_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("iBeam"), QObject::IbeamCursor );    cur = QBitmap(sizev_width, sizev_height, sizev_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Vertical"), QObject::SizeVerCursor );    cur = QBitmap(sizeh_width, sizeh_height, sizeh_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Horizontal"), QObject::SizeHorCursor );    cur = QBitmap(sizef_width, sizef_height, sizef_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Slash"), QObject::SizeBDiagCursor );    cur = QBitmap(sizeb_width, sizeb_height, sizeb_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size Backslash"), QObject::SizeFDiagCursor );    cur = QBitmap(sizeall_width, sizeall_height, sizeall_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Size All"), QObject::SizeAllCursor );    cur = QBitmap( 25, 25, 1 );    cur.setMask( cur );    comb->insertItem( cur, tr("Blank"), QObject::BlankCursor );    cur = QBitmap(vsplit_width, vsplit_height, vsplit_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Split Vertical"), QObject::SplitVCursor );    cur = QBitmap(hsplit_width, hsplit_height, hsplit_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Split Horizontal"), QObject::SplitHCursor );    cur = QBitmap(hand_width, hand_height, hand_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Pointing Hand"), QObject::PointingHandCursor );    cur = QBitmap(no_width, no_height, no_bits, TRUE);    cur.setMask( cur );    comb->insertItem( cur, tr("Forbidden"), QObject::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 ){    init_colors();    whatsThis = new PropertyWhatsThis( this );    showSorted = FALSE;    header()->setMovingEnabled( FALSE );    header()->setStretchEnabled( TRUE );    setResizePolicy( QScrollView::Manual );    viewport()->setAcceptDrops( TRUE );    viewport()->installEventFilter( this );    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( header(), SIGNAL( sectionClicked( int ) ),	     this, SLOT( toggleSort() ) );    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 );    setVScrollBarMode( AlwaysOn );    setColumnWidthMode( 1, Manual );    mousePressed = FALSE;    pressItem = 0;    header()->installEventFilter( this );}void PropertyList::toggleSort(){    showSorted = !showSorted;    editor->clear();    editor->setup();}void PropertyList::resizeEvent( QResizeEvent *e ){    QListView::resizeEvent( e );    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::Palet

⌨️ 快捷键说明

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