Exemple #1
0
void HSSExpression::setScope(HSSSimpleSelection::p newScope)
{
    this->scope = newScope;
    //propagate values
    if (this->left && this->left->isA(HSSParserNodeTypeExpression))
    {
        HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->left);
        leftExpression->setScope(newScope);
    }
    else if (this->left && this->left->isA(HSSParserNodeTypeFunctionCall))
    {
        HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->left);
        leftFunction->setScope(newScope);
    }
    if (this->right && this->right->isA(HSSParserNodeTypeExpression))
    {
        HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->right);
        rightExpression->setScope(newScope);
    }
    else if (this->right && this->right->isA(HSSParserNodeTypeFunctionCall))
    {
        HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->right);
        rightFunction->setScope(newScope);
    }

    this->setDirty(true);
}
Exemple #2
0
void HSSExpression::setPercentageObserved(HSSObservableProperty property, HSSObservable *observed)
{
    this->percentageObserved = observed;
    this->percentageObservedProperty = property;

    //propagate values
    if (this->left && this->left->isA(HSSParserNodeTypeExpression))
    {
        HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->left);
        leftExpression->setPercentageObserved(property, observed);
    }
    else if (this->left && this->left->isA(HSSParserNodeTypeFunctionCall))
    {
        HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->left);
        leftFunction->setPercentageObserved(property, observed);
    }
    if (this->right && this->right->isA(HSSParserNodeTypeExpression))
    {
        HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->right);
        rightExpression->setPercentageObserved(property, observed);
    }
    else if (this->right && this->right->isA(HSSParserNodeTypeFunctionCall))
    {
        HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->right);
        rightFunction->setPercentageObserved(property, observed);
    }

    this->setDirty(true);
}
Exemple #3
0
void HSSExpression::setPercentageBase(HSSUnit value)
{
    this->percentageBase = value;

    //propagate values
    if (this->left && this->left->isA(HSSParserNodeTypeExpression))
    {
        HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->left);
        leftExpression->setPercentageBase(value);
    }
    else if (this->left && this->left->isA(HSSParserNodeTypeFunctionCall))
    {
        HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->left);
        leftFunction->setPercentageBase(value);
    }
    if (this->right && this->right->isA(HSSParserNodeTypeExpression))
    {
        HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->right);
        rightExpression->setPercentageBase(value);
    }
    else if (this->right && this->right->isA(HSSParserNodeTypeFunctionCall))
    {
        HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->right);
        rightFunction->setPercentageBase(value);
    }

    this->setDirty(true);
}
Exemple #4
0
void HSSRequest::setDSrc(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeKeywordConstant:
    case HSSParserNodeTypeFunctionCall:
    case HSSParserNodeTypeStringConstant:
    {
        this->dSrc = value;
        if (this->observedSrc)
        {
            this->observedSrc->removeObserver(this->observedSrcProperty, HSSObservablePropertySrc, this);
        }

        switch (value->getType())
        {
        case HSSParserNodeTypeKeywordConstant:
            /**
             *  @todo what here?
             */
            break;

        case HSSParserNodeTypeStringConstant:
        {
            HSSStringConstant::p theString = qSharedPointerCast<HSSStringConstant > (value);
            this->src = QUrl(theString->getValue());
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
            fnct->setScope(this->scope);
            fnct->setThisObj(this->getThisObj());
            QVariant remoteValue = fnct->evaluate();
            if (remoteValue.canConvert<AXRString>())
            {
                this->src = QUrl(remoteValue.value<AXRString>());
            }

            break;
        }

        default:
            break;
        }

        this->notifyObservers(HSSObservablePropertySrc, &this->src);

        break;
    }

    default:
        throw AXRWarning("HSSRequest", "Invalid value for src of " + this->name);
    }
}
Exemple #5
0
void HSSFunction::setScope(HSSSimpleSelection::p newScope)
{
    this->scope = newScope;
    std::deque<HSSParserNode::p>::const_iterator it;
    for (it = this->_arguments.begin(); it != this->_arguments.end(); ++it)
    {
        const HSSParserNode::p node = (*it);
        switch (node->getType())
        {
        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p func = qSharedPointerCast<HSSFunction > (node);
            func->setScope(newScope);
            break;
        }

        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p exp = qSharedPointerCast<HSSExpression > (node);
            exp->setScope(newScope);
            break;
        }

        default:
            break;
        }

        switch (node->getStatementType())
        {
        case HSSStatementTypeObjectDefinition:
        {
            HSSObjectDefinition::p objdef = qSharedPointerCast<HSSObjectDefinition > (node);
            objdef->setScope(newScope);
            break;
        }

        default:
            break;
        }
    }
}
Exemple #6
0
void HSSRequest::setDTarget(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeKeywordConstant:
    case HSSParserNodeTypeFunctionCall:
    {
        this->dTarget = value;
        if (this->observedTarget)
        {
            this->observedTarget->removeObserver(this->observedTargetProperty, HSSObservablePropertyTarget, this);
        }

        switch (value->getType())
        {
        case HSSParserNodeTypeKeywordConstant:
            /**
             *  @todo what here?
             */
            break;

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
            if (fnct)
            {
                fnct->setScope(this->scope);
                fnct->setThisObj(this->getThisObj());
                QVariant remoteValue = fnct->evaluate();
                if (remoteValue.canConvert< HSSSelection::p >())
                {
                    HSSSimpleSelection::p selection = remoteValue.value< HSSSelection::p >()->joinAll();
                    this->target->clear();
                    this->target->insert(this->target->end(), selection->begin(), selection->end());
                }

                /**
                 *  @todo potentially leaking
                 */
                fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyTarget, this, new HSSValueChangedCallback<HSSRequest > (this, &HSSRequest::targetChanged));
                this->observedTarget = fnct.data();
                this->observedTargetProperty = HSSObservablePropertyValue;
            }

            break;
        }

        default:
            break;
        }

        this->notifyObservers(HSSObservablePropertySrc, &this->src);

        break;
    }

    default:
        throw AXRWarning("HSSRequest", "Invalid value for src of " + this->name);
    }
}
Exemple #7
0
void HSSColorStop::setDBalance(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeNumberConstant:
    case HSSParserNodeTypePercentageConstant:
    case HSSParserNodeTypeExpression:
        this->dBalance = value;
        this->balance = this->_evaluatePropertyValue(
                                             &HSSColorStop::balanceChanged,
                                             value,
                                             1.,
                                             HSSObservablePropertyBalance,
                                             this->observedBalance,
                                             this->observedBalanceProperty
                                             );

        break;

    case HSSParserNodeTypeFunctionCall:
    {
        this->dBalance = value;
        HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
        if (fnct && fnct->isA(HSSFunctionTypeRef))
        {
            fnct->setScope(this->scope);
            fnct->setThisObj(this->getThisObj());
            QVariant remoteValue = fnct->evaluate();
            if (remoteValue.canConvert<HSSUnit>())
            {
                this->balance = remoteValue.value<HSSUnit>();
            }

            fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyBalance, this, new HSSValueChangedCallback<HSSColorStop > (this, &HSSColorStop::balanceChanged));

        }
        else
        {
            throw AXRWarning("HSSDGradient", "Invalid function type for balance of " + this->name);
        }

        break;
    }

    default:
        throw AXRWarning("HSSColorStop", "Invalid value for balance of " + this->name);
    }
    this->notifyObservers(HSSObservablePropertyBalance, &this->balance);
    this->notifyObservers(HSSObservablePropertyValue, NULL);
}
void HSSFunctionAction::fire()
{
    HSSFunction::p function = this->getFunction();
    function->_evaluate(function->getArguments());
}
Exemple #9
0
void HSSColorStop::setDColor(HSSParserNode::p value)
{
    bool valid = false;

    switch (value->getType())
    {
    case HSSParserNodeTypeObjectNameConstant:
    {
        this->dColor = value;
        try
        {
            HSSObjectNameConstant::p objname = qSharedPointerCast<HSSObjectNameConstant > (value);
            HSSObjectDefinition::p objdef = this->getController()->objectTreeGet(objname->getValue());
            this->setDColor(objdef);
            valid = true;

        }
        catch (const AXRError &e)
        {
            e.raise();
        }

        break;
    }


    case HSSParserNodeTypeFunctionCall:
    {
        this->dColor = value;
        HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
        if (fnct && fnct->isA(HSSFunctionTypeRef))
        {
            fnct->setScope(this->scope);
            fnct->setThisObj(this->getThisObj());
            QVariant remoteValue = fnct->evaluate();
            if (remoteValue.canConvert<HSSRgb::p>())
            {
                this->color = remoteValue.value<HSSRgb::p>();
                valid = true;
            }

            fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyColor, this, new HSSValueChangedCallback<HSSColorStop > (this, &HSSColorStop::colorChanged));
        }
        break;
    }

    case HSSParserNodeTypeKeywordConstant:
    {
        HSSKeywordConstant::p theKW = qSharedPointerCast<HSSKeywordConstant>(value);
        AXRString kwValue = theKW->getValue();

        if (kwValue == "black")
        {
            this->color = HSSRgb::blackColor(this->getController());
            valid = true;
        }
        else if (kwValue == "white")
        {
            this->color = HSSRgb::whiteColor(this->getController());
            valid = true;
        }
        else if (kwValue == "transparent")
        {
            //the color will remain empty for transparent
            this->color.clear();
            valid = true;
        }

        break;
    }

    default:
        break;
    }

    switch (value->getStatementType())
    {
    case HSSStatementTypeObjectDefinition:
    {
        this->dColor = value;
        HSSObjectDefinition::p objdef = qSharedPointerCast<HSSObjectDefinition > (value);
        objdef->setScope(this->scope);
        objdef->setThisObj(this->getThisObj());
        objdef->apply();
        HSSObject::p theobj = objdef->getObject();
        if (theobj && theobj->isA(HSSObjectTypeRgb))
        {
            this->color = qSharedPointerCast<HSSRgb > (theobj);
            valid = true;
        }

        break;
    }

    default:
        break;
    }

    if (!valid)
        throw AXRWarning("HSSColorStop", "Invalid value for color of " + this->name);

    this->notifyObservers(HSSObservablePropertyColor, &this->color);
    this->notifyObservers(HSSObservablePropertyValue, NULL);
}
Exemple #10
0
void HSSLog::fire()
{
    switch (this->dValue->getType()) {
        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p fnct = boost::static_pointer_cast<HSSFunction>(this->dValue);
            if(fnct->isA(HSSFunctionTypeRef)){
                HSSRefFunction::p refFnct = boost::static_pointer_cast<HSSRefFunction>(fnct);
                refFnct->setScope(this->scope);
                void * data = refFnct->evaluate();
                switch (refFnct->getPropertyName()) {
                    case HSSObservablePropertyWidth:
                    case HSSObservablePropertyHeight:
                    case HSSObservablePropertyAnchorX:
                    case HSSObservablePropertyAnchorY:
                    case HSSObservablePropertyAlignX:
                    case HSSObservablePropertyAlignY:
                    case HSSObservablePropertyContentAlignX:
                    case HSSObservablePropertyContentAlignY:
                    case HSSObservablePropertyStartX:
                    case HSSObservablePropertyStartY:
                    case HSSObservablePropertyEndX:
                    case HSSObservablePropertyEndY:
                    case HSSObservablePropertyPosition:
                    case HSSObservablePropertyRed:
                    case HSSObservablePropertyGreen:
                    case HSSObservablePropertyBlue:
                    case HSSObservablePropertyAlpha:
                    case HSSObservablePropertySize:
                    case HSSObservablePropertyCorners:
                    {
                        std_log(*(long double*)data);
                        break;
                    }
                        
                    case HSSObservablePropertyMargin:
                    case HSSObservablePropertyPadding:
                    case HSSObservablePropertyShape:
                    case HSSObservablePropertyStartColor:
                    case HSSObservablePropertyEndColor:
                    case HSSObservablePropertyColorStops:
                    case HSSObservablePropertyBalance:
                    case HSSObservablePropertyFace:
                    case HSSObservablePropertyColor:
                    case HSSObservablePropertyAction:
                    {
                        std_log((*(HSSObject::p *)data)->toString());
                        break;
                    }
                        
                    case HSSObservablePropertyBackground:
                    case HSSObservablePropertyBorder:
                    case HSSObservablePropertyFont:
                    {
                        std::vector<HSSObject::p> v_data = *(std::vector<HSSObject::p>*)data;
                        std::vector<HSSObject::p>::iterator it;
                        if (v_data.size() == 0) {
                            std_log("empty");
                        } else {
                            for (it=v_data.begin(); it!=v_data.end(); it++) {
                                std_log((*it)->toString());
                            }
                        }
                        break;
                    }
                        
                    case HSSObservablePropertyOn:
                    {
                        boost::unordered_map<HSSEventType, std::vector<HSSObject::p> > m_data = *(boost::unordered_map<HSSEventType, std::vector<HSSObject::p> >*)data;
                        boost::unordered_map<HSSEventType, std::vector<HSSObject::p> >::iterator it;
                        if (m_data.size() == 0) {
                            std_log("empty");
                        } else {
                            for (it=m_data.begin(); it!=m_data.end(); it++) {
                                std::vector<HSSObject::p> v_data = (*it).second;
                                std::vector<HSSObject::p>::iterator it2;
                                for (it2=v_data.begin(); it2!=v_data.end(); it2++) {
                                    std_log((*it2)->toString());
                                }
                            }
                        }
                        break;
                    }
                        
                    case HSSObservablePropertyDirectionPrimary:
                    case HSSObservablePropertyDirectionSecondary:
                    case HSSObservablePropertyTransform:
                    case HSSObservablePropertyTextAlign:
                    case HSSObservablePropertyWeight:
                    case HSSObservablePropertySrc:
                    case HSSObservablePropertyMode:
                    case HSSObservablePropertyContentTarget:
                    {
                        std_log(*(std::string*)data);
                        break;
                    }
                        
                    case HSSObservablePropertyFlagChanged:
                    case HSSObservablePropertyText:
                    case HSSObservablePropertyTarget:
                    default:
                    {
                        std_log("logging this property is not supported");
                        break;
                    }
                }
            }
            break;
        }
        
        case HSSParserNodeTypeStringConstant:
        {
            HSSStringConstant::p str = boost::static_pointer_cast<HSSStringConstant>(this->dValue);
            std_log(str->getValue());
            break;
        }
            
        default:
        {
            std_log(this->dValue->toString());
            break;
        }
    }
}
Exemple #11
0
HSSUnit HSSExpression::evaluate()
{
    if (this->isDirty())
    {
        this->setDirty(false);

        //left
        switch (this->getLeft()->getType())
        {
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->getLeft());
            this->leftval = leftExpression->evaluate();
            if (this->leftObserved)
            {
                this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
            }
            leftExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
            this->leftObserved = leftExpression.data();
            this->leftObservedProperty = HSSObservablePropertyValue;
            break;
        }

        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p leftNumber = qSharedPointerCast<HSSNumberConstant > (this->getLeft());
            this->leftval = leftNumber->getValue();
            break;
        }

        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p leftPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getLeft());
            this->leftval = leftPercentage->getValue(this->percentageBase);
            if (this->leftObserved)
            {
                this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
            }
            this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
            this->leftObserved = this->percentageObserved;
            this->leftObservedProperty = this->percentageObservedProperty;
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->getLeft());
            QVariant remoteValue = leftFunction->evaluate();
            if (remoteValue.canConvert<HSSUnit*>())
            {
                this->leftval = *remoteValue.value<HSSUnit*>();
                if (this->leftObserved)
                {
                    this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
                }
                leftFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
                this->leftObserved = leftFunction.data();
                this->leftObservedProperty = HSSObservablePropertyValue;

            }
            else
            {
                this->rightval = 0.;
            }

            break;
        }

        default:
            std_log1("############ HSSExpression::evaluate() unknwown node type in left member");
            break;
        }


        //right
        switch (this->getRight()->getType())
        {
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->getRight());
            this->rightval = rightExpression->evaluate();
            if (this->rightObserved)
            {
                this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
            }
            rightExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
            this->rightObserved = rightExpression.data();
            this->rightObservedProperty = HSSObservablePropertyValue;
            break;
        }

        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p rightNumber = qSharedPointerCast<HSSNumberConstant > (this->getRight());
            this->rightval = rightNumber->getValue();
            break;
        }

        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p rightPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getRight());
            this->rightval = rightPercentage->getValue(this->percentageBase);
            if (this->rightObserved)
            {
                this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
            }
            this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
            this->rightObserved = this->percentageObserved;
            this->rightObservedProperty = this->percentageObservedProperty;
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->getRight());
            QVariant remoteValue = rightFunction->evaluate();
            if (remoteValue.canConvert<HSSUnit*>())
            {
                this->rightval = *remoteValue.value<HSSUnit*>();
                if (this->rightObserved)
                {
                    this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
                }
                rightFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
                this->rightObserved = rightFunction.data();
                this->rightObservedProperty = HSSObservablePropertyValue;
            }
            else
            {
                this->rightval = 0.;
            }

            break;
        }

        default:
            std_log1("############ HSSExpression::evaluate() unknwown node type in right member");
            break;
        }

        this->setValue(this->calculate(this->leftval, this->rightval));
    }

    return this->getValue();
}