From: Manuel Nickschas Date: Wed, 30 Jul 2008 22:56:22 +0000 (+0200) Subject: Add selection (and highlight) display to ChatLine X-Git-Tag: 0.3.0~146 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=65c657b9339661b5ba31f132c914873f4a9093ae Add selection (and highlight) display to ChatLine --- diff --git a/src/qtui/chatline.cpp b/src/qtui/chatline.cpp index 237fad68..6e4982a4 100644 --- a/src/qtui/chatline.cpp +++ b/src/qtui/chatline.cpp @@ -34,6 +34,7 @@ ChatLine::ChatLine(const QModelIndex &index, QGraphicsItem *parent) : QGraphicsI _timestampItem->setPos(0,0); _width = _height = 0; + _selection = 0; } ChatLine::~ChatLine() { @@ -47,6 +48,15 @@ QRectF ChatLine::boundingRect () const { return QRectF(0, 0, _width, _height); } +ChatItem *ChatLine::item(ChatLineModel::ColumnType column) const { + switch(column) { + case ChatLineModel::TimestampColumn: return _timestampItem; + case ChatLineModel::SenderColumn: return _senderItem; + case ChatLineModel::ContentsColumn: return _contentsItem; + default: return 0; + } +} + qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandlePos) { if(width != _width) prepareGeometryChange(); qreal firstsep = QtUi::style()->firstColumnSeparator()/2; @@ -63,6 +73,32 @@ qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandl return _height; } -void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { +void ChatLine::setSelected(bool selected, ChatLineModel::ColumnType minColumn) { + if(selected) { + _selection = (_selection & 0x80) | 0x40 | minColumn; + for(int i = 0; i < minColumn; i++) item((ChatLineModel::ColumnType)i)->clearSelection(); + for(int i = minColumn; i <= ChatLineModel::ContentsColumn; i++) item((ChatLineModel::ColumnType)i)->setFullSelection(); + } + else { + _selection &= 0x80; + for(int i = 0; i <= ChatLineModel::ContentsColumn; i++) item((ChatLineModel::ColumnType)i)->clearSelection(); + } + update(); +} +void ChatLine::setHighlighted(bool highlighted) { + if(highlighted) _selection |= 0x80; + else _selection &= 0x7f; + update(); +} + +void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + if(_selection & Highlighted) { + painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor())); + } + if(_selection & Selected) { + qreal left = item((ChatLineModel::ColumnType)(_selection & 0x3f))->x(); + QRectF selectRect(left, 0, width() - left, height()); + painter->fillRect(selectRect, QApplication::palette().brush(QPalette::Highlight)); + } } diff --git a/src/qtui/chatline.h b/src/qtui/chatline.h index c7ac49b7..3649c549 100644 --- a/src/qtui/chatline.h +++ b/src/qtui/chatline.h @@ -23,7 +23,7 @@ #include -#include "messagemodel.h" +#include "chatlinemodel.h" class ChatItem; @@ -34,23 +34,25 @@ class ChatLine : public QGraphicsItem { virtual ~ChatLine(); virtual QRectF boundingRect () const; - inline int width() const { return _width; } - inline int height() const { return _height; } + inline qreal width() const { return _width; } + inline qreal height() const { return _height; } + ChatItem *item(ChatLineModel::ColumnType) const; virtual void paint (QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - //void layout(); // returns height qreal setGeometry(qreal width, qreal firstColPos, qreal secondColPos); - - //void myMousePressEvent ( QGraphicsSceneMouseEvent * event ) { qDebug() << "press"; mousePressEvent(event); } + void setSelected(bool selected, ChatLineModel::ColumnType minColumn = ChatLineModel::ContentsColumn); + void setHighlighted(bool highlighted); protected: - //bool sceneEvent ( QEvent * event ); private: ChatItem *_timestampItem, *_senderItem, *_contentsItem; - int _width, _height; + qreal _width, _height; + + enum { Selected = 0x40, Highlighted = 0x80 }; + quint8 _selection; // save space, so we put both the col and the flags into one byte }; #endif