* We should always use qreal for scene coordinates
* Provide a few convenience methods
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ //virtual bool handleClick(ClickMode mode);
+
inline QTextLayout *layout() const;
virtual QTextLayout::FormatRange selectionFormat() const;
inline QTextLayout *layout() const;
virtual QTextLayout::FormatRange selectionFormat() const;
showOwnNicksAction->setCheckable(true);
showOwnNicksAction->setChecked(_filter->showOwnMessages());
showOwnNicksAction->setCheckable(true);
showOwnNicksAction->setChecked(_filter->showOwnMessages());
- if(scene()->sectionByScenePos(event->pos()) == ChatLineModel::SenderColumn) {
+ if(scene()->columnByScenePos(event->pos()) == ChatLineModel::SenderColumn) {
contextMenu.addSeparator();
QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
contextMenu.addSeparator();
QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
}
void ChatMonitorView::mouseDoubleClickEvent(QMouseEvent *event) {
}
void ChatMonitorView::mouseDoubleClickEvent(QMouseEvent *event) {
- if(scene()->sectionByScenePos(event->pos()) != ChatLineModel::SenderColumn) {
+ if(scene()->columnByScenePos(event->pos()) != ChatLineModel::SenderColumn) {
ChatView::mouseDoubleClickEvent(event);
return;
}
ChatView::mouseDoubleClickEvent(event);
return;
}
ChatScene::~ChatScene() {
}
ChatScene::~ChatScene() {
}
+bool ChatScene::containsBuffer(const BufferId &id) const {
+ MessageFilter *filter = qobject_cast<MessageFilter*>(model());
+ if(filter)
+ return filter->containsBuffer(id);
+ else
+ return false;
+}
+
void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
Q_UNUSED(index);
void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
Q_UNUSED(index);
}
void ChatScene::updateSelection(const QPointF &pos) {
}
void ChatScene::updateSelection(const QPointF &pos) {
- // This is somewhat hacky... we look at the contents item that is at the cursor's y position (ignoring x), since
- // it has the full height. From this item, we can then determine the row index and hence the ChatLine.
- ChatItem *contentItem = static_cast<ChatItem *>(itemAt(QPointF(_secondColHandle->sceneRight() + 1, pos.y())));
- if(!contentItem) return;
-
- int curRow = contentItem->row();
- int curColumn;
- if(pos.x() > _secondColHandle->sceneRight()) curColumn = ChatLineModel::ContentsColumn;
- else if(pos.x() > _firstColHandlePos) curColumn = ChatLineModel::SenderColumn;
- else curColumn = ChatLineModel::TimestampColumn;
-
+ int curRow = rowByScenePos(pos);
+ if(curRow < 0) return;
+ int curColumn = (int)columnByScenePos(pos);
ChatLineModel::ColumnType minColumn = (ChatLineModel::ColumnType)qMin(curColumn, _selectionStartCol);
if(minColumn != _selectionMinCol) {
_selectionMinCol = minColumn;
ChatLineModel::ColumnType minColumn = (ChatLineModel::ColumnType)qMin(curColumn, _selectionStartCol);
if(minColumn != _selectionMinCol) {
_selectionMinCol = minColumn;
-int ChatScene::sectionByScenePos(int x) {
+ChatLineModel::ColumnType ChatScene::columnByScenePos(qreal x) {
if(x < _firstColHandle->x())
return ChatLineModel::TimestampColumn;
if(x < _secondColHandle->x())
if(x < _firstColHandle->x())
return ChatLineModel::TimestampColumn;
if(x < _secondColHandle->x())
return ChatLineModel::ContentsColumn;
}
return ChatLineModel::ContentsColumn;
}
+int ChatScene::rowByScenePos(qreal y) {
+ // This is somewhat hacky... we look at the contents item that is at the given y position, since
+ // it has the full height. From this item, we can then determine the row index and hence the ChatLine.
+ // ChatItems cover their ChatLine, so we won't get to the latter directly.
+ ChatItem *contentItem = static_cast<ChatItem *>(itemAt(QPointF(_secondColHandle->sceneRight() + 1, y)));
+ if(!contentItem) return -1;
+ return contentItem->row();
+}
+
void ChatScene::updateSceneRect(qreal width) {
if(_lines.isEmpty()) {
updateSceneRect(QRectF(0, 0, width, 0));
void ChatScene::updateSceneRect(qreal width) {
if(_lines.isEmpty()) {
updateSceneRect(QRectF(0, 0, width, 0));
#include <QAbstractItemModel>
#include <QGraphicsScene>
#include <QSet>
#include <QAbstractItemModel>
#include <QGraphicsScene>
#include <QSet>
+#include "chatlinemodel.h"
#include "columnhandleitem.h"
#include "messagefilter.h"
#include "columnhandleitem.h"
#include "messagefilter.h"
+ enum ClickMode {
+ NoClick,
+ SingleClick,
+ DoubleClick,
+ TripleClick
+ };
+
ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, QObject *parent);
virtual ~ChatScene();
inline QAbstractItemModel *model() const { return _model; }
inline QString idString() const { return _idString; }
ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, QObject *parent);
virtual ~ChatScene();
inline QAbstractItemModel *model() const { return _model; }
inline QString idString() const { return _idString; }
- int sectionByScenePos(int x);
- inline int sectionByScenePos(const QPoint &pos) { return sectionByScenePos(pos.x()); }
+ int rowByScenePos(qreal y);
+ inline int rowByScenePos(const QPointF &pos) { return rowByScenePos(pos.y()); }
+ ChatLineModel::ColumnType columnByScenePos(qreal x);
+ inline ChatLineModel::ColumnType columnByScenePos(const QPointF &pos) { return columnByScenePos(pos.x()); }
inline bool isSingleBufferScene() const { return _singleBufferScene; }
inline bool isSingleBufferScene() const { return _singleBufferScene; }
- inline bool containsBuffer(const BufferId &id) const;
+ bool containsBuffer(const BufferId &id) const;
inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
inline ColumnHandleItem *firstColumnHandle() const { return _firstColHandle; }
inline ChatLine *chatLine(int row) { return (row < _lines.count()) ? _lines[row] : 0; }
inline ColumnHandleItem *firstColumnHandle() const { return _firstColHandle; }
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
+ //virtual bool handleLeftClick(ClickMode mode);
protected slots:
void rowsInserted(const QModelIndex &, int, int);
protected slots:
void rowsInserted(const QModelIndex &, int, int);
struct WebPreview {
ChatItem *parentItem;
QGraphicsItem *previewItem;
struct WebPreview {
ChatItem *parentItem;
QGraphicsItem *previewItem;
WebPreview webPreview;
};
WebPreview webPreview;
};
-bool ChatScene::containsBuffer(const BufferId &id) const {
- MessageFilter *filter = qobject_cast<MessageFilter*>(model());
- if(filter)
- return filter->containsBuffer(id);
- else
- return false;
-}
-
_scrollTimer.setSingleShot(true);
connect(&_scrollTimer, SIGNAL(timeout()), SLOT(scrollTimerTimeout()));
_scrollTimer.setSingleShot(true);
connect(&_scrollTimer, SIGNAL(timeout()), SLOT(scrollTimerTimeout()));
- _scene = new ChatScene(filter, filter->idString(), viewport()->width() - 2, this); // see below: resizeEvent()
+ _scene = new ChatScene(filter, filter->idString(), viewport()->width() - 4, this); // see below: resizeEvent()
connect(_scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &)));
connect(_scene, SIGNAL(lastLineChanged(QGraphicsItem *, qreal)), this, SLOT(lastLineChanged(QGraphicsItem *, qreal)));
connect(_scene, SIGNAL(mouseMoveWhileSelecting(const QPointF &)), this, SLOT(mouseMoveWhileSelecting(const QPointF &)));
connect(_scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &)));
connect(_scene, SIGNAL(lastLineChanged(QGraphicsItem *, qreal)), this, SLOT(lastLineChanged(QGraphicsItem *, qreal)));
connect(_scene, SIGNAL(mouseMoveWhileSelecting(const QPointF &)), this, SLOT(mouseMoveWhileSelecting(const QPointF &)));