qdesigner_propertysheet.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 933 行 · 第 1/3 页

CPP
933
字号
/******************************************************************************** Copyright (C) 1992-2007 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://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 "qdesigner_propertysheet_p.h"#include "qdesigner_utils_p.h"#include "layoutinfo_p.h"#include "qlayout_widget_p.h"#include <formbuilderextra_p.h>#include <QtDesigner/QDesignerFormWindowInterface>#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerWidgetDataBaseInterface>#include <QtDesigner/QExtensionManager>#include <QtCore/QMetaObject>#include <QtCore/QMetaProperty>#include <QtGui/QLayout>#include <QtGui/QDockWidget>#include <QtGui/QDialog>#include <QtGui/QLabel>#include <QtGui/QGroupBox>#include <QtGui/QStyle>#include <QtGui/QApplication>#include <QtGui/QToolBar>static const QMetaObject *propertyIntroducedBy(const QMetaObject *meta, int index){    if (index >= meta->propertyOffset())        return meta;    if (meta->superClass())        return propertyIntroducedBy(meta->superClass(), index);    return 0;}static QDesignerFormEditorInterface *formEditorForWidget(QWidget *w) {    const QDesignerFormWindowInterface *formWindow =  QDesignerFormWindowInterface::findFormWindow(w);    if (!formWindow)        return 0;    return formWindow->core();}static bool hasLayoutAttributes(QObject *object){    if (!object->isWidgetType())        return false;    QWidget *w =  qobject_cast<QWidget *>(object);    if (const QDesignerFormEditorInterface *core = formEditorForWidget(w)) {        if (const QDesignerWidgetDataBaseInterface *db = core->widgetDataBase()) {            if (db->isContainer(w))                return true;        }    }    return false;}// ---------- QDesignerPropertySheet::InfoQDesignerPropertySheet::Info::Info() :    changed(0),    visible(1),    attribute(0),    reset(1),    defaultDynamic(0),    propertyType(PropertyNone){}// ----------- QDesignerPropertySheetQDesignerPropertySheet::ObjectType QDesignerPropertySheet::objectType(const QObject *o){    if (qobject_cast<const QLayout *>(o))        return ObjectLayout;    if (!o->isWidgetType())        return ObjectNone;    if (qobject_cast<const QLayoutWidget *>(o))        return ObjectLayoutWidget;    if (qobject_cast<const QLabel*>(o))        return ObjectLabel;    if (o->inherits("Q3GroupBox"))        return ObjectQ3GroupBox;    return ObjectNone;}QDesignerPropertySheet::PropertyType QDesignerPropertySheet::propertyTypeFromName(const QString &name){    if (name == QLatin1String("layoutLeftMargin"))        return  PropertyLayoutLeftMargin;    if (name == QLatin1String("layoutTopMargin"))        return  PropertyLayoutTopMargin;    if (name == QLatin1String("layoutRightMargin"))        return  PropertyLayoutRightMargin;    if (name == QLatin1String("layoutBottomMargin"))        return  PropertyLayoutBottomMargin;    if (name == QLatin1String("layoutSpacing"))        return  PropertyLayoutSpacing;    if (name == QLatin1String("layoutHorizontalSpacing"))        return  PropertyLayoutHorizontalSpacing;    if (name == QLatin1String("layoutVerticalSpacing"))        return  PropertyLayoutVerticalSpacing;    if (name == QLatin1String("buddy"))        return  PropertyBuddy;    if (name == QLatin1String("sizeConstraint"))        return  PropertySizeConstraint;    if (name == QLatin1String("geometry"))        return PropertyGeometry;    if (name == QLatin1String("checkable"))        return PropertyCheckable;    if (name.startsWith(QLatin1String("accessible")))        return  PropertyAccessibility;    return PropertyNone;}QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent)    : QObject(parent),      m_meta(object->metaObject()),      m_objectType(objectType(object)),      m_canHaveLayoutAttributes( hasLayoutAttributes(object)),      m_object(object),      m_lastLayout(0),      m_lastLayoutPropertySheet(0),      m_LastLayoutByDesigner(false){    const QMetaObject *baseMeta = m_meta;    while (baseMeta && QString::fromUtf8(baseMeta->className()).startsWith(QLatin1String("QDesigner"))) {        baseMeta = baseMeta->superClass();    }    Q_ASSERT(baseMeta != 0);    for (int index=0; index<count(); ++index) {        const QMetaProperty p = m_meta->property(index);        const QString name = QString::fromUtf8(p.name());        if (p.type() == QVariant::KeySequence) {            createFakeProperty(name);        } else {            setVisible(index, false); // use the default for `real' properties        }        QString pgroup = QString::fromUtf8(baseMeta->className());        if (const QMetaObject *pmeta = propertyIntroducedBy(baseMeta, index)) {            pgroup = QString::fromUtf8(pmeta->className());        }        Info &info = ensureInfo(index);        info.group = pgroup;        info.propertyType = propertyTypeFromName(name);        if (p.type() == QVariant::Cursor) {            info.defaultValue = p.read(m_object);        }    }    if (object->isWidgetType()) {        createFakeProperty(QLatin1String("focusPolicy"));        createFakeProperty(QLatin1String("cursor"));        createFakeProperty(QLatin1String("toolTip"));        createFakeProperty(QLatin1String("whatsThis"));        createFakeProperty(QLatin1String("acceptDrops"));        createFakeProperty(QLatin1String("dragEnabled"));        createFakeProperty(QLatin1String("windowModality"));        if (qobject_cast<const QToolBar *>(m_object)) // prevent toolbars from being dragged off            createFakeProperty(QLatin1String("floatable"), QVariant(true));        if (m_canHaveLayoutAttributes) {            static const QString layoutGroup = QLatin1String("Layout");            int pindex = count();            createFakeProperty(QLatin1String("layoutLeftMargin"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);            pindex = count();            createFakeProperty(QLatin1String("layoutTopMargin"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);            pindex = count();            createFakeProperty(QLatin1String("layoutRightMargin"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);            pindex = count();            createFakeProperty(QLatin1String("layoutBottomMargin"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);            pindex = count();            createFakeProperty(QLatin1String("layoutSpacing"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);            pindex = count();            createFakeProperty(QLatin1String("layoutHorizontalSpacing"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);            pindex = count();            createFakeProperty(QLatin1String("layoutVerticalSpacing"), 0);            setAttribute(pindex, true);            setPropertyGroup(pindex, layoutGroup);        }        if (m_objectType == ObjectLabel)            createFakeProperty(QLatin1String("buddy"), QVariant(QByteArray()));    }    if (qobject_cast<const QDialog*>(object)) {        createFakeProperty(QLatin1String("modal"));    }    if (qobject_cast<const QDockWidget*>(object)) {        createFakeProperty(QLatin1String("floating"));    }    typedef QList<QByteArray> ByteArrayList;    const ByteArrayList names = object->dynamicPropertyNames();    if (!names.empty()) {        const ByteArrayList::const_iterator cend =  names.constEnd();        for (ByteArrayList::const_iterator it = names.constBegin(); it != cend; ++it) {            const char* cName = it->constData();            const QString name = QString::fromLatin1(cName);            const int idx = addDynamicProperty(name, object->property(cName));            if (idx != -1)                ensureInfo(idx).defaultDynamic = true;        }    }}QDesignerPropertySheet::~QDesignerPropertySheet(){}QObject *QDesignerPropertySheet::object() const{    return m_object;}bool QDesignerPropertySheet::dynamicPropertiesAllowed() const{    return true;}bool QDesignerPropertySheet::canAddDynamicProperty(const QString &propName) const{    const int index = m_meta->indexOfProperty(propName.toUtf8());    if (index != -1)        return false; // property already exists and is not a dynamic one    if (m_addIndex.contains(propName)) {        const int idx = m_addIndex.value(propName);        if (isVisible(idx))            return false; // dynamic property already exists        else            return true;    }    if (propName.startsWith(QLatin1String("_q_")))        return false;    return true;}int QDesignerPropertySheet::addDynamicProperty(const QString &propName, const QVariant &value){    if (!value.isValid())        return -1; // property has invalid type    if (!canAddDynamicProperty(propName))        return -1;    if (m_addIndex.contains(propName)) {

⌨️ 快捷键说明

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