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

📄 converter.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the tools applications of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "ui3reader.h"#include "parser.h"#include "domtool.h"#include "ui4.h"#include "widgetinfo.h"#include "globaldefs.h"#include "qt3to4.h"#include "utils.h"#include "option.h"#include "cppextractimages.h"#include <QtDebug>#include <QFile>#include <QHash>#include <QPair>#include <QStringList>#include <QDateTime>#include <QRegExp>#include <stdio.h>#include <stdlib.h>enum { warnHeaderGeneration = 0 };#define CONVERT_PROPERTY(o, n) \    do { \        if (name == QLatin1String(o) \                && !WidgetInfo::isValidProperty(className, (o)) \                && WidgetInfo::isValidProperty(className, (n))) { \            prop->setAttributeName((n)); \        } \    } while (0)static QString classNameForObjectName(const QDomElement &widget, const QString &objectName){    QList<QDomElement> widgetStack;    widgetStack.append(widget);    while (!widgetStack.isEmpty()) {        QDomElement w = widgetStack.takeFirst();        QDomElement child = w.firstChild().toElement();        while (!child.isNull()) {            if (child.tagName() == QLatin1String("property")                && child.attribute(QLatin1String("name")) == QLatin1String("name")) {                QDomElement name = child.firstChild().toElement();                DomString str;                str.read(name);                if (str.text() == objectName)                    return w.attribute(QLatin1String("class"));            } else if (child.tagName() == QLatin1String("widget")                || child.tagName() == QLatin1String("vbox")                || child.tagName() == QLatin1String("hbox")                || child.tagName() == QLatin1String("grid")) {                widgetStack.prepend(child);            }            child = child.nextSibling().toElement();        }    }    return QString();}// Check for potential KDE classes like//  K3ListView or KLineEdit as precise as possiblestatic inline bool isKDEClass(const QString &className){    if (className.indexOf(QLatin1Char(':')) != -1)        return false;    const int size = className.size();    if (size < 3 || className.at(0) != QLatin1Char('K'))        return false;    // K3ListView    if (className.at(1) == QLatin1Char('3')) {        if (size < 4)            return false;        return className.at(2).isUpper() &&  className.at(3).isLower();    }    // KLineEdit    return className.at(1) .isUpper() && className.at(2).isLower();}DomUI *Ui3Reader::generateUi4(const QDomElement &widget, bool implicitIncludes){    QDomNodeList nl;    candidateCustomWidgets.clear();    QString objClass = getClassName(widget);    if (objClass.isEmpty())        return 0;    QString objName = getObjectName(widget);    DomUI *ui = new DomUI;    ui->setAttributeVersion(QLatin1String("4.0"));    QString pixmapFunction = QLatin1String("qPixmapFromMimeSource");    QStringList ui_tabstops;    QStringList ui_custom_slots;    QList<DomInclude*> ui_includes;    QList<DomWidget*> ui_toolbars;    QList<DomWidget*> ui_menubars;    QList<DomAction*> ui_action_list;    QList<DomActionGroup*> ui_action_group_list;    QList<DomCustomWidget*> ui_customwidget_list;    QList<DomConnection*> ui_connection_list;    QList<QPair<int, int> > ui_connection_lineinfo_list;    QString author, comment, exportMacro;    QString klass;    for (QDomElement n = root.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) {        QString tagName = n.tagName().toLower();        if (tagName == QLatin1String("tabstops")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("tabstop")) {                    QString name = n2.firstChild().toText().data();                    ui_tabstops.append(name);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("pixmapfunction")) {            pixmapFunction = n.firstChild().toText().data();        } else if (tagName == QLatin1String("class")) {            klass = n.firstChild().toText().data();        } else if (tagName == QLatin1String("author")) {            author = n.firstChild().toText().data();        } else if (tagName == QLatin1String("comment")) {            comment = n.firstChild().toText().data();        } else if (tagName == QLatin1String("exportmacro")) {            exportMacro = n.firstChild().toText().data();        } else if ( n.tagName() == QLatin1String("includehints") ) {            QDomElement n2 = n.firstChild().toElement();            while ( !n2.isNull() ) {                if ( n2.tagName() == QLatin1String("includehint") ) {                    QString name = n2.firstChild().toText().data();                    DomInclude *incl = new DomInclude();                    incl->setText(fixHeaderName(name));                    incl->setAttributeLocation(n.attribute(QLatin1String("location"), QLatin1String("local")));                    ui_includes.append(incl);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("includes")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("include")) {                    QString name = n2.firstChild().toText().data();                    if (n2.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) == QLatin1String("in declaration")) {                        if (name.right(5) == QLatin1String(".ui.h"))                            continue;                        DomInclude *incl = new DomInclude();                        incl->setText(fixHeaderName(name));                        incl->setAttributeLocation(n2.attribute(QLatin1String("location"), QLatin1String("global")));                        ui_includes.append(incl);                    }                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("include")) {            QString name = n.firstChild().toText().data();            if (n.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) == QLatin1String("in declaration")) {                if (name.right(5) == QLatin1String(".ui.h"))                    continue;                DomInclude *incl = new DomInclude();                incl->setText(fixHeaderName(name));                incl->setAttributeLocation(n.attribute(QLatin1String("location"), QLatin1String("global")));                ui_includes.append(incl);            }        } else if (tagName == QLatin1String("layoutdefaults")) {            QString margin = n.attribute(QLatin1String("margin"));            QString spacing = n.attribute(QLatin1String("spacing"));            DomLayoutDefault *layoutDefault = new DomLayoutDefault();            if (!margin.isEmpty())                layoutDefault->setAttributeMargin(margin.toInt());            if (!spacing.isEmpty())                layoutDefault->setAttributeSpacing(spacing.toInt());            ui->setElementLayoutDefault(layoutDefault);        } else if (tagName == QLatin1String("layoutfunctions")) {            QString margin = n.attribute(QLatin1String("margin"));            QString spacing = n.attribute(QLatin1String("spacing"));            DomLayoutFunction *layoutDefault = new DomLayoutFunction();            if (!margin.isEmpty())                layoutDefault->setAttributeMargin(margin);            if (!spacing.isEmpty())                layoutDefault->setAttributeSpacing(spacing);            ui->setElementLayoutFunction(layoutDefault);        } else if (tagName == QLatin1String("images")) {            QDomNodeList nl = n.elementsByTagName(QLatin1String("image"));            QList<DomImage*> ui_image_list;            for (int i=0; i<(int)nl.length(); i++) {                QDomElement e = nl.item(i).toElement();                QDomElement tmp = e.firstChild().toElement();                if (tmp.tagName().toLower() != QLatin1String("data"))                    continue;                // create the image                DomImage *img = new DomImage();                img->setAttributeName(e.attribute(QLatin1String("name")));                // create the data                DomImageData *data = new DomImageData();                img->setElementData(data);                if (tmp.hasAttribute(QLatin1String("format")))                    data->setAttributeFormat(tmp.attribute(QLatin1String("format"), QLatin1String("PNG")));                if (tmp.hasAttribute(QLatin1String("length")))                    data->setAttributeLength(tmp.attribute(QLatin1String("length")).toInt());                data->setText(tmp.firstChild().toText().data());                ui_image_list.append(img);                QString format = img->elementData()->attributeFormat();                QString extension = format.left(format.indexOf('.')).toLower();                m_imageMap[img->attributeName()] = img->attributeName() + QLatin1Char('.') + extension;            }            if (ui_image_list.size()) {                DomImages *images = new DomImages();                images->setElementImage(ui_image_list);                ui->setElementImages(images);            }        } else if (tagName == QLatin1String("actions")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                QString tag = n2.tagName().toLower();                if (tag == QLatin1String("action")) {                    DomAction *action = new DomAction();                    action->read(n2);                    QList<DomProperty*> properties = action->elementProperty();                    QString actionName = fixActionProperties(properties);                    action->setAttributeName(actionName);                    action->setElementProperty(properties);                    if (actionName.isEmpty()) {                        delete action;                    } else                        ui_action_list.append(action);                } else if (tag == QLatin1String("actiongroup")) {                    DomActionGroup *g= new DomActionGroup();                    g->read(n2);                    fixActionGroup(g);                    ui_action_group_list.append(g);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("toolbars")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("toolbar")) {                    DomWidget *tb = createWidget(n2, QLatin1String("QToolBar"));                    ui_toolbars.append(tb);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("menubar")) {            DomWidget *tb = createWidget(n, QLatin1String("QMenuBar"));            ui_menubars.append(tb);        } else if (tagName == QLatin1String("customwidgets")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("customwidget")) {                    DomCustomWidget *customWidget = new DomCustomWidget;                    customWidget->read(n2);

⌨️ 快捷键说明

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