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 HistoryDialog::setMessages(QValueList<Kopete::Message> msgs) { // Clear View DOM::HTMLElement htmlBody = mHtmlPart->htmlDocument().body(); while(htmlBody.hasChildNodes()) htmlBody.removeChild(htmlBody.childNodes().item(htmlBody.childNodes().length() - 1)); // ---- QString dir = (QApplication::reverseLayout() ? QString::fromLatin1("rtl") : QString::fromLatin1("ltr")); QValueList<Kopete::Message>::iterator it = msgs.begin(); QString accountLabel; QString resultHTML = "<b><font color=\"red\">" + (*it).timestamp().date().toString() + "</font></b><br/>"; DOM::HTMLElement newNode = mHtmlPart->document().createElement(QString::fromLatin1("span")); newNode.setAttribute(QString::fromLatin1("dir"), dir); newNode.setInnerHTML(resultHTML); mHtmlPart->htmlDocument().body().appendChild(newNode); // Populating HTML Part with messages for ( it = msgs.begin(); it != msgs.end(); ++it ) { if ( mMainWidget->messageFilterBox->currentItem() == 0 || ( mMainWidget->messageFilterBox->currentItem() == 1 && (*it).direction() == Kopete::Message::Inbound ) || ( mMainWidget->messageFilterBox->currentItem() == 2 && (*it).direction() == Kopete::Message::Outbound ) ) { resultHTML = ""; if (accountLabel.isEmpty() || accountLabel != (*it).from()->account()->accountLabel()) // If the message's account is new, just specify it to the user { if (!accountLabel.isEmpty()) resultHTML += "<br/><br/><br/>"; resultHTML += "<b><font color=\"blue\">" + (*it).from()->account()->accountLabel() + "</font></b><br/>"; } accountLabel = (*it).from()->account()->accountLabel(); QString body = (*it).parsedBody(); if (!mMainWidget->searchLine->text().isEmpty()) // If there is a search, then we hightlight the keywords { body = body.replace(mMainWidget->searchLine->text(), "<span style=\"background-color:yellow\">" + mMainWidget->searchLine->text() + "</span>", false); } resultHTML += "(<b>" + (*it).timestamp().time().toString() + "</b>) " + ((*it).direction() == Kopete::Message::Outbound ? "<font color=\"" + KopetePrefs::prefs()->textColor().dark().name() + "\"><b>></b></font> " : "<font color=\"" + KopetePrefs::prefs()->textColor().light(200).name() + "\"><b><</b></font> ") + body + "<br/>"; newNode = mHtmlPart->document().createElement(QString::fromLatin1("span")); newNode.setAttribute(QString::fromLatin1("dir"), dir); newNode.setInnerHTML(resultHTML); mHtmlPart->htmlDocument().body().appendChild(newNode); } } }