added another level of unneeded abstraction

This commit is contained in:
fourtf
2017-02-02 22:15:09 +01:00
parent 93660233fd
commit c6c90d9f50
10 changed files with 330 additions and 237 deletions
+25
View File
@@ -8,12 +8,14 @@
#include <QFontDatabase>
#include <QPainter>
#include <QVBoxLayout>
#include <boost/signals2.hpp>
namespace chatterino {
namespace widgets {
ChatWidget::ChatWidget(QWidget *parent)
: QWidget(parent)
, messages()
, channel(Channels::getEmpty())
, channelName(QString())
, vbox(this)
@@ -52,12 +54,35 @@ ChatWidget::setChannelName(const QString &name)
if (!this->channelName.isEmpty()) {
Channels::removeChannel(this->channelName);
messageAppendedConnection.disconnect();
messageRemovedConnection.disconnect();
}
messages.clear();
if (channel.isEmpty()) {
this->channel = NULL;
} else {
this->channel = Channels::addChannel(channel);
messageAppendedConnection =
this->channel.get()->messageAppended.connect([this](
std::shared_ptr<messages::Message> &message) {
std::shared_ptr<messages::MessageRef> deleted;
auto messageRef = new messages::MessageRef(message);
this->messages.appendItem(
std::shared_ptr<messages::MessageRef>(messageRef), deleted);
});
messageRemovedConnection =
this->channel.get()->messageRemovedFromStart.connect(
[this](std::shared_ptr<messages::Message> &message) {});
}
this->view.layoutMessages();
+15
View File
@@ -2,7 +2,10 @@
#define CHATWIDGET_H
#include "channel.h"
#include "messages/limitedqueuesnapshot.h"
#include "messages/messageref.h"
#include "messages/word.h"
#include "messages/wordpart.h"
#include "widgets/chatwidgetheader.h"
#include "widgets/chatwidgetinput.h"
#include "widgets/chatwidgetview.h"
@@ -11,6 +14,7 @@
#include <QVBoxLayout>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
#include <boost/signals2/connection.hpp>
namespace chatterino {
namespace widgets {
@@ -45,10 +49,18 @@ public:
void showChangeChannelPopup();
messages::LimitedQueueSnapshot<std::shared_ptr<messages::MessageRef>>
getMessagesSnapshot()
{
return messages.getSnapshot();
}
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
private:
messages::LimitedQueue<std::shared_ptr<messages::MessageRef>> messages;
std::shared_ptr<Channel> channel;
QString channelName;
@@ -58,6 +70,9 @@ private:
ChatWidgetView view;
ChatWidgetInput input;
boost::signals2::connection messageAppendedConnection;
boost::signals2::connection messageRemovedConnection;
public:
void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save();
+10 -16
View File
@@ -37,17 +37,9 @@ ChatWidgetView::~ChatWidgetView()
bool
ChatWidgetView::layoutMessages()
{
auto c = this->chatWidget->getChannel();
if (c == NULL) {
this->scrollbar.hide();
return false;
}
bool showScrollbar = false;
auto messages = c->getMessageSnapshot();
auto messages = chatWidget->getMessagesSnapshot();
bool redraw = false;
@@ -99,7 +91,7 @@ ChatWidgetView::paintEvent(QPaintEvent *)
painter.setRenderHint(QPainter::SmoothPixmapTransform);
auto c = this->chatWidget->getChannel();
// auto c = this->chatWidget->getChannel();
QColor color;
@@ -137,10 +129,12 @@ ChatWidgetView::paintEvent(QPaintEvent *)
painter.fillRect(QRect(0, 9, 500, 2), QColor(0, 0, 0));*/
if (c == NULL)
return;
// if (c == NULL)
// return;
auto messages = c->getMessageSnapshot();
// auto messages = c->getMessageSnapshot();
auto messages = chatWidget->getMessagesSnapshot();
int start = this->scrollbar.getCurrentValue();
@@ -152,9 +146,9 @@ ChatWidgetView::paintEvent(QPaintEvent *)
(fmod(this->scrollbar.getCurrentValue(), 1)));
for (int i = start; i < messages.getLength(); ++i) {
messages::Message *message = messages[i].get();
messages::MessageRef *messageRef = messages[i].get();
for (messages::WordPart const &wordPart : message->getWordParts()) {
for (messages::WordPart const &wordPart : messageRef->getWordParts()) {
painter.setPen(QColor(255, 0, 0));
painter.drawRect(wordPart.getX(), wordPart.getY() + y,
wordPart.getWidth(), wordPart.getHeight());
@@ -188,7 +182,7 @@ ChatWidgetView::paintEvent(QPaintEvent *)
}
}
y += message->getHeight();
y += messageRef->getHeight();
if (y > height()) {
break;
+1
View File
@@ -2,6 +2,7 @@
#define CHATVIEW_H
#include "channel.h"
#include "messages/messageref.h"
#include "messages/word.h"
#include "widgets/scrollbar.h"