void RelinkingListView::drawStatusLayer(QPainter* painter) { QRect const drawing_rect(viewport()->rect()); QModelIndex top_index(this->indexAt(drawing_rect.topLeft())); if (!top_index.isValid()) { // No [visible] elements at all? return; } if (top_index.row() > 0) { // The appearence of any element actually depends on its neighbours, // so we start with the element above our topmost visible one. top_index = top_index.sibling(top_index.row() - 1, 0); } GroupAggregator group_aggregator; int const rows = top_index.model()->rowCount(top_index.parent()); for (int row = top_index.row(); row < rows; ++row) { QModelIndex const index(top_index.sibling(row, 0)); QRect const item_rect(visualRect(index)); QRect rect(drawing_rect); rect.setTop(item_rect.top()); rect.setBottom(item_rect.bottom()); rect.setWidth(item_rect.height()); rect.moveRight(drawing_rect.right()); int const status = index.data(RelinkingModel::UncommittedStatusRole).toInt(); group_aggregator.process(rect, status); if (row != top_index.row() && !item_rect.intersects(drawing_rect)) { // Note that we intentionally break *after* processing // the first invisible item. That's because the appearence // of its immediate predecessor depends on it. The topmost item // is allowed to be invisible, as it's processed for the same reason, // that is to make its immediate neighbour to display correctly. break; } } painter->setRenderHint(QPainter::Antialiasing); // Prepare for drawing existing items. QPen pen(QColor(0x3a5827)); pen.setWidthF(1.5); QBrush brush(QColor(0x89e74a)); // Draw existing, then missing items. for (int status = RelinkingModel::Exists, i = 0; i < 2; ++i) { painter->setPen(pen); painter->setBrush(brush); BOOST_FOREACH(IndicationGroup const& group, group_aggregator.groups()) { if (group.status == status) { qreal const radius = 0.5 * group.rect.width(); QRectF rect(group.rect); rect.adjust(pen.widthF(), pen.widthF(), -pen.widthF(), -pen.widthF()); painter->drawRoundedRect(rect, radius, radius); } } // Prepare for drawing missing items. status = RelinkingModel::Missing; pen.setColor(QColor(0x6f2719)); brush.setColor(QColor(0xff674b)); } }
string make_map( string map_src, int map_width, int map_height ) { mixed base_map; string map_str; int ix, iy; base_map = allocate( map_height + 2 ); for( iy = sizeof(base_map); iy--; ) base_map[iy] = allocate( map_width + 2 ); // Create the grid from the map_src for( iy = map_height + 2; iy--; ) for( ix = map_width + 2; ix--; ) if( iy == 0 || iy > map_height || ix == 0 || ix > map_width || map_src[(ix-1) + (iy-1) * map_width] != ' ' ) { base_map[iy][ix] = 1; } // else // msg("Clear base_map for ix="+ix+", iy="+iy); // Upper-left corner if( base_map[1][1] ) map_str = " "; else map_str = "."; // Top row for( ix = 1; ix <= map_width; ix++ ) map_str += bottom_row[bottom_index(ix, 0, base_map)]; // Upper-right corner if( base_map[1][map_width] ) map_str += " \n"; else map_str += ".\n"; // Loop through map rows for( iy = 1; iy <= map_height; iy++ ) { // Leftmost column, top row if( base_map[iy][1] ) map_str += base_map[iy-1][1]?" ":"'"; else map_str += "|"; // Top cell row, middle for( ix = 1; ix <= map_width; ix++ ) if( base_map[iy][ix] ) map_str += top_row[top_index(ix, iy, base_map)]; else map_str += " "; // Rightmost column, top row if( base_map[iy][map_width] ) map_str += base_map[iy-1][map_width]?" \n":"'\n"; else map_str += "|\n"; // Leftmost column, middle row if( base_map[iy][1] ) map_str += " "; else map_str += "|"; // Middle cell row, middle for( ix = 1; ix <= map_width; ix++ ) if( base_map[iy][ix] ) map_str += middle_row[middle_index(ix, iy, base_map)]; else map_str += " "; // Rightmost column, middle row if( base_map[iy][map_width] ) map_str += " \n"; else map_str += "|\n"; // Leftmost column, bottom row if( base_map[iy][1] ) map_str += base_map[iy+1][1]?" ":"."; else map_str += "|"; // Bottom cell row, middle for( ix = 1; ix <= map_width; ix++ ) if( base_map[iy][ix] ) map_str += bottom_row[bottom_index(ix, iy, base_map)]; else map_str += " "; // Rightmost column, top row if( base_map[iy][map_width] ) map_str += base_map[iy+1][map_width]?" \n":".\n"; else map_str += "|\n"; } // Bottom-left corner if( base_map[map_height][1] ) map_str += " "; else map_str += "'"; // Bottom row for( ix = 1; ix <= map_width; ix++ ) map_str += top_row[top_index(ix, map_height+1, base_map)]; // Bottom-right corner if( base_map[map_height][map_width] ) map_str += " \n"; else map_str += "'\n"; return map_str[..<2]; // Drop trailing \n }