2017-01-01 02:30:42 +01:00
|
|
|
#include "chatwidgetview.h"
|
2017-01-11 01:08:20 +01:00
|
|
|
#include "word.h"
|
|
|
|
#include "wordpart.h"
|
|
|
|
#include "message.h"
|
|
|
|
|
|
|
|
#include <QScroller>
|
|
|
|
#include <QPainter>
|
2017-01-01 02:30:42 +01:00
|
|
|
|
|
|
|
ChatWidgetView::ChatWidgetView()
|
2017-01-03 21:19:33 +01:00
|
|
|
: QWidget(),
|
2017-01-05 16:07:20 +01:00
|
|
|
scrollbar(this),
|
|
|
|
m_channel(NULL)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2017-01-05 16:07:20 +01:00
|
|
|
auto scroll = QScroller::scroller(this);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
scroll->scrollTo(QPointF(0, 100));
|
|
|
|
|
|
|
|
m_channel = Channel::getChannel("ian678");
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
void ChatWidgetView::resizeEvent(QResizeEvent *)
|
|
|
|
{
|
|
|
|
scrollbar.resize(scrollbar.width(), height());
|
|
|
|
scrollbar.move(width() - scrollbar.width(), 0);
|
2017-01-11 01:08:20 +01:00
|
|
|
|
|
|
|
auto c = channel();
|
|
|
|
|
|
|
|
if (c == NULL) return;
|
|
|
|
|
|
|
|
auto messages = c->getMessagesClone();
|
|
|
|
|
|
|
|
for (std::shared_ptr<Message>& message : messages)
|
|
|
|
{
|
|
|
|
message.get()->layout(width(), true);
|
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
|
|
|
void ChatWidgetView::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
auto c = channel();
|
|
|
|
|
|
|
|
if (c == NULL) return;
|
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
auto messages = c->getMessagesClone();
|
|
|
|
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
for (std::shared_ptr<Message> const& message : messages)
|
|
|
|
{
|
|
|
|
for (WordPart const& wordPart : message.get()->wordParts())
|
|
|
|
{
|
|
|
|
// image
|
|
|
|
if (wordPart.word().isImage())
|
|
|
|
{
|
|
|
|
LazyLoadedImage& lli = wordPart.word().getImage();
|
|
|
|
|
|
|
|
const QImage* image = lli.image();
|
|
|
|
|
|
|
|
if (image != NULL)
|
|
|
|
{
|
|
|
|
painter.drawImage(QRect(wordPart.x(), wordPart.y() + y, wordPart.width(), wordPart.height()), *image);
|
|
|
|
}
|
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
// text
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.drawText(wordPart.x(), wordPart.y() + y, wordPart.getText());
|
|
|
|
}
|
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-01-11 01:08:20 +01:00
|
|
|
y += message.get()->height();
|
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|