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 <memory>
|
2015-01-06 22:10:37 +08:00
|
|
|
#include <vector>
|
2015-01-20 17:44:05 +08:00
|
|
|
#include <QPointF>
|
|
|
|
#include <QRectF>
|
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-20 17:44:05 +08:00
|
|
|
ChatLine();
|
2014-11-12 21:11:25 +08:00
|
|
|
virtual ~ChatLine();
|
|
|
|
|
2015-02-01 00:49:19 +08:00
|
|
|
QRectF sceneBoundingRect() const;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
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);
|
2015-01-20 17:44:05 +08:00
|
|
|
void removeFromScene();
|
|
|
|
void addToScene(QGraphicsScene* scene);
|
|
|
|
void setVisible(bool visible);
|
2014-11-12 21:11:25 +08:00
|
|
|
void selectionCleared();
|
2015-02-03 17:33:46 +08:00
|
|
|
void selectionFocusChanged(bool focusIn);
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
int getColumnCount();
|
2015-01-20 17:31:50 +08:00
|
|
|
int getRow() const;
|
2015-01-20 17:44:05 +08:00
|
|
|
|
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-02-01 00:50:35 +08:00
|
|
|
//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);
|
|
|
|
|
2015-01-05 01:21:35 +08:00
|
|
|
protected:
|
2015-01-20 17:44:05 +08:00
|
|
|
friend class ChatLog;
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
QPointF mapToContent(ChatLineContent* c, QPointF pos);
|
2015-01-20 17:44:05 +08:00
|
|
|
|
2015-01-05 01:21:35 +08:00
|
|
|
void addColumn(ChatLineContent* item, ColumnFormat fmt);
|
2014-11-12 21:11:25 +08:00
|
|
|
void updateBBox();
|
2015-01-20 17:31:50 +08:00
|
|
|
void setRow(int idx);
|
2014-11-12 21:11:25 +08:00
|
|
|
void visibilityChanged(bool visible);
|
|
|
|
|
|
|
|
private:
|
2015-01-20 17:31:50 +08:00
|
|
|
int row = -1;
|
2015-01-20 17:44:05 +08:00
|
|
|
std::vector<ChatLineContent*> content;
|
2015-01-06 22:10:37 +08:00
|
|
|
std::vector<ColumnFormat> format;
|
2015-01-20 17:44:05 +08:00
|
|
|
qreal width = 100.0;
|
2015-01-20 18:51:34 +08:00
|
|
|
qreal columnSpacing = 15.0;
|
2014-11-12 21:11:25 +08:00
|
|
|
QRectF bbox;
|
2015-02-01 01:12:51 +08:00
|
|
|
bool isVisible = false;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CHATLINE_H
|