mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-12 16:15:43 -04:00
Moved RSTextBrowser::checkImage to ImageUtil for use in MimeTextEdit
This commit is contained in:
parent
44bb2c0f05
commit
7b28bf5256
7 changed files with 121 additions and 67 deletions
|
@ -23,6 +23,8 @@
|
|||
#include "util/rstime.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QByteArray>
|
||||
#include <QImage>
|
||||
#include <QClipboard>
|
||||
|
@ -39,6 +41,64 @@
|
|||
|
||||
ImageUtil::ImageUtil() {}
|
||||
|
||||
bool ImageUtil::checkImage(const QTextEdit *edit, const QPoint &pos, QRect *cursorRectStartOut, QRect *cursorRectLeftOut, QRect *cursorRectRightOut, QRect *cursorRectEndOut)
|
||||
{
|
||||
QString imageStr;
|
||||
return checkImage(edit, pos, imageStr, cursorRectStartOut, cursorRectLeftOut, cursorRectRightOut, cursorRectEndOut);
|
||||
}
|
||||
|
||||
bool ImageUtil::checkImage(const QTextEdit *edit, const QPoint &pos, QString &imageStr, QRect *cursorRectStartOut, QRect *cursorRectLeftOut, QRect *cursorRectRightOut, QRect *cursorRectEndOut)
|
||||
{
|
||||
//Get text cursor under pos. But if pos is under text browser end line this return last cursor.
|
||||
QTextCursor cursor = edit->cursorForPosition(pos);
|
||||
//First get rect of cursor (could be at left or right of image)
|
||||
QRect cursorRectStart = edit->cursorRect(cursor);
|
||||
//Second get text
|
||||
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);//To get character just before
|
||||
QRect cursorRectLeft = edit->cursorRect(cursor);
|
||||
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
|
||||
QRect cursorRectRight = edit->cursorRect(cursor);
|
||||
imageStr = cursor.selection().toHtml();
|
||||
|
||||
if (cursorRectStartOut) {
|
||||
*cursorRectStartOut = cursorRectStart;
|
||||
}
|
||||
if (cursorRectLeftOut) {
|
||||
*cursorRectLeftOut = cursorRectLeft;
|
||||
}
|
||||
if (cursorRectRightOut) {
|
||||
*cursorRectRightOut = cursorRectRight;
|
||||
}
|
||||
|
||||
QRect cursorRectEnd = cursorRectStart;
|
||||
//Finally set left with right of precedent character.
|
||||
if (cursorRectEnd.top() < cursorRectLeft.bottom())
|
||||
{
|
||||
cursorRectEnd.setLeft(cursorRectLeft.right());
|
||||
} else {
|
||||
//Image on new line
|
||||
cursorRectEnd.setLeft(0);
|
||||
}
|
||||
//And set Right with left of next character.
|
||||
if (cursorRectEnd.bottom() > cursorRectRight.top())
|
||||
{
|
||||
cursorRectEnd.setRight(cursorRectRight.left());
|
||||
} else {
|
||||
//New line after Image.
|
||||
}
|
||||
|
||||
if (cursorRectEndOut) {
|
||||
*cursorRectEndOut = cursorRectEnd;
|
||||
}
|
||||
|
||||
//If pos is on text rect
|
||||
if (cursorRectEnd.contains(pos))
|
||||
{
|
||||
return imageStr.indexOf("base64,") != -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImageUtil::extractImage(QWidget *window, QTextCursor cursor, QString file)
|
||||
{
|
||||
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue