properties.cpp

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

CPP
643
字号
/******************************************************************************** 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 "properties_p.h"#include "ui4_p.h"#include "abstractformbuilder.h"#include "formbuilderextra_p.h"#include <QtCore/QDateTime>#include <QtCore/QUrl>#include <QtCore/qdebug.h>#include <QtGui/QIcon>#include <QtGui/QPixmap>#include <QtGui/QFont>#include <QtGui/QFrame>#include <QtGui/QAbstractScrollArea>#include <private/qfont_p.h>static bool toBool(const QString &str){    return str.toLower() == QLatin1String("true");}#ifdef QFORMINTERNAL_NAMESPACEnamespace QFormInternal{#endif// Convert complex DOM types with the help of  QAbstractFormBuilderQVariant domPropertyToVariant(QAbstractFormBuilder *afb,const QMetaObject *meta,const  DomProperty *p){    // Complex types that need functions from QAbstractFormBuilder    switch(p->kind()) {    case DomProperty::String: {        const int index = meta->indexOfProperty(p->attributeName().toUtf8());        if (index != -1 && meta->property(index).type() == QVariant::KeySequence)            return qVariantFromValue(QKeySequence(p->elementString()->text()));    }        break;    case DomProperty::Pixmap: {        const DomResourcePixmap * dpx = afb->domPixmap(p);        return qVariantFromValue(dpx ? afb->domPropertyToPixmap(p) : QPixmap());    }    case DomProperty::IconSet: {        const DomResourcePixmap * dpx = afb->domPixmap(p);        return qVariantFromValue(dpx ? afb->domPropertyToIcon(p) : QIcon());    }    case DomProperty::Palette: {        const DomPalette *dom = p->elementPalette();        QPalette palette;        if (dom->elementActive())            afb->setupColorGroup(palette, QPalette::Active, dom->elementActive());        if (dom->elementInactive())            afb->setupColorGroup(palette, QPalette::Inactive, dom->elementInactive());        if (dom->elementDisabled())            afb->setupColorGroup(palette, QPalette::Disabled, dom->elementDisabled());        palette.setCurrentColorGroup(QPalette::Active);        return qVariantFromValue(palette);    }    case DomProperty::Set: {        const QByteArray pname = p->attributeName().toUtf8();        const int index = meta->indexOfProperty(pname);        if (index == -1) {            uiLibWarning(QObject::tr("The set-type property %1 could not be read.").arg(p->attributeName()));            return QVariant();        }        const QMetaEnum e = meta->property(index).enumerator();        Q_ASSERT(e.isFlag() == true);        return QVariant(e.keysToValue(p->elementSet().toUtf8()));    }    case DomProperty::Enum: {        const QByteArray pname = p->attributeName().toUtf8();        const int index = meta->indexOfProperty(pname);        if (index == -1) {            // ### special-casing for Line (QFrame) -- fix for 4.2            if (!qstrcmp(meta->className(), "QFrame")                && (pname == QByteArray("orientation"))) {                return QVariant((p->elementEnum() == QLatin1String("Qt::Horizontal")) ? QFrame::HLine : QFrame::VLine);            } else {                uiLibWarning(QObject::tr("The enumeration-type property %1 could not be read.").arg(p->attributeName()));                return QVariant();            }        }        const QMetaEnum e = meta->property(index).enumerator();        return QVariant(e.keyToValue(p->elementEnum().toUtf8()));    }    default:        break;    }    // simple type    return domPropertyToVariant(p);}// Convert simple DOM typesQVariant domPropertyToVariant(const DomProperty *p){    // requires non-const virtual nameToIcon, etc.    switch(p->kind()) {    case DomProperty::Bool:        return QVariant(toBool(p->elementBool()));    case DomProperty::Cstring:        return QVariant(p->elementCstring());    case DomProperty::Point: {        const DomPoint *point = p->elementPoint();        return QVariant(QPoint(point->elementX(), point->elementY()));    }    case DomProperty::PointF: {        const DomPointF *pointf = p->elementPointF();        return QVariant(QPointF(pointf->elementX(), pointf->elementY()));    }    case DomProperty::Size: {        const DomSize *size = p->elementSize();        return QVariant(QSize(size->elementWidth(), size->elementHeight()));    }    case DomProperty::SizeF: {        const DomSizeF *sizef = p->elementSizeF();        return QVariant(QSizeF(sizef->elementWidth(), sizef->elementHeight()));    }    case DomProperty::Rect: {        const DomRect *rc = p->elementRect();        const QRect g(rc->elementX(), rc->elementY(), rc->elementWidth(), rc->elementHeight());        return QVariant(g);    }    case DomProperty::RectF: {        const DomRectF *rcf = p->elementRectF();        const QRectF g(rcf->elementX(), rcf->elementY(), rcf->elementWidth(), rcf->elementHeight());        return QVariant(g);    }    case DomProperty::String:        return QVariant(p->elementString()->text());    case DomProperty::Number:        return QVariant(p->elementNumber());    case DomProperty::UInt:        return QVariant(p->elementUInt());    case DomProperty::LongLong:        return QVariant(p->elementLongLong());    case DomProperty::ULongLong:        return QVariant(p->elementULongLong());    case DomProperty::Double:        return QVariant(p->elementDouble());    case DomProperty::Char: {        const DomChar *character = p->elementChar();        const QChar c(character->elementUnicode());        return qVariantFromValue(c);    }    case DomProperty::Color: {        const DomColor *color = p->elementColor();        const QColor c(color->elementRed(), color->elementGreen(), color->elementBlue());        return qVariantFromValue(c);    }    case DomProperty::Font: {        const DomFont *font = p->elementFont();        QFont f;        if (font->hasElementFamily() && !font->elementFamily().isEmpty())            f.setFamily(font->elementFamily());        if (font->hasElementPointSize() && font->elementPointSize() > 0)            f.setPointSize(font->elementPointSize());        if (font->hasElementWeight() && font->elementWeight() > 0)            f.setWeight(font->elementWeight());        if (font->hasElementItalic())            f.setItalic(font->elementItalic());        if (font->hasElementBold())            f.setBold(font->elementBold());        if (font->hasElementUnderline())            f.setUnderline(font->elementUnderline());        if (font->hasElementStrikeOut())            f.setStrikeOut(font->elementStrikeOut());        if (font->hasElementKerning())            f.setKerning(font->elementKerning());        if (font->hasElementAntialiasing())            f.setStyleStrategy(font->elementAntialiasing() ? QFont::PreferDefault : QFont::NoAntialias);        if (font->hasElementStyleStrategy()) {            f.setStyleStrategy(enumKeyOfObjectToValue<QAbstractFormBuilderGadget, QFont::StyleStrategy>("styleStrategy", font->elementStyleStrategy().toLatin1()));        }        return qVariantFromValue(f);    }    case DomProperty::Date: {        const DomDate *date = p->elementDate();        return QVariant(QDate(date->elementYear(), date->elementMonth(), date->elementDay()));    }    case DomProperty::Time: {        const DomTime *t = p->elementTime();        return QVariant(QTime(t->elementHour(), t->elementMinute(), t->elementSecond()));    }    case DomProperty::DateTime: {        const DomDateTime *dateTime = p->elementDateTime();        const QDate d(dateTime->elementYear(), dateTime->elementMonth(), dateTime->elementDay());        const QTime tm(dateTime->elementHour(), dateTime->elementMinute(), dateTime->elementSecond());        return QVariant(QDateTime(d, tm));    }    case DomProperty::Url: {        const DomUrl *url = p->elementUrl();        return QVariant(QUrl(url->elementString()->text()));    }    case DomProperty::Cursor:        return qVariantFromValue(QCursor(static_cast<Qt::CursorShape>(p->elementCursor())));    case DomProperty::CursorShape:        return qVariantFromValue(QCursor(enumKeyOfObjectToValue<QAbstractFormBuilderGadget, Qt::CursorShape>("cursorShape", p->elementCursorShape().toLatin1())));    case DomProperty::Locale: {        const DomLocale *locale = p->elementLocale();        return qVariantFromValue(QLocale(enumKeyOfObjectToValue<QAbstractFormBuilderGadget, QLocale::Language>("language", locale->attributeLanguage().toLatin1()),                    enumKeyOfObjectToValue<QAbstractFormBuilderGadget, QLocale::Country>("country", locale->attributeCountry().toLatin1())));    }    case DomProperty::SizePolicy: {        const DomSizePolicy *sizep = p->elementSizePolicy();        QSizePolicy sizePolicy;        sizePolicy.setHorizontalStretch(sizep->elementHorStretch());        sizePolicy.setVerticalStretch(sizep->elementVerStretch());        const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType");        if (sizep->hasElementHSizeType()) {            sizePolicy.setHorizontalPolicy((QSizePolicy::Policy) sizep->elementHSizeType());        } else if (sizep->hasAttributeHSizeType()) {            const QSizePolicy::Policy sp = enumKeyToValue<QSizePolicy::Policy>(sizeType_enum, sizep->attributeHSizeType().toLatin1());            sizePolicy.setHorizontalPolicy(sp);        }        if (sizep->hasElementVSizeType()) {            sizePolicy.setVerticalPolicy((QSizePolicy::Policy) sizep->elementVSizeType());        } else if (sizep->hasAttributeVSizeType()) {            const  QSizePolicy::Policy sp = enumKeyToValue<QSizePolicy::Policy>(sizeType_enum, sizep->attributeVSizeType().toLatin1());            sizePolicy.setVerticalPolicy(sp);        }        return qVariantFromValue(sizePolicy);    }    case DomProperty::StringList:        return QVariant(p->elementStringList()->elementString());    default:        uiLibWarning(QObject::tr("Reading properties of the type %1 is not supported yet.").arg(p->kind()));        break;    }    return QVariant();}// Apply a simple variant type to a DOM propertystatic bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop){    switch (v.type()) {    case QVariant::String: {        DomString *str = new DomString();        str->setText(v.toString());        if (!translateString)            str->setAttributeNotr(QLatin1String("true"));        dom_prop->setElementString(str);    }

⌨️ 快捷键说明

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