2014-11-16 19:58:43 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project
|
|
|
|
|
2014-11-16 19:58:43 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
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
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-11-16 19:58:43 +08:00
|
|
|
|
2015-06-06 09:40:08 +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 CHATLOG_H
|
|
|
|
#define CHATLOG_H
|
|
|
|
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QDateTime>
|
2015-02-15 18:53:26 +08:00
|
|
|
#include <QMargins>
|
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-20 17:44:05 +08:00
|
|
|
class QMouseEvent;
|
2015-01-04 22:18:23 +08:00
|
|
|
class QTimer;
|
2014-11-12 21:11:25 +08:00
|
|
|
class ChatLineContent;
|
2015-02-15 19:15:46 +08:00
|
|
|
struct ToxFile;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
class ChatLog : public QGraphicsView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ChatLog(QWidget* parent = 0);
|
2015-02-08 17:11:55 +08:00
|
|
|
virtual ~ChatLog();
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2015-01-05 02:28:27 +08:00
|
|
|
void insertChatlineAtBottom(ChatLine::Ptr l);
|
|
|
|
void insertChatlineOnTop(ChatLine::Ptr l);
|
2015-01-05 17:51:01 +08:00
|
|
|
void insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines);
|
2014-11-12 21:11:25 +08:00
|
|
|
void clearSelection();
|
|
|
|
void clear();
|
2015-02-08 17:32:52 +08:00
|
|
|
void copySelectedText(bool toSelectionBuffer = false) const;
|
2015-01-25 21:06:06 +08:00
|
|
|
void setBusyNotification(ChatLine::Ptr notification);
|
2015-01-10 18:57:46 +08:00
|
|
|
void setTypingNotification(ChatLine::Ptr notification);
|
|
|
|
void setTypingNotificationVisible(bool visible);
|
2015-01-25 21:06:06 +08:00
|
|
|
void scrollToLine(ChatLine::Ptr line);
|
2015-01-27 02:32:33 +08:00
|
|
|
void selectAll();
|
2015-02-15 18:43:01 +08:00
|
|
|
void forceRelayout();
|
2015-01-27 02:32:33 +08:00
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
QString getSelectedText() const;
|
|
|
|
|
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
|
|
|
|
2015-01-10 18:57:46 +08:00
|
|
|
ChatLine::Ptr getTypingNotification() const;
|
2015-01-25 21:34:36 +08:00
|
|
|
QVector<ChatLine::Ptr> getLines();
|
2015-06-24 02:58:30 +08:00
|
|
|
ChatLine::Ptr getLatestLine() const;
|
2015-03-26 05:31:39 +08:00
|
|
|
// repetition interval sender name (sec)
|
|
|
|
const uint repNameAfter = 5*60;
|
2015-01-10 18:57:46 +08:00
|
|
|
|
2015-02-11 23:32:42 +08:00
|
|
|
signals:
|
|
|
|
void selectionChanged();
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
protected:
|
2015-01-14 18:27:52 +08:00
|
|
|
QRectF calculateSceneRect() const;
|
2014-11-12 21:11:25 +08:00
|
|
|
QRect getVisibleRect() const;
|
|
|
|
ChatLineContent* getContentFromPos(QPointF scenePos) const;
|
|
|
|
|
2015-01-25 21:06:06 +08:00
|
|
|
void layout(int start, int end, qreal width);
|
2015-01-14 06:59:38 +08:00
|
|
|
bool isOverSelection(QPointF scenePos) const;
|
|
|
|
bool stickToBottom() const;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2015-01-14 06:59:38 +08:00
|
|
|
qreal useableWidth() const;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2015-01-05 21:06:14 +08:00
|
|
|
void reposition(int start, int end, qreal deltaY);
|
2014-11-12 21:11:25 +08:00
|
|
|
void updateSceneRect();
|
|
|
|
void checkVisibility();
|
|
|
|
void scrollToBottom();
|
2015-01-25 21:06:06 +08:00
|
|
|
void startResizeWorker();
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2015-06-09 02:08:24 +08:00
|
|
|
virtual void mouseDoubleClickEvent(QMouseEvent* ev) final override;
|
|
|
|
virtual void mousePressEvent(QMouseEvent* ev) final override;
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent* ev) final override;
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent* ev) final override;
|
|
|
|
virtual void scrollContentsBy(int dx, int dy) final override;
|
|
|
|
virtual void resizeEvent(QResizeEvent* ev) final override;
|
|
|
|
virtual void showEvent(QShowEvent*) final override;
|
|
|
|
virtual void focusInEvent(QFocusEvent* ev) final override;
|
|
|
|
virtual void focusOutEvent(QFocusEvent* ev) final override;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2014-12-10 04:47:25 +08:00
|
|
|
void updateMultiSelectionRect();
|
2015-01-10 18:57:46 +08:00
|
|
|
void updateTypingNotification();
|
2015-01-25 21:06:06 +08:00
|
|
|
void updateBusyNotification();
|
2014-12-10 04:47:25 +08:00
|
|
|
|
2015-01-15 18:48:41 +08:00
|
|
|
ChatLine::Ptr findLineByPosY(qreal yPos) const;
|
2015-01-15 02:43:52 +08:00
|
|
|
|
2015-01-04 22:18:23 +08:00
|
|
|
private slots:
|
|
|
|
void onSelectionTimerTimeout();
|
2015-01-25 21:06:06 +08:00
|
|
|
void onWorkerTimeout();
|
2015-01-04 22:18:23 +08:00
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
private:
|
|
|
|
void retranslateUi();
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2015-02-03 01:11:29 +08:00
|
|
|
QAction* copyAction = nullptr;
|
2015-06-06 03:37:01 +08:00
|
|
|
QAction* selectAllAction = nullptr;
|
2014-11-12 21:11:25 +08:00
|
|
|
QGraphicsScene* scene = nullptr;
|
2015-01-25 21:06:06 +08:00
|
|
|
QGraphicsScene* busyScene = nullptr;
|
2015-01-07 20:05:28 +08:00
|
|
|
QVector<ChatLine::Ptr> lines;
|
2015-01-04 20:29:14 +08:00
|
|
|
QList<ChatLine::Ptr> visibleLines;
|
2015-01-10 18:57:46 +08:00
|
|
|
ChatLine::Ptr typingNotification;
|
2015-01-25 21:06:06 +08:00
|
|
|
ChatLine::Ptr busyNotification;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
// selection
|
2015-01-15 02:43:52 +08:00
|
|
|
int selClickedRow = -1; //These 4 are only valid while selectionMode != None
|
2014-12-09 20:17:08 +08:00
|
|
|
int selClickedCol = -1;
|
|
|
|
int selFirstRow = -1;
|
2014-11-12 21:11:25 +08:00
|
|
|
int selLastRow = -1;
|
2015-02-03 17:33:46 +08:00
|
|
|
QColor selectionRectColor = QColor::fromRgbF(0.23, 0.68, 0.91).lighter(150);
|
2014-12-09 20:17:08 +08:00
|
|
|
SelectionMode selectionMode = None;
|
2014-11-12 21:11:25 +08:00
|
|
|
QPointF clickPos;
|
2014-12-09 20:17:08 +08:00
|
|
|
QGraphicsRectItem* selGraphItem = nullptr;
|
2015-01-04 22:18:23 +08:00
|
|
|
QTimer* selectionTimer = nullptr;
|
2015-01-07 22:03:02 +08:00
|
|
|
QTimer* workerTimer = nullptr;
|
2015-01-04 22:18:23 +08:00
|
|
|
AutoScrollDirection selectionScrollDir = NoDirection;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2015-01-14 17:56:44 +08:00
|
|
|
//worker vars
|
|
|
|
int workerLastIndex = 0;
|
|
|
|
bool workerStb = false;
|
2015-01-25 21:06:06 +08:00
|
|
|
ChatLine::Ptr workerAnchorLine;
|
2015-01-07 22:03:02 +08:00
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
// layout
|
2015-02-15 17:19:38 +08:00
|
|
|
QMargins margins = QMargins(10,10,10,10);
|
2015-01-05 21:06:14 +08:00
|
|
|
qreal lineSpacing = 5.0f;
|
2014-11-12 21:11:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CHATLOG_H
|