bool kpTool::currentPointCardinallyNextToLast () const { if (m_lastPoint == QPoint (-1, -1)) return true; int dx = kAbs (m_currentPoint.x () - m_lastPoint.x ()); int dy = kAbs (m_currentPoint.y () - m_lastPoint.y ()); return (dx + dy <= 1); }
QColor PrettyPopupMenu::calcPixmapColor() { KConfig *config = KGlobal::config(); config->setGroup("WM"); QColor color = QApplication::palette().active().highlight(); // QColor activeTitle = QApplication::palette().active().background(); // QColor inactiveTitle = QApplication::palette().inactive().background(); QColor activeTitle = config->readColorEntry("activeBackground", &color); QColor inactiveTitle = config->readColorEntry("inactiveBackground", &color); // figure out which color is most suitable for recoloring to int h1, s1, v1, h2, s2, v2, h3, s3, v3; activeTitle.hsv(&h1, &s1, &v1); inactiveTitle.hsv(&h2, &s2, &v2); QApplication::palette().active().background().hsv(&h3, &s3, &v3); if ( (kAbs(h1-h3)+kAbs(s1-s3)+kAbs(v1-v3) < kAbs(h2-h3)+kAbs(s2-s3)+kAbs(v2-v3)) && ((kAbs(h1-h3)+kAbs(s1-s3)+kAbs(v1-v3) < 32) || (s1 < 32)) && (s2 > s1)) color = inactiveTitle; else color = activeTitle; // limit max/min brightness int r, g, b; color.rgb(&r, &g, &b); int gray = qGray(r, g, b); if (gray > 180) { r = (r - (gray - 180) < 0 ? 0 : r - (gray - 180)); g = (g - (gray - 180) < 0 ? 0 : g - (gray - 180)); b = (b - (gray - 180) < 0 ? 0 : b - (gray - 180)); } else if (gray < 76) { r = (r + (76 - gray) > 255 ? 255 : r + (76 - gray)); g = (g + (76 - gray) > 255 ? 255 : g + (76 - gray)); b = (b + (76 - gray) > 255 ? 255 : b + (76 - gray)); } color.setRgb(r, g, b); return color; }
float kScreenUnitPerWorldUnitAtPos ( const KVector & pos ) { GLdouble ox, oy, xx, xy, yx, yy, zx, zy, z, model[16], proj[16]; GLint view[4]; GLdouble px = pos[X], py = pos[Y], pz = pos[Z]; glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetIntegerv(GL_VIEWPORT, (GLint*)view); gluProject(px, py, pz, model, proj, view, &ox, &oy, &z); gluProject(px + 1.0, py, pz, model, proj, view, &xx, &xy, &z); gluProject(px, py + 1.0, pz, model, proj, view, &yx, &yy, &z); gluProject(px, py, pz + 1.0, model, proj, view, &zx, &zy, &z); return (kMax(kMax(kAbs(xx-ox)+kAbs(xy-oy),kAbs(yx-ox)+kAbs(yy-oy)),kAbs(zx-ox)+kAbs(zy-oy))); }
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(); } } }