void RowPainter::paint(Painter &p, const FakeRow *row, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) { auto item = row->item(); auto history = item->history(); paintRow(p, row, history, item, nullptr, item->date, fullWidth, active, selected, onlyBackground, ms, [&p, row, active, selected](int nameleft, int namewidth, HistoryItem *item) { int lastWidth = namewidth, texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip; item->drawInDialog(p, QRect(nameleft, texttop, lastWidth, st::dialogsTextFont->height), active, selected, row->_cacheFor, row->_cache); }, [] { }); }
void Renderer::drawContourData(const Output* output) { // Render E4Q before E3T QVector<Element::Type> typesToRender; typesToRender.append(Element::ENP); typesToRender.append(Element::E4Q); typesToRender.append(Element::E3T); typesToRender.append(Element::E2L); QVectorIterator<Element::Type> it(typesToRender); while(it.hasNext()) { Element::Type elemTypeToRender = it.next(); const Mesh::Elements& elems = mMesh->elements(); for(int i = 0; i < elems.count(); i++){ const Element& elem = elems[i]; if( elem.eType() != elemTypeToRender ) continue; if( elem.isDummy() ) continue; // For each element // If the element's activity flag is off, ignore it if( ! output->isActive(i) ){ continue; } // If the element is outside the view of the canvas, skip it if( elemOutsideView(i) ){ continue; } const BBox& bbox = mMesh->projectedBBox(i); // Get the BBox of the element in pixels int topLim, bottomLim, leftLim, rightLim; bbox2rect(bbox, leftLim, rightLim, topLim, bottomLim); for(int j=topLim; j<=bottomLim; j++) { paintRow(i, j, leftLim, rightLim, output); } } // for all elements } // for element types }
void CensusVisualizerView::paintEvent(QPaintEvent *event) { if (!visualizer->model()) return; QFontMetricsF fm(font()); const int RowHeight = fm.height() + ExtraHeight; const int MinY = qMax(0, event->rect().y() - RowHeight); const int MaxY = MinY + event->rect().height() + RowHeight; QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing| QPainter::TextAntialiasing); int row = MinY / RowHeight; int y = row * RowHeight; for (; row < visualizer->model()->rowCount(); ++row) { paintRow(&painter, row, y, RowHeight); y += RowHeight; if (y > MaxY) break; } }
void KPrTimeLineView::paintEvent(QPaintEvent *event) { if (!m_mainView->model()) { return; } const int rowHeight = m_mainView->rowsHeight(); const int minY = qMax(0, event->rect().y() - rowHeight); const int maxY = minY + event->rect().height() + rowHeight; QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); int row = minY / rowHeight; int y = row * rowHeight; int rowCount = m_mainView->rowCount(); for (; row < rowCount; ++row) { paintRow(&painter, row, y, rowHeight); y += rowHeight; if (y > maxY) { break; } } }
void RowPainter::paint(Painter &p, const Row *row, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) { auto history = row->history(); auto item = history->lastMsg; auto cloudDraft = history->cloudDraft(); if (Data::draftIsNull(cloudDraft)) { cloudDraft = nullptr; } auto displayDate = [item, cloudDraft]() { if (item) { if (cloudDraft) { return (item->date > cloudDraft->date) ? item->date : cloudDraft->date; } return item->date; } return cloudDraft ? cloudDraft->date : QDateTime(); }; int unreadCount = history->unreadCount(); if (history->peer->migrateFrom()) { if (auto migrated = App::historyLoaded(history->peer->migrateFrom()->id)) { unreadCount += migrated->unreadCount(); } } if (item && cloudDraft && unreadCount > 0) { cloudDraft = nullptr; // Draw item, if draft is older. } paintRow(p, row, history, item, cloudDraft, displayDate(), fullWidth, active, selected, onlyBackground, ms, [&p, fullWidth, active, selected, ms, history, unreadCount](int nameleft, int namewidth, HistoryItem *item) { int availableWidth = namewidth; int texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip; if (unreadCount) { auto counter = QString::number(unreadCount); auto mutedCounter = history->mute(); auto unreadRight = fullWidth - st::dialogsPadding.x(); auto unreadTop = texttop + st::dialogsTextFont->ascent - st::dialogsUnreadFont->ascent - (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2; auto unreadWidth = 0; UnreadBadgeStyle st; st.active = active; st.muted = history->mute(); paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth); availableWidth -= unreadWidth + st.padding; } else if (history->isPinnedDialog()) { auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon)); icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth); availableWidth -= icon.width() + st::dialogsUnreadPadding; } auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService); if (!history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) { item->drawInDialog(p, QRect(nameleft, texttop, availableWidth, st::dialogsTextFont->height), active, selected, history->textCachedFor, history->lastItemTextCache); } }, [&p, fullWidth, active, selected, ms, history, unreadCount] { if (unreadCount) { auto counter = QString::number(unreadCount); if (counter.size() > 4) { counter = qsl("..") + counter.mid(counter.size() - 3); } auto mutedCounter = history->mute(); auto unreadRight = st::dialogsPadding.x() + st::dialogsPhotoSize; auto unreadTop = st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight; auto unreadWidth = 0; UnreadBadgeStyle st; st.active = active; st.muted = history->mute(); paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth); } }); }
void HeatmapView::paintEvent(QPaintEvent *) { if (!m_data) { return; } QPainter painter(this); painter.fillRect(0, m_data->headerRows() * m_rowHeight, width(), height(), Qt::white); /* Draw data rows */ painter.translate(0, m_data->headerRows() * m_rowHeight - m_viewBottom % m_rowHeight); int rowStart = m_viewBottom / m_rowHeight; int rowEnd = qMin<int>(qCeil(m_viewTop / (double)m_rowHeight), m_data->dataRows()); for (unsigned i = rowStart; i < rowEnd; ++i) { HeatmapRowIterator* itr = m_data->dataRowIterator(i, m_viewLeft, m_viewRight, width()); paintRow(painter, itr); painter.translate(0, m_rowHeight); delete itr; } /* Draw Header */ painter.resetTransform(); painter.fillRect(0, 0, width(), m_data->headerRows() * m_rowHeight, Qt::white); for (unsigned i = 0; i < m_data->headerRows(); ++i) { HeatmapRowIterator* itr = m_data->headerRowIterator(i, m_viewLeft, m_viewRight, width()); paintRow(painter, itr); painter.translate(0, m_rowHeight); delete itr; } /* Draw Axis Lines */ painter.resetTransform(); painter.setPen(Qt::black); painter.drawLine(0, m_rowHeight, width(), m_rowHeight); painter.drawLine(0, m_rowHeight * 2, width(), m_rowHeight * 2); painter.setPen(QColor(240, 240, 240)); painter.translate(0, m_data->headerRows() * m_rowHeight - m_viewBottom % m_rowHeight); for (unsigned i = rowStart; i < rowEnd; ++i) { painter.drawLine(0, m_rowHeight, width(), m_rowHeight); painter.translate(0, m_rowHeight); } /* Draw selection borders */ painter.resetTransform(); painter.setPen(Qt::green); if (m_selectionState->type == SelectionState::Horizontal) { double dxdt = width() / (double)m_viewWidth; double scroll = m_viewLeft * dxdt; double left = (m_selectionState->start * dxdt) - scroll; double right = (m_selectionState->end * dxdt) - scroll; /* Highlight time */ if (left >= 0 && left <= width()) { painter.drawLine(left, 0, left, height()); } if (right >= 0 && right <= width()) { painter.drawLine(right, 0, right, height()); } } else if (m_selectionState->type == SelectionState::Vertical) { /* Highlight row */ int row = m_selectionState->start; for (unsigned i = rowStart; i < rowEnd; ++i) { if (m_data->dataRowAt(i) == row) { row = i - rowStart; painter.translate(0, m_data->headerRows() * m_rowHeight - m_viewBottom % m_rowHeight); painter.drawLine(0, (row + 1) * m_rowHeight, width(), (row + 1) * m_rowHeight); if (row > 0) { painter.drawLine(0, row * m_rowHeight, width(), row * m_rowHeight); } break; } } } }