1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/chatlog/chatline.h

111 lines
2.6 KiB
C
Raw Normal View History

2014-11-16 19:58:43 +08:00
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
2014-11-12 21:11:25 +08:00
#ifndef CHATLINE_H
#define CHATLINE_H
2015-01-04 20:29:14 +08:00
#include <QMouseEvent>
#include <memory>
#include <vector>
2014-11-12 21:11:25 +08:00
class ChatLog;
class ChatLineContent;
class QGraphicsScene;
class QStyleOptionGraphicsItem;
struct ColumnFormat
{
enum Policy {
FixedSize,
VariableSize,
};
enum Align {
Left,
Center,
Right,
};
ColumnFormat() {}
2014-12-09 05:08:23 +08:00
ColumnFormat(qreal s, Policy p, Align halign = Left)
2014-11-12 21:11:25 +08:00
: size(s)
, policy(p)
, hAlign(halign)
{}
qreal size = 1.0;
Policy policy = VariableSize;
Align hAlign = Left;
};
using ColumnFormats = QVector<ColumnFormat>;
class ChatLine
{
public:
2015-01-04 20:29:14 +08:00
using Ptr = std::shared_ptr<ChatLine>;
2015-01-05 01:21:35 +08:00
explicit ChatLine();
2014-11-12 21:11:25 +08:00
virtual ~ChatLine();
virtual QRectF boundingSceneRect() const;
2014-11-12 23:45:24 +08:00
void replaceContent(int col, ChatLineContent* lineContent);
2014-11-12 21:11:25 +08:00
void layout(qreal width, QPointF scenePos);
2015-01-05 21:06:14 +08:00
void moveBy(qreal deltaY);
2014-11-12 21:11:25 +08:00
void selectionCleared();
void selectionCleared(int col);
int getColumnCount();
int getRowIndex() const;
2014-12-14 04:11:03 +08:00
ChatLineContent* getContent(int col) const;
2015-01-07 00:47:57 +08:00
ChatLineContent* getContent(QPointF scenePos) const;
2014-11-12 21:11:25 +08:00
bool isOverSelection(QPointF scenePos);
2015-01-04 20:29:14 +08:00
void removeFromScene();
2015-01-05 01:21:35 +08:00
void addToScene(QGraphicsScene* scene);
2015-01-04 20:29:14 +08:00
2015-01-10 18:57:46 +08:00
void setVisible(bool visible);
2015-01-05 01:21:35 +08:00
protected:
2014-11-12 21:11:25 +08:00
QPointF mapToContent(ChatLineContent* c, QPointF pos);
2015-01-05 01:21:35 +08:00
void addColumn(ChatLineContent* item, ColumnFormat fmt);
2014-11-12 21:11:25 +08:00
void updateBBox();
friend class ChatLog;
void setRowIndex(int idx);
void visibilityChanged(bool visible);
//comparators
static bool lessThanBSRectTop(const ChatLine::Ptr lhs, const qreal rhs);
static bool lessThanBSRectBottom(const ChatLine::Ptr lhs, const qreal rhs);
static bool lessThanRowIndex(const ChatLine::Ptr lhs, const ChatLine::Ptr rhs);
2014-11-12 21:11:25 +08:00
private:
int rowIndex = -1;
std::vector<ChatLineContent*> content; // 3 columns
std::vector<ColumnFormat> format;
2014-11-12 21:11:25 +08:00
qreal width;
QRectF bbox;
bool isVisible = false;
};
#endif // CHATLINE_H