📄 propertyeditor.cpp
字号:
bool PropertyItem::hasCustomContents() const{ return FALSE;}/*! \sa hasCustomContents()*/void PropertyItem::drawCustomContents( QPainter *, const QRect & ){}QString PropertyItem::currentItem() const{ return QString::null;}int PropertyItem::currentIntItem() const{ return -1;}void PropertyItem::setCurrentItem( const QString & ){}void PropertyItem::setCurrentItem( int ){}int PropertyItem::currentIntItemFromObject() const{ return -1;}QString PropertyItem::currentItemFromObject() const{ return QString::null;}void PropertyItem::setFocus( QWidget *w ){ if ( !qApp->focusWidget() || listview->propertyEditor()->formWindow() && ( !MainWindow::self->isAFormWindowChild( qApp->focusWidget() ) && !qApp->focusWidget()->inherits( "Editor" ) ) ) w->setFocus();}void PropertyItem::setText( int col, const QString &t ){ QString txt( t ); if ( col == 1 ) txt = txt.replace( "\n", " " ); QListViewItem::setText( col, txt );}// --------------------------------------------------------------PropertyTextItem::PropertyTextItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName, bool comment, bool multiLine, bool ascii, bool a ) : PropertyItem( l, after, prop, propName ), withComment( comment ), hasMultiLines( multiLine ), asciiOnly( ascii ), accel( a ){ lin = 0; box = 0;}QLineEdit *PropertyTextItem::lined(){ if ( lin ) return lin; if ( hasMultiLines ) { box = new QHBox( listview->viewport() ); box->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); box->setLineWidth( 2 ); box->hide(); } lin = 0; if ( hasMultiLines ) lin = new QLineEdit( box ); else lin = new QLineEdit( listview->viewport() ); if ( asciiOnly ) { if ( PropertyItem::name() == "name" ) { lin->setValidator( new AsciiValidator( QString(":"), lin, "ascii_validator" ) ); if ( listview->propertyEditor()->formWindow()->isFake() ) lin->setEnabled( FALSE ); } else { lin->setValidator( new AsciiValidator( QString("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9" "\xaa\xab\xac\xad\xae\xaf\xb1\xb2\xb3" "\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc" "\xbd\xbe\xbf"), lin, "ascii_validator" ) ); } } if ( !hasMultiLines ) { lin->hide(); } else { button = new QPushButton( tr("..."), box ); setupStyle( button ); button->setFixedWidth( 20 ); connect( button, SIGNAL( clicked() ), this, SLOT( getText() ) ); lin->setFrame( FALSE ); } connect( lin, SIGNAL( returnPressed() ), this, SLOT( setValue() ) ); connect( lin, SIGNAL( textChanged( const QString & ) ), this, SLOT( setValue() ) ); if ( PropertyItem::name() == "name" || PropertyItem::name() == "itemName" ) connect( lin, SIGNAL( returnPressed() ), listview->propertyEditor()->formWindow()->commandHistory(), SLOT( checkCompressedCommand() ) ); lin->installEventFilter( listview ); return lin;}PropertyTextItem::~PropertyTextItem(){ delete (QLineEdit*)lin; lin = 0; delete (QHBox*)box; box = 0;}void PropertyTextItem::setChanged( bool b, bool updateDb ){ PropertyItem::setChanged( b, updateDb ); if ( withComment && childCount() > 0 ) ( (PropertyTextItem*)PropertyItem::child( 0 ) )->lined()->setEnabled( b );}bool PropertyTextItem::hasSubItems() const{ return withComment;}void PropertyTextItem::childValueChanged( PropertyItem *child ){ if ( PropertyItem::name() != "name" ) MetaDataBase::setPropertyComment( listview->propertyEditor()->widget(), PropertyItem::name(), child->value().toString() ); else MetaDataBase::setExportMacro( listview->propertyEditor()->widget(), child->value().toString() ); listview->propertyEditor()->formWindow()->commandHistory()->setModified( TRUE );}void PropertyTextItem::showEditor(){ PropertyItem::showEditor(); if ( !lin || lin->text().length() == 0 ) { lined()->blockSignals( TRUE ); lined()->setText( value().toString() ); lined()->blockSignals( FALSE ); } QWidget* w; if ( hasMultiLines ) w = box; else w= lined(); placeEditor( w ); if ( !w->isVisible() || !lined()->hasFocus() ) { w->show(); setFocus( lined() ); }}void PropertyTextItem::createChildren(){ PropertyTextItem *i = new PropertyTextItem( listview, this, this, PropertyItem::name() == "name" ? "export macro" : "comment", FALSE, FALSE, PropertyItem::name() == "name" ); i->lined()->setEnabled( isChanged() ); addChild( i );}void PropertyTextItem::initChildren(){ if ( !childCount() ) return; PropertyItem *item = PropertyItem::child( 0 ); if ( item ) { if ( PropertyItem::name() != "name" ) item->setValue( MetaDataBase::propertyComment( listview->propertyEditor()->widget(), PropertyItem::name() ) ); else item->setValue( MetaDataBase::exportMacro( listview->propertyEditor()->widget() ) ); }}void PropertyTextItem::hideEditor(){ PropertyItem::hideEditor(); QWidget* w; if ( hasMultiLines ) w = box; else w = lined(); w->hide();}void PropertyTextItem::setValue( const QVariant &v ){ if ( ( !hasSubItems() || !isOpen() ) && value() == v ) return; if ( lin ) { lined()->blockSignals( TRUE ); int oldCursorPos; oldCursorPos = lin->cursorPosition(); lined()->setText( v.toString() ); if ( oldCursorPos < (int)lin->text().length() ) lin->setCursorPosition( oldCursorPos ); lined()->blockSignals( FALSE ); } setText( 1, v.toString() ); PropertyItem::setValue( v );}void PropertyTextItem::setValue(){ setText( 1, lined()->text() ); QVariant v; if ( accel ) { v = QVariant( QKeySequence( lined()->text() ) ); if ( v.toString().isNull() ) return; // not yet valid input } else { v = lined()->text(); } PropertyItem::setValue( v ); notifyValueChange();}void PropertyTextItem::getText(){ QString txt = MultiLineEditor::getText( listview, value().toString(), !listview->propertyEditor()->widget()->inherits( "QButton" ) ); if ( !txt.isEmpty() ) { setText( 1, txt ); PropertyItem::setValue( txt ); notifyValueChange(); lined()->blockSignals( TRUE ); lined()->setText( txt ); lined()->blockSignals( FALSE ); }}// --------------------------------------------------------------PropertyDoubleItem::PropertyDoubleItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName ) : PropertyItem( l, after, prop, propName ){ lin = 0;}QLineEdit *PropertyDoubleItem::lined(){ if ( lin ) return lin; lin = new QLineEdit( listview->viewport() ); lin->setValidator( new QDoubleValidator( lin, "double_validator" ) ); connect( lin, SIGNAL( returnPressed() ), this, SLOT( setValue() ) ); connect( lin, SIGNAL( textChanged( const QString & ) ), this, SLOT( setValue() ) ); lin->installEventFilter( listview ); return lin;}PropertyDoubleItem::~PropertyDoubleItem(){ delete (QLineEdit*)lin; lin = 0;}void PropertyDoubleItem::showEditor(){ PropertyItem::showEditor(); if ( !lin ) { lined()->blockSignals( TRUE ); lined()->setText( QString::number( value().toDouble() ) ); lined()->blockSignals( FALSE ); } QWidget* w = lined(); placeEditor( w ); if ( !w->isVisible() || !lined()->hasFocus() ) { w->show(); setFocus( lined() ); }}void PropertyDoubleItem::hideEditor(){ PropertyItem::hideEditor(); QWidget* w = lined(); w->hide();}void PropertyDoubleItem::setValue( const QVariant &v ){ if ( value() == v ) return; if ( lin ) { lined()->blockSignals( TRUE ); int oldCursorPos; oldCursorPos = lin->cursorPosition(); lined()->setText( QString::number( v.toDouble() ) ); if ( oldCursorPos < (int)lin->text().length() ) lin->setCursorPosition( oldCursorPos ); lined()->blockSignals( FALSE ); } setText( 1, QString::number( v.toDouble() ) ); PropertyItem::setValue( v );}void PropertyDoubleItem::setValue(){ setText( 1, lined()->text() ); QVariant v = lined()->text().toDouble(); PropertyItem::setValue( v ); notifyValueChange();}// --------------------------------------------------------------PropertyDateItem::PropertyDateItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName ) : PropertyItem( l, after, prop, propName ){ lin = 0;}QDateEdit *PropertyDateItem::lined(){ if ( lin ) return lin; lin = new QDateEdit( listview->viewport() ); QObjectList *l = lin->queryList( "QLineEdit" ); for ( QObject *o = l->first(); o; o = l->next() ) o->installEventFilter( listview ); delete l; connect( lin, SIGNAL( valueChanged( const QDate & ) ), this, SLOT( setValue() ) ); return lin;}PropertyDateItem::~PropertyDateItem(){ delete (QDateEdit*)lin; lin = 0;}void PropertyDateItem::showEditor(){ PropertyItem::showEditor(); if ( !lin ) { lined()->blockSignals( TRUE ); lined()->setDate( value().toDate() ); lined()->blockSignals( FALSE ); } placeEditor( lin ); if ( !lin->isVisible() ) { lin->show(); setFocus( lin ); }}void PropertyDateItem::hideEditor(){ PropertyItem::hideEditor(); if ( lin ) lin->hide();}void PropertyDateItem::setValue( const QVariant &v ){ if ( ( !hasSubItems() || !isOpen() ) && value() == v ) return; if ( lin ) { lined()->blockSignals( TRUE ); if ( lined()->date() != v.toDate() ) lined()->setDate( v.toDate() ); lined()->blockSignals( FALSE ); } setText( 1, v.toDate().toString( ::Qt::ISODate ) ); PropertyItem::setValue( v );}void PropertyDateItem::setValue(){ setText( 1, lined()->date().toString( ::Qt::ISODate ) ); QVariant v; v = lined()->date(); PropertyItem::setValue( v ); notifyValueChange();}// --------------------------------------------------------------PropertyTimeItem::PropertyTimeItem( PropertyList *l, PropertyItem *after, PropertyItem *prop, const QString &propName ) : PropertyItem( l, after, prop, propName ){ lin = 0;}QTimeEdit *PropertyTimeItem::lined(){ if ( lin ) return lin; lin = new QTimeEdit( listview->viewport() ); connect( lin, SIGNAL( valueChanged( const QTime & ) ), this, SLOT( setValue() ) ); QObjectList *l = lin->queryList( "QLineEdit" ); for ( QObject *o = l->first(); o; o = l->next() ) o->installEventFilter( listview ); delete l; return lin;}PropertyTimeItem::~PropertyTimeItem(){ delete (QTimeEdit*)lin; lin = 0;}void PropertyTimeItem::showEditor(){ PropertyItem::showEditor(); if ( !lin ) { lined()->blockSignals( TRUE ); lined()->setTime( value().toTime() ); lined()->blockSignals( FALSE ); } placeEditor( lin ); if ( !lin->isVisible() ) { lin->show(); setFocus( lin ); }}void PropertyTimeItem::hideEditor(){ PropertyItem::hideEditor(); if ( lin ) lin->hide();}void PropertyTimeItem::setValue( const QVariant &v ){ if ( ( !hasSubItems() || !isOpen() ) && value() == v ) return; if ( lin ) { lined()->blockSignals( TRUE ); if ( lined()->time() != v.toTime() ) lined()->setTime( v.toTime() ); lined()->blockSignals( FALSE ); } setText( 1, v.toTime().toString( ::Qt::ISODate ) ); PropertyItem::setValue( v );}void PropertyTimeItem::setValue(){ setText( 1, lined()->time().toString( ::Qt::ISODate ) ); QVariant v; v = lined()->time(); PropertyItem::setValue( v ); notifyValueChange();}// --------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -