static int position_vectorto(lua_State* l) { CelxLua celx(l); celx.checkArgs(2, 2, "One argument expected to position:vectorto"); UniversalCoord* uc = this_position(l); UniversalCoord* uc2 = to_position(l, 2); if (uc2 == NULL) { celx.doError("Argument to position:vectorto must be a position"); } celx.newVector(*uc2 - *uc); return 1; }
static int position_addvector(lua_State* l) { CelxLua celx(l); celx.checkArgs(2, 2, "One argument expected to position:addvector()"); UniversalCoord* uc = this_position(l); Vec3d* v3d = celx.toVector(2); if (v3d == NULL) { celx.doError("Vector expected as argument to position:addvector"); } else if (uc != NULL && v3d != NULL) { UniversalCoord ucnew = *uc + *v3d; position_new(l, ucnew); } return 1; }
static int position_set(lua_State* l) { CelxLua celx(l); celx.checkArgs(3, 3, "Invalid access of position-component"); UniversalCoord* uc = this_position(l); string key = celx.safeGetString(2, AllErrors, "Invalid key in position-access"); double value = celx.safeGetNumber(3, AllErrors, "Position components must be numbers"); if (key == "x") uc->x = value; else if (key == "y") uc->y = value; else if (key == "z") uc->z = value; else { celx.doError("Invalid key in position-access"); } return 0; }
void GroupedIconView::LayoutItems() { if (!model()) return; const int count = model()->rowCount(); QString last_group; QPoint next_position(0, 0); int max_row_height = 0; visual_rects_.clear(); visual_rects_.reserve(count); headers_.clear(); for (int i=0 ; i<count ; ++i) { const QModelIndex index(model()->index(i, 0)); const QString group = index.data(Role_Group).toString(); const QSize size(rectForIndex(index).size()); // Is this the first item in a new group? if (group != last_group) { // Add the group header. Header header; header.y = next_position.y() + max_row_height + header_indent_; header.first_row = i; header.text = group; if (!last_group.isNull()) { header.y += header_spacing_; } headers_ << header; // Remember this group so we don't add it again. last_group = group; // Move the next item immediately below the header. next_position.setX(0); next_position.setY(header.y + header_height() + header_indent_ + header_spacing_); max_row_height = 0; } // Take into account padding and spacing QPoint this_position(next_position); if (this_position.x() == 0) { this_position.setX(this_position.x() + item_indent_); } else { this_position.setX(this_position.x() + spacing()); } // Should this item wrap? if (next_position.x() != 0 && this_position.x() + size.width() >= viewport()->width()) { next_position.setX(0); next_position.setY(next_position.y() + max_row_height); this_position = next_position; this_position.setX(this_position.x() + item_indent_); max_row_height = 0; } // Set this item's geometry visual_rects_.append(QRect(this_position, size)); // Update next index next_position.setX(this_position.x() + size.width()); max_row_height = qMax(max_row_height, size.height()); } verticalScrollBar()->setRange(0, next_position.y() + max_row_height - viewport()->height()); update(); }