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

📄 qdesigner_resource.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    QList<DomWidget*> widgets = topLevel->elementWidget();    for (int i=0; i<widgets.size(); ++i) {        QWidget *w = create(widgets.at(i), parentWidget);        if (!w)            continue;        w->move(w->pos() + m_formWindow->grid());        // ### change the init properties of w        createdWidgets.append(w);    }    m_isMainWidget = saved;    return createdWidgets;}QList<QWidget*> QDesignerResource::paste(QIODevice *dev, QWidget *parentWidget){    QDomDocument doc;    if (!doc.setContent(dev))        return QList<QWidget*>();    QDomElement root = doc.firstChild().toElement();    DomUI ui;    ui.read(root);    return paste(&ui, parentWidget);}void QDesignerResource::layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing){    QAbstractFormBuilder::layoutInfo(layout, parent, margin, spacing);    QLayoutWidget *layoutWidget = qobject_cast<QLayoutWidget*>(parent);    if (layoutWidget && margin) {        if (*margin == INT_MIN)            *margin = 1;        else            *margin = *margin + 1;    }}QString QDesignerResource::qtify(const QString &name){    QString qname = name;    if (qname.count() > 1 && qname.at(1).toUpper() == qname.at(1) && (qname.at(0) == QLatin1Char('Q') || qname.at(0) == QLatin1Char('K')))        qname = qname.mid(1);    int i=0;    while (i < qname.length()) {        if (qname.at(i).toLower() != qname.at(i))            qname[i] = qname.at(i).toLower();        else            break;        ++i;    }    return qname;}DomCustomWidgets *QDesignerResource::saveCustomWidgets(){    if (m_usedCustomWidgets.isEmpty())        return 0;    QList<DomCustomWidget*> custom_widget_list;    foreach (QDesignerWidgetDataBaseItemInterface *item, m_usedCustomWidgets.keys()) {        DomCustomWidget *custom_widget = new DomCustomWidget;        custom_widget->setElementClass(item->name());        if (item->isContainer())            custom_widget->setElementContainer(item->isContainer());        if (!item->includeFile().isEmpty()) {            DomHeader *header = new DomHeader;            header->setText(item->includeFile());            custom_widget->setElementHeader(header);            custom_widget->setElementExtends(item->extends());        }        custom_widget_list.append(custom_widget);    }    DomCustomWidgets *customWidgets = new DomCustomWidgets;    customWidgets->setElementCustomWidget(custom_widget_list);    return customWidgets;}QList<DomProperty*> QDesignerResource::computeProperties(QObject *object){    QList<DomProperty*> properties;    if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_core->extensionManager(), object)) {        for (int index = 0; index < sheet->count(); ++index) {            QString propertyName = sheet->propertyName(index);            QVariant value = sheet->property(index);            if (QLayout *layout = qobject_cast<QLayout*>(object)) {                if (propertyName == QLatin1String("margin") && qobject_cast<QLayoutWidget*>(layout->parentWidget()))                    value = value.toInt() - 1;            }            if (!sheet->isChanged(index))                continue;            if (DomProperty *p = createProperty(object, propertyName, value)) {                if (p->kind() == DomProperty::String && qobject_cast<MetaDataBase*>(core()->metaDataBase())) {                    MetaDataBaseItem *item = static_cast<MetaDataBaseItem*>(core()->metaDataBase()->item(object));                    if (item && !item->propertyComment(propertyName).isEmpty()) {                        p->elementString()->setAttributeComment(item->propertyComment(propertyName));                    }                }                properties.append(p);            }        }    }    return properties;}DomProperty *QDesignerResource::createProperty(QObject *object, const QString &propertyName, const QVariant &value){    if (!checkProperty(object, propertyName)) {        return 0;    }    if (qVariantCanConvert<EnumType>(value)) {        EnumType e = qvariant_cast<EnumType>(value);        int v = e.value.toInt();        QMapIterator<QString, QVariant> it(e.items);        while (it.hasNext()) {            if (it.next().value().toInt() != v)                continue;            DomProperty *p = new DomProperty;            // check if we have a standard cpp set function            const QMetaObject *meta = object->metaObject();            int pindex = meta->indexOfProperty(propertyName.toLatin1());            if (pindex != -1) {                QMetaProperty meta_property = meta->property(pindex);                if (!meta_property.hasStdCppSet())                    p->setAttributeStdset(0);            }            p->setAttributeName(propertyName);            p->setElementEnum(it.key());            return p;        }        return 0;    } else if (qVariantCanConvert<FlagType>(value)) {        FlagType f = qvariant_cast<FlagType>(value);        uint v = f.value.toUInt();        QMapIterator<QString, QVariant> it(f.items);        QStringList keys;        while (it.hasNext()) {            uint x = it.next().value().toUInt();            if (v == x) {                DomProperty *p = new DomProperty;                // check if we have a standard cpp set function                const QMetaObject *meta = object->metaObject();                int pindex = meta->indexOfProperty(propertyName.toLatin1());                if (pindex != -1) {                    QMetaProperty meta_property = meta->property(pindex);                    if (!meta_property.hasStdCppSet())                        p->setAttributeStdset(0);                }                p->setAttributeName(propertyName);                p->setElementSet(it.key());                return p;            }            if ((v & x) == x)                keys.push_back(it.key());        }        if (keys.isEmpty())            return 0;        DomProperty *p = new DomProperty;        p->setAttributeName(propertyName);        p->setElementSet(keys.join(QLatin1String("|")));        return p;    }    return QAbstractFormBuilder::createProperty(object, propertyName, value);}void QDesignerResource::createResources(DomResources *resources){    if (resources == 0)        return;    QList<DomResource*> dom_include = resources->elementInclude();    foreach (DomResource *res, dom_include) {        QString path = m_formWindow->absoluteDir().absoluteFilePath(res->attributeLocation());                while (!QFile::exists(path)) {            if (QMessageBox::warning(m_formWindow, QObject::tr("Loading qrc file"),                QObject::tr("The specified qrc file <p><b>%1</b></p><p>could not be found. "                "Do you want to update the file location?</p>").arg(path),                QObject::tr("&Yes"), QObject::tr("&No"),                QString(), 0, 1) == 0) {                QFileInfo fi(path);                path = QFileDialog::getOpenFileName(m_formWindow,                    QObject::tr("New location for %1").arg(fi.fileName()), fi.absolutePath(),                    QObject::tr("Resource files (*.qrc)"));                if (path.isEmpty())                    break;            } else {                break;            }        }        if (!path.isEmpty())            m_formWindow->addResourceFile(path);    }}DomResources *QDesignerResource::saveResources(){    QStringList res_list = m_formWindow->resourceFiles();    QList<DomResource*> dom_include;    foreach (QString res, res_list) {        DomResource *dom_res = new DomResource;        QString conv_path = m_formWindow->absoluteDir().relativeFilePath(res);        dom_res->setAttributeLocation(conv_path.replace(QDir::separator(), QLatin1Char('/')));        dom_include.append(dom_res);    }    DomResources *dom_resources = new DomResources;    dom_resources->setElementInclude(dom_include);    return dom_resources;}QIcon QDesignerResource::nameToIcon(const QString &filePath, const QString &qrcPath){    QString file_path = filePath;    QString qrc_path = qrcPath;    if (qrc_path.isEmpty())        file_path = workingDirectory().absoluteFilePath(file_path);    else        qrc_path = workingDirectory().absoluteFilePath(qrc_path);    return core()->iconCache()->nameToIcon(file_path, qrc_path);}QString QDesignerResource::iconToFilePath(const QIcon &pm) const{    QString file_path = core()->iconCache()->iconToFilePath(pm);    QString qrc_path = core()->iconCache()->iconToQrcPath(pm);    if (qrc_path.isEmpty())        return workingDirectory().relativeFilePath(file_path);    return file_path;}QString QDesignerResource::iconToQrcPath(const QIcon &pm) const{    QString qrc_path = core()->iconCache()->iconToQrcPath(pm);    if (qrc_path.isEmpty())        return QString();    return workingDirectory().relativeFilePath(qrc_path);}QPixmap QDesignerResource::nameToPixmap(const QString &filePath, const QString &qrcPath){    QString file_path = filePath;    QString qrc_path = qrcPath;    if (qrc_path.isEmpty())        file_path = workingDirectory().absoluteFilePath(file_path);    else        qrc_path = workingDirectory().absoluteFilePath(qrc_path);    return core()->iconCache()->nameToPixmap(file_path, qrc_path);}QString QDesignerResource::pixmapToFilePath(const QPixmap &pm) const{    QString file_path = core()->iconCache()->pixmapToFilePath(pm);    QString qrc_path = core()->iconCache()->pixmapToQrcPath(pm);    if (qrc_path.isEmpty())        return workingDirectory().relativeFilePath(file_path);    return file_path;}QString QDesignerResource::pixmapToQrcPath(const QPixmap &pm) const{    QString qrc_path = core()->iconCache()->pixmapToQrcPath(pm);    if (qrc_path.isEmpty())        return QString();    return workingDirectory().relativeFilePath(qrc_path);}DomAction *QDesignerResource::createDom(QAction *action){    if (!core()->metaDataBase()->item(action) || action->menu())        return 0;    return QAbstractFormBuilder::createDom(action);}DomActionGroup *QDesignerResource::createDom(QActionGroup *actionGroup){    if (core()->metaDataBase()->item(actionGroup) != 0) {        return QAbstractFormBuilder::createDom(actionGroup);    }    return 0;}QAction *QDesignerResource::create(DomAction *ui_action, QObject *parent){    if (QAction *action = QAbstractFormBuilder::create(ui_action, parent)) {        core()->metaDataBase()->add(action);        return action;    }    return 0;}QActionGroup *QDesignerResource::create(DomActionGroup *ui_action_group, QObject *parent){    if (QActionGroup *actionGroup = QAbstractFormBuilder::create(ui_action_group, parent)) {        core()->metaDataBase()->add(actionGroup);        return actionGroup;    }    return 0;}DomActionRef *QDesignerResource::createActionRefDom(QAction *action){    if (!core()->metaDataBase()->item(action)            || qobject_cast<SentinelAction*>(action)            || (!action->isSeparator() && !action->menu() && action->objectName().isEmpty()))        return 0;    return QAbstractFormBuilder::createActionRefDom(action);}void QDesignerResource::addMenuAction(QAction *action){    core()->metaDataBase()->add(action);}QAction *QDesignerResource::createAction(QObject *parent, const QString &name){    if (QAction *action = QAbstractFormBuilder::createAction(parent, name)) {        core()->metaDataBase()->add(action);        return action;    }    return 0;}QActionGroup *QDesignerResource::createActionGroup(QObject *parent, const QString &name){    if (QActionGroup *actionGroup = QAbstractFormBuilder::createActionGroup(parent, name)) {        core()->metaDataBase()->add(actionGroup);        return actionGroup;    }    return 0;}

⌨️ 快捷键说明

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