📄 abstractformbuilder.cpp
字号:
} break; case DomProperty::Set: { QByteArray pname = p->attributeName().toUtf8(); int index = meta->indexOfProperty(pname); if (index == -1) { qWarning() << "property" << pname << "is not supported"; break; } QMetaEnum e = meta->property(index).enumerator(); Q_ASSERT(e.isFlag() == true); v = e.keysToValue(p->elementSet().toUtf8()); } break; case DomProperty::Enum: { QByteArray pname = p->attributeName().toUtf8(); int index = meta->indexOfProperty(pname); if (index == -1) { // ### special-casing for Line (QFrame) -- fix for 4.2 if (!qstrcmp(meta->className(), "QFrame") && (pname == QLatin1String("orientation"))) { v = (p->elementEnum() == QLatin1String("Qt::Horizontal")) ? QFrame::HLine : QFrame::VLine; } else { qWarning() << "property" << pname << "is not supported"; } break; } QMetaEnum e = meta->property(index).enumerator(); v = e.keyToValue(p->elementEnum().toUtf8()); } break; case DomProperty::SizePolicy: { DomSizePolicy *sizep = p->elementSizePolicy(); QSizePolicy sizePolicy; sizePolicy.setHorizontalStretch(sizep->elementHorStretch()); sizePolicy.setVerticalStretch(sizep->elementVerStretch()); sizePolicy.setHorizontalPolicy((QSizePolicy::Policy) sizep->elementHSizeType()); sizePolicy.setVerticalPolicy((QSizePolicy::Policy) sizep->elementVSizeType()); v = qVariantFromValue(sizePolicy); } break; case DomProperty::StringList: { DomStringList *sl = p->elementStringList(); v = sl->elementString(); } break; default: qWarning() << "QAbstractFormBuilder::toVariant:" << p->kind() << " not implemented yet!"; break; } return v;}/*! \internal*/void QAbstractFormBuilder::setupColorGroup(QPalette &palette, QPalette::ColorGroup colorGroup, DomColorGroup *group){ // old format QList<DomColor*> colors = group->elementColor(); for (int role = 0; role < colors.size(); ++role) { DomColor *color = colors.at(role); QColor c(color->elementRed(), color->elementGreen(), color->elementBlue()); palette.setColor(colorGroup, QPalette::ColorRole(role), c); } // new format int e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("colorRole"); Q_ASSERT(e_index != -1); QMetaEnum colorRole_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); QList<DomColorRole*> colorRoles = group->elementColorRole(); for (int role = 0; role < colorRoles.size(); ++role) { DomColorRole *colorRole = colorRoles.at(role); if (colorRole->hasAttributeRole()) { int r = colorRole_enum.keyToValue(colorRole->attributeRole().toLatin1()); if (r != -1) { QBrush br = setupBrush(colorRole->elementBrush()); palette.setBrush(colorGroup, QPalette::ColorRole(r), br); } } }}/*! \internal*/DomColorGroup *QAbstractFormBuilder::saveColorGroup(const QPalette &palette){ int e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("colorRole"); Q_ASSERT(e_index != -1); QMetaEnum colorRole_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); DomColorGroup *group = new DomColorGroup(); QList<DomColorRole*> colorRoles; uint mask = palette.resolve(); for (int role = QPalette::WindowText; role < QPalette::NColorRoles; ++role) { if (mask & (1 << role)) { QBrush br = palette.brush(QPalette::ColorRole(role)); DomColorRole *colorRole = new DomColorRole(); colorRole->setElementBrush(saveBrush(br)); colorRole->setAttributeRole(colorRole_enum.valueToKey(role)); colorRoles.append(colorRole); } } group->setElementColorRole(colorRoles); return group;}/*! \internal*/QBrush QAbstractFormBuilder::setupBrush(DomBrush *brush){ int e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("brushStyle"); Q_ASSERT(e_index != -1); QMetaEnum brushStyle_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); QBrush br; if (!brush->hasAttributeBrushStyle()) return br; int style = brushStyle_enum.keyToValue(brush->attributeBrushStyle().toLatin1()); if (style == Qt::LinearGradientPattern || style == Qt::RadialGradientPattern || style == Qt::ConicalGradientPattern) { e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("gradientType"); Q_ASSERT(e_index != -1); QMetaEnum gradientType_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("gradientSpread"); Q_ASSERT(e_index != -1); QMetaEnum gradientSpread_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("gradientCoordinate"); Q_ASSERT(e_index != -1); QMetaEnum gradientCoordinate_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); DomGradient *gradient = brush->elementGradient(); int type = gradientType_enum.keyToValue(gradient->attributeType().toLatin1()); QGradient *gr = 0; if (type == QGradient::LinearGradient) { gr = new QLinearGradient(QPointF(gradient->attributeStartX(), gradient->attributeStartY()), QPointF(gradient->attributeEndX(), gradient->attributeEndY())); } else if (type == QGradient::RadialGradient) { gr = new QRadialGradient(QPointF(gradient->attributeCentralX(), gradient->attributeCentralY()), gradient->attributeRadius(), QPointF(gradient->attributeFocalX(), gradient->attributeFocalY())); } else if (type == QGradient::ConicalGradient) { gr = new QConicalGradient(QPointF(gradient->attributeCentralX(), gradient->attributeCentralY()), gradient->attributeAngle()); } if (!gr) return br; int spread = gradientSpread_enum.keyToValue(gradient->attributeSpread().toLatin1()); gr->setSpread((QGradient::Spread)spread); int coord = gradientCoordinate_enum.keyToValue(gradient->attributeCoordinateMode().toLatin1()); gr->setCoordinateMode((QGradient::CoordinateMode)coord); QList<DomGradientStop *> stops = gradient->elementGradientStop(); QListIterator<DomGradientStop *> it(stops); while (it.hasNext()) { DomGradientStop *stop = it.next(); DomColor *color = stop->elementColor(); gr->setColorAt(stop->attributePosition(), QColor::fromRgb(color->elementRed(), color->elementGreen(), color->elementBlue(), color->attributeAlpha())); } br = QBrush(*gr); delete gr; } else if (style == Qt::TexturePattern) { DomProperty *texture = brush->elementTexture(); if (texture && texture->kind() == DomProperty::Pixmap) { DomResourcePixmap *pixmap = texture->elementPixmap(); Q_ASSERT(pixmap != 0); QString iconPath = pixmap->text(); QString qrcPath = pixmap->attributeResource(); QPixmap p = nameToPixmap(iconPath, qrcPath); br.setTexture(p); } } else { DomColor *color = brush->elementColor(); br.setColor(QColor::fromRgb(color->elementRed(), color->elementGreen(), color->elementBlue(), color->attributeAlpha())); br.setStyle((Qt::BrushStyle)style); } return br;}/*! \internal*/DomBrush *QAbstractFormBuilder::saveBrush(const QBrush &br){ int e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("brushStyle"); Q_ASSERT(e_index != -1); QMetaEnum brushStyle_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); DomBrush *brush = new DomBrush(); Qt::BrushStyle style = br.style(); brush->setAttributeBrushStyle(brushStyle_enum.valueToKey(style)); if (style == Qt::LinearGradientPattern || style == Qt::RadialGradientPattern || style == Qt::ConicalGradientPattern) { e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("gradientType"); Q_ASSERT(e_index != -1); QMetaEnum gradientType_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("gradientSpread"); Q_ASSERT(e_index != -1); QMetaEnum gradientSpread_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); e_index = QAbstractFormBuilderGadget::staticMetaObject.indexOfProperty("gradientCoordinate"); Q_ASSERT(e_index != -1); QMetaEnum gradientCoordinate_enum = QAbstractFormBuilderGadget::staticMetaObject.property(e_index).enumerator(); DomGradient *gradient = new DomGradient(); const QGradient *gr = br.gradient(); QGradient::Type type = gr->type(); gradient->setAttributeType(gradientType_enum.valueToKey(type)); gradient->setAttributeSpread(gradientSpread_enum.valueToKey(gr->spread())); gradient->setAttributeCoordinateMode(gradientCoordinate_enum.valueToKey(gr->coordinateMode())); QList<DomGradientStop *> stops; QGradientStops st = gr->stops(); QVectorIterator<QPair<qreal, QColor> > it(st); while (it.hasNext()) { QPair<qreal, QColor> pair = it.next(); DomGradientStop *stop = new DomGradientStop(); stop->setAttributePosition(pair.first); DomColor *color = new DomColor(); color->setElementRed(pair.second.red()); color->setElementGreen(pair.second.green()); color->setElementBlue(pair.second.blue()); color->setAttributeAlpha(pair.second.alpha()); stop->setElementColor(color); stops.append(stop); } gradient->setElementGradientStop(stops); if (type == QGradient::LinearGradient) { QLinearGradient *lgr = (QLinearGradient *)(gr); gradient->setAttributeStartX(lgr->start().x()); gradient->setAttributeStartY(lgr->start().y()); gradient->setAttributeEndX(lgr->finalStop().x()); gradient->setAttributeEndY(lgr->finalStop().y()); } else if (type == QGradient::RadialGradient) { QRadialGradient *rgr = (QRadialGradient *)(gr); gradient->setAttributeCentralX(rgr->center().x()); gradient->setAttributeCentralY(rgr->center().y()); gradient->setAttributeFocalX(rgr->focalPoint().x()); gradient->setAttributeFocalY(rgr->focalPoint().y()); gradient->setAttributeRadius(rgr->radius()); } else if (type == QGradient::ConicalGradient) { QConicalGradient *cgr = (QConicalGradient *)(gr); gradient->setAttributeCentralX(cgr->center().x()); gradient->setAttributeCentralY(cgr->center().y()); gradient->setAttributeAngle(cgr->angle()); } brush->setElementGradient(gradient); } else if (style == Qt::TexturePattern) { QPixmap pixmap = br.texture(); if (!pixmap.isNull()) { QString iconPath = pixmapToFilePath(pixmap); QString qrcPath = pixmapToQrcPath(pixmap); DomProperty *p = new DomProperty; DomResourcePixmap *pix = new DomResourcePixmap; if (!qrcPath.isEmpty()) pix->setAttributeResource(qrcPath); pix->setText(iconPath); p->setAttributeName(QLatin1String("pixmap")); p->setElementPixmap(pix); brush->setElementTexture(p); } } else { QColor c = br.color(); DomColor *color = new DomColor(); color->setElementRed(c.red()); color->setElementGreen(c.green()); color->setElementBlue(c.blue()); color->setAttributeAlpha(c.alpha()); brush->setElementColor(color); } return brush;}/*! \internal*/QWidget *QAbstractFormBuilder::createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name){ Q_UNUSED(widgetName); Q_UNUSED(parentWidget); Q_UNUSED(name); return 0;}/*! \internal*/QLayout *QAbstractFormBuilder::createLayout(const QString &layoutName, QObject *parent, const QString &name){ Q_UNUSED(layoutName); Q_UNUSED(parent); Q_UNUSED(name); return 0;}/*! \internal*/QAction *QAbstractFormBuilder::createAction(QObject *parent, const QString &name){ QAction *action = new QAction(parent); action->setObjectName(name); m_actions.insert(name, action); return action;}/*! \internal*/QActionGroup *QAbstractFormBuilder::createActionGroup(QObject *parent, const QString &name){ QActionGroup *g = new QActionGroup(parent); g->setObjectName(name); m_actionGroups.insert(name, g); return g;}/*! \fn void QAbstractFormBuilder::save(QIODevice *device, QWidget *widget) Saves an XML representation of the given \a widget to the specified \a device in the standard \c{.ui} file format. \sa load()*/void QAbstractFormBuilder::save(QIODevice *dev, QWidget *widget){ DomWidget *ui_widget = createDom(widget, 0); Q_ASSERT( ui_widget != 0 ); DomUI *ui = new DomUI(); ui->setAttributeVersion(QLatin1String("4.0")); ui->setElementWidget(ui_widget); saveDom(ui, widget); QDomDocument doc; doc.appendChild(ui->write(doc)); QByteArray bytes = doc.toString().toUtf8(); dev->write(bytes, bytes.size()); m_laidout.clear(); delete ui;}/*! \internal*/void QAbstractFormBuilder::saveDom(DomUI *ui, QWidget *widget){ ui->setElementClass(widget->objectName()); if (DomConnections *ui_connections = saveConnections()) { ui->setElementConnections(ui_connections); } if (DomCustomWidgets *ui_customWidgets = saveCustomWidgets()) { ui->setElementCustomWidgets(ui_customWidgets); } if (DomTabStops *ui_tabStops = saveTabStops()) { ui->setElementTabStops(ui_tabStops); } if (DomResources *ui_resources = saveResources()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -