some visual tweaks, moving on message delivery statuses

This commit is contained in:
Blue 2020-02-04 18:14:51 +03:00
parent a4136ff9fe
commit ed56cca2e7
7 changed files with 62 additions and 20 deletions

View File

@ -107,6 +107,10 @@ static const std::deque<QString> subscriptionStateNames = {"None", "From", "To",
static const std::deque<QString> affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"}; static const std::deque<QString> affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"};
static const std::deque<QString> roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"}; static const std::deque<QString> roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"};
static const std::deque<QString> messageStateNames = {"Pending", "Sent", "Delivered", "Error"};
static const std::deque<QString> messageStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"};
QString generateUUID(); QString generateUUID();
static const std::vector<QColor> colorPalette = { static const std::vector<QColor> colorPalette = {

View File

@ -298,6 +298,18 @@
<source>Other</source> <source>Other</source>
<translation>Другой</translation> <translation>Другой</translation>
</message> </message>
<message>
<source>Pending</source>
<translation>В процессе</translation>
</message>
<message>
<source>Sent</source>
<translation>Отправлено</translation>
</message>
<message>
<source>Delivered</source>
<translation>Доставлено</translation>
</message>
</context> </context>
<context> <context>
<name>JoinConference</name> <name>JoinConference</name>

View File

@ -36,10 +36,12 @@ const QRegularExpression urlReg("(?<!<a\\shref=['\"])(?<!<img\\ssrc=['\"])("
const QRegularExpression imgReg("((?:https?|ftp)://\\S+\\.(?:jpg|jpeg|png|svg|gif))"); const QRegularExpression imgReg("((?:https?|ftp)://\\S+\\.(?:jpg|jpeg|png|svg|gif))");
Message::Message(const Shared::Message& source, bool outgoing, const QString& p_sender, const QString& avatarPath, QWidget* parent): Message::Message(const Shared::Message& source, bool outgoing, const QString& p_sender, const QString& avatarPath, QWidget* parent):
QHBoxLayout(parent), QWidget(parent),
msg(source), msg(source),
body(new QWidget()), body(new QWidget()),
statusBar(new QWidget()),
bodyLayout(new QVBoxLayout(body)), bodyLayout(new QVBoxLayout(body)),
layout(new QHBoxLayout(this)),
date(new QLabel(msg.getTime().toLocalTime().toString())), date(new QLabel(msg.getTime().toLocalTime().toString())),
sender(new QLabel(p_sender)), sender(new QLabel(p_sender)),
text(new QLabel()), text(new QLabel()),
@ -54,15 +56,17 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
hasFile(false), hasFile(false),
commentAdded(false) commentAdded(false)
{ {
setContentsMargins(0, 0, 0, 0);
layout->setContentsMargins(10, 5, 10, 5);
body->setBackgroundRole(QPalette::AlternateBase); body->setBackgroundRole(QPalette::AlternateBase);
body->setAutoFillBackground(true); body->setAutoFillBackground(true);
QString bd = msg.getBody(); QString bd = msg.getBody();
//bd.replace(imgReg, "<img src=\"\\1\"/>"); //bd.replace(imgReg, "<img src=\"\\1\"/>");
bd.replace(urlReg, "<a href=\"\\1\">\\1</a>"); bd.replace(urlReg, "<a href=\"\\1\">\\1</a>");
bd.replace("\n", "<br>"); //bd.replace("\n", "<br>");
text->setTextFormat(Qt::RichText); text->setTextFormat(Qt::RichText);
text->setText(bd);; text->setText("<p style=\"white-space: pre-wrap;\">" + bd + "</p>");;
text->setTextInteractionFlags(text->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); text->setTextInteractionFlags(text->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
text->setWordWrap(true); text->setWordWrap(true);
text->setOpenExternalLinks(true); text->setOpenExternalLinks(true);
@ -81,7 +85,6 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
bodyLayout->addWidget(sender); bodyLayout->addWidget(sender);
bodyLayout->addWidget(text); bodyLayout->addWidget(text);
bodyLayout->addWidget(date);
shadow->setBlurRadius(10); shadow->setBlurRadius(10);
shadow->setXOffset(1); shadow->setXOffset(1);
@ -90,22 +93,33 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
body->setGraphicsEffect(shadow); body->setGraphicsEffect(shadow);
avatar->setMaximumHeight(60); avatar->setMaximumHeight(60);
avatar->setMaximumWidth(60); avatar->setMaximumWidth(60);
QVBoxLayout* aLay = new QVBoxLayout();
aLay->addWidget(avatar);
aLay->addStretch();
statusBar->setContentsMargins(0, 0, 0, 0);
QHBoxLayout* statusLay = new QHBoxLayout();
statusLay->setContentsMargins(0, 0, 0, 0);
statusBar->setLayout(statusLay);
if (outgoing) { if (outgoing) {
sender->setAlignment(Qt::AlignRight); sender->setAlignment(Qt::AlignRight);
date->setAlignment(Qt::AlignRight); date->setAlignment(Qt::AlignRight);
addStretch(); QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast<uint8_t>(source.getState())]));
addWidget(body); QLabel* statusIcon = new QLabel();
addItem(aLay); statusIcon->setToolTip(QCoreApplication::translate("Global", Shared::messageStateNames[static_cast<uint8_t>(source.getState())].toLatin1()));
statusIcon->setPixmap(q.pixmap(12, 12));
statusLay->addWidget(statusIcon);
statusLay->addWidget(date);
layout->addStretch();
layout->addWidget(body);
layout->addWidget(avatar);
} else { } else {
addItem(aLay); layout->addWidget(avatar);
addWidget(body); layout->addWidget(body);
addStretch(); layout->addStretch();
statusLay->addWidget(date);
} }
bodyLayout->addWidget(statusBar);
layout->setAlignment(avatar, Qt::AlignTop);
} }
Message::~Message() Message::~Message()

View File

@ -37,7 +37,7 @@
/** /**
* @todo write docs * @todo write docs
*/ */
class Message : public QHBoxLayout class Message : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -62,7 +62,9 @@ signals:
private: private:
Shared::Message msg; Shared::Message msg;
QWidget* body; QWidget* body;
QWidget* statusBar;
QVBoxLayout* bodyLayout; QVBoxLayout* bodyLayout;
QHBoxLayout* layout;
QLabel* date; QLabel* date;
QLabel* sender; QLabel* sender;
QLabel* text; QLabel* text;

View File

@ -38,7 +38,10 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
busyShown(false), busyShown(false),
progress() progress()
{ {
setContentsMargins(0, 0, 0, 0);
layout->setContentsMargins(0, 0, 0, 0);
setBackgroundRole(QPalette::Base); setBackgroundRole(QPalette::Base);
layout->setSpacing(0);
layout->addStretch(); layout->addStretch();
} }
@ -145,9 +148,9 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc
if (res == end) { if (res == end) {
layout->addLayout(message); layout->addWidget(message);
} else { } else {
layout->insertLayout(index, message); layout->insertWidget(index + 1, message);
} }
if (msg.hasOutOfBandUrl()) { if (msg.hasOutOfBandUrl()) {

View File

@ -46,7 +46,8 @@ Conversation::Conversation(bool muc, Models::Account* acc, const QString pJid, c
scroll(down), scroll(down),
manualSliderChange(false), manualSliderChange(false),
requestingHistory(false), requestingHistory(false),
everShown(false) everShown(false),
tsb(QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient) == 1)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
@ -77,8 +78,12 @@ Conversation::Conversation(bool muc, Models::Account* acc, const QString pJid, c
QScrollBar* vs = m_ui->scrollArea->verticalScrollBar(); QScrollBar* vs = m_ui->scrollArea->verticalScrollBar();
m_ui->scrollArea->setWidget(line); m_ui->scrollArea->setWidget(line);
vs->installEventFilter(&vis); vs->installEventFilter(&vis);
vs->setBackgroundRole(QPalette::Base);
vs->setAutoFillBackground(true); if (!tsb) {
vs->setBackgroundRole(QPalette::Base);
vs->setAutoFillBackground(true);
}
connect(vs, &QScrollBar::valueChanged, this, &Conversation::onSliderValueChanged); connect(vs, &QScrollBar::valueChanged, this, &Conversation::onSliderValueChanged);
m_ui->scrollArea->installEventFilter(&scrollResizeCatcher); m_ui->scrollArea->installEventFilter(&scrollResizeCatcher);
m_ui->filesPanel->installEventFilter(&attachResizeCatcher); m_ui->filesPanel->installEventFilter(&attachResizeCatcher);
@ -313,8 +318,9 @@ void Conversation::onScrollResize()
if (everShown) { if (everShown) {
int size = m_ui->scrollArea->width(); int size = m_ui->scrollArea->width();
QScrollBar* bar = m_ui->scrollArea->verticalScrollBar(); QScrollBar* bar = m_ui->scrollArea->verticalScrollBar();
if (bar->isVisible()) { if (bar->isVisible() && !tsb) {
size -= bar->width(); size -= bar->width();
} }
line->setMaximumWidth(size); line->setMaximumWidth(size);
} }

View File

@ -135,6 +135,7 @@ protected:
bool manualSliderChange; bool manualSliderChange;
bool requestingHistory; bool requestingHistory;
bool everShown; bool everShown;
bool tsb; //transient scroll bars
}; };
#endif // CONVERSATION_H #endif // CONVERSATION_H