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 CHATLOG_H
|
|
|
|
#define CHATLOG_H
|
|
|
|
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QDateTime>
|
2014-12-10 04:47:25 +08:00
|
|
|
#include <QMarginsF>
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2015-01-04 20:29:14 +08:00
|
|
|
#include "chatline.h"
|
|
|
|
#include "chatmessage.h"
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
class QGraphicsScene;
|
2014-12-09 20:17:08 +08:00
|
|
|
class QGraphicsRectItem;
|
2015-01-04 22:18:23 +08:00
|
|
|
class QTimer;
|
2014-11-12 21:11:25 +08:00
|
|
|
class ChatLineContent;
|
2014-11-17 03:01:37 +08:00
|
|
|
class ToxFile;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
class ChatLog : public QGraphicsView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ChatLog(QWidget* parent = 0);
|
|
|
|
virtual ~ChatLog();
|
|
|
|
|
2015-01-04 20:29:14 +08:00
|
|
|
void insertChatline(ChatLine::Ptr l);
|
2014-11-12 21:11:25 +08:00
|
|
|
void clearSelection();
|
|
|
|
void clear();
|
|
|
|
void copySelectedText() const;
|
|
|
|
QString getSelectedText() const;
|
2015-01-02 19:04:04 +08:00
|
|
|
QString toPlainText() const;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2014-12-14 04:11:03 +08:00
|
|
|
bool isEmpty() const;
|
2015-01-04 21:21:05 +08:00
|
|
|
bool hasTextToBeCopied() const;
|
2014-12-14 04:11:03 +08:00
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
protected:
|
|
|
|
QRect getVisibleRect() const;
|
|
|
|
ChatLineContent* getContentFromPos(QPointF scenePos) const;
|
|
|
|
|
|
|
|
bool layout(int start, int end, qreal width);
|
|
|
|
bool isOverSelection(QPointF scenePos);
|
|
|
|
bool stickToBottom();
|
|
|
|
|
2014-12-10 04:47:25 +08:00
|
|
|
qreal useableWidth();
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
void reposition(int start, int end);
|
|
|
|
void repositionDownTo(int start, qreal end);
|
|
|
|
void updateSceneRect();
|
|
|
|
void partialUpdate();
|
|
|
|
void fullUpdate();
|
|
|
|
void checkVisibility();
|
|
|
|
void scrollToBottom();
|
|
|
|
|
|
|
|
virtual void mousePressEvent(QMouseEvent* ev);
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent* ev);
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent* ev);
|
|
|
|
virtual void scrollContentsBy(int dx, int dy);
|
|
|
|
virtual void resizeEvent(QResizeEvent *ev);
|
|
|
|
|
2014-12-10 04:47:25 +08:00
|
|
|
void updateMultiSelectionRect();
|
|
|
|
|
2015-01-04 22:18:23 +08:00
|
|
|
private slots:
|
|
|
|
void onSelectionTimerTimeout();
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
private:
|
2014-12-09 20:17:08 +08:00
|
|
|
enum SelectionMode {
|
|
|
|
None,
|
|
|
|
Precise,
|
|
|
|
Multi,
|
|
|
|
};
|
|
|
|
|
2015-01-04 22:18:23 +08:00
|
|
|
enum AutoScrollDirection {
|
|
|
|
NoDirection,
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
};
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
QGraphicsScene* scene = nullptr;
|
2015-01-04 20:29:14 +08:00
|
|
|
QList<ChatLine::Ptr> lines;
|
|
|
|
QList<ChatLine::Ptr> visibleLines;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
bool multiLineInsert = false;
|
|
|
|
bool stickToBtm = false;
|
|
|
|
int insertStartIndex = -1;
|
|
|
|
|
|
|
|
// selection
|
2014-12-09 20:17:08 +08:00
|
|
|
int selClickedRow = -1;
|
|
|
|
int selClickedCol = -1;
|
|
|
|
int selFirstRow = -1;
|
2014-11-12 21:11:25 +08:00
|
|
|
int selLastRow = -1;
|
2014-12-09 20:17:08 +08:00
|
|
|
SelectionMode selectionMode = None;
|
2014-11-12 21:11:25 +08:00
|
|
|
QPointF clickPos;
|
|
|
|
QPointF lastPos;
|
2014-12-09 20:17:08 +08:00
|
|
|
QGraphicsRectItem* selGraphItem = nullptr;
|
2015-01-04 22:18:23 +08:00
|
|
|
QTimer* selectionTimer = nullptr;
|
|
|
|
AutoScrollDirection selectionScrollDir = NoDirection;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
// actions
|
|
|
|
QAction* copyAction = nullptr;
|
|
|
|
|
|
|
|
// layout
|
2014-12-10 04:47:25 +08:00
|
|
|
QMarginsF margins = QMarginsF(10.0,10.0,10.0,10.0);
|
2014-11-12 21:11:25 +08:00
|
|
|
qreal lineSpacing = 10.0f;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CHATLOG_H
|