diff options
author | Kevin Smith <git@kismith.co.uk> | 2013-10-04 14:20:53 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2013-11-08 20:42:01 (GMT) |
commit | 238ee0861cc2f9b0143bce986abbd15ce638c561 (patch) | |
tree | 304ed1e0e9af2f27509dd33102232d174817b992 /Swift/QtUI/QtPlainChatView.cpp | |
parent | ef23f6f50352dc24db7ddea07d3a90c1637d7369 (diff) | |
download | swift-238ee0861cc2f9b0143bce986abbd15ce638c561.zip swift-238ee0861cc2f9b0143bce986abbd15ce638c561.tar.bz2 |
Improve some access for screen readers.
Includes the start of a very ugly plain text chat log
Change-Id: I26b6d8f752164e4f8a12fe66aedc93af67345cca
Diffstat (limited to 'Swift/QtUI/QtPlainChatView.cpp')
-rw-r--r-- | Swift/QtUI/QtPlainChatView.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Swift/QtUI/QtPlainChatView.cpp b/Swift/QtUI/QtPlainChatView.cpp new file mode 100644 index 0000000..267b13b --- /dev/null +++ b/Swift/QtUI/QtPlainChatView.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/QtUI/QtPlainChatView.h> + +#include <QTextEdit> +#include <QVBoxLayout> + +#include <Swiften/Base/foreach.h> + +#include <Swift/QtUI/ChatSnippet.h> +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtUtilities.h> + + +namespace Swift { + +QtPlainChatView::QtPlainChatView(QWidget* parent) : QtChatView(parent) { + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(0,0,0,0); + log_ = new QTextEdit(this); + log_->setReadOnly(true); + mainLayout->addWidget(log_); +} + +QtPlainChatView::~QtPlainChatView() { + +} + +QString chatMessageToString(const ChatWindow::ChatMessage& message) { + QString result; + foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) { + boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart; + boost::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart; + boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart; + boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart; + + if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) { + QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text)); + text.replace("\n","<br/>"); + result += text; + continue; + } + if ((uriPart = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) { + QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target)); + result += "<a href='" + uri + "' >" + uri + "</a>"; + continue; + } + if ((emoticonPart = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) { + result += P2QSTRING(emoticonPart->alternativeText); + continue; + } + if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) { + //FIXME: Maybe do something here. Anything, really. + continue; + } + } + return result; +} + +std::string QtPlainChatView::addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/) { + QString text = "<p>"; + if (label) { + text += P2QSTRING(label->getLabel()) + "<br/>"; + } + QString name = senderIsSelf ? "you" : P2QSTRING(senderName); + text += QString(tr("At %1 %2 said:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>"; + text += chatMessageToString(message); + text += "</p>"; + log_->append(text); + return ""; +}; + +std::string QtPlainChatView::addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/) { + QString text = "<p>"; + if (label) { + text += P2QSTRING(label->getLabel()) + "<br/>"; + } + QString name = senderIsSelf ? "you" : P2QSTRING(senderName); + text += QString(tr("At %1 %2 ")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name); + text += chatMessageToString(message); + text += "</p>"; + log_->append(text); + return ""; +}; + + +} |