Ejemplo n.º 1
0
//----------------------------------------------------------------------------//
void NamedElement::setName(const String& name)
{
    if (d_name == name)
        return;

    if (getParentElement())
    {
        NamedElement* parent = dynamic_cast<NamedElement*>(getParentElement());

        if (parent && parent->isChild(name))
        {
            CEGUI_THROW(AlreadyExistsException("Failed to rename "
                "NamedElement at: " + getNamePath() + " as: " + name + ". A Window "
                "with that name is already attached as a sibling."));
        }
    }

    // log this under informative level
    Logger::getSingleton().logEvent("Renamed element at: " + getNamePath() +
                                    " as: " + name, Informative);

    d_name = name;

    NamedElementEventArgs args(this);
    onNameChanged(args);
}
Ejemplo n.º 2
0
void CSSEdit::colorSelectClicked()
{
    QToolButton *colorButton;
    QString propertyName;
    if (sender() == m_colorButton)
    {
        colorButton = m_colorButton;
        propertyName = "color";
    }
    else if (sender() == m_backgroundButton)
    {
        colorButton = m_backgroundButton;
        propertyName = "background-color";
    }
    else
        return;

    if (! m_elements.contains(m_currentElement))
        return;
    Element *element = &m_elements[m_currentElement];
    Element parentElement = getParentElement(m_currentElement);
    QColor color = QColorDialog::getColor(QColor(colorButton->text()), this);
    if (color.isValid())
    {
        colorButton->setText(color.name());
        QPalette palette = colorButton->palette();
        palette.setColor(QPalette::Normal, QPalette::ButtonText, color);
        colorButton->setPalette(palette);
        if (parentElement[propertyName] == color.name())
            element->remove(propertyName);
        else
            element->insert(propertyName, color.name());
        updatePreview();
    }
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------//
Rectf Element::getUnclippedOuterRect_impl(bool skipAllPixelAlignment) const
{
    const Sizef pixel_size = skipAllPixelAlignment ?
        calculatePixelSize(true) : getPixelSize();
    Rectf ret(Vector2f(0, 0), pixel_size);

    const Element* parent = getParentElement();

    Rectf parent_rect;
    if (parent)
    {
        const CachedRectf& base = parent->getChildContentArea(isNonClient());
        parent_rect = skipAllPixelAlignment ? base.getFresh(true) : base.get();
    }
    else
    {
        parent_rect = Rectf(Vector2f(0, 0), getRootContainerSize());
    }

    const Sizef parent_size = parent_rect.getSize();

    Vector2f offset = parent_rect.d_min + CoordConverter::asAbsolute(getArea().d_min, parent_size, false);

    switch (getHorizontalAlignment())
    {
        case HA_CENTRE:
            offset.d_x += (parent_size.d_width - pixel_size.d_width) * 0.5f;
            break;
        case HA_RIGHT:
            offset.d_x += parent_size.d_width - pixel_size.d_width;
            break;
        default:
            break;
    }

    switch (getVerticalAlignment())
    {
        case VA_CENTRE:
            offset.d_y += (parent_size.d_height - pixel_size.d_height) * 0.5f;
            break;
        case VA_BOTTOM:
            offset.d_y += parent_size.d_height - pixel_size.d_height;
            break;
        default:
            break;
    }

    if (d_pixelAligned && !skipAllPixelAlignment)
    {
        offset = Vector2f(CoordConverter::alignToPixels(offset.d_x),
                          CoordConverter::alignToPixels(offset.d_y));
    }

    ret.offset(offset);
    return ret;
}
Ejemplo n.º 4
0
void CSSEdit::propertyChanged()
{
    if (! sender())
        return;
    if (! m_elements.contains(m_currentElement))
        return;
    Element *element = &m_elements[m_currentElement];
    Element parentElement = getParentElement(m_currentElement);

    if (sender() == m_fontCombo)
    {
        QString font = m_fontCombo->currentText();
        if (parentElement["font-family"] == font)
            element->remove("font-family");
        else
            element->insert("font-family", font);
    }
    else if (sender() == m_sizeSpin)
    {
        QString size = QString::number(m_sizeSpin->value()) + "pt";
        if (parentElement["font-size"] == size)
            element->remove("font-size");
        else
            element->insert("font-size", size);
    }
    else if (sender() == m_boldButton)
    {
        QString weight = (m_boldButton->isChecked() ? "bold" : "normal");
        if (parentElement["font-weight"] == weight)
            element->remove("font-weight");
        else
            element->insert("font-weight", weight);
    }
    else if(sender() == m_italicButton)
    {
        QString style = (m_italicButton->isChecked() ? "italic" : "normal");
        if (parentElement["font-style"] == style)
            element->remove("font-style");
        else
            element->insert("font-style", style);
    }
    else if(sender() == m_underlineButton)
    {
        QString decoration = (m_underlineButton->isChecked() ? "underline" : "none");
        if (parentElement["text-decoration"] == decoration)
            element->remove("text-decoration");
        else
            element->insert("text-decoration", decoration);
    }

    updatePreview();
}
Ejemplo n.º 5
0
//----------------------------------------------------------------------------//
String NamedElement::getNamePath() const
{
    String path("");

    Element* parent_element = getParentElement();
    NamedElement* parent_named_element = dynamic_cast<NamedElement*>(parent_element);

    if (parent_element)
    {
        if (parent_named_element)
            path = parent_named_element->getNamePath() + '/';
        else
            path = "<not a named element>/";
    }

    path += getName();

    return path;
}
Ejemplo n.º 6
0
    ElementPtr Node::getRootElement() const
    {
      ElementPtr found;
      if (isElement()) {
        found = toElement();
      } else {
        found = getParentElement();
      }

      if (!found)
        return ElementPtr();

      ElementPtr parent = found->getParentElement();
      while (parent)
      {
        found = parent;
        parent = parent->getParentElement();
      }
      return found;
    }
Ejemplo n.º 7
0
void CSSEdit::setCurrentElement(int index)
{
    if (! m_elements.contains(m_elementCombo->itemData(index).toString()))
        return;
    m_currentElement = m_elementCombo->itemData(index).toString();
    Element *element = &m_elements[m_currentElement];
    Element parentElement = getParentElement(m_currentElement);

    QColor color(element->contains("color") ? element->value("color") : parentElement["color"]);
    m_colorButton->setText(color.name());
    QPalette palette = m_colorButton->palette();
    palette.setColor(QPalette::Normal, QPalette::ButtonText, color);
    m_colorButton->setPalette(palette);

    color = QColor(element->contains("background-color") ?
        element->value("background-color") : parentElement["background-color"]);
    m_backgroundButton->setText(color.name());
    palette = m_backgroundButton->palette();
    palette.setColor(QPalette::Normal, QPalette::ButtonText, color);
    m_backgroundButton->setPalette(palette);

    m_fontCombo->setCurrentFont(element->contains("font-family") ?
            element->value("font-family") : parentElement["font-family"]);

    QString value = element->contains("font-size") ?
        element->value("font-size") : parentElement["font-size"];
    if (! value.endsWith("pt"))
        value = parentElement["font-size"];
    m_sizeSpin->setValue(value.left(value.length() - 2).toInt());

    value = element->contains("font-weight") ? element->value("font-weight") : parentElement["font-weight"];
    m_boldButton->setChecked(value == "bold");

    value = element->contains("font-style") ? element->value("font-style") : parentElement["font-style"];
    m_italicButton->setChecked(value == "italic");

    value = element->contains("text-decoration") ? element->value("text-decoration") : parentElement["text-decoration"];
    m_underlineButton->setChecked(value == "underline");

    updatePreview();
}
Ejemplo n.º 8
0
 ElementPtr Node::getParentElementChecked() const throw(Exceptions::CheckFailed)
 {
   ElementPtr result = getParentElement();
   ZS_THROW_CUSTOM_IF(Exceptions::CheckFailed, !result)
   return result;
 }