⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converter.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        DomProperty *prop = 0;        // sizeHint        prop = new DomProperty();        prop->setAttributeName(QLatin1String("sizeHint"));        prop->setElementSize(new DomSize());        prop->elementSize()->setElementWidth(size.width);        prop->elementSize()->setElementHeight(size.height);        properties.append(prop);        // sizeType        prop = new DomProperty();        prop->setAttributeName(QLatin1String("sizeType"));        prop->setElementEnum(sizeType);        properties.append(prop);        // orientation        prop = new DomProperty();        prop->setAttributeName(QLatin1String("orientation"));        prop->setElementEnum(orientation);        properties.append(prop);        ui_spacer->setElementProperty(properties);        lay_item->setElementSpacer(ui_spacer);    } else {        DomLayout *ui_layout = createLayout(e);        Q_ASSERT(ui_layout != 0);        fixLayoutMargin(ui_layout);        lay_item->setElementLayout(ui_layout);    }    if (e.hasAttribute(QLatin1String("row")))        lay_item->setAttributeRow(e.attribute(QLatin1String("row")).toInt());    if (e.hasAttribute(QLatin1String("column")))        lay_item->setAttributeColumn(e.attribute(QLatin1String("column")).toInt());    if (e.hasAttribute(QLatin1String("rowspan")))        lay_item->setAttributeRowSpan(e.attribute(QLatin1String("rowspan")).toInt());    if (e.hasAttribute(QLatin1String("colspan")))        lay_item->setAttributeColSpan(e.attribute(QLatin1String("colspan")).toInt());    return lay_item;}void Ui3Reader::fixLayoutMargin(DomLayout *ui_layout){    bool hasMargin = false;    QList<DomProperty*> properties = ui_layout->elementProperty();    foreach (DomProperty *p, properties) {        if (p->attributeName() == QLatin1String("margin"))            hasMargin = true;    }    if (!hasMargin) {        DomProperty *margin = new DomProperty();        margin->setAttributeName(QLatin1String("margin"));        margin->setElementNumber(0);        properties.append(margin);        ui_layout->setElementProperty(properties);    }}void Ui3Reader::findDerivedFontProperties(const QDomElement &n, DomFont &result) const{    bool italic = false;    bool bold = false;    bool underline = false;    bool strikeout = false;    QDomNode pn = n.parentNode();    while(!pn.isNull()) {        for (QDomElement e=pn.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {            if (e.tagName().toLower() == QLatin1String("property") &&                e.attribute(QLatin1String("name")) == QLatin1String("font")) {                QDomElement f = e.firstChild().toElement();                for (QDomElement fp = f.firstChild().toElement(); !fp.isNull(); fp = fp.nextSibling().toElement()) {                    QString name = fp.tagName().toLower();                    QString text = fp.text();                    if (!italic && name == QLatin1String("italic")) {                        italic = true;                        if (text == QLatin1String("true") || text == QLatin1String("1"))                            result.setElementItalic(true);                    } else if (!bold && name == QLatin1String("bold")) {                        bold = true;                        if (text == QLatin1String("true") || text == QLatin1String("1"))                            result.setElementBold(true);                    } else if (!underline && name == QLatin1String("underline")) {                        underline = true;                        if (text == QLatin1String("true") || text == QLatin1String("1"))                            result.setElementUnderline(true);                    } else if (!strikeout && name == QLatin1String("strikeout")) {                        strikeout = true;                        if (text == QLatin1String("true") || text == QLatin1String("1"))                            result.setElementStrikeOut(true);                    } else if (name == QLatin1String("family")) {                        if (result.elementFamily().isEmpty())                            result.setElementFamily(text.toAscii());                    } else if (name == QLatin1String("pointsize")) {                        if (!result.elementPointSize())                            result.setElementPointSize(text.toInt());                    }                }            }        }        pn = pn.parentNode();    }}void Ui3Reader::createProperties(const QDomElement &n, QList<DomProperty*> *properties,                                 const QString &className){    QString objectName;    for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {        if (e.tagName().toLower() == QLatin1String("property")) {            QString name = e.attribute(QLatin1String("name"));            // changes in QPalette            if (name == QLatin1String("colorGroup")                    || name == QLatin1String("paletteForegroundColor")                    || name == QLatin1String("paletteBackgroundColor")                    || name == QLatin1String("backgroundMode")                    || name == QLatin1String("backgroundOrigin")                    || name == QLatin1String("paletteBackgroundPixmap")                    || name == QLatin1String("backgroundBrush")) {                errorInvalidProperty(name, objectName, className);                continue;            }            // changes in QFrame            if (name == QLatin1String("contentsRect")) {                errorInvalidProperty(name, objectName, className);                continue;            }            // changes in QWidget            if (name == QLatin1String("underMouse")                    || name == QLatin1String("ownFont")) {                errorInvalidProperty(name, objectName, className);                continue;            }            if (name == QLatin1String("font")) {                QDomElement f = e.firstChild().toElement();                DomFont font;                findDerivedFontProperties(f, font);                e.removeChild(f);                QDomDocument doc = e.ownerDocument();                f = font.write(doc);                e.appendChild(f);            }            DomProperty *prop = readProperty(e);            if (!prop)                continue;            if (prop->kind() == DomProperty::String) {                QDomNodeList comments = e.elementsByTagName(QLatin1String("comment"));                if (comments.length()) {                    QString comment = comments.item(0).firstChild().toText().data();                    if (!comment.isEmpty())                        prop->elementString()->setAttributeComment(comment);                }            }            if (className == QLatin1String("Line")                    && prop->attributeName() == QLatin1String("orientation")) {                delete prop;                continue;            }            if (className.mid(1) == QLatin1String("LineEdit")) {                if (name == QLatin1String("hasMarkedText")) {                    prop->setAttributeName(QLatin1String("hasSelectedText"));                } else if (name == QLatin1String("edited")) {                    prop->setAttributeName(QLatin1String("modified"));                } else if (name == QLatin1String("markedText")) {                    prop->setAttributeName(QLatin1String("selectedText"));                }            }            if (className.endsWith("ComboBox")) {                CONVERT_PROPERTY(QLatin1String("currentItem"), QLatin1String("currentIndex"));                CONVERT_PROPERTY(QLatin1String("insertionPolicy"), QLatin1String("insertPolicy"));            }            if (className == QLatin1String("QToolBar")) {                if (name == QLatin1String("label")) {                    prop->setAttributeName(QLatin1String("windowTitle"));                }            }            CONVERT_PROPERTY(QLatin1String("customWhatsThis"), QLatin1String("whatsThis"));            CONVERT_PROPERTY(QLatin1String("icon"), QLatin1String("windowIcon"));            CONVERT_PROPERTY(QLatin1String("iconText"), QLatin1String("windowIconText"));            CONVERT_PROPERTY(QLatin1String("caption"), QLatin1String("windowTitle"));            if (name == QLatin1String("name")) {                continue; // skip the property name            }            if (name == QLatin1String("accel")) {                prop->setAttributeName(QLatin1String("shortcut"));            }            CONVERT_PROPERTY(QLatin1String("pixmap"), QLatin1String("icon"));            CONVERT_PROPERTY(QLatin1String("iconSet"), QLatin1String("icon"));            CONVERT_PROPERTY(QLatin1String("textLabel"), QLatin1String("text"));            CONVERT_PROPERTY(QLatin1String("toggleButton"), QLatin1String("checkable"));            CONVERT_PROPERTY(QLatin1String("isOn"), QLatin1String("checked"));            CONVERT_PROPERTY(QLatin1String("maxValue"), QLatin1String("maximum"));            CONVERT_PROPERTY(QLatin1String("minValue"), QLatin1String("minimum"));            CONVERT_PROPERTY(QLatin1String("lineStep"), QLatin1String("singleStep"));            name = prop->attributeName(); // sync the name            // resolve the flags and enumerator            if (prop->kind() == DomProperty::Set) {                QStringList flags = prop->elementSet().split(QLatin1Char('|'));                QStringList v;                foreach (QString fl, flags) {                    QString e = WidgetInfo::resolveEnumerator(className, fl);                    if (e.isEmpty()) {                        e = m_porting->renameEnumerator(className + QLatin1String("::") + fl);                    }                    if (e.isEmpty()) {                        fprintf(stderr, "uic3: flag '%s' for widget '%s' is not supported\n", fl.latin1(), className.latin1());                        continue;                    }                    v.append(e);                }                if (v.isEmpty()) {                    delete prop;                    continue;                }                prop->setElementSet(v.join(QLatin1String("|")));            } else if (prop->kind() == DomProperty::Enum) {                QString e = WidgetInfo::resolveEnumerator(className, prop->elementEnum());                if (e.isEmpty()) {                    e = m_porting->renameEnumerator(className + QLatin1String("::") + prop->elementEnum());                }                if (e.isEmpty()) {                    fprintf(stderr, "uic3: enumerator '%s' for widget '%s' is not supported\n",                            prop->elementEnum().latin1(), className.latin1());                    delete prop;                    continue;                }                prop->setElementEnum(e);            }            if (className.size()                    && !(className == QLatin1String("QLabel") && name == QLatin1String("buddy"))                    && !(name == QLatin1String("buttonGroupId"))                    && !(name == QLatin1String("frameworkCode"))                    && !(name == QLatin1String("database"))) {                if (!WidgetInfo::isValidProperty(className, name)) {                    errorInvalidProperty(name, objectName, className);                    delete prop;                } else {                    properties->append(prop);                }            } else {                properties->append(prop);            }        }    }}DomProperty *Ui3Reader::readProperty(const QDomElement &e){    QString name = e.firstChild().toElement().tagName().toLower();    if (name == QLatin1String("class")) // skip class        name = e.firstChild().nextSibling().toElement().tagName().toLower();    DomProperty *p = new DomProperty;    p->read(e);    if (p->kind() == DomProperty::Unknown) {        delete p;        p = 0;    }    return p;}void Ui3Reader::createAttributes(const QDomElement &n, QList<DomProperty*> *properties,                                 const QString &className){    Q_UNUSED(className);    for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {        if (e.tagName().toLower() == QLatin1String("attribute")) {            QString name = e.attribute(QLatin1String("name"));            DomProperty *prop = readProperty(e);            if (!prop)                continue;            properties->append(prop);        }    }}QString Ui3Reader::fixDeclaration(const QString &d) const{    QString text;    int i = 0;    while (i < d.size()) {        QChar ch = d.at(i);        if (ch.isLetter() || ch == QLatin1Char('_')) {            int start = i;            while (i < d.size() && (d.at(i).isLetterOrNumber() || d.at(i) == QLatin1Char('_')))                ++i;            text += fixClassName(d.mid(start, i-start));        } else {            text += ch;            ++i;        }    }    return text;}/*    fixes a (possible composite) type name*/QString Ui3Reader::fixType(const QString &t) const{    QString newText = t;    //split type name on <>*& and whitespace    QStringList typeNames = t.split(QRegExp("<|>|\\*|&| "), QString::SkipEmptyParts);    foreach(QString typeName , typeNames) {        QString newName = fixClassName(typeName);        if( newName != typeName ) {            newText.replace(typeName, newName);        }    }    return newText;}QString Ui3Reader::fixMethod(const QString &method) const{    const QByteArray normalized = QMetaObject::normalizedSignature(method.toLatin1());    QByteArray result;    int index = normalized.indexOf('(');    if (index == -1)        return QLatin1String(normalized);    result.append(normalized.left(++index));    int limit = normalized.length()-1;    while (index < limit) {        QByteArray type;        while ((index < limit) && (normalized.at(index) != ','))            type.append(normalized.at(index++));        result.append(fixType(QLatin1String(type)).toLatin1());        if ((index < limit) && (normalized.at(index) == ','))            result.append(normalized.at(index++));    }    result.append(normalized.mid(index));    return QLatin1String(result);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -