X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatline.cpp;fp=src%2Fqtui%2Fchatline.cpp;h=d0f39066528de19db698bbffe1edc02a6de49a15;hp=2c3cda571e30b6b759bd43c623fc0d540170f672;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/qtui/chatline.cpp b/src/qtui/chatline.cpp index 2c3cda57..d0f39066 100644 --- a/src/qtui/chatline.cpp +++ b/src/qtui/chatline.cpp @@ -18,6 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "chatline.h" + #include #include #include @@ -25,10 +27,9 @@ #include "bufferinfo.h" #include "buffersyncer.h" -#include "client.h" #include "chatitem.h" -#include "chatline.h" #include "chatview.h" +#include "client.h" #include "columnhandleitem.h" #include "messagemodel.h" #include "networkmodel.h" @@ -36,22 +37,27 @@ #include "qtuisettings.h" #include "qtuistyle.h" -ChatLine::ChatLine(int row, QAbstractItemModel *model, - const qreal &width, - const qreal ×tampWidth, const qreal &senderWidth, const qreal &contentsWidth, - const QPointF &senderPos, const QPointF &contentsPos, - QGraphicsItem *parent) - : QGraphicsItem(parent), - _row(row), // needs to be set before the items - _model(model), - _contentsItem(contentsPos, contentsWidth, this), - _senderItem(QRectF(senderPos, QSizeF(senderWidth, _contentsItem.height())), this), - _timestampItem(QRectF(0, 0, timestampWidth, _contentsItem.height()), this), - _width(width), - _height(_contentsItem.height()), - _selection(0), - _mouseGrabberItem(nullptr), - _hoverItem(nullptr) +ChatLine::ChatLine(int row, + QAbstractItemModel* model, + const qreal& width, + const qreal& timestampWidth, + const qreal& senderWidth, + const qreal& contentsWidth, + const QPointF& senderPos, + const QPointF& contentsPos, + QGraphicsItem* parent) + : QGraphicsItem(parent) + , _row(row) + , // needs to be set before the items + _model(model) + , _contentsItem(contentsPos, contentsWidth, this) + , _senderItem(QRectF(senderPos, QSizeF(senderWidth, _contentsItem.height())), this) + , _timestampItem(QRectF(0, 0, timestampWidth, _contentsItem.height()), this) + , _width(width) + , _height(_contentsItem.height()) + , _selection(0) + , _mouseGrabberItem(nullptr) + , _hoverItem(nullptr) { Q_ASSERT(model); QModelIndex index = model->index(row, ChatLineModel::ContentsColumn); @@ -60,15 +66,13 @@ ChatLine::ChatLine(int row, QAbstractItemModel *model, setHighlighted(index.data(MessageModel::FlagsRole).toInt() & Message::Highlight); } - ChatLine::~ChatLine() { if (chatView()) chatView()->setHasCache(this, false); } - -ChatItem *ChatLine::item(ChatLineModel::ColumnType column) +ChatItem* ChatLine::item(ChatLineModel::ColumnType column) { switch (column) { case ChatLineModel::TimestampColumn: @@ -82,8 +86,7 @@ ChatItem *ChatLine::item(ChatLineModel::ColumnType column) } } - -ChatItem *ChatLine::itemAt(const QPointF &pos) +ChatItem* ChatLine::itemAt(const QPointF& pos) { if (_contentsItem.boundingRect().contains(pos)) return &_contentsItem; @@ -94,7 +97,6 @@ ChatItem *ChatLine::itemAt(const QPointF &pos) return nullptr; } - void ChatLine::clearCache() { _timestampItem.clearCache(); @@ -102,18 +104,16 @@ void ChatLine::clearCache() _contentsItem.clearCache(); } - -void ChatLine::setMouseGrabberItem(ChatItem *item) +void ChatLine::setMouseGrabberItem(ChatItem* item) { _mouseGrabberItem = item; } - -bool ChatLine::sceneEvent(QEvent *event) +bool ChatLine::sceneEvent(QEvent* event) { if (event->type() == QEvent::GrabMouse) { // get mouse cursor pos relative to us - ChatView *view = chatScene()->chatView(); + ChatView* view = chatScene()->chatView(); QPointF linePos = mapFromScene(view->mapToScene(view->mapFromGlobal(QCursor::pos()))); setMouseGrabberItem(itemAt(linePos)); } @@ -123,16 +123,14 @@ bool ChatLine::sceneEvent(QEvent *event) return QGraphicsItem::sceneEvent(event); } - -void ChatLine::setFirstColumn(const qreal ×tampWidth, const qreal &senderWidth, const QPointF &senderPos) +void ChatLine::setFirstColumn(const qreal& timestampWidth, const qreal& senderWidth, const QPointF& senderPos) { _timestampItem.setGeometry(timestampWidth, _height); _senderItem.setGeometry(senderWidth, _height); _senderItem.setPos(senderPos); } - -void ChatLine::setSecondColumn(const qreal &senderWidth, const qreal &contentsWidth, const QPointF &contentsPos, qreal &linePos) +void ChatLine::setSecondColumn(const qreal& senderWidth, const qreal& contentsWidth, const QPointF& contentsPos, qreal& linePos) { // linepos is the *bottom* position for the line qreal height = _contentsItem.setGeometryByWidth(contentsWidth); @@ -151,8 +149,7 @@ void ChatLine::setSecondColumn(const qreal &senderWidth, const qreal &contentsWi setPos(0, linePos); } - -void ChatLine::setGeometryByWidth(const qreal &width, const qreal &contentsWidth, qreal &linePos) +void ChatLine::setGeometryByWidth(const qreal& width, const qreal& contentsWidth, qreal& linePos) { // linepos is the *bottom* position for the line qreal height = _contentsItem.setGeometryByWidth(contentsWidth); @@ -170,10 +167,9 @@ void ChatLine::setGeometryByWidth(const qreal &width, const qreal &contentsWidth _width = width; } - setPos(0, linePos); // set pos is _very_ cheap if nothing changes. + setPos(0, linePos); // set pos is _very_ cheap if nothing changes. } - void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) { if (selected) { @@ -198,21 +194,21 @@ void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) } } - void ChatLine::setHighlighted(bool highlighted) { - if (highlighted) _selection |= Highlighted; - else _selection &= ~Highlighted; + if (highlighted) + _selection |= Highlighted; + else + _selection &= ~Highlighted; update(); } - -void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void ChatLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); - const QAbstractItemModel *model_ = model(); + const QAbstractItemModel* model_ = model(); QModelIndex myIdx = model_->index(row(), 0); Message::Type type = (Message::Type)myIdx.data(MessageModel::TypeRole).toInt(); auto label = myIdx.data(ChatLineModel::MsgLabelRole).value(); @@ -238,52 +234,46 @@ void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, contentsItem()->paint(painter, option, widget); } - // We need to dispatch all mouse-related events to the appropriate (mouse grabbing) ChatItem -ChatItem *ChatLine::mouseEventTargetItem(const QPointF &pos) +ChatItem* ChatLine::mouseEventTargetItem(const QPointF& pos) { if (mouseGrabberItem()) return mouseGrabberItem(); return itemAt(pos); } - -void ChatLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void ChatLine::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { - ChatItem *item = mouseEventTargetItem(event->pos()); + ChatItem* item = mouseEventTargetItem(event->pos()); if (item) item->mouseMoveEvent(event); } - -void ChatLine::mousePressEvent(QGraphicsSceneMouseEvent *event) +void ChatLine::mousePressEvent(QGraphicsSceneMouseEvent* event) { - ChatItem *item = mouseEventTargetItem(event->pos()); + ChatItem* item = mouseEventTargetItem(event->pos()); if (item) item->mousePressEvent(event); } - -void ChatLine::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void ChatLine::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { - ChatItem *item = mouseEventTargetItem(event->pos()); + ChatItem* item = mouseEventTargetItem(event->pos()); if (item) item->mouseReleaseEvent(event); } - -void ChatLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +void ChatLine::hoverEnterEvent(QGraphicsSceneHoverEvent* event) { - ChatItem *item = mouseEventTargetItem(event->pos()); + ChatItem* item = mouseEventTargetItem(event->pos()); if (item && !_hoverItem) { _hoverItem = item; item->hoverEnterEvent(event); } } - -void ChatLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +void ChatLine::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) { if (_hoverItem) { _hoverItem->hoverLeaveEvent(event); @@ -291,10 +281,9 @@ void ChatLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) } } - -void ChatLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void ChatLine::hoverMoveEvent(QGraphicsSceneHoverEvent* event) { - ChatItem *item = mouseEventTargetItem(event->pos()); + ChatItem* item = mouseEventTargetItem(event->pos()); if (item) item->hoverMoveEvent(event); }