void ChatAreaWidget::mouseReleaseEvent(QMouseEvent * event) { QTextEdit::mouseReleaseEvent(event); QPointF documentHitPost(event->pos().x() + horizontalScrollBar()->value(), event->pos().y() + verticalScrollBar()->value()); int pos = this->document()->documentLayout()->hitTest(documentHitPost, Qt::ExactHit); if (pos > 0) { QTextCursor cursor(document()); cursor.setPosition(pos); if(!cursor.atEnd()) { cursor.setPosition(pos+1); QTextFormat format = cursor.charFormat(); if (format.isImageFormat()) { QString imageName = format.toImageFormat().name(); if (QRegExp("^data:ftrans.*").exactMatch(imageName)) { QString data = imageName.right(imageName.length() - 12); int endpos = data.indexOf("/png;base64"); data = data.left(endpos); int middlepos = data.indexOf("."); QString widgetID = data.left(middlepos); QString widgetBtn = data.right(data.length() - middlepos - 1); qDebug() << "ChatAreaWidget::mouseReleaseEvent:" << widgetID << widgetBtn; emit onFileTranfertInterract(widgetID, widgetBtn); } } } } }
QSizeF QTextImageHandler::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) { Q_UNUSED(posInDocument) const QTextImageFormat imageFormat = format.toImageFormat(); if (qApp->thread() != QThread::currentThread()) return getImageSize(doc, imageFormat); return getPixmapSize(doc, imageFormat); }
void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) { Q_UNUSED(posInDocument) const QTextImageFormat imageFormat = format.toImageFormat(); if (qApp->thread() != QThread::currentThread()) { const QImage image = getImage(doc, imageFormat); p->drawImage(rect, image, image.rect()); } else { const QPixmap pixmap = getPixmap(doc, imageFormat); p->drawPixmap(rect, pixmap, pixmap.rect()); } }