📄 propertyeditor.cpp
字号:
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(); 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 ); setupStyle( button ); 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; comb->insertItem( QPixmap::fromMimeSource( "arrow.png" ), tr("Arrow"), QObject::ArrowCursor); comb->insertItem( QPixmap::fromMimeSource( "uparrow.png" ), tr("Up-Arrow"), QObject::UpArrowCursor ); comb->insertItem( QPixmap::fromMimeSource( "cross.png" ), tr("Cross"), QObject::CrossCursor ); comb->insertItem( QPixmap::fromMimeSource( "wait.png" ), tr("Waiting"), QObject::WaitCursor ); comb->insertItem( QPixmap::fromMimeSource( "ibeam.png" ), tr("iBeam"), QObject::IbeamCursor ); comb->insertItem( QPixmap::fromMimeSource( "sizev.png" ), tr("Size Vertical"), QObject::SizeVerCursor ); comb->insertItem( QPixmap::fromMimeSource( "sizeh.png" ), tr("Size Horizontal"), QObject::SizeHorCursor ); comb->insertItem( QPixmap::fromMimeSource( "sizef.png" ), tr("Size Slash"), QObject::SizeBDiagCursor ); comb->insertItem( QPixmap::fromMimeSource( "sizeb.png" ), tr("Size Backslash"), QObject::SizeFDiagCursor ); comb->insertItem( QPixmap::fromMimeSource( "sizeall.png" ), tr("Size All"), QObject::SizeAllCursor ); cur = QBitmap( 25, 25, 1 ); cur.setMask( cur ); comb->insertItem( cur, tr("Blank"), QObject::BlankCursor ); comb->insertItem( QPixmap::fromMimeSource( "vsplit.png" ), tr("Split Vertical"), QObject::SplitVCursor ); comb->insertItem( QPixmap::fromMimeSource( "hsplit.png" ), tr("Split Horizontal"), QObject::SplitHCursor ); comb->insertItem( QPixmap::fromMimeSource( "hand.png" ), tr("Pointing Hand"), QObject::PointingHandCursor ); comb->insertItem( QPixmap::fromMimeSource( "no.png" ), 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 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -