mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactoring
This commit is contained in:
parent
5399b40874
commit
4f01f5ec0e
@ -140,8 +140,6 @@ void ChatLine::addColumn(ChatLineContent* item, ColumnFormat fmt)
|
|||||||
if(!item)
|
if(!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
item->setChatLine(this);
|
|
||||||
|
|
||||||
format << fmt;
|
format << fmt;
|
||||||
content << item;
|
content << item;
|
||||||
}
|
}
|
||||||
@ -239,14 +237,13 @@ void ChatLine::layout(qreal w, QPointF scenePos)
|
|||||||
updateBBox();
|
updateBBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLine::layout(QPointF scenePos)
|
void ChatLine::moveBy(qreal deltaY)
|
||||||
{
|
{
|
||||||
// reposition only
|
// reposition only
|
||||||
QPointF offset = pos - scenePos;
|
|
||||||
for(ChatLineContent* c : content)
|
for(ChatLineContent* c : content)
|
||||||
c->setPos(c->pos() - offset);
|
c->moveBy(0, deltaY);
|
||||||
|
|
||||||
pos = scenePos;
|
pos.setY(pos.y() + deltaY);
|
||||||
|
|
||||||
updateBBox();
|
updateBBox();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
void replaceContent(int col, ChatLineContent* lineContent);
|
void replaceContent(int col, ChatLineContent* lineContent);
|
||||||
|
|
||||||
void layout(qreal width, QPointF scenePos);
|
void layout(qreal width, QPointF scenePos);
|
||||||
void layout(QPointF scenePos);
|
void moveBy(qreal deltaY);
|
||||||
|
|
||||||
void selectionCleared();
|
void selectionCleared();
|
||||||
void selectionCleared(int col);
|
void selectionCleared(int col);
|
||||||
|
@ -16,16 +16,6 @@
|
|||||||
|
|
||||||
#include "chatlinecontent.h"
|
#include "chatlinecontent.h"
|
||||||
|
|
||||||
void ChatLineContent::setChatLine(ChatLine* chatline)
|
|
||||||
{
|
|
||||||
line = chatline;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatLine* ChatLineContent::getChatLine() const
|
|
||||||
{
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatLineContent::setIndex(int r, int c)
|
void ChatLineContent::setIndex(int r, int c)
|
||||||
{
|
{
|
||||||
row = r;
|
row = r;
|
||||||
|
@ -29,8 +29,6 @@ public:
|
|||||||
ChatLineContentType = QGraphicsItem::UserType + 1,
|
ChatLineContentType = QGraphicsItem::UserType + 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatLine* getChatLine() const;
|
|
||||||
|
|
||||||
int getColumn() const;
|
int getColumn() const;
|
||||||
int getRow() const;
|
int getRow() const;
|
||||||
|
|
||||||
@ -56,12 +54,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ChatLine;
|
friend class ChatLine;
|
||||||
|
|
||||||
void setIndex(int row, int col);
|
void setIndex(int row, int col);
|
||||||
void setChatLine(ChatLine* chatline);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChatLine* line = nullptr;
|
|
||||||
int row = -1;
|
int row = -1;
|
||||||
int col = -1;
|
int col = -1;
|
||||||
};
|
};
|
||||||
|
@ -126,10 +126,6 @@ qreal ChatLog::layout(int start, int end, qreal width)
|
|||||||
h += l->boundingSceneRect().height() + lineSpacing;
|
h += l->boundingSceneRect().height() + lineSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
// move up
|
|
||||||
if(deltaRepos != 0)
|
|
||||||
reposition(end-1, lines.size());
|
|
||||||
|
|
||||||
return deltaRepos;
|
return deltaRepos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +146,7 @@ void ChatLog::partialUpdate()
|
|||||||
if(!visibleLines.empty())
|
if(!visibleLines.empty())
|
||||||
{
|
{
|
||||||
repos = layout(visibleLines.first()->getRowIndex(), visibleLines.last()->getRowIndex(), useableWidth());
|
repos = layout(visibleLines.first()->getRowIndex(), visibleLines.last()->getRowIndex(), useableWidth());
|
||||||
|
reposition(visibleLines.last()->getRowIndex()+1, lines.size(), -repos);
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->value() - repos);
|
verticalScrollBar()->setValue(verticalScrollBar()->value() - repos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,9 +154,6 @@ void ChatLog::partialUpdate()
|
|||||||
}
|
}
|
||||||
while(repos != 0);
|
while(repos != 0);
|
||||||
|
|
||||||
if(!visibleLines.empty())
|
|
||||||
reposition(visibleLines.last()->getRowIndex(), lines.size());
|
|
||||||
|
|
||||||
checkVisibility();
|
checkVisibility();
|
||||||
|
|
||||||
setViewportUpdateMode(oldUpdateMode);
|
setViewportUpdateMode(oldUpdateMode);
|
||||||
@ -318,7 +312,7 @@ qreal ChatLog::useableWidth()
|
|||||||
return width() - verticalScrollBar()->sizeHint().width() - margins.right() - margins.left();
|
return width() - verticalScrollBar()->sizeHint().width() - margins.right() - margins.left();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLog::reposition(int start, int end)
|
void ChatLog::reposition(int start, int end, qreal deltaY)
|
||||||
{
|
{
|
||||||
if(lines.isEmpty())
|
if(lines.isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -326,33 +320,10 @@ void ChatLog::reposition(int start, int end)
|
|||||||
start = clamp<int>(start, 0, lines.size() - 1);
|
start = clamp<int>(start, 0, lines.size() - 1);
|
||||||
end = clamp<int>(end + 1, 0, lines.size());
|
end = clamp<int>(end + 1, 0, lines.size());
|
||||||
|
|
||||||
qreal h = lines[start]->boundingSceneRect().bottom() + lineSpacing;
|
for(int i = start; i < end; ++i)
|
||||||
|
|
||||||
for(int i = start + 1; i < end; ++i)
|
|
||||||
{
|
{
|
||||||
ChatLine* l = lines[i].get();
|
ChatLine* l = lines[i].get();
|
||||||
l->layout(QPointF(0, h));
|
l->moveBy(deltaY);
|
||||||
h += l->boundingSceneRect().height() + lineSpacing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatLog::repositionDownTo(int start, qreal end)
|
|
||||||
{
|
|
||||||
if(lines.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
start = clamp<int>(start, 0, lines.size() - 1);
|
|
||||||
|
|
||||||
qreal h = lines[start]->boundingSceneRect().bottom() + lineSpacing;
|
|
||||||
|
|
||||||
for(int i = start + 1; i < lines.size(); ++i)
|
|
||||||
{
|
|
||||||
ChatLine* l = lines[i].get();
|
|
||||||
l->layout(QPointF(0, h));
|
|
||||||
h += l->boundingSceneRect().height() + lineSpacing;
|
|
||||||
|
|
||||||
if(h > end)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,7 @@ protected:
|
|||||||
|
|
||||||
qreal useableWidth();
|
qreal useableWidth();
|
||||||
|
|
||||||
void reposition(int start, int end);
|
void reposition(int start, int end, qreal deltaY);
|
||||||
void repositionDownTo(int start, qreal end);
|
|
||||||
void updateSceneRect();
|
void updateSceneRect();
|
||||||
void partialUpdate();
|
void partialUpdate();
|
||||||
void fullUpdate();
|
void fullUpdate();
|
||||||
@ -116,7 +115,7 @@ private:
|
|||||||
|
|
||||||
// layout
|
// layout
|
||||||
QMarginsF margins = QMarginsF(10.0,10.0,10.0,10.0);
|
QMarginsF margins = QMarginsF(10.0,10.0,10.0,10.0);
|
||||||
qreal lineSpacing = 10.0f;
|
qreal lineSpacing = 5.0f;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "src/misc/style.h"
|
#include "src/misc/style.h"
|
||||||
|
|
||||||
#define NAME_COL_WIDTH 75.0
|
#define NAME_COL_WIDTH 75.0
|
||||||
#define TIME_COL_WIDTH 85.0
|
#define TIME_COL_WIDTH 90.0
|
||||||
|
|
||||||
ChatMessage::ChatMessage()
|
ChatMessage::ChatMessage()
|
||||||
{
|
{
|
||||||
|
@ -19,16 +19,16 @@
|
|||||||
|
|
||||||
#include "../chatlinecontent.h"
|
#include "../chatlinecontent.h"
|
||||||
|
|
||||||
class Image : public QObject, public ChatLineContent
|
class Image : public ChatLineContent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Image(QSizeF size, const QString &filename);
|
Image(QSizeF size, const QString &filename);
|
||||||
|
|
||||||
virtual QRectF boundingRect() const;
|
virtual QRectF boundingRect() const override;
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
virtual void setWidth(qreal width);
|
virtual void setWidth(qreal width) override;
|
||||||
virtual QRectF boundingSceneRect() const;
|
virtual QRectF boundingSceneRect() const override;
|
||||||
virtual qreal getAscent() const;
|
virtual qreal getAscent() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSizeF size;
|
QSizeF size;
|
||||||
|
@ -28,12 +28,12 @@ class Spinner : public QObject, public ChatLineContent
|
|||||||
public:
|
public:
|
||||||
Spinner(QSizeF size);
|
Spinner(QSizeF size);
|
||||||
|
|
||||||
virtual QRectF boundingRect() const;
|
virtual QRectF boundingRect() const override;
|
||||||
virtual QRectF boundingSceneRect() const;
|
virtual QRectF boundingSceneRect() const override;
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
virtual void setWidth(qreal width);
|
virtual void setWidth(qreal width) override;
|
||||||
virtual void visibilityChanged(bool visible);
|
virtual void visibilityChanged(bool visible) override;
|
||||||
virtual qreal getAscent() const;
|
virtual qreal getAscent() const override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void timeout();
|
void timeout();
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include <QAbstractTextDocumentLayout>
|
#include <QAbstractTextDocumentLayout>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwText)
|
Text::Text(const QString& txt, QFont font, bool enableElide, const QString &rwText)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user