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
@ -50,7 +50,8 @@ FeedView::FeedView(QWidget* parent):
|
||||
modelState(Models::MessageFeed::complete),
|
||||
progress(),
|
||||
dividerFont(),
|
||||
dividerMetrics(dividerFont)
|
||||
dividerMetrics(dividerFont),
|
||||
mousePressed(false)
|
||||
{
|
||||
horizontalScrollBar()->setRange(0, 0);
|
||||
verticalScrollBar()->setSingleStep(approximateSingleMessageHeight);
|
||||
@ -413,9 +414,35 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
|
||||
return;
|
||||
}
|
||||
|
||||
mousePressed = false;
|
||||
//qDebug() << event;
|
||||
|
||||
QAbstractItemView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void FeedView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QAbstractItemView::mousePressEvent(event);
|
||||
mousePressed = event->button() == Qt::LeftButton;
|
||||
}
|
||||
|
||||
void FeedView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
QAbstractItemView::mouseReleaseEvent(event);
|
||||
|
||||
if (mousePressed && specialDelegate) {
|
||||
QPoint point = event->localPos().toPoint();
|
||||
QModelIndex index = indexAt(point);
|
||||
if (index.isValid()) {
|
||||
QRect rect = visualRect(index);
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
if (rect.contains(point)) {
|
||||
del->leftClick(point, index, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QAbstractItemView::resizeEvent(event);
|
||||
|
@ -68,6 +68,8 @@ protected:
|
||||
void paintEvent(QPaintEvent * event) override;
|
||||
void updateGeometries() override;
|
||||
void mouseMoveEvent(QMouseEvent * event) override;
|
||||
void mousePressEvent(QMouseEvent * event) override;
|
||||
void mouseReleaseEvent(QMouseEvent * event) override;
|
||||
void resizeEvent(QResizeEvent * event) override;
|
||||
|
||||
private:
|
||||
@ -93,6 +95,7 @@ private:
|
||||
Progress progress;
|
||||
QFont dividerFont;
|
||||
QFontMetrics dividerMetrics;
|
||||
bool mousePressed;
|
||||
|
||||
static const std::set<int> geometryChangingRoles;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index) override;
|
||||
void endClearWidgets();
|
||||
void beginClearWidgets();
|
||||
void leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const;
|
||||
|
||||
static int avatarHeight;
|
||||
static int margin;
|
||||
|
Loading…
Reference in New Issue
Block a user