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

121 lines
2.9 KiB
C
Raw Normal View History

2014-11-16 19:58:43 +08:00
/*
Copyright © 2014-2019 by The qTox Project Contributors
2014-11-16 19:58:43 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2014-11-16 19:58:43 +08:00
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.
qTox is distributed in the hope that it will be useful,
2014-11-16 19:58:43 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-11-16 19:58:43 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-11-16 19:58:43 +08:00
*/
2014-11-12 21:11:25 +08:00
#ifndef CHATLINE_H
#define CHATLINE_H
2015-01-20 17:44:05 +08:00
#include <QPointF>
#include <QRectF>
#include <QVector>
#include <memory>
2014-11-12 21:11:25 +08:00
class ChatLog;
class ChatLineContent;
class QGraphicsScene;
class QStyleOptionGraphicsItem;
class QFont;
2014-11-12 21:11:25 +08:00
struct ColumnFormat
{
enum Policy
{
2014-11-12 21:11:25 +08:00
FixedSize,
VariableSize,
};
enum Align
{
2014-11-12 21:11:25 +08:00
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)
{
}
2014-11-12 21:11:25 +08:00
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();
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();
void selectionFocusChanged(bool focusIn);
void fontChanged(const QFont& font);
2019-02-21 21:53:31 +08:00
void reloadTheme();
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);
// comparators
2015-04-13 05:49:24 +08:00
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-02-01 00:50:35 +08:00
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;
QVector<ChatLineContent*> content;
QVector<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;
bool isVisible = false;
2014-11-12 21:11:25 +08:00
};
#endif // CHATLINE_H