📄 qpropertyeditor_items.cpp
字号:
i->setFake(true); i->setParent(this); m_properties << i; i = new IntProperty(value.verticalStretch(), QLatin1String("verticalStretch")); i->setFake(true); i->setParent(this); m_properties << i;}QVariant SizePolicyProperty::value() const{ QSizePolicy sizePolicy; sizePolicy.setHorizontalPolicy(int_to_size_type(propertyAt(0)->value().toInt())); sizePolicy.setVerticalPolicy(int_to_size_type(propertyAt(1)->value().toInt())); sizePolicy.setHorizontalStretch(propertyAt(2)->value().toInt()); sizePolicy.setVerticalStretch(propertyAt(3)->value().toInt()); return qVariantFromValue(sizePolicy);}void SizePolicyProperty::setValue(const QVariant &value){ QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(value); propertyAt(0)->setValue(size_type_to_int(sizePolicy.horizontalPolicy())); propertyAt(1)->setValue(size_type_to_int(sizePolicy.verticalPolicy())); propertyAt(2)->setValue(sizePolicy.horizontalStretch()); propertyAt(3)->setValue(sizePolicy.verticalStretch());}QVariant SizePolicyProperty::decoration() const{ return QVariant();}QString SizePolicyProperty::toString() const{ return AbstractPropertyGroup::toString();}// -------------------------------------------------------------------------DateTimeProperty::DateTimeProperty(const QDateTime &value, const QString &name) : AbstractProperty<QDateTime>(value, name){}void DateTimeProperty::setValue(const QVariant &value){ m_value = value.toDateTime();}QString DateTimeProperty::toString() const{ return m_value.toString();}QWidget *DateTimeProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ QDateTimeEdit *lineEdit = new QDateTimeEdit(parent); QObject::connect(lineEdit, SIGNAL(dateTimeChanged(QDateTime)), target, receiver); return lineEdit;}void DateTimeProperty::updateEditorContents(QWidget *editor){ if (QDateTimeEdit *lineEdit = qobject_cast<QDateTimeEdit*>(editor)) { lineEdit->setDateTime(m_value); }}void DateTimeProperty::updateValue(QWidget *editor){ if (QDateTimeEdit *lineEdit = qobject_cast<QDateTimeEdit*>(editor)) { QDateTime newValue = lineEdit->dateTime(); if (newValue != m_value) { m_value = newValue; setChanged(true); } }}// -------------------------------------------------------------------------DateProperty::DateProperty(const QDate &value, const QString &name) : AbstractProperty<QDate>(value, name){}void DateProperty::setValue(const QVariant &value){ m_value = value.toDate();}QString DateProperty::toString() const{ return m_value.toString();}QWidget *DateProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ QDateEdit *lineEdit = new QDateEdit(parent); QObject::connect(lineEdit, SIGNAL(dateChanged(QDate)), target, receiver); return lineEdit;}void DateProperty::updateEditorContents(QWidget *editor){ if (QDateEdit *lineEdit = qobject_cast<QDateEdit*>(editor)) { lineEdit->setDate(m_value); }}void DateProperty::updateValue(QWidget *editor){ if (QDateEdit *lineEdit = qobject_cast<QDateEdit*>(editor)) { QDate newValue = lineEdit->date(); if (newValue != m_value) { m_value = newValue; setChanged(true); } }}// -------------------------------------------------------------------------TimeProperty::TimeProperty(const QTime &value, const QString &name) : AbstractProperty<QTime>(value, name){}void TimeProperty::setValue(const QVariant &value){ m_value = value.toTime();}QString TimeProperty::toString() const{ return m_value.toString();}QWidget *TimeProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ QTimeEdit *lineEdit = new QTimeEdit(parent); QObject::connect(lineEdit, SIGNAL(timeChanged(QTime)), target, receiver); return lineEdit;}void TimeProperty::updateEditorContents(QWidget *editor){ if (QTimeEdit *lineEdit = qobject_cast<QTimeEdit*>(editor)) { lineEdit->setTime(m_value); }}void TimeProperty::updateValue(QWidget *editor){ if (QTimeEdit *lineEdit = qobject_cast<QTimeEdit*>(editor)) { QTime newValue = lineEdit->time(); if (newValue != m_value) { m_value = newValue; setChanged(true); } }}// -------------------------------------------------------------------------CursorProperty::CursorProperty(const QCursor &value, const QString &name) : AbstractProperty<QCursor>(value, name){}void CursorProperty::setValue(const QVariant &value){ m_value = qvariant_cast<QCursor>(value);}QString CursorProperty::toString() const{ return cursorName(m_value.shape());}QVariant CursorProperty::decoration() const{ return qVariantFromValue(cursorPixmap(m_value.shape()));}QWidget *CursorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ QComboBox *combo = new QComboBox(parent); combo->view()->setTextElideMode(Qt::ElideLeft); combo->setFrame(0); addCursor(combo, Qt::ArrowCursor); addCursor(combo, Qt::UpArrowCursor); addCursor(combo, Qt::CrossCursor); addCursor(combo, Qt::WaitCursor); addCursor(combo, Qt::IBeamCursor); addCursor(combo, Qt::SizeVerCursor); addCursor(combo, Qt::SizeHorCursor); addCursor(combo, Qt::SizeBDiagCursor); addCursor(combo, Qt::SizeFDiagCursor); addCursor(combo, Qt::SizeAllCursor); addCursor(combo, Qt::BlankCursor); addCursor(combo, Qt::SplitVCursor); addCursor(combo, Qt::SplitHCursor); addCursor(combo, Qt::PointingHandCursor); addCursor(combo, Qt::ForbiddenCursor); QObject::connect(combo, SIGNAL(activated(int)), target, receiver); return combo;}void CursorProperty::updateEditorContents(QWidget *editor){ if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) { combo->setCurrentIndex(m_value.shape()); }}void CursorProperty::updateValue(QWidget *editor){ if (QComboBox *combo = qobject_cast<QComboBox*>(editor)) { QCursor newValue(static_cast<Qt::CursorShape>(combo->currentIndex())); if (newValue.shape() != m_value.shape()) { m_value = newValue; setChanged(true); } }}QString CursorProperty::cursorName(int shape){ switch (shape) { case Qt::ArrowCursor: return QString::fromUtf8("Arrow"); case Qt::UpArrowCursor: return QString::fromUtf8("Up-Arrow"); case Qt::CrossCursor: return QString::fromUtf8("Cross"); case Qt::WaitCursor: return QString::fromUtf8("Waiting"); case Qt::IBeamCursor: return QString::fromUtf8("IBeam"); case Qt::SizeVerCursor: return QString::fromUtf8("Size Vertical"); case Qt::SizeHorCursor: return QString::fromUtf8("Size Horizontal"); case Qt::SizeBDiagCursor: return QString::fromUtf8("Size Slash"); case Qt::SizeFDiagCursor: return QString::fromUtf8("Size Backslash"); case Qt::SizeAllCursor: return QString::fromUtf8("Size All"); case Qt::BlankCursor: return QString::fromUtf8("Blank"); case Qt::SplitVCursor: return QString::fromUtf8("Split Vertical"); case Qt::SplitHCursor: return QString::fromUtf8("Split Horizontal"); case Qt::PointingHandCursor: return QString::fromUtf8("Pointing Hand"); case Qt::ForbiddenCursor: return QString::fromUtf8("Forbidden"); case Qt::WhatsThisCursor: return QString::fromUtf8("Whats This"); case Qt::BusyCursor: return QString::fromUtf8("Busy"); default: return QString(); }}QPixmap CursorProperty::cursorPixmap(int shape){ switch (shape) { case Qt::ArrowCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/arrow.png")); case Qt::UpArrowCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/uparrow.png")); case Qt::CrossCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/cross.png")); case Qt::WaitCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/wait.png")); case Qt::IBeamCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/ibeam.png")); case Qt::SizeVerCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizev.png")); case Qt::SizeHorCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizeh.png")); case Qt::SizeBDiagCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizef.png")); case Qt::SizeFDiagCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizeb.png")); case Qt::SizeAllCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/sizeall.png")); case Qt::BlankCursor: { QBitmap cur = QBitmap(25, 25); cur.clear(); return cur; } case Qt::SplitVCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/vsplit.png")); case Qt::SplitHCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/hsplit.png")); case Qt::PointingHandCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/hand.png")); case Qt::ForbiddenCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/no.png")); case Qt::WhatsThisCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/whatsthis.png")); case Qt::BusyCursor: return QPixmap(QString::fromUtf8(":/trolltech/formeditor/images/cursors/busy.png")); default: return QPixmap(); }}void CursorProperty::addCursor(QComboBox *combo, int shape) const{ combo->addItem(cursorPixmap(shape), cursorName(shape), shape);}// -------------------------------------------------------------------------AlignmentProperty::AlignmentProperty(const QMap<QString, QVariant> &items, Qt::Alignment value, const QString &name) : AbstractPropertyGroup(name){ QStringList horz_keys = QStringList() << QString::fromUtf8("Qt::AlignLeft") << QString::fromUtf8("Qt::AlignRight") << QString::fromUtf8("Qt::AlignHCenter") << QString::fromUtf8("Qt::AlignJustify"); // << "Qt::AlignAbsolute" QMap<QString, QVariant> horz_map; foreach (QString h, horz_keys) { horz_map.insert(h, items.value(h)); } MapProperty *ph = new MapProperty(horz_map, uint(value & Qt::AlignHorizontal_Mask), QLatin1String("horizontal")); ph->setFake(true); ph->setParent(this); m_properties << ph; QStringList vert_keys = QStringList() << QString::fromUtf8("Qt::AlignTop") << QString::fromUtf8("Qt::AlignBottom") << QString::fromUtf8("Qt::AlignVCenter"); QMap<QString, QVariant> vert_map; foreach (QString h, vert_keys) { vert_map.insert(h, items.value(h)); } MapProperty *pv = new MapProperty(vert_map, int(value & Qt::AlignVertical_Mask), QLatin1String("vertical")); pv->setFake(true); pv->setParent(this); m_properties << pv;}QVariant AlignmentProperty::value() const{ return uint(propertyAt(0)->value().toUInt() | propertyAt(1)->value().toUInt());}void AlignmentProperty::setValue(const QVariant &value){ QVariant v = value; if (qVariantCanConvert<FlagType>(value)) v = qvariant_cast<FlagType>(value).value; else if (qVariantCanConvert<EnumType>(value)) v = qvariant_cast<EnumType>(value).value; propertyAt(0)->setValue(v.toUInt() & Qt::AlignHorizontal_Mask); propertyAt(1)->setValue(v.toUInt() & Qt::AlignVertical_Mask);}// -------------------------------------------------------------------------DoubleProperty::DoubleProperty(double value, const QString &name) : AbstractProperty<double>(value, name){}void DoubleProperty::setValue(const QVariant &value){ m_value = value.toDouble();}QString DoubleProperty::toString() const{ return QString::number(m_value);}QWidget *DoubleProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ QLineEdit *lineEdit = new QLineEdit(parent); lineEdit->setFrame(0); lineEdit->setValidator(new QDoubleValidator(lineEdit)); QObject::connect(lineEdit, SIGNAL(textChanged(QString)), target, receiver); return lineEdit;}void DoubleProperty::updateEditorContents(QWidget *editor){ if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) { double v = lineEdit->text().toDouble(); if (v != m_value) lineEdit->setText(QString::number(m_value)); }}void DoubleProperty::updateValue(QWidget *editor){ if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor)) { double newValue = lineEdit->text().toDouble(); if (newValue != m_value) { m_value = newValue; setChanged(true); } }}// -------------------------------------------------------------------------PaletteProperty::PaletteProperty(const QPalette &value, QWidget *selectedWidget, const QString &name) : AbstractProperty<QPalette>(value, name){ m_selectedWidget = selectedWidget;}void PaletteProperty::setValue(const QVariant &value){ m_value = qvariant_cast<QPalette>(value);}QString PaletteProperty::toString() const{ return QString(); // ### implement me}QWidget *PaletteProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ PaletteEditorButton *btn = new PaletteEditorButton(m_value, m_selectedWidget, parent); QObject::connect(btn, SIGNAL(changed()), target, receiver); return btn;}void PaletteProperty::updateEditorContents(QWidget *editor){ if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) { btn->setPalette(m_value); }}void PaletteProperty::updateValue(QWidget *editor){ if (PaletteEditorButton *btn = qobject_cast<PaletteEditorButton*>(editor)) { QPalette newValue = btn->palette(); if (newValue.resolve() != m_value.resolve() || newValue != m_value) { m_value = newValue; setChanged(true); } }}// -------------------------------------------------------------------------SeparatorProperty::SeparatorProperty(const QString &value, const QString &name) : StringProperty(value, name){}QWidget *SeparatorProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const{ Q_UNUSED(parent); Q_UNUSED(target); Q_UNUSED(receiver); return 0;}bool SeparatorProperty::hasEditor() const{ return false; }void SeparatorProperty::updateEditorContents(QWidget *editor){ Q_UNUSED(editor); }void SeparatorProperty::updateValue(QWidget *editor){ Q_UNUSED(editor); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -