mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
fd9d7d64bf
|
@ -23,6 +23,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#define CONTENT_WIDTH 250
|
||||||
|
|
||||||
uint FileTransferInstance::Idconter = 0;
|
uint FileTransferInstance::Idconter = 0;
|
||||||
|
|
||||||
FileTransferInstance::FileTransferInstance(ToxFile File)
|
FileTransferInstance::FileTransferInstance(ToxFile File)
|
||||||
|
@ -34,6 +36,11 @@ FileTransferInstance::FileTransferInstance(ToxFile File)
|
||||||
remotePaused = false;
|
remotePaused = false;
|
||||||
|
|
||||||
filename = File.fileName;
|
filename = File.fileName;
|
||||||
|
QFont font;
|
||||||
|
font.setPixelSize(10);
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
filenameElided = fm.elidedText(filename, Qt::ElideRight, CONTENT_WIDTH);
|
||||||
|
|
||||||
size = getHumanReadableSize(File.filesize);
|
size = getHumanReadableSize(File.filesize);
|
||||||
speed = "0B/s";
|
speed = "0B/s";
|
||||||
eta = "00:00";
|
eta = "00:00";
|
||||||
|
@ -328,7 +335,7 @@ QString FileTransferInstance::drawButtonlessForm(const QString &type)
|
||||||
imgBStr = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyRGreenFileButton.png")) + "\">";
|
imgBStr = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyRGreenFileButton.png")) + "\">";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString content = "<p>" + filename + "</p><p>" + size + "</p>";
|
QString content = "<p>" + filenameElided + "</p><p>" + size + "</p>";
|
||||||
|
|
||||||
return wrapIntoForm(content, type, imgAStr, imgBStr);
|
return wrapIntoForm(content, type, imgAStr, imgBStr);
|
||||||
}
|
}
|
||||||
|
@ -354,9 +361,9 @@ QString FileTransferInstance::draw2ButtonsForm(const QString &type, const QImage
|
||||||
QString imgBstr = "<img src=\"data:ftrans." + widgetId + ".btnB/png;base64," + QImage2base64(imgB) + "\">";
|
QString imgBstr = "<img src=\"data:ftrans." + widgetId + ".btnB/png;base64," + QImage2base64(imgB) + "\">";
|
||||||
|
|
||||||
QString content;
|
QString content;
|
||||||
QString progrBar = "<img src=\"data:progressbar." + widgetId + "/png;base64," + QImage2base64(drawProgressBarImg(double(lastBytesSent)/totalBytes, 250, 9)) + "\">";
|
QString progrBar = "<img src=\"data:progressbar." + widgetId + "/png;base64," + QImage2base64(drawProgressBarImg(double(lastBytesSent)/totalBytes, CONTENT_WIDTH, 9)) + "\">";
|
||||||
|
|
||||||
content = "<p>" + filename + "</p>";
|
content = "<p>" + filenameElided + "</p>";
|
||||||
content += "<table cellspacing=\"0\"><tr>";
|
content += "<table cellspacing=\"0\"><tr>";
|
||||||
content += "<td>" + size + "</td>";
|
content += "<td>" + size + "</td>";
|
||||||
content += "<td align=center>" + speed + "</td>";
|
content += "<td align=center>" + speed + "</td>";
|
||||||
|
@ -375,7 +382,7 @@ QString FileTransferInstance::wrapIntoForm(const QString& content, const QString
|
||||||
res = "<table cellspacing=\"0\">\n";
|
res = "<table cellspacing=\"0\">\n";
|
||||||
res += "<tr valign=middle>\n";
|
res += "<tr valign=middle>\n";
|
||||||
res += insertMiniature(type);
|
res += insertMiniature(type);
|
||||||
res += "<td width=280>\n";
|
res += "<td width=" + QString::number(CONTENT_WIDTH + 30) + ">\n";
|
||||||
res += "<div class=" + type + ">";
|
res += "<div class=" + type + ">";
|
||||||
res += content;
|
res += content;
|
||||||
res += "</div>\n";
|
res += "</div>\n";
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
bool remotePaused;
|
bool remotePaused;
|
||||||
QImage pic;
|
QImage pic;
|
||||||
QString filename, size, speed, eta;
|
QString filename, size, speed, eta;
|
||||||
|
QString filenameElided;
|
||||||
QDateTime lastUpdate;
|
QDateTime lastUpdate;
|
||||||
long long lastBytesSent, totalBytes;
|
long long lastBytesSent, totalBytes;
|
||||||
int fileNum;
|
int fileNum;
|
||||||
|
|
|
@ -39,13 +39,11 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
|
||||||
chatTextTable = textCursor().insertTable(1,3);
|
chatTextTable = textCursor().insertTable(1,3);
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
QTextTableFormat tableFormat;
|
||||||
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::VariableLength,0),
|
|
||||||
QTextLength(QTextLength::PercentageLength,100),
|
|
||||||
QTextLength(QTextLength::VariableLength,0)});
|
|
||||||
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
|
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
|
||||||
|
tableFormat.setCellSpacing(2);
|
||||||
|
tableFormat.setWidth(QTextLength(QTextLength::PercentageLength,100));
|
||||||
chatTextTable->setFormat(tableFormat);
|
chatTextTable->setFormat(tableFormat);
|
||||||
chatTextTable->format().setCellSpacing(2);
|
setNameColWidth(100);
|
||||||
chatTextTable->format().setWidth(QTextLength(QTextLength::PercentageLength,100));
|
|
||||||
|
|
||||||
// nameFormat.setAlignment(Qt::AlignRight);
|
// nameFormat.setAlignment(Qt::AlignRight);
|
||||||
// nameFormat.setNonBreakableLines(true);
|
// nameFormat.setNonBreakableLines(true);
|
||||||
|
@ -135,3 +133,14 @@ void ChatAreaWidget::checkSlider()
|
||||||
QScrollBar* scroll = verticalScrollBar();
|
QScrollBar* scroll = verticalScrollBar();
|
||||||
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
|
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatAreaWidget::setNameColWidth(int w)
|
||||||
|
{
|
||||||
|
nameWidth = w;
|
||||||
|
|
||||||
|
QTextTableFormat tableFormat = chatTextTable->format();
|
||||||
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::FixedLength, 100),
|
||||||
|
QTextLength(QTextLength::PercentageLength, 100),
|
||||||
|
QTextLength(QTextLength::FixedLength, 40)});
|
||||||
|
chatTextTable->setFormat(tableFormat);
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ public:
|
||||||
virtual ~ChatAreaWidget();
|
virtual ~ChatAreaWidget();
|
||||||
void insertMessage(ChatAction *msgAction);
|
void insertMessage(ChatAction *msgAction);
|
||||||
|
|
||||||
|
int nameColWidth() {return nameWidth;}
|
||||||
|
void setNameColWidth(int w);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void onFileTranfertInterract(QString widgetName, QString buttonName);
|
void onFileTranfertInterract(QString widgetName, QString buttonName);
|
||||||
|
|
||||||
|
@ -47,6 +50,7 @@ private:
|
||||||
QList<ChatAction*> messages;
|
QList<ChatAction*> messages;
|
||||||
bool lockSliderToBottom;
|
bool lockSliderToBottom;
|
||||||
int sliderPosition;
|
int sliderPosition;
|
||||||
|
int nameWidth;
|
||||||
QTextTable *chatTextTable;
|
QTextTable *chatTextTable;
|
||||||
QTextBlockFormat nameFormat, dateFormat;
|
QTextBlockFormat nameFormat, dateFormat;
|
||||||
};
|
};
|
||||||
|
|
|
@ -125,7 +125,7 @@ void ChatForm::startFileSend(ToxFile file)
|
||||||
name = "";
|
name = "";
|
||||||
previousName = Widget::getInstance()->getUsername();
|
previousName = Widget::getInstance()->getUsername();
|
||||||
|
|
||||||
chatWidget->insertMessage(new FileTransferAction(fileTrans, name, QTime::currentTime().toString("hh:mm"), true));
|
chatWidget->insertMessage(new FileTransferAction(fileTrans, getElidedName(name), QTime::currentTime().toString("hh:mm"), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onFileRecvRequest(ToxFile file)
|
void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
|
@ -156,7 +156,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
name = "";
|
name = "";
|
||||||
previousName = f->getName();
|
previousName = f->getName();
|
||||||
|
|
||||||
chatWidget->insertMessage(new FileTransferAction(fileTrans, name, QTime::currentTime().toString("hh:mm"), false));
|
chatWidget->insertMessage(new FileTransferAction(fileTrans, getElidedName(name), QTime::currentTime().toString("hh:mm"), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
||||||
|
|
|
@ -169,7 +169,7 @@ void GenericChatForm::addMessage(QString author, QString message, QDateTime date
|
||||||
|
|
||||||
if (previousName == author)
|
if (previousName == author)
|
||||||
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
|
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
|
||||||
else chatWidget->insertMessage(new MessageAction(author , message, date, isMe));
|
else chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe));
|
||||||
previousName = author;
|
previousName = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,3 +212,12 @@ void GenericChatForm::addSystemInfoMessage(const QString &message, const QString
|
||||||
|
|
||||||
chatWidget->insertMessage(new SystemMessageAction(message, type, date));
|
chatWidget->insertMessage(new SystemMessageAction(message, type, date));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GenericChatForm::getElidedName(const QString& name)
|
||||||
|
{
|
||||||
|
QFont font;
|
||||||
|
font.setBold(true);
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
|
||||||
|
return fm.elidedText(name, Qt::ElideRight, chatWidget->nameColWidth());
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,8 @@ protected slots:
|
||||||
void onEmoteInsertRequested(QString str);
|
void onEmoteInsertRequested(QString str);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QString getElidedName(const QString& name);
|
||||||
|
|
||||||
CroppingLabel *nameLabel;
|
CroppingLabel *nameLabel;
|
||||||
MaskablePixmapWidget *avatar;
|
MaskablePixmapWidget *avatar;
|
||||||
QWidget *headWidget;
|
QWidget *headWidget;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user