From ed56cca2e708e5fabcc2c5616ae10f9098c00fe1 Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 4 Feb 2020 18:14:51 +0300 Subject: [PATCH] some visual tweaks, moving on message delivery statuses --- global.h | 4 ++++ translations/squawk.ru.ts | 12 +++++++++++ ui/utils/message.cpp | 40 +++++++++++++++++++++++++------------ ui/utils/message.h | 4 +++- ui/utils/messageline.cpp | 7 +++++-- ui/widgets/conversation.cpp | 14 +++++++++---- ui/widgets/conversation.h | 1 + 7 files changed, 62 insertions(+), 20 deletions(-) diff --git a/global.h b/global.h index f194862..c815149 100644 --- a/global.h +++ b/global.h @@ -107,6 +107,10 @@ static const std::deque subscriptionStateNames = {"None", "From", "To", static const std::deque affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"}; static const std::deque roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"}; + +static const std::deque messageStateNames = {"Pending", "Sent", "Delivered", "Error"}; +static const std::deque messageStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; + QString generateUUID(); static const std::vector colorPalette = { diff --git a/translations/squawk.ru.ts b/translations/squawk.ru.ts index 412b6d8..4fe02e3 100644 --- a/translations/squawk.ru.ts +++ b/translations/squawk.ru.ts @@ -298,6 +298,18 @@ Other Другой + + Pending + В процессе + + + Sent + Отправлено + + + Delivered + Доставлено + JoinConference diff --git a/ui/utils/message.cpp b/ui/utils/message.cpp index c20930f..ac8be9c 100644 --- a/ui/utils/message.cpp +++ b/ui/utils/message.cpp @@ -36,10 +36,12 @@ const QRegularExpression urlReg("(?setContentsMargins(10, 5, 10, 5); body->setBackgroundRole(QPalette::AlternateBase); body->setAutoFillBackground(true); QString bd = msg.getBody(); //bd.replace(imgReg, ""); bd.replace(urlReg, "\\1"); - bd.replace("\n", "
"); + //bd.replace("\n", "
"); text->setTextFormat(Qt::RichText); - text->setText(bd);; + text->setText("

" + bd + "

");; text->setTextInteractionFlags(text->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); text->setWordWrap(true); text->setOpenExternalLinks(true); @@ -81,7 +85,6 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_ bodyLayout->addWidget(sender); bodyLayout->addWidget(text); - bodyLayout->addWidget(date); shadow->setBlurRadius(10); shadow->setXOffset(1); @@ -90,22 +93,33 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_ body->setGraphicsEffect(shadow); avatar->setMaximumHeight(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) { sender->setAlignment(Qt::AlignRight); date->setAlignment(Qt::AlignRight); - addStretch(); - addWidget(body); - addItem(aLay); + QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast(source.getState())])); + QLabel* statusIcon = new QLabel(); + statusIcon->setToolTip(QCoreApplication::translate("Global", Shared::messageStateNames[static_cast(source.getState())].toLatin1())); + statusIcon->setPixmap(q.pixmap(12, 12)); + statusLay->addWidget(statusIcon); + statusLay->addWidget(date); + layout->addStretch(); + layout->addWidget(body); + layout->addWidget(avatar); } else { - addItem(aLay); - addWidget(body); - addStretch(); + layout->addWidget(avatar); + layout->addWidget(body); + layout->addStretch(); + statusLay->addWidget(date); } + + bodyLayout->addWidget(statusBar); + layout->setAlignment(avatar, Qt::AlignTop); } Message::~Message() diff --git a/ui/utils/message.h b/ui/utils/message.h index 537f40b..b9d76ee 100644 --- a/ui/utils/message.h +++ b/ui/utils/message.h @@ -37,7 +37,7 @@ /** * @todo write docs */ -class Message : public QHBoxLayout +class Message : public QWidget { Q_OBJECT public: @@ -62,7 +62,9 @@ signals: private: Shared::Message msg; QWidget* body; + QWidget* statusBar; QVBoxLayout* bodyLayout; + QHBoxLayout* layout; QLabel* date; QLabel* sender; QLabel* text; diff --git a/ui/utils/messageline.cpp b/ui/utils/messageline.cpp index ba95259..c436c57 100644 --- a/ui/utils/messageline.cpp +++ b/ui/utils/messageline.cpp @@ -38,7 +38,10 @@ MessageLine::MessageLine(bool p_room, QWidget* parent): busyShown(false), progress() { + setContentsMargins(0, 0, 0, 0); + layout->setContentsMargins(0, 0, 0, 0); setBackgroundRole(QPalette::Base); + layout->setSpacing(0); layout->addStretch(); } @@ -145,9 +148,9 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc if (res == end) { - layout->addLayout(message); + layout->addWidget(message); } else { - layout->insertLayout(index, message); + layout->insertWidget(index + 1, message); } if (msg.hasOutOfBandUrl()) { diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index ef06dd6..6b3613f 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -46,7 +46,8 @@ Conversation::Conversation(bool muc, Models::Account* acc, const QString pJid, c scroll(down), manualSliderChange(false), requestingHistory(false), - everShown(false) + everShown(false), + tsb(QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient) == 1) { 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(); m_ui->scrollArea->setWidget(line); 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); m_ui->scrollArea->installEventFilter(&scrollResizeCatcher); m_ui->filesPanel->installEventFilter(&attachResizeCatcher); @@ -313,8 +318,9 @@ void Conversation::onScrollResize() if (everShown) { int size = m_ui->scrollArea->width(); QScrollBar* bar = m_ui->scrollArea->verticalScrollBar(); - if (bar->isVisible()) { + if (bar->isVisible() && !tsb) { size -= bar->width(); + } line->setMaximumWidth(size); } diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index 5e68965..311db65 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -135,6 +135,7 @@ protected: bool manualSliderChange; bool requestingHistory; bool everShown; + bool tsb; //transient scroll bars }; #endif // CONVERSATION_H