Exemplo n.º 1
0
bool HoverHandler::matchColorItem(const ScopeChain &scopeChain,
                                  const Document::Ptr &qmlDocument,
                                  const QList<AST::Node *> &astPath,
                                  unsigned pos)
{
    AST::UiObjectInitializer *initializer = nodeInitializer(astPath.last());
    if (!initializer)
        return false;

    AST::UiObjectMember *member = 0;
    for (AST::UiObjectMemberList *list = initializer->members; list; list = list->next) {
        if (posIsInSource(pos, list->member)) {
            member = list->member;
            break;
        }
    }
    if (!member)
        return false;

    QString color;
    const Value *value = 0;
    if (const AST::UiScriptBinding *binding = AST::cast<const AST::UiScriptBinding *>(member)) {
        if (binding->qualifiedId && posIsInSource(pos, binding->statement)) {
            value = scopeChain.evaluate(binding->qualifiedId);
            if (value && value->asColorValue()) {
                color = textAt(qmlDocument,
                               binding->statement->firstSourceLocation(),
                               binding->statement->lastSourceLocation());
            }
        }
    } else if (const AST::UiPublicMember *publicMember =
               AST::cast<const AST::UiPublicMember *>(member)) {
        if (publicMember->name && posIsInSource(pos, publicMember->statement)) {
            value = scopeChain.lookup(publicMember->name->asString());
            if (const Reference *ref = value->asReference())
                value = scopeChain.context()->lookupReference(ref);
                color = textAt(qmlDocument,
                               publicMember->statement->firstSourceLocation(),
                               publicMember->statement->lastSourceLocation());
        }
    }

    if (!color.isEmpty()) {
        color.remove(QLatin1Char('\''));
        color.remove(QLatin1Char('\"'));
        color.remove(QLatin1Char(';'));

        m_colorTip = QmlJS::toQColor(color);
        if (m_colorTip.isValid()) {
            setToolTip(color);
            return true;
        }
    }
    return false;
}
 bool hasStatePrototype(Node *ast)
 {
     Bind *bind = m_scopeChain.document()->bind();
     const ObjectValue *v = bind->findQmlObject(ast);
     if (!v)
         return false;
     PrototypeIterator it(v, m_scopeChain.context());
     while (it.hasNext()) {
         const ObjectValue *proto = it.next();
         const CppComponentValue *qmlProto = value_cast<CppComponentValue>(proto);
         if (!qmlProto)
             continue;
         if (qmlProto->metaObject() == m_statePrototype->metaObject())
             return true;
     }
     return false;
 }
 CollectStateNames(const ScopeChain &scopeChain)
     : m_scopeChain(scopeChain)
 {
     m_statePrototype = scopeChain.context()->valueOwner()->cppQmlTypes().objectByCppName(QLatin1String("QDeclarativeState"));
 }