_timestampItem->setPos(0,0);
_width = _height = 0;
+ _selection = 0;
}
ChatLine::~ChatLine() {
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;
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));
+ }
}
#include <QGraphicsItem>
-#include "messagemodel.h"
+#include "chatlinemodel.h"
class ChatItem;
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