void Block::dispatchEvents() { if (!m_changed) return; mergeCompatibleStyles(); for (int i = 0; i < m_style_spans.size(); i++) { ensureStyleAlignWithLines(i); TextStyleSpan ¤t_style = m_style_spans[i]; if (current_style.text_segment == 0) { current_style.text_segment = m_screen->createTextSegment(current_style); current_style.text_segment->setLine(m_new_line, m_width, &m_text_line); } else if (m_new_line != m_line) { current_style.text_segment->setLine(m_new_line, m_width, &m_text_line); } if (current_style.style_dirty) { current_style.text_segment->setTextStyle(current_style); current_style.style_dirty = false; } if (current_style.index_dirty || current_style.text_dirty) { current_style.text_segment->setStringSegment(current_style.start_index, current_style.end_index, current_style.text_dirty); current_style.index_dirty = false; current_style.text_dirty = false; } current_style.text_segment->setLatin(m_only_latin); current_style.text_segment->dispatchEvents(); } m_changed = false; m_line = m_new_line; }
Block *Block::takeLine(int line) { if (line >= lineCount()) return nullptr; m_changed = true; Block *to_return = new Block(m_screen); int start_index = line * m_width; int end_index = start_index + (m_width - 1); for (int i = 0; i < m_style_list.size(); i++) { ensureStyleAlignWithLines(i); TextStyleLine ¤t_style = m_style_list[i]; if (current_style.start_index >= start_index && current_style.end_index <= end_index) { current_style.releaseTextSegment(m_screen); current_style.start_index -= start_index; current_style.end_index -= start_index; current_style.index_dirty = true; to_return->m_style_list.append(TextStyleLine(current_style, current_style.start_index, current_style.end_index)); m_style_list.remove(i); i--; } else if (current_style.start_index > end_index) { current_style.start_index -= (end_index + 1) - start_index; current_style.end_index -= (end_index + 1) - start_index; current_style.index_dirty = true; current_style.text_dirty = true; } } to_return->m_text_line = m_text_line.mid(start_index, m_width); m_text_line.remove(start_index, m_width); return to_return; }
Block *Block::split(int line) { if (line >= lineCount()) return nullptr; m_changed = true; Block *to_return = new Block(m_screen); int start_index = line * m_width; for (int i = 0; i < m_style_spans.size(); i++) { ensureStyleAlignWithLines(i); TextStyleSpan ¤t_style = m_style_spans[i]; if (current_style.start_index >= start_index) { current_style.start_index -= start_index; current_style.end_index -= start_index; current_style.index_dirty = true; current_style.text_dirty = true; current_style.index_dirty = true; to_return->m_style_spans.append(TextStyleSpan(current_style, current_style.start_index, current_style.end_index)); m_style_spans.remove(i); i--; } } to_return->m_text_line = m_text_line.mid(start_index, m_text_line.size() - start_index); m_text_line.remove(start_index, m_text_line.size() - start_index); return to_return; }
void Block::removeLine(int line) { if (line >= lineCount()) return; m_changed = true; int start_index = line * m_width; int end_index = start_index + (m_width - 1); for (int i = 0; i < m_style_list.size(); i++) { ensureStyleAlignWithLines(i); TextStyleLine ¤t_style = m_style_list[i]; if (current_style.start_index >= start_index && current_style.end_index <= end_index) { current_style.releaseTextSegment(m_screen); m_style_list.remove(i); i--; } else if (current_style.start_index > end_index) { current_style.start_index -= (end_index + 1) - start_index; current_style.end_index -= (end_index + 1) - start_index; current_style.index_dirty = true; current_style.text_dirty = true; } } m_text_line.remove(start_index, m_width); }