forked from blue/squawk
seem to have found a text block, to activate with the click later
This commit is contained in:
parent
d86e2c28a0
commit
eac87e713f
4 changed files with 101 additions and 6 deletions
|
@ -22,7 +22,9 @@
|
|||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QAbstractItemView>
|
||||
#include <QtMath>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextBlock>
|
||||
#include <cmath>
|
||||
|
||||
#include "messagedelegate.h"
|
||||
#include "messagefeed.h"
|
||||
|
@ -303,7 +305,7 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
|
||||
QSizeF size = bodyRenderer->size();
|
||||
size.setWidth(bodyRenderer->idealWidth());
|
||||
messageSize = QSize(qCeil(size.width()), qCeil(size.height()));
|
||||
messageSize = QSize(std::ceil(size.width()), std::ceil(size.height()));
|
||||
messageSize.rheight() += textMargin;
|
||||
}
|
||||
|
||||
|
@ -364,6 +366,68 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
return messageSize;
|
||||
}
|
||||
|
||||
void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
|
||||
{
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
if (data.text.size() > 0) {
|
||||
QRect localHint = sizeHint.adjusted(bubbleMargin, bubbleMargin + margin, -bubbleMargin, -bubbleMargin / 2);
|
||||
if (needToDrawSender(index, data)) {
|
||||
localHint.adjust(0, nickMetrics.lineSpacing() + textMargin, 0, 0);
|
||||
}
|
||||
|
||||
int attachHeight = 0;
|
||||
switch (data.attach.state) {
|
||||
case Models::none:
|
||||
break;
|
||||
case Models::uploading:
|
||||
attachHeight += Preview::calculateAttachSize(Shared::resolvePath(data.attach.localPath), localHint).height() + textMargin;
|
||||
[[fallthrough]];
|
||||
case Models::downloading:
|
||||
attachHeight += barHeight + textMargin;
|
||||
break;
|
||||
case Models::remote:
|
||||
attachHeight += buttonHeight + textMargin;
|
||||
break;
|
||||
case Models::ready:
|
||||
case Models::local: {
|
||||
QSize aSize = Preview::calculateAttachSize(Shared::resolvePath(data.attach.localPath), localHint);
|
||||
attachHeight += aSize.height() + textMargin;
|
||||
}
|
||||
break;
|
||||
case Models::errorDownload: {
|
||||
QSize commentSize = dateMetrics.boundingRect(localHint, Qt::TextWordWrap, data.attach.error).size();
|
||||
attachHeight += commentSize.height() + buttonHeight + textMargin * 2;
|
||||
}
|
||||
break;
|
||||
case Models::errorUpload: {
|
||||
QSize aSize = Preview::calculateAttachSize(Shared::resolvePath(data.attach.localPath), localHint);
|
||||
QSize commentSize = dateMetrics.boundingRect(localHint, Qt::TextWordWrap, data.attach.error).size();
|
||||
attachHeight += aSize.height() + commentSize.height() + textMargin * 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
int bottomSize = std::max(dateMetrics.lineSpacing(), statusIconSize);
|
||||
localHint.adjust(0, attachHeight, 0, -(bottomSize + textMargin));
|
||||
|
||||
if (localHint.contains(point)) {
|
||||
qDebug() << "MESSAGE CLICKED";
|
||||
QPoint translated = point - localHint.topLeft();
|
||||
|
||||
bodyRenderer->setPlainText(data.text);
|
||||
bodyRenderer->setTextWidth(localHint.size().width());
|
||||
|
||||
int pos = bodyRenderer->documentLayout()->hitTest(translated, Qt::FuzzyHit);
|
||||
QTextBlock block = bodyRenderer->findBlock(pos);
|
||||
QString text = block.text();
|
||||
if (text.size() > 0) {
|
||||
qDebug() << text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDelegate::initializeFonts(const QFont& font)
|
||||
{
|
||||
bodyFont = font;
|
||||
|
@ -625,9 +689,9 @@ int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter,
|
|||
painter->translate(option.rect.topLeft());
|
||||
bodyRenderer->drawContents(painter);
|
||||
painter->restore();
|
||||
QSize bodySize(qCeil(bodyRenderer->idealWidth()), qCeil(bodyRenderer->size().height()));
|
||||
|
||||
QSize bodySize(std::ceil(bodyRenderer->idealWidth()), std::ceil(bodyRenderer->size().height()));
|
||||
|
||||
/*
|
||||
QTextBrowser* editor = nullptr;
|
||||
if (option.state.testFlag(QStyle::State_MouseOver)) {
|
||||
std::set<QString> ids({data.id});
|
||||
|
@ -645,7 +709,7 @@ int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter,
|
|||
editor->setMaximumSize(bodySize);
|
||||
editor->move(option.rect.left(), option.rect.y());
|
||||
editor->show();
|
||||
}
|
||||
}*/
|
||||
|
||||
option.rect.adjust(0, bodySize.height() + textMargin, 0, 0);
|
||||
return bodySize.width();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue