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

📄 qdesigner_resource.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer 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://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** 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 "qdesigner_resource.h"#include "formwindow.h"#include "qdesigner_tabwidget_p.h"#include "qdesigner_toolbox_p.h"#include "qdesigner_stackedbox_p.h"#include "qdesigner_toolbar_p.h"#include "qdesigner_dockwidget_p.h"#include "qdesigner_menu_p.h"#include "qdesigner_menubar_p.h"// shared#include <widgetdatabase_p.h>#include <layout_p.h>#include <layoutinfo_p.h>#include <spacer_widget_p.h>#include <resourcefile_p.h>#include <pluginmanager_p.h>#include <metadatabase_p.h>#include <qdesigner_widget_p.h>#include <qlayout_widget_p.h>#include <qdesigner_promotedwidget_p.h>#include <qdesigner_utils_p.h>// sdk#include <QtDesigner/QtDesigner>#include <QtGui/QMenu>#include <QtGui/QMessageBox>#include <QtGui/QLayout>#include <QtGui/QTabWidget>#include <QtGui/QToolBox>#include <QtGui/QTabBar>#include <QtGui/QAction>#include <QtGui/QActionGroup>#include <QtGui/QApplication>#include <QtGui/QMainWindow>#include <QtGui/QSplitter>#include <QtGui/QMenuBar>#include <QtGui/QFileDialog>#include <QtCore/QBuffer>#include <QtCore/QDir>#include <QtCore/QProcess>#include <QtCore/QLibraryInfo>#include <QtCore/QMetaProperty>#include <QtCore/qdebug.h>#include <QtXml/QDomDocument>using namespace qdesigner_internal;QDesignerResource::QDesignerResource(FormWindow *formWindow)   : m_formWindow(formWindow), m_core(formWindow->core()){    setWorkingDirectory(formWindow->absoluteDir());    m_topLevelSpacerCount = 0;    m_copyWidget = false;    // ### generalise    m_internal_to_qt.insert(QLatin1String("QLayoutWidget"), QLatin1String("QWidget"));    m_internal_to_qt.insert(QLatin1String("QDesignerWidget"), QLatin1String("QWidget"));    m_internal_to_qt.insert(QLatin1String("QDesignerStackedWidget"), QLatin1String("QStackedWidget"));    m_internal_to_qt.insert(QLatin1String("QDesignerTabWidget"), QLatin1String("QTabWidget"));    m_internal_to_qt.insert(QLatin1String("QDesignerDialog"), QLatin1String("QDialog"));    m_internal_to_qt.insert(QLatin1String("QDesignerLabel"), QLatin1String("QLabel"));    m_internal_to_qt.insert(QLatin1String("QDesignerToolBox"), QLatin1String("QToolBox"));    m_internal_to_qt.insert(QLatin1String("QDesignerToolBar"), QLatin1String("QToolBar"));    m_internal_to_qt.insert(QLatin1String("QDesignerMenuBar"), QLatin1String("QMenuBar"));    m_internal_to_qt.insert(QLatin1String("QDesignerMenu"), QLatin1String("QMenu"));    m_internal_to_qt.insert(QLatin1String("QDesignerDockWidget"), QLatin1String("QDockWidget"));    m_internal_to_qt.insert(QLatin1String("QDesignerQ3WidgetStack"), QLatin1String("Q3WidgetStack"));    // invert    QHashIterator<QString, QString> it(m_internal_to_qt);    while (it.hasNext()) {        it.next();        if (it.value() == QLatin1String("QDesignerWidget")                || it.value() == QLatin1String("QLayoutWidget"))            continue;        m_qt_to_internal.insert(it.value(), it.key());    }}QDesignerResource::~QDesignerResource(){}void QDesignerResource::save(QIODevice *dev, QWidget *widget){    m_topLevelSpacerCount = 0;    QAbstractFormBuilder::save(dev, widget);    if (m_topLevelSpacerCount != 0) {        QMessageBox::warning(widget->window(), QApplication::translate("Designer", "Qt Designer"),               QApplication::translate("Designer", "This file contains top level spacers.<br>"                           "They have <b>NOT</b> been saved into the form.<br>"                           "Perhaps you forgot to create a layout?"),                           QMessageBox::Ok, 0);    }}void QDesignerResource::saveDom(DomUI *ui, QWidget *widget){    QAbstractFormBuilder::saveDom(ui, widget);    QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), widget);    Q_ASSERT(sheet != 0);    ui->setElementClass(sheet->property(sheet->indexOf(QLatin1String("objectName"))).toString());    for (int index = 0; index < m_formWindow->toolCount(); ++index) {        QDesignerFormWindowToolInterface *tool = m_formWindow->tool(index);        Q_ASSERT(tool != 0);        tool->saveToDom(ui, widget);    }    QString author = m_formWindow->author();    if (!author.isEmpty()) {        ui->setElementAuthor(author);    }    QString comment = m_formWindow->comment();    if (!comment.isEmpty()) {        ui->setElementComment(comment);    }    QString exportMacro = m_formWindow->exportMacro();    if (!exportMacro.isEmpty()) {        ui->setElementExportMacro(exportMacro);    }    if (!m_formWindow->includeHints().isEmpty()) {        QList<DomInclude*> ui_includes;        foreach (QString includeHint, m_formWindow->includeHints()) {            if (includeHint.isEmpty())                continue;            DomInclude *incl = new DomInclude;            QString location = QLatin1String("local");            if (includeHint.at(0) == QLatin1Char('<'))                location = QLatin1String("global");            includeHint = includeHint                .replace(QLatin1Char('"'), "")                .replace(QLatin1Char('<'), "")                .replace(QLatin1Char('>'), "");            incl->setAttributeLocation(location);            incl->setText(includeHint);            ui_includes.append(incl);        }        DomIncludes *includes = new DomIncludes;        includes->setElementInclude(ui_includes);        ui->setElementIncludes(includes);    }    int defaultMargin = INT_MIN, defaultSpacing = INT_MIN;    m_formWindow->layoutDefault(&defaultMargin, &defaultSpacing);    if (defaultMargin != INT_MIN || defaultSpacing != INT_MIN) {        DomLayoutDefault *def = new DomLayoutDefault;        if (defaultMargin != INT_MIN)            def->setAttributeMargin(defaultMargin);        if (defaultSpacing != INT_MIN)            def->setAttributeSpacing(defaultSpacing);        ui->setElementLayoutDefault(def);    }    QString marginFunction, spacingFunction;    m_formWindow->layoutFunction(&marginFunction, &spacingFunction);    if (!marginFunction.isEmpty() || !spacingFunction.isEmpty()) {        DomLayoutFunction *def = new DomLayoutFunction;        if (!marginFunction.isEmpty())            def->setAttributeMargin(marginFunction);        if (!spacingFunction.isEmpty())            def->setAttributeSpacing(spacingFunction);        ui->setElementLayoutFunction(def);    }    QString pixFunction = m_formWindow->pixmapFunction();    if (!pixFunction.isEmpty()) {        ui->setElementPixmapFunction(pixFunction);    }}QWidget *QDesignerResource::create(DomUI *ui, QWidget *parentWidget){    QString version = ui->attributeVersion();    if (version != QLatin1String("4.0")) {        // Try to convert it ourselves.        QProcess uic3;        uic3.start(QLibraryInfo::location(QLibraryInfo::BinariesPath)                   + QDir::separator() + QLatin1String("uic3"), QStringList()                   << QLatin1String("-convert") << m_formWindow->fileName());        bool allOK = uic3.waitForFinished();        if (allOK) {            QByteArray ba = uic3.readAll();            QBuffer buffer(&ba);            m_formWindow->setFileName(QString());            QWidget *w = load(&buffer, parentWidget);            if (!w) {                allOK = false;            } else {                QMessageBox::information(parentWidget->window(), QApplication::translate("Designer", "Qt Designer"),                   QApplication::translate("Designer", "This file was created using Designer from Qt-%1 and"                               " will be converted to a new form by Qt Designer.\n"                               "The old form has been untouched, but you will have to save this form"                               " under a new name.").arg(version), QMessageBox::Ok, 0);                return w;            }        }        if (!allOK) {            QMessageBox::warning(parentWidget->window(), QApplication::translate("Designer", "Qt Designer"),               QApplication::translate("Designer", "This file was created using designer from Qt-%1 and "                           "could not be read. "                           "Please run it through <b>uic3 -convert</b> to convert "                           "it to Qt-4's ui format.").arg(version),                               QMessageBox::Ok, 0);            return 0;        }    }    m_isMainWidget = true;    QWidget *mainWidget = QAbstractFormBuilder::create(ui, parentWidget);    if (mainWidget == 0)        return 0;    if (m_formWindow) {        m_formWindow->setAuthor(ui->elementAuthor());        m_formWindow->setComment(ui->elementComment());        m_formWindow->setExportMacro(ui->elementExportMacro());        m_formWindow->setPixmapFunction(ui->elementPixmapFunction());        if (DomLayoutDefault *def = ui->elementLayoutDefault()) {            m_formWindow->setLayoutDefault(def->attributeMargin(), def->attributeSpacing());        }        if (DomLayoutFunction *fun = ui->elementLayoutFunction()) {            m_formWindow->setLayoutFunction(fun->attributeMargin(), fun->attributeSpacing());        }        if (DomIncludes *includes = ui->elementIncludes()) {            QStringList includeHints;            foreach (DomInclude *incl, includes->elementInclude()) {                QString text = incl->text();                if (text.isEmpty())                    continue;                if (incl->hasAttributeLocation() && incl->attributeLocation() == QLatin1String("global")) {                    text = text.prepend('<').append('>');                } else {                    text = text.prepend('"').append('"');                }                includeHints.append(text);            }            m_formWindow->setIncludeHints(includeHints);        }        for (int index = 0; index < m_formWindow->toolCount(); ++index) {            QDesignerFormWindowToolInterface *tool = m_formWindow->tool(index);            Q_ASSERT(tool != 0);            tool->loadFromDom(ui, mainWidget);        }    }    return mainWidget;}QWidget *QDesignerResource::create(DomWidget *ui_widget, QWidget *parentWidget){    if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(parentWidget))        parentWidget = promoted->child();    QString className = ui_widget->attributeClass();    if (!m_isMainWidget && className == QLatin1String("QWidget") && ui_widget->elementLayout().size()) {        // ### check if elementLayout.size() == 1        QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), parentWidget);        if (container == 0) {            // generate a QLayoutWidget iff the parent is not an QDesignerContainerExtension.            ui_widget->setAttributeClass(QLatin1String("QLayoutWidget"));        }    }    // save the actions    QList<DomActionRef*> actionRefs = ui_widget->elementAddAction();    ui_widget->setElementAddAction(QList<DomActionRef*>());    QWidget *w = QAbstractFormBuilder::create(ui_widget, parentWidget);    // restore the actions    ui_widget->setElementAddAction(actionRefs);    if (w == 0)        return 0;    // ### generalize using the extension manager    QDesignerMenu *menu = qobject_cast<QDesignerMenu*>(w);    QDesignerMenuBar *menuBar = qobject_cast<QDesignerMenuBar*>(w);    QDesignerToolBar *toolBar = qobject_cast<QDesignerToolBar*>(w);    if (menu) {        menu->interactive(false);        menu->hide();    } else if (menuBar) {        menuBar->interactive(false);    } else if (toolBar) {        toolBar->interactive(false);    }    foreach (DomActionRef *ui_action_ref, actionRefs) {        QString name = ui_action_ref->attributeName();        if (name == QLatin1String("separator")) {            QAction *sep = new QAction(w);            sep->setSeparator(true);            w->addAction(sep);            addMenuAction(sep);        } else if (QAction *a = m_actions.value(name)) {            w->addAction(a);        } else if (QActionGroup *g = m_actionGroups.value(name)) {            w->addActions(g->actions());        } else if (QMenu *menu = qFindChild<QMenu*>(w, name)) {            w->addAction(menu->menuAction());            addMenuAction(menu->menuAction());        }    }    if (menu) {        menu->interactive(true);        menu->adjustSpecialActions();    } else if (menuBar) {        menuBar->interactive(true);        menuBar->adjustSpecialActions();    } else if (toolBar) {        toolBar->interactive(true);        toolBar->adjustSpecialActions();

⌨️ 快捷键说明

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