Commit f017608a authored by scuq's avatar scuq

chat alignment, unread on startup

parent ab89e893
Pipeline #361 passed with stage
in 21 minutes and 14 seconds
......@@ -82,6 +82,12 @@ void dialogChat::setupSignals()
this, SLOT (slOnMessageReceived(QDateTime, QString, bool, bool, QMap<QString, QVariant>, QString, QString, bool, int, int))
);
connect( this->session, SIGNAL (siChannelUnreadCountReceived(const int, const QString)),
this, SLOT (slChannelUnreadCountReceived(const int, const QString))
);
//slChannelUnreadCountReceived
}
void dialogChat::setUnread()
......@@ -94,6 +100,7 @@ void dialogChat::setUnread()
this->m_unreadBlinkTimer->start((int)this->m_unreadBlinkInterval);
qApp->alert(this);
}
void dialogChat::setRead()
......@@ -131,6 +138,7 @@ void dialogChat::setChatFont(QFont font)
{
this->ui->textBrowserChatOutput->setFont(font);
this->ui->plainTextEditChatInput->setFont(font);
this->setChatFontInternal(font);
}
void dialogChat::closeEvent(QCloseEvent *closeev)
......@@ -175,6 +183,11 @@ void dialogChat::setColorUnreadCurrent(const QColor &value)
colorUnreadCurrent = value;
}
void dialogChat::setChatFontInternal(QFont font)
{
this->chatFont = font;
}
QColor dialogChat::getColorUnread2() const
{
return colorUnread2;
......@@ -308,6 +321,13 @@ void dialogChat::on_plainTextEditChatInput_textChanged()
}
void dialogChat::slChannelUnreadCountReceived(const int &unreadcount, const QString &channelid)
{
if (channelid == this->contact->getDirectChannelId()) {
this->setUnread();
}
}
void dialogChat::slChannelPosted(const QJsonDocument &replyJson, const QString &channelid)
{
......@@ -381,7 +401,9 @@ void dialogChat::slOnMessageReceived(QDateTime timestamp, QString message, bool
if (longestsendernamelen > this->longestUsernameLen) {
this->longestUsernameLen = longestsendernamelen;
QFontMetrics fm(this->getChatFontInternal());
this->longestUsernameLen = fm.averageCharWidth() *1.7 * longestsendernamelen ;
}
......@@ -399,25 +421,15 @@ void dialogChat::slOnMessageReceived(QDateTime timestamp, QString message, bool
if ( (hasAttachment) && !(hasImage) ) {
this->insertText( QString("[%1] %4 %2 %3").arg(
timestamp.toString(this->getChatDateTimeFormat()),
attachmentMarker,
message,
usernamestr
)
);
this->insertText(timestamp.toString(this->getChatDateTimeFormat()), message, usernamestr);
}
if ( (hasImage) ) {
QString _message = message;
this->insertText( QString("[%1] %3 %2").arg(
timestamp.toString(this->getChatDateTimeFormat()),
message,
usernamestr
)
);
this->insertText(timestamp.toString(this->getChatDateTimeFormat()), message, usernamestr);
this->insertChatImageSkeleton(imageProperties);
......@@ -425,12 +437,8 @@ void dialogChat::slOnMessageReceived(QDateTime timestamp, QString message, bool
if ( !(hasAttachment) && !(hasImage) ) {
this->insertText( QString("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td width=\"50\">[%1]</td><td align=\"right\" width=\"100\">%3</td><td width=\"*\">%2</td></tr></table>").arg(
timestamp.toString(this->getChatDateTimeFormat()),
message,
usernamestr
)
);
this->insertText(timestamp.toString(this->getChatDateTimeFormat()), message, usernamestr);
}
this->ui->textBrowserChatOutput->verticalScrollBar()->setValue(this->ui->textBrowserChatOutput->verticalScrollBar()->maximum());
......@@ -461,18 +469,42 @@ void dialogChat::slGlobalSettingsChanged(QMap<QString, QVariant> globalSettings)
}
void dialogChat::insertText(QString text)
void dialogChat::insertText(QString datetime, QString text, QString usernamestr)
{
QRegExp regExp("((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w]+@)[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%\\/\\.\\w\\-]*)?\\??(?:[\\-\\+=&;%@\\.\\w]*)#?(?:[\\.\\!\\/\\\\\\w]*))?)");
QString textout;
QFontMetrics fm(this->getChatFontInternal());
int datewidth = fm.averageCharWidth() *1.4 * datetime.length() ;
text.replace(regExp, "<a href='\\1'>\\1</a>");
textout = QString("<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\" width=\"100%\">" \
" <tr>" \
" <td width=\"%5\">[%1]</td>" \
" <td align=\"right\" width=\"%4\">%3</td>" \
" <td width=\"*\">%2</td>" \
" </tr>" \
"</table>" \
).arg(
datetime,
text,
usernamestr,
QString::number(this->longestUsernameLen),
QString::number(datewidth)
);
qDebug() << longestUsernameLen;
textout = ""+text;
// textout.toHtmlEscaped();
textout.replace(regExp, "<a href='\\1'>\\1</a>");
......@@ -569,7 +601,7 @@ void dialogChat::insertChatImageSkeleton(QMap<QString, QVariant> imageProperties
int _scaledHeight;
if ( this->ui->textBrowserChatOutput->width() < imageProperties["width"].toInt() ) {
_scaledWidth = qCeil(this->ui->textBrowserChatOutput->width() * 0.8);
_scaledWidth = qCeil(this->ui->textBrowserChatOutput->width() * 0.4);
_scaledHeight = qCeil(_scaledWidth / aspectRatio);
} else {
_scaledWidth = imageProperties["width"].toInt();
......@@ -653,14 +685,19 @@ void dialogChat::slUpdateFromDownloadedFile(const QString &fileid, QByteArray fi
int _scaledHeight;
if ( this->ui->textBrowserChatOutput->width() < image.width() ) {
_scaledWidth = ceil(this->ui->textBrowserChatOutput->width() * 0.8);
_scaledWidth = ceil(this->ui->textBrowserChatOutput->width() * 0.4);
_scaledHeight = ceil(_scaledWidth / aspectRatio);
} else {
_scaledWidth = image.width();
_scaledHeight = image.height();
}
QImage scaled = image.scaled(_scaledWidth,_scaledHeight);
//QImage scaled = image.scaled(_scaledWidth,_scaledHeight);
QRect rect(0, 0, _scaledWidth, _scaledHeight);
QImage scaled = image.copy(rect);
if ( !(image.isNull()) ) {
......@@ -716,6 +753,11 @@ void dialogChat::slOnBlinkTimerRefresh()
}
QFont dialogChat::getChatFontInternal() const
{
return chatFont;
}
QColor dialogChat::getColorChatLink() const
{
return m_colorchatlink;
......
......@@ -51,9 +51,13 @@ public:
QColor getColorUnreadCurrent() const;
void setColorUnreadCurrent(const QColor &value);
QFont getChatFontInternal() const;
void setChatFontInternal(QFont font);
private slots:
void on_plainTextEditChatInput_textChanged();
//void slChannelPostsReceived(const QJsonDocument &replyJson, const QString &channelid);
void slChannelUnreadCountReceived( const int &unreadcount, const QString &channelid );
void slChannelPosted(const QJsonDocument &replyJson, const QString &channelid);
void slOnMessageReceived(QDateTime timestamp, QString message, bool hasAttachment, bool hasImage, QMap<QString, QVariant> imageProperties, QString channelid, QString senderid, bool historic, int msgcounthint, int longestsendernamelen);
void slGlobalSettingsChanged(QMap<QString, QVariant> globalSettings);
......@@ -78,6 +82,7 @@ private:
account *m_account;
QColor m_colorchatlink;
int historicMsgPrintCount;
QFont chatFont;
QMap<QString, ImContact*> m_contacts;
void setChatDetails();
void loadMessageHistrory();
......@@ -87,7 +92,7 @@ private:
void setUnread();
void setRead();
void setupTimers();
void insertText(QString text);
void insertText(QString datetime, QString text, QString usernamestr);
void insertHline();
void insertChatImageSkeleton(QMap<QString, QVariant> imageProperties);
void setChatFont(QFont font);
......
......@@ -567,6 +567,30 @@ void ImSession::parseChannelPostsHistory(const QJsonDocument &replyJson, const Q
siChannelPostsHistoryReceived( _timestamp, _message, _hasAttachment, _hasImage, _imageProperties, channelid, _userid, true, post_order.count(), longestSenderNameLen );
}
}
void ImSession::parseUnreadCount(const QJsonDocument &replyJson, const QString &channelid)
{
QJsonObject unread_data = replyJson.object();
int _unreadCount = 0;
QString _channelId = 0;
if (unread_data.keys().contains("msg_count")) {
_unreadCount = unread_data["msg_count"].toInt();
}
if (unread_data.keys().contains("channel_id")) {
_channelId = unread_data["channel_id"].toString();
}
if (_unreadCount > 0) {
emit siChannelUnreadCountReceived( _unreadCount, _channelId );
}
//emit siChannelUnreadCountReceived( QJsonDocument::fromJson(pReply->readAll()), _channelid );
}
......@@ -616,7 +640,7 @@ void ImSession::parseNetworkResponse(QNetworkReply *pReply)
if (callingFuncName.startsWith( "mmapi::requestUnreadCount" )) {
//qDebug().noquote() << "getChannelPosts: " << QJsonDocument::fromJson( pReply->readAll() ).toJson(QJsonDocument::Indented);
QString _channelid = callingFuncName.split("__")[1];
emit siChannelUnreadCountReceived( QJsonDocument::fromJson(pReply->readAll()), _channelid );
parseUnreadCount( QJsonDocument::fromJson(pReply->readAll()), _channelid );
}
if (callingFuncName.startsWith( "mmapi::requestRemoteViewChannel" )) {
QString _channelid = callingFuncName.split("__")[1];
......@@ -811,6 +835,8 @@ void ImSession::slReplyChannelListReceived(const QJsonDocument &replyJson)
}
emit siRosterUpdate( iMContacts );
this->requestUnreadCount();
qDebug() << QString("%1: channel list received.").arg(this->metaObject()->className());
}
......
......@@ -92,6 +92,7 @@ private:
void setupTimers();
QString getMateIdFromDirectChannelName(QString directchannelname);
void parseChannelPostsHistory(const QJsonDocument &replyJson, const QString &channelid);
void parseUnreadCount(const QJsonDocument &replyJson, const QString &channelid);
protected:
QMap<QNetworkReply*, QString> netReplies;
QMap<QNetworkReply*, QHash<QString, QString> > netParams;
......@@ -107,7 +108,7 @@ signals:
void siUserStatusReceived( const QJsonDocument &replyJson );
void siChannelPostsHistoryReceived( QDateTime timestamp, QString message, bool hasAttachment, bool hasImage, QMap<QString, QVariant> imageProperties, QString channelid, QString sendername, bool historic, int msgcounthint, int longestsendernamelen );
void siChannelPosted( const QJsonDocument &replyJson, const QString &channelid );
void siChannelUnreadCountReceived( const QJsonDocument &replyJson, const QString &channelid );
void siChannelUnreadCountReceived( const int &unreadcount, const QString &channelid );
void siFileDownloaded( const QString &fileid, QByteArray filedata );
void siMessageReceived(QDateTime timestamp, QString message, bool hasAttachment, bool hasImage, QMap<QString, QVariant> imageProperties, QString channelid, QString sendername, bool historic, int msgcounthint, int longestsendernamelen);
void siMessageReceived(QString channelid, QString senderid);
......
......@@ -63,7 +63,7 @@ void RosterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
if (_model->getStatusShape() == "Ellipse" ) {
painter->setBrush(QBrush( _model->getColorOnline() ));
painter->drawEllipse(myOption.rect.center(), statusBaseSize, statusBaseSize);
painter->drawEllipse(QPoint(myOption.rect.left()+10, myOption.rect.center().ry()), statusBaseSize, statusBaseSize);
}
if (_model->getStatusShape() == "Rectangle" ) {
......@@ -90,7 +90,7 @@ void RosterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
if (_model->getStatusShape() == "Ellipse" ) {
painter->setBrush(QBrush( _model->getColorOffline() ));
painter->drawEllipse(myOption.rect.center(), statusBaseSize, statusBaseSize);
painter->drawEllipse(QPoint(myOption.rect.left()+10, myOption.rect.center().ry()), statusBaseSize, statusBaseSize);
}
if (_model->getStatusShape() == "Rectangle" ) {
painter->setBrush(QBrush( _model->getColorOffline() ));
......@@ -116,7 +116,7 @@ void RosterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
if (_model->getStatusShape() == "Ellipse" ) {
painter->setBrush(QBrush( _model->getColorAway() ));
painter->drawEllipse(myOption.rect.center(), statusBaseSize, statusBaseSize);
painter->drawEllipse(QPoint(myOption.rect.left()+10, myOption.rect.center().ry()), statusBaseSize, statusBaseSize);
}
if (_model->getStatusShape() == "Rectangle" ) {
painter->setBrush(QBrush( _model->getColorAway() ));
......@@ -142,7 +142,7 @@ void RosterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
if (_model->getChannelShape() == "Ellipse" ) {
painter->setBrush(QBrush( _model->getColorChannel() ));
painter->drawEllipse(myOption.rect.center(), channelBaseSize, channelBaseSize);
painter->drawEllipse(QPoint(myOption.rect.left()+10, myOption.rect.center().ry()), channelBaseSize, channelBaseSize);
}
if (_model->getChannelShape() == "Rectangle" ) {
painter->setBrush(QBrush( _model->getColorChannel() ));
......
......@@ -35,6 +35,11 @@ void RosterModel::setupSignals()
connect( this->session, SIGNAL (siMessageReceived(QString, QString)),
this, SLOT (slReceivedUnreadMessages(QString, QString))
);
connect( this->session, SIGNAL (siChannelUnreadCountReceived(const int, const QString)),
this, SLOT (slChannelUnreadCountReceived(const int, const QString))
);
//slReceivedUnreadMessages
}
......@@ -396,6 +401,44 @@ void RosterModel::slReceivedUnreadMessages(QString channelid, QString senderid)
}
void RosterModel::slChannelUnreadCountReceived(const int &unreadcount, const QString &channelid)
{
if ( channelid.length() > 0 ) {
QMapIterator<QString, ImContact*> cntcts(this->iMContacts);
while (cntcts.hasNext()) {
cntcts.next();
for(int i = 0; i<this->rowCount(); ++i) {
QModelIndex nickname_index = this->index(i, (qint64)RosterModel::ColumnIndex::nickname);
QModelIndex unread_index = this->index(i, (qint64)RosterModel::ColumnIndex::unread);
//this->setUserData(status_index,"");
if (cntcts.value()->getDirectChannelId() == channelid ) {
if (this->itemData(nickname_index)[0].toString() == cntcts.value()->getUsername() ) {
cntcts.value()->setUnreadMessages(true);
emit (dataChanged(unread_index,unread_index));
qDebug() << "pendingunreadmessages " << cntcts.value()->getUsername();
return;
}
}
}
}
}
}
void RosterModel::slOnRead(QString channelid)
{
......
......@@ -115,6 +115,7 @@ private slots:
void slGlobalSettingsChanged(QMap<QString, QVariant> globalSettings);
void slOnRosterUpdateReceived(QMap<QString, ImContact*> imContacts);
void slReceivedUnreadMessages(QString channelid, QString senderid);
void slChannelUnreadCountReceived( const int &unreadcount, const QString &channelid );
void slOnRead(QString channelid);
void slOnBlinkTimerRefresh();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment