void LensItem::updateEffect() { LensItem *item; for (int a = 0; a < dialog->origPathItem.count(); a++) { QGraphicsPathItem* pItem = dialog->origPathItem[a]; QPainterPath path = dialog->origPath[a]; path = pItem->mapToScene(path); for (int b = 0; b < dialog->lensList.count(); b++) { item = dialog->lensList[b]; path = lensDeform(path, item->mapToScene(item->rect().center()), item->rect().width() / 2.0, item->strength / 100.0); } path = pItem->mapFromScene(path); pItem->setPath(path); } }
void PathDeformRenderer::paint(QPainter *painter) { int pad_x = 5; int pad_y = 5; int skip_x = qRound(m_pathBounds.width() + pad_x + m_fontSize/2); int skip_y = qRound(m_pathBounds.height() + pad_y); painter->setPen(Qt::NoPen); painter->setBrush(Qt::black); QRectF clip(painter->clipPath().boundingRect()); int overlap = pad_x / 2; for (int start_y=0; start_y < height(); start_y += skip_y) { if (start_y > clip.bottom()) break; int start_x = -overlap; for (; start_x < width(); start_x += skip_x) { if (start_y + skip_y >= clip.top() && start_x + skip_x >= clip.left() && start_x <= clip.right()) { for (int i=0; i<m_paths.size(); ++i) { QPainterPath path = lensDeform(m_paths[i], QPointF(start_x, start_y)); painter->drawPath(path); } } } overlap = skip_x - (start_x - width()); } if (preferImage()) { painter->drawImage(m_pos - QPointF(m_radius + LENS_EXTENT, m_radius + LENS_EXTENT), m_lens_image); } else { painter->drawPixmap(m_pos - QPointF(m_radius + LENS_EXTENT, m_radius + LENS_EXTENT), m_lens_pixmap); } }