qdesigner_propertycommand.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,210 行 · 第 1/4 页
CPP
1,210 行
if (mask & maskBit) { for (int group = QPalette::Active; group < QPalette::NColorGroups; group++) { const QPalette::ColorGroup pgroup = static_cast<QPalette::ColorGroup>(group); const QPalette::ColorRole prole = static_cast<QPalette::ColorRole>(role); rc.setColor(pgroup, prole, newValue.color(pgroup, prole)); } // Set the resolve bit from NewValue in return value uint r = rc.resolve(); const bool origFlag = newValue.resolve() & maskBit; if (origFlag) r |= maskBit; else r &= ~maskBit; rc.resolve(r); } } return rc;}// apply changed subproperties to a QAlignment which is a flag combination of vertical and horizontalQt::Alignment applyAlignmentSubProperty(Qt::Alignment oldValue, Qt::Alignment newValue, unsigned mask){ // easy: both changed. if (mask == (SubPropertyHorizontalAlignment|SubPropertyVerticalAlignment)) return newValue; // Change subprop const Qt::Alignment changeMask = (mask & SubPropertyHorizontalAlignment) ? Qt::AlignHorizontal_Mask : Qt::AlignVertical_Mask; const Qt::Alignment takeOverMask = (mask & SubPropertyHorizontalAlignment) ? Qt::AlignVertical_Mask : Qt::AlignHorizontal_Mask; return (oldValue & takeOverMask) | (newValue & changeMask);}// apply changed subproperties to a variantQVariant applySubProperty(const QVariant &oldValue, const QVariant &newValue, qdesigner_internal::SpecialProperty specialProperty, unsigned mask){ if (mask == SubPropertyAll) return newValue; switch (oldValue.type()) { case QVariant::Rect: return applyRectSubProperty(oldValue.toRect(), newValue.toRect(), mask); case QVariant::Size: return applySizeSubProperty(oldValue.toSize(), newValue.toSize(), mask); case QVariant::SizePolicy: return qVariantFromValue(applySizePolicySubProperty(qvariant_cast<QSizePolicy>(oldValue), qvariant_cast<QSizePolicy>(newValue), mask)); case QVariant::Font: return qVariantFromValue(applyFontSubProperty(qvariant_cast<QFont>(oldValue), qvariant_cast<QFont>(newValue), mask)); case QVariant::Palette: return qVariantFromValue(applyPaletteSubProperty(qvariant_cast<QPalette>(oldValue), qvariant_cast<QPalette>(newValue), mask)); default: // Enumerations, flags switch (specialProperty) { case qdesigner_internal::SP_Alignment: { qdesigner_internal::FlagType f = qvariant_cast<qdesigner_internal::FlagType>(oldValue); f.value = static_cast<uint>(applyAlignmentSubProperty(variantToAlignment(oldValue), variantToAlignment(newValue), mask)); QVariant v; qVariantSetValue(v, f); return v; } default: break; } break; } return newValue;}}namespace qdesigner_internal {// figure out special propertyenum SpecialProperty getSpecialProperty(const QString& propertyName){ if (propertyName == QLatin1String("objectName")) return SP_ObjectName; if (propertyName == QLatin1String("icon")) return SP_Icon; if (propertyName == QLatin1String("currentTabName")) return SP_CurrentTabName; if (propertyName == QLatin1String("geometry")) return SP_Geometry; if (propertyName == QLatin1String("windowTitle")) return SP_WindowTitle; if (propertyName == QLatin1String("minimumSize")) return SP_MinimumSize; if (propertyName == QLatin1String("maximumSize")) return SP_MaximumSize; if (propertyName == QLatin1String("alignment")) return SP_Alignment; if (propertyName == QLatin1String("autoDefault")) return SP_AutoDefault; return SP_None;}PropertyHelper::PropertyHelper(QObject* object, SpecialProperty specialProperty, QDesignerPropertySheetExtension *sheet, int index) : m_specialProperty(specialProperty), m_object(object), m_objectType(OT_Object), m_propertySheet(sheet), m_index(index), m_oldValue(m_propertySheet->property(m_index), m_propertySheet->isChanged(m_index)){ if (object->isWidgetType()) { m_parentWidget = (qobject_cast<QWidget*>(object))->parentWidget(); m_objectType = OT_Widget; } else { if (const QAction *action = qobject_cast<const QAction *>(m_object)) m_objectType = action->associatedWidgets().empty() ? OT_FreeAction : OT_AssociatedAction; } if(debugPropertyCommands) qDebug() << "PropertyHelper on " << m_object->objectName() << " index= " << m_index << " type = " << m_objectType;}QDesignerIntegration *PropertyHelper::integration(QDesignerFormWindowInterface *fw) const{ return qobject_cast<QDesignerIntegration *>(fw->core()->integration());}// Set widget value, apply corrections and checks in case of main window.void PropertyHelper::checkApplyWidgetValue(QDesignerFormWindowInterface *fw, QWidget* w, SpecialProperty specialProperty, QVariant &value){ bool isMainContainer = false; if (QDesignerFormWindowCursorInterface *cursor = fw->cursor()) { if (cursor->isWidgetSelected(w)) { if (cursor->isWidgetSelected(fw->mainContainer())) { isMainContainer = true; } } } if (!isMainContainer) return; QWidget *container = fw->core()->integration()->containerWindow(fw); if (!container) return; switch (specialProperty) { case SP_MinimumSize: { const QSize diff = diffSize(fw); const QSize size = checkSize(value.toSize()); container->setMinimumSize((size + diff).expandedTo(QSize(16, 16))); qVariantSetValue(value, size); } break; case SP_MaximumSize: { QSize fs, cs; checkSizes(fw, value.toSize(), &fs, &cs); container->setMaximumSize(cs); fw->mainContainer()->setMaximumSize(fs); qVariantSetValue(value, fs); } break; case SP_Geometry: { QRect r = value.toRect(); QSize fs, cs; checkSizes(fw, r.size(), &fs, &cs); container->resize(cs); r.setSize(fs); qVariantSetValue(value, r); } break; default: break; }}unsigned PropertyHelper::updateMask() const{ unsigned rc = 0; switch (m_specialProperty) { case SP_ObjectName: case SP_CurrentTabName: if (m_objectType != OT_FreeAction) rc |= UpdateObjectInspector; break; case SP_Icon: if (m_objectType == OT_AssociatedAction) rc |= UpdateObjectInspector; break; default: break; } return rc;}bool PropertyHelper::canMerge(const PropertyHelper &other) const{ return m_object == other.m_object && m_index == other.m_index;}// Update the object to reflect the changesvoid PropertyHelper::updateObject(QDesignerFormWindowInterface *fw, const QVariant &oldValue, const QVariant &newValue){ if(debugPropertyCommands){ qDebug() << "PropertyHelper::updateObject(" << m_object->objectName() << ") " << oldValue << " -> " << newValue; } switch (m_objectType) { case OT_Widget: { switch (m_specialProperty) { case SP_ObjectName: QDesignerFormWindowCommand::updateBuddies(fw, oldValue.toString(), newValue.toString()); break; default: break; } } break; case OT_AssociatedAction: case OT_FreeAction: if (m_specialProperty == SP_ObjectName) { QAction *act = qobject_cast<QAction *>(m_object); act->setData(QVariant(true)); // this triggers signal "changed" in QAction act->setData(QVariant(false)); } break; default: break; } if (m_specialProperty == SP_ObjectName) { QDesignerIntegration *integr = integration(fw); if (integr) integr->emitObjectNameChanged(fw, m_object, newValue.toString()); }}PropertyHelper::Value PropertyHelper::setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, unsigned subPropertyMask){ // Set new whole value if (subPropertyMask == SubPropertyAll) return applyValue(fw, m_oldValue.first, Value(value, changed)); // apply subproperties const QVariant maskedNewValue = applySubProperty(m_oldValue.first, value, m_specialProperty, subPropertyMask); return applyValue(fw, m_oldValue.first, Value(maskedNewValue, changed));}// Apply the value and update. Returns corrected valuePropertyHelper::Value PropertyHelper::applyValue(QDesignerFormWindowInterface *fw, const QVariant &oldValue, Value newValue){ if(debugPropertyCommands){ qDebug() << "PropertyHelper::applyValue(" << m_object->objectName() << ") " << oldValue << " -> " << newValue.first << " changed=" << newValue.second; } if (m_objectType == OT_Widget) { checkApplyWidgetValue(fw, qobject_cast<QWidget *>(m_object), m_specialProperty, newValue.first); } m_propertySheet->setProperty(m_index, newValue.first); m_propertySheet->setChanged(m_index, newValue.second); if (m_specialProperty == SP_ObjectName) { fw->ensureUniqueObjectName(m_object); newValue.first = m_propertySheet->property(m_index); } updateObject(fw, oldValue, newValue.first); return newValue;}PropertyHelper::Value PropertyHelper::restoreOldValue(QDesignerFormWindowInterface *fw){ return applyValue(fw, m_propertySheet->property(m_index), m_oldValue);}// find the default value in widget DB in case PropertySheet::reset failsQVariant PropertyHelper::findDefaultValue(QDesignerFormWindowInterface *fw) const{ if (m_specialProperty == SP_AutoDefault && qobject_cast<const QPushButton*>(m_object)) { // AutoDefault defaults to true on dialogs const bool isDialog = qobject_cast<const QDialog *>(fw->mainContainer()); return QVariant(isDialog); } const int item_idx = fw->core()->widgetDataBase()->indexOfObject(m_object); if (item_idx == -1) return m_oldValue.first; // We simply don't know the value in this case const QDesignerWidgetDataBaseItemInterface *item = fw->core()->widgetDataBase()->item(item_idx); const QList<QVariant> default_prop_values = item->defaultPropertyValues(); if (m_index < default_prop_values.size()) return default_prop_values.at(m_index); if (m_oldValue.first.type() == QVariant::Color) return QColor(); return m_oldValue.first; // Again, we just don't know}PropertyHelper::Value PropertyHelper::restoreDefaultValue(QDesignerFormWindowInterface *fw){ Value defaultValue = qMakePair(QVariant(), false); const QVariant currentValue = m_propertySheet->property(m_index);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?