Since we have the cached wraplists back for the moment, we need to invalidate the caches
for all ChatLineModelItems before relayouting the scene. So instead of having each ChatView trigger
the layout change for his scene, we now inform the ChatLineModel itself, which invalidates its
items' caches and then emits a dataChanged() signal that is caught by the scenes.
***************************************************************************/
#include "chatlinemodel.h"
+#include "qtui.h"
+#include "qtuistyle.h"
ChatLineModel::ChatLineModel(QObject *parent)
: MessageModel(parent)
{
qRegisterMetaType<WrapList>("ChatLineModel::WrapList");
qRegisterMetaTypeStreamOperators<WrapList>("ChatLineModel::WrapList");
+
+ connect(QtUi::style(), SIGNAL(changed()), SLOT(styleChanged()));
}
// MessageModelItem *ChatLineModel::createMessageModelItem(const Message &msg) {
return msg;
}
+void ChatLineModel::styleChanged() {
+ foreach(ChatLineModelItem item, _messageList) {
+ item.invalidateWrapList();
+ }
+ emit dataChanged(index(0,0), index(rowCount()-1, columnCount()-1));
+}
+
QDataStream &operator<<(QDataStream &out, const ChatLineModel::WrapList wplist) {
out << wplist.count();
ChatLineModel::WrapList::const_iterator it = wplist.begin();
virtual inline void removeAllMessages() { _messageList.clear(); }
virtual Message takeMessageAt(int i);
+protected slots:
+ virtual void styleChanged();
+
private:
QList<ChatLineModelItem> _messageList;
};
virtual inline Message::Type msgType() const { return _styledMsg.type(); }
virtual inline Message::Flags msgFlags() const { return _styledMsg.flags(); }
+ virtual inline void invalidateWrapList() { _wrapList.clear(); }
+
/// Used to store information about words to be used for wrapping
struct Word {
quint16 start;
this, SLOT(rowsInserted(const QModelIndex &, int, int)));
connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
this, SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int)));
+ connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex)));
if(model->rowCount() > 0)
rowsInserted(QModelIndex(), 0, model->rowCount() - 1);
updateSceneRect();
}
+void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) {
+ // This should only be sent (currently) if the style is reloaded -> re-layout the whole scene
+ // TODO: Check range and only do partial relayouts, if appropriate
+
+ layout();
+}
+
void ChatScene::updateForViewport(qreal width, qreal height) {
_viewportHeight = height;
setWidth(width);
protected slots:
void rowsInserted(const QModelIndex &, int, int);
void rowsAboutToBeRemoved(const QModelIndex &, int, int);
+ void dataChanged(const QModelIndex &, const QModelIndex &);
private slots:
void firstHandlePositionChanged(qreal xpos);
setScene(_scene);
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
- connect(QtUi::style(), SIGNAL(changed()), this, SLOT(styleChanged()));
}
bool ChatView::event(QEvent *event) {
vbar->setValue(vbar->maximum());
}
-void ChatView::styleChanged() {
- scene()->layout();
-}
-
MsgId ChatView::lastMsgId() const {
if(!scene())
return MsgId();
void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
void mouseMoveWhileSelecting(const QPointF &scenePos);
void scrollTimerTimeout();
- void styleChanged();
private:
void init(MessageFilter *filter);