void MetabarFunctions::toggle(DOM::DOMString item) { DOM::HTMLDocument doc = m_html->htmlDocument(); DOM::HTMLElement node = static_cast<DOM::HTMLElement>(doc.getElementById(item)); if(!node.isNull()) { DOM::NodeList children = node.childNodes(); DOM::CSSStyleDeclaration style = node.style(); DOM::DOMString expanded = node.getAttribute("expanded"); bool isExpanded = expanded == "true"; int height = 0; if(!isExpanded) { height = getHeight(node); } DOM::DOMString att = isExpanded ? "false" : "true"; node.setAttribute("expanded", att); KConfig config("metabarrc"); config.setGroup("General"); if(config.readBoolEntry("AnimateResize", false)) { resizeMap[item.string()] = height; if(!timer->isActive()) { timer->start(RESIZE_SPEED); } } else { style.setProperty("height", QString("%1px").arg(height), CSS_PRIORITY); } } }
int MetabarFunctions::getHeight(DOM::HTMLElement &element) { int height = 0; DOM::NodeList children = element.childNodes(); for(uint i = 0; i < children.length(); i++) { DOM::HTMLElement node = static_cast<DOM::HTMLElement>(children.item(i)); DOM::CSSStyleDeclaration style = node.style(); DOM::DOMString css_height = style.getPropertyValue("height"); if(!css_height.isNull()) { height += css_height.string().left(css_height.string().length() - 2).toInt(); } else { int h = 0; if(!node.isNull()) { h = node.getRect().height(); } DOM::DOMString display = style.getPropertyValue("display"); if(display == "none") { h = 0; } else if(h == 0) { h = 20; } height += h; } } return height; }
void MetabarFunctions::hide(DOM::DOMString item) { DOM::HTMLDocument doc = m_html->htmlDocument(); DOM::HTMLElement node = static_cast<DOM::HTMLElement>(doc.getElementById(item)); if(!node.isNull()) { DOM::HTMLElement parent = static_cast<DOM::HTMLElement>(node.parentNode()); DOM::CSSStyleDeclaration style = parent.style(); style.setProperty("display", "none", CSS_PRIORITY); } }
void MetabarFunctions::animate() { QMap<QString, int>::Iterator it; for(it = resizeMap.begin(); it != resizeMap.end(); ++it ) { QString id = it.key(); int height = it.data(); int currentHeight = 0; DOM::HTMLDocument doc = m_html->htmlDocument(); DOM::HTMLElement node = static_cast<DOM::HTMLElement>(doc.getElementById(id)); DOM::CSSStyleDeclaration style = node.style(); QString currentHeightString = style.getPropertyValue("height").string(); if(currentHeightString.endsWith("px")) { currentHeight = currentHeightString.left(currentHeightString.length() - 2).toInt(); } if(currentHeight == height) { resizeMap.remove(id); if(resizeMap.isEmpty()) { timer->stop(); } } else { int diff = kAbs(currentHeight - height); int changeValue = RESIZE_STEP; if(diff < RESIZE_STEP) { changeValue = diff; } int change = currentHeight < height ? changeValue : -changeValue; style.setProperty("height", QString("%1px").arg(currentHeight + change), CSS_PRIORITY); doc.updateRendering(); } } }