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